blob: 28d8dc20cb6dbe675bad69ecb85abf777d8a2756 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __BEN_VLAN_802_1Q_INC__
2#define __BEN_VLAN_802_1Q_INC__
3
4#include <linux/if_vlan.h>
Eric Dumazet9618e2f2010-06-24 00:55:06 +00005#include <linux/u64_stats_sync.h>
Jiri Pirko5b9ea6e2011-12-08 04:11:18 +00006#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Patrick McHardy22d1ba72008-07-08 03:23:57 -07008
9/**
10 * struct vlan_priority_tci_mapping - vlan egress priority mappings
11 * @priority: skb priority
12 * @vlan_qos: vlan priority: (skb->priority << 13) & 0xE000
13 * @next: pointer to next struct
14 */
15struct vlan_priority_tci_mapping {
16 u32 priority;
Patrick McHardy9bb85822008-07-08 03:24:44 -070017 u16 vlan_qos;
Patrick McHardy22d1ba72008-07-08 03:23:57 -070018 struct vlan_priority_tci_mapping *next;
19};
20
Eric Dumazet97932412009-11-17 04:53:09 +000021
22/**
Eric Dumazet4af429d2010-11-10 23:42:00 +000023 * struct vlan_pcpu_stats - VLAN percpu rx/tx stats
Eric Dumazet97932412009-11-17 04:53:09 +000024 * @rx_packets: number of received packets
25 * @rx_bytes: number of received bytes
Eric Dumazet9618e2f2010-06-24 00:55:06 +000026 * @rx_multicast: number of received multicast packets
Eric Dumazet4af429d2010-11-10 23:42:00 +000027 * @tx_packets: number of transmitted packets
28 * @tx_bytes: number of transmitted bytes
Eric Dumazet9618e2f2010-06-24 00:55:06 +000029 * @syncp: synchronization point for 64bit counters
Eric Dumazet4af429d2010-11-10 23:42:00 +000030 * @rx_errors: number of rx errors
31 * @tx_dropped: number of tx drops
Eric Dumazet97932412009-11-17 04:53:09 +000032 */
Eric Dumazet4af429d2010-11-10 23:42:00 +000033struct vlan_pcpu_stats {
Eric Dumazet9618e2f2010-06-24 00:55:06 +000034 u64 rx_packets;
35 u64 rx_bytes;
36 u64 rx_multicast;
Eric Dumazet4af429d2010-11-10 23:42:00 +000037 u64 tx_packets;
38 u64 tx_bytes;
Eric Dumazet9618e2f2010-06-24 00:55:06 +000039 struct u64_stats_sync syncp;
Eric Dumazet4af429d2010-11-10 23:42:00 +000040 u32 rx_errors;
41 u32 tx_dropped;
Eric Dumazet97932412009-11-17 04:53:09 +000042};
43
Patrick McHardy22d1ba72008-07-08 03:23:57 -070044/**
Jiri Pirko7da82c02011-12-08 04:11:15 +000045 * struct vlan_dev_priv - VLAN private device data
Patrick McHardy22d1ba72008-07-08 03:23:57 -070046 * @nr_ingress_mappings: number of ingress priority mappings
47 * @ingress_priority_map: ingress priority mappings
48 * @nr_egress_mappings: number of egress priority mappings
49 * @egress_priority_map: hash of egress priority mappings
50 * @vlan_id: VLAN identifier
51 * @flags: device flags
52 * @real_dev: underlying netdevice
53 * @real_dev_addr: address of underlying netdevice
54 * @dent: proc dir entry
Eric Dumazet4af429d2010-11-10 23:42:00 +000055 * @vlan_pcpu_stats: ptr to percpu rx stats
Patrick McHardy22d1ba72008-07-08 03:23:57 -070056 */
Jiri Pirko7da82c02011-12-08 04:11:15 +000057struct vlan_dev_priv {
Patrick McHardy22d1ba72008-07-08 03:23:57 -070058 unsigned int nr_ingress_mappings;
59 u32 ingress_priority_map[8];
60 unsigned int nr_egress_mappings;
61 struct vlan_priority_tci_mapping *egress_priority_map[16];
62
Patrick McHardy9bb85822008-07-08 03:24:44 -070063 u16 vlan_id;
64 u16 flags;
Patrick McHardy22d1ba72008-07-08 03:23:57 -070065
66 struct net_device *real_dev;
67 unsigned char real_dev_addr[ETH_ALEN];
68
69 struct proc_dir_entry *dent;
Eric Dumazet4af429d2010-11-10 23:42:00 +000070 struct vlan_pcpu_stats __percpu *vlan_pcpu_stats;
Patrick McHardy22d1ba72008-07-08 03:23:57 -070071};
72
Jiri Pirko7da82c02011-12-08 04:11:15 +000073static inline struct vlan_dev_priv *vlan_dev_priv(const struct net_device *dev)
Patrick McHardy22d1ba72008-07-08 03:23:57 -070074{
75 return netdev_priv(dev);
76}
77
Jiri Pirko5b9ea6e2011-12-08 04:11:18 +000078/* if this changes, algorithm will have to be reworked because this
79 * depends on completely exhausting the VLAN identifier space. Thus
80 * it gives constant time look-up, but in many cases it wastes memory.
81 */
82#define VLAN_GROUP_ARRAY_SPLIT_PARTS 8
83#define VLAN_GROUP_ARRAY_PART_LEN (VLAN_N_VID/VLAN_GROUP_ARRAY_SPLIT_PARTS)
84
85struct vlan_group {
86 unsigned int nr_vlan_devs;
87 struct hlist_node hlist; /* linked list */
88 struct net_device **vlan_devices_arrays[VLAN_GROUP_ARRAY_SPLIT_PARTS];
89};
90
91struct vlan_info {
92 struct net_device *real_dev; /* The ethernet(like) device
93 * the vlan is attached to.
94 */
95 struct vlan_group grp;
96 struct list_head vid_list;
97 unsigned int nr_vids;
98 struct rcu_head rcu;
99};
100
Jiri Pirko536d1d42011-07-20 04:54:49 +0000101static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
102 u16 vlan_id)
103{
104 struct net_device **array;
105 array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
106 return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL;
107}
108
109static inline void vlan_group_set_device(struct vlan_group *vg,
110 u16 vlan_id,
111 struct net_device *dev)
112{
113 struct net_device **array;
114 if (!vg)
115 return;
116 array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
117 array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev;
118}
119
David Lamparter69ecca82011-07-17 08:53:12 +0000120/* Must be invoked with rcu_read_lock or with RTNL. */
121static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
122 u16 vlan_id)
123{
Jiri Pirko5b9ea6e2011-12-08 04:11:18 +0000124 struct vlan_info *vlan_info = rcu_dereference_rtnl(real_dev->vlan_info);
David Lamparter69ecca82011-07-17 08:53:12 +0000125
Jiri Pirko5b9ea6e2011-12-08 04:11:18 +0000126 if (vlan_info)
127 return vlan_group_get_device(&vlan_info->grp, vlan_id);
David Lamparter69ecca82011-07-17 08:53:12 +0000128
129 return NULL;
130}
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/* found in vlan_dev.c */
Patrick McHardyc17d8872007-06-13 12:05:22 -0700133void vlan_dev_set_ingress_priority(const struct net_device *dev,
Patrick McHardy9bb85822008-07-08 03:24:44 -0700134 u32 skb_prio, u16 vlan_prio);
Patrick McHardyc17d8872007-06-13 12:05:22 -0700135int vlan_dev_set_egress_priority(const struct net_device *dev,
Patrick McHardy9bb85822008-07-08 03:24:44 -0700136 u32 skb_prio, u16 vlan_prio);
Patrick McHardyb3ce0322008-07-05 21:26:27 -0700137int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
Patrick McHardyc17d8872007-06-13 12:05:22 -0700138void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Patrick McHardy9bb85822008-07-08 03:24:44 -0700140int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id);
Patrick McHardy07b5b172007-06-13 12:07:54 -0700141void vlan_setup(struct net_device *dev);
142int register_vlan_dev(struct net_device *dev);
Eric Dumazet23289a32009-10-27 07:06:36 +0000143void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
Patrick McHardy07b5b172007-06-13 12:07:54 -0700144
Patrick McHardy7750f402008-07-08 03:23:36 -0700145static inline u32 vlan_get_ingress_priority(struct net_device *dev,
Patrick McHardy9bb85822008-07-08 03:24:44 -0700146 u16 vlan_tci)
Patrick McHardy7750f402008-07-08 03:23:36 -0700147{
Jiri Pirko7da82c02011-12-08 04:11:15 +0000148 struct vlan_dev_priv *vip = vlan_dev_priv(dev);
Patrick McHardy7750f402008-07-08 03:23:36 -0700149
Eric Dumazet05423b22009-10-26 18:40:35 -0700150 return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
Patrick McHardy7750f402008-07-08 03:23:36 -0700151}
152
Patrick McHardy70c03b42008-07-05 21:26:57 -0700153#ifdef CONFIG_VLAN_8021Q_GVRP
154extern int vlan_gvrp_request_join(const struct net_device *dev);
155extern void vlan_gvrp_request_leave(const struct net_device *dev);
156extern int vlan_gvrp_init_applicant(struct net_device *dev);
157extern void vlan_gvrp_uninit_applicant(struct net_device *dev);
158extern int vlan_gvrp_init(void);
159extern void vlan_gvrp_uninit(void);
160#else
161static inline int vlan_gvrp_request_join(const struct net_device *dev) { return 0; }
162static inline void vlan_gvrp_request_leave(const struct net_device *dev) {}
163static inline int vlan_gvrp_init_applicant(struct net_device *dev) { return 0; }
164static inline void vlan_gvrp_uninit_applicant(struct net_device *dev) {}
165static inline int vlan_gvrp_init(void) { return 0; }
166static inline void vlan_gvrp_uninit(void) {}
167#endif
168
Stephen Hemmingerb30200612008-10-28 22:12:36 -0700169extern const char vlan_fullname[];
170extern const char vlan_version[];
171extern int vlan_netlink_init(void);
172extern void vlan_netlink_fini(void);
Patrick McHardy07b5b172007-06-13 12:07:54 -0700173
174extern struct rtnl_link_ops vlan_link_ops;
175
Pavel Emelyanovd9ed0f02008-04-16 00:49:09 -0700176extern int vlan_net_id;
177
Pavel Emelyanova59a8c12008-04-16 00:51:51 -0700178struct proc_dir_entry;
179
Pavel Emelyanovd9ed0f02008-04-16 00:49:09 -0700180struct vlan_net {
Pavel Emelyanova59a8c12008-04-16 00:51:51 -0700181 /* /proc/net/vlan */
182 struct proc_dir_entry *proc_vlan_dir;
183 /* /proc/net/vlan/config */
184 struct proc_dir_entry *proc_vlan_conf;
Pavel Emelyanov7a17a2f2008-04-16 00:54:39 -0700185 /* Determines interface naming scheme. */
186 unsigned short name_type;
Pavel Emelyanovd9ed0f02008-04-16 00:49:09 -0700187};
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189#endif /* !(__BEN_VLAN_802_1Q_INC__) */