Skip to content

Commit

Permalink
Create the interfaces for PACKET_MMAP endpoints to implement.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 715019134
  • Loading branch information
manninglucas authored and gvisor-bot committed Jan 31, 2025
1 parent a500a2c commit de5a2e8
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion pkg/tcpip/stack/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type PacketEndpoint interface {
// match the endpoint.
//
// Implementers should treat packet as immutable and should copy it
// before before modification.
// before modification.
//
// linkHeader may have a length of 0, in which case the PacketEndpoint
// should construct its own ethernet header for applications.
Expand All @@ -171,6 +171,67 @@ type PacketEndpoint interface {
HandlePacket(nicID tcpip.NICID, netProto tcpip.NetworkProtocolNumber, pkt *PacketBuffer)
}

// MappablePacketEndpoint is a packet endpoint that supports forwarding its
// packets to a PacketMMapEndpoint.
type MappablePacketEndpoint interface {
PacketEndpoint

// GetPacketMMapOpts returns the options for initializing a PacketMMapEndpoint
// for this endpoint.
GetPacketMMapOpts(req *tcpip.TpacketReq, isRx bool) PacketMMapOpts

// SetPacketMMapEndpoint sets the PacketMMapEndpoint for this endpoint. All
// packets received by this endpoint will be forwarded to the provided
// PacketMMapEndpoint.
SetPacketMMapEndpoint(ep PacketMMapEndpoint)

// GetPacketMMapEndpoint returns the PacketMMapEndpoint for this endpoint or
// nil if there is none.
GetPacketMMapEndpoint() PacketMMapEndpoint

// HandlePacketMMapCopy is a function that is called when a packet received is
// too large for the buffer size specified for the memory mapped endpoint. In
// this case, the packet is copied and passed to the original packet endpoint.
HandlePacketMMapCopy(nicID tcpip.NICID, netProto tcpip.NetworkProtocolNumber, pkt *PacketBuffer)
}

// PacketMMapOpts are the options for initializing a PacketMMapEndpoint.
//
// +stateify savable
type PacketMMapOpts struct {
Req *tcpip.TpacketReq
IsRx bool
Cooked bool
Stack *Stack
Stats *tcpip.TransportEndpointStats
Wq *waiter.Queue
NICID tcpip.NICID
NetProto tcpip.NetworkProtocolNumber
PacketEndpoint MappablePacketEndpoint
}

// PacketMMapEndpoint is the interface implemented by endpoints to handle memory
// mapped packets over the packet transport protocol (PACKET_MMAP).
type PacketMMapEndpoint interface {
// HandlePacket is called by the stack when new packets arrive that
// match the endpoint.
//
// Implementers should treat packet as immutable and should copy it
// before modification.
//
// linkHeader may have a length of 0, in which case the PacketEndpoint
// should construct its own ethernet header for applications.
//
// HandlePacket may modify pkt.
HandlePacket(nicID tcpip.NICID, netProto tcpip.NetworkProtocolNumber, pkt *PacketBuffer)

// Close releases any resources associated with the endpoint.
Close()

// Readiness returns the events that the endpoint is ready for.
Readiness(mask waiter.EventMask) waiter.EventMask
}

// UnknownDestinationPacketDisposition enumerates the possible return values from
// HandleUnknownDestinationPacket().
type UnknownDestinationPacketDisposition int
Expand Down

0 comments on commit de5a2e8

Please sign in to comment.