internal.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. unsigned int __percpu *pending_refcnt;
  56. struct tpacket_kbdq_core prb_bdqc;
  57. };
  58. extern struct mutex fanout_mutex;
  59. #define PACKET_FANOUT_MAX 256
  60. struct packet_fanout {
  61. possible_net_t net;
  62. unsigned int num_members;
  63. u16 id;
  64. u8 type;
  65. u8 flags;
  66. atomic_t rr_cur;
  67. struct list_head list;
  68. struct sock *arr[PACKET_FANOUT_MAX];
  69. spinlock_t lock;
  70. atomic_t sk_ref;
  71. struct packet_type prot_hook ____cacheline_aligned_in_smp;
  72. };
  73. struct packet_rollover {
  74. int sock;
  75. struct rcu_head rcu;
  76. atomic_long_t num;
  77. atomic_long_t num_huge;
  78. atomic_long_t num_failed;
  79. #define ROLLOVER_HLEN (L1_CACHE_BYTES / sizeof(u32))
  80. u32 history[ROLLOVER_HLEN] ____cacheline_aligned;
  81. } ____cacheline_aligned_in_smp;
  82. struct packet_sock {
  83. /* struct sock has to be the first member of packet_sock */
  84. struct sock sk;
  85. struct packet_fanout *fanout;
  86. union tpacket_stats_u stats;
  87. struct packet_ring_buffer rx_ring;
  88. struct packet_ring_buffer tx_ring;
  89. int copy_thresh;
  90. spinlock_t bind_lock;
  91. struct mutex pg_vec_lock;
  92. unsigned int running:1, /* prot_hook is attached*/
  93. auxdata:1,
  94. origdev:1,
  95. has_vnet_hdr:1;
  96. int pressure;
  97. int ifindex; /* bound device */
  98. __be16 num;
  99. struct packet_rollover *rollover;
  100. struct packet_mclist *mclist;
  101. atomic_t mapped;
  102. enum tpacket_versions tp_version;
  103. unsigned int tp_hdrlen;
  104. unsigned int tp_reserve;
  105. unsigned int tp_loss:1;
  106. unsigned int tp_tx_has_off:1;
  107. unsigned int tp_tstamp;
  108. struct net_device __rcu *cached_dev;
  109. int (*xmit)(struct sk_buff *skb);
  110. struct packet_type prot_hook ____cacheline_aligned_in_smp;
  111. };
  112. static struct packet_sock *pkt_sk(struct sock *sk)
  113. {
  114. return (struct packet_sock *)sk;
  115. }
  116. #endif