T0TOsoundlink mini说明书安装说明

41869人阅读
android(5)
上篇文章《》中,我们给大家介绍了,如何在移动领域使用灵巧的消息传输协议MQTT来完成消息推送,最后也提到了开源项目Mosquitto。实际上,Mosquitto是一个实现了MQTT3.1协议的代理服务器,由MQTT协议创始人之一的Andy Stanford-Clark开发,它为我们提供了非常棒的轻量级数据交换的解决方案。本文的主旨在于记录Mosquitto服务的安装和使用,以备日后查阅。1、获取&安装Mosquitto提供了Windows、Linux以及qnx系统的版本,安装文件可从地址中获取(建议使用最新的1.1.x版本)。Windows系统下的安装过程非常简单,我们甚至可以把Mosquitto直接安装成为系统服务;但是,在实际应用中,我们更倾向于使用Linux系统的服务器,接下来我们就将重点介绍Linux版Mosquitto的安装方法。在Linux系统上安装Mosquitto,本人建议大家使用源码安装模式,最新的源码可从地址中获取。解压之后,我们可以在源码目录里面找到主要的配置文件config.mk,其中包含了所有Mosquitto的安装选项,详细的参数说明如下:# 是否支持tcpd/libwrap功能.
#WITH_WRAP:=yes
# 是否开启SSL/TLS支持
#WITH_TLS:=yes
# 是否开启TLS/PSK支持
#WITH_TLS_PSK:=yes
# Comment out to disable client client threading support.
#WITH_THREADING:=yes
# 是否使用严格的协议版本(老版本兼容会有点问题)
#WITH_STRICT_PROTOCOL:=yes
# 是否开启桥接模式
#WITH_BRIDGE:=yes
# 是否开启持久化功能
#WITH_PERSISTENCE:=yes
# 是否监控运行状态
#WITH_MEMORY_TRACKING:=yes这里需要注意的是,默认情况下Mosquitto的安装需要OpenSSL的支持;如果不需要SSL,则需要关闭config.mk里面的某些与SSL功能有关的选项(WITH_TLS、WITH_TLS_PSK)。接着,就是运行make install进行安装,完成之后会在系统命令行里发现mosquitto、mosquitto_passwd、mosquitto_pub和mosquitto_sub四个工具(截图如下),分别用于启动代理、管理密码、发布消息和订阅消息。2、配置&运行安装完成之后,所有配置文件会被放置于/etc/mosquitto/目录下,其中最重要的就是Mosquitto的配置文件,即mosquitto.conf,以下是详细的配置参数说明。# =================================================================
# General configuration
# =================================================================
# 客户端心跳的间隔时间
#retry_interval 20
# 系统状态的刷新时间
#sys_interval 10
# 系统资源的回收时间,0表示尽快处理
#store_clean_interval 10
# 服务进程的PID
#pid_file /var/run/mosquitto.pid
# 服务进程的系统用户
#user mosquitto
# 客户端心跳消息的最大并发数
#max_inflight_messages 10
# 客户端心跳消息缓存队列
#max_queued_messages 100
# 用于设置客户端长连接的过期时间,默认永不过期
#persistent_client_expiration
# =================================================================
# Default listener
# =================================================================
# 服务绑定的IP地址
#bind_address
# 服务绑定的端口号
#port 1883
# 允许的最大连接数,-1表示没有限制
#max_connections -1
# cafile:CA证书文件
# capath:CA证书目录
# certfile:PEM证书文件
# keyfile:PEM密钥文件
# 必须提供证书以保证数据安全性
#require_certificate false
# 若require_certificate值为true,use_identity_as_username也必须为true
#use_identity_as_username false
# 启用PSK(Pre-shared-key)支持
# SSL/TSL加密算法,可以使用“openssl ciphers”命令获取
# as the output of that command.
# =================================================================
# Persistence
# =================================================================
# 消息自动保存的间隔时间
#autosave_interval 1800
# 消息自动保存功能的开关
#autosave_on_changes false
# 持久化功能的开关
persistence true
# 持久化DB文件
#persistence_file mosquitto.db
# 持久化DB文件目录
#persistence_location /var/lib/mosquitto/
# =================================================================
# =================================================================
# 4种日志模式:stdout、stderr、syslog、topic
# none 则表示不记日志,此配置可以提升些许性能
log_dest none
# 选择日志的级别(可设置多项)
#log_type error
#log_type warning
#log_type notice
#log_type information
# 是否记录客户端连接信息
#connection_messages true
# 是否记录日志时间
#log_timestamp true
# =================================================================
# Security
# =================================================================
# 客户端ID的前缀限制,可用于保证安全性
#clientid_prefixes
# 允许匿名用户
#allow_anonymous true
# 用户/密码文件,默认格式:username:password
#password_file
# PSK格式密码文件,默认格式:identity:key
# pattern write sensor/%u/data
# ACL权限配置,常用语法如下:
# 用户限制:user &username&
# 话题限制:topic [read|write] &topic&
# 正则限制:pattern write sensor/%u/data
# =================================================================
# =================================================================
# 允许服务之间使用“桥接”模式(可用于分布式部署)
#connection &name&
#address &host&[:&port&]
#topic &topic& [[[out | in | both] qos-level] local-prefix remote-prefix]
# 设置桥接的客户端ID
# 桥接断开时,是否清除远程服务器中的消息
#cleansession false
# 是否发布桥接的状态信息
#notifications true
# 设置桥接模式下,消息将会发布到的话题地址
# $SYS/broker/connection/&clientid&/state
#notification_topic
# 设置桥接的keepalive数值
#keepalive_interval 60
# 桥接模式,目前有三种:automatic、lazy、once
#start_type automatic
# 桥接模式automatic的超时时间
#restart_timeout 30
# 桥接模式lazy的超时时间
#idle_timeout 60
# 桥接客户端的用户名
# 桥接客户端的密码
# bridge_cafile:桥接客户端的CA证书文件
# bridge_capath:桥接客户端的CA证书目录
# bridge_certfile:桥接客户端的PEM证书文件
# bridge_keyfile:桥接客户端的PEM密钥文件
#bridge_cafile
#bridge_capath
#bridge_certfile
#bridge_keyfile
# 自己的配置可以放到以下目录中
include_dir /etc/mosquitto/conf.d最后,启动Mosquitto服务很简单,直接运行命令行“mosquitto -c /etc/mosquitto/mosquitto.conf -d”即可开启服务。接下来,就让我们尽情体验Mosquitto的强大功能吧!当然,有了Mosquitto,我们就可以安心地抛弃“简陋”的rsmb了,有兴趣的话,大家还可以尝试把Mosquitto服务运用到上一篇的Android推送服务中。另外,Mosquitto是个异步IO框架,经测试可以轻松处理20000个以上的客户端连接。当然,实际的最大承载量还和业务的复杂度还有比较大的关系。下图是本人在一台普通Linux机器上进行的压力测试结果,大家可以参考。友情提醒:测试的时候不要忘记调整系统的最大连接数和栈大小,比如:Linux上可用ulimit -n20000 -s512命令设置你需要的系统参数。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:552400次
积分:5881
积分:5881
排名:第3027名
原创:97篇
评论:505条
(1)(1)(1)(1)(1)(2)(1)(1)(2)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(2)(2)(2)(1)(2)(1)(2)(1)(1)(1)(1)(1)(1)(2)(3)(4)(3)(1)(1)(1)(2)(5)(2)(1)(1)(1)(1)(2)(1)(1)(1)(2)(1)(1)(2)(2)(1)(1)(4)(3)(8)PF_RING API
API documentation for PF_RING: high-speed packet capture, filtering and analysis framework.
PF_RING library header file.
struct  
struct  
struct  
struct  
struct  
struct  
struct  
#define    65535
#define    4096
#define    500
#define    10 /* ns = 0.1 ms */
#define    
#define    1000 /* ns */
#define    500 /* # packets */
#define    pthread_mutex_t
#define    pthread_mutex_init
#define    pthread_mutex_lock
#define    pthread_mutex_lock
#define    pthread_mutex_unlock
#define    pthread_mutex_destroy
#define (a, b)   ((((a)-&tv_sec&(b)-&tv_sec)||(((a)-&tv_sec==(b)-&tv_sec)&&((a)-&tv_nsec&(b)-&tv_nsec)))?1:0)
#define (x)   __builtin_expect((x),1)
#define (x)   __builtin_expect((x),0)
#define (x)   __asm volatile(&prefetcht0 %0& :: &m& (*(const unsigned long *)x));
#define    32
#define    (1 &&
  flag: Set the hw RSS function to symmetric mode (both directions of the same flow go to the same hw queue).
