XDP Socket

Defaults

XDP_SOCK_XSKS_MAP_DEFAULT
[source]

Default xsks map name

Constructor

xdp_sock_t *xdp_sock_new(xdp_iface_t *xdp_interface)
[source]

Create new xdp_sock object.

Returns:

On success new xdp_sock object, or NULL if the new xdp_sock could not be created.

Destructor

void xdp_sock_destroy(xdp_sock_t **self_p)
[source]

Destroy xdp_sock object. You must use this for any tcp server created via the xdp_sock_new method.

Parameters:
  • self_p (xdp_sock_t**) – pointer to xdp_sock_t object reference, so the destructor can nullify it

Returns:

None (void)

Methods

int xdp_sock_lookup_bpf_map(xdp_sock_t *self, xdp_iface_t *xdp_interface, const char *map_name, uint32_t key_size, uint32_t value_size)
[source]

Attach XSKS map to socket fd

Parameters:
  • self_p (xdp_sock_t*) – pointer to xdp_sock_t object

  • xdp_interface (xdp_iface_t*) – pointer to xdp_iface_t object

  • map_name (const char*) – map name

  • key_size (uint32_t) – map keys size

  • value_size (uint32_t) – map values size

Returns:

0 on success, err value on failiure

int xdp_sock_set_sockopt(xdp_sock_t *self, int opt_type, int opt_value)
[source]

Set socket option

Parameters:
  • self_p (xdp_sock_t*) – pointer to xdp_sock_t object

  • opt_type (int) – option type

  • opt_value (int) – option value

Returns:

0 on success, err value on failiure

Sock Options

XDP_SOCK_SO_PREFER_BUSY_POLL
[source]

Prefer busy poll sockopt

XDP_SOCK_SO_BUSY_POLL
[source]

Busy poll sockopt

XDP_SOCK_SO_BUSY_POLL_BUDGET
[source]

Busy poll budget sockopt

int xdp_sock_get_fd(xdp_sock_t *self)
[source]

Get socket descriptor

Parameters:
  • self_p (xdp_sock_t*) – pointer to xdp_sock_t object

Returns:

socket descriptor

int xdp_sock_rx_batch_get_size(xdp_sock_t *self, uint32_t *frames_rcvd, uint32_t nb)
[source]

Get size, number of frames received

Parameters:
  • self_p (xdp_sock_t*) – pointer to xdp_sock_t object

  • frames_rcvd (uint32_t*) – number of received frames

  • nb (uint32_t) – maximum number of frames to receive

Returns:

0 on success, -1 on failiure

int xdp_sock_rx_batch_release(xdp_sock_t *self, uint32_t frames_rcvd)
[source]

Release received batch

Parameters:
  • self_p (xdp_sock_t*) – pointer to xdp_sock_t object

  • frames_rcvd (uint32_t) – number of received frames to release

Returns:

0 on success

int xdp_sock_recv(xdp_sock_t *self, char *buffer, size_t *buffer_size)
[source]

Read/receive a frame from the RX batch

Parameters:
  • self_p (xdp_sock_t*) – pointer to xdp_sock_t object

  • buffer (char*) – receive buffer

  • buffer_size (size_t*) – size of the received buffer

Returns:

0 on success

int xdp_sock_tx_batch_set_size(xdp_sock_t *self, uint32_t nb)
[source]

Set size of the TX batch

Parameters:
  • self_p (xdp_sock_t*) – pointer to xdp_sock_t object

  • nb (uint32_t) – number of slots to prepare in the tx ring

Returns:

0 on success, -1 on failiure

int xdp_sock_tx_batch_release(xdp_sock_t *self, uint32_t frames_send)
[source]

Trigger send of the frames in the TX batch

Parameters:
  • self_p (xdp_sock_t*) – pointer to xdp_sock_t object

  • frames_send (uint32_t) – number of frames to send

Returns:

0 on success

int xdp_sock_send(xdp_sock_t *self, char *buffer, size_t buffer_size)
[source]

Send/place a frame in the TX ring

Parameters:
  • self_p (xdp_sock_t*) – pointer to xdp_sock_t object

  • buffer (char*) – buffer to send

  • buffer_size (size_t) – size of the buffer to send

Returns:

0 on success