PF_RING API
API documentation for PF_RING: high-speed packet capture, filtering and analysis framework.
Loading...
Searching...
No Matches
pf_ring.h
Go to the documentation of this file.
1/*
2 *
3 * Definitions for packet ring
4 *
5 * 2004-25 - ntop
6 *
7 */
8
9#ifndef __RING_H
10#define __RING_H
11
19#ifdef __KERNEL__
20#include <linux/in6.h>
21
22#else /* Userspace*/
23
24#include <netinet/in.h>
25
26#include <endian.h>
27#if __BYTE_ORDER == __LITTLE_ENDIAN
28#define __LITTLE_ENDIAN_BITFIELD
29#elif __BYTE_ORDER == __BIG_ENDIAN
30#define __BIG_ENDIAN_BITFIELD
31#else
32# error "Unknown byte order"
33#endif
34
35#endif /* __KERNEL__ */
36
37/* Versioning */
38#define RING_VERSION "9.2.0"
39#define RING_VERSION_NUM 0x090200
40
41/* Increment whenever there is a change in some shared data structure
42 * between kernel and userspace, including ioctl or packet header layout */
43#define RING_FLOWSLOT_VERSION 21
44
45#define RING_MAGIC
46#define RING_MAGIC_VALUE 0x88
47
48#define RING_USE_SOCKADDR_LL /* use sockaddr_ll instead of sockaddr */
49
50#define MIN_NUM_SLOTS 512
51#define DEFAULT_NUM_SLOTS 4096
52#define DEFAULT_BUCKET_LEN 128
53#define MAX_NUM_DEVICES 256
54
55#define MAX_NUM_RING_SOCKETS 512
56
57#define MAX_CLUSTER_QUEUES 64
58
59/* Watermark */
60#define DEFAULT_MIN_PKT_QUEUED 128
61#define DEFAULT_POLL_WATERMARK_TIMEOUT 0
62
63#define FILTERING_SAMPLING_RATIO 10
64
65/* Set */
66#define SO_ADD_TO_CLUSTER 99
67#define SO_REMOVE_FROM_CLUSTER 100
68#define SO_SET_STRING 101
69#define SO_ADD_FILTERING_RULE 102
70#define SO_REMOVE_FILTERING_RULE 103
71#define SO_TOGGLE_FILTER_POLICY 104
72#define SO_SET_SAMPLING_RATE 105
73#define SO_ACTIVATE_RING 106
74#define SO_RING_BUCKET_LEN 107
75#define SO_SET_CHANNEL_ID 108
76#define SO_PURGE_IDLE_HASH_RULES 109 /* inactivity (sec) */
77#define SO_SET_APPL_NAME 110
78#define SO_SET_PACKET_DIRECTION 111
79#define SO_SET_MASTER_RING 112
80#define SO_ADD_HW_FILTERING_RULE 113
81#define SO_DEL_HW_FILTERING_RULE 114
82#define SO_DISCARD_INJECTED_PKTS 115 /* discard stack injected packets */
83#define SO_DEACTIVATE_RING 116
84#define SO_SET_POLL_WATERMARK 117
85#define SO_SET_VIRTUAL_FILTERING_DEVICE 118
86#define SO_REHASH_RSS_PACKET 119
87#define SO_SET_FILTERING_SAMPLING_RATE 120
88#define SO_SET_POLL_WATERMARK_TIMEOUT 121
89#define SO_SET_DEV_TIME 122
90#define SO_ADJ_DEV_TIME 123
91#define SO_SHUTDOWN_RING 124
92#define SO_PURGE_IDLE_RULES 125 /* inactivity (sec) */
93#define SO_SET_SOCKET_MODE 126
94#define SO_USE_SHORT_PKT_HEADER 127
95#define SO_CONTROL_DEV_QUEUE 128
96#define SO_ENABLE_RX_PACKET_BOUNCE 131
97#define SO_SET_APPL_STATS 133
98#define SO_SET_STACK_INJECTION_MODE 134 /* stack injection/interception from userspace */
99#define SO_CREATE_CLUSTER_REFEREE 135
100#define SO_PUBLISH_CLUSTER_OBJECT 136
101#define SO_LOCK_CLUSTER_OBJECT 137
102#define SO_UNLOCK_CLUSTER_OBJECT 138
103#define SO_SET_CUSTOM_BOUND_DEV_NAME 139
104#define SO_SET_IFF_PROMISC 140
105#define SO_SET_VLAN_ID 141
106
107/* Get */
108#define SO_GET_RING_VERSION 170
109#define SO_GET_FILTERING_RULE_STATS 171
110#define SO_GET_HASH_FILTERING_RULE_STATS 172
111#define SO_GET_ZC_DEVICE_INFO 173
112#define SO_GET_NUM_RX_CHANNELS 174
113#define SO_GET_RING_ID 175
114#define SO_GET_BPF_EXTENSIONS 176
115#define SO_GET_BOUND_DEVICE_ADDRESS 177
116#define SO_GET_NUM_QUEUED_PKTS 178
117#define SO_GET_PKT_HEADER_LEN 179
118#define SO_GET_LOOPBACK_TEST 180
119#define SO_GET_BUCKET_LEN 181
120#define SO_GET_DEVICE_TYPE 182
121#define SO_GET_EXTRA_DMA_MEMORY 183
122#define SO_GET_BOUND_DEVICE_IFINDEX 184
123#define SO_GET_DEVICE_IFINDEX 185
124#define SO_GET_APPL_STATS_FILE_NAME 186
125#define SO_GET_LINK_STATUS 187
126#define SO_GET_DEV_TX_TIME 188
127#define SO_GET_DEV_STATS 189
128#define SO_SELECT_ZC_DEVICE 190
129#define SO_GET_CLUSTER_OBJECT_INFO 191
130
131/* Error codes */
132#define PF_RING_ERROR_GENERIC -1
133#define PF_RING_ERROR_INVALID_ARGUMENT -2
134#define PF_RING_ERROR_NO_PKT_AVAILABLE -3
135#define PF_RING_ERROR_NO_TX_SLOT_AVAILABLE -4
136#define PF_RING_ERROR_WRONG_CONFIGURATION -5
137#define PF_RING_ERROR_END_OF_DEMO_MODE -6
138#define PF_RING_ERROR_NOT_SUPPORTED -7
139#define PF_RING_ERROR_INVALID_LIB_VERSION -8
140#define PF_RING_ERROR_UNKNOWN_ADAPTER -9
141#define PF_RING_ERROR_NOT_ENOUGH_MEMORY -10
142#define PF_RING_ERROR_INVALID_STATUS -11
143#define PF_RING_ERROR_RING_NOT_ENABLED -12
144#define PF_RING_ERROR_BAD_IFNAME -13
145#define PF_RING_ERROR_MOD_NOT_LOADED -14
146#define PF_RING_ERROR_UNABLE_TO_MAP -15
147#define PF_RING_ERROR_UNABLE_TO_GET_INFO -16
148#define PF_RING_ERROR_MMAP_FAILURE -17
149#define PF_RING_ERROR_INIT_FAILURE -18
150
151#define REFLECTOR_NAME_LEN 8
152
153#ifndef IN6ADDR_ANY_INIT
154#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
155#endif
156
157/* *********************************** */
158
159#ifdef __KERNEL__
160
161#if(LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
162
163/* From linux 5.4.34 */
164typedef long __kernel_time_t;
165
166struct timeval {
167 __kernel_time_t tv_sec; /* seconds */
168 __kernel_suseconds_t tv_usec; /* microseconds */
169};
170
171struct timespec {
172 __kernel_time_t tv_sec; /* seconds */
173 long tv_nsec; /* nanoseconds */
174};
175
176struct timespec ns_to_timespec(const s64 nsec);
177struct timeval ns_to_timeval(const s64 nsec);
178
179#define ktime_to_timeval(kt) ns_to_timeval((kt))
180
181#endif
182
183#endif
184
185/*
186 Note that as offsets *can* be negative,
187 please do not change them to unsigned
188*/
190 /* This 'eth_offset' offset *must* be added to all offsets below
191 * ONLY if you are inside the kernel. Ignore it in user-space. */
192 int16_t eth_offset;
193
194 int16_t vlan_offset;
195 int16_t l3_offset;
196 int16_t l4_offset;
197 int16_t payload_offset;
198} __attribute__((packed));
199
200#ifndef ETH_ALEN
201#define ETH_ALEN 6
202#endif
203
204#define REFLECT_PACKET_DEVICE_NONE 0
205
206typedef union {
207 struct in6_addr v6; /* IPv6 src/dst IP addresses (Network byte order) */
208 u_int32_t v4; /* IPv4 src/dst IP addresses */
209} ip_addr;
210
211#define ipv4_tos ip_tos
212#define ipv6_tos ip_tos
213#define ipv4_src ip_src.v4
214#define ipv4_dst ip_dst.v4
215#define ipv6_src ip_src.v6
216#define ipv6_dst ip_dst.v6
217#define host4_low host_low.v4
218#define host4_high host_high.v4
219#define host6_low host_low.v6
220#define host6_high host_high.v6
221#define host4_peer_a host_peer_a.v4
222#define host4_peer_b host_peer_b.v4
223#define host6_peer_a host_peer_a.v6
224#define host6_peer_b host_peer_b.v6
225
227 u_int16_t h_vlan_id; /* Tag Control Information (QoS, VLAN ID) */
228 u_int16_t h_proto; /* packet type ID field */
229} __attribute__((packed));
230
231#define NEXTHDR_HOP 0
232#define NEXTHDR_IPV6 41
233#define NEXTHDR_ROUTING 43
234#define NEXTHDR_FRAGMENT 44
235#define NEXTHDR_ESP 50
236#define NEXTHDR_AUTH 51
237#define NEXTHDR_NONE 59
238#define NEXTHDR_DEST 60
239#define NEXTHDR_MOBILITY 135
240
242#if defined(__LITTLE_ENDIAN_BITFIELD)
243 u_int8_t priority:4,
244 version:4;
245#elif defined(__BIG_ENDIAN_BITFIELD)
246 u_int8_t version:4,
247 priority:4;
248#endif
249 u_int8_t flow_lbl[3];
250 u_int16_t payload_len;
251 u_int8_t nexthdr;
252 u_int8_t hop_limit;
253 struct in6_addr saddr;
254 struct in6_addr daddr;
255} __attribute__((packed));
256
258 u_int8_t nexthdr;
259 u_int8_t hdrlen;
260 u_int8_t padding[6];
261} __attribute__((packed));
262
263#define GRE_HEADER_CHECKSUM 0x8000
264#define GRE_HEADER_ROUTING 0x4000
265#define GRE_HEADER_KEY 0x2000
266#define GRE_HEADER_SEQ_NUM 0x1000
267#define GRE_HEADER_VERSION 0x0007
268
270 u_int16_t flags_and_version;
271 u_int16_t proto;
272 /* Optional fields */
273} __attribute__((packed));
274
275#define GTP_SIGNALING_PORT 2123
276#define GTP_U_DATA_PORT 2152
277
278#define GTP_VERSION_1 0x1
279#define GTP_VERSION_2 0x2
280#define GTP_PROTOCOL_TYPE 0x1
281
283#define GTP_FLAGS_VERSION 0xE0
284#define GTP_FLAGS_VERSION_SHIFT 5
285#define GTP_FLAGS_PROTOCOL_TYPE 0x10
286#define GTP_FLAGS_RESERVED 0x08
287#define GTP_FLAGS_EXTENSION 0x04
288#define GTP_FLAGS_SEQ_NUM 0x02
289#define GTP_FLAGS_NPDU_NUM 0x01
290 u_int8_t flags;
291 u_int8_t message_type;
292 u_int16_t payload_len;
293 u_int32_t teid;
294} __attribute__((__packed__));
295
296/* Optional: GTP_FLAGS_EXTENSION | GTP_FLAGS_SEQ_NUM | GTP_FLAGS_NPDU_NUM */
298 u_int16_t seq_num;
299 u_int8_t npdu_num;
300 u_int8_t next_ext_hdr;
301} __attribute__((__packed__));
302
303/* Optional: GTP_FLAGS_EXTENSION && next_ext_hdr != 0 */
305#define GTP_EXT_HDR_LEN_UNIT_BYTES 4
306 u_int8_t len; /* 4-byte unit */
307 /*
308 * u_char contents[len*4-2];
309 * u_int8_t next_ext_hdr;
310 */
311} __attribute__((__packed__));
312
313#define NO_TUNNEL_ID 0xFFFFFFFF
314
315/* Tunneling Protocols (e.g. GTP) */
316typedef struct {
317 u_int32_t tunnel_id; /* GTP/GRE tunnelId or NO_TUNNEL_ID for no filtering */
318 u_int8_t tunneled_dmac[ETH_ALEN], tunneled_smac[ETH_ALEN]; /* MAC src/dst addresses */
319 u_int16_t tunneled_eth_type; /* Ethernet type */
320 u_int8_t tunneled_ip_version; /* Layer 4 protocol */
321 u_int8_t tunneled_proto; /* Layer 4 protocol */
322 ip_addr tunneled_ip_src, tunneled_ip_dst;
323 u_int16_t tunneled_l4_src_port, tunneled_l4_dst_port;
324} __attribute__((packed))
325tunnel_info;
326
327#define MOBILE_IP_PORT 434
328
330 u_int8_t message_type, next_header;
331 u_int16_t reserved;
332} __attribute__((packed));
333
334#define VXLAN_IP_PORT 4789
335
336struct vxlan_hdr {
337 u_int8_t flags[2];
338 u_int16_t gdp;
339 u_int8_t vni[3];
340 u_int8_t res;
341} __attribute__((packed));
342
343typedef enum {
344 long_pkt_header = 0, /* it includes PF_RING-extensions over the original pcap header */
345 short_pkt_header /* Short pcap-like header */
346} pkt_header_len;
347
349 /* Core fields (also used by NetFlow) */
350 u_int8_t dmac[ETH_ALEN], smac[ETH_ALEN]; /* MAC src/dst addresses */
351 u_int16_t eth_type; /* Ethernet type */
352 u_int16_t vlan_id; /* VLAN Id or NO_VLAN */
353 u_int16_t qinq_vlan_id; /* VLAN Id or NO_VLAN */
354 u_int8_t ip_version;
355 u_int8_t l3_proto, ip_tos; /* Layer 3 protocol, TOS */
356 ip_addr ip_src, ip_dst; /* IPv4/6 src/dst IP addresses */
357 u_int16_t l4_src_port, l4_dst_port;/* Layer 4 src/dst ports */
358 u_int8_t icmp_type, icmp_code; /* Variables for ICMP packets */
359 struct {
360 u_int8_t flags; /* TCP flags (0 if not available) */
361 u_int32_t seq_num, ack_num; /* TCP sequence number */
362 } tcp;
363 tunnel_info tunnel;
364 int32_t last_matched_rule_id; /* If > 0 identifies a rule that matched the packet */
365 struct pkt_offset offset; /* Offsets of L3/L4/payload elements */
366} __attribute__((packed));
367
368#define UNKNOWN_INTERFACE -1
369#define FAKE_PACKET -2 /* It indicates that the returned packet
370 is faked, and that the info is basically
371 a message from PF_RING
372 */
373
375 u_int64_t timestamp_ns; /* Packet timestamp at ns precision. Note that if your NIC supports
376 hardware timestamp, this is the place to read timestamp from */
377#define PKT_FLAGS_CHECKSUM_OFFLOAD 1 << 0 /* IP/TCP checksum offload enabled */
378#define PKT_FLAGS_CHECKSUM_OK 1 << 1 /* Valid checksum (with IP/TCP checksum offload enabled) */
379#define PKT_FLAGS_IP_MORE_FRAG 1 << 2 /* IP More fragments flag set */
380#define PKT_FLAGS_IP_FRAG_OFFSET 1 << 3 /* IP fragment offset set (not 0) */
381#define PKT_FLAGS_VLAN_HWACCEL 1 << 4 /* VLAN stripped by hw */
382#define PKT_FLAGS_FLOW_HIT 1 << 5 /* PF_RING_FLOW_OFFLOAD: flow hit */
383#define PKT_FLAGS_FLOW_MISS 1 << 6 /* PF_RING_FLOW_OFFLOAD: flow miss */
384#define PKT_FLAGS_FLOW_UNHANDLED 1 << 7 /* PF_RING_FLOW_OFFLOAD: flow unhandled */
385 u_int32_t flags;
386
387 u_int8_t rx_direction; /* 1=RX: packet received by the NIC, 0=TX: packet transmitted by the NIC */
388 u_int8_t port_id; /* Port ID (when exported by devices like Arista MetaWatch) */
389 u_int16_t device_id; /* Device ID (when exported by devices like Arista MetaWatch) */
390
391 int32_t if_index; /* index of the interface on which the packet has been received.
392 It can be also used to report other information */
393
394 u_int32_t pkt_hash; /* Hash based on the packet header */
395
396 /* --- short header ends here --- */
397
398 struct {
399 int32_t bounce_interface; /* Interface Id where this packet will bounce after processing
400 if its values is other than UNKNOWN_INTERFACE */
401 struct sk_buff *reserved; /* Kernel only pointer */
402 } tx;
403
404 struct {
405 u_int32_t pid /* process id */;
406 } process;
407
408 /* NOTE: leave it as last field of the memset on parse_pkt() will fail */
409 struct pkt_parsing_info parsed_pkt; /* packet parsing info */
410} __attribute__((packed));
412/* NOTE: Keep 'struct pfring_pkthdr' in sync with 'struct pcap_pkthdr' */
413
414struct pfring_pkthdr {
415 /* pcap header */
416 struct timeval ts; /* time stamp */
417 u_int32_t caplen; /* length of portion present */
418 u_int32_t len; /* length of whole packet (off wire) */
419 struct pfring_extended_pkthdr extended_hdr; /* PF_RING extended header */
420} __attribute__((packed));
421
422/* *********************************** */
423
424#define MAX_NUM_LIST_ELEMENTS MAX_NUM_RING_SOCKETS /* sizeof(bits_set) [see below] */
425
426#ifdef __KERNEL__
427typedef struct {
428 u_int32_t num_elements, top_element_id;
429 spinlock_t list_lock;
430 void *list_elements[MAX_NUM_LIST_ELEMENTS];
431} lockless_list;
432
433void init_lockless_list(lockless_list *l);
434int lockless_list_add(lockless_list *l, void *elem);
435int lockless_list_remove(lockless_list *l, void *elem);
436void* lockless_list_get_next(lockless_list *l, u_int32_t *last_list_idx);
437void* lockless_list_get_first(lockless_list *l, u_int32_t *last_list_idx);
438void lockless_list_empty(lockless_list *l, u_int8_t free_memory);
439void term_lockless_list(lockless_list *l, u_int8_t free_memory);
440#endif
441
442/* ************************************************* */
443
444typedef struct {
445 int32_t if_index; /* Index of the interface on which the packet has been received */
446 u_int8_t smac[ETH_ALEN], dmac[ETH_ALEN]; /* Use '0' (zero-ed MAC address) for any MAC address.
447 This is applied to both source and destination. */
448 u_int16_t vlan_id; /* Use 0 for any vlan */
449 u_int16_t eth_type; /* Use 0 for any ethernet type */
450 u_int8_t proto; /* Use 0 for any l3 protocol */
451 ip_addr shost, dhost; /* User '0' for any host. This is applied to both source and destination. */
452 ip_addr shost_mask, dhost_mask; /* IPv4/6 network mask */
453 u_int16_t sport_low, sport_high; /* All ports between port_low...port_high means 'any' port */
454 u_int16_t dport_low, dport_high; /* All ports between port_low...port_high means 'any' port */
455 struct {
456 u_int8_t flags; /* TCP flags (0 if not available) */
457 } tcp;
458} __attribute__((packed))
459filtering_rule_core_fields;
460
461/* ************************************************* */
462
463typedef struct {
464
465#define FILTER_TUNNEL_ID_FLAG 1 << 0
466 u_int16_t optional_fields; /* Use this mask to activate optional fields */
467
468 struct {
469 u_int32_t tunnel_id; /* GTP/GRE tunnelId or NO_TUNNEL_ID for no filtering */
470 ip_addr shost, dhost; /* Filter on tunneled IPs */
471 ip_addr shost_mask, dhost_mask; /* IPv4/6 network mask */
472 } tunnel;
473
474 char payload_pattern[32]; /* If strlen(payload_pattern) > 0, the packet payload
475 must match the specified pattern */
476} __attribute__((packed))
477filtering_rule_extended_fields;
478
479/* ************************************************* */
480
481#define FILTERING_RULE_AUTO_RULE_ID 0xFFFF
482
483typedef enum {
484 forward_packet_and_stop_rule_evaluation = 0,
485 dont_forward_packet_and_stop_rule_evaluation,
486 execute_action_and_continue_rule_evaluation,
487 execute_action_and_stop_rule_evaluation,
488 forward_packet_add_rule_and_stop_rule_evaluation, /* auto-filled hash rule */
489 reflect_packet_and_stop_rule_evaluation,
490 reflect_packet_and_continue_rule_evaluation,
491 bounce_packet_and_stop_rule_evaluation,
492 bounce_packet_and_continue_rule_evaluation
493} rule_action_behaviour;
494
495typedef enum {
496 pkt_detail_flow,
497 pkt_detail_aggregation
498} pkt_detail_mode;
499
500typedef enum {
501 rx_and_tx_direction = 0,
502 rx_only_direction,
503 tx_only_direction
504} packet_direction;
505
506typedef enum {
507 send_and_recv_mode = 0,
508 send_only_mode,
509 recv_only_mode,
510 management_only_mode
511} socket_mode;
512
513typedef struct {
514 unsigned long jiffies_last_match; /* Jiffies of the last rule match (updated by pf_ring) */
515 struct net_device *reflector_dev; /* Reflector device */
516} __attribute__((packed))
517filtering_internals;
518
519typedef struct {
520 /* FILTERING_RULE_AUTO_RULE_ID to auto generate a rule ID */
521 u_int16_t rule_id; /* Rules are processed in order from lowest to highest id */
522
523 rule_action_behaviour rule_action; /* What to do in case of match */
524 u_int8_t balance_id, balance_pool; /* If balance_pool > 0, then pass the packet above only if the
525 (hash(proto, sip, sport, dip, dport) % balance_pool) = balance_id */
526 u_int8_t locked; /* Do not purge with pfring_purge_idle_rules() */
527 u_int8_t bidirectional; /* Swap peers when checking if they match the rule. Default: monodir */
528 filtering_rule_core_fields core_fields;
529 filtering_rule_extended_fields extended_fields;
530 char reflector_device_name[REFLECTOR_NAME_LEN];
531
532 filtering_internals internals; /* PF_RING internal fields */
533} __attribute__((packed))
534filtering_rule;
535
536/* *********************************** */
537
538/* 82599 packet steering filters */
539
540typedef struct {
541 u_int8_t proto;
542 u_int32_t s_addr, d_addr;
543 u_int16_t s_port, d_port;
544 u_int16_t queue_id;
545} __attribute__((packed))
546intel_82599_five_tuple_filter_hw_rule;
547
548typedef struct {
549 u_int16_t vlan_id;
550 u_int8_t proto;
551 u_int32_t s_addr, d_addr;
552 u_int16_t s_port, d_port;
553 u_int16_t queue_id;
554} __attribute__((packed))
555intel_82599_perfect_filter_hw_rule;
556
557/*
558 Rules are defined per port. Each redirector device
559 has 4 ports (numbered 0..3):
560
561 0 +--------------+ 2 +--------------+
562 LAN <===> | | <===> | 1/10G |
563 | Redirector | | Ethernet |
564 LAN <===> | Switch | <===> | Adapter |
565 1 +--------------+ 3 +--------------+
566
567 Drop Rule
568 Discard incoming packets matching the filter
569 on 'rule_port'
570
571 Redirect Rule
572 Divert incoming packets matching the filter
573 on 'rule_port' to 'rule_target_port'.
574
575 Mirror Rule
576 Copy incoming packets matching the filter
577 on 'rule_port' to 'rule_target_port'. The original
578 packet will continue its journey (i.e. packet are
579 actually duplicated)
580*/
581
582typedef enum {
583 drop_rule,
584 redirect_rule,
585 mirror_rule
586} silicom_redirector_rule_type;
587
588typedef struct {
589 silicom_redirector_rule_type rule_type;
590 u_int8_t rule_port; /* Port on which the rule is defined */
591 u_int8_t rule_target_port; /* Target port (ignored for drop rules) */
592 u_int16_t vlan_id_low, vlan_id_high;
593 u_int8_t l3_proto;
594 ip_addr src_addr, dst_addr;
595 u_int32_t src_mask, dst_mask;
596 u_int16_t src_port_low, src_port_high;
597 u_int16_t dst_port_low, dst_port_high;
598} __attribute__((packed))
599silicom_redirector_hw_rule;
600
601typedef enum {
602 default_pass,
603 default_drop
604} generic_default_action_type;
605
606typedef enum {
607 flow_drop_rule,
608 flow_mark_rule,
609 flow_pass_rule,
610 flow_steer_rule,
611 flow_unlearn_rule
612} generic_flow_rule_action_type;
613
614/* Deprecated (Accolade) */
615typedef struct {
616 generic_flow_rule_action_type action;
617 u_int64_t flow_id; /* flow id from flow metadata */
618 u_int32_t thread; /* id of the thread setting the rule - deprecated */
619} __attribute__((packed))
620generic_flow_id_hw_rule;
621
622/* Mellanox, Napatech */
623typedef struct {
624 generic_flow_rule_action_type action;
625 ip_addr src_ip;
626 ip_addr dst_ip;
627 ip_addr src_ip_mask; /* deprecated */
628 ip_addr dst_ip_mask; /* deprecated */
629 u_int16_t src_port;
630 u_int16_t dst_port;
631 u_int16_t vlan_id;
632 u_int8_t ip_version;
633 u_int8_t protocol;
634 u_int8_t interface; /* from extended_hdr.if_index */
635 u_int8_t queue_id; /* with action == flow_steer_rule */
636 u_int64_t flow_id; /* Napatech Flow Manager only */
637} __attribute__((packed))
638generic_flow_tuple_hw_rule;
639
640typedef enum {
641 intel_82599_five_tuple_rule,
642 intel_82599_perfect_filter_rule,
643 silicom_redirector_rule,
644 generic_flow_id_rule,
645 generic_flow_tuple_rule,
646} hw_filtering_rule_type;
647
648typedef struct {
649 hw_filtering_rule_type rule_family_type;
650
651 /* FILTERING_RULE_AUTO_RULE_ID to auto generate a rule ID
652 * Supported by Mellanox */
653 u_int16_t rule_id;
654
655 /* Rule priority (when supported by the adapter)
656 * Supported by Mellanox (0..2) */
657 u_int16_t priority;
658
659 union {
660 intel_82599_five_tuple_filter_hw_rule five_tuple_rule; /* Intel ixgbe */
661 intel_82599_perfect_filter_hw_rule perfect_rule; /* Intel ixgbe */
662 silicom_redirector_hw_rule redirector_rule; /* Silicom Redirector (Intel) */
663 generic_flow_id_hw_rule flow_id_rule;
664 generic_flow_tuple_hw_rule flow_tuple_rule; /* Mellanox */
665 } rule_family;
666} __attribute__((packed))
667hw_filtering_rule;
668
669#define MAGIC_HW_FILTERING_RULE_REQUEST 0x29010020 /* deprecated? */
670
671#ifdef __KERNEL__
672
673#define ETHTOOL_PFRING_SRXFTCHECK 0x10000000
674#define ETHTOOL_PFRING_SRXFTRLDEL 0x10000031
675#define ETHTOOL_PFRING_SRXFTRLINS 0x10000032
676
677#if defined(I82599_HW_FILTERING_SUPPORT) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,40))
678#define FLOW_EXT 0x80000000
679union _kcompat_ethtool_flow_union {
680 struct ethtool_tcpip4_spec tcp_ip4_spec;
681 struct ethtool_usrip4_spec usr_ip4_spec;
682 __u8 hdata[60];
683};
684struct _kcompat_ethtool_flow_ext {
685 __be16 vlan_etype;
686 __be16 vlan_tci;
687 __be32 data[2];
688};
689struct _kcompat_ethtool_rx_flow_spec {
690 __u32 flow_type;
691 union _kcompat_ethtool_flow_union h_u;
692 struct _kcompat_ethtool_flow_ext h_ext;
693 union _kcompat_ethtool_flow_union m_u;
694 struct _kcompat_ethtool_flow_ext m_ext;
695 __u64 ring_cookie;
696 __u32 location;
697};
698#define ethtool_rx_flow_spec _kcompat_ethtool_rx_flow_spec
699#endif /* defined(I82599_HW_FILTERING_SUPPORT) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,40)) */
700
701#endif /* __KERNEL__ */
702
703typedef enum {
704 add_hw_rule,
705 remove_hw_rule
706} hw_filtering_rule_command;
708/* *********************************** */
709
710struct pfring_timespec {
711 u_int32_t tv_sec;
712 u_int32_t tv_nsec;
713} __attribute__((packed));
714
715/* *********************************** */
716
717/* Used by PF_RING_FLOW_OFFLOAD (Napatech Flow Manager) */
718typedef struct {
719 u_int64_t flow_id;
720
721#if 0
722 u_int16_t vlan_id;
723
724 u_int8_t ip_version;
725 u_int8_t l4_protocol;
726
727 u_int8_t tos;
728 u_int8_t tcp_flags;
729
730 ip_addr src_ip;
731 ip_addr dst_ip;
732
733 u_int16_t src_port;
734 u_int16_t dst_port;
735#endif
736
737#define PF_RING_FLOW_UPDATE_CAUSE_SW 0
738#define PF_RING_FLOW_UPDATE_CAUSE_TIMEOUT 1
739#define PF_RING_FLOW_UPDATE_CAUSE_TCP_TERM 2
740#define PF_RING_FLOW_UPDATE_CAUSE_PERIODIC 3
741#define PF_RING_FLOW_UPDATE_CAUSE_PROBE 4
742#define PF_RING_FLOW_UPDATE_CAUSE_UNKNOWN 5
743 u_int8_t cause;
744 u_int8_t padding_0;
745 u_int16_t padding_1;
746
747 u_int16_t flags_out;
748 u_int16_t flags_in;
749
750 u_int32_t packets_out;
751 u_int32_t packets_in;
752 u_int64_t bytes_out;
753 u_int64_t bytes_in;
754
755 struct pfring_timespec last_seen;
756} __attribute__((packed))
757pfring_flow_update;
758
759/* *********************************** */
760
761/* Deprecated (Accolade) */
762typedef struct {
763 u_int32_t flow_id;
764
765 u_int8_t ip_version;
766 u_int8_t l4_protocol;
767
768 u_int8_t tos;
769 u_int8_t tcp_flags;
770
771 ip_addr src_ip;
772 ip_addr dst_ip;
773
774 u_int16_t vlan_id;
775 u_int8_t start_of_flow;
776 u_int8_t reserved; /* padding */
777
778 u_int16_t src_port;
779 u_int16_t dst_port;
780
781 u_int32_t fwd_packets;
782 u_int32_t rev_packets;
783 u_int64_t fwd_bytes;
784 u_int64_t rev_bytes;
785
786 struct pfring_timespec fwd_ts_first;
787 struct pfring_timespec fwd_ts_last;
788 struct pfring_timespec rev_ts_first;
789 struct pfring_timespec rev_ts_last;
790} __attribute__((packed))
791generic_flow_update;
792
793/* Deprecated (Accolade) */
794typedef struct {
795 generic_flow_rule_action_type action;
796 u_int32_t flow_id;
797} __attribute__((packed))
798generic_flow_feedback;
799
800/* *********************************** */
801
802extern struct pf_ring_socket *pfr; /* Forward */
803
804/* *********************************** */
805
806typedef int (*five_tuple_rule_handler)(struct pf_ring_socket *pfr,
807 hw_filtering_rule *rule,
808 hw_filtering_rule_command request);
809typedef int (*perfect_filter_hw_rule_handler)(struct pf_ring_socket *pfr,
810 hw_filtering_rule *rule,
811 hw_filtering_rule_command request);
812
813typedef struct {
814 five_tuple_rule_handler five_tuple_handler;
815 perfect_filter_hw_rule_handler perfect_filter_handler;
816} __attribute__((packed))
817hw_filtering_device_handler;
818
819/* *********************************** */
820
821/* Hash size used for precise packet matching */
822#define DEFAULT_RING_HASH_SIZE 4096
823
824/*
825 * The hashtable contains only perfect matches: no
826 * wildacards or so are accepted. (bidirectional)
827 */
828typedef struct {
829 u_int16_t rule_id; /* Future use */
830 u_int16_t vlan_id;
831 u_int8_t ip_version;
832 u_int8_t proto; /* Layer 3 protocol */
833 ip_addr host_peer_a, host_peer_b;
834 u_int16_t port_peer_a, port_peer_b;
835
836 rule_action_behaviour rule_action; /* What to do in case of match */
837 char reflector_device_name[REFLECTOR_NAME_LEN];
838
839 filtering_internals internals; /* PF_RING internal fields */
840} __attribute__((packed))
841hash_filtering_rule;
842
843typedef struct {
844 u_int64_t match;
845 u_int64_t filtered;
846 u_int64_t match_forward;
847 u_int32_t inactivity; /* sec */
848} __attribute__((packed))
849hash_filtering_rule_stats;
851/* ************************************************* */
852
853typedef struct _sw_filtering_hash_bucket {
854 hash_filtering_rule rule;
855 u_int64_t match; /* number of packets matching the rule */
856 u_int64_t filtered; /* number of packets filtered by the rule */
857 u_int64_t match_forward; /* number of packets sampled by the rule (equivalent to match minus filtered) */
858 struct _sw_filtering_hash_bucket *next;
859} __attribute__((packed))
860sw_filtering_hash_bucket;
861
862/* *********************************** */
863
864#define RING_MIN_SLOT_SIZE (60+sizeof(struct pfring_pkthdr))
865#define RING_MAX_SLOT_SIZE (1514+sizeof(struct pfring_pkthdr))
866
867#if !defined(__cplusplus)
868
869#define min_val(a,b) ((a < b) ? a : b)
870#define max_val(a,b) ((a > b) ? a : b)
871
872#endif
873
874/* *********************************** */
876/* False sharing reference: http://en.wikipedia.org/wiki/False_sharing */
877
878typedef struct flowSlotInfo {
879 /* first page, managed by kernel */
880 u_int16_t version, sample_rate;
881 u_int32_t min_num_slots, slot_len, data_len;
882 u_int64_t tot_mem;
883 volatile u_int64_t insert_off;
884 u_int64_t kernel_remove_off;
885 u_int64_t tot_pkts, tot_lost;
886 volatile u_int64_t tot_insert;
887 u_int64_t kernel_tot_read;
888 u_int64_t tot_fwd_ok, tot_fwd_notok;
889 u_int64_t good_pkt_sent, pkt_send_error;
890 /* <-- 64 bytes here, should be enough to avoid some L1 VIVT coherence issues (32 ~ 64bytes lines) */
891 char padding[128-104];
892 /* <-- 128 bytes here, should be enough to avoid false sharing in most L2 (64 ~ 128bytes lines) */
893 char k_padding[4096-128];
894 /* <-- 4096 bytes here, to get a page aligned block writable by kernel side only */
895
896 /* second page, managed by userland */
897 volatile u_int64_t tot_read;
898 volatile u_int64_t remove_off /* managed by userland */;
899 char u_padding[4096-16];
900 /* <-- 8192 bytes here, to get a page aligned block writable by userland only */
901} __attribute__((packed))
902FlowSlotInfo;
903
904/* **************************************** */
905
906#ifdef __KERNEL__
907FlowSlotInfo *getRingPtr(void);
908int allocateRing(char *deviceName, u_int32_t numSlots, u_int32_t bucketLen, u_int32_t sampleRate);
909unsigned int pollRing(struct file *fp, struct poll_table_struct * wait);
910void deallocateRing(void);
911#endif /* __KERNEL__ */
912
913/* *********************************** */
914
915#define PF_RING 27 /* (0x1b) Packet Ring */
916#define SOCK_RING PF_RING
917
918/* ioctl() */
919#define SIORINGPOLL 0x8888
920
921/* ************************************************* */
922
923#ifdef __KERNEL__
924struct ring_sock {
925 struct sock sk; /* It MUST be the first element */
926 struct pf_ring_socket *pf_ring_sk;
927};
928#endif
929
930/* *********************************** */
931
932/* ZC driver API - data structures */
933
934typedef int (*zc_dev_wait_packet)(void *rx_adapter, int mode);
935typedef int (*zc_dev_notify)(void *rx_adapter, void *tx_adapter, u_int8_t device_in_use);
936typedef int (*zc_dev_set_time)(void *rx_adapter, u_int64_t time_ns);
937typedef int (*zc_dev_adjust_time)(void *rx_adapter, int64_t offset_ns);
938typedef int (*zc_dev_get_tx_time)(void *tx_adapter, u_int64_t *time_ns);
939typedef int (*zc_dev_control_queue)(void *rx_adapter, u_int8_t enable);
940typedef int (*zc_dev_get_stats)(void *rx_adapter, u_int64_t *rx_missed);
941
942typedef struct {
943 zc_dev_wait_packet wait_packet;
944 zc_dev_notify usage_notification;
945 zc_dev_set_time set_time;
946 zc_dev_adjust_time adjust_time;
947 zc_dev_get_tx_time get_tx_time;
948 zc_dev_control_queue control_queue;
949 zc_dev_get_stats get_stats;
950} __attribute__((packed))
951zc_dev_callbacks;
952
953typedef enum {
954 add_device_mapping = 0,
955 remove_device_mapping
956} zc_dev_operation;
957
958/* IMPORTANT NOTE
959 * add new family types ALWAYS at the end
960 * (i.e. append) of this datatype */
961typedef enum {
962 intel_e1000e = 0,
963 intel_igb,
964 intel_ixgbe,
965 intel_ixgbe_82598,
966 intel_ixgbe_82599,
967 intel_igb_ts,
968 intel_e1000,
969 intel_ixgbe_82599_ts,
970 intel_i40e,
971 intel_ixgbe_vf,
972 intel_ixgbe_x550,
973 intel_ice,
974 intel_i40e_ice_vf
975} zc_dev_model;
976
977typedef struct {
978 u_int32_t packet_memory_num_slots;
979 u_int32_t packet_memory_slot_len;
980 u_int32_t descr_packet_memory_tot_len;
981 u_int16_t registers_index;
982 u_int16_t stats_index;
983 u_int32_t vector;
984 u_int32_t num_queues;
985} __attribute__((packed))
986zc_dev_ring_info;
987
988/* ************************************************* */
989
990typedef struct {
991 zc_dev_ring_info rx;
992 zc_dev_ring_info tx;
993 u_int32_t phys_card_memory_len;
994 zc_dev_model device_model;
995} __attribute__((packed))
996zc_memory_info;
997
998typedef struct {
999 zc_memory_info mem_info;
1000 u_int16_t channel_id;
1001 void *rx_descr_packet_memory; /* Invalid in userland */
1002 void *tx_descr_packet_memory; /* Invalid in userland */
1003 char *phys_card_memory; /* Invalid in userland */
1004 struct net_device *dev; /* Invalid in userland */
1005 struct device *hwdev; /* Invalid in userland */
1006 u_char device_address[6];
1007#ifdef __KERNEL__
1008 wait_queue_head_t *packet_waitqueue;
1009#else
1010 void *packet_waitqueue;
1011#endif
1012 u_int8_t *interrupt_received;
1013 u_int8_t in_use;
1014 void *rx_adapter;
1015 void *tx_adapter;
1016 zc_dev_callbacks callbacks;
1017} __attribute__((packed))
1018zc_dev_info;
1019
1020#ifndef IFNAMSIZ
1021#define IFNAMSIZ 16
1022#endif
1023
1024typedef struct {
1025 zc_dev_operation operation;
1026 char device_name[IFNAMSIZ];
1027 int32_t channel_id;
1028 zc_dev_model device_model; /* out */
1029} __attribute__((packed))
1030zc_dev_mapping;
1031
1032/* ************************************************* */
1033
1034#define RING_ANY_CHANNEL ((u_int64_t)-1)
1035#define MAX_NUM_RX_CHANNELS 64 /* channel_id_mask is a 64 bit mask */
1036#define UNKNOWN_NUM_RX_CHANNELS 1
1037
1038#define RING_ANY_VLAN ((u_int16_t)0xFFFF)
1039#define RING_NO_VLAN ((u_int16_t)0)
1040
1041/* ************************************************* */
1042
1043typedef enum {
1044 cluster_per_flow = 0, /* 6-tuple: <src ip, src port, dst ip, dst port, proto, vlan> */
1045 cluster_round_robin,
1046 cluster_per_flow_2_tuple, /* 2-tuple: <src ip, dst ip > */
1047 cluster_per_flow_4_tuple, /* 4-tuple: <src ip, src port, dst ip, dst port > */
1048 cluster_per_flow_5_tuple, /* 5-tuple: <src ip, src port, dst ip, dst port, proto > */
1049 cluster_per_flow_tcp_5_tuple, /* 5-tuple only with TCP, 2 tuple with all other protos */
1050 /* same as above, computing on tunnel content when present */
1051 cluster_per_inner_flow, /* 6-tuple: <src ip, src port, dst ip, dst port, proto, vlan> */
1052 cluster_per_inner_flow_2_tuple, /* 2-tuple: <src ip, dst ip > */
1053 cluster_per_inner_flow_4_tuple, /* 4-tuple: <src ip, src port, dst ip, dst port > */
1054 cluster_per_inner_flow_5_tuple, /* 5-tuple: <src ip, src port, dst ip, dst port, proto > */
1055 cluster_per_inner_flow_tcp_5_tuple,/* 5-tuple only with TCP, 2 tuple with all other protos */
1056 /* new types, for L2-only protocols */
1057 cluster_per_flow_ip_5_tuple, /* 5-tuple only with IP, 2 tuple with non-IP <src mac, dst mac> */
1058 cluster_per_inner_flow_ip_5_tuple, /* 5-tuple only with IP, 2 tuple with non-IP <src mac, dst mac> */
1059 cluster_per_flow_ip_with_dup_tuple, /* 1-tuple: <src ip> and <dst ip> with duplication */
1060 cluster_per_flow_ip_with_dup_tuple_ext /* 1-tuple: <src ip> and <dst ip> with duplication, fan-out on hash(src ip) == hash (dst ip) and port != 443 */
1061} cluster_type;
1063#define MAX_CLUSTER_TYPE_ID cluster_per_flow_ip_with_dup_tuple_ext
1064
1065struct add_to_cluster {
1066 u_int16_t cluster_id;
1067 u_int16_t queue_id;
1068#define CLUSTER_OPTION_RELAXED_DISTRIBUTION (1<<0)
1069 u_int32_t options;
1070 cluster_type the_type;
1071} __attribute__((packed));
1072
1073typedef enum {
1074 standard_nic_family = 0, /* No Hw Filtering */
1075 intel_82599_family
1076} pfring_device_type;
1077
1078typedef struct {
1079 char device_name[IFNAMSIZ];
1080 pfring_device_type device_type;
1081
1082 /* Entry in the /proc filesystem */
1083 struct proc_dir_entry *proc_entry;
1084} __attribute__((packed))
1085virtual_filtering_device_info;
1087/* ************************************************* */
1088
1090 u_int32_t cluster_id;
1091 u_int32_t recovered; /* fresh or recovered */
1092} __attribute__((packed));
1093
1095 u_int32_t cluster_id;
1096 u_int32_t object_type;
1097 u_int32_t object_id;
1098} __attribute__((packed));
1099
1101 u_int32_t cluster_id;
1102 u_int32_t object_type;
1103 u_int32_t object_id;
1104 u_int32_t lock_mask;
1105 u_int32_t reserved; /* used by VMs to pass the op */
1106 u_int32_t locked_mask; /* out */
1107} __attribute__((packed));
1108
1109/* ************************************************* */
1110
1111typedef enum {
1112 cluster_slave = 0,
1113 cluster_master = 1
1114} cluster_client_type;
1115
1116/* ************************************************* */
1117
1118#ifdef __KERNEL__
1119
1120#if(LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0))
1121#ifndef netdev_notifier_info_to_dev
1122#define netdev_notifier_info_to_dev(a) ((struct net_device*)a)
1123#endif
1124#endif
1125
1126/*
1127 * A ring cluster is used group together rings used by various applications
1128 * so that they look, from the PF_RING point of view, as a single ring.
1129 * This means that developers can use clusters for sharing packets across
1130 * applications using various policies as specified in the hashing_mode
1131 * parameter.
1132 */
1133struct ring_cluster {
1134 u_int32_t cluster_id; /* 0 = no cluster */
1135 u_int16_t num_cluster_queues;
1136 u_int16_t max_queue_index;
1137 u_int16_t hashing_id;
1138 u_int8_t relaxed_distribution;
1139 u_int8_t padding;
1140 cluster_type hashing_mode;
1141 struct sock *sk[MAX_CLUSTER_QUEUES];
1142};
1143
1144/*
1145 * Linked-list of ring clusters
1146 */
1147typedef struct {
1148 struct ring_cluster cluster;
1149 struct list_head list;
1150} ring_cluster_element;
1151
1152#define MAX_NUM_ZC_BOUND_SOCKETS MAX_NUM_RING_SOCKETS
1153
1154typedef struct {
1155 u8 num_bound_sockets;
1156 zc_dev_info zc_dev;
1157 struct list_head list;
1158 /*
1159 In the ZC world only one application can open and enable the
1160 device@channel per direction. The array below is used to keep
1161 pointers to the sockets bound to device@channel.
1162 No more than one socket can be enabled for RX and one for TX.
1163 */
1164 struct pf_ring_socket *bound_sockets[MAX_NUM_ZC_BOUND_SOCKETS];
1165 spinlock_t lock;
1166} zc_dev_list;
1167
1168#define MAX_NUM_IFINDEX 0x7FFFFFFF
1169#define MAX_NUM_DEV_IDX 1024
1170
1171#define ANY_IFINDEX (MAX_NUM_IFINDEX-1)
1172#define NONE_IFINDEX (MAX_NUM_IFINDEX-2)
1173
1174/*
1175 * Linked-list of virtual filtering devices
1176 */
1177typedef struct {
1178 virtual_filtering_device_info info;
1179 struct list_head list;
1180} virtual_filtering_device_element;
1181
1182/* ************************************************* */
1183
1184typedef struct {
1185 u_int8_t set;
1186 u_int8_t direct_mapping;
1187 int32_t ifindex;
1188} ifindex_map_item;
1189
1190/* ************************************************* */
1191
1192typedef struct {
1193 struct net_device *dev;
1194
1195 /* Note: we keep device_name here for a couple of reasons:
1196 * 1. some device types might NOT have a net_device handler
1197 * 2. when a device name changes we need to remember the old name */
1198 char device_name[IFNAMSIZ];
1199
1200 pfring_device_type device_type; /* Device Type */
1201 int32_t dev_index;
1202
1203 u_int8_t do_not_remove_promisc; /* promisc was set before any socket */
1204 atomic_t promisc_users; /* number of rings with promisc set bound to this device */
1205
1206 /* Entry in the /proc filesystem */
1207 struct proc_dir_entry *proc_entry;
1208 struct proc_dir_entry *proc_info_entry;
1209
1210 /* ZC */
1211 u_int8_t is_zc_device;
1212 zc_dev_model zc_dev_model;
1213 u_int32_t num_zc_dev_rx_queues; /* 0 for non ZC devices */
1214 u_int32_t num_zc_rx_slots;
1215 u_int32_t num_zc_tx_slots;
1216
1217 /* Hardware Filters */
1218 struct {
1219 u_int16_t num_filters;
1220 hw_filtering_device_handler filter_handlers;
1221 } hw_filters;
1222
1223 struct list_head device_list;
1224} pf_ring_device;
1225
1226/* ************************************************* */
1227
1228struct dma_memory_info {
1229 u_int32_t num_chunks, chunk_len;
1230 u_int32_t num_slots, slot_len;
1231 unsigned long *virtual_addr; /* chunks pointers */
1232 u_int64_t *dma_addr; /* per-slot DMA addresses */
1233 struct device *hwdev; /* dev for DMA mapping */
1234};
1235
1236/* ************************************************* */
1237
1238typedef struct {
1239 u_int32_t object_type;
1240 u_int32_t object_id;
1241 u_int32_t lock_bitmap;
1242
1243 struct list_head list;
1244} cluster_object;
1245
1246struct cluster_referee {
1247 u_int32_t id;
1248 u_int32_t users;
1249 u_int8_t master_running;
1250 struct list_head objects_list;
1251
1252 struct list_head list;
1253};
1254
1255/* ************************************************* */
1256
1257typedef u_int32_t (*do_rehash_rss)(struct sk_buff *skb, struct pfring_pkthdr *hdr);
1258
1259/* ************************************************* */
1260
1261#define NUM_FRAGMENTS_HASH_SLOTS 4096
1262#define MAX_CLUSTER_FRAGMENTS_LEN 8*NUM_FRAGMENTS_HASH_SLOTS
1263
1264struct hash_fragment_node {
1265 /* Key */
1266 u_int32_t ipv4_src_host, ipv4_dst_host;
1267 u_int16_t ip_fragment_id;
1268
1269 /* Value */
1270 u_int8_t cluster_app_id; /* Identifier of the app where the main fragment has been placed */
1271
1272 /* Expire */
1273 unsigned long expire_jiffies; /* Time at which this entry will be expired */
1274
1275 /* collision list */
1276 struct list_head frag_list;
1277};
1278
1279/* ************************************************* */
1280
1281/*
1282 * Ring options
1283 */
1284struct pf_ring_socket {
1285 struct mutex ring_config_lock;
1286
1287 u_int8_t ring_active, ring_shutdown, num_rx_channels, num_bound_devices;
1288 pf_ring_device *ring_dev;
1289
1290 /* last device set with bind, needed to heck channels when multiple
1291 * devices are used with quick-mode */
1292 pf_ring_device *last_bind_dev;
1293
1294 DECLARE_BITMAP(pf_dev_mask, MAX_NUM_DEV_IDX /* bits */);
1295 int ring_pid;
1296 u_int32_t ring_id;
1297 packet_direction direction; /* Specify the capture direction for packets */
1298 socket_mode mode; /* Specify the link direction to enable (RX, TX, both) */
1299 pkt_header_len header_len;
1300 u_int8_t stack_injection_mode;
1301 u_int8_t discard_injected_pkts;
1302 u_int8_t promisc_enabled;
1303 u_int8_t __padding;
1304
1305 struct sock *sk;
1306
1307 char appl_name[64]; /* String that identifies the application bound to the socket */
1308
1309 /* /proc */
1310 char sock_proc_name[64]; /* /proc/net/pf_ring/<sock_proc_name> */
1311 char sock_proc_stats_name[64]; /* /proc/net/pf_ring/stats/<sock_proc_stats_name> */
1312 char statsString[1024];
1313 char custom_bound_device_name[32];
1314
1315 /* Poll Watermark */
1316 u_int32_t num_poll_calls;
1317 u_int16_t poll_num_pkts_watermark;
1318 u_int16_t poll_watermark_timeout;
1319 u_long queue_nonempty_timestamp;
1320
1321 /* Master Ring */
1322 struct pf_ring_socket *master_ring;
1323
1324 /* Used to transmit packets after they have been received
1325 from user space */
1326 struct {
1327 u_int8_t enable_tx_with_bounce;
1328 spinlock_t consume_tx_packets_lock;
1329 int32_t last_tx_dev_idx;
1330 struct net_device *last_tx_dev;
1331 } tx;
1332
1333 /* ZC (Direct NIC Access) */
1334 zc_dev_mapping zc_mapping;
1335 zc_dev_info *zc_dev;
1336 zc_dev_list *zc_device_entry;
1337
1338 /* Extra DMA memory */
1339 struct dma_memory_info *extra_dma_memory;
1340
1341 /* Cluster */
1342 u_int32_t cluster_id /* 0 = no cluster */;
1343
1344 /* Channel */
1345 int64_t channel_id_mask; /* -1 = any channel */
1346 u_int16_t num_channels_per_ring;
1347
1348 /* rehash rss function pointer */
1349 do_rehash_rss rehash_rss;
1350
1351 /* Ring Slots */
1352 u_char *ring_memory;
1353 u_int16_t slot_header_len;
1354 u_int32_t bucket_len, slot_tot_mem;
1355 FlowSlotInfo *slots_info; /* Points to ring_memory */
1356 u_char *ring_slots; /* Points to ring_memory+sizeof(FlowSlotInfo) */
1357
1358 /* Packet Sampling */
1359 u_int32_t sample_rate;
1360 u_int32_t pkts_to_sample;
1361 u_int32_t sample_rnd_shift;
1362
1363 /* Virtual Filtering Device */
1364 virtual_filtering_device_element *v_filtering_dev;
1365
1366 /* VLAN ID */
1367 u_int16_t vlan_id; /* 0 = all VLANs are accepted */
1368
1369 int32_t bpfFilter; /* bool */
1370
1371 /* Sw Filtering Rules - default policy */
1372 u_int8_t sw_filtering_rules_default_accept_policy; /* 1=default policy is accept, drop otherwise */
1373
1374 /* Sw Filtering Rules - hash */
1375 sw_filtering_hash_bucket **sw_filtering_hash;
1376 u_int64_t sw_filtering_hash_match;
1377 u_int64_t sw_filtering_hash_miss;
1378 u_int64_t sw_filtering_hash_filtered;
1379 u_int32_t num_sw_filtering_hash;
1380
1381 /* Sw Filtering Rules - wildcard */
1382 u_int32_t num_sw_filtering_rules;
1383 struct list_head sw_filtering_rules;
1384
1385 /* Hw Filtering Rules */
1386 u_int16_t num_hw_filtering_rules;
1387 struct list_head hw_filtering_rules;
1388
1389 /* Filtering sampling */
1390 u_int32_t filtering_sample_rate;
1391 u_int32_t filtering_sampling_size;
1392
1393 /* Locks */
1394 atomic_t num_ring_users;
1395 wait_queue_head_t ring_slots_waitqueue;
1396 spinlock_t ring_index_lock;
1397 rwlock_t ring_rules_lock;
1398
1399 /* Indexes (Internal) */
1400 u_int32_t insert_page_id, insert_slot_id;
1401
1402 /* Kernel consumer */
1403 char *kernel_consumer_options, *kernel_consumer_private;
1404
1405 /* Userspace cluster (ZC) */
1406 struct cluster_referee *cluster_referee;
1407 cluster_client_type cluster_role;
1408};
1409
1410/* **************************************** */
1411
1412#if LINUX_VERSION_CODE < KERNEL_VERSION(5,11,0)
1413#define SINGLE_PROT_HOOK
1414#endif
1415
1416typedef struct {
1417 u_int32_t magic;
1418
1419 struct net *net;
1420
1421#ifndef SINGLE_PROT_HOOK
1422 struct packet_type prot_hook;
1423#endif
1424
1425 /* /proc entry for ring module */
1426 struct proc_dir_entry *proc;
1427 struct proc_dir_entry *proc_dir;
1428 struct proc_dir_entry *proc_dev_dir;
1429 struct proc_dir_entry *proc_stats_dir;
1430
1431 /* Map ifindex to pf device idx (used for quick_mode_rings, num_rings_per_device) */
1432 ifindex_map_item ifindex_map[MAX_NUM_DEV_IDX];
1433
1434 /* quick mode <ifindex, channel> to <ring> table */
1435 struct pf_ring_socket* quick_mode_rings[MAX_NUM_DEV_IDX][MAX_NUM_RX_CHANNELS];
1436
1437 /* Keep track of number of rings per device (plus any) */
1438 u_int8_t num_rings_per_device[MAX_NUM_DEV_IDX];
1439 u_int32_t num_any_rings;
1440} pf_ring_net;
1441
1442/* **************************************** */
1443
1444#define MAX_NUM_PATTERN 32
1445
1446typedef struct {
1447 filtering_rule rule;
1448
1449#ifdef CONFIG_TEXTSEARCH
1450 struct ts_config *pattern[MAX_NUM_PATTERN];
1451#endif
1452 struct list_head list;
1453} sw_filtering_rule_element;
1454
1455typedef struct {
1456 hw_filtering_rule rule;
1457 struct list_head list;
1458} hw_filtering_rule_element;
1459
1460/* **************************************** */
1461
1462/* Exported functions - used by drivers */
1463
1464int pf_ring_skb_ring_handler(struct sk_buff *skb,
1465 u_int8_t recv_packet,
1466 u_int8_t real_skb /* 1=real skb, 0=faked skb */,
1467 int32_t channel_id,
1468 u_int32_t num_rx_channels);
1469
1470/* ZC driver API */
1471
1472void pf_ring_zc_dev_handler(zc_dev_operation operation,
1473 zc_dev_callbacks *callbacks,
1474 zc_dev_ring_info *rx_info,
1475 zc_dev_ring_info *tx_info,
1476 void *rx_descr_packet_memory,
1477 void *tx_descr_packet_memory,
1478 void *phys_card_memory,
1479 u_int32_t phys_card_memory_len,
1480 u_int32_t channel_id,
1481 struct net_device *dev,
1482 struct device *hwdev,
1483 zc_dev_model device_model,
1484 u_char *device_address,
1485 wait_queue_head_t *packet_waitqueue,
1486 u_int8_t *interrupt_received,
1487 void *rx_adapter_ptr,
1488 void *tx_adapter_ptr);
1489
1490#endif /* __KERNEL__ */
1491
1492/* *********************************** */
1493
1494#endif /* __RING_H */
Definition pf_ring.h:316
Definition pf_ring.h:850
Definition pf_ring.h:1062
Definition pf_ring.h:1086
Definition pf_ring.h:226
Definition pf_ring.h:875
Definition pf_ring.h:269
Definition pf_ring.h:304
Definition pf_ring.h:282
Definition pf_ring.h:297
Definition pf_ring.h:241
Definition pf_ring.h:257
Definition pf_ring.h:1097
Definition pf_ring.h:329
Definition pf_ring.h:371
Definition pf_ring.h:411
Definition pf_ring.h:707
Definition pf_ring.h:189
Definition pf_ring.h:348
Definition pf_ring.h:1091
Definition pf_ring.h:336
Definition pf_ring.h:206