libpcap  1.10.1
About: libpcap is a packet filter library used by tools like tcpdump.
  Fossies Dox: libpcap-1.10.1.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

pcap-dpdk.c File Reference
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <rte_config.h>
#include <rte_common.h>
#include <rte_errno.h>
#include <rte_log.h>
#include <rte_malloc.h>
#include <rte_memory.h>
#include <rte_eal.h>
#include <rte_launch.h>
#include <rte_atomic.h>
#include <rte_cycles.h>
#include <rte_lcore.h>
#include <rte_per_lcore.h>
#include <rte_branch_prediction.h>
#include <rte_interrupts.h>
#include <rte_random.h>
#include <rte_debug.h>
#include <rte_ether.h>
#include <rte_ethdev.h>
#include <rte_mempool.h>
#include <rte_mbuf.h>
#include <rte_bus.h>
#include "pcap-int.h"
#include "pcap-dpdk.h"
Include dependency graph for pcap-dpdk.c:

Go to the source code of this file.

Data Structures

struct  dpdk_ts_helper
 
struct  pcap_dpdk
 

Macros

#define ETHER_ADDR_TYPE   struct ether_addr
 
#define DPDK_DEF_LOG_LEV   RTE_LOG_ERR
 
#define DPDK_LIB_NAME   "libpcap_dpdk"
 
#define DPDK_DESC   "Data Plane Development Kit (DPDK) Interface"
 
#define DPDK_ERR_PERM_MSG   "permission denied, DPDK needs root permission"
 
#define DPDK_ARGC_MAX   64
 
#define DPDK_CFG_MAX_LEN   1024
 
#define DPDK_DEV_NAME_MAX   32
 
#define DPDK_DEV_DESC_MAX   512
 
#define DPDK_CFG_ENV_NAME   "DPDK_CFG"
 
#define DPDK_DEF_MIN_SLEEP_MS   1
 
#define DPDK_MAC_ADDR_SIZE   32
 
#define DPDK_DEF_MAC_ADDR   "00:00:00:00:00:00"
 
#define DPDK_PCI_ADDR_SIZE   16
 
#define DPDK_DEF_CFG   "--log-level=error -l0 -dlibrte_pmd_e1000.so -dlibrte_pmd_ixgbe.so -dlibrte_mempool_ring.so"
 
#define DPDK_PREFIX   "dpdk:"
 
#define DPDK_PORTID_MAX   65535U
 
#define MBUF_POOL_NAME   "mbuf_pool"
 
#define DPDK_TX_BUF_NAME   "tx_buffer"
 
#define DPDK_NB_MBUFS   8192U
 
#define MEMPOOL_CACHE_SIZE   256
 
#define MAX_PKT_BURST   32
 
#define RTE_TEST_RX_DESC_DEFAULT   1024
 
#define RTE_TEST_TX_DESC_DEFAULT   1024
 
#define RTE_ETH_PCAP_SNAPLEN   ETHER_MAX_JUMBO_FRAME_LEN
 

Functions

static void dpdk_fmt_errmsg_for_rte_errno (char *, size_t, int, const char *,...)
 
static int dpdk_init_timer (struct pcap_dpdk *pd)
 
static void calculate_timestamp (struct dpdk_ts_helper *helper, struct timeval *ts)
 
static uint32_t dpdk_gather_data (unsigned char *data, uint32_t len, struct rte_mbuf *mbuf)
 
static int dpdk_read_with_timeout (pcap_t *p, struct rte_mbuf **pkts_burst, const uint16_t burst_cnt)
 
static int pcap_dpdk_dispatch (pcap_t *p, int max_cnt, pcap_handler cb, u_char *cb_arg)
 
static int pcap_dpdk_inject (pcap_t *p, const void *buf, int size)
 
static void pcap_dpdk_close (pcap_t *p)
 
static void nic_stats_display (struct pcap_dpdk *pd)
 
