aboutsummaryrefslogtreecommitdiffstats
path: root/net/8021q/vlan.h
diff options
context:
space:
mode:
Diffstat (limited to 'net/8021q/vlan.h')
-rw-r--r--net/8021q/vlan.h58
1 files changed, 49 insertions, 9 deletions
diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h
index 670f1e8cfc0f..ba5983f34c42 100644
--- a/net/8021q/vlan.h
+++ b/net/8021q/vlan.h
@@ -49,6 +49,7 @@ struct netpoll;
49 * @ingress_priority_map: ingress priority mappings 49 * @ingress_priority_map: ingress priority mappings
50 * @nr_egress_mappings: number of egress priority mappings 50 * @nr_egress_mappings: number of egress priority mappings
51 * @egress_priority_map: hash of egress priority mappings 51 * @egress_priority_map: hash of egress priority mappings
52 * @vlan_proto: VLAN encapsulation protocol
52 * @vlan_id: VLAN identifier 53 * @vlan_id: VLAN identifier
53 * @flags: device flags 54 * @flags: device flags
54 * @real_dev: underlying netdevice 55 * @real_dev: underlying netdevice
@@ -62,6 +63,7 @@ struct vlan_dev_priv {
62 unsigned int nr_egress_mappings; 63 unsigned int nr_egress_mappings;
63 struct vlan_priority_tci_mapping *egress_priority_map[16]; 64 struct vlan_priority_tci_mapping *egress_priority_map[16];
64 65
66 __be16 vlan_proto;
65 u16 vlan_id; 67 u16 vlan_id;
66 u16 flags; 68 u16 flags;
67 69
@@ -87,10 +89,17 @@ static inline struct vlan_dev_priv *vlan_dev_priv(const struct net_device *dev)
87#define VLAN_GROUP_ARRAY_SPLIT_PARTS 8 89#define VLAN_GROUP_ARRAY_SPLIT_PARTS 8
88#define VLAN_GROUP_ARRAY_PART_LEN (VLAN_N_VID/VLAN_GROUP_ARRAY_SPLIT_PARTS) 90#define VLAN_GROUP_ARRAY_PART_LEN (VLAN_N_VID/VLAN_GROUP_ARRAY_SPLIT_PARTS)
89 91
92enum vlan_protos {
93 VLAN_PROTO_8021Q = 0,
94 VLAN_PROTO_8021AD,
95 VLAN_PROTO_NUM,
96};
97
90struct vlan_group { 98struct vlan_group {
91 unsigned int nr_vlan_devs; 99 unsigned int nr_vlan_devs;
92 struct hlist_node hlist; /* linked list */ 100 struct hlist_node hlist; /* linked list */
93 struct net_device **vlan_devices_arrays[VLAN_GROUP_ARRAY_SPLIT_PARTS]; 101 struct net_device **vlan_devices_arrays[VLAN_PROTO_NUM]
102 [VLAN_GROUP_ARRAY_SPLIT_PARTS];
94}; 103};
95 104
96struct vlan_info { 105struct vlan_info {
@@ -103,37 +112,67 @@ struct vlan_info {
103 struct rcu_head rcu; 112 struct rcu_head rcu;
104}; 113};
105 114
106static inline struct net_device *vlan_group_get_device(struct vlan_group *vg, 115static inline unsigned int vlan_proto_idx(__be16 proto)
107 u16 vlan_id) 116{
117 switch (proto) {
118 case __constant_htons(ETH_P_8021Q):
119 return VLAN_PROTO_8021Q;
120 case __constant_htons(ETH_P_8021AD):
121 return VLAN_PROTO_8021AD;
122 default:
123 BUG();
124 return 0;
125 }
126}
127
128static inline struct net_device *__vlan_group_get_device(struct vlan_group *vg,
129 unsigned int pidx,
130 u16 vlan_id)
108{ 131{
109 struct net_device **array; 132 struct net_device **array;
110 array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN]; 133
134 array = vg->vlan_devices_arrays[pidx]
135 [vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
111 return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL; 136 return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL;
112} 137}
113 138
139static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
140 __be16 vlan_proto,
141 u16 vlan_id)
142{
143 return __vlan_group_get_device(vg, vlan_proto_idx(vlan_proto), vlan_id);
144}
145
114static inline void vlan_group_set_device(struct vlan_group *vg, 146static inline void vlan_group_set_device(struct vlan_group *vg,
115 u16 vlan_id, 147 __be16 vlan_proto, u16 vlan_id,
116 struct net_device *dev) 148 struct net_device *dev)
117{ 149{
118 struct net_device **array; 150 struct net_device **array;
119 if (!vg) 151 if (!vg)
120 return; 152 return;
121 array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN]; 153 array = vg->vlan_devices_arrays[vlan_proto_idx(vlan_proto)]
154 [vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
122 array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev; 155 array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev;
123} 156}
124 157
125/* Must be invoked with rcu_read_lock or with RTNL. */ 158/* Must be invoked with rcu_read_lock or with RTNL. */
126static inline struct net_device *vlan_find_dev(struct net_device *real_dev, 159static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
127 u16 vlan_id) 160 __be16 vlan_proto, u16 vlan_id)
128{ 161{
129 struct vlan_info *vlan_info = rcu_dereference_rtnl(real_dev->vlan_info); 162 struct vlan_info *vlan_info = rcu_dereference_rtnl(real_dev->vlan_info);
130 163
131 if (vlan_info) 164 if (vlan_info)
132 return vlan_group_get_device(&vlan_info->grp, vlan_id); 165 return vlan_group_get_device(&vlan_info->grp,
166 vlan_proto, vlan_id);
133 167
134 return NULL; 168 return NULL;
135} 169}
136 170
171#define vlan_group_for_each_dev(grp, i, dev) \
172 for ((i) = 0; i < VLAN_PROTO_NUM * VLAN_N_VID; i++) \
173 if (((dev) = __vlan_group_get_device((grp), (i) / VLAN_N_VID, \
174 (i) % VLAN_N_VID)))
175
137/* found in vlan_dev.c */ 176/* found in vlan_dev.c */
138void vlan_dev_set_ingress_priority(const struct net_device *dev, 177void vlan_dev_set_ingress_priority(const struct net_device *dev,
139 u32 skb_prio, u16 vlan_prio); 178 u32 skb_prio, u16 vlan_prio);
@@ -142,7 +181,8 @@ int vlan_dev_set_egress_priority(const struct net_device *dev,
142int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask); 181int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
143void vlan_dev_get_realdev_name(const struct net_device *dev, char *result); 182void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
144 183
145int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id); 184int vlan_check_real_dev(struct net_device *real_dev,
185 __be16 protocol, u16 vlan_id);
146void vlan_setup(struct net_device *dev); 186void vlan_setup(struct net_device *dev);
147int register_vlan_dev(struct net_device *dev); 187int register_vlan_dev(struct net_device *dev);
148void unregister_vlan_dev(struct net_device *dev, struct list_head *head); 188void unregister_vlan_dev(struct net_device *dev, struct list_head *head);