diff options
author | Pavel Emelyanov <xemul@parallels.com> | 2012-08-13 01:49:39 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-08-14 19:56:33 -0400 |
commit | 2787b04b6c5e7607510e8248b38b0aeacb5505f6 (patch) | |
tree | f8a8965dd9ae95614b77fdc827190c72951e01f2 | |
parent | ad5b310228da567e35a2ea5dcb2fd62e3a36654e (diff) |
packet: Introduce net/packet/internal.h header
The diag module will need to access some private packet_sock data, so
move it to a header in advance. This file will be shared between the
af_packet.c and the diag.c
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/packet/af_packet.c | 99 | ||||
-rw-r--r-- | net/packet/internal.h | 103 |
2 files changed, 105 insertions, 97 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index ceaca7c134a0..8a1605ae4029 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c | |||
@@ -93,6 +93,8 @@ | |||
93 | #include <net/inet_common.h> | 93 | #include <net/inet_common.h> |
94 | #endif | 94 | #endif |
95 | 95 | ||
96 | #include "internal.h" | ||
97 | |||
96 | /* | 98 | /* |
97 | Assumptions: | 99 | Assumptions: |
98 | - if device has no dev->hard_header routine, it adds and removes ll header | 100 | - if device has no dev->hard_header routine, it adds and removes ll header |
@@ -146,14 +148,6 @@ dev->hard_header == NULL (ll header is added by device, we cannot control it) | |||
146 | 148 | ||
147 | /* Private packet socket structures. */ | 149 | /* Private packet socket structures. */ |
148 | 150 | ||
149 | struct packet_mclist { | ||
150 | struct packet_mclist *next; | ||
151 | int ifindex; | ||
152 | int count; | ||
153 | unsigned short type; | ||
154 | unsigned short alen; | ||
155 | unsigned char addr[MAX_ADDR_LEN]; | ||
156 | }; | ||
157 | /* identical to struct packet_mreq except it has | 151 | /* identical to struct packet_mreq except it has |
158 | * a longer address field. | 152 | * a longer address field. |
159 | */ | 153 | */ |
@@ -175,63 +169,7 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u, | |||
175 | #define BLK_PLUS_PRIV(sz_of_priv) \ | 169 | #define BLK_PLUS_PRIV(sz_of_priv) \ |
176 | (BLK_HDR_LEN + ALIGN((sz_of_priv), V3_ALIGNMENT)) | 170 | (BLK_HDR_LEN + ALIGN((sz_of_priv), V3_ALIGNMENT)) |
177 | 171 | ||
178 | /* kbdq - kernel block descriptor queue */ | ||
179 | struct tpacket_kbdq_core { | ||
180 | struct pgv *pkbdq; | ||
181 | unsigned int feature_req_word; | ||
182 | unsigned int hdrlen; | ||
183 | unsigned char reset_pending_on_curr_blk; | ||
184 | unsigned char delete_blk_timer; | ||
185 | unsigned short kactive_blk_num; | ||
186 | unsigned short blk_sizeof_priv; | ||
187 | |||
188 | /* last_kactive_blk_num: | ||
189 | * trick to see if user-space has caught up | ||
190 | * in order to avoid refreshing timer when every single pkt arrives. | ||
191 | */ | ||
192 | unsigned short last_kactive_blk_num; | ||
193 | |||
194 | char *pkblk_start; | ||
195 | char *pkblk_end; | ||
196 | int kblk_size; | ||
197 | unsigned int knum_blocks; | ||
198 | uint64_t knxt_seq_num; | ||
199 | char *prev; | ||
200 | char *nxt_offset; | ||
201 | struct sk_buff *skb; | ||
202 | |||
203 | atomic_t blk_fill_in_prog; | ||
204 | |||
205 | /* Default is set to 8ms */ | ||
206 | #define DEFAULT_PRB_RETIRE_TOV (8) | ||
207 | |||
208 | unsigned short retire_blk_tov; | ||
209 | unsigned short version; | ||
210 | unsigned long tov_in_jiffies; | ||
211 | |||
212 | /* timer to retire an outstanding block */ | ||
213 | struct timer_list retire_blk_timer; | ||
214 | }; | ||
215 | |||
216 | #define PGV_FROM_VMALLOC 1 | 172 | #define PGV_FROM_VMALLOC 1 |
217 | struct pgv { | ||
218 | char *buffer; | ||
219 | }; | ||
220 | |||
221 | struct packet_ring_buffer { | ||
222 | struct pgv *pg_vec; | ||
223 | unsigned int head; | ||
224 | unsigned int frames_per_block; | ||
225 | unsigned int frame_size; | ||
226 | unsigned int frame_max; | ||
227 | |||
228 | unsigned int pg_vec_order; | ||
229 | unsigned int pg_vec_pages; | ||
230 | unsigned int pg_vec_len; | ||
231 | |||
232 | struct tpacket_kbdq_core prb_bdqc; | ||
233 | atomic_t pending; | ||
234 | }; | ||
235 | 173 | ||
236 | #define BLOCK_STATUS(x) ((x)->hdr.bh1.block_status) | 174 | #define BLOCK_STATUS(x) ((x)->hdr.bh1.block_status) |
237 | #define BLOCK_NUM_PKTS(x) ((x)->hdr.bh1.num_pkts) | 175 | #define BLOCK_NUM_PKTS(x) ((x)->hdr.bh1.num_pkts) |
@@ -269,34 +207,6 @@ static void prb_fill_vlan_info(struct tpacket_kbdq_core *, | |||
269 | struct tpacket3_hdr *); | 207 | struct tpacket3_hdr *); |
270 | static void packet_flush_mclist(struct sock *sk); | 208 | static void packet_flush_mclist(struct sock *sk); |
271 | 209 | ||
272 | struct packet_fanout; | ||
273 | struct packet_sock { | ||
274 | /* struct sock has to be the first member of packet_sock */ | ||
275 | struct sock sk; | ||
276 | struct packet_fanout *fanout; | ||
277 | struct tpacket_stats stats; | ||
278 | union tpacket_stats_u stats_u; | ||
279 | struct packet_ring_buffer rx_ring; | ||
280 | struct packet_ring_buffer tx_ring; | ||
281 | int copy_thresh; | ||
282 | spinlock_t bind_lock; | ||
283 | struct mutex pg_vec_lock; | ||
284 | unsigned int running:1, /* prot_hook is attached*/ | ||
285 | auxdata:1, | ||
286 | origdev:1, | ||
287 | has_vnet_hdr:1; | ||
288 | int ifindex; /* bound device */ | ||
289 | __be16 num; | ||
290 | struct packet_mclist *mclist; | ||
291 | atomic_t mapped; | ||
292 | enum tpacket_versions tp_version; | ||
293 | unsigned int tp_hdrlen; | ||
294 | unsigned int tp_reserve; | ||
295 | unsigned int tp_loss:1; | ||
296 | unsigned int tp_tstamp; | ||
297 | struct packet_type prot_hook ____cacheline_aligned_in_smp; | ||
298 | }; | ||
299 | |||
300 | #define PACKET_FANOUT_MAX 256 | 210 | #define PACKET_FANOUT_MAX 256 |
301 | 211 | ||
302 | struct packet_fanout { | 212 | struct packet_fanout { |
@@ -334,11 +244,6 @@ struct packet_skb_cb { | |||
334 | (((x)->kactive_blk_num < ((x)->knum_blocks-1)) ? \ | 244 | (((x)->kactive_blk_num < ((x)->knum_blocks-1)) ? \ |
335 | ((x)->kactive_blk_num+1) : 0) | 245 | ((x)->kactive_blk_num+1) : 0) |
336 | 246 | ||
337 | static struct packet_sock *pkt_sk(struct sock *sk) | ||
338 | { | ||
339 | return (struct packet_sock *)sk; | ||
340 | } | ||
341 | |||
342 | static void __fanout_unlink(struct sock *sk, struct packet_sock *po); | 247 | static void __fanout_unlink(struct sock *sk, struct packet_sock *po); |
343 | static void __fanout_link(struct sock *sk, struct packet_sock *po); | 248 | static void __fanout_link(struct sock *sk, struct packet_sock *po); |
344 | 249 | ||
diff --git a/net/packet/internal.h b/net/packet/internal.h new file mode 100644 index 000000000000..2c5fca28b242 --- /dev/null +++ b/net/packet/internal.h | |||
@@ -0,0 +1,103 @@ | |||
1 | #ifndef __PACKET_INTERNAL_H__ | ||
2 | #define __PACKET_INTERNAL_H__ | ||
3 | |||
4 | struct 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 */ | ||
14 | struct 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 | |||
51 | struct pgv { | ||
52 | char *buffer; | ||
53 | }; | ||
54 | |||
55 | struct 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 | |||
70 | struct packet_fanout; | ||
71 | struct packet_sock { | ||
72 | /* struct sock has to be the first member of packet_sock */ | ||
73 | struct sock sk; | ||
74 | struct packet_fanout *fanout; | ||
75 | struct tpacket_stats stats; | ||
76 | union tpacket_stats_u stats_u; | ||
77 | struct packet_ring_buffer rx_ring; | ||
78 | struct packet_ring_buffer tx_ring; | ||
79 | int copy_thresh; | ||
80 | spinlock_t bind_lock; | ||
81 | struct mutex pg_vec_lock; | ||
82 | unsigned int running:1, /* prot_hook is attached*/ | ||
83 | auxdata:1, | ||
84 | origdev:1, | ||
85 | has_vnet_hdr:1; | ||
86 | int ifindex; /* bound device */ | ||
87 | __be16 num; | ||
88 | struct packet_mclist *mclist; | ||
89 | atomic_t mapped; | ||
90 | enum tpacket_versions tp_version; | ||
91 | unsigned int tp_hdrlen; | ||
92 | unsigned int tp_reserve; | ||
93 | unsigned int tp_loss:1; | ||
94 | unsigned int tp_tstamp; | ||
95 | struct packet_type prot_hook ____cacheline_aligned_in_smp; | ||
96 | }; | ||
97 | |||
98 | static struct packet_sock *pkt_sk(struct sock *sk) | ||
99 | { | ||
100 | return (struct packet_sock *)sk; | ||
101 | } | ||
102 | |||
103 | #endif | ||