static int pcap_dpdk_stats (pcap_t *p, struct pcap_stat *ps)
 
static int pcap_dpdk_setnonblock (pcap_t *p, int nonblock)
 
static int pcap_dpdk_getnonblock (pcap_t *p)
 
static int check_link_status (uint16_t portid, struct rte_eth_link *plink)
 
static void eth_addr_str (struct ether_addr *addrp, char *mac_str, int len)
 
static uint16_t portid_by_device (char *device)
 
static int parse_dpdk_cfg (char *dpdk_cfg, char **dargv)
 
static int dpdk_pre_init (char *ebuf, int eaccess_not_fatal)
 
static int pcap_dpdk_activate (pcap_t *p)
 
pcap_tpcap_dpdk_create (const char *device, char *ebuf, int *is_ours)
 
int pcap_dpdk_findalldevs (pcap_if_list_t *devlistp, char *ebuf)
 

Variables

static int is_dpdk_pre_inited =0
 
static char dpdk_cfg_buf [1024]
 
static uint16_t nb_rxd = 1024
 
static uint16_t nb_txd = 1024
 
static struct rte_eth_dev_tx_buffer * tx_buffer
 
static struct rte_eth_conf port_conf
 

Macro Definition Documentation

◆ DPDK_ARGC_MAX

#define DPDK_ARGC_MAX   64

Definition at line 139 of file pcap-dpdk.c.

◆ DPDK_CFG_ENV_NAME

#define DPDK_CFG_ENV_NAME   "DPDK_CFG"

Definition at line 143 of file pcap-dpdk.c.

◆ DPDK_CFG_MAX_LEN

#define DPDK_CFG_MAX_LEN   1024

Definition at line 140 of file pcap-dpdk.c.

◆ DPDK_DEF_CFG

#define DPDK_DEF_CFG   "--log-level=error -l0 -dlibrte_pmd_e1000.so -dlibrte_pmd_ixgbe.so -dlibrte_mempool_ring.so"

Definition at line 149 of file pcap-dpdk.c.

◆ DPDK_DEF_LOG_LEV

#define DPDK_DEF_LOG_LEV   RTE_LOG_ERR

Definition at line 128 of file pcap-dpdk.c.

◆ DPDK_DEF_MAC_ADDR

#define DPDK_DEF_MAC_ADDR   "00:00:00:00:00:00"

Definition at line 147 of file pcap-dpdk.c.

◆ DPDK_DEF_MIN_SLEEP_MS

#define DPDK_DEF_MIN_SLEEP_MS   1

Definition at line 144 of file pcap-dpdk.c.

◆ DPDK_DESC

#define DPDK_DESC   "Data Plane Development Kit (DPDK) Interface"

Definition at line 137 of file pcap-dpdk.c.

◆ DPDK_DEV_DESC_MAX

#define DPDK_DEV_DESC_MAX   512

Definition at line 142 of file pcap-dpdk.c.

◆ DPDK_DEV_NAME_MAX

#define DPDK_DEV_NAME_MAX   32

Definition at line 141 of file pcap-dpdk.c.

◆ DPDK_ERR_PERM_MSG

#define DPDK_ERR_PERM_MSG   "permission denied, DPDK needs root permission"

Definition at line 138 of file pcap-dpdk.c.

◆ DPDK_LIB_NAME

#define DPDK_LIB_NAME   "libpcap_dpdk"

Definition at line 136 of file pcap-dpdk.c.

◆ DPDK_MAC_ADDR_SIZE

#define DPDK_MAC_ADDR_SIZE   32

Definition at line 146 of file pcap-dpdk.c.

◆ DPDK_NB_MBUFS

#define DPDK_NB_MBUFS   8192U

Definition at line 155 of file pcap-dpdk.c.

◆ DPDK_PCI_ADDR_SIZE

#define DPDK_PCI_ADDR_SIZE   16

Definition at line 148 of file pcap-dpdk.c.

