go.mod: bump all deps
Bump all transitive and direct dependencies. Signed-off-by: Casey Callendrello <c1@caseyc.net>
This commit is contained in:
2
vendor/github.com/vishvananda/netns/.golangci.yml
generated
vendored
Normal file
2
vendor/github.com/vishvananda/netns/.golangci.yml
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
run:
|
||||
timeout: 5m
|
12
vendor/github.com/vishvananda/netns/README.md
generated
vendored
12
vendor/github.com/vishvananda/netns/README.md
generated
vendored
@ -23,6 +23,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
|
||||
"github.com/vishvananda/netns"
|
||||
)
|
||||
|
||||
@ -48,14 +49,3 @@ func main() {
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## NOTE
|
||||
|
||||
The library can be safely used only with Go >= 1.10 due to [golang/go#20676](https://github.com/golang/go/issues/20676).
|
||||
|
||||
After locking a goroutine to its current OS thread with `runtime.LockOSThread()`
|
||||
and changing its network namespace, any new subsequent goroutine won't be
|
||||
scheduled on that thread while it's locked. Therefore, the new goroutine
|
||||
will run in a different namespace leading to unexpected results.
|
||||
|
||||
See [here](https://www.weave.works/blog/linux-namespaces-golang-followup) for more details.
|
||||
|
9
vendor/github.com/vishvananda/netns/doc.go
generated
vendored
Normal file
9
vendor/github.com/vishvananda/netns/doc.go
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// Package netns allows ultra-simple network namespace handling. NsHandles
|
||||
// can be retrieved and set. Note that the current namespace is thread
|
||||
// local so actions that set and reset namespaces should use LockOSThread
|
||||
// to make sure the namespace doesn't change due to a goroutine switch.
|
||||
// It is best to close NsHandles when you are done with them. This can be
|
||||
// accomplished via a `defer ns.Close()` on the handle. Changing namespaces
|
||||
// requires elevated privileges, so in most cases this code needs to be run
|
||||
// as root.
|
||||
package netns
|
111
vendor/github.com/vishvananda/netns/netns_linux.go
generated
vendored
111
vendor/github.com/vishvananda/netns/netns_linux.go
generated
vendored
@ -1,33 +1,31 @@
|
||||
// +build linux,go1.10
|
||||
|
||||
package netns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// Deprecated: use syscall pkg instead (go >= 1.5 needed).
|
||||
// Deprecated: use golang.org/x/sys/unix pkg instead.
|
||||
const (
|
||||
CLONE_NEWUTS = 0x04000000 /* New utsname group? */
|
||||
CLONE_NEWIPC = 0x08000000 /* New ipcs */
|
||||
CLONE_NEWUSER = 0x10000000 /* New user namespace */
|
||||
CLONE_NEWPID = 0x20000000 /* New pid namespace */
|
||||
CLONE_NEWNET = 0x40000000 /* New network namespace */
|
||||
CLONE_IO = 0x80000000 /* Get io context */
|
||||
bindMountPath = "/run/netns" /* Bind mount path for named netns */
|
||||
CLONE_NEWUTS = unix.CLONE_NEWUTS /* New utsname group? */
|
||||
CLONE_NEWIPC = unix.CLONE_NEWIPC /* New ipcs */
|
||||
CLONE_NEWUSER = unix.CLONE_NEWUSER /* New user namespace */
|
||||
CLONE_NEWPID = unix.CLONE_NEWPID /* New pid namespace */
|
||||
CLONE_NEWNET = unix.CLONE_NEWNET /* New network namespace */
|
||||
CLONE_IO = unix.CLONE_IO /* Get io context */
|
||||
)
|
||||
|
||||
// Setns sets namespace using syscall. Note that this should be a method
|
||||
// in syscall but it has not been added.
|
||||
const bindMountPath = "/run/netns" /* Bind mount path for named netns */
|
||||
|
||||
// Setns sets namespace using golang.org/x/sys/unix.Setns.
|
||||
//
|
||||
// Deprecated: Use golang.org/x/sys/unix.Setns instead.
|
||||
func Setns(ns NsHandle, nstype int) (err error) {
|
||||
return unix.Setns(int(ns), nstype)
|
||||
}
|
||||
@ -35,19 +33,20 @@ func Setns(ns NsHandle, nstype int) (err error) {
|
||||
// Set sets the current network namespace to the namespace represented
|
||||
// by NsHandle.
|
||||
func Set(ns NsHandle) (err error) {
|
||||
return Setns(ns, CLONE_NEWNET)
|
||||
return unix.Setns(int(ns), unix.CLONE_NEWNET)
|
||||
}
|
||||
|
||||
// New creates a new network namespace, sets it as current and returns
|
||||
// a handle to it.
|
||||
func New() (ns NsHandle, err error) {
|
||||
if err := unix.Unshare(CLONE_NEWNET); err != nil {
|
||||
if err := unix.Unshare(unix.CLONE_NEWNET); err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return Get()
|
||||
}
|
||||
|
||||
// NewNamed creates a new named network namespace and returns a handle to it
|
||||
// NewNamed creates a new named network namespace, sets it as current,
|
||||
// and returns a handle to it
|
||||
func NewNamed(name string) (NsHandle, error) {
|
||||
if _, err := os.Stat(bindMountPath); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(bindMountPath, 0755)
|
||||
@ -65,13 +64,15 @@ func NewNamed(name string) (NsHandle, error) {
|
||||
|
||||
f, err := os.OpenFile(namedPath, os.O_CREATE|os.O_EXCL, 0444)
|
||||
if err != nil {
|
||||
newNs.Close()
|
||||
return None(), err
|
||||
}
|
||||
f.Close()
|
||||
|
||||
nsPath := fmt.Sprintf("/proc/%d/task/%d/ns/net", os.Getpid(), syscall.Gettid())
|
||||
err = syscall.Mount(nsPath, namedPath, "bind", syscall.MS_BIND, "")
|
||||
nsPath := fmt.Sprintf("/proc/%d/task/%d/ns/net", os.Getpid(), unix.Gettid())
|
||||
err = unix.Mount(nsPath, namedPath, "bind", unix.MS_BIND, "")
|
||||
if err != nil {
|
||||
newNs.Close()
|
||||
return None(), err
|
||||
}
|
||||
|
||||
@ -82,7 +83,7 @@ func NewNamed(name string) (NsHandle, error) {
|
||||
func DeleteNamed(name string) error {
|
||||
namedPath := path.Join(bindMountPath, name)
|
||||
|
||||
err := syscall.Unmount(namedPath, syscall.MNT_DETACH)
|
||||
err := unix.Unmount(namedPath, unix.MNT_DETACH)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -108,7 +109,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.
|
||||
@ -133,33 +134,38 @@ func GetFromDocker(id string) (NsHandle, error) {
|
||||
}
|
||||
|
||||
// borrowed from docker/utils/utils.go
|
||||
func findCgroupMountpoint(cgroupType string) (string, error) {
|
||||
output, err := ioutil.ReadFile("/proc/mounts")
|
||||
func findCgroupMountpoint(cgroupType string) (int, string, error) {
|
||||
output, err := os.ReadFile("/proc/mounts")
|
||||
if err != nil {
|
||||
return "", err
|
||||
return -1, "", err
|
||||
}
|
||||
|
||||
// /proc/mounts has 6 fields per line, one mount per line, e.g.
|
||||
// cgroup /sys/fs/cgroup/devices cgroup rw,relatime,devices 0 0
|
||||
for _, line := range strings.Split(string(output), "\n") {
|
||||
parts := strings.Split(line, " ")
|
||||
if len(parts) == 6 && parts[2] == "cgroup" {
|
||||
for _, opt := range strings.Split(parts[3], ",") {
|
||||
if opt == cgroupType {
|
||||
return parts[1], nil
|
||||
if len(parts) == 6 {
|
||||
switch parts[2] {
|
||||
case "cgroup2":
|
||||
return 2, parts[1], nil
|
||||
case "cgroup":
|
||||
for _, opt := range strings.Split(parts[3], ",") {
|
||||
if opt == cgroupType {
|
||||
return 1, parts[1], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("cgroup mountpoint not found for %s", cgroupType)
|
||||
return -1, "", fmt.Errorf("cgroup mountpoint not found for %s", cgroupType)
|
||||
}
|
||||
|
||||
// Returns the relative path to the cgroup docker is running in.
|
||||
// borrowed from docker/utils/utils.go
|
||||
// modified to get the docker pid instead of using /proc/self
|
||||
func getThisCgroup(cgroupType string) (string, error) {
|
||||
dockerpid, err := ioutil.ReadFile("/var/run/docker.pid")
|
||||
func getDockerCgroup(cgroupVer int, cgroupType string) (string, error) {
|
||||
dockerpid, err := os.ReadFile("/var/run/docker.pid")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -171,14 +177,15 @@ func getThisCgroup(cgroupType string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
output, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cgroup", pid))
|
||||
output, err := os.ReadFile(fmt.Sprintf("/proc/%d/cgroup", pid))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, line := range strings.Split(string(output), "\n") {
|
||||
parts := strings.Split(line, ":")
|
||||
// any type used by docker should work
|
||||
if parts[1] == cgroupType {
|
||||
if (cgroupVer == 1 && parts[1] == cgroupType) ||
|
||||
(cgroupVer == 2 && parts[1] == "") {
|
||||
return parts[2], nil
|
||||
}
|
||||
}
|
||||
@ -190,46 +197,56 @@ func getThisCgroup(cgroupType string) (string, error) {
|
||||
// modified to only return the first pid
|
||||
// modified to glob with id
|
||||
// modified to search for newer docker containers
|
||||
// modified to look for cgroups v2
|
||||
func getPidForContainer(id string) (int, error) {
|
||||
pid := 0
|
||||
|
||||
// memory is chosen randomly, any cgroup used by docker works
|
||||
cgroupType := "memory"
|
||||
|
||||
cgroupRoot, err := findCgroupMountpoint(cgroupType)
|
||||
cgroupVer, cgroupRoot, err := findCgroupMountpoint(cgroupType)
|
||||
if err != nil {
|
||||
return pid, err
|
||||
}
|
||||
|
||||
cgroupThis, err := getThisCgroup(cgroupType)
|
||||
cgroupDocker, err := getDockerCgroup(cgroupVer, cgroupType)
|
||||
if err != nil {
|
||||
return pid, err
|
||||
}
|
||||
|
||||
id += "*"
|
||||
|
||||
var pidFile string
|
||||
if cgroupVer == 1 {
|
||||
pidFile = "tasks"
|
||||
} else if cgroupVer == 2 {
|
||||
pidFile = "cgroup.procs"
|
||||
} else {
|
||||
return -1, fmt.Errorf("Invalid cgroup version '%d'", cgroupVer)
|
||||
}
|
||||
|
||||
attempts := []string{
|
||||
filepath.Join(cgroupRoot, cgroupThis, id, "tasks"),
|
||||
filepath.Join(cgroupRoot, cgroupDocker, id, pidFile),
|
||||
// With more recent lxc versions use, cgroup will be in lxc/
|
||||
filepath.Join(cgroupRoot, cgroupThis, "lxc", id, "tasks"),
|
||||
filepath.Join(cgroupRoot, cgroupDocker, "lxc", id, pidFile),
|
||||
// With more recent docker, cgroup will be in docker/
|
||||
filepath.Join(cgroupRoot, cgroupThis, "docker", id, "tasks"),
|
||||
filepath.Join(cgroupRoot, cgroupDocker, "docker", id, pidFile),
|
||||
// Even more recent docker versions under systemd use docker-<id>.scope/
|
||||
filepath.Join(cgroupRoot, "system.slice", "docker-"+id+".scope", "tasks"),
|
||||
filepath.Join(cgroupRoot, "system.slice", "docker-"+id+".scope", pidFile),
|
||||
// Even more recent docker versions under cgroup/systemd/docker/<id>/
|
||||
filepath.Join(cgroupRoot, "..", "systemd", "docker", id, "tasks"),
|
||||
filepath.Join(cgroupRoot, "..", "systemd", "docker", id, pidFile),
|
||||
// Kubernetes with docker and CNI is even more different. Works for BestEffort and Burstable QoS
|
||||
filepath.Join(cgroupRoot, "..", "systemd", "kubepods", "*", "pod*", id, "tasks"),
|
||||
filepath.Join(cgroupRoot, "..", "systemd", "kubepods", "*", "pod*", id, pidFile),
|
||||
// Same as above but for Guaranteed QoS
|
||||
filepath.Join(cgroupRoot, "..", "systemd", "kubepods", "pod*", id, "tasks"),
|
||||
filepath.Join(cgroupRoot, "..", "systemd", "kubepods", "pod*", id, pidFile),
|
||||
// Another flavor of containers location in recent kubernetes 1.11+. Works for BestEffort and Burstable QoS
|
||||
filepath.Join(cgroupRoot, cgroupThis, "kubepods.slice", "*.slice", "*", "docker-"+id+".scope", "tasks"),
|
||||
filepath.Join(cgroupRoot, cgroupDocker, "kubepods.slice", "*.slice", "*", "docker-"+id+".scope", pidFile),
|
||||
// Same as above but for Guaranteed QoS
|
||||
filepath.Join(cgroupRoot, cgroupThis, "kubepods.slice", "*", "docker-"+id+".scope", "tasks"),
|
||||
filepath.Join(cgroupRoot, cgroupDocker, "kubepods.slice", "*", "docker-"+id+".scope", pidFile),
|
||||
// When runs inside of a container with recent kubernetes 1.11+. Works for BestEffort and Burstable QoS
|
||||
filepath.Join(cgroupRoot, "kubepods.slice", "*.slice", "*", "docker-"+id+".scope", "tasks"),
|
||||
filepath.Join(cgroupRoot, "kubepods.slice", "*.slice", "*", "docker-"+id+".scope", pidFile),
|
||||
// Same as above but for Guaranteed QoS
|
||||
filepath.Join(cgroupRoot, "kubepods.slice", "*", "docker-"+id+".scope", "tasks"),
|
||||
filepath.Join(cgroupRoot, "kubepods.slice", "*", "docker-"+id+".scope", pidFile),
|
||||
}
|
||||
|
||||
var filename string
|
||||
@ -247,7 +264,7 @@ func getPidForContainer(id string) (int, error) {
|
||||
return pid, fmt.Errorf("Unable to find container: %v", id[:len(id)-1])
|
||||
}
|
||||
|
||||
output, err := ioutil.ReadFile(filename)
|
||||
output, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return pid, err
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
//go:build !linux
|
||||
// +build !linux
|
||||
|
||||
package netns
|
||||
@ -10,6 +11,14 @@ var (
|
||||
ErrNotImplemented = errors.New("not implemented")
|
||||
)
|
||||
|
||||
// Setns sets namespace using golang.org/x/sys/unix.Setns on Linux. It
|
||||
// is not implemented on other platforms.
|
||||
//
|
||||
// Deprecated: Use golang.org/x/sys/unix.Setns instead.
|
||||
func Setns(ns NsHandle, nstype int) (err error) {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
func Set(ns NsHandle) (err error) {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
@ -18,6 +27,14 @@ func New() (ns NsHandle, err error) {
|
||||
return -1, ErrNotImplemented
|
||||
}
|
||||
|
||||
func NewNamed(name string) (NsHandle, error) {
|
||||
return -1, ErrNotImplemented
|
||||
}
|
||||
|
||||
func DeleteNamed(name string) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
func Get() (NsHandle, error) {
|
||||
return -1, ErrNotImplemented
|
||||
}
|
@ -1,11 +1,3 @@
|
||||
// Package netns allows ultra-simple network namespace handling. NsHandles
|
||||
// can be retrieved and set. Note that the current namespace is thread
|
||||
// local so actions that set and reset namespaces should use LockOSThread
|
||||
// to make sure the namespace doesn't change due to a goroutine switch.
|
||||
// It is best to close NsHandles when you are done with them. This can be
|
||||
// accomplished via a `defer ns.Close()` on the handle. Changing namespaces
|
||||
// requires elevated privileges, so in most cases this code needs to be run
|
||||
// as root.
|
||||
package netns
|
||||
|
||||
import (
|
||||
@ -38,7 +30,7 @@ func (ns NsHandle) Equal(other NsHandle) bool {
|
||||
// String shows the file descriptor number and its dev and inode.
|
||||
func (ns NsHandle) String() string {
|
||||
if ns == -1 {
|
||||
return "NS(None)"
|
||||
return "NS(none)"
|
||||
}
|
||||
var s unix.Stat_t
|
||||
if err := unix.Fstat(int(ns), &s); err != nil {
|
||||
@ -71,7 +63,7 @@ func (ns *NsHandle) Close() error {
|
||||
if err := unix.Close(int(*ns)); err != nil {
|
||||
return err
|
||||
}
|
||||
(*ns) = -1
|
||||
*ns = -1
|
||||
return nil
|
||||
}
|
||||
|
45
vendor/github.com/vishvananda/netns/nshandle_others.go
generated
vendored
Normal file
45
vendor/github.com/vishvananda/netns/nshandle_others.go
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
//go:build !linux
|
||||
// +build !linux
|
||||
|
||||
package netns
|
||||
|
||||
// NsHandle is a handle to a network namespace. It can only be used on Linux,
|
||||
// but provides stub methods on other platforms.
|
||||
type NsHandle int
|
||||
|
||||
// Equal determines if two network handles refer to the same network
|
||||
// namespace. It is only implemented on Linux.
|
||||
func (ns NsHandle) Equal(_ NsHandle) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// String shows the file descriptor number and its dev and inode.
|
||||
// It is only implemented on Linux, and returns "NS(none)" on other
|
||||
// platforms.
|
||||
func (ns NsHandle) String() string {
|
||||
return "NS(none)"
|
||||
}
|
||||
|
||||
// UniqueId returns a string which uniquely identifies the namespace
|
||||
// associated with the network handle. It is only implemented on Linux,
|
||||
// and returns "NS(none)" on other platforms.
|
||||
func (ns NsHandle) UniqueId() string {
|
||||
return "NS(none)"
|
||||
}
|
||||
|
||||
// IsOpen returns true if Close() has not been called. It is only implemented
|
||||
// on Linux and always returns false on other platforms.
|
||||
func (ns NsHandle) IsOpen() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Close closes the NsHandle and resets its file descriptor to -1.
|
||||
// It is only implemented on Linux.
|
||||
func (ns *NsHandle) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// None gets an empty (closed) NsHandle.
|
||||
func None() NsHandle {
|
||||
return NsHandle(-1)
|
||||
}
|
Reference in New Issue
Block a user