fix: add default interface

This commit is contained in:
Markus Pesch 2021-04-26 09:56:38 +02:00
parent 87307a345c
commit 7f5782cde5
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982

View File

@ -71,6 +71,14 @@ func Read(cnfFile string) (*types.Config, error) {
return nil, fmt.Errorf("failed to decode json: %w", err) return nil, fmt.Errorf("failed to decode json: %w", err)
} }
if len(cnf.Ifaces) <= 0 {
defaultInterface, err := getDefaultInterfaceByIP()
if err != nil {
return nil, err
}
cnf.Ifaces = []string{defaultInterface.Name}
}
for _, iface := range cnf.Ifaces { for _, iface := range cnf.Ifaces {
if _, err := net.InterfaceByName(iface); err != nil { if _, err := net.InterfaceByName(iface); err != nil {
return nil, fmt.Errorf("unknown interface: %v", iface) return nil, fmt.Errorf("unknown interface: %v", iface)