internal.h 3.2 KB

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