Change tcpip.Route.Mask to tcpip.AddressMask.

PiperOrigin-RevId: 214975659
Change-Id: I7bd31a2c54f03ff52203109da312e4206701c44c
This commit is contained in:
Googler
2018-09-28 12:18:15 -07:00
committed by Shentubot
parent e22c4cba47
commit fb65b0b471
7 changed files with 15 additions and 9 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ func createStack(t *testing.T) *stack.Stack {
s.SetRouteTable([]tcpip.Route{{
Destination: tcpip.Address(strings.Repeat("\x00", 4)),
Mask: tcpip.Address(strings.Repeat("\x00", 4)),
Mask: tcpip.AddressMask(strings.Repeat("\x00", 4)),
Gateway: "",
NIC: nicid,
}})
+2 -2
View File
@@ -68,7 +68,7 @@ func newLoopbackStack() (*stack.Stack, *tcpip.Error) {
// IPv4
{
Destination: tcpip.Address(strings.Repeat("\x00", 4)),
Mask: tcpip.Address(strings.Repeat("\x00", 4)),
Mask: tcpip.AddressMask(strings.Repeat("\x00", 4)),
Gateway: "",
NIC: NICID,
},
@@ -76,7 +76,7 @@ func newLoopbackStack() (*stack.Stack, *tcpip.Error) {
// IPv6
{
Destination: tcpip.Address(strings.Repeat("\x00", 16)),
Mask: tcpip.Address(strings.Repeat("\x00", 16)),
Mask: tcpip.AddressMask(strings.Repeat("\x00", 16)),
Gateway: "",
NIC: NICID,
},
+2 -2
View File
@@ -108,14 +108,14 @@ func newTestContext(t *testing.T) *testContext {
c.s0.SetRouteTable(
[]tcpip.Route{{
Destination: lladdr1,
Mask: tcpip.Address(strings.Repeat("\xff", 16)),
Mask: tcpip.AddressMask(strings.Repeat("\xff", 16)),
NIC: 1,
}},
)
c.s1.SetRouteTable(
[]tcpip.Route{{
Destination: lladdr0,
Mask: tcpip.Address(strings.Repeat("\xff", 16)),
Mask: tcpip.AddressMask(strings.Repeat("\xff", 16)),
NIC: 1,
}},
)
+1 -1
View File
@@ -150,7 +150,7 @@ func main() {
s.SetRouteTable([]tcpip.Route{
{
Destination: tcpip.Address(strings.Repeat("\x00", len(addr))),
Mask: tcpip.Address(strings.Repeat("\x00", len(addr))),
Mask: tcpip.AddressMask(strings.Repeat("\x00", len(addr))),
Gateway: "",
NIC: 1,
},
+1 -1
View File
@@ -490,7 +490,7 @@ type Route struct {
// Mask specifies which bits of the Destination and the target address
// must match for this row to be viable.
Mask Address
Mask AddressMask
// Gateway is the gateway to be used if this row is viable.
Gateway Address
+1 -1
View File
@@ -123,7 +123,7 @@ func TestSubnetCreation(t *testing.T) {
func TestRouteMatch(t *testing.T) {
tests := []struct {
d Address
m Address
m AddressMask
a Address
want bool
}{
+7 -1
View File
@@ -86,7 +86,7 @@ func (r *Route) toTcpipRoute(id tcpip.NICID) tcpip.Route {
return tcpip.Route{
Destination: ipToAddress(r.Destination),
Gateway: ipToAddress(r.Gateway),
Mask: ipToAddress(net.IP(r.Mask)),
Mask: ipToAddressMask(net.IP(r.Mask)),
NIC: id,
}
}
@@ -203,6 +203,12 @@ func ipToAddress(ip net.IP) tcpip.Address {
return addr
}
// ipToAddressMask converts IP to tcpip.AddressMask, ignoring the protocol.
func ipToAddressMask(ip net.IP) tcpip.AddressMask {
_, addr := ipToAddressAndProto(ip)
return tcpip.AddressMask(addr)
}
// generateRndMac returns a random local MAC address.
// Copied from eth_random_addr() (include/linux/etherdevice.h)
func generateRndMac() net.HardwareAddr {