internal.h 3.1 KB

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