mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
netstack: support mtu in routes
PiperOrigin-RevId: 640919454
This commit is contained in:
@@ -54,6 +54,11 @@ type Route struct {
|
||||
// neighbor cache.
|
||||
// +checklocks:mu
|
||||
neighborEntry *neighborEntry
|
||||
|
||||
// mtu is the maximum transmission unit to use for this route.
|
||||
// If mtu is 0, this field is ignored and the MTU of the outgoing NIC
|
||||
// is used for egress packets.
|
||||
mtu uint32
|
||||
}
|
||||
|
||||
// +stateify savable
|
||||
@@ -140,7 +145,7 @@ func (r *Route) fieldsLocked() RouteInfo {
|
||||
// ownership of the provided local address.
|
||||
//
|
||||
// Returns an empty route if validation fails.
|
||||
func constructAndValidateRoute(netProto tcpip.NetworkProtocolNumber, addressEndpoint AssignableAddressEndpoint, localAddressNIC, outgoingNIC *nic, gateway, localAddr, remoteAddr tcpip.Address, handleLocal, multicastLoop bool) *Route {
|
||||
func constructAndValidateRoute(netProto tcpip.NetworkProtocolNumber, addressEndpoint AssignableAddressEndpoint, localAddressNIC, outgoingNIC *nic, gateway, localAddr, remoteAddr tcpip.Address, handleLocal, multicastLoop bool, mtu uint32) *Route {
|
||||
if localAddr.BitLen() == 0 {
|
||||
localAddr = addressEndpoint.AddressWithPrefix().Address
|
||||
}
|
||||
@@ -165,6 +170,7 @@ func constructAndValidateRoute(netProto tcpip.NetworkProtocolNumber, addressEndp
|
||||
addressEndpoint,
|
||||
handleLocal,
|
||||
multicastLoop,
|
||||
mtu,
|
||||
)
|
||||
|
||||
return r
|
||||
@@ -172,7 +178,7 @@ func constructAndValidateRoute(netProto tcpip.NetworkProtocolNumber, addressEndp
|
||||
|
||||
// makeRoute initializes a new route. It takes ownership of the provided
|
||||
// AssignableAddressEndpoint.
|
||||
func makeRoute(netProto tcpip.NetworkProtocolNumber, gateway, localAddr, remoteAddr tcpip.Address, outgoingNIC, localAddressNIC *nic, localAddressEndpoint AssignableAddressEndpoint, handleLocal, multicastLoop bool) *Route {
|
||||
func makeRoute(netProto tcpip.NetworkProtocolNumber, gateway, localAddr, remoteAddr tcpip.Address, outgoingNIC, localAddressNIC *nic, localAddressEndpoint AssignableAddressEndpoint, handleLocal, multicastLoop bool, mtu uint32) *Route {
|
||||
if localAddressNIC.stack != outgoingNIC.stack {
|
||||
panic(fmt.Sprintf("cannot create a route with NICs from different stacks"))
|
||||
}
|
||||
@@ -198,7 +204,7 @@ func makeRoute(netProto tcpip.NetworkProtocolNumber, gateway, localAddr, remoteA
|
||||
}
|
||||
}
|
||||
|
||||
r := makeRouteInner(netProto, localAddr, remoteAddr, outgoingNIC, localAddressNIC, localAddressEndpoint, loop)
|
||||
r := makeRouteInner(netProto, localAddr, remoteAddr, outgoingNIC, localAddressNIC, localAddressEndpoint, loop, mtu)
|
||||
if r.Loop()&PacketOut == 0 {
|
||||
// Packet will not leave the stack, no need for a gateway or a remote link
|
||||
// address.
|
||||
@@ -238,7 +244,7 @@ func makeRoute(netProto tcpip.NetworkProtocolNumber, gateway, localAddr, remoteA
|
||||
return r
|
||||
}
|
||||
|
||||
func makeRouteInner(netProto tcpip.NetworkProtocolNumber, localAddr, remoteAddr tcpip.Address, outgoingNIC, localAddressNIC *nic, localAddressEndpoint AssignableAddressEndpoint, loop PacketLooping) *Route {
|
||||
func makeRouteInner(netProto tcpip.NetworkProtocolNumber, localAddr, remoteAddr tcpip.Address, outgoingNIC, localAddressNIC *nic, localAddressEndpoint AssignableAddressEndpoint, loop PacketLooping, mtu uint32) *Route {
|
||||
r := &Route{
|
||||
routeInfo: routeInfo{
|
||||
NetProto: netProto,
|
||||
@@ -249,6 +255,7 @@ func makeRouteInner(netProto tcpip.NetworkProtocolNumber, localAddr, remoteAddr
|
||||
},
|
||||
localAddressNIC: localAddressNIC,
|
||||
outgoingNIC: outgoingNIC,
|
||||
mtu: mtu,
|
||||
}
|
||||
|
||||
r.mu.Lock()
|
||||
@@ -270,7 +277,7 @@ func makeLocalRoute(netProto tcpip.NetworkProtocolNumber, localAddr, remoteAddr
|
||||
if outgoingNIC.IsLoopback() {
|
||||
loop = PacketOut
|
||||
}
|
||||
return makeRouteInner(netProto, localAddr, remoteAddr, outgoingNIC, localAddressNIC, localAddressEndpoint, loop)
|
||||
return makeRouteInner(netProto, localAddr, remoteAddr, outgoingNIC, localAddressNIC, localAddressEndpoint, loop, 0 /* mtu */)
|
||||
}
|
||||
|
||||
// RemoteLinkAddress returns the link-layer (MAC) address of the next hop in
|
||||
@@ -515,8 +522,11 @@ func (r *Route) DefaultTTL() uint8 {
|
||||
return r.outgoingNIC.getNetworkEndpoint(r.NetProto()).DefaultTTL()
|
||||
}
|
||||
|
||||
// MTU returns the MTU of the underlying network endpoint.
|
||||
// MTU returns the MTU of the route if present, otherwise the MTU of the underlying network endpoint.
|
||||
func (r *Route) MTU() uint32 {
|
||||
if r.mtu > 0 {
|
||||
return r.mtu
|
||||
}
|
||||
return r.outgoingNIC.getNetworkEndpoint(r.NetProto()).MTU()
|
||||
}
|
||||
|
||||
|
||||
@@ -1192,7 +1192,7 @@ func (s *Stack) NewRouteForMulticast(nicID tcpip.NICID, remoteAddr tcpip.Address
|
||||
}
|
||||
|
||||
if addressEndpoint := s.getAddressEP(nic, tcpip.Address{} /* localAddr */, remoteAddr, tcpip.Address{} /* srcHint */, netProto); addressEndpoint != nil {
|
||||
return constructAndValidateRoute(netProto, addressEndpoint, nic, nic, tcpip.Address{} /* gateway */, tcpip.Address{} /* localAddr */, remoteAddr, s.handleLocal, false /* multicastLoop */)
|
||||
return constructAndValidateRoute(netProto, addressEndpoint, nic, nic, tcpip.Address{} /* gateway */, tcpip.Address{} /* localAddr */, remoteAddr, s.handleLocal, false /* multicastLoop */, 0 /* mtu */)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1303,14 +1303,14 @@ func isNICForwarding(nic *nic, proto tcpip.NetworkProtocolNumber) bool {
|
||||
// endpoint.
|
||||
//
|
||||
// +checklocksread:s.mu
|
||||
func (s *Stack) findRouteWithLocalAddrFromAnyInterfaceRLocked(outgoingNIC *nic, localAddr, remoteAddr, srcHint, gateway tcpip.Address, netProto tcpip.NetworkProtocolNumber, multicastLoop bool) *Route {
|
||||
func (s *Stack) findRouteWithLocalAddrFromAnyInterfaceRLocked(outgoingNIC *nic, localAddr, remoteAddr, srcHint, gateway tcpip.Address, netProto tcpip.NetworkProtocolNumber, multicastLoop bool, mtu uint32) *Route {
|
||||
for _, aNIC := range s.nics {
|
||||
addressEndpoint := s.getAddressEP(aNIC, localAddr, remoteAddr, srcHint, netProto)
|
||||
if addressEndpoint == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if r := constructAndValidateRoute(netProto, addressEndpoint, aNIC /* localAddressNIC */, outgoingNIC, gateway, localAddr, remoteAddr, s.handleLocal, multicastLoop); r != nil {
|
||||
if r := constructAndValidateRoute(netProto, addressEndpoint, aNIC /* localAddressNIC */, outgoingNIC, gateway, localAddr, remoteAddr, s.handleLocal, multicastLoop, mtu); r != nil {
|
||||
return r
|
||||
}
|
||||
}
|
||||
@@ -1359,11 +1359,12 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n
|
||||
tcpip.Address{}, /* gateway */
|
||||
localAddr,
|
||||
remoteAddr,
|
||||
nic, /* outboundNIC */
|
||||
nic, /* outgoingNIC */
|
||||
nic, /* localAddressNIC*/
|
||||
addressEndpoint,
|
||||
s.handleLocal,
|
||||
multicastLoop,
|
||||
0, /* mtu */
|
||||
), nil
|
||||
}
|
||||
}
|
||||
@@ -1398,7 +1399,7 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n
|
||||
if needRoute {
|
||||
gateway = route.Gateway
|
||||
}
|
||||
r := constructAndValidateRoute(netProto, addressEndpoint, nic /* outgoingNIC */, nic /* outgoingNIC */, gateway, localAddr, remoteAddr, s.handleLocal, multicastLoop)
|
||||
r := constructAndValidateRoute(netProto, addressEndpoint, nic /* outgoingNIC */, nic /* outgoingNIC */, gateway, localAddr, remoteAddr, s.handleLocal, multicastLoop, route.MTU)
|
||||
if r == nil {
|
||||
panic(fmt.Sprintf("non-forwarding route validation failed with route table entry = %#v, id = %d, localAddr = %s, remoteAddr = %s", route, id, localAddr, remoteAddr))
|
||||
}
|
||||
@@ -1424,7 +1425,8 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n
|
||||
chosenRoute = route
|
||||
continue
|
||||
}
|
||||
if r := s.findRouteWithLocalAddrFromAnyInterfaceRLocked(nic, localAddr, remoteAddr, route.SourceHint, route.Gateway, netProto, multicastLoop); r != nil {
|
||||
|
||||
if r := s.findRouteWithLocalAddrFromAnyInterfaceRLocked(nic, localAddr, remoteAddr, route.SourceHint, route.Gateway, netProto, multicastLoop, route.MTU); r != nil {
|
||||
return r
|
||||
}
|
||||
}
|
||||
@@ -1453,7 +1455,7 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n
|
||||
if id != 0 {
|
||||
if aNIC, ok := s.nics[id]; ok {
|
||||
if addressEndpoint := s.getAddressEP(aNIC, localAddr, remoteAddr, chosenRoute.SourceHint, netProto); addressEndpoint != nil {
|
||||
if r := constructAndValidateRoute(netProto, addressEndpoint, aNIC /* localAddressNIC */, nic /* outgoingNIC */, gateway, localAddr, remoteAddr, s.handleLocal, multicastLoop); r != nil {
|
||||
if r := constructAndValidateRoute(netProto, addressEndpoint, aNIC /* localAddressNIC */, nic /* outgoingNIC */, gateway, localAddr, remoteAddr, s.handleLocal, multicastLoop, chosenRoute.MTU); r != nil {
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
@@ -1466,7 +1468,7 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n
|
||||
if id == 0 {
|
||||
// If an interface is not specified, try to find a NIC that holds the local
|
||||
// address endpoint to construct a route.
|
||||
if r := s.findRouteWithLocalAddrFromAnyInterfaceRLocked(nic, localAddr, remoteAddr, chosenRoute.SourceHint, gateway, netProto, multicastLoop); r != nil {
|
||||
if r := s.findRouteWithLocalAddrFromAnyInterfaceRLocked(nic, localAddr, remoteAddr, chosenRoute.SourceHint, gateway, netProto, multicastLoop, chosenRoute.MTU); r != nil {
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -831,7 +831,7 @@ func TestNetworkSendMultiRoute(t *testing.T) {
|
||||
testSendTo(t, s, "\x06\x00\x00\x00", ep2, nil)
|
||||
}
|
||||
|
||||
func testRoute(t *testing.T, s *stack.Stack, nic tcpip.NICID, srcAddr, dstAddr, expectedSrcAddr tcpip.Address) {
|
||||
func testRoute(t *testing.T, s *stack.Stack, nic tcpip.NICID, srcAddr, dstAddr, expectedSrcAddr tcpip.Address, expectedRouteMTU int) {
|
||||
r, err := s.FindRoute(nic, srcAddr, dstAddr, fakeNetNumber, false /* multicastLoop */)
|
||||
if err != nil {
|
||||
t.Fatal("FindRoute failed:", err)
|
||||
@@ -846,6 +846,10 @@ func testRoute(t *testing.T, s *stack.Stack, nic tcpip.NICID, srcAddr, dstAddr,
|
||||
if r.RemoteAddress() != dstAddr {
|
||||
t.Fatalf("got Route.RemoteAddress() = %s, want = %s", dstAddr, r.RemoteAddress())
|
||||
}
|
||||
|
||||
if int(r.MTU()) != expectedRouteMTU {
|
||||
t.Fatalf("got Route.MTU() = %d, want = %d", r.MTU(), expectedRouteMTU)
|
||||
}
|
||||
}
|
||||
|
||||
func testNoRoute(t *testing.T, s *stack.Stack, nic tcpip.NICID, srcAddr, dstAddr tcpip.Address) {
|
||||
@@ -1043,6 +1047,8 @@ func TestRouteWithDownNIC(t *testing.T) {
|
||||
var addr2 = tcpip.AddrFrom4Slice([]byte("\x02\x00\x00\x00"))
|
||||
var nic1Dst = tcpip.AddrFrom4Slice([]byte("\x05\x00\x00\x00"))
|
||||
var nic2Dst = tcpip.AddrFrom4Slice([]byte("\x06\x00\x00\x00"))
|
||||
var nic1RouteMTU = 1500
|
||||
var nic2RouteMTU = 1460
|
||||
|
||||
setup := func(t *testing.T) (*stack.Stack, *channel.Endpoint, *channel.Endpoint) {
|
||||
s := stack.New(stack.Options{
|
||||
@@ -1094,8 +1100,8 @@ func TestRouteWithDownNIC(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.SetRouteTable([]tcpip.Route{
|
||||
{Destination: subnet1, Gateway: tcpip.AddrFrom4Slice([]byte("\x00\x00\x00\x00")), NIC: nicID1},
|
||||
{Destination: subnet0, Gateway: tcpip.AddrFrom4Slice([]byte("\x00\x00\x00\x00")), NIC: nicID2},
|
||||
{Destination: subnet1, Gateway: tcpip.AddrFrom4Slice([]byte("\x00\x00\x00\x00")), NIC: nicID1, MTU: uint32(nic1RouteMTU)},
|
||||
{Destination: subnet0, Gateway: tcpip.AddrFrom4Slice([]byte("\x00\x00\x00\x00")), NIC: nicID2, MTU: uint32(nic2RouteMTU)},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1110,14 +1116,14 @@ func TestRouteWithDownNIC(t *testing.T) {
|
||||
s, _, _ := setup(t)
|
||||
|
||||
// Test routes to odd address.
|
||||
testRoute(t, s, unspecifiedNIC, tcpip.Address{}, tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), addr1)
|
||||
testRoute(t, s, unspecifiedNIC, addr1, tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), addr1)
|
||||
testRoute(t, s, nicID1, addr1, tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), addr1)
|
||||
testRoute(t, s, unspecifiedNIC, tcpip.Address{}, tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), addr1, nic1RouteMTU)
|
||||
testRoute(t, s, unspecifiedNIC, addr1, tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), addr1, nic1RouteMTU)
|
||||
testRoute(t, s, nicID1, addr1, tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), addr1, nic1RouteMTU)
|
||||
|
||||
// Test routes to even address.
|
||||
testRoute(t, s, unspecifiedNIC, tcpip.Address{}, tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), addr2)
|
||||
testRoute(t, s, unspecifiedNIC, addr2, tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), addr2)
|
||||
testRoute(t, s, nicID2, addr2, tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), addr2)
|
||||
testRoute(t, s, unspecifiedNIC, tcpip.Address{}, tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), addr2, nic2RouteMTU)
|
||||
testRoute(t, s, unspecifiedNIC, addr2, tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), addr2, nic2RouteMTU)
|
||||
testRoute(t, s, nicID2, addr2, tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), addr2, nic2RouteMTU)
|
||||
|
||||
// Bringing NIC1 down should result in no routes to odd addresses. Routes to
|
||||
// even addresses should continue to be available as NIC2 is still up.
|
||||
@@ -1127,9 +1133,9 @@ func TestRouteWithDownNIC(t *testing.T) {
|
||||
testNoRoute(t, s, unspecifiedNIC, tcpip.Address{}, nic1Dst)
|
||||
testNoRoute(t, s, unspecifiedNIC, addr1, nic1Dst)
|
||||
testNoRoute(t, s, nicID1, addr1, nic1Dst)
|
||||
testRoute(t, s, unspecifiedNIC, tcpip.Address{}, nic2Dst, addr2)
|
||||
testRoute(t, s, unspecifiedNIC, addr2, nic2Dst, addr2)
|
||||
testRoute(t, s, nicID2, addr2, nic2Dst, addr2)
|
||||
testRoute(t, s, unspecifiedNIC, tcpip.Address{}, nic2Dst, addr2, nic2RouteMTU)
|
||||
testRoute(t, s, unspecifiedNIC, addr2, nic2Dst, addr2, nic2RouteMTU)
|
||||
testRoute(t, s, nicID2, addr2, nic2Dst, addr2, nic2RouteMTU)
|
||||
|
||||
// Bringing NIC2 down should result in no routes to even addresses. No
|
||||
// route should be available to any address as routes to odd addresses
|
||||
@@ -1151,9 +1157,9 @@ func TestRouteWithDownNIC(t *testing.T) {
|
||||
if err := upFn(s, nicID1); err != nil {
|
||||
t.Fatalf("test.upFn(_, %d): %s", nicID1, err)
|
||||
}
|
||||
testRoute(t, s, unspecifiedNIC, tcpip.Address{}, nic1Dst, addr1)
|
||||
testRoute(t, s, unspecifiedNIC, addr1, nic1Dst, addr1)
|
||||
testRoute(t, s, nicID1, addr1, nic1Dst, addr1)
|
||||
testRoute(t, s, unspecifiedNIC, tcpip.Address{}, nic1Dst, addr1, nic1RouteMTU)
|
||||
testRoute(t, s, unspecifiedNIC, addr1, nic1Dst, addr1, nic1RouteMTU)
|
||||
testRoute(t, s, nicID1, addr1, nic1Dst, addr1, nic1RouteMTU)
|
||||
testNoRoute(t, s, unspecifiedNIC, tcpip.Address{}, nic2Dst)
|
||||
testNoRoute(t, s, unspecifiedNIC, addr2, nic2Dst)
|
||||
testNoRoute(t, s, nicID2, addr2, nic2Dst)
|
||||
@@ -1286,6 +1292,8 @@ func TestRoutes(t *testing.T) {
|
||||
// Set a route table that sends all packets with odd destination
|
||||
// addresses through the first NIC, and all even destination address
|
||||
// through the second one.
|
||||
nic1RouteMTU := 1500
|
||||
nic2RouteMTU := 1460
|
||||
{
|
||||
subnet0, err := tcpip.NewSubnet(tcpip.AddrFromSlice([]byte("\x00\x00\x00\x00")), tcpip.MaskFrom("\x01\x00\x00\x00"))
|
||||
if err != nil {
|
||||
@@ -1295,25 +1303,26 @@ func TestRoutes(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s.SetRouteTable([]tcpip.Route{
|
||||
{Destination: subnet1, Gateway: tcpip.AddrFromSlice([]byte("\x00\x00\x00\x00")), NIC: 1},
|
||||
{Destination: subnet0, Gateway: tcpip.AddrFromSlice([]byte("\x00\x00\x00\x00")), NIC: 2},
|
||||
{Destination: subnet1, Gateway: tcpip.AddrFromSlice([]byte("\x00\x00\x00\x00")), NIC: 1, MTU: uint32(nic1RouteMTU)},
|
||||
{Destination: subnet0, Gateway: tcpip.AddrFromSlice([]byte("\x00\x00\x00\x00")), NIC: 2, MTU: uint32(nic2RouteMTU)},
|
||||
})
|
||||
}
|
||||
|
||||
// Test routes to odd address.
|
||||
testRoute(t, s, 0, tcpip.Address{}, tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")))
|
||||
testRoute(t, s, 0, tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")))
|
||||
testRoute(t, s, 1, tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")))
|
||||
testRoute(t, s, 0, tcpip.AddrFromSlice([]byte("\x03\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x03\x00\x00\x00")))
|
||||
testRoute(t, s, 1, tcpip.AddrFromSlice([]byte("\x03\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x03\x00\x00\x00")))
|
||||
testRoute(t, s, 0, tcpip.Address{}, tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")), nic1RouteMTU)
|
||||
testRoute(t, s, 0, tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")), nic1RouteMTU)
|
||||
testRoute(t, s, 1, tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")), nic1RouteMTU)
|
||||
testRoute(t, s, 0, tcpip.AddrFromSlice([]byte("\x03\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x03\x00\x00\x00")), nic1RouteMTU)
|
||||
testRoute(t, s, 1, tcpip.AddrFromSlice([]byte("\x03\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x05\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x03\x00\x00\x00")), nic1RouteMTU)
|
||||
|
||||
// Test routes to even address.
|
||||
testRoute(t, s, 0, tcpip.Address{}, tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x04\x00\x00\x00")))
|
||||
testRoute(t, s, 0, tcpip.AddrFromSlice([]byte("\x02\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x02\x00\x00\x00")))
|
||||
testRoute(t, s, 2, tcpip.AddrFromSlice([]byte("\x02\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x02\x00\x00\x00")))
|
||||
testRoute(t, s, 0, tcpip.AddrFromSlice([]byte("\x04\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x04\x00\x00\x00")))
|
||||
testRoute(t, s, 2, tcpip.AddrFromSlice([]byte("\x04\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x04\x00\x00\x00")))
|
||||
testRoute(t, s, 0, tcpip.Address{}, tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x04\x00\x00\x00")), nic2RouteMTU)
|
||||
testRoute(t, s, 0, tcpip.AddrFromSlice([]byte("\x02\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x02\x00\x00\x00")), nic2RouteMTU)
|
||||
testRoute(t, s, 2, tcpip.AddrFromSlice([]byte("\x02\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x02\x00\x00\x00")), nic2RouteMTU)
|
||||
testRoute(t, s, 0, tcpip.AddrFromSlice([]byte("\x04\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x04\x00\x00\x00")), nic2RouteMTU)
|
||||
testRoute(t, s, 2, tcpip.AddrFromSlice([]byte("\x04\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x06\x00\x00\x00")), tcpip.AddrFromSlice([]byte("\x04\x00\x00\x00")), nic2RouteMTU)
|
||||
|
||||
// Try to send to odd numbered address from even numbered ones, then
|
||||
// vice-versa.
|
||||
|
||||
@@ -1525,6 +1525,11 @@ type Route struct {
|
||||
// SourceHint indicates a preferred source address to use when NICs
|
||||
// have multiple addresses.
|
||||
SourceHint Address
|
||||
|
||||
// MTU is the maximum transmission unit to use for this route.
|
||||
// If MTU is 0, this field is ignored and the MTU of the NIC for which this route
|
||||
// is configured is used for egress packets.
|
||||
MTU uint32
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer interface.
|
||||
|
||||
Reference in New Issue
Block a user