From 16f76ac49329d435983c4e3ec71db17d88eabecd Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Thu, 1 Jun 2023 09:39:52 -0700 Subject: [PATCH] sharedmem: mark as GSO-compatible Really, any LinkWriter is compatible with gVisor GSO: there's nothing special to be done. Anything with a WritePackets method is good to go. PiperOrigin-RevId: 537048401 --- pkg/tcpip/link/fdbased/endpoint.go | 2 +- pkg/tcpip/link/sharedmem/sharedmem.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/tcpip/link/fdbased/endpoint.go b/pkg/tcpip/link/fdbased/endpoint.go index a731d2d5e..beac836b7 100644 --- a/pkg/tcpip/link/fdbased/endpoint.go +++ b/pkg/tcpip/link/fdbased/endpoint.go @@ -754,7 +754,7 @@ func (e *endpoint) GSOMaxSize() uint32 { return e.gsoMaxSize } -// SupportsHWGSO implements stack.GSOEndpoint. +// SupportedGSO implements stack.GSOEndpoint. func (e *endpoint) SupportedGSO() stack.SupportedGSO { return e.gsoKind } diff --git a/pkg/tcpip/link/sharedmem/sharedmem.go b/pkg/tcpip/link/sharedmem/sharedmem.go index 1c4f08d24..fdffee342 100644 --- a/pkg/tcpip/link/sharedmem/sharedmem.go +++ b/pkg/tcpip/link/sharedmem/sharedmem.go @@ -133,8 +133,15 @@ type Options struct { // VirtioNetHeaderRequired if true, indicates that all outbound packets should have // a virtio header and inbound packets should have a virtio header as well. VirtioNetHeaderRequired bool + + // GSOMaxSize is the maximum GSO packet size. It is zero if GSO is + // disabled. Note that only gVisor GSO is supported, not host GSO. + GSOMaxSize uint32 } +var _ stack.LinkEndpoint = (*endpoint)(nil) +var _ stack.GSOEndpoint = (*endpoint)(nil) + type endpoint struct { // mtu (maximum transmission unit) is the maximum size of a packet. // mtu is immutable. @@ -160,6 +167,11 @@ type endpoint struct { // hdrSize is immutable. hdrSize uint32 + // gSOMaxSize is the maximum GSO packet size. It is zero if GSO is + // disabled. Note that only gVisor GSO is supported, not host GSO. + // gsoMaxSize is immutable. + gsoMaxSize uint32 + // virtioNetHeaderRequired if true indicates that a virtio header is expected // in all inbound/outbound packets. virtioNetHeaderRequired bool @@ -202,6 +214,7 @@ func New(opts Options) (stack.LinkEndpoint, error) { peerFD: opts.PeerFD, onClosed: opts.OnClosed, virtioNetHeaderRequired: opts.VirtioNetHeaderRequired, + gsoMaxSize: opts.GSOMaxSize, } if err := e.tx.init(opts.BufferSize, &opts.TX); err != nil { @@ -480,3 +493,13 @@ func (e *endpoint) dispatchLoop(d stack.NetworkDispatcher) { func (*endpoint) ARPHardwareType() header.ARPHardwareType { return header.ARPHardwareEther } + +// GSOMaxSize implements stack.GSOEndpoint. +func (e *endpoint) GSOMaxSize() uint32 { + return e.gsoMaxSize +} + +// SupportsGSO implements stack.GSOEndpoint. +func (e *endpoint) SupportedGSO() stack.SupportedGSO { + return stack.GvisorGSOSupported +}