FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
fastmm::net::XdpFilter Class Reference

The BPF objects of one interface: subscription hash map, XSKMAP, per-CPU fallback counter and the program, plus its XDP link once attached. More...

#include <fastmm/net/xdp_datagram_source.hpp>

Public Member Functions

 XdpFilter ()=default
 
 ~XdpFilter ()
 
 XdpFilter (const XdpFilter &)=delete
 
XdpFilter & operator= (const XdpFilter &)=delete
 
 XdpFilter (XdpFilter &&o) noexcept
 
XdpFilter & operator= (XdpFilter &&o) noexcept
 
int create (std::span< const xdp::Key > keys, std::uint32_t xsk_slots, std::string &err)
 Creates the maps (XSKMAP with xsk_slots entries), inserts keys and loads the program.
 
int attach (unsigned ifindex, bool generic) noexcept
 BPF_LINK_CREATE (attach type BPF_XDP) on ifindex with XDP_FLAGS_DRV_MODE or XDP_FLAGS_SKB_MODE.
 
void detach () noexcept
 
int set_socket (std::uint32_t queue, int xsk_fd) noexcept
 xsks[queue] = xsk_fd. The socket must be bound.
 
int fallback_count (std::uint64_t &out) noexcept
 Sum of the per-CPU fallback counters.
 
int test_run (std::span< const std::byte > frame, std::uint32_t &action) noexcept
 BPF_PROG_TEST_RUN on frame (at least 14 bytes).
 
int prog_fd () const noexcept
 
int link_fd () const noexcept
 
void close () noexcept
 

Detailed Description

The BPF objects of one interface: subscription hash map, XSKMAP, per-CPU fallback counter and the program, plus its XDP link once attached.

Closing the link fd detaches the program.

Constructor & Destructor Documentation

◆ XdpFilter() [1/3]

fastmm::net::XdpFilter::XdpFilter ( )
default

◆ ~XdpFilter()

fastmm::net::XdpFilter::~XdpFilter ( )
inline

◆ XdpFilter() [2/3]

fastmm::net::XdpFilter::XdpFilter ( const XdpFilter &  )
delete

◆ XdpFilter() [3/3]

fastmm::net::XdpFilter::XdpFilter ( XdpFilter &&  o)
inlinenoexcept

Member Function Documentation

◆ operator=() [1/2]

XdpFilter & fastmm::net::XdpFilter::operator= ( const XdpFilter &  )
delete

◆ operator=() [2/2]

XdpFilter & fastmm::net::XdpFilter::operator= ( XdpFilter &&  o)
inlinenoexcept

◆ create()

int fastmm::net::XdpFilter::create ( std::span< const xdp::Key >  keys,
std::uint32_t  xsk_slots,
std::string &  err 
)

Creates the maps (XSKMAP with xsk_slots entries), inserts keys and loads the program.

Returns 0 or -errno; err names the failing step and carries the verifier log when the load fails.

◆ attach()

int fastmm::net::XdpFilter::attach ( unsigned  ifindex,
bool  generic 
)
noexcept

BPF_LINK_CREATE (attach type BPF_XDP) on ifindex with XDP_FLAGS_DRV_MODE or XDP_FLAGS_SKB_MODE.

Returns 0 or -errno: -EBUSY or -EEXIST when the interface already has an XDP program, -EOPNOTSUPP when the driver has no native XDP.

◆ detach()

void fastmm::net::XdpFilter::detach ( )
noexcept

◆ set_socket()

int fastmm::net::XdpFilter::set_socket ( std::uint32_t  queue,
int  xsk_fd 
)
noexcept

xsks[queue] = xsk_fd. The socket must be bound.

◆ fallback_count()

int fastmm::net::XdpFilter::fallback_count ( std::uint64_t &  out)
noexcept

Sum of the per-CPU fallback counters.

◆ test_run()

int fastmm::net::XdpFilter::test_run ( std::span< const std::byte >  frame,
std::uint32_t &  action 
)
noexcept

BPF_PROG_TEST_RUN on frame (at least 14 bytes).

Returns 0 or -errno; the XDP action in action.

◆ prog_fd()

int fastmm::net::XdpFilter::prog_fd ( ) const
inlinenoexcept

◆ link_fd()

int fastmm::net::XdpFilter::link_fd ( ) const
inlinenoexcept

◆ close()

void fastmm::net::XdpFilter::close ( )
noexcept