1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #335 from glevand/for-merge-netns

netns: Update to latest for arm64
This commit is contained in:
Jana Radhakrishnan 2015-06-26 13:14:57 -07:00
commit f621be2b30
3 changed files with 20 additions and 16 deletions

View file

@ -131,7 +131,7 @@
}, },
{ {
"ImportPath": "github.com/vishvananda/netns", "ImportPath": "github.com/vishvananda/netns",
"Rev": "5478c060110032f972e86a1f844fdb9a2f008f2c" "Rev": "b7a04d6db3dce92b370e6d5b6ab9e2361a3c53e1"
} }
] ]
} }

View file

@ -52,33 +52,30 @@ func Get() (NsHandle, error) {
return GetFromThread(os.Getpid(), syscall.Gettid()) return GetFromThread(os.Getpid(), syscall.Gettid())
} }
// GetFromName gets a handle to a named network namespace such as one // GetFromPath gets a handle to a network namespace
// created by `ip netns add`. // identified by the path
func GetFromName(name string) (NsHandle, error) { func GetFromPath(path string) (NsHandle, error) {
fd, err := syscall.Open(fmt.Sprintf("/var/run/netns/%s", name), syscall.O_RDONLY, 0) fd, err := syscall.Open(path, syscall.O_RDONLY, 0)
if err != nil { if err != nil {
return -1, err return -1, err
} }
return NsHandle(fd), nil return NsHandle(fd), nil
} }
// 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))
}
// GetFromPid gets a handle to the network namespace of a given pid. // GetFromPid gets a handle to the network namespace of a given pid.
func GetFromPid(pid int) (NsHandle, error) { func GetFromPid(pid int) (NsHandle, error) {
fd, err := syscall.Open(fmt.Sprintf("/proc/%d/ns/net", pid), syscall.O_RDONLY, 0) return GetFromPath(fmt.Sprintf("/proc/%d/ns/net", pid))
if err != nil {
return -1, err
}
return NsHandle(fd), nil
} }
// GetFromThread gets a handle to the network namespace of a given pid and tid. // GetFromThread gets a handle to the network namespace of a given pid and tid.
func GetFromThread(pid, tid int) (NsHandle, error) { func GetFromThread(pid, tid int) (NsHandle, error) {
name := fmt.Sprintf("/proc/%d/task/%d/ns/net", pid, tid) return GetFromPath(fmt.Sprintf("/proc/%d/task/%d/ns/net", pid, tid))
fd, err := syscall.Open(name, syscall.O_RDONLY, 0)
if err != nil {
return -1, err
}
return NsHandle(fd), nil
} }
// GetFromDocker gets a handle to the network namespace of a docker container. // GetFromDocker gets a handle to the network namespace of a docker container.

View file

@ -0,0 +1,7 @@
// +build linux,arm64
package netns
const (
SYS_SETNS = 268
)