It's more transparent for the caller to handle conversion.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -65,18 +65,13 @@ func ResetHandles() {
|
| 65 | 65 |
} |
| 66 | 66 |
} |
| 67 | 67 |
|
| 68 |
-// ParseHandlerInt transforms the namespace handler into an integer |
|
| 69 |
-func ParseHandlerInt() int {
|
|
| 70 |
- return int(getHandler()) |
|
| 71 |
-} |
|
| 72 |
- |
|
| 73 |
-// GetHandler returns the namespace handler |
|
| 74 |
-func getHandler() netns.NsHandle {
|
|
| 68 |
+// NsHandle returns the network namespace handle for the initial (host) namespace. |
|
| 69 |
+func NsHandle() netns.NsHandle {
|
|
| 75 | 70 |
ns, _ := initNamespace() |
| 76 | 71 |
return ns |
| 77 | 72 |
} |
| 78 | 73 |
|
| 79 |
-// NlHandle returns the netlink handler |
|
| 74 |
+// NlHandle returns the netlink handle. |
|
| 80 | 75 |
func NlHandle() nlwrap.Handle {
|
| 81 | 76 |
_, nl := initNamespace() |
| 82 | 77 |
return nl |
| ... | ... |
@@ -262,7 +262,7 @@ func (n *Namespace) AddInterface(ctx context.Context, srcName, dstPrefix, dstNam |
| 262 | 262 |
if nerr := n.nlHandle.LinkSetName(iface, i.SrcName()); nerr != nil {
|
| 263 | 263 |
log.G(ctx).Errorf("renaming interface (%s->%s) failed, %v after config error %v", i.DstName(), i.SrcName(), nerr, err)
|
| 264 | 264 |
} |
| 265 |
- if nerr := n.nlHandle.LinkSetNsFd(iface, ns.ParseHandlerInt()); nerr != nil {
|
|
| 265 |
+ if nerr := n.nlHandle.LinkSetNsFd(iface, int(ns.NsHandle())); nerr != nil {
|
|
| 266 | 266 |
log.G(ctx).Errorf("moving interface %s to host ns failed, %v, after config error %v", i.SrcName(), nerr, err)
|
| 267 | 267 |
} |
| 268 | 268 |
return err |
| ... | ... |
@@ -845,8 +845,9 @@ func (n *Namespace) RemoveInterface(i *Interface) error {
|
| 845 | 845 |
} |
| 846 | 846 |
} else if !n.isDefault {
|
| 847 | 847 |
// Move the network interface to caller namespace. |
| 848 |
+ // |
|
| 848 | 849 |
// 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 |
| 849 |
- if err := n.nlHandle.LinkSetNsFd(iface, ns.ParseHandlerInt()); err != nil {
|
|
| 850 |
+ if err := n.nlHandle.LinkSetNsFd(iface, int(ns.NsHandle())); err != nil {
|
|
| 850 | 851 |
log.G(context.TODO()).Debugf("LinkSetNsFd failed for interface %s: %v", i.SrcName(), err)
|
| 851 | 852 |
return err |
| 852 | 853 |
} |