astraceroute: use switch instead of lookup table for short proto id
[netsniff-ng.git] / ring_rx.h
blob67ddc03a30596d097050b39712517cbd9a7360f8
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
5 */
7 #ifndef RX_RING_H
8 #define RX_RING_H
10 #include <stdbool.h>
12 #include "ring.h"
14 extern void ring_rx_setup(struct ring *ring, int sock, size_t size, int ifindex,
15 struct pollfd *poll, bool v3, bool jumbo_support,
16 bool verbose, uint32_t fanout_group, uint32_t fanout_type);
17 extern void destroy_rx_ring(int sock, struct ring *ring);
18 extern int get_rx_net_stats(int sock, uint64_t *packets, uint64_t *drops, bool v3);
20 static inline int user_may_pull_from_rx(struct tpacket2_hdr *hdr)
22 return ((hdr->tp_status & TP_STATUS_USER) == TP_STATUS_USER);
25 static inline void kernel_may_pull_from_rx(struct tpacket2_hdr *hdr)
27 hdr->tp_status = TP_STATUS_KERNEL;
30 #ifdef HAVE_TPACKET3
31 static inline int user_may_pull_from_rx_block(struct block_desc *pbd)
33 return ((pbd->h1.block_status & TP_STATUS_USER) == TP_STATUS_USER);
36 static inline void kernel_may_pull_from_rx_block(struct block_desc *pbd)
38 pbd->h1.block_status = TP_STATUS_KERNEL;
40 #endif /* HAVE_TPACKET3 */
42 /* Fanout types. */
44 #ifndef PACKET_FANOUT_HASH
45 # define PACKET_FANOUT_HASH 0
46 #endif
48 #ifndef PACKET_FANOUT_LB
49 # define PACKET_FANOUT_LB 1
50 #endif
52 #ifndef PACKET_FANOUT_CPU
53 # define PACKET_FANOUT_CPU 2
54 #endif
56 #ifndef PACKET_FANOUT_ROLLOVER
57 # define PACKET_FANOUT_ROLLOVER 3
58 #endif
60 #ifndef PACKET_FANOUT_RND
61 # define PACKET_FANOUT_RND 4
62 #endif
64 #ifndef PACKET_FANOUT_QM
65 # define PACKET_FANOUT_QM 5
66 #endif
68 #ifndef PACKET_FANOUT_FLAG_ROLLOVER
69 # define PACKET_FANOUT_FLAG_ROLLOVER 0x1000
70 #endif
72 #ifndef PACKET_FANOUT_FLAG_DEFRAG
73 # define PACKET_FANOUT_FLAG_DEFRAG 0x8000
74 #endif
76 #endif /* RX_RING_H */