Added switch case to check netMode

Signed-off-by: Roberto Bonafiglia <roberto.bonafiglia@suse.com>
pull/5215/head
Roberto Bonafiglia 3 years ago
parent 2c39febdd2
commit 0c83f50c4c

@ -103,26 +103,37 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt
} }
logrus.Debugf("The interface %s will be used by flannel", iface.Name) logrus.Debugf("The interface %s will be used by flannel", iface.Name)
if netMode == (ipv4+ipv6) || netMode == ipv4 { switch netMode {
case ipv4:
ifaceAddr, err = ip.GetInterfaceIP4Addrs(iface) ifaceAddr, err = ip.GetInterfaceIP4Addrs(iface)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to find IPv4 address for interface %s", iface.Name) return nil, fmt.Errorf("failed to find IPv4 address for interface %s", iface.Name)
} }
logrus.Infof("The interface %s with ipv4 address %s will be used by flannel", iface.Name, ifaceAddr[0]) logrus.Infof("The interface %s with ipv4 address %s will be used by flannel", iface.Name, ifaceAddr[0])
} else { ifacev6Addr = append(ifacev6Addr, nil)
case ipv6:
ifacev6Addr, err = ip.GetInterfaceIP6Addrs(iface)
if err != nil {
return nil, fmt.Errorf("failed to find IPv6 address for interface %s", iface.Name)
}
logrus.Infof("Using dual-stack mode. The ipv6 address %s will be used by flannel", ifacev6Addr[0])
ifaceAddr = append(ifaceAddr, nil) ifaceAddr = append(ifaceAddr, nil)
case (ipv4 + ipv6):
ifaceAddr, err = ip.GetInterfaceIP4Addrs(iface)
if err != nil {
return nil, fmt.Errorf("failed to find IPv4 address for interface %s", iface.Name)
} }
logrus.Infof("The interface %s with ipv4 address %s will be used by flannel", iface.Name, ifaceAddr[0])
if netMode == (ipv4 + ipv6) {
ifacev6Addr, err = ip.GetInterfaceIP6Addrs(iface) ifacev6Addr, err = ip.GetInterfaceIP6Addrs(iface)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to find IPv6 address for interface %s", iface.Name) return nil, fmt.Errorf("failed to find IPv6 address for interface %s", iface.Name)
} }
logrus.Infof("Using dual-stack mode. The ipv6 address %s will be used by flannel", ifacev6Addr[0]) logrus.Infof("Using dual-stack mode. The ipv6 address %s will be used by flannel", ifacev6Addr[0])
} else { default:
ifaceAddr = append(ifaceAddr, nil)
ifacev6Addr = append(ifacev6Addr, nil) ifacev6Addr = append(ifacev6Addr, nil)
} }
if iface.MTU == 0 { if iface.MTU == 0 {
return nil, fmt.Errorf("failed to determine MTU for %s interface", iface.Name) return nil, fmt.Errorf("failed to determine MTU for %s interface", iface.Name)
} }

Loading…
Cancel
Save