◆ DPDK_PORTID_MAX

#define DPDK_PORTID_MAX   65535U

Definition at line 151 of file pcap-dpdk.c.

◆ DPDK_PREFIX

#define DPDK_PREFIX   "dpdk:"

Definition at line 150 of file pcap-dpdk.c.

◆ DPDK_TX_BUF_NAME

#define DPDK_TX_BUF_NAME   "tx_buffer"

Definition at line 153 of file pcap-dpdk.c.

◆ ETHER_ADDR_TYPE

#define ETHER_ADDR_TYPE   struct ether_addr

Definition at line 125 of file pcap-dpdk.c.

◆ MAX_PKT_BURST

#define MAX_PKT_BURST   32

Definition at line 157 of file pcap-dpdk.c.

◆ MBUF_POOL_NAME

#define MBUF_POOL_NAME   "mbuf_pool"

Definition at line 152 of file pcap-dpdk.c.

◆ MEMPOOL_CACHE_SIZE

#define MEMPOOL_CACHE_SIZE   256

Definition at line 156 of file pcap-dpdk.c.

◆ RTE_ETH_PCAP_SNAPLEN

#define RTE_ETH_PCAP_SNAPLEN   ETHER_MAX_JUMBO_FRAME_LEN

Definition at line 168 of file pcap-dpdk.c.

◆ RTE_TEST_RX_DESC_DEFAULT

#define RTE_TEST_RX_DESC_DEFAULT   1024

Definition at line 159 of file pcap-dpdk.c.

◆ RTE_TEST_TX_DESC_DEFAULT

#define RTE_TEST_TX_DESC_DEFAULT   1024

Definition at line 160 of file pcap-dpdk.c.

Function Documentation

◆ calculate_timestamp()

static void calculate_timestamp ( struct dpdk_ts_helper helper,
struct timeval *  ts 
)
inlinestatic

◆ check_link_status()

static int check_link_status ( uint16_t  portid,
struct rte_eth_link *  plink 
)
static

Definition at line 482 of file pcap-dpdk.c.

References pcap_dpdk::portid.

Referenced by pcap_dpdk_activate().

◆ dpdk_fmt_errmsg_for_rte_errno()

static void dpdk_fmt_errmsg_for_rte_errno ( char *  errbuf,
size_t  errbuflen,
int  errnum,
const char *  fmt,
  ... 
)
static

Definition at line 215 of file pcap-dpdk.c.

References snprintf(), and vsnprintf().

Referenced by dpdk_pre_init(), and pcap_dpdk_activate().

◆ dpdk_gather_data()

static uint32_t dpdk_gather_data ( unsigned char *  data,
uint32_t  len,
struct rte_mbuf *  mbuf 
)
static

Definition at line 275 of file pcap-dpdk.c.

Referenced by pcap_dpdk_dispatch().

◆ dpdk_init_timer()

static int dpdk_init_timer ( struct pcap_dpdk pd)
static

Definition at line 255 of file pcap-dpdk.c.

References gettimeofday(), and pd.

Referenced by pcap_dpdk_activate().

◆ dpdk_pre_init()

◆ dpdk_read_with_timeout()

static int dpdk_read_with_timeout ( pcap_t p,
struct rte_mbuf **  pkts_burst,
const uint16_t  burst_cnt 
)
static

Definition at line 287 of file pcap-dpdk.c.

References pcap::break_loop, DPDK_DEF_MIN_SLEEP_MS, pcap::opt, pd, pcap::priv, and pcap_opt::timeout.

Referenced by pcap_dpdk_dispatch().

◆ eth_addr_str()

static void eth_addr_str ( struct ether_addr *  addrp,
char *  mac_str,
int  len 
)
static

Definition at line 488 of file pcap-dpdk.c.

References DPDK_DEF_MAC_ADDR, and snprintf().

Referenced by pcap_dpdk_activate().

◆ nic_stats_display()

