bytecodealliance/rustix

Support for syscalls required for AF_XDP

arctic-alpaca opened this issue · 1 comments

Hi,

I'm experimenting with AF_XDP and would love to use rustix instead of libc. For the BPF side of things, I use aya, so only the non-BPF related syscalls remain. Some syscalls are already supported like mmap and socket but others would need to be implemented or expanded/modified. I created a list of missing syscalls, constants and structs. Most of the syscalls, etc were added in 4.18 with some additions and modifications in later kernel versions.

Syscalls:

  • setsockopt
    • setsockopt(fd, SOL_XDP, XDP_UMEM_REG, umem_reg, sizeof(umem_reg)), umem_reg see structs
    • setsockopt(fs, SOL_XDP, XDP_UMEM_FILL_RING, fill_size, sizeof(fill_size)), fill_size = u32 (https://github.com/torvalds/linux/blob/v6.6/net/xdp/xsk.c#L944)
    • setsockopt(fs, SOL_XDP, XDP_UMEM_COMPLETION_RING, comp_size, sizeof(comp_size)), comp_size = u32
    • setsockopt(fs, SOL_XDP, XDP_RX_RING, rx_size, sizeof(rx_size)), rx_size = u32
    • setsockopt(fs, SOL_XDP, XDP_TX_RING, tx_size, sizeof(tx_size)) tx_size = u32
  • getsockopt
    • getsockopt(fd, SOL_XDP, XDP_MMAP_OFFSETS, *xdp_mmap_offsets, &optlen), xdp_mmap_offsets see structs
    • getsockopt(fd, SOL_XDP, XDP_STATISTICS, *xdp_statistics, &optlen), xdp_statistics see structs
    • getsockopt(fd, SOL_XDP, XDP_OPTIONS, *xdp_options, &optlen), xdp_options see structs
  • bind
    • bind(fd, *sockaddr_xdp, sizeof(sockaddr_xdp)), sockaddr_xdp see structs, bind with various addresses is already supported but not with sockaddr_xdp
  • if_indextoname
  • if_nametoindex (optional)

Constants:

Structs:

If this is something you are interested in adding, I'd be happy to work on PR(s) to implement it but I would require some guidance:

  • Some syscall parameters/returns come in two versions, how should this be implemented?
  • Should kernel versions required for syscalls be listed?
  • I'm unsure how testing can be done for things like setsockopt as I don't think there is a syscall to check their result.
  • For {get,set}sockopt and bind I can orient myself at already existing syscalls in rustix but for if_indextoname and if_nametoindex, I'm unsure how to implement them.

With #946 and #972 merged, this is completed.