Skip to content

Commit

Permalink
Rename Interface.Addresses() to Interface.Addrs()
Browse files Browse the repository at this point in the history
In order to align our transport.Interface wrapper more
closely to Go's net.Interface type.
  • Loading branch information
stv0g committed Feb 1, 2023
1 parent 818ab5f commit d668f81
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/vnet-udpproxy/README
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This example demonstrates how VNet can be used to communicate with non-VNet addresses using UDPProxy.

In this example we listen map the VNet Address `10.0.0.11` to a real address of our choice. We then
send to our real address from three different VNet Addresses.
send to our real address from three different VNet addresses.

If you pass `-address 192.168.1.3:8000` the traffic will be the following

Expand Down
4 changes: 2 additions & 2 deletions net.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ func (ifc *Interface) AddAddress(addr net.Addr) {
ifc.addrs = append(ifc.addrs, addr)
}

// Addresses returns a slice of configured addresses on the interface
func (ifc *Interface) Addresses() ([]net.Addr, error) {
// Addrs returns a slice of configured addresses on the interface
func (ifc *Interface) Addrs() ([]net.Addr, error) {
if len(ifc.addrs) == 0 {
return nil, ErrNoAddressAssigned
}
Expand Down
4 changes: 2 additions & 2 deletions stdnet/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func TestStdNet(t *testing.T) {
log.Debugf("interfaces: %+v", interfaces)
for _, ifc := range interfaces {
if ifc.Name == lo0String {
_, err := ifc.Addresses()
_, err := ifc.Addrs()
if !assert.NoError(t, err, "should succeed") {
return
}
}

if addrs, err := ifc.Addresses(); err == nil {
if addrs, err := ifc.Addrs(); err == nil {
for _, addr := range addrs {
log.Debugf("[%d] %s:%s",
ifc.Index,
Expand Down
6 changes: 3 additions & 3 deletions vnet/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (v *Net) getAllIPAddrs(ipv6 bool) []net.IP {
ips := []net.IP{}

for _, ifc := range v.interfaces {
addrs, err := ifc.Addresses()
addrs, err := ifc.Addrs()
if err != nil {
continue
}
Expand Down Expand Up @@ -403,7 +403,7 @@ func (v *Net) determineSourceIP(locIP, dstIP net.IP) net.IP {
return nil
}

addrs, err2 := ifc.Addresses()
addrs, err2 := ifc.Addrs()
if err2 != nil {
return nil
}
Expand Down Expand Up @@ -441,7 +441,7 @@ func (v *Net) determineSourceIP(locIP, dstIP net.IP) net.IP {
// caller must hold the mutex
func (v *Net) hasIPAddr(ip net.IP) bool { //nolint:gocognit
for _, ifc := range v.interfaces {
if addrs, err := ifc.Addresses(); err == nil {
if addrs, err := ifc.Addrs(); err == nil {
for _, addr := range addrs {
var locIP net.IP
if ipNet, ok := addr.(*net.IPNet); ok {
Expand Down
12 changes: 6 additions & 6 deletions vnet/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestNetVirtual(t *testing.T) {
ifc.Flags,
"Flags mismatch")

addrs, err := ifc.Addresses()
addrs, err := ifc.Addrs()
assert.NoError(t, err, "should succeed")
assert.Equal(t, 1, len(addrs), "should be one address")
case "eth0":
Expand All @@ -50,13 +50,13 @@ func TestNetVirtual(t *testing.T) {
ifc.Flags,
"Flags mismatch")

_, err := ifc.Addresses()
_, err := ifc.Addrs()
assert.NotNil(t, err, "should fail")
default:
assert.Fail(t, "unknown tnet.Interface: %v", ifc.Name)
}

if addrs, err := ifc.Addresses(); err == nil {
if addrs, err := ifc.Addrs(); err == nil {
for _, addr := range addrs {
log.Debugf("[%d] %s:%s",
ifc.Index,
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestNetVirtual(t *testing.T) {
ifc.Flags,
"Flags mismatch")

addrs, err2 := ifc.Addresses()
addrs, err2 := ifc.Addrs()
assert.NoError(t, err2, "should succeed")
assert.Equal(t, 1, len(addrs), "should be one address")
}
Expand All @@ -108,7 +108,7 @@ func TestNetVirtual(t *testing.T) {
ifc.Flags,
"Flags mismatch")

_, err = ifc.Addresses()
_, err = ifc.Addrs()
assert.NotNil(t, err, "should fail")

_, err = nw.InterfaceByName("foo0")
Expand All @@ -134,7 +134,7 @@ func TestNetVirtual(t *testing.T) {
Mask: net.CIDRMask(24, 32),
})

_, err = ifc.Addresses()
_, err = ifc.Addrs()
assert.NoError(t, err, "should succeed")

assert.True(t, nw.hasIPAddr(net.ParseIP("127.0.0.1")),
Expand Down
2 changes: 1 addition & 1 deletion vnet/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func (r *Router) setRouter(parent *Router) error {
return err
}

addrs, _ := ifc.Addresses()
addrs, _ := ifc.Addrs()
if len(addrs) == 0 {
return errNoIPAddrEth0
}
Expand Down
10 changes: 5 additions & 5 deletions vnet/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func getIPAddr(n NIC) (string, error) {
return "", err
}

addrs, err := eth0.Addresses()
addrs, err := eth0.Addrs()
if err != nil {
return "", err
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestRouterStandalone(t *testing.T) {
eth0, err := nic.getInterface("eth0")
assert.Nil(t, err, "should succeed")

addrs, err := eth0.Addresses()
addrs, err := eth0.Addrs()
assert.Nil(t, err, "should succeed")
assert.Equal(t, 1, len(addrs), "should match")
assert.Equal(t, "ip+net", addrs[0].Network(), "should match")
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestRouterStandalone(t *testing.T) {
// Now, eth0 must have one address assigned
eth0, err2 := nic[i].getInterface("eth0")
assert.Nil(t, err2, "should succeed")
addrs, err2 := eth0.Addresses()
addrs, err2 := eth0.Addrs()
assert.Nil(t, err2, "should succeed")
assert.Equal(t, 1, len(addrs), "should match")
//nolint:forcetypeassert
Expand Down Expand Up @@ -229,7 +229,7 @@ func TestRouterStandalone(t *testing.T) {
// Now, eth0 must have one address assigned
eth0, err2 := nic[i].getInterface("eth0")
assert.Nil(t, err2, "should succeed")
addrs, err2 := eth0.Addresses()
addrs, err2 := eth0.Addrs()
assert.Nil(t, err2, "should succeed")
assert.Equal(t, 1, len(addrs), "should match")
//nolint:forcetypeassert
Expand Down Expand Up @@ -332,7 +332,7 @@ func TestRouterDelay(t *testing.T) {
// Now, eth0 must have one address assigned
eth0, err2 := nic[i].getInterface("eth0")
assert.Nil(t, err2, "should succeed")
addrs, err2 := eth0.Addresses()
addrs, err2 := eth0.Addrs()
assert.Nil(t, err2, "should succeed")
assert.Equal(t, 1, len(addrs), "should match")
//nolint:forcetypeassert
Expand Down
2 changes: 1 addition & 1 deletion vnet/stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestStressTestUDP(t *testing.T) {
continue
}

addrs, err2 := ifc.Addresses()
addrs, err2 := ifc.Addrs()
if !assert.NoError(t, err2, "should succeed") {
return
}
Expand Down

0 comments on commit d668f81

Please sign in to comment.