Use link ParentIndex where available

This commit is contained in:
Bryan Boreham committed 2016-03-17 18:20:18 +00:00
1 parent b153e6a0d2
commit a66543f98e
1 file changed
+8 -3
+8 -3
View File
@@ -117,7 +117,13 @@ func GetWeaveNetDevs(processID int) ([]NetDev, error) {
indexes := make(map[int]struct{})
err = forEachLink(func(link netlink.Link) error {
if link.Attrs().MasterIndex == weaveBridge.Attrs().Index {
indexes[link.Attrs().Index] = struct{}{}
peerIndex := link.Attrs().ParentIndex
if peerIndex == 0 {
// perhaps running on an older kernel where ParentIndex doesn't work.
// as fall-back, assume the indexes are consecutive
peerIndex = link.Attrs().Index - 1
}
indexes[peerIndex] = struct{}{}
}
return nil
})
@@ -125,9 +131,8 @@ func GetWeaveNetDevs(processID int) ([]NetDev, error) {
return nil, err
}
return FindNetDevs(processID, func(link netlink.Link) bool {
// For checking, rely on index number of veth end inside namespace being -1 of end outside
_, isveth := link.(*netlink.Veth)
_, found := indexes[link.Attrs().Index+1]
_, found := indexes[link.Attrs().Index]
return isveth && found
})
}