DPDK
1.6.0r2
|
#include <stdint.h>
#include <rte_mempool.h>
#include <rte_atomic.h>
#include <rte_prefetch.h>
#include <rte_branch_prediction.h>
Data Structures | |
struct | rte_ctrlmbuf |
union | rte_vlan_macip |
struct | rte_pktmbuf |
struct | rte_mbuf |
struct | rte_pktmbuf_pool_private |
Macros | |
#define | PKT_RX_VLAN_PKT 0x0001 |
#define | PKT_RX_RSS_HASH 0x0002 |
#define | PKT_RX_FDIR 0x0004 |
#define | PKT_RX_L4_CKSUM_BAD 0x0008 |
#define | PKT_RX_IP_CKSUM_BAD 0x0010 |
#define | PKT_RX_IPV4_HDR 0x0020 |
#define | PKT_RX_IPV4_HDR_EXT 0x0040 |
#define | PKT_RX_IPV6_HDR 0x0080 |
#define | PKT_RX_IPV6_HDR_EXT 0x0100 |
#define | PKT_RX_IEEE1588_PTP 0x0200 |
#define | PKT_RX_IEEE1588_TMST 0x0400 |
#define | PKT_TX_VLAN_PKT 0x0800 |
#define | PKT_TX_IP_CKSUM 0x1000 |
#define | PKT_TX_L4_MASK 0x6000 |
#define | PKT_TX_L4_NO_CKSUM 0x0000 |
#define | PKT_TX_TCP_CKSUM 0x2000 |
#define | PKT_TX_SCTP_CKSUM 0x4000 |
#define | PKT_TX_UDP_CKSUM 0x6000 |
#define | PKT_TX_IEEE1588_TMST 0x8000 |
#define | PKT_TX_OFFLOAD_MASK (PKT_TX_VLAN_PKT | PKT_TX_IP_CKSUM | PKT_TX_L4_MASK) |
#define | TX_VLAN_CMP_MASK 0xFFFF0000 |
#define | TX_MAC_LEN_CMP_MASK 0x0000FE00 |
#define | TX_IP_LEN_CMP_MASK 0x000001FF |
#define | RTE_MBUF_FROM_BADDR(ba) (((struct rte_mbuf *)(ba)) - 1) |
#define | RTE_MBUF_TO_BADDR(mb) (((struct rte_mbuf *)(mb)) + 1) |
#define | RTE_MBUF_INDIRECT(mb) (RTE_MBUF_FROM_BADDR((mb)->buf_addr) != (mb)) |
#define | RTE_MBUF_DIRECT(mb) (RTE_MBUF_FROM_BADDR((mb)->buf_addr) == (mb)) |
#define | __rte_mbuf_sanity_check(m, t, is_h) do { } while(0) |
#define | __rte_mbuf_sanity_check_raw(m, t, is_h) do { } while(0) |
#define | RTE_MBUF_ASSERT(exp) do { } while(0) |
#define | RTE_MBUF_PREFETCH_TO_FREE(m) |
#define | rte_ctrlmbuf_data(m) ((m)->ctrl.data) |
#define | rte_ctrlmbuf_len(m) ((m)->ctrl.data_len) |
#define | rte_pktmbuf_mtod(m, t) ((t)((m)->pkt.data)) |
#define | rte_pktmbuf_pkt_len(m) ((m)->pkt.pkt_len) |
#define | rte_pktmbuf_data_len(m) ((m)->pkt.data_len) |
Enumerations | |
enum | rte_mbuf_type { RTE_MBUF_CTRL, RTE_MBUF_PKT } |
Functions | |
static uint16_t | rte_mbuf_refcnt_update (struct rte_mbuf *m, int16_t value) |
static uint16_t | rte_mbuf_refcnt_read (const struct rte_mbuf *m) |
static void | rte_mbuf_refcnt_set (struct rte_mbuf *m, uint16_t new_value) |
void | rte_mbuf_sanity_check (const struct rte_mbuf *m, enum rte_mbuf_type t, int is_header) |
void | rte_ctrlmbuf_init (struct rte_mempool *mp, void *opaque_arg, void *m, unsigned i) |
static struct rte_mbuf * | rte_ctrlmbuf_alloc (struct rte_mempool *mp) |
static void | rte_ctrlmbuf_free (struct rte_mbuf *m) |
void | rte_pktmbuf_init (struct rte_mempool *mp, void *opaque_arg, void *m, unsigned i) |
void | rte_pktmbuf_pool_init (struct rte_mempool *mp, void *opaque_arg) |
static void | rte_pktmbuf_reset (struct rte_mbuf *m) |
static struct rte_mbuf * | rte_pktmbuf_alloc (struct rte_mempool *mp) |
static void | rte_pktmbuf_attach (struct rte_mbuf *mi, struct rte_mbuf *md) |
static void | rte_pktmbuf_detach (struct rte_mbuf *m) |
static void | rte_pktmbuf_free_seg (struct rte_mbuf *m) |
static void | rte_pktmbuf_free (struct rte_mbuf *m) |
static struct rte_mbuf * | rte_pktmbuf_clone (struct rte_mbuf *md, struct rte_mempool *mp) |
static void | rte_pktmbuf_refcnt_update (struct rte_mbuf *m, int16_t v) |
static uint16_t | rte_pktmbuf_headroom (const struct rte_mbuf *m) |
static uint16_t | rte_pktmbuf_tailroom (const struct rte_mbuf *m) |
static struct rte_mbuf * | rte_pktmbuf_lastseg (struct rte_mbuf *m) |
static char * | rte_pktmbuf_prepend (struct rte_mbuf *m, uint16_t len) |
static char * | rte_pktmbuf_append (struct rte_mbuf *m, uint16_t len) |
static char * | rte_pktmbuf_adj (struct rte_mbuf *m, uint16_t len) |
static int | rte_pktmbuf_trim (struct rte_mbuf *m, uint16_t len) |
static int | rte_pktmbuf_is_contiguous (const struct rte_mbuf *m) |
void | rte_pktmbuf_dump (const struct rte_mbuf *m, unsigned dump_len) |
RTE Mbuf
The mbuf library provides the ability to create and destroy buffers that may be used by the RTE application to store message buffers. The message buffers are stored in a mempool, using the RTE mempool library.
This library provide an API to allocate/free mbufs, manipulate control message buffer (ctrlmbuf), which are generic message buffers, and packet buffers (pktmbuf), which are used to carry network packets.
To understand the concepts of packet buffers or mbufs, you should read "TCP/IP Illustrated, Volume 2: The Implementation, Addison-Wesley, 1995, ISBN 0-201-63354-X from Richard Stevens" http://www.kohala.com/start/tcpipiv2.html
The main modification of this implementation is the use of mbuf for transports other than packets. mbufs can have other types.
#define __rte_mbuf_sanity_check | ( | m, | |
t, | |||
is_h | |||
) | do { } while(0) |
check mbuf type in debug mode
#define __rte_mbuf_sanity_check_raw | ( | m, | |
t, | |||
is_h | |||
) | do { } while(0) |
check mbuf type in debug mode if mbuf pointer is not null
#define PKT_RX_FDIR 0x0004 |
RX packet with FDIR infos.
#define PKT_RX_IEEE1588_PTP 0x0200 |
RX IEEE1588 L2 Ethernet PT Packet.
#define PKT_RX_IEEE1588_TMST 0x0400 |
RX IEEE1588 L2/L4 timestamped packet.
#define PKT_RX_IP_CKSUM_BAD 0x0010 |
IP cksum of RX pkt. is not OK.
#define PKT_RX_IPV4_HDR 0x0020 |
RX packet with IPv4 header.
#define PKT_RX_IPV4_HDR_EXT 0x0040 |
RX packet with extended IPv4 header.
#define PKT_RX_IPV6_HDR 0x0080 |
RX packet with IPv6 header.
#define PKT_RX_IPV6_HDR_EXT 0x0100 |
RX packet with extended IPv6 header.
#define PKT_RX_L4_CKSUM_BAD 0x0008 |
L4 cksum of RX pkt. is not OK.
#define PKT_RX_RSS_HASH 0x0002 |
RX packet with RSS hash result.
#define PKT_RX_VLAN_PKT 0x0001 |
RX packet is a 802.1q VLAN packet.
#define PKT_TX_IEEE1588_TMST 0x8000 |
TX IEEE1588 packet to timestamp.
#define PKT_TX_IP_CKSUM 0x1000 |
IP cksum of TX pkt. computed by NIC.
#define PKT_TX_L4_MASK 0x6000 |
Mask bits for L4 checksum offload request.
#define PKT_TX_L4_NO_CKSUM 0x0000 |
Disable L4 cksum of TX pkt.
#define PKT_TX_OFFLOAD_MASK (PKT_TX_VLAN_PKT | PKT_TX_IP_CKSUM | PKT_TX_L4_MASK) |
Bit Mask to indicate what bits required for building TX context
#define PKT_TX_SCTP_CKSUM 0x4000 |
SCTP cksum of TX pkt. computed by NIC.
#define PKT_TX_TCP_CKSUM 0x2000 |
TCP cksum of TX pkt. computed by NIC.
#define PKT_TX_UDP_CKSUM 0x6000 |
UDP cksum of TX pkt. computed by NIC.
#define PKT_TX_VLAN_PKT 0x0800 |
TX packet is a 802.1q VLAN packet.
#define rte_ctrlmbuf_data | ( | m | ) | ((m)->ctrl.data) |
A macro that returns the pointer to the carried data.
The value that can be read or assigned.
m | The control mbuf. |
#define rte_ctrlmbuf_len | ( | m | ) | ((m)->ctrl.data_len) |
A macro that returns the length of the carried data.
The value that can be read or assigned.
m | The control mbuf. |
#define RTE_MBUF_ASSERT | ( | exp | ) | do { } while(0) |
MBUF asserts in debug mode
#define RTE_MBUF_DIRECT | ( | mb | ) | (RTE_MBUF_FROM_BADDR((mb)->buf_addr) == (mb)) |
Returns TRUE if given mbuf is direct, or FALSE otherwise.
#define RTE_MBUF_FROM_BADDR | ( | ba | ) | (((struct rte_mbuf *)(ba)) - 1) |
Given the buf_addr returns the pointer to corresponding mbuf.
#define RTE_MBUF_INDIRECT | ( | mb | ) | (RTE_MBUF_FROM_BADDR((mb)->buf_addr) != (mb)) |
Returns TRUE if given mbuf is indirect, or FALSE otherwise.
#define RTE_MBUF_PREFETCH_TO_FREE | ( | m | ) |
Mbuf prefetch
#define RTE_MBUF_TO_BADDR | ( | mb | ) | (((struct rte_mbuf *)(mb)) + 1) |
Given the pointer to mbuf returns an address where it's buf_addr should point to.
#define rte_pktmbuf_data_len | ( | m | ) | ((m)->pkt.data_len) |
A macro that returns the length of the segment.
The value can be read or assigned.
m | The packet mbuf. |
#define rte_pktmbuf_mtod | ( | m, | |
t | |||
) | ((t)((m)->pkt.data)) |
A macro that points to the start of the data in the mbuf.
The returned pointer is cast to type t. Before using this function, the user must ensure that m_headlen(m) is large enough to read its data.
m | The packet mbuf. |
t | The type to cast the result into. |
#define rte_pktmbuf_pkt_len | ( | m | ) | ((m)->pkt.pkt_len) |
A macro that returns the length of the packet.
The value can be read or assigned.
m | The packet mbuf. |
#define TX_IP_LEN_CMP_MASK 0x000001FF |
IP length - 9-bits. MAC+IP length.
#define TX_MAC_LEN_CMP_MASK 0x0000FE00 |
MAC length - 7-bits.
#define TX_VLAN_CMP_MASK 0xFFFF0000 |
VLAN length - 16-bits.
enum rte_mbuf_type |
|
staticread |
Allocate a new mbuf (type is ctrl) from mempool mp.
This new mbuf is initialized with data pointing to the beginning of buffer, and with a length of zero.
mp | The mempool from which the mbuf is allocated. |
|
inlinestatic |
Free a control mbuf back into its original mempool.
m | The control mbuf to be freed. |
void rte_ctrlmbuf_init | ( | struct rte_mempool * | mp, |
void * | opaque_arg, | ||
void * | m, | ||
unsigned | i | ||
) |
The control mbuf constructor.
This function initializes some fields in an mbuf structure that are not modified by the user once created (mbuf type, origin pool, buffer start address, and so on). This function is given as a callback function to rte_mempool_create() at pool creation time.
mp | The mempool from which the mbuf is allocated. |
opaque_arg | A pointer that can be used by the user to retrieve useful information for mbuf initialization. This pointer comes from the init_arg parameter of rte_mempool_create(). |
m | The mbuf to initialize. |
i | The index of the mbuf in the pool table. |
|
inlinestatic |
Reads the value of an mbuf's refcnt.
|
inlinestatic |
Sets an mbuf's refcnt to the defined value.
|
inlinestatic |
Adds given value to an mbuf's refcnt and returns its new value.
void rte_mbuf_sanity_check | ( | const struct rte_mbuf * | m, |
enum rte_mbuf_type | t, | ||
int | is_header | ||
) |
Sanity checks on an mbuf.
Check the consistency of the given mbuf. The function will cause a panic if corruption is detected.
m | The mbuf to be checked. |
t | The expected type of the mbuf. |
is_header | True if the mbuf is a packet header, false if it is a sub-segment of a packet (in this case, some fields like nb_segs are not checked) |
|
inlinestatic |
Remove len bytes at the beginning of an mbuf.
Returns a pointer to the start address of the new data area. If the length is greater than the length of the first segment, then the function will fail and return NULL, without modifying the mbuf.
m | The packet mbuf. |
len | The amount of data to remove (in bytes). |
|
staticread |
Allocate a new mbuf (type is pkt) from a mempool.
This new mbuf contains one segment, which has a length of 0. The pointer to data is initialized to have some bytes of headroom in the buffer (if buffer size allows).
mp | The mempool from which the mbuf is allocated. |
|
inlinestatic |
Append len bytes to an mbuf.
Append len bytes to an mbuf and return a pointer to the start address of the added data. If there is not enough tailroom in the last segment, the function will return NULL, without modifying the mbuf.
m | The packet mbuf. |
len | The amount of data to append (in bytes). |
Attach packet mbuf to another packet mbuf. After attachment we refer the mbuf we attached as 'indirect', while mbuf we attached to as 'direct'. Right now, not supported:
mi | The indirect packet mbuf. |
md | The direct packet mbuf. |
|
staticread |
Creates a "clone" of the given packet mbuf.
Walks through all segments of the given packet mbuf, and for each of them:
md | The packet mbuf to be cloned. |
mp | The mempool from which the "clone" mbufs are allocated. |
|
inlinestatic |
Detach an indirect packet mbuf -
m | The indirect attached packet mbuf. |
void rte_pktmbuf_dump | ( | const struct rte_mbuf * | m, |
unsigned | dump_len | ||
) |
Dump an mbuf structure to the console.
Dump all fields for the given packet mbuf and all its associated segments (in the case of a chained buffer).
m | The packet mbuf. |
dump_len | If dump_len != 0, also dump the "dump_len" first data bytes of the packet. |
|
inlinestatic |
Free a packet mbuf back into its original mempool.
Free an mbuf, and all its segments in case of chained buffers. Each segment is added back into its original mempool.
m | The packet mbuf to be freed. |
|
inlinestatic |
Free a segment of a packet mbuf into its original mempool.
Free an mbuf, without parsing other segments in case of chained buffers.
m | The packet mbuf segment to be freed. |
|
inlinestatic |
Get the headroom in a packet mbuf.
m | The packet mbuf. |
void rte_pktmbuf_init | ( | struct rte_mempool * | mp, |
void * | opaque_arg, | ||
void * | m, | ||
unsigned | i | ||
) |
The packet mbuf constructor.
This function initializes some fields in the mbuf structure that are not modified by the user once created (mbuf type, origin pool, buffer start address, and so on). This function is given as a callback function to rte_mempool_create() at pool creation time.
mp | The mempool from which mbufs originate. |
opaque_arg | A pointer that can be used by the user to retrieve useful information for mbuf initialization. This pointer comes from the init_arg parameter of rte_mempool_create(). |
m | The mbuf to initialize. |
i | The index of the mbuf in the pool table. |
|
inlinestatic |
Test if mbuf data is contiguous.
m | The packet mbuf. |
Get the last segment of the packet.
m | The packet mbuf. |
void rte_pktmbuf_pool_init | ( | struct rte_mempool * | mp, |
void * | opaque_arg | ||
) |
A packet mbuf pool constructor.
This function initializes the mempool private data in the case of a pktmbuf pool. This private data is needed by the driver. The function is given as a callback function to rte_mempool_create() at pool creation. It can be extended by the user, for example, to provide another packet size.
mp | The mempool from which mbufs originate. |
opaque_arg | A pointer that can be used by the user to retrieve useful information for mbuf initialization. This pointer comes from the init_arg parameter of rte_mempool_create(). |
|
inlinestatic |
Prepend len bytes to an mbuf data area.
Returns a pointer to the new data start address. If there is not enough headroom in the first segment, the function will return NULL, without modifying the mbuf.
m | The pkt mbuf. |
len | The amount of data to prepend (in bytes). |
|
inlinestatic |
Adds given value to the refcnt of all packet mbuf segments.
Walks through all segments of given packet mbuf and for each of them invokes rte_mbuf_refcnt_update().
m | The packet mbuf whose refcnt to be updated. |
v | The value to add to the mbuf's segments refcnt. |
|
inlinestatic |
Reset the fields of a packet mbuf to their default values.
The given mbuf must have only one segment.
m | The packet mbuf to be resetted. |
|
inlinestatic |
Get the tailroom of a packet mbuf.
m | The packet mbuf. |
|
inlinestatic |
Remove len bytes of data at the end of the mbuf.
If the length is greater than the length of the last segment, the function will fail and return -1 without modifying the mbuf.
m | The packet mbuf. |
len | The amount of data to remove (in bytes). |