internal.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. struct list_head remove_list;
  13. };
  14. /* kbdq - kernel block descriptor queue */
  15. struct tpacket_kbdq_core {
  16. struct pgv *pkbdq;
  17. unsigned int feature_req_word;
  18. unsigned int hdrlen;
  19. unsigned char reset_pending_on_curr_blk;
  20. unsigned short kactive_blk_num;
  21. unsigned short blk_sizeof_priv;
  22. unsigned short version;
  23. char *pkblk_start;
  24. char *pkblk_end;
  25. int kblk_size;
  26. unsigned int max_frame_len;
  27. unsigned int knum_blocks;
  28. uint64_t knxt_seq_num;
  29. char *prev;
  30. char *nxt_offset;
  31. struct sk_buff *skb;
  32. rwlock_t blk_fill_in_prog_lock;
  33. /* Default is set to 8ms */
  34. #define DEFAULT_PRB_RETIRE_TOV (8)
  35. ktime_t interval_ktime;
  36. /* timer to retire an outstanding block */
  37. struct hrtimer retire_blk_timer;
  38. };
  39. struct pgv {
  40. char *buffer;
  41. };
  42. struct packet_ring_buffer {
  43. struct pgv *pg_vec;
  44. unsigned int head;
  45. unsigned int frames_per_block;
  46. unsigned int frame_size;
  47. unsigned int frame_max;
  48. unsigned int pg_vec_order;
  49. unsigned int pg_vec_pages;
  50. unsigned int pg_vec_len;
  51. unsigned int __percpu *pending_refcnt;
  52. union {
  53. unsigned long *rx_owner_map;
  54. struct tpacket_kbdq_core prb_bdqc;
  55. };
  56. };
  57. extern struct mutex fanout_mutex;
  58. #define PACKET_FANOUT_MAX (1 << 16)
  59. struct packet_fanout {
  60. possible_net_t net;
  61. unsigned int num_members;
  62. u32 max_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. spinlock_t lock;
  72. refcount_t sk_ref;
  73. struct packet_type prot_hook ____cacheline_aligned_in_smp;
  74. struct sock __rcu *arr[] __counted_by(max_num_members);
  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 long flags;
  95. int ifindex; /* bound device */
  96. u8 vnet_hdr_sz;
  97. __be16 num;
  98. struct packet_rollover *rollover;
  99. struct packet_mclist *mclist;
  100. atomic_long_t mapped;
  101. enum tpacket_versions tp_version;
  102. unsigned int tp_hdrlen;
  103. unsigned int tp_reserve;
  104. unsigned int tp_tstamp;
  105. struct completion skb_completion;
  106. struct net_device __rcu *cached_dev;
  107. struct packet_type prot_hook ____cacheline_aligned_in_smp;
  108. atomic_t tp_drops ____cacheline_aligned_in_smp;
  109. };
  110. #define pkt_sk(ptr) container_of_const(ptr, struct packet_sock, sk)
  111. enum packet_sock_flags {
  112. PACKET_SOCK_ORIGDEV,
  113. PACKET_SOCK_AUXDATA,
  114. PACKET_SOCK_TX_HAS_OFF,
  115. PACKET_SOCK_TP_LOSS,
  116. PACKET_SOCK_RUNNING,
  117. PACKET_SOCK_PRESSURE,
  118. PACKET_SOCK_QDISC_BYPASS,
  119. };
  120. static inline void packet_sock_flag_set(struct packet_sock *po,
  121. enum packet_sock_flags flag,
  122. bool val)
  123. {
  124. if (val)
  125. set_bit(flag, &po->flags);
  126. else
  127. clear_bit(flag, &po->flags);
  128. }
  129. static inline bool packet_sock_flag(const struct packet_sock *po,
  130. enum packet_sock_flags flag)
  131. {
  132. return test_bit(flag, &po->flags);
  133. }
  134. #endif