Path: xname,
Args: []string{"ip", "link", "add", ti.name, "type", "dummy"},
})
+ ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
+ Path: xname,
+ Args: []string{"ip", "address", "add", ti.local, "peer", ti.remote, "dev", ti.name},
+ })
+ ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
+ Path: xname,
+ Args: []string{"ip", "address", "del", ti.local, "peer", ti.remote, "dev", ti.name},
+ })
ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
Path: xname,
Args: []string{"ip", "link", "delete", ti.name, "type", "dummy"},
return nil
}
-func (ti *testInterface) setPointToPoint(suffix int, local, remote string) error {
+func (ti *testInterface) setPointToPoint(suffix int) error {
ti.name = fmt.Sprintf("gotest%d", suffix)
- ti.local = local
- ti.remote = remote
xname, err := exec.LookPath("ip")
if err != nil {
return err
}
ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
Path: xname,
- Args: []string{"ip", "tunnel", "add", ti.name, "mode", "gre", "local", local, "remote", remote},
+ Args: []string{"ip", "tunnel", "add", ti.name, "mode", "gre", "local", ti.local, "remote", ti.remote},
+ })
+ ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
+ Path: xname,
+ Args: []string{"ip", "address", "add", ti.local, "peer", ti.remote, "dev", ti.name},
})
ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
Path: xname,
- Args: []string{"ip", "tunnel", "del", ti.name, "mode", "gre", "local", local, "remote", remote},
+ Args: []string{"ip", "address", "del", ti.local, "peer", ti.remote, "dev", ti.name},
})
- xname, err = exec.LookPath("ifconfig")
- if err != nil {
- return err
- }
- ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
+ ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{
Path: xname,
- Args: []string{"ifconfig", ti.name, "inet", local, "dstaddr", remote},
+ Args: []string{"ip", "tunnel", "del", ti.name, "mode", "gre", "local", ti.local, "remote", ti.remote},
})
return nil
}
local, remote := "169.254.0.1", "169.254.0.254"
ip := ParseIP(remote)
for i := 0; i < 3; i++ {
- ti := &testInterface{}
- if err := ti.setPointToPoint(5963+i, local, remote); err != nil {
+ ti := &testInterface{local: local, remote: remote}
+ if err := ti.setPointToPoint(5963 + i); err != nil {
t.Skipf("test requries external command: %v", err)
}
if err := ti.setup(); err != nil {
t.Fatal(err)
}
for _, ifi := range ift {
- if ti.name == ifi.Name {
- ifat, err := ifi.Addrs()
- if err != nil {
+ if ti.name != ifi.Name {
+ continue
+ }
+ ifat, err := ifi.Addrs()
+ if err != nil {
+ ti.teardown()
+ t.Fatal(err)
+ }
+ for _, ifa := range ifat {
+ if ip.Equal(ifa.(*IPNet).IP) {
ti.teardown()
- t.Fatal(err)
- }
- for _, ifa := range ifat {
- if ip.Equal(ifa.(*IPNet).IP) {
- ti.teardown()
- t.Fatalf("got %v; want %v", ip, local)
- }
+ t.Fatalf("got %v", ifa)
}
}
}
t.Skip("must be root")
}
+ local, remote := "169.254.0.1", "169.254.0.254"
+ ip := ParseIP(remote)
for i := 0; i < 3; i++ {
ift1, err := Interfaces()
if err != nil {
t.Fatal(err)
}
- ti := &testInterface{}
+ ti := &testInterface{local: local, remote: remote}
if err := ti.setBroadcast(5682 + i); err != nil {
t.Skipf("test requires external command: %v", err)
}
ti.teardown()
t.Fatalf("got %v; want gt %v", len(ift2), len(ift1))
}
+ for _, ifi := range ift2 {
+ if ti.name != ifi.Name {
+ continue
+ }
+ ifat, err := ifi.Addrs()
+ if err != nil {
+ ti.teardown()
+ t.Fatal(err)
+ }
+ for _, ifa := range ifat {
+ if ip.Equal(ifa.(*IPNet).IP) {
+ ti.teardown()
+ t.Fatalf("got %v", ifa)
+ }
+ }
+ }
if err := ti.teardown(); err != nil {
t.Fatal(err)
} else {