Refactor common.GetBridgeNetDev

- Optimize. Use LinkByName instead of iterating over list of available
  links. Linux does not support interfaces with the same names.
- Remove unnecessary indirection in utility functions which return
  common.NetDev.
This commit is contained in:
Martynas Pumputis committed 2016-07-05 15:12:39 +01:00
1 parent e5c23bf9f5
commit 05baa566c6
6 files changed
+40 -19

No files matched your search

+10
View File
@@ -35,3 +35,13 @@ func WithNetNSLink(ns netns.NsHandle, ifName string, work func(link netlink.Link
return work(link)
})
}
func WithNetNSLinkByPid(pid int, ifName string, work func(link netlink.Link) error) error {
ns, err := netns.GetFromPid(pid)
if err != nil {
return err
}
defer ns.Close()
return WithNetNSLink(ns, ifName, work)
}