blob: e891f025a1b9870f35fb72f341d7f8f3f993e476 [file] [log] [blame]
Pavel Emelyanov2787b042012-08-13 05:49:39 +00001#ifndef __PACKET_INTERNAL_H__
2#define __PACKET_INTERNAL_H__
3
4struct packet_mclist {
5 struct packet_mclist *next;
6 int ifindex;
7 int count;
8 unsigned short type;
9 unsigned short alen;
10 unsigned char addr[MAX_ADDR_LEN];
11};
12
13/* kbdq - kernel block descriptor queue */
14struct tpacket_kbdq_core {
15 struct pgv *pkbdq;
16 unsigned int feature_req_word;
17 unsigned int hdrlen;
18 unsigned char reset_pending_on_curr_blk;
19 unsigned char delete_blk_timer;
20 unsigned short kactive_blk_num;
21 unsigned short blk_sizeof_priv;
22
23 /* last_kactive_blk_num:
24 * trick to see if user-space has caught up
25 * in order to avoid refreshing timer when every single pkt arrives.
26 */
27 unsigned short last_kactive_blk_num;
28
29 char *pkblk_start;
30 char *pkblk_end;
31 int kblk_size;
32 unsigned int knum_blocks;
33 uint64_t knxt_seq_num;
34 char *prev;
35 char *nxt_offset;
36 struct sk_buff *skb;
37
38 atomic_t blk_fill_in_prog;
39
40 /* Default is set to 8ms */
41#define DEFAULT_PRB_RETIRE_TOV (8)
42
43 unsigned short retire_blk_tov;
44 unsigned short version;
45 unsigned long tov_in_jiffies;
46
47 /* timer to retire an outstanding block */
48 struct timer_list retire_blk_timer;
49};
50
51struct pgv {
52 char *buffer;
53};
54
55struct packet_ring_buffer {
56 struct pgv *pg_vec;
57 unsigned int head;
58 unsigned int frames_per_block;
59 unsigned int frame_size;
60 unsigned int frame_max;
61
62 unsigned int pg_vec_order;
63 unsigned int pg_vec_pages;
64 unsigned int pg_vec_len;
65
66 struct tpacket_kbdq_core prb_bdqc;
67 atomic_t pending;
68};
69
Pavel Emelyanovfff33212012-08-16 05:36:48 +000070extern struct mutex fanout_mutex;
71#define PACKET_FANOUT_MAX 256
72
73struct packet_fanout {
74#ifdef CONFIG_NET_NS
75 struct net *net;
76#endif
77 unsigned int num_members;
78 u16 id;
79 u8 type;
Willem de Bruijn77f65eb2013-03-19 10:18:11 +000080 u8 flags;
Pavel Emelyanovfff33212012-08-16 05:36:48 +000081 atomic_t rr_cur;
82 struct list_head list;
83 struct sock *arr[PACKET_FANOUT_MAX];
Willem de Bruijn77f65eb2013-03-19 10:18:11 +000084 int next[PACKET_FANOUT_MAX];
Pavel Emelyanovfff33212012-08-16 05:36:48 +000085 spinlock_t lock;
86 atomic_t sk_ref;
87 struct packet_type prot_hook ____cacheline_aligned_in_smp;
88};
89
Pavel Emelyanov2787b042012-08-13 05:49:39 +000090struct packet_sock {
91 /* struct sock has to be the first member of packet_sock */
92 struct sock sk;
93 struct packet_fanout *fanout;
94 struct tpacket_stats stats;
95 union tpacket_stats_u stats_u;
96 struct packet_ring_buffer rx_ring;
97 struct packet_ring_buffer tx_ring;
98 int copy_thresh;
99 spinlock_t bind_lock;
100 struct mutex pg_vec_lock;
101 unsigned int running:1, /* prot_hook is attached*/
102 auxdata:1,
103 origdev:1,
104 has_vnet_hdr:1;
105 int ifindex; /* bound device */
106 __be16 num;
107 struct packet_mclist *mclist;
108 atomic_t mapped;
109 enum tpacket_versions tp_version;
110 unsigned int tp_hdrlen;
111 unsigned int tp_reserve;
112 unsigned int tp_loss:1;
Paul Chavent5920cd3a2012-11-06 23:10:47 +0000113 unsigned int tp_tx_has_off:1;
Pavel Emelyanov2787b042012-08-13 05:49:39 +0000114 unsigned int tp_tstamp;
115 struct packet_type prot_hook ____cacheline_aligned_in_smp;
116};
117
118static struct packet_sock *pkt_sk(struct sock *sk)
119{
120 return (struct packet_sock *)sk;
121}
122
123#endif