internal.h 2.8 KB

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