disable lock when no namespace is needed (#95)

Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
This commit is contained in:
Serguei Bezverkhi 2020-01-22 16:39:39 -05:00 committed by Michael Stapelberg
parent 327d5c62cd
commit 26bcabf490
1 changed files with 8 additions and 1 deletions

View File

@ -88,7 +88,14 @@ func (cc *Conn) dialNetlink() (*netlink.Conn, error) {
if cc.TestDial != nil {
return nltest.Dial(cc.TestDial), nil
}
return netlink.Dial(unix.NETLINK_NETFILTER, &netlink.Config{NetNS: cc.NetNS})
disableNSLockThread := false
if cc.NetNS == 0 {
// Since process is operating in main namespace, there is no reason to have NSLockThread lock,
// as it causes some performance penalties.
disableNSLockThread = true
}
return netlink.Dial(unix.NETLINK_NETFILTER, &netlink.Config{NetNS: cc.NetNS, DisableNSLockThread: disableNSLockThread})
}
func (cc *Conn) setErr(err error) {