mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Provide MTU for pipe LinkEndpoint
...so that callers can set different MTUs for different configurations. PiperOrigin-RevId: 416629560
This commit is contained in:
committed by
gVisor bot
parent
fe88fe6768
commit
7b6078e252
@@ -26,12 +26,14 @@ import (
|
||||
var _ stack.LinkEndpoint = (*Endpoint)(nil)
|
||||
|
||||
// New returns both ends of a new pipe.
|
||||
func New(linkAddr1, linkAddr2 tcpip.LinkAddress) (*Endpoint, *Endpoint) {
|
||||
func New(linkAddr1, linkAddr2 tcpip.LinkAddress, mtu uint32) (*Endpoint, *Endpoint) {
|
||||
ep1 := &Endpoint{
|
||||
linkAddr: linkAddr1,
|
||||
mtu: mtu,
|
||||
}
|
||||
ep2 := &Endpoint{
|
||||
linkAddr: linkAddr2,
|
||||
mtu: mtu,
|
||||
}
|
||||
ep1.linked = ep2
|
||||
ep2.linked = ep1
|
||||
@@ -43,6 +45,7 @@ type Endpoint struct {
|
||||
dispatcher stack.NetworkDispatcher
|
||||
linked *Endpoint
|
||||
linkAddr tcpip.LinkAddress
|
||||
mtu uint32
|
||||
}
|
||||
|
||||
func (e *Endpoint) deliverPackets(r stack.RouteInfo, proto tcpip.NetworkProtocolNumber, pkts stack.PacketBufferList) {
|
||||
@@ -96,8 +99,8 @@ func (e *Endpoint) IsAttached() bool {
|
||||
func (*Endpoint) Wait() {}
|
||||
|
||||
// MTU implements stack.LinkEndpoint.
|
||||
func (*Endpoint) MTU() uint32 {
|
||||
return header.IPv6MinimumMTU
|
||||
func (e *Endpoint) MTU() uint32 {
|
||||
return e.mtu
|
||||
}
|
||||
|
||||
// Capabilities implements stack.LinkEndpoint.
|
||||
|
||||
@@ -113,7 +113,7 @@ var (
|
||||
|
||||
func newTestContext(t *testing.T) *testContext {
|
||||
t.Helper()
|
||||
localNIC, remoteNIC := pipe.New("" /* linkAddr1 */, "" /* linkAddr2 */)
|
||||
localNIC, remoteNIC := pipe.New("" /* linkAddr1 */, "" /* linkAddr2 */, header.IPv4MinimumMTU)
|
||||
|
||||
localStack := stack.New(stack.Options{
|
||||
NetworkProtocols: []stack.NetworkProtocolFactory{ipv4.NewProtocol},
|
||||
|
||||
@@ -44,10 +44,12 @@ import (
|
||||
)
|
||||
|
||||
func setupStack(t *testing.T, stackOpts stack.Options, host1NICID, host2NICID tcpip.NICID) (*stack.Stack, *stack.Stack) {
|
||||
const maxFrameSize = header.IPv6MinimumMTU + header.EthernetMinimumSize
|
||||
|
||||
host1Stack := stack.New(stackOpts)
|
||||
host2Stack := stack.New(stackOpts)
|
||||
|
||||
host1NIC, host2NIC := pipe.New(utils.LinkAddr1, utils.LinkAddr2)
|
||||
host1NIC, host2NIC := pipe.New(utils.LinkAddr1, utils.LinkAddr2, maxFrameSize)
|
||||
|
||||
if err := host1Stack.CreateNIC(host1NICID, utils.NewEthernetEndpoint(host1NIC)); err != nil {
|
||||
t.Fatalf("host1Stack.CreateNIC(%d, _): %s", host1NICID, err)
|
||||
|
||||
@@ -279,8 +279,9 @@ func SetupRouterStack(t *testing.T, s *stack.Stack, ep1, ep2 stack.LinkEndpoint)
|
||||
// SetupRoutedStacks creates the NICs, sets forwarding, adds addresses and sets
|
||||
// the route tables for the passed stacks.
|
||||
func SetupRoutedStacks(t *testing.T, host1Stack, routerStack, host2Stack *stack.Stack) {
|
||||
host1NIC, routerNIC1 := pipe.New(LinkAddr1, LinkAddr2)
|
||||
routerNIC2, host2NIC := pipe.New(LinkAddr3, LinkAddr4)
|
||||
const maxFrameSize = header.IPv6MinimumMTU + header.EthernetMinimumSize
|
||||
host1NIC, routerNIC1 := pipe.New(LinkAddr1, LinkAddr2, maxFrameSize)
|
||||
routerNIC2, host2NIC := pipe.New(LinkAddr3, LinkAddr4, maxFrameSize)
|
||||
|
||||
SetupRouterStack(t, routerStack, NewEthernetEndpoint(routerNIC1), NewEthernetEndpoint(routerNIC2))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user