Incorporate with reviewer's comments
This commit is contained in:
parent
8c52f50849
commit
7924ef76da
@ -51,20 +51,23 @@ func init() {
|
|||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultRouteInterfaceName() string {
|
func getDefaultRouteInterfaceName() (string, error) {
|
||||||
routeToDstIP, err := netlink.RouteList(nil, netlink.FAMILY_ALL)
|
routeToDstIP, err := netlink.RouteList(nil, netlink.FAMILY_ALL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range routeToDstIP {
|
for _, v := range routeToDstIP {
|
||||||
l, _ := netlink.LinkByIndex(v.LinkIndex)
|
|
||||||
if v.Dst == nil {
|
if v.Dst == nil {
|
||||||
return l.Attrs().Name
|
l, err := netlink.LinkByIndex(v.LinkIndex)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return l.Attrs().Name, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return "", fmt.Errorf("no default route interface found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConf(bytes []byte) (*NetConf, string, error) {
|
func loadConf(bytes []byte) (*NetConf, string, error) {
|
||||||
@ -73,9 +76,9 @@ func loadConf(bytes []byte) (*NetConf, string, error) {
|
|||||||
return nil, "", fmt.Errorf("failed to load netconf: %v", err)
|
return nil, "", fmt.Errorf("failed to load netconf: %v", err)
|
||||||
}
|
}
|
||||||
if n.Master == "" {
|
if n.Master == "" {
|
||||||
defaultRouteInterface := getDefaultRouteInterfaceName()
|
defaultRouteInterface, err := getDefaultRouteInterfaceName()
|
||||||
if defaultRouteInterface == "" {
|
if err != nil {
|
||||||
return nil, "", fmt.Errorf(`cannot get default route interface for master`)
|
return nil, "", err
|
||||||
}
|
}
|
||||||
n.Master = defaultRouteInterface
|
n.Master = defaultRouteInterface
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user