static void nic_stats_display ( struct pcap_dpdk pd)
static

Definition at line 436 of file pcap-dpdk.c.

References pd, and pcap_dpdk::portid.

Referenced by pcap_dpdk_stats().

◆ parse_dpdk_cfg()

static int parse_dpdk_cfg ( char *  dpdk_cfg,
char **  dargv 
)
static

Definition at line 542 of file pcap-dpdk.c.

References DPDK_ARGC_MAX, and skip_space().

Referenced by dpdk_pre_init().

◆ pcap_dpdk_activate()

◆ pcap_dpdk_close()

static void pcap_dpdk_close ( pcap_t p)
static

Definition at line 420 of file pcap-dpdk.c.

References pcap_cleanup_live_common(), pd, and pcap::priv.

Referenced by pcap_dpdk_activate().

◆ pcap_dpdk_create()

pcap_t* pcap_dpdk_create ( const char *  device,
char *  ebuf,
int *  is_ours 
)

Definition at line 966 of file pcap-dpdk.c.

References pcap::activate_op, PCAP_CREATE_COMMON, and pcap_dpdk_activate().

◆ pcap_dpdk_dispatch()

◆ pcap_dpdk_findalldevs()

int pcap_dpdk_findalldevs ( pcap_if_list_t devlistp,
char *  ebuf 
)

Definition at line 983 of file pcap-dpdk.c.

◆ pcap_dpdk_getnonblock()

static int pcap_dpdk_getnonblock ( pcap_t p)
static

Definition at line 478 of file pcap-dpdk.c.

References pd, and pcap::priv.

Referenced by pcap_dpdk_activate().

◆ pcap_dpdk_inject()

static int pcap_dpdk_inject ( pcap_t p,
const void *  buf,
int  size 
)
static

Definition at line 411 of file pcap-dpdk.c.

References pcap::errbuf, PCAP_ERRBUF_SIZE, PCAP_ERROR, and pcap_strlcpy().

Referenced by pcap_dpdk_activate().

◆ pcap_dpdk_setnonblock()

static int pcap_dpdk_setnonblock ( pcap_t p,
int  nonblock 
)
static

Definition at line 472 of file pcap-dpdk.c.

References pcap_dpdk::nonblock, pd, and pcap::priv.

Referenced by pcap_dpdk_activate().

◆ pcap_dpdk_stats()

static int pcap_dpdk_stats ( pcap_t p,
struct pcap_stat ps 
)
static

◆ portid_by_device()

static uint16_t portid_by_device ( char *  device)
static

Definition at line 513 of file pcap-dpdk.c.

References DPDK_PORTID_MAX, and DPDK_PREFIX.

Referenced by pcap_dpdk_activate().

Variable Documentation

◆ dpdk_cfg_buf

char dpdk_cfg_buf[1024]
static

Definition at line 145 of file pcap-dpdk.c.

Referenced by dpdk_pre_init().

◆ is_dpdk_pre_inited

int is_dpdk_pre_inited =0
static

Definition at line 135 of file pcap-dpdk.c.

Referenced by dpdk_pre_init().

◆ nb_rxd

uint16_t nb_rxd = 1024
static

Definition at line 162 of file pcap-dpdk.c.

Referenced by pcap_dpdk_activate().

◆ nb_txd

uint16_t nb_txd = 1024
static

Definition at line 163 of file pcap-dpdk.c.

Referenced by pcap_dpdk_activate().

◆ port_conf

struct rte_eth_conf port_conf
static
Initial value:
= {
.rxmode = {
.split_hdr_size = 0,
},
.txmode = {
.mq_mode = ETH_MQ_TX_NONE,
},
}

Definition at line 171 of file pcap-dpdk.c.

Referenced by pcap_dpdk_activate().

◆ tx_buffer

struct rte_eth_dev_tx_buffer* tx_buffer
static

Definition at line 171 of file pcap-dpdk.c.

Referenced by pcap_dpdk_activate().