GetFromName: use /run/netns instead of /var/run/netns

The GetFromName() function looked for network namespaces in "/var/run",
whereas DeleteNamed() and NewNamed() used the "bindMountPath" const (which
points to "/run/netns"). While "/var/run" should be symlink to "/run" on
most distros, this is not a guarantee, so use the same paths so that at
least the code is consistently using this path.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-01-13 17:02:52 +01:00 committed by Jeff Widman
parent e6c3e222e7
commit a21f45a794

View File

@ -108,7 +108,7 @@ func GetFromPath(path string) (NsHandle, error) {
// GetFromName gets a handle to a named network namespace such as one
// created by `ip netns add`.
func GetFromName(name string) (NsHandle, error) {
return GetFromPath(fmt.Sprintf("/var/run/netns/%s", name))
return GetFromPath(filepath.Join(bindMountPath, name))
}
// GetFromPid gets a handle to the network namespace of a given pid.