diff options
author | Bhasker Hariharan <bhaskerh@google.com> | 2019-10-14 12:49:50 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-10-14 13:10:16 -0700 |
commit | a2964259702cc4ed3f10d2b8e352a36ef26f0215 (patch) | |
tree | 8bbb3c053715438d5788e06feea92e85f8acc62c | |
parent | 470997ca9990f2a985b7c29f5f27dc56b5fbec32 (diff) |
Use a different fanoutID for each new fdbased endpoint.
PiperOrigin-RevId: 274638272
-rw-r--r-- | pkg/tcpip/link/fdbased/endpoint.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/pkg/tcpip/link/fdbased/endpoint.go b/pkg/tcpip/link/fdbased/endpoint.go index 7636418b1..f80ac3435 100644 --- a/pkg/tcpip/link/fdbased/endpoint.go +++ b/pkg/tcpip/link/fdbased/endpoint.go @@ -178,6 +178,14 @@ type Options struct { RXChecksumOffload bool } +// fanoutID is used for AF_PACKET based endpoints to enable PACKET_FANOUT +// support in the host kernel. This allows us to use multiple FD's to receive +// from the same underlying NIC. The fanoutID needs to be the same for a given +// set of FD's that point to the same NIC. Trying to set the PACKET_FANOUT +// option for an FD with a fanoutID already in use by another FD for a different +// NIC will return an EINVAL. +var fanoutID = 1 + // New creates a new fd-based endpoint. // // Makes fd non-blocking, but does not take ownership of fd, which must remain @@ -245,6 +253,10 @@ func New(opts *Options) (stack.LinkEndpoint, error) { e.inboundDispatchers = append(e.inboundDispatchers, inboundDispatcher) } + // Increment fanoutID to ensure that we don't re-use the same fanoutID for + // the next endpoint. + fanoutID++ + return e, nil } @@ -265,7 +277,6 @@ func createInboundDispatcher(e *endpoint, fd int, isSocket bool) (linkDispatcher case *unix.SockaddrLinklayer: // enable PACKET_FANOUT mode is the underlying socket is // of type AF_PACKET. - const fanoutID = 1 const fanoutType = 0x8000 // PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_DEFRAG fanoutArg := fanoutID | fanoutType<<16 if err := syscall.SetsockoptInt(fd, syscall.SOL_PACKET, unix.PACKET_FANOUT, fanoutArg); err != nil { |