aboutsummaryrefslogtreecommitdiffstats
path: root/net/packet
diff options
context:
space:
mode:
authorchetan loke <loke.chetan@gmail.com>2011-08-25 06:43:30 -0400
committerDavid S. Miller <davem@davemloft.net>2011-08-26 12:38:44 -0400
commitbc59ba399113fcbcac56ba22edde4b816199d48c (patch)
tree16c9023b050de412a934008b99eb8c2cf3464be1 /net/packet
parent165c68d5a291537eaf2d3821a19335c9ec100ba6 (diff)
af_packet: Prefixed tpacket_v3 structs to avoid name space collision
structs introduced in tpacket_v3 implementation are prefixed with 'tpacket' to avoid namespace collision. Compile tested. Signed-off-by: Chetan Loke <loke.chetan@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/packet')
-rw-r--r--net/packet/af_packet.c117
1 files changed, 62 insertions, 55 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 4371e3a67789..2ea3d63e1d4c 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -171,13 +171,13 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
171 171
172#define V3_ALIGNMENT (8) 172#define V3_ALIGNMENT (8)
173 173
174#define BLK_HDR_LEN (ALIGN(sizeof(struct block_desc), V3_ALIGNMENT)) 174#define BLK_HDR_LEN (ALIGN(sizeof(struct tpacket_block_desc), V3_ALIGNMENT))
175 175
176#define BLK_PLUS_PRIV(sz_of_priv) \ 176#define BLK_PLUS_PRIV(sz_of_priv) \
177 (BLK_HDR_LEN + ALIGN((sz_of_priv), V3_ALIGNMENT)) 177 (BLK_HDR_LEN + ALIGN((sz_of_priv), V3_ALIGNMENT))
178 178
179/* kbdq - kernel block descriptor queue */ 179/* kbdq - kernel block descriptor queue */
180struct kbdq_core { 180struct tpacket_kbdq_core {
181 struct pgv *pkbdq; 181 struct pgv *pkbdq;
182 unsigned int feature_req_word; 182 unsigned int feature_req_word;
183 unsigned int hdrlen; 183 unsigned int hdrlen;
@@ -230,7 +230,7 @@ struct packet_ring_buffer {
230 unsigned int pg_vec_pages; 230 unsigned int pg_vec_pages;
231 unsigned int pg_vec_len; 231 unsigned int pg_vec_len;
232 232
233 struct kbdq_core prb_bdqc; 233 struct tpacket_kbdq_core prb_bdqc;
234 atomic_t pending; 234 atomic_t pending;
235}; 235};
236 236
@@ -249,21 +249,25 @@ static void *packet_previous_frame(struct packet_sock *po,
249 struct packet_ring_buffer *rb, 249 struct packet_ring_buffer *rb,
250 int status); 250 int status);
251static void packet_increment_head(struct packet_ring_buffer *buff); 251static void packet_increment_head(struct packet_ring_buffer *buff);
252static int prb_curr_blk_in_use(struct kbdq_core *, 252static int prb_curr_blk_in_use(struct tpacket_kbdq_core *,
253 struct block_desc *); 253 struct tpacket_block_desc *);
254static void *prb_dispatch_next_block(struct kbdq_core *, 254static void *prb_dispatch_next_block(struct tpacket_kbdq_core *,
255 struct packet_sock *); 255 struct packet_sock *);
256static void prb_retire_current_block(struct kbdq_core *, 256static void prb_retire_current_block(struct tpacket_kbdq_core *,
257 struct packet_sock *, unsigned int status); 257 struct packet_sock *, unsigned int status);
258static int prb_queue_frozen(struct kbdq_core *); 258static int prb_queue_frozen(struct tpacket_kbdq_core *);
259static void prb_open_block(struct kbdq_core *, struct block_desc *); 259static void prb_open_block(struct tpacket_kbdq_core *,
260 struct tpacket_block_desc *);
260static void prb_retire_rx_blk_timer_expired(unsigned long); 261static void prb_retire_rx_blk_timer_expired(unsigned long);
261static void _prb_refresh_rx_retire_blk_timer(struct kbdq_core *); 262static void _prb_refresh_rx_retire_blk_timer(struct tpacket_kbdq_core *);
262static void prb_init_blk_timer(struct packet_sock *, struct kbdq_core *, 263static void prb_init_blk_timer(struct packet_sock *,
263 void (*func) (unsigned long)); 264 struct tpacket_kbdq_core *,
264static void prb_fill_rxhash(struct kbdq_core *, struct tpacket3_hdr *); 265 void (*func) (unsigned long));
265static void prb_clear_rxhash(struct kbdq_core *, struct tpacket3_hdr *); 266static void prb_fill_rxhash(struct tpacket_kbdq_core *, struct tpacket3_hdr *);
266static void prb_fill_vlan_info(struct kbdq_core *, struct tpacket3_hdr *); 267static void prb_clear_rxhash(struct tpacket_kbdq_core *,
268 struct tpacket3_hdr *);
269static void prb_fill_vlan_info(struct tpacket_kbdq_core *,
270 struct tpacket3_hdr *);
267static void packet_flush_mclist(struct sock *sk); 271static void packet_flush_mclist(struct sock *sk);
268 272
269struct packet_fanout; 273struct packet_fanout;
@@ -322,11 +326,11 @@ struct packet_skb_cb {
322 326
323#define PACKET_SKB_CB(__skb) ((struct packet_skb_cb *)((__skb)->cb)) 327#define PACKET_SKB_CB(__skb) ((struct packet_skb_cb *)((__skb)->cb))
324 328
325#define GET_PBDQC_FROM_RB(x) ((struct kbdq_core *)(&(x)->prb_bdqc)) 329#define GET_PBDQC_FROM_RB(x) ((struct tpacket_kbdq_core *)(&(x)->prb_bdqc))
326#define GET_PBLOCK_DESC(x, bid) \ 330#define GET_PBLOCK_DESC(x, bid) \
327 ((struct block_desc *)((x)->pkbdq[(bid)].buffer)) 331 ((struct tpacket_block_desc *)((x)->pkbdq[(bid)].buffer))
328#define GET_CURR_PBLOCK_DESC_FROM_CORE(x) \ 332#define GET_CURR_PBLOCK_DESC_FROM_CORE(x) \
329 ((struct block_desc *)((x)->pkbdq[(x)->kactive_blk_num].buffer)) 333 ((struct tpacket_block_desc *)((x)->pkbdq[(x)->kactive_blk_num].buffer))
330#define GET_NEXT_PRB_BLK_NUM(x) \ 334#define GET_NEXT_PRB_BLK_NUM(x) \
331 (((x)->kactive_blk_num < ((x)->knum_blocks-1)) ? \ 335 (((x)->kactive_blk_num < ((x)->knum_blocks-1)) ? \
332 ((x)->kactive_blk_num+1) : 0) 336 ((x)->kactive_blk_num+1) : 0)
@@ -480,7 +484,7 @@ static inline void *packet_current_frame(struct packet_sock *po,
480 return packet_lookup_frame(po, rb, rb->head, status); 484 return packet_lookup_frame(po, rb, rb->head, status);
481} 485}
482 486
483static void prb_del_retire_blk_timer(struct kbdq_core *pkc) 487static void prb_del_retire_blk_timer(struct tpacket_kbdq_core *pkc)
484{ 488{
485 del_timer_sync(&pkc->retire_blk_timer); 489 del_timer_sync(&pkc->retire_blk_timer);
486} 490}
@@ -489,7 +493,7 @@ static void prb_shutdown_retire_blk_timer(struct packet_sock *po,
489 int tx_ring, 493 int tx_ring,
490 struct sk_buff_head *rb_queue) 494 struct sk_buff_head *rb_queue)
491{ 495{
492 struct kbdq_core *pkc; 496 struct tpacket_kbdq_core *pkc;
493 497
494 pkc = tx_ring ? &po->tx_ring.prb_bdqc : &po->rx_ring.prb_bdqc; 498 pkc = tx_ring ? &po->tx_ring.prb_bdqc : &po->rx_ring.prb_bdqc;
495 499
@@ -501,7 +505,7 @@ static void prb_shutdown_retire_blk_timer(struct packet_sock *po,
501} 505}
502 506
503static void prb_init_blk_timer(struct packet_sock *po, 507static void prb_init_blk_timer(struct packet_sock *po,
504 struct kbdq_core *pkc, 508 struct tpacket_kbdq_core *pkc,
505 void (*func) (unsigned long)) 509 void (*func) (unsigned long))
506{ 510{
507 init_timer(&pkc->retire_blk_timer); 511 init_timer(&pkc->retire_blk_timer);
@@ -512,7 +516,7 @@ static void prb_init_blk_timer(struct packet_sock *po,
512 516
513static void prb_setup_retire_blk_timer(struct packet_sock *po, int tx_ring) 517static void prb_setup_retire_blk_timer(struct packet_sock *po, int tx_ring)
514{ 518{
515 struct kbdq_core *pkc; 519 struct tpacket_kbdq_core *pkc;
516 520
517 if (tx_ring) 521 if (tx_ring)
518 BUG(); 522 BUG();
@@ -568,7 +572,7 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po,
568 return tmo; 572 return tmo;
569} 573}
570 574
571static void prb_init_ft_ops(struct kbdq_core *p1, 575static void prb_init_ft_ops(struct tpacket_kbdq_core *p1,
572 union tpacket_req_u *req_u) 576 union tpacket_req_u *req_u)
573{ 577{
574 p1->feature_req_word = req_u->req3.tp_feature_req_word; 578 p1->feature_req_word = req_u->req3.tp_feature_req_word;
@@ -579,14 +583,14 @@ static void init_prb_bdqc(struct packet_sock *po,
579 struct pgv *pg_vec, 583 struct pgv *pg_vec,
580 union tpacket_req_u *req_u, int tx_ring) 584 union tpacket_req_u *req_u, int tx_ring)
581{ 585{
582 struct kbdq_core *p1 = &rb->prb_bdqc; 586 struct tpacket_kbdq_core *p1 = &rb->prb_bdqc;
583 struct block_desc *pbd; 587 struct tpacket_block_desc *pbd;
584 588
585 memset(p1, 0x0, sizeof(*p1)); 589 memset(p1, 0x0, sizeof(*p1));
586 590
587 p1->knxt_seq_num = 1; 591 p1->knxt_seq_num = 1;
588 p1->pkbdq = pg_vec; 592 p1->pkbdq = pg_vec;
589 pbd = (struct block_desc *)pg_vec[0].buffer; 593 pbd = (struct tpacket_block_desc *)pg_vec[0].buffer;
590 p1->pkblk_start = (char *)pg_vec[0].buffer; 594 p1->pkblk_start = (char *)pg_vec[0].buffer;
591 p1->kblk_size = req_u->req3.tp_block_size; 595 p1->kblk_size = req_u->req3.tp_block_size;
592 p1->knum_blocks = req_u->req3.tp_block_nr; 596 p1->knum_blocks = req_u->req3.tp_block_nr;
@@ -610,7 +614,7 @@ static void init_prb_bdqc(struct packet_sock *po,
610/* Do NOT update the last_blk_num first. 614/* Do NOT update the last_blk_num first.
611 * Assumes sk_buff_head lock is held. 615 * Assumes sk_buff_head lock is held.
612 */ 616 */
613static void _prb_refresh_rx_retire_blk_timer(struct kbdq_core *pkc) 617static void _prb_refresh_rx_retire_blk_timer(struct tpacket_kbdq_core *pkc)
614{ 618{
615 mod_timer(&pkc->retire_blk_timer, 619 mod_timer(&pkc->retire_blk_timer,
616 jiffies + pkc->tov_in_jiffies); 620 jiffies + pkc->tov_in_jiffies);
@@ -643,9 +647,9 @@ static void _prb_refresh_rx_retire_blk_timer(struct kbdq_core *pkc)
643static void prb_retire_rx_blk_timer_expired(unsigned long data) 647static void prb_retire_rx_blk_timer_expired(unsigned long data)
644{ 648{
645 struct packet_sock *po = (struct packet_sock *)data; 649 struct packet_sock *po = (struct packet_sock *)data;
646 struct kbdq_core *pkc = &po->rx_ring.prb_bdqc; 650 struct tpacket_kbdq_core *pkc = &po->rx_ring.prb_bdqc;
647 unsigned int frozen; 651 unsigned int frozen;
648 struct block_desc *pbd; 652 struct tpacket_block_desc *pbd;
649 653
650 spin_lock(&po->sk.sk_receive_queue.lock); 654 spin_lock(&po->sk.sk_receive_queue.lock);
651 655
@@ -709,8 +713,8 @@ out:
709 spin_unlock(&po->sk.sk_receive_queue.lock); 713 spin_unlock(&po->sk.sk_receive_queue.lock);
710} 714}
711 715
712static inline void prb_flush_block(struct kbdq_core *pkc1, 716static inline void prb_flush_block(struct tpacket_kbdq_core *pkc1,
713 struct block_desc *pbd1, __u32 status) 717 struct tpacket_block_desc *pbd1, __u32 status)
714{ 718{
715 /* Flush everything minus the block header */ 719 /* Flush everything minus the block header */
716 720
@@ -752,13 +756,14 @@ static inline void prb_flush_block(struct kbdq_core *pkc1,
752 * Note:We DONT refresh the timer on purpose. 756 * Note:We DONT refresh the timer on purpose.
753 * Because almost always the next block will be opened. 757 * Because almost always the next block will be opened.
754 */ 758 */
755static void prb_close_block(struct kbdq_core *pkc1, struct block_desc *pbd1, 759static void prb_close_block(struct tpacket_kbdq_core *pkc1,
760 struct tpacket_block_desc *pbd1,
756 struct packet_sock *po, unsigned int stat) 761 struct packet_sock *po, unsigned int stat)
757{ 762{
758 __u32 status = TP_STATUS_USER | stat; 763 __u32 status = TP_STATUS_USER | stat;
759 764
760 struct tpacket3_hdr *last_pkt; 765 struct tpacket3_hdr *last_pkt;
761 struct hdr_v1 *h1 = &pbd1->hdr.bh1; 766 struct tpacket_hdr_v1 *h1 = &pbd1->hdr.bh1;
762 767
763 if (po->stats.tp_drops) 768 if (po->stats.tp_drops)
764 status |= TP_STATUS_LOSING; 769 status |= TP_STATUS_LOSING;
@@ -786,7 +791,7 @@ static void prb_close_block(struct kbdq_core *pkc1, struct block_desc *pbd1,
786 pkc1->kactive_blk_num = GET_NEXT_PRB_BLK_NUM(pkc1); 791 pkc1->kactive_blk_num = GET_NEXT_PRB_BLK_NUM(pkc1);
787} 792}
788 793
789static inline void prb_thaw_queue(struct kbdq_core *pkc) 794static inline void prb_thaw_queue(struct tpacket_kbdq_core *pkc)
790{ 795{
791 pkc->reset_pending_on_curr_blk = 0; 796 pkc->reset_pending_on_curr_blk = 0;
792} 797}
@@ -798,10 +803,11 @@ static inline void prb_thaw_queue(struct kbdq_core *pkc)
798 * 2) retire_blk_timer is refreshed. 803 * 2) retire_blk_timer is refreshed.
799 * 804 *
800 */ 805 */
801static void prb_open_block(struct kbdq_core *pkc1, struct block_desc *pbd1) 806static void prb_open_block(struct tpacket_kbdq_core *pkc1,
807 struct tpacket_block_desc *pbd1)
802{ 808{
803 struct timespec ts; 809 struct timespec ts;
804 struct hdr_v1 *h1 = &pbd1->hdr.bh1; 810 struct tpacket_hdr_v1 *h1 = &pbd1->hdr.bh1;
805 811
806 smp_rmb(); 812 smp_rmb();
807 813
@@ -861,7 +867,7 @@ static void prb_open_block(struct kbdq_core *pkc1, struct block_desc *pbd1)
861 * case and __packet_lookup_frame_in_block will check if block-0 867 * case and __packet_lookup_frame_in_block will check if block-0
862 * is free and can now be re-used. 868 * is free and can now be re-used.
863 */ 869 */
864static inline void prb_freeze_queue(struct kbdq_core *pkc, 870static inline void prb_freeze_queue(struct tpacket_kbdq_core *pkc,
865 struct packet_sock *po) 871 struct packet_sock *po)
866{ 872{
867 pkc->reset_pending_on_curr_blk = 1; 873 pkc->reset_pending_on_curr_blk = 1;
@@ -876,10 +882,10 @@ static inline void prb_freeze_queue(struct kbdq_core *pkc,
876 * Else, we will freeze the queue. 882 * Else, we will freeze the queue.
877 * So, caller must check the return value. 883 * So, caller must check the return value.
878 */ 884 */
879static void *prb_dispatch_next_block(struct kbdq_core *pkc, 885static void *prb_dispatch_next_block(struct tpacket_kbdq_core *pkc,
880 struct packet_sock *po) 886 struct packet_sock *po)
881{ 887{
882 struct block_desc *pbd; 888 struct tpacket_block_desc *pbd;
883 889
884 smp_rmb(); 890 smp_rmb();
885 891
@@ -901,10 +907,10 @@ static void *prb_dispatch_next_block(struct kbdq_core *pkc,
901 return (void *)pkc->nxt_offset; 907 return (void *)pkc->nxt_offset;
902} 908}
903 909
904static void prb_retire_current_block(struct kbdq_core *pkc, 910static void prb_retire_current_block(struct tpacket_kbdq_core *pkc,
905 struct packet_sock *po, unsigned int status) 911 struct packet_sock *po, unsigned int status)
906{ 912{
907 struct block_desc *pbd = GET_CURR_PBLOCK_DESC_FROM_CORE(pkc); 913 struct tpacket_block_desc *pbd = GET_CURR_PBLOCK_DESC_FROM_CORE(pkc);
908 914
909 /* retire/close the current block */ 915 /* retire/close the current block */
910 if (likely(TP_STATUS_KERNEL == BLOCK_STATUS(pbd))) { 916 if (likely(TP_STATUS_KERNEL == BLOCK_STATUS(pbd))) {
@@ -932,36 +938,36 @@ static void prb_retire_current_block(struct kbdq_core *pkc,
932 BUG(); 938 BUG();
933} 939}
934 940
935static inline int prb_curr_blk_in_use(struct kbdq_core *pkc, 941static inline int prb_curr_blk_in_use(struct tpacket_kbdq_core *pkc,
936 struct block_desc *pbd) 942 struct tpacket_block_desc *pbd)
937{ 943{
938 return TP_STATUS_USER & BLOCK_STATUS(pbd); 944 return TP_STATUS_USER & BLOCK_STATUS(pbd);
939} 945}
940 946
941static inline int prb_queue_frozen(struct kbdq_core *pkc) 947static inline int prb_queue_frozen(struct tpacket_kbdq_core *pkc)
942{ 948{
943 return pkc->reset_pending_on_curr_blk; 949 return pkc->reset_pending_on_curr_blk;
944} 950}
945 951
946static inline void prb_clear_blk_fill_status(struct packet_ring_buffer *rb) 952static inline void prb_clear_blk_fill_status(struct packet_ring_buffer *rb)
947{ 953{
948 struct kbdq_core *pkc = GET_PBDQC_FROM_RB(rb); 954 struct tpacket_kbdq_core *pkc = GET_PBDQC_FROM_RB(rb);
949 atomic_dec(&pkc->blk_fill_in_prog); 955 atomic_dec(&pkc->blk_fill_in_prog);
950} 956}
951 957
952static inline void prb_fill_rxhash(struct kbdq_core *pkc, 958static inline void prb_fill_rxhash(struct tpacket_kbdq_core *pkc,
953 struct tpacket3_hdr *ppd) 959 struct tpacket3_hdr *ppd)
954{ 960{
955 ppd->hv1.tp_rxhash = skb_get_rxhash(pkc->skb); 961 ppd->hv1.tp_rxhash = skb_get_rxhash(pkc->skb);
956} 962}
957 963
958static inline void prb_clear_rxhash(struct kbdq_core *pkc, 964static inline void prb_clear_rxhash(struct tpacket_kbdq_core *pkc,
959 struct tpacket3_hdr *ppd) 965 struct tpacket3_hdr *ppd)
960{ 966{
961 ppd->hv1.tp_rxhash = 0; 967 ppd->hv1.tp_rxhash = 0;
962} 968}
963 969
964static inline void prb_fill_vlan_info(struct kbdq_core *pkc, 970static inline void prb_fill_vlan_info(struct tpacket_kbdq_core *pkc,
965 struct tpacket3_hdr *ppd) 971 struct tpacket3_hdr *ppd)
966{ 972{
967 if (vlan_tx_tag_present(pkc->skb)) { 973 if (vlan_tx_tag_present(pkc->skb)) {
@@ -972,7 +978,7 @@ static inline void prb_fill_vlan_info(struct kbdq_core *pkc,
972 } 978 }
973} 979}
974 980
975static void prb_run_all_ft_ops(struct kbdq_core *pkc, 981static void prb_run_all_ft_ops(struct tpacket_kbdq_core *pkc,
976 struct tpacket3_hdr *ppd) 982 struct tpacket3_hdr *ppd)
977{ 983{
978 prb_fill_vlan_info(pkc, ppd); 984 prb_fill_vlan_info(pkc, ppd);
@@ -983,8 +989,9 @@ static void prb_run_all_ft_ops(struct kbdq_core *pkc,
983 prb_clear_rxhash(pkc, ppd); 989 prb_clear_rxhash(pkc, ppd);
984} 990}
985 991
986static inline void prb_fill_curr_block(char *curr, struct kbdq_core *pkc, 992static inline void prb_fill_curr_block(char *curr,
987 struct block_desc *pbd, 993 struct tpacket_kbdq_core *pkc,
994 struct tpacket_block_desc *pbd,
988 unsigned int len) 995 unsigned int len)
989{ 996{
990 struct tpacket3_hdr *ppd; 997 struct tpacket3_hdr *ppd;
@@ -1006,8 +1013,8 @@ static void *__packet_lookup_frame_in_block(struct packet_sock *po,
1006 unsigned int len 1013 unsigned int len
1007 ) 1014 )
1008{ 1015{
1009 struct kbdq_core *pkc; 1016 struct tpacket_kbdq_core *pkc;
1010 struct block_desc *pbd; 1017 struct tpacket_block_desc *pbd;
1011 char *curr, *end; 1018 char *curr, *end;
1012 1019
1013 pkc = GET_PBDQC_FROM_RB(((struct packet_ring_buffer *)&po->rx_ring)); 1020 pkc = GET_PBDQC_FROM_RB(((struct packet_ring_buffer *)&po->rx_ring));
@@ -1087,8 +1094,8 @@ static inline void *prb_lookup_block(struct packet_sock *po,
1087 unsigned int previous, 1094 unsigned int previous,
1088 int status) 1095 int status)
1089{ 1096{
1090 struct kbdq_core *pkc = GET_PBDQC_FROM_RB(rb); 1097 struct tpacket_kbdq_core *pkc = GET_PBDQC_FROM_RB(rb);
1091 struct block_desc *pbd = GET_PBLOCK_DESC(pkc, previous); 1098 struct tpacket_block_desc *pbd = GET_PBLOCK_DESC(pkc, previous);
1092 1099
1093 if (status != BLOCK_STATUS(pbd)) 1100 if (status != BLOCK_STATUS(pbd))
1094 return NULL; 1101 return NULL;