vlan.h 4.3 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4
#ifndef __BEN_VLAN_802_1Q_INC__
#define __BEN_VLAN_802_1Q_INC__

#include <linux/if_vlan.h>
E
Eric Dumazet 已提交
5
#include <linux/u64_stats_sync.h>
L
Linus Torvalds 已提交
6

7 8 9 10 11 12 13 14 15

/**
 *	struct vlan_priority_tci_mapping - vlan egress priority mappings
 *	@priority: skb priority
 *	@vlan_qos: vlan priority: (skb->priority << 13) & 0xE000
 *	@next: pointer to next struct
 */
struct vlan_priority_tci_mapping {
	u32					priority;
16
	u16					vlan_qos;
17 18 19
	struct vlan_priority_tci_mapping	*next;
};

E
Eric Dumazet 已提交
20 21

/**
E
Eric Dumazet 已提交
22
 *	struct vlan_pcpu_stats - VLAN percpu rx/tx stats
E
Eric Dumazet 已提交
23 24
 *	@rx_packets: number of received packets
 *	@rx_bytes: number of received bytes
E
Eric Dumazet 已提交
25
 *	@rx_multicast: number of received multicast packets
E
Eric Dumazet 已提交
26 27
 *	@tx_packets: number of transmitted packets
 *	@tx_bytes: number of transmitted bytes
E
Eric Dumazet 已提交
28
 *	@syncp: synchronization point for 64bit counters
E
Eric Dumazet 已提交
29 30
 *	@rx_errors: number of rx errors
 *	@tx_dropped: number of tx drops
E
Eric Dumazet 已提交
31
 */
E
Eric Dumazet 已提交
32
struct vlan_pcpu_stats {
E
Eric Dumazet 已提交
33 34 35
	u64			rx_packets;
	u64			rx_bytes;
	u64			rx_multicast;
E
Eric Dumazet 已提交
36 37
	u64			tx_packets;
	u64			tx_bytes;
E
Eric Dumazet 已提交
38
	struct u64_stats_sync	syncp;
E
Eric Dumazet 已提交
39 40
	u32			rx_errors;
	u32			tx_dropped;
E
Eric Dumazet 已提交
41 42
};

43 44 45 46 47 48 49 50 51 52 53
/**
 *	struct vlan_dev_info - VLAN private device data
 *	@nr_ingress_mappings: number of ingress priority mappings
 *	@ingress_priority_map: ingress priority mappings
 *	@nr_egress_mappings: number of egress priority mappings
 *	@egress_priority_map: hash of egress priority mappings
 *	@vlan_id: VLAN identifier
 *	@flags: device flags
 *	@real_dev: underlying netdevice
 *	@real_dev_addr: address of underlying netdevice
 *	@dent: proc dir entry
E
Eric Dumazet 已提交
54
 *	@vlan_pcpu_stats: ptr to percpu rx stats
55 56 57 58 59 60 61
 */
struct vlan_dev_info {
	unsigned int				nr_ingress_mappings;
	u32					ingress_priority_map[8];
	unsigned int				nr_egress_mappings;
	struct vlan_priority_tci_mapping	*egress_priority_map[16];

62 63
	u16					vlan_id;
	u16					flags;
64 65 66 67 68

	struct net_device			*real_dev;
	unsigned char				real_dev_addr[ETH_ALEN];

	struct proc_dir_entry			*dent;
E
Eric Dumazet 已提交
69
	struct vlan_pcpu_stats __percpu		*vlan_pcpu_stats;
70 71 72 73 74 75 76
};

static inline struct vlan_dev_info *vlan_dev_info(const struct net_device *dev)
{
	return netdev_priv(dev);
}

77 78 79 80 81 82 83 84 85 86 87 88
/* Must be invoked with rcu_read_lock or with RTNL. */
static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
					       u16 vlan_id)
{
	struct vlan_group *grp = rcu_dereference_rtnl(real_dev->vlgrp);

	if (grp)
		return vlan_group_get_device(grp, vlan_id);

	return NULL;
}

L
Linus Torvalds 已提交
89
/* found in vlan_dev.c */
90
void vlan_dev_set_ingress_priority(const struct net_device *dev,
91
				   u32 skb_prio, u16 vlan_prio);
92
int vlan_dev_set_egress_priority(const struct net_device *dev,
93
				 u32 skb_prio, u16 vlan_prio);
94
int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
95
void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
L
Linus Torvalds 已提交
96

97
int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id);
P
Patrick McHardy 已提交
98 99
void vlan_setup(struct net_device *dev);
int register_vlan_dev(struct net_device *dev);
100
void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
P
Patrick McHardy 已提交
101

102
static inline u32 vlan_get_ingress_priority(struct net_device *dev,
103
					    u16 vlan_tci)
104 105 106
{
	struct vlan_dev_info *vip = vlan_dev_info(dev);

E
Eric Dumazet 已提交
107
	return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
108 109
}

P
Patrick McHardy 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
#ifdef CONFIG_VLAN_8021Q_GVRP
extern int vlan_gvrp_request_join(const struct net_device *dev);
extern void vlan_gvrp_request_leave(const struct net_device *dev);
extern int vlan_gvrp_init_applicant(struct net_device *dev);
extern void vlan_gvrp_uninit_applicant(struct net_device *dev);
extern int vlan_gvrp_init(void);
extern void vlan_gvrp_uninit(void);
#else
static inline int vlan_gvrp_request_join(const struct net_device *dev) { return 0; }
static inline void vlan_gvrp_request_leave(const struct net_device *dev) {}
static inline int vlan_gvrp_init_applicant(struct net_device *dev) { return 0; }
static inline void vlan_gvrp_uninit_applicant(struct net_device *dev) {}
static inline int vlan_gvrp_init(void) { return 0; }
static inline void vlan_gvrp_uninit(void) {}
#endif

126 127 128 129
extern const char vlan_fullname[];
extern const char vlan_version[];
extern int vlan_netlink_init(void);
extern void vlan_netlink_fini(void);
P
Patrick McHardy 已提交
130 131 132

extern struct rtnl_link_ops vlan_link_ops;

133 134
extern int vlan_net_id;

135 136
struct proc_dir_entry;

137
struct vlan_net {
138 139 140 141
	/* /proc/net/vlan */
	struct proc_dir_entry *proc_vlan_dir;
	/* /proc/net/vlan/config */
	struct proc_dir_entry *proc_vlan_conf;
142 143
	/* Determines interface naming scheme. */
	unsigned short name_type;
144 145
};

L
Linus Torvalds 已提交
146
#endif /* !(__BEN_VLAN_802_1Q_INC__) */