xdp: update the incorrectly named "Readonly*" names

PiperOrigin-RevId: 592664806
This commit is contained in:
Kevin Krakauer
2023-12-20 14:57:27 -08:00
committed by gVisor bot
parent 4f712ce420
commit f76d64021e
4 changed files with 21 additions and 23 deletions
+2 -2
View File
@@ -151,13 +151,13 @@ func New(opts *Options) (stack.LinkEndpoint, error) {
umemSize = 1 << 21
nFrames = umemSize / frameSize
)
xdpOpts := xdp.ReadOnlySocketOpts{
xdpOpts := xdp.Opts{
NFrames: nFrames,
FrameSize: frameSize,
NDescriptors: nFrames / 2,
Bind: opts.Bind,
}
ep.control, err = xdp.ReadOnlyFromSocket(opts.FD, uint32(opts.InterfaceIndex), 0 /* queueID */, xdpOpts)
ep.control, err = xdp.NewFromSocket(opts.FD, uint32(opts.InterfaceIndex), 0 /* queueID */, xdpOpts)
if err != nil {
return nil, fmt.Errorf("failed to create AF_XDP dispatcher: %v", err)
}
+13 -15
View File
@@ -63,10 +63,8 @@ type ControlBlock struct {
Completion CompletionQueue
}
// TODO(b/240191988): None of this is read-only anymore.
// ReadOnlySocketOpts configure a read-only AF_XDP socket.
type ReadOnlySocketOpts struct {
// Opts configure an AF_XDP socket.
type Opts struct {
NFrames uint32
FrameSize uint32
NDescriptors uint32
@@ -74,11 +72,11 @@ type ReadOnlySocketOpts struct {
UseNeedWakeup bool
}
// DefaultReadOnlyOpts provides recommended default options for initializing a
// readonly AF_XDP socket. AF_XDP setup is extremely finnicky and can fail if
// incorrect values are used.
func DefaultReadOnlyOpts() ReadOnlySocketOpts {
return ReadOnlySocketOpts{
// DefaultOpts provides recommended default options for initializing an AF_XDP
// socket. AF_XDP setup is extremely finnicky and can fail if incorrect values
// are used.
func DefaultOpts() Opts {
return Opts{
NFrames: 4096,
// Frames must be 2048 or 4096 bytes, although not all drivers support
// both.
@@ -87,19 +85,19 @@ func DefaultReadOnlyOpts() ReadOnlySocketOpts {
}
}
// ReadOnlySocket returns an initialized read-only AF_XDP socket bound to a
// particular interface and queue.
func ReadOnlySocket(ifaceIdx, queueID uint32, opts ReadOnlySocketOpts) (*ControlBlock, error) {
// New returns an initialized AF_XDP socket bound to a particular interface and
// queue.
func New(ifaceIdx, queueID uint32, opts Opts) (*ControlBlock, error) {
sockfd, err := unix.Socket(unix.AF_XDP, unix.SOCK_RAW, 0)
if err != nil {
return nil, fmt.Errorf("failed to create AF_XDP socket: %v", err)
}
return ReadOnlyFromSocket(sockfd, ifaceIdx, queueID, opts)
return NewFromSocket(sockfd, ifaceIdx, queueID, opts)
}
// ReadOnlyFromSocket takes an AF_XDP socket, initializes it, and binds it to a
// NewFromSocket takes an AF_XDP socket, initializes it, and binds it to a
// particular interface and queue.
func ReadOnlyFromSocket(sockfd int, ifaceIdx, queueID uint32, opts ReadOnlySocketOpts) (*ControlBlock, error) {
func NewFromSocket(sockfd int, ifaceIdx, queueID uint32, opts Opts) (*ControlBlock, error) {
if opts.FrameSize != 2048 && opts.FrameSize != 4096 {
return nil, fmt.Errorf("invalid frame size %d: must be either 2048 or 4096", opts.FrameSize)
}
+4 -4
View File
@@ -61,7 +61,7 @@ func sizeOfTXQueueDesc() uint64 {
return uint64(unsafe.Sizeof(unix.XDPDesc{}))
}
func (fq *FillQueue) init(off unix.XDPMmapOffsets, opts ReadOnlySocketOpts) {
func (fq *FillQueue) init(off unix.XDPMmapOffsets, opts Opts) {
fillQueueRingHdr := (*reflect.SliceHeader)(unsafe.Pointer(&fq.ring))
fillQueueRingHdr.Data = uintptr(unsafe.Pointer(&fq.mem[off.Fr.Desc]))
fillQueueRingHdr.Len = int(opts.NDescriptors)
@@ -71,7 +71,7 @@ func (fq *FillQueue) init(off unix.XDPMmapOffsets, opts ReadOnlySocketOpts) {
fq.flags = (*atomicbitops.Uint32)(unsafe.Pointer(&fq.mem[off.Fr.Flags]))
}
func (rq *RXQueue) init(off unix.XDPMmapOffsets, opts ReadOnlySocketOpts) {
func (rq *RXQueue) init(off unix.XDPMmapOffsets, opts Opts) {
rxQueueRingHdr := (*reflect.SliceHeader)(unsafe.Pointer(&rq.ring))
rxQueueRingHdr.Data = uintptr(unsafe.Pointer(&rq.mem[off.Rx.Desc]))
rxQueueRingHdr.Len = int(opts.NDescriptors)
@@ -85,7 +85,7 @@ func (rq *RXQueue) init(off unix.XDPMmapOffsets, opts ReadOnlySocketOpts) {
rq.cachedConsumer = rq.consumer.Load()
}
func (cq *CompletionQueue) init(off unix.XDPMmapOffsets, opts ReadOnlySocketOpts) {
func (cq *CompletionQueue) init(off unix.XDPMmapOffsets, opts Opts) {
completionQueueRingHdr := (*reflect.SliceHeader)(unsafe.Pointer(&cq.ring))
completionQueueRingHdr.Data = uintptr(unsafe.Pointer(&cq.mem[off.Cr.Desc]))
completionQueueRingHdr.Len = int(opts.NDescriptors)
@@ -99,7 +99,7 @@ func (cq *CompletionQueue) init(off unix.XDPMmapOffsets, opts ReadOnlySocketOpts
cq.cachedConsumer = cq.consumer.Load()
}
func (tq *TXQueue) init(off unix.XDPMmapOffsets, opts ReadOnlySocketOpts) {
func (tq *TXQueue) init(off unix.XDPMmapOffsets, opts Opts) {
txQueueRingHdr := (*reflect.SliceHeader)(unsafe.Pointer(&tq.ring))
txQueueRingHdr.Data = uintptr(unsafe.Pointer(&tq.mem[off.Tx.Desc]))
txQueueRingHdr.Len = int(opts.NDescriptors)
+2 -2
View File
@@ -106,8 +106,8 @@ func (pc *TcpdumpCommand) execute() error {
}
defer cleanup()
controlBlock, err := xdp.ReadOnlySocket(
uint32(iface.Index), 0 /* queueID */, xdp.DefaultReadOnlyOpts())
controlBlock, err := xdp.New(
uint32(iface.Index), 0 /* queueID */, xdp.DefaultOpts())
if err != nil {
return fmt.Errorf("failed to create socket: %v", err)
}