#define    (1 &&
  flag: The device is open in reentrant mode.
#define    (1 &&
  flag: If uset, PF_RING does not fill the field extended_hdr of struct .
#define    (1 &&
  flag: The device is open in promiscuous mode.
#define    (1 &&
  flag: Force PF_RING to set the timestamp on received packets (usually it is not set when using zero-copy, for optimizing performance).
#define    (1 &&
  flag: Enable hw timestamping, when available.
#define    (1 &&
  flag: Enable fast forwarding support (see ).
#define    (1 &&
  flag: Set hw RSS to send all traffic to queue 0.
#define    (1 &&
  flag: Strip hw timestamp from the packet.
#define    (1 &&
  flag: Disable packet parsing also when 1-copy is used.
#define    (1 && 10)
  flag: Disable packet timestamping also when 1-copy is used.
#define    (1 && 11)
  flag: Enable chunk mode operations.
#define    (1 && 12)
  flag:
hardware timestamp support+stripping.
#define    (1 && 13)
  flag: Force userspace bpf even with standard drivers (not only with ZC).
#define    (1 && 14)
  flag: Do not touch/reprogram hw RSS
#define    (1 && 15)
  flag: / hardware timestamp support+stripping.
#define    (1 && 16)
  flag: Compute RSS on src/dst IP only (not 4-tuple)
