Blame view

net/packet/internal.h 3.17 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
2787b04b6   Pavel Emelyanov   packet: Introduce...
2
3
  #ifndef __PACKET_INTERNAL_H__
  #define __PACKET_INTERNAL_H__
fb5c2c17a   Reshetova, Elena   net: convert pack...
4
  #include <linux/refcount.h>
2787b04b6   Pavel Emelyanov   packet: Introduce...
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  struct packet_mclist {
  	struct packet_mclist	*next;
  	int			ifindex;
  	int			count;
  	unsigned short		type;
  	unsigned short		alen;
  	unsigned char		addr[MAX_ADDR_LEN];
  };
  
  /* kbdq - kernel block descriptor queue */
  struct tpacket_kbdq_core {
  	struct pgv	*pkbdq;
  	unsigned int	feature_req_word;
  	unsigned int	hdrlen;
  	unsigned char	reset_pending_on_curr_blk;
  	unsigned char   delete_blk_timer;
  	unsigned short	kactive_blk_num;
  	unsigned short	blk_sizeof_priv;
  
  	/* last_kactive_blk_num:
  	 * trick to see if user-space has caught up
  	 * in order to avoid refreshing timer when every single pkt arrives.
  	 */
  	unsigned short	last_kactive_blk_num;
  
  	char		*pkblk_start;
  	char		*pkblk_end;
  	int		kblk_size;
dc808110b   Eric Dumazet   packet: handle to...
33
  	unsigned int	max_frame_len;
2787b04b6   Pavel Emelyanov   packet: Introduce...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  	unsigned int	knum_blocks;
  	uint64_t	knxt_seq_num;
  	char		*prev;
  	char		*nxt_offset;
  	struct sk_buff	*skb;
  
  	atomic_t	blk_fill_in_prog;
  
  	/* Default is set to 8ms */
  #define DEFAULT_PRB_RETIRE_TOV	(8)
  
  	unsigned short  retire_blk_tov;
  	unsigned short  version;
  	unsigned long	tov_in_jiffies;
  
  	/* timer to retire an outstanding block */
  	struct timer_list retire_blk_timer;
  };
  
  struct pgv {
  	char *buffer;
  };
  
  struct packet_ring_buffer {
  	struct pgv		*pg_vec;
0578edc56   Daniel Borkmann   packet: reorder a...
59

2787b04b6   Pavel Emelyanov   packet: Introduce...
60
61
62
63
  	unsigned int		head;
  	unsigned int		frames_per_block;
  	unsigned int		frame_size;
  	unsigned int		frame_max;
3a7ad0634   Eric Dumazet   Revert "packet: s...
64
  	unsigned int		pg_vec_order;
2787b04b6   Pavel Emelyanov   packet: Introduce...
65
66
  	unsigned int		pg_vec_pages;
  	unsigned int		pg_vec_len;
b01384081   Daniel Borkmann   packet: use percp...
67
  	unsigned int __percpu	*pending_refcnt;
0578edc56   Daniel Borkmann   packet: reorder a...
68
69
  
  	struct tpacket_kbdq_core	prb_bdqc;
2787b04b6   Pavel Emelyanov   packet: Introduce...
70
  };
fff3321d7   Pavel Emelyanov   packet: Report fa...
71
72
73
74
  extern struct mutex fanout_mutex;
  #define PACKET_FANOUT_MAX	256
  
  struct packet_fanout {
0c5c9fb55   Eric W. Biederman   net: Introduce po...
75
  	possible_net_t		net;
fff3321d7   Pavel Emelyanov   packet: Report fa...
76
77
78
  	unsigned int		num_members;
  	u16			id;
  	u8			type;
77f65ebdc   Willem de Bruijn   packet: packet fa...
79
  	u8			flags;
47dceb8ec   Willem de Bruijn   packet: add class...
80
81
82
83
  	union {
  		atomic_t		rr_cur;
  		struct bpf_prog __rcu	*bpf_prog;
  	};
fff3321d7   Pavel Emelyanov   packet: Report fa...
84
85
86
  	struct list_head	list;
  	struct sock		*arr[PACKET_FANOUT_MAX];
  	spinlock_t		lock;
fb5c2c17a   Reshetova, Elena   net: convert pack...
87
  	refcount_t		sk_ref;
fff3321d7   Pavel Emelyanov   packet: Report fa...
88
89
  	struct packet_type	prot_hook ____cacheline_aligned_in_smp;
  };
0648ab70a   Willem de Bruijn   packet: rollover ...
90
91
  struct packet_rollover {
  	int			sock;
a9b639181   Willem de Bruijn   packet: rollover ...
92
93
94
  	atomic_long_t		num;
  	atomic_long_t		num_huge;
  	atomic_long_t		num_failed;
3b3a5b0aa   Willem de Bruijn   packet: rollover ...
95
96
  #define ROLLOVER_HLEN	(L1_CACHE_BYTES / sizeof(u32))
  	u32			history[ROLLOVER_HLEN] ____cacheline_aligned;
0648ab70a   Willem de Bruijn   packet: rollover ...
97
  } ____cacheline_aligned_in_smp;
2787b04b6   Pavel Emelyanov   packet: Introduce...
98
99
100
101
  struct packet_sock {
  	/* struct sock has to be the first member of packet_sock */
  	struct sock		sk;
  	struct packet_fanout	*fanout;
ee80fbf30   Daniel Borkmann   packet: account s...
102
  	union  tpacket_stats_u	stats;
2787b04b6   Pavel Emelyanov   packet: Introduce...
103
104
105
106
107
  	struct packet_ring_buffer	rx_ring;
  	struct packet_ring_buffer	tx_ring;
  	int			copy_thresh;
  	spinlock_t		bind_lock;
  	struct mutex		pg_vec_lock;
a6361f0ca   Willem de Bruijn   packet: fix bitfi...
108
109
  	unsigned int		running;	/* bind_lock must be held */
  	unsigned int		auxdata:1,	/* writer must hold sock lock */
2787b04b6   Pavel Emelyanov   packet: Introduce...
110
  				origdev:1,
a6361f0ca   Willem de Bruijn   packet: fix bitfi...
111
112
113
  				has_vnet_hdr:1,
  				tp_loss:1,
  				tp_tx_has_off:1;
2ccdbaa6d   Willem de Bruijn   packet: rollover ...
114
  	int			pressure;
2787b04b6   Pavel Emelyanov   packet: Introduce...
115
116
  	int			ifindex;	/* bound device		*/
  	__be16			num;
0648ab70a   Willem de Bruijn   packet: rollover ...
117
  	struct packet_rollover	*rollover;
2787b04b6   Pavel Emelyanov   packet: Introduce...
118
119
120
121
122
  	struct packet_mclist	*mclist;
  	atomic_t		mapped;
  	enum tpacket_versions	tp_version;
  	unsigned int		tp_hdrlen;
  	unsigned int		tp_reserve;
2787b04b6   Pavel Emelyanov   packet: Introduce...
123
  	unsigned int		tp_tstamp;
e40526cb2   Daniel Borkmann   packet: fix use a...
124
  	struct net_device __rcu	*cached_dev;
d346a3fae   Daniel Borkmann   packet: introduce...
125
  	int			(*xmit)(struct sk_buff *skb);
2787b04b6   Pavel Emelyanov   packet: Introduce...
126
127
128
129
130
131
132
133
134
  	struct packet_type	prot_hook ____cacheline_aligned_in_smp;
  };
  
  static struct packet_sock *pkt_sk(struct sock *sk)
  {
  	return (struct packet_sock *)sk;
  }
  
  #endif