mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	Having to say
> #ifdef CONFIG_NET_NS
> 	struct net *net;
> #endif
in structures is a little bit wordy and a little bit error prone.
Instead it is possible to say:
> typedef struct {
> #ifdef CONFIG_NET_NS
>       struct net *net;
> #endif
> } possible_net_t;
And then in a header say:
> 	possible_net_t net;
Which is cleaner and easier to use and easier to test, as the
possible_net_t is always there no matter what the compile options.
Further this allows read_pnet and write_pnet to be functions in all
cases which is better at catching typos.
This change adds possible_net_t, updates the definitions of read_pnet
and write_pnet, updates optional struct net * variables that
write_pnet uses on to have the type possible_net_t, and finally fixes
up the b0rked users of read_pnet and write_pnet.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
		
	
			
		
			
				
	
	
		
			125 lines
		
	
	
	
		
			2.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			125 lines
		
	
	
	
		
			2.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#ifndef __PACKET_INTERNAL_H__
 | 
						|
#define __PACKET_INTERNAL_H__
 | 
						|
 | 
						|
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;
 | 
						|
	unsigned int	max_frame_len;
 | 
						|
	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;
 | 
						|
 | 
						|
	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;
 | 
						|
 | 
						|
	unsigned int __percpu	*pending_refcnt;
 | 
						|
 | 
						|
	struct tpacket_kbdq_core	prb_bdqc;
 | 
						|
};
 | 
						|
 | 
						|
extern struct mutex fanout_mutex;
 | 
						|
#define PACKET_FANOUT_MAX	256
 | 
						|
 | 
						|
struct packet_fanout {
 | 
						|
	possible_net_t		net;
 | 
						|
	unsigned int		num_members;
 | 
						|
	u16			id;
 | 
						|
	u8			type;
 | 
						|
	u8			flags;
 | 
						|
	atomic_t		rr_cur;
 | 
						|
	struct list_head	list;
 | 
						|
	struct sock		*arr[PACKET_FANOUT_MAX];
 | 
						|
	int			next[PACKET_FANOUT_MAX];
 | 
						|
	spinlock_t		lock;
 | 
						|
	atomic_t		sk_ref;
 | 
						|
	struct packet_type	prot_hook ____cacheline_aligned_in_smp;
 | 
						|
};
 | 
						|
 | 
						|
struct packet_sock {
 | 
						|
	/* struct sock has to be the first member of packet_sock */
 | 
						|
	struct sock		sk;
 | 
						|
	struct packet_fanout	*fanout;
 | 
						|
	union  tpacket_stats_u	stats;
 | 
						|
	struct packet_ring_buffer	rx_ring;
 | 
						|
	struct packet_ring_buffer	tx_ring;
 | 
						|
	int			copy_thresh;
 | 
						|
	spinlock_t		bind_lock;
 | 
						|
	struct mutex		pg_vec_lock;
 | 
						|
	unsigned int		running:1,	/* prot_hook is attached*/
 | 
						|
				auxdata:1,
 | 
						|
				origdev:1,
 | 
						|
				has_vnet_hdr:1;
 | 
						|
	int			ifindex;	/* bound device		*/
 | 
						|
	__be16			num;
 | 
						|
	struct packet_mclist	*mclist;
 | 
						|
	atomic_t		mapped;
 | 
						|
	enum tpacket_versions	tp_version;
 | 
						|
	unsigned int		tp_hdrlen;
 | 
						|
	unsigned int		tp_reserve;
 | 
						|
	unsigned int		tp_loss:1;
 | 
						|
	unsigned int		tp_tx_has_off:1;
 | 
						|
	unsigned int		tp_tstamp;
 | 
						|
	struct net_device __rcu	*cached_dev;
 | 
						|
	int			(*xmit)(struct sk_buff *skb);
 | 
						|
	struct packet_type	prot_hook ____cacheline_aligned_in_smp;
 | 
						|
};
 | 
						|
 | 
						|
static struct packet_sock *pkt_sk(struct sock *sk)
 | 
						|
{
 | 
						|
	return (struct packet_sock *)sk;
 | 
						|
}
 | 
						|
 | 
						|
#endif
 |