refactor: inline

This eliminates the unnecessary indirection via interface names,
instead identifying the interface by its index.
This commit is contained in:
Matthias Radestock committed 2016-01-19 16:36:16 +00:00
1 parent 0caa9dd652
commit b5256f7b71
2 files changed
+16 -17

No files matched your search

+16 -6
View File
@@ -52,15 +52,25 @@ func EnsureInterfaceAndMcastRoute(ifaceName string) (*net.Interface, error) {
return nil, err
}
dest := net.IPv4(224, 0, 0, 0)
// check for currently-existing route after subscribing, to avoid race
if CheckRouteExists(ifaceName, dest) {
return iface, err
check := func(route netlink.Route) bool {
return route.LinkIndex == iface.Index && route.Dst.IP.Equal(dest)
}
for update := range ch {
if update.Route.LinkIndex == iface.Index && update.Route.Dst.IP.Equal(dest) {
break
// check for currently-existing route after subscribing, to avoid race
routes, err := netlink.RouteList(nil, netlink.FAMILY_V4)
if err != nil {
return nil, err
}
for _, route := range routes {
if check(route) {
return iface, nil
}
}
for update := range ch {
if check(update.Route) {
return iface, nil
}
}
// should never get here
return iface, nil
}
-11
View File
@@ -54,14 +54,3 @@ func forEachRoute(ignoreIfaceNames map[string]struct{}, check func(name string,
}
return nil
}
func CheckRouteExists(ifaceName string, dest net.IP) bool {
found := false
forEachRoute(map[string]struct{}{}, func(name string, route netlink.Route) error {
if name == ifaceName && route.Dst.IP.Equal(dest) {
found = true
}
return nil
})
return found
}