internal.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. union {
  67. atomic_t rr_cur;
  68. struct bpf_prog __rcu *bpf_prog;
  69. };
  70. struct list_head list;
  71. struct sock *arr[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_rollover {
  77. int sock;
  78. atomic_long_t num;
  79. atomic_long_t num_huge;
  80. atomic_long_t num_failed;
  81. #define ROLLOVER_HLEN (L1_CACHE_BYTES / sizeof(u32))
  82. u32 history[ROLLOVER_HLEN] ____cacheline_aligned;
  83. } ____cacheline_aligned_in_smp;
  84. struct packet_sock {
  85. /* struct sock has to be the first member of packet_sock */
  86. struct sock sk;
  87. struct packet_fanout *fanout;
  88. union tpacket_stats_u stats;
  89. struct packet_ring_buffer rx_ring;
  90. struct packet_ring_buffer tx_ring;
  91. int copy_thresh;
  92. spinlock_t bind_lock;
  93. struct mutex pg_vec_lock;
  94. unsigned int running; /* bind_lock must be held */
  95. unsigned int auxdata:1, /* writer must hold sock lock */
  96. origdev:1,
  97. has_vnet_hdr:1,
  98. tp_loss:1,
  99. tp_tx_has_off: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_tstamp;
  110. struct net_device __rcu *cached_dev;
  111. int (*xmit)(struct sk_buff *skb);
  112. struct packet_type prot_hook ____cacheline_aligned_in_smp;
  113. };
  114. static struct packet_sock *pkt_sk(struct sock *sk)
  115. {
  116. return (struct packet_sock *)sk;
  117. }
  118. #endif