daemon/libnetwork/ns: remove ParseHandlerInt, add NsHandle

It's more transparent for the caller to handle conversion.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2026-03-29 16:45:31 +02:00
parent af73684bc3
commit 5378f5427f
2 changed files with 6 additions and 10 deletions

View File

@@ -65,18 +65,13 @@ func ResetHandles() {
}
}
// ParseHandlerInt transforms the namespace handler into an integer
func ParseHandlerInt() int {
return int(getHandler())
}
// GetHandler returns the namespace handler
func getHandler() netns.NsHandle {
// NsHandle returns the network namespace handle for the initial (host) namespace.
func NsHandle() netns.NsHandle {
ns, _ := initNamespace()
return ns
}
// NlHandle returns the netlink handler
// NlHandle returns the netlink handle.
func NlHandle() nlwrap.Handle {
_, nl := initNamespace()
return nl

View File

@@ -262,7 +262,7 @@ func (n *Namespace) AddInterface(ctx context.Context, srcName, dstPrefix, dstNam
if nerr := n.nlHandle.LinkSetName(iface, i.SrcName()); nerr != nil {
log.G(ctx).Errorf("renaming interface (%s->%s) failed, %v after config error %v", i.DstName(), i.SrcName(), nerr, err)
}
if nerr := n.nlHandle.LinkSetNsFd(iface, ns.ParseHandlerInt()); nerr != nil {
if nerr := n.nlHandle.LinkSetNsFd(iface, int(ns.NsHandle())); nerr != nil {
log.G(ctx).Errorf("moving interface %s to host ns failed, %v, after config error %v", i.SrcName(), nerr, err)
}
return err
@@ -845,8 +845,9 @@ func (n *Namespace) RemoveInterface(i *Interface) error {
}
} else if !n.isDefault {
// Move the network interface to caller namespace.
//
// TODO(aker): What's this really doing? There are no calls to LinkDel in this package: is this code really used? (Interface.Remove() has 3 callers); see https://github.com/moby/moby/pull/46315/commits/108595c2fe852a5264b78e96f9e63cda284990a6#r1331265335
if err := n.nlHandle.LinkSetNsFd(iface, ns.ParseHandlerInt()); err != nil {
if err := n.nlHandle.LinkSetNsFd(iface, int(ns.NsHandle())); err != nil {
log.G(context.TODO()).Debugf("LinkSetNsFd failed for interface %s: %v", i.SrcName(), err)
return err
}