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