#define    
#define    
typedef void(*  )(const struct
*h, const u_char *p, const u_char *user_bytes)
typedef struct  
typedef void 
enum   {
enum   {
enum   {
enum   { ,
*  (const char *device_name, u_int32_t caplen, u_int32_t )
 This call is used to initialize a PF_RING socket hence obtain a handle of type struct pfring that can be used in subsequent calls.
*  (const char *device_name, u_int32_t caplen, u_int32_t , u_int8_t consumer_plugin_id, char *consumer_data, u_int consumer_data_len)
 Same as , but initializes a kernel plugin for packet processing.
u_int8_t  (const char *device_name, u_int32_t caplen, u_int32_t ,
 This call is similar to
with the exception that in case of a multi RX-queue NIC, instead of opening a single ring for the whole device, several individual rings are open (one per RX-queue).
void  ( *ring)
 Shutdown a socket.
void  (u_short cpu_percentage)
 Set the scheduler priority for the current thread.
int  ( *ring,
looper, const u_char *user_bytes, u_int8_t wait_for_packet)
 Process ingress packets until
is called, or an error occurs.
void  ( *)
 Break a receive loop ( or blocking ).
void  ( *ring)
 This call is used to terminate an PF_RING device previously open.
int  ( *ring,
 Read ring statistics (packets received and dropped).
int  ( *ring, u_char **buffer, u_int buffer_len, struct
*hdr, u_int8_t wait_for_incoming_packet)
 This call returns an incoming packet when available.
int  ( *ring, u_char **buffer, u_int buffer_len, struct
*hdr, u_int8_t wait_for_incoming_packet, u_int8_t level, u_int8_t add_timestamp, u_int8_t add_hash)
 Same of , with additional parameters to force packet parsing.
int  ( *ring, u_char **metadata, u_int32_t *metadata_len)
 Get metadata for the last captured packet, if any.
int  ( *ring, u_int16_t watermark)
 Whenever a user-space application has to wait until incoming packets arrive, it can instruct PF_RING not to return from poll() call unless at least “watermark” packets have been returned.
int  ( *ring, u_int duration)
 Set the poll timeout when passive wait is used.
int  ( *ring, u_int16_t watermark)
 Set the number of packets that have to be enqueued in the egress queue before being sent on the wire.
int  ( *ring,
 Set a specified filtering rule into the NIC.
int  ( *ring, u_int16_t rule_id)
 Remove the specified filtering rule from the NIC.
int  ( *ring, u_int32_t channel_id)
 Set the device channel id to be used.
int  ( *ring, u_int64_t channel_mask)
 Set the channel mask to be used for packet capture.
int  ( *ring, char *name)
 Tell PF_RING the name of the application (usually argv[0]) that uses this ring.
int  ( *ring, char *stats)
 Set custom application statistics.
char *  ( *ring, char *path, u_int path_len)
 Return the filename where the application statistics can be read.
int  ( *ring, char *device_name)
 Bind a socket to a device.
int  ( *ring, char *pkt, u_int pkt_len, u_int8_t flush_packet)
 Send a raw packet (i.e.
int  ( *ring, char *pkt, u_int pkt_len, u_int8_t flush_packet, int if_index)
 Same as , with the possibility to specify the outgoing interface index.
int  ( *ring, char *pkt, u_int pkt_len, struct timespec *ts)
 Same as , but this function allows to send a raw packet returning the exact time (ns) it has been sent on the wire.
u_int8_t  ( *ring)
 Returns the number of RX channels (also known as RX queues) of the ethernet interface to which this ring is bound.
int  ( *ring, u_int32_t rate)
 Implement packet sampling directly into the kernel.
int  ( *ring,
level, u_int32_t additional_bytes)
 Set packet slicing level.
int  ( *ring)
 Returns the file descriptor associated to the specified ring.
int  ( *ring,
direction)
 Tell PF_RING to consider only those packets matching the specified direction.
int  ( *ring,
 Tell PF_RING if the application needs to send and/or receive packets to/from the socket.
int  ( *ring, u_int clusterId,
 This call allows a ring to be added to a cluster that can spawn across address spaces.
int  ( *ring)
 This call allows a ring to be removed from a previous joined cluster.
int  ( *ring, u_int32_t master_id)
 Set the master ring using the id (vanilla PF_RING only)
int  ( *ring,
 Set the master ring using the PF_RING handle (vanilla PF_RING only).
u_int16_t  ( *ring)
 Return the ring id.
u_int32_t  ( *ring)
 Return an estimation of the enqueued packets.
u_int8_t  ( *ring)
 Return the identifier of the kernel plugin responsible for consuming packets.
int  ( *ring, u_int8_t plugin_id, char *plugin_data, u_int plugin_data_len)
 Initialize the kernel plugin for packet processing.
int  ( *ring,
*rule_to_add, u_char add_rule)
 Add or remove a hash filtering rule.
int  ( *ring,
*rule_to_add)
 Add a wildcard filtering rule to an existing ring.
int  ( *ring, u_int16_t rule_id)
 Remove a previously added filtering rule.
int  ( *ring, u_int16_t inactivity_sec)
 Remove hash filtering rules inactive for the specified number of seconds.
int  ( *ring, u_int16_t inactivity_sec)
 Remove filtering rules inactive for the specified number of seconds.
int  ( *ring,
*rule, char *stats, u_int *stats_len)
 Read statistics of a hash filtering rule.
int  ( *ring, u_int16_t rule_id, char *stats, u_int *stats_len)
 Read statistics of a hash filtering rule.
int  ( *ring, u_int8_t rules_default_accept_policy)
 Set the default filtering policy.
int  ( *ring)
 Tells PF_RING to rehash incoming packets using a bi-directional hash function.
int  ( *ring, u_int wait_duration)
 Performs passive wait on a PF_RING socket, similar to the standard poll(), taking care of data structures synchronization.
int  ( *ring)
 Check if a packet is available.
int  ( *ring, struct timespec *ts)
 This call returns the arrival time of the next incoming packet, when available.
int  ( *ring, u_int64_t *timestamp_ns)
 This call returns the raw timestamp of the next incoming packet, when available.
void  (u_int32_t *version)
 Read the ring version.
int  ( *ring, u_int32_t *version)
 Read the ring version.
int  ( *ring, char *device_name)
 Set a reflector device to send all incoming packets.
int  ( *ring, u_char mac_address[6])
 Returns the MAC address of the device bound to the socket.
u_int16_t  ( *ring)
 Return the size of the PF_RING packet header (vanilla PF_RING only).
int  ( *ring, int *if_index)
 Returns the interface index of the device bound to the socket.
int  ( *ring, char *device_name, int *if_index)
 Return the interface index of the provided device.
int  ( *ring,
 Set a filtering device.
int  ( *ring, char *buffer, u_int buffer_len, u_int test_len)
 This call processes packets until
is called or an error occurs.
int  ( *ring)
 When a ring is created, it is not enabled (i.e.
int  ( *ring)
 Disable a ring.
int  ( *ring, char *filter_buffer)
 In order to set BPF filters through the PF_RING API it’s necessary to enable (this is the default) BPF support at compile time and link PF_RING-enabled applications against the -lpcap library (it is possible to disable the BPF support with "cd userland/lib/; ./configure --disable- make" to avoid linking libpcap).
int  ( *ring)
 Remove the BPF filter.
int  ( *ring,
 Sets the filtering mode (software only, hardware only, both software and hardware) in order to implicitly add/remove hardware rules by means of the same API functionality used for software (wildcard and hash) rules.
int  ( *ring, struct timespec *ts)
 Reads the time from the device hardware clock, when the adapter supports hardware timestamping.
int  ( *ring, struct timespec *ts)
 Sets the time in the device hardware clock, when the adapter supports hardware timestamping.
int  ( *ring, struct timespec *offset, int8_t sign)
 Adjust the time in the device hardware clock with an offset, when the adapter supports hardware timestamping.
void  ( *ring)
 Synchronizes the ingress ring indexes/registers with the kernel.
int  ( *ring, int tx_interface_id)
 Send the last received packet to the specified device.
int  ( *ring)
 Return the link status.
u_char *  ( *ring,
*pkt_handle)
 Return the pointer to the buffer pointed by the packet buffer handle.
int  ( *ring,
*pkt_handle, u_int32_t )
 Set the length of the packet.
int  ( *ring,
*pkt_handle, int if_index)
 Bind the buffer handle (handling a packet) to an interface id.
int  ( *ring,
*pkt_handle, int if_index)
 Add an interface index to the interface indexes bound to the buffer handle.
*  ( *ring)
 Allocate a packet buffer handle.
void  ( *ring,
*pkt_handle)
 Release a packet buffer handle previously allocated by pfring_alloc_pkt_buff.
int  ( *ring,
*pkt_handle, struct
*hdr, u_int8_t wait_for_incoming_packet)
 Same as , this function receive a packet filling the buffer pointed by the provided packet handle instead of returning a new buffer.
int  ( *ring,
*pkt_handle, u_int8_t flush_packet)
 Same as , this function send the packet pointed by the provided packet buffer handle.
int  ( *ring)
 Synchronizes the egress ring indexes/registers flushing enqueued packets.
int  ( *ring, char *string_to_search)
 Add a string to search in the packet payload (used for filtering).
void  ( *bundle,
 Initialize a bundle socket.
int  ( *bundle,
 Add a ring to a bundle socket.
int  ( *bundle, u_int wait_duration)
 Poll on a bundle socket.
int  ( *bundle, u_char **buffer, u_int buffer_len, struct
*hdr, u_int8_t wait_for_incoming_packet)
 Same as
on a bundle socket.
void  ( *bundle)
 Destroy a bundle socket.
void  ( *bundle)
 Close a bundle socket.
int  (u_char *pkt, struct
*hdr, u_int8_t level, u_int8_t add_timestamp, u_int8_t add_hash)
 Parse a packet.
int  (const char *device, int set_promisc)
 Set the promiscuous mode flag to a device.
int  ( *ring, int set_promisc)
 Set the promiscuous mode to bound device.
char *  (double val, char *buf, u_int buf_len, u_int8_t add_decimals)
 Format a number.
int  ( *ring, char *device_name, u_int8_t enable_rx, u_int8_t enable_tx)
 Enables rx and tx hardware timestamping, when the adapter supports it.
int  ( *ring)
 Return the size of the MTU.
int  ( *ring,
*settings)
 Return NIC settings: max packet length, num rx/tx slots (ZC only).
int  (char *buff, u_int buff_len, const u_char *p, const struct
 Print a packet (the header with parsing info must be provided).
int  (char *buff, u_int buff_len, const u_char *p, u_int , u_int caplen)
 Print a packet.
int  ( *ring, void **chunk,
*chunk_info, u_int8_t wait_for_incoming_chunk)
 Receive a packet chunk, if enabled via
int  ( *ring, char *custom_dev_name)
 Set a custom device name to which the socket is bound.
int  (u_char *buffer, u_int32_t buffer_len, struct timespec *ts)
 Reads a IXIA-formatted timestamp from an incoming packet and puts it into the timestamp variable.
void  (u_char *buffer, struct
 Strip a IXIA-formatted timestamp from an incoming packet.
int  (u_char *buffer, u_int32_t buffer_len, struct timespec *ts)
 Reads a VSS/APCON-formatted timestamp from an incoming packet and puts it into the timestamp variable.
void  (u_char *buffer, struct
 Strip an VSS/APCON-formatted timestamp from an incoming packet.
u_int32_t  ( *ring)
 Get interface speed.
int  (char *filter_buffer, u_int caplen, struct
void  (struct
int32_t  (time_t t)
PF_RING library header file.
This header file must be included in any PF_RING-based applications.
#define DEFAULT_POLL_DURATION   500
#define likely
   __builtin_expect((x),1)
#define MAX_CAPLEN   65535
#define MAX_NUM_BUNDLE_ELEMENTS   32
#define PAGE_SIZE   4096
#define PF_RING_CHUNK_MODE   (1 && 11)
flag: Enable chunk mode operations.
This mode is supported only by specific adapters and it's not for general purpose.
#define PF_RING_DNA_FIXED_RSS_Q_0   
#define PF_RING_DNA_SYMMETRIC_RSS   
#define PF_RING_DO_NOT_PARSE   (1 &&
flag: Disable packet parsing also when 1-copy is used.
(parsing already disabled in zero-copy)
#define PF_RING_DO_NOT_TIMESTAMP   (1 && 10)
flag: Disable packet timestamping also when 1-copy is used.
(sw timestamp already disabled in zero-copy)
#define PF_RING_HW_TIMESTAMP   (1 &&
flag: Enable hw timestamping, when available.
#define PF_RING_IXIA_TIMESTAMP   (1 && 12)
hardware timestamp support+stripping.
#define PF_RING_LONG_HEADER   (1 &&
flag: If uset, PF_RING does not fill the field extended_hdr of struct .
If set, the extended_hdr field is also properly filled. In case you do not need extended information, set this value to 0 in order to speedup the operation.
#define PF_RING_PROMISC   (1 &&
flag: The device is open in promiscuous mode.
#define PF_RING_REENTRANT   (1 &&
flag: The device is open in reentrant mode.
This is implemented by means of semaphores and it results is slightly worse performance. Use reentrant mode only for multithreaded applications.
#define PF_RING_RX_PACKET_BOUNCE   (1 &&
flag: Enable fast forwarding support (see ).
#define PF_RING_STRIP_HW_TIMESTAMP   (1 &&
flag: Strip hw timestamp from the packet.
#define PF_RING_TIMESTAMP   (1 &&
flag: Force PF_RING to set the timestamp on received packets (usually it is not set when using zero-copy, for optimizing performance).
#define PF_RING_USERSPACE_BPF   (1 && 13)
flag: Force userspace bpf even with standard drivers (not only with ZC).
#define PF_RING_VSS_APCON_TIMESTAMP   (1 && 15)
flag: / hardware timestamp support+stripping.
#define PF_RING_ZC_FIXED_RSS_Q_0   (1 &&
flag: Set hw RSS to send all traffic to queue 0.
Other queues can be selected using hw filters (ZC cards with hw filtering only).
#define PF_RING_ZC_IPONLY_RSS   (1 && 16)
flag: Compute RSS on src/dst IP only (not 4-tuple)
#define PF_RING_ZC_NOT_REPROGRAM_RSS   (1 && 14)
flag: Do not touch/reprogram hw RSS
#define PF_RING_ZC_SYMMETRIC_RSS   (1 &&
flag: Set the hw RSS function to symmetric mode (both directions of the same flow go to the same hw queue).
Supported by ZC drivers only. This option is also available with the PF_RING-aware libpcap via the PCAP_PF_RING_ZC_RSS environment variable.
#define POLL_QUEUE_MIN_LEN   500 /* # packets */
#define POLL_SLEEP_MAX   1000 /* ns */
#define POLL_SLEEP_MIN   
#define POLL_SLEEP_STEP   10 /* ns = 0.1 ms */
#define prefetch
   __asm volatile(&prefetcht0 %0& :: &m& (*(const unsigned long *)x));
#define pthread_rwlock_destroy   pthread_mutex_destroy
#define pthread_rwlock_init   pthread_mutex_init
#define pthread_rwlock_rdlock   pthread_mutex_lock
#define pthread_rwlock_t   pthread_mutex_t
#define pthread_rwlock_unlock   pthread_mutex_unlock
#define pthread_rwlock_wrlock   pthread_mutex_lock
#define timespec_is_before
   ((((a)-&tv_sec&(b)-&tv_sec)||(((a)-&tv_sec==(b)-&tv_sec)&&((a)-&tv_nsec&(b)-&tv_nsec)))?1:0)
#define unlikely
   __builtin_expect((x),0)
typedef struct
typedef void
typedef void(* pfringProcesssPacket)(const struct
*h, const u_char *p, const u_char *user_bytes)
Enumeratorpick_round_robin 
pick_fifo 
Enumeratorhardware_and_software 
hardware_only 
software_only 
EnumeratorFULL_PACKET_SLICING 
L2_SLICING 
L3_SLICING 
L4_SLICING 
EnumeratorPCAP_CHUNK 
PCAP_NSEC_CHUNK 
UNKNOWN_CHUNK_TYPE 
int32_t gmt_to_local
time_t 
int pfring_add_filtering_rule
rule_to_add 
Add a wildcard filtering rule to an existing ring.
Each rule will have a unique rule Id across the ring (i.e. two rings can have rules with the same id).
PF_RING allows filtering packets in two ways: precise (a.k.a. hash filtering) or wildcard filtering. Precise filtering is used when it is necessary to track a precise 6-tuple connection &vlan Id, protocol, source IP, source port, destination IP, destination port&. Wildcard filtering is used instead whenever a filter can have wildcards on some of its fields (e.g. match all UDP packets regardless of their destination). If some field is set to zero it will not participate in filter calculation.
Note about packet reflection: packet reflection is the ability to bridge packets in kernel without sending them to userspace and back. You can specify packet reflection inside the filtering rules.
typedef struct { ... char reflector_device_name[REFLECTOR_NAME_LEN]; ... } ;
In the reflector_device_name you need to specify a device name (e.g. eth0) on which packets matching the filter will be reflected. Make sure NOT to specify as reflection device the same device name on which you capture packets, as otherwise you will create a packet loop.
Parameters
ringThe PF_RING handle on which the rule will be added.
rule_to_addThe rule to add as defined in the last chapter of this document.
Returns0 on success, a negative value otherwise.
int pfring_add_hw_rule
rule 
Set a specified filtering rule into the NIC.
Note that no PF_RING filter is added, but only a NIC filter.
Some multi-queue modern network adapters feature "packet steering" capabilities. Using them it is possible to instruct the hardware NIC to assign selected packets to a specific RX queue. If the specified queue has an Id that exceeds the maximum queueId, such packet is discarded thus acting as a hardware firewall filter. Note: kernel packet filtering is not supported by ZC.
Parameters
ringThe PF_RING handle on which the rule will be added.
ruleThe filtering rule to be set in the NIC as defined in the last chapter of this document. All rule parameters should be defined, and if set to zero they do not participate to filtering.
Returns0 on success, a negative value otherwise (e.g. the rule to be added has wrong format or if the NIC to which this ring is bound does not support hardware filters).
int pfring_add_pkt_buff_ifindex
pkt_handle,
if_index 
Add an interface index to the interface indexes bound to the buffer handle.
This is used to specify the egress interfaces (fan-out) of a packet buffer.
Parameters
ringThe PF_RING handle.
pkt_handleThe packet handle.
if_indexThe interface index.
Returns0 on success, a negative value otherwise.
int pfring_adjust_device_clock
struct timespec * 
int8_t 
sign 
Adjust the time in the device hardware clock with an offset, when the adapter supports hardware timestamping.
Parameters
ringThe PF_RING handle.
offsetThe time offset.
signThe offset sign.
Returns0 on success, a negative value otherwise.
* pfring_alloc_pkt_buff
Allocate a packet buffer handle.
The memory is allocated by PF_RING into the kernel and it is managed by PF_RING (i.e. no free() on this memory) using the pfring_XXX_XXX calls.
Parameters
ringThe PF_RING handle.
ReturnsThe buffer handle.
int pfring_bind
char * 
device_name 
Bind a socket to a device.
Parameters
ringThe PF_RING handle.
device_nameThe device name.
Returns0 on success, a negative value otherwise.
void pfring_breakloop
Break a receive loop ( or blocking ).
Parameters
ringThe PF_RING handle.
int pfring_bundle_add
ring 
Add a ring to a bundle socket.
Parameters
bundleThe PF_RING bundle handle.
ringThe PF_RING handle to add.
Returns0 on success, a negative value otherwise.
void pfring_bundle_close
Close a bundle socket.
Parameters
bundleThe PF_RING bundle handle.
void pfring_bundle_destroy
Destroy a bundle socket.
Parameters
bundleThe PF_RING bundle handle.
void pfring_bundle_init
Initialize a bundle socket.
Parameters
bundleThe PF_RING bundle handle.
bundle_read_policyThe policy for reading ingress packets.
int pfring_bundle_poll
u_int 
wait_duration 
Poll on a bundle socket.
Parameters
bundleThe PF_RING bundle handle.
wait_durationThe poll duration.
ReturnsThe poll return value.
int pfring_bundle_read
u_char ** 
u_int 
buffer_len,
u_int8_t 
wait_for_incoming_packet 
on a bundle socket.
Parameters
bundleThe PF_RING bundle handle.
buffer_len
wait_for_incoming_packet
Returns0 in case of no packet being received (non-blocking), 1 in case of success, -1 in case of error.
void pfring_close
This call is used to terminate an PF_RING device previously open.
Note that you must always close a device before leaving an application. If unsure, you can close a device from a signal handler.
Parameters
ringThe PF_RING handle that we are attempting to close.
void pfring_config
u_short 
cpu_percentage)
Set the scheduler priority for the current thread.
Parameters
cpu_percentageThe priority.
int pfring_disable_ring
Disable a ring.
Parameters
ringThe PF_RING handle to disable.
Returns0 on success, a negative value otherwise.
int pfring_enable_hw_timestamp
char * 
device_name,
u_int8_t 
enable_rx,
u_int8_t 
enable_tx 
Enables rx and tx hardware timestamping, when the adapter supports it.
Parameters
ringThe PF_RING handle.
device_nameThe name of the device where timestamping will be enabled.
enable_rxFlag to enable rx timestamping.
enable_txFlag to enable tx timestamping.
Returns0 on success, a negative value otherwise.
int pfring_enable_ring
When a ring is created, it is not enabled (i.e.
incoming packets are dropped) until the above function is called.
Parameters
ringThe PF_RING handle to enable.
Returns0 on success, a negative value otherwise (e.g. the ring cannot be enabled).
int pfring_enable_rss_rehash
Tells PF_RING to rehash incoming packets using a bi-directional hash function.
This is also available with the PF_RING-aware libpcap via the PCAP_PF_RING_RSS_REHASH environment variable.
Parameters
ringThe PF_RING handle to query.
Returns0 on success, a negative value otherwise.
int pfring_flush_tx_packets
Synchronizes the egress ring indexes/registers flushing enqueued packets.
Parameters
ringThe PF_RING handle.
@return0 on success, a negative value otherwise.
char* pfring_format_numbers
double 
char * 
u_int 
u_int8_t 
add_decimals 
Format a number.
Parameters
valThe value.
bufThe destination buffer.
buf_lenThe destination buffer length.
add_decimalsA flag indicating whether to add decimals.
ReturnsThe produced string.
void pfring_free_bpf_filter
char* pfring_get_appl_stats_file_name
char * 
u_int 
path_len 
Return the filename where the application statistics can be read.
Parameters
ringThe PF_RING handle.
pathA user-allocated buffer on which the stats filename will be stored.
path_lenThe path len.
ReturnsThe path if success, NULL otherwise.
int pfring_get_bound_device_address
u_char 
mac_address[6] 
Returns the MAC address of the device bound to the socket.
Parameters
ringThe PF_RING handle to query.
mac_addressThe memory area where the MAC address will be copied.
Returns0 on success, a negative value otherwise.
int pfring_get_bound_device_ifindex
int * 
if_index 
Returns the interface index of the device bound to the socket.
Parameters
ringThe PF_RING handle to query.
if_indexThe memory area where the interface index will be copied
Returns0 on success, a negative value otherwise.
int pfring_get_card_settings
settings 
Return NIC settings: max packet length, num rx/tx slots (ZC only).
Parameters
ringThe PF_RING handle.
settingsThe card settings (output).
Returns0 on success, a negative value otherwise.
int pfring_get_device_clock
struct timespec * 
Reads the time from the device hardware clock, when the adapter supports hardware timestamping.
Parameters
ringThe PF_RING handle.
tsThe struct where time will be stored.
Returns0 on success, a negative value otherwise.
int pfring_get_device_ifindex
char * 
device_name,
int * 
if_index 
Return the interface index of the provided device.
Parameters
ringThe PF_RING handle.
device_nameThe device name.
if_indexThe memory area for storing the interface index.
Returns0 on success, a negative value otherwise.
int pfring_get_filtering_rule_stats
u_int16_t 
char * 
u_int * 
stats_len 
Read statistics of a hash filtering rule.
Parameters
ringThe PF_RING handle from which stats will be read.
rule_idThe rule id that identifies the rule for which stats are read.
statsA buffer allocated by the user that will contain the rule statistics. Please make sure that the buffer is large enough to contain the statistics. Such buffer will contain number of received and dropped packets.
stats_lenThe size (in bytes) of the stats buffer.
Returns0 on success, a negative value otherwise (e.g. the rule does not exist).
int pfring_get_hash_filtering_rule_stats
char * 
u_int * 
stats_len 
Read statistics of a hash filtering rule.
Parameters
ringThe PF_RING handle on which the rule will be added/removed.
ruleThe rule for which stats are read. This needs to be the same rule that has been previously added.
statsA buffer allocated by the user that will contain the rule statistics. Please make sure that the buffer is large enough to contain the statistics. Such buffer will contain plugin-defined data in case of kernel plugin, a
struct otherwise.
stats_lenThe size (in bytes) of the stats buffer.
Returns0 on success, a negative value otherwise (e.g. the rule to be removed does not exist).
u_int32_t pfring_get_interface_speed
Get interface speed.
Parameters
Returns0 if interface speed is unknown, the interface speed otherwise.
int pfring_get_link_status
Return the link status.
Parameters
ringThe PF_RING handle.
Returns1 if link is up, 0 otherwise.
int pfring_get_metadata
u_char ** 
u_int32_t * 
metadata_len 
Get metadata for the last captured packet, if any.
This is usually used with ZC SPSC queues for reading packet metadata.
Parameters
metadataPtr to a variable that will contain the packet metadata (out).
Returns0 if this is supported by the actual module and metadata is found, a negative error value otherwise.
int pfring_get_mtu_size
Return the size of the MTU.
Parameters
ringThe PF_RING handle.
ReturnsThe MTU size on success, a negative value otherwise.
u_int32_t pfring_get_num_queued_pkts
Return an estimation of the enqueued packets.
Parameters
ringThe PF_RING handle.
@return0 on success, a negative value otherwise.
u_int8_t pfring_get_num_rx_channels
Returns the number of RX channels (also known as RX queues) of the ethernet interface to which this ring is bound.
Parameters
ringThe PF_RING handle to query.
ReturnsThe number of RX channels, or 1 (default) in case this in information is unknown.
u_int8_t pfring_get_packet_consumer_mode
Return the identifier of the kernel plugin responsible for consuming packets.
Parameters
ringThe PF_RING handle.
ReturnsThe kernel plugin identifier.
u_char* pfring_get_pkt_buff_data
pkt_handle 
Return the pointer to the buffer pointed by the packet buffer handle.
Parameters
ringThe PF_RING handle.
pkt_handleThe packet handle.
ReturnsThe pointer to the packet buffer.
u_int16_t pfring_get_ring_id
Return the ring id.
Parameters
ringThe PF_RING handle.
ReturnsThe ring id.
int pfring_get_selectable_fd
Returns the file descriptor associated to the specified ring.
This number can be used in function calls such as poll() and select() for passively waiting for incoming packets.
Parameters
ringThe PF_RING handle to query.
ReturnsA number that can be used as reference to this ring, in function calls that require a selectable file descriptor.
u_int16_t pfring_get_slot_header_len
Return the size of the PF_RING packet header (vanilla PF_RING only).
Parameters
ringThe PF_RING handle.
ReturnsThe size of the packet header.
int pfring_handle_hash_filtering_rule
rule_to_add,
u_char 
add_rule 
Add or remove a hash filtering rule.
All rule parameters should be defined in the filtering rule (no wildcards).
Parameters
ringThe PF_RING handle from which stats will be read.
rule_to_addThe rule that will be added/removed as defined in the last chapter of this document. All rule parameters should be defined in the filtering rule (no wildcards).
add_ruleIf set to a positive value the rule is added, if zero the rule is removed.
Returns0 on success, a negative value otherwise (e.g. the rule to be removed does not exist).
void pfring_handle_ixia_hw_timestamp
u_char * 
Strip a IXIA-formatted timestamp from an incoming packet.
If the timestamp is found, the hdr parameter (caplen and len fields) are decreased by the size of the timestamp.
Parameters
bufferIncoming packet buffer.
hdrThis is an in/out parameter: it is used to read the original packet len, and it is updated (size decreased) if the hw timestamp is found
Returns0 on success, a negative value otherwise.
void pfring_handle_vss_apcon_hw_timestamp
u_char * 
Strip an VSS/APCON-formatted timestamp from an incoming packet.
If the timestamp is found, the hdr parameter (caplen and len fields) are decreased by the size of the timestamp.
Parameters
bufferIncoming packet buffer.
hdrThis is an in/out parameter: it is used to read the original packet len, and it is updated (size decreased) if the hw timestamp is found
Returns0 on success, a negative value otherwise.
int pfring_is_pkt_available
Check if a packet is available.
Parameters
ringThe PF_RING handle.
Returns1 if a packet is available, 0 otherwise.
int pfring_loop
const u_char * 
user_bytes,
u_int8_t 
wait_for_packet 
Process ingress packets until
is called, or an error occurs.
Parameters
ringThe PF_RING handle.
looperThe user callback for packet processing.
user_bytesThe user ptr passed to the callback.
wait_for_packetIf 0 active wait is used to check the packet availability.
Returns0 on success (), a negative value otherwise.
int pfring_loopback_test
char * 
u_int 
buffer_len,
u_int 
test_len 
This call processes packets until
is called or an error occurs.
Parameters
ringThe PF_RING handle.
looperA callback to be called for each received packet. The parameters passed to this routine are: a pointer to a struct , a pointer to the packet memory, and a pointer to user_bytes.
user_bytesA pointer to user’s data which is passed to the callback.
wait_for_packetIf 0 active wait is used to check the packet availability.
ReturnsA non-negative number if
is called. A negative number in case of error.
int pfring_next_pkt_raw_timestamp
u_int64_t * 
timestamp_ns 
This call returns the raw timestamp of the next incoming packet, when available.
This is available with adapters supporting rx hardware timestamping only.
Parameters
ringThe PF_RING handle where we perform the check.
timestamp_nsWhere the timestamp will be stored.
Returns0 in case of success, a negative number in case of error.
int pfring_next_pkt_time
struct timespec * 
This call returns the arrival time of the next incoming packet, when available.
Parameters
ringThe PF_RING handle where we perform the check.
tsThe struct where the time will be stored.
Returns0 in case of success, a negative number in case of error.
* pfring_open
const char * 
device_name,
u_int32_t 
u_int32_t 
flags 
This call is used to initialize a PF_RING socket hence obtain a handle of type struct pfring that can be used in subsequent calls.
Note that:
you can use physical (e.g. ethX) and virtual (e.g. tapX) devices, RX-queues (e.g. ethX), and additional modules (e.g. zc:ethX, dag:dagX:Y, "multi:ethA@X;ethB@Y;ethC@Z", "stack:ethX").
you need super-user capabilities in order to open a device. Parameters
device_nameSymbolic name of the PF_RING-aware device we’re attempting to open (e.g. eth0).
caplenMaximum packet capture len (also known as snaplen).
flagsIt allows several options to be specified on a compact format using bitmaps (see PF_RING_* macros).
ReturnsOn success a handle is returned, NULL otherwise.
* pfring_open_consumer
const char * 
device_name,
u_int32_t 
u_int32_t 
u_int8_t 
consumer_plugin_id,
char * 
consumer_data,
u_int 
consumer_data_len 
Same as , but initializes a kernel plugin for packet processing.
Parameters
device_name
consumer_plugin_idThe plugin id.
consumer_dataThe plugin data.
consumer_data_lenThe size of the plugin data.
ReturnsOn success a handle is returned, NULL otherwise.
u_int8_t pfring_open_multichannel
const char * 
device_name,
u_int32_t 
u_int32_t 
ring[MAX_NUM_RX_CHANNELS] 
This call is similar to
with the exception that in case of a multi RX-queue NIC, instead of opening a single ring for the whole device, several individual rings are open (one per RX-queue).
Parameters
device_nameSymbolic name of the PF_RING-aware device we’re attempting to open (e.g. eth0). No queue name hash to be specified, but just the main device name.
caplenMaximum packet capture len (also known as snaplen).
for details.
ringA pointer to an array of rings that will contain the opened ring pointers.
ReturnsThe last index of the ring array that contain a valid ring pointer.
int pfring_parse_bpf_filter
char * 
filter_buffer,
u_int 
filter 
int pfring_parse_pkt
u_char * 
u_int8_t 
u_int8_t 
add_timestamp,
u_int8_t 
add_hash 
Parse a packet.
It expects that the hdr memory is either zeroed or contains valid values for the current packet, in order to avoid parsing twice the same packet headers. This is implemented by controlling the l3_offset and l4_offset fields, indicating that respectively the L2 and L3 layers have been parsed when other than zero.
Parameters
pktThe packet buffer.
hdrThe header to be filled.
levelThe header level where to stop parsing.
add_timestampAdd the timestamp.
add_hashCompute an IP-based bidirectional hash.
ReturnsA non-negative number indicating the topmost header level on success, a negative value otherwise.
int pfring_poll
u_int 
wait_duration 
Performs passive wait on a PF_RING socket, similar to the standard poll(), taking care of data structures synchronization.
Parameters
ringThe PF_RING socket to poll.
wait_durationThe poll timeout in msec.
Returns0 on success, a negative value otherwise.
int pfring_print_parsed_pkt
char * 
u_int 
const u_char * 
const struct
Print a packet (the header with parsing info must be provided).
Parameters
buffThe destination buffer.
buff_lenThe destination buffer length.
pThe packet.
hThe header.
Returns0 on success, a negative value otherwise.
int pfring_print_pkt
char * 
u_int 
const u_char * 
u_int 
u_int 
caplen 
Print a packet.
Parameters
buffThe destination buffer.
buff_lenThe destination buffer length.
pThe packet.
caplenThe packet length.
Returns0 on success, a negative value otherwise.
int pfring_purge_idle_hash_rules
u_int16_t 
inactivity_sec 
Remove hash filtering rules inactive for the specified number of seconds.
Parameters
ringThe PF_RING handle on which the rules will be removed.
inactivity_secThe inactivity threshold.
Returns0 on success, a negative value otherwise.
int pfring_purge_idle_rules
u_int16_t 
inactivity_sec 
Remove filtering rules inactive for the specified number of seconds.
Parameters
ringThe PF_RING handle on which the rules will be removed.
inactivity_secThe inactivity threshold.
Returns0 on success, a negative value otherwise
int pfring_read_ixia_hw_timestamp
u_char * 
u_int32_t 
buffer_len,
struct timespec * 
Reads a IXIA-formatted timestamp from an incoming packet and puts it into the timestamp variable.
Parameters
bufferIncoming packet buffer.
buffer_lenIncoming packet buffer length.
tsIf found the hardware timestamp will be placed here
ReturnsThe length of the IXIA timestamp (hence 0 means that the timestamp has not been found).
int pfring_read_vss_apcon_hw_timestamp
u_char * 
u_int32_t 
buffer_len,
struct timespec * 
Reads a VSS/APCON-formatted timestamp from an incoming packet and puts it into the timestamp variable.
Parameters
bufferIncoming packet buffer.
buffer_lenIncoming packet buffer length.
tsIf found the hardware timestamp will be placed here
ReturnsThe length of the VSS/APCON timestamp
int pfring_recv
u_char ** 
u_int 
buffer_len,
u_int8_t 
wait_for_incoming_packet 
This call returns an incoming packet when available.
Parameters
ringThe PF_RING handle where we perform the check.
bufferA memory area allocated by the caller where the incoming packet will be stored. Note that this parameter is a pointer to a pointer, in order to enable zero-copy implementations (buffer_len must be set to 0).
buffer_lenThe length of the memory area above. Note that the incoming packet is cut if it is too long for the allocated area. A length of 0 indicates to use the zero-copy optimization, when available.
hdrA memory area where the packet header will be copied.
wait_for_incoming_packetIf 0 we simply check the packet availability, otherwise the call is blocked until a packet is available. This option is also available with the PF_RING-aware libpcap via the PCAP_PF_RING_ACTIVE_POLL environment variable.
Returns0 in case of no packet being received (non-blocking), 1 in case of success, -1 in case of error.
int pfring_recv_chunk
void ** 
chunk_info,
u_int8_t 
wait_for_incoming_chunk 
Receive a packet chunk, if enabled via
Parameters
ringThe PF_RING handle.
chunkA buffer that will point to the received chunk. Note that the chunk format is adapter specific.
chunk_infoInformations about the chunk content and length.
wait_for_incoming_chunkIf 0 active wait is used to check the packet availability.
Returns0 on success, a negative value otherwise.
int pfring_recv_parsed
u_char ** 
u_int 
buffer_len,
u_int8_t 
wait_for_incoming_packet,
u_int8_t 
u_int8_t 
add_timestamp,
u_int8_t 
add_hash 
Same of , with additional parameters to force packet parsing.
Parameters
buffer_len
wait_for_incoming_packet
levelThe header level where to stop parsing.
add_timestampAdd the timestamp.
add_hashCompute an IP-based bidirectional hash.
Returns0 in case of no packet being received (non-blocking), 1 in case of success, -1 in case of error.
int pfring_recv_pkt_buff
pkt_handle,
u_int8_t 
wait_for_incoming_packet 
Same as , this function receive a packet filling the buffer pointed by the provided packet handle instead of returning a new buffer.
In a nutshell, the returned packet is put on the passed function argument.
Parameters
ringThe PF_RING handle.
pkt_handleThe packet buffer handle.
hdrThe PF_RING header.
wait_for_incoming_packetIf 0 we simply check the packet availability, otherwise the call is blocked until a packet is available.
Returns0 in case of no packet being received (non-blocking), 1 in case of success, -1 in case of error.
void pfring_release_pkt_buff
pkt_handle 
Release a packet buffer handle previously allocated by pfring_alloc_pkt_buff.
Parameters
ringThe PF_RING handle.
pkt_handleThe packet buffer handle.
int pfring_remove_bpf_filter
Remove the BPF filter.
Parameters
ringThe PF_RING handle.
Returns0 on success, a negative value otherwise.
int pfring_remove_filtering_rule
u_int16_t 
rule_id 
Remove a previously added filtering rule.
Parameters
ringThe PF_RING handle on which the rule will be removed.
rule_idThe id of a previously added rule that will be removed.
Returns0 on success, a negative value otherwise (e.g. the rule does not exist).
int pfring_remove_from_cluster
This call allows a ring to be removed from a previous joined cluster.
Parameters
ringThe PF_RING handle to be cluster.
clusterIdA numeric identifier of the cluster to which the ring will be bound.
Returns0 on success, a negative value otherwise.
int pfring_remove_hw_rule
u_int16_t 
rule_id 
Remove the specified filtering rule from the NIC.
Parameters
ringThe PF_RING handle on which the rule will be removed.
ruleThe filtering rule to be removed from the NIC.
Returns0 on success, a negative value otherwise.
int pfring_search_payload
char * 
string_to_search 
Add a string to search in the packet payload (used for filtering).
Parameters
ringThe PF_RING handle.
string_to_searchThe string to search.
Returns0 on success, a negative value otherwise.
int pfring_send
char * 
u_int 
u_int8_t 
flush_packet 
Send a raw packet (i.e.
it is sent on wire as specified). This packet must be fully specified (the MAC address up) and it will be transmitted as-is without any further manipulation.
Depending on the driver being used, packet transmission happens differently:
Vanilla and PF_RING aware drivers: PF_RING does not accelerate the TX so the standard Linux transmission facilities are used. Do not expect speed advantage when using PF_RING in this mode.
ZC: line rate transmission is supported. Parameters
ringThe PF_RING handle on which the packet has to be sent.
pktThe buffer containing the packet to send.
pkt_lenThe length of the pkt buffer.
flush_packet1 = Flush possible transmission queues. If set to 0, you will decrease your CPU usage but at the cost of sending packets in trains and thus at larger latency.
ReturnsThe number of bytes sent if success, a negative value otherwise.
int pfring_send_get_time
char * 
u_int 
struct timespec * 
Same as , but this function allows to send a raw packet returning the exact time (ns) it has been sent on the wire.
Note that this is available when the adapter supports tx hardware timestamping only and might affect performance.
Parameters
tsThe struct where the tx timestamp will be stored.
ReturnsThe number of bytes sent if success, a negative value otherwise.
int pfring_send_ifindex
char * 
u_int 
u_int8_t 
flush_packet,
if_index 
Same as , with the possibility to specify the outgoing interface index.
Parameters
flush_packet
if_indexThe interface index assigned to the outgoing device.
ReturnsThe number of bytes sent if success, a negative value otherwise.
int pfring_send_last_rx_packet
tx_interface_id 
Send the last received packet to the specified device.
This is an optimization working with standard PF_RING only.
Parameters
ringThe PF_RING handle on which the packet has been received.
tx_interface_idThe egress interface index.
Returns0 on success, a negative value otherwise.
int pfring_send_pkt_buff
pkt_handle,
u_int8_t 
flush_packet 
Same as , this function send the packet pointed by the provided packet buffer handle.
Note: this function resets the content of the buffer handle so if you need to keep its content, make sure you copy the data before you call it.
Parameters
ringThe PF_RING handle.
pkt_handleThe packet buffer handle.
flush_packetFlush all packets in the transmission queues, if any.
ReturnsThe number of bytes sent if success, a negative value otherwise.
int pfring_set_application_name
char * 
name 
Tell PF_RING the name of the application (usually argv[0]) that uses this ring.
This information is used to identify the application when accessing the files present in the PF_RING /proc filesystem. This is also available with the PF_RING-aware libpcap via the PCAP_PF_RING_APPNAME environment variable. Example: $ cat /proc/net/pf_ring/16614-eth0.0 | grep Name Appl. Name : pfcount
Parameters
ringThe PF_RING handle to enable.
nameThe name of the application using this ring.
Returns0 on success, a negative value otherwise.
int pfring_set_application_stats
char * 
stats 
Set custom application statistics.
Parameters
ringThe PF_RING handle.
statsThe application stats.
Returns0 on success, a negative value otherwise.
int pfring_set_bound_dev_name
char * 
custom_dev_name 
Set a custom device name to which the socket is bound.
This function should be called for devices that are not visible via ifconfig
Parameters
ringThe PF_RING handle.
custom_dev_nameThe custom device name to be used for this socket.
Returns0 on success, a negative value otherwise.
int pfring_set_bpf_filter
char * 
filter_buffer 
In order to set BPF filters through the PF_RING API it’s necessary to enable (this is the default) BPF support at compile time and link PF_RING-enabled applications against the -lpcap library (it is possible to disable the BPF support with "cd userland/lib/; ./configure --disable- make" to avoid linking libpcap).
Parameters
ringThe PF_RING handle on which the filter will be set.
filter_bufferThe filter to set.
Returns0 on success, a negative value otherwise.
int pfring_set_channel_id
u_int32_t 
channel_id 
Set the device channel id to be used.
Parameters
ringThe PF_RING handle.
channel_idThe channel id.
Returns0 on success, a negative value otherwise.
int pfring_set_channel_mask
u_int64_t 
channel_mask 
Set the channel mask to be used for packet capture.
Parameters
ringThe PF_RING handle.
channel_maskThe channel mask.
Returns0 on success, a negative value otherwise.
int pfring_set_cluster
u_int 
clusterId,
the_type 
This call allows a ring to be added to a cluster that can spawn across address spaces.
On a nuthsell when two or more sockets are clustered they share incoming packets that are balanced on a per-flow manner. This technique is useful for exploiting multicore systems of for sharing packets in the same address space across multiple threads. Clustering is also available with the PF_RING-aware libpcap via the PCAP_PF_RING_CLUSTER_ID environment variable (Round-Robin by default, per-flow via the PCAP_PF_RING_USE_CLUSTER_PER_FLOW environment variable).
Parameters
ringThe PF_RING handle to be cluster.
clusterIdA numeric identifier of the cluster to which the ring will be bound.
the_typeThe cluster type (2-tuple, 4-tuple, 5-tuple, tcp only 5-tuple, 6-tuple flow or Round-Robin).
Returns0 on success, a negative value otherwise.
int pfring_set_device_clock
struct timespec * 
Sets the time in the device hardware clock, when the adapter supports hardware timestamping.
Parameters
ringThe PF_RING handle.
tsThe time to be set.
Returns0 on success, a negative value otherwise.
int pfring_set_direction
direction 
Tell PF_RING to consider only those packets matching the specified direction.
If the application does not call this function, all the packets (regardless of the direction, either RX or TX) are returned.
Parameters
ringThe PF_RING handle to enable.
directionThe packet direction (RX, TX or both RX and TX).
Returns0 on success, a negative value otherwise.
int pfring_set_filtering_mode
mode 
Sets the filtering mode (software only, hardware only, both software and hardware) in order to implicitly add/remove hardware rules by means of the same API functionality used for software (wildcard and hash) rules.
Parameters
ringThe PF_RING handle on which the rule will be removed.
modeThe filtering mode.
Returns0 on success, a negative value otherwise.
int pfring_set_if_promisc
const char * 
set_promisc 
Set the promiscuous mode flag to a device.
Parameters
deviceThe device name.
set_promiscThe promisc flag.
Returns0 on success, a negative value otherwise.
int pfring_set_master
master 
Set the master ring using the PF_RING handle (vanilla PF_RING only).
Parameters
ringThe PF_RING handle.
masterThe master PF_RING handle.
Returns0 on success, a negative value otherwise.
int pfring_set_master_id
u_int32_t 
master_id 
Set the master ring using the id (vanilla PF_RING only)
Parameters
ringThe PF_RING handle.
masterThe master socket id.
Returns0 on success, a negative value otherwise.
int pfring_set_packet_consumer_mode
u_int8_t 
plugin_id,
char * 
plugin_data,
u_int 
plugin_data_len 
Initialize the kernel plugin for packet processing.
Parameters
ringThe PF_RING handle.
plugin_idThe plugin id.
plugin_dataThe plugin data.
plugin_data_lenThe size of the plugin data.
Returns0 on success, a negative value otherwise.
int pfring_set_packet_slicing
u_int32_t 
additional_bytes 
Set packet slicing level.
Parameters
ringThe PF_RING handle on which slicing is applied, when supported.
levelThe slicing level (disabled, L2, L3, L4, ..)
additional_bytesBytes to capture in addition to the selected layer.
Returns0 on success, a negative value otherwise.
int pfring_set_pkt_buff_ifindex
pkt_handle,
if_index 
Bind the buffer handle (handling a packet) to an interface id.
This function call is useful to specify the egress interface index.
Parameters
ringThe PF_RING handle.
pkt_handleThe packet handle.
if_indexThe interface index.
Returns0 on success, a negative value otherwise.
int pfring_set_pkt_buff_len
pkt_handle,
u_int32_t 
Set the length of the packet.
This function call is not necessary unless you want to custom set the packet length, instead of using the size from the received packet.
Parameters
ringThe PF_RING handle.
pkt_handleThe packet handle.
lenThe packet length.
Returns0 on success, a negative value otherwise.
int pfring_set_poll_duration
u_int 
duration 
Set the poll timeout when passive wait is used.
Parameters
ringThe PF_RING handle to enable.
durationThe poll timeout in msec.
Returns0 on success, a negative value otherwise.
int pfring_set_poll_watermark
u_int16_t 
watermark 
Whenever a user-space application has to wait until incoming packets arrive, it can instruct PF_RING not to return from poll() call unless at least “watermark” packets have been returned.
A low watermark value such as 1, reduces the latency of poll() but likely increases the number of poll() calls. A high watermark (it cannot exceed 50% of the ring size, otherwise the PF_RING kernel module will top its value) instead reduces the number of poll() calls but slightly increases the packet latency. The default value for the watermark (i.e. if user-space applications do not manipulate is value via this call) is 128.
Parameters
ringThe PF_RING handle to enable.
watermarkThe packet poll watermark.
Returns0 on success, a negative value otherwise.
int pfring_set_promisc
set_promisc 
Set the promiscuous mode to bound device.
Parameters
ringThe PF_RING handle.
set_promiscThe promisc flag.
Returns0 on success, a negative value otherwise.
int pfring_set_reflector_device
char * 
device_name 
Set a reflector device to send all incoming packets.
This open a new socket and packets are automatically sent using .
Parameters
ringThe PF_RING handle.
device_nameThe device name.
Returns0 on success, a negative value otherwise.
int pfring_set_sampling_rate
u_int32_t 
rate 
Implement packet sampling directly into the kernel.
Note that this solution is much more efficient than implementing it in user-space. Sampled packets are only those that pass all filters (if any).
Parameters
ringThe PF_RING handle on which sampling is applied.
rateThe sampling rate. Rate of X means that 1 packet out of X is forwarded. This means that a sampling rate of 1 disables sampling.
Returns0 on success, a negative value otherwise.
int pfring_set_socket_mode
mode 
Tell PF_RING if the application needs to send and/or receive packets to/from the socket.
Parameters
ringThe PF_RING handle to enable.
modeThe socket mode (send, receive or both send and receive).
Returns0 on success, a negative value otherwise.
int pfring_set_tx_watermark
u_int16_t 
watermark 
Set the number of packets that have to be enqueued in the egress queue before being sent on the wire.
Parameters
ringThe PF_RING handle to enable.
watermarkThe tx watermark.
Returns0 on success, a negative value otherwise.
int pfring_set_virtual_device
info 
Set a filtering device.
Parameters
ringThe PF_RING handle.
infoThe filtering device info.
Returns0 on success, a negative value otherwise.
void pfring_shutdown
Shutdown a socket.
Parameters
ringThe PF_RING handle.
int pfring_stats
stats 
Read ring statistics (packets received and dropped).
Parameters
ringThe PF_RING handle.
statsA user-allocated buffer on which stats (number of received and dropped packets) will be stored.
Returns0 on uccess, a negative value otherwise.
void pfring_sync_indexes_with_kernel
Synchronizes the ingress ring indexes/registers with the kernel.
Parameters
ringThe PF_RING handle.
int pfring_toggle_filtering_policy
u_int8_t 
rules_default_accept_policy 
Set the default filtering policy.
This means that if no rule is matching the incoming packet the default policy will decide if the packet is forwarded to user space or dropped. Note that filtering rules are limited to a ring, so each ring can have a different set of rules and default policy.
Parameters
ringThe PF_RING handle on which the rule will be added/removed.
rules_default_accept_policyIf set to a positive value the default policy is accept (i.e. forward packets to user space), drop otherwise.
Returns0 on success, a negative value otherwise.
int pfring_version
u_int32_t * 
version 
Read the ring version.
Note that if the ring version is 5.6 the retuned ring version is 0x050600.
Parameters
ringThe PF_RING handle, in case the module supports versioning.
versionA user-allocated buffer on which ring version will be copied.
Returns0 on success, a negative value otherwise.
void pfring_version_noring
u_int32_t * 
Read the ring version.
Note that if the ring version is 5.6 the retuned ring version is 0x050600.
Parameters
versionA user-allocated buffer on which ring version will be copied.}

我要回帖

更多关于 soundlink mini说明书 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信