internal.h 3.3 KB

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