Fix the dependency issue (#231)

This commit is contained in:
Robbie Zhang
2018-06-21 12:09:42 -07:00
committed by GitHub
parent 027b76651d
commit 6ec1098bb8
16629 changed files with 74837 additions and 4975021 deletions

View File

@@ -1,51 +0,0 @@
# netns - network namespaces in go #
The netns package provides an ultra-simple interface for handling
network namespaces in go. Changing namespaces requires elevated
privileges, so in most cases this code needs to be run as root.
## Local Build and Test ##
You can use go get command:
go get github.com/vishvananda/netns
Testing (requires root):
sudo -E go test github.com/vishvananda/netns
## Example ##
```go
package main
import (
"fmt"
"net"
"runtime"
"github.com/vishvananda/netns"
)
func main() {
// Lock the OS Thread so we don't accidentally switch namespaces
runtime.LockOSThread()
defer runtime.UnlockOSThread()
// Save the current network namespace
origns, _ := netns.Get()
defer origns.Close()
// Create a new network namespace
newns, _ := netns.New()
netns.Set(newns)
defer newns.Close()
// Do something with the network namespace
ifaces, _ := net.Interfaces()
fmt.Printf("Interfaces: %v\n", ifaces)
// Switch back to the original namespace
netns.Set(origns)
}
```

View File

@@ -1,66 +0,0 @@
package netns
import (
"runtime"
"sync"
"testing"
)
func TestGetNewSetDelete(t *testing.T) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
origns, err := Get()
if err != nil {
t.Fatal(err)
}
newns, err := New()
if err != nil {
t.Fatal(err)
}
if origns.Equal(newns) {
t.Fatal("New ns failed")
}
if err := Set(origns); err != nil {
t.Fatal(err)
}
newns.Close()
if newns.IsOpen() {
t.Fatal("newns still open after close", newns)
}
ns, err := Get()
if err != nil {
t.Fatal(err)
}
if !ns.Equal(origns) {
t.Fatal("Reset ns failed", origns, newns, ns)
}
}
func TestNone(t *testing.T) {
ns := None()
if ns.IsOpen() {
t.Fatal("None ns is open", ns)
}
}
func TestThreaded(t *testing.T) {
ncpu := runtime.GOMAXPROCS(-1)
if ncpu < 2 {
t.Skip("-cpu=2 or larger required")
}
// Lock this thread simply to ensure other threads get used.
runtime.LockOSThread()
defer runtime.UnlockOSThread()
wg := &sync.WaitGroup{}
for i := 0; i < ncpu; i++ {
wg.Add(1)
go func() {
defer wg.Done()
TestGetNewSetDelete(t)
}()
}
wg.Wait()
}