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.h54
1 files changed, 45 insertions, 9 deletions
diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h
index 670f1e8cfc0f..245de9653db0 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,16 @@ 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_NUM,
95};
96
90struct vlan_group { 97struct vlan_group {
91 unsigned int nr_vlan_devs; 98 unsigned int nr_vlan_devs;
92 struct hlist_node hlist; /* linked list */ 99 struct hlist_node hlist; /* linked list */
93 struct net_device **vlan_devices_arrays[VLAN_GROUP_ARRAY_SPLIT_PARTS]; 100 struct net_device **vlan_devices_arrays[VLAN_PROTO_NUM]
101 [VLAN_GROUP_ARRAY_SPLIT_PARTS];
94}; 102};
95 103
96struct vlan_info { 104struct vlan_info {
@@ -103,37 +111,64 @@ struct vlan_info {
103 struct rcu_head rcu; 111 struct rcu_head rcu;
104}; 112};
105 113
106static inline struct net_device *vlan_group_get_device(struct vlan_group *vg, 114static inline unsigned int vlan_proto_idx(__be16 proto)
107 u16 vlan_id) 115{
116 switch (proto) {
117 case __constant_htons(ETH_P_8021Q):
118 return VLAN_PROTO_8021Q;
119 default:
120 BUG();
121 }
122}
123
124static inline struct net_device *__vlan_group_get_device(struct vlan_group *vg,
125 unsigned int pidx,
126 u16 vlan_id)
108{ 127{
109 struct net_device **array; 128 struct net_device **array;
110 array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN]; 129
130 array = vg->vlan_devices_arrays[pidx]
131 [vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
111 return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL; 132 return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL;
112} 133}
113 134
135static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
136 __be16 vlan_proto,
137 u16 vlan_id)
138{
139 return __vlan_group_get_device(vg, vlan_proto_idx(vlan_proto), vlan_id);
140}
141
114static inline void vlan_group_set_device(struct vlan_group *vg, 142static inline void vlan_group_set_device(struct vlan_group *vg,
115 u16 vlan_id, 143 __be16 vlan_proto, u16 vlan_id,
116 struct net_device *dev) 144 struct net_device *dev)
117{ 145{
118 struct net_device **array; 146 struct net_device **array;
119 if (!vg) 147 if (!vg)
120 return; 148 return;
121 array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN]; 149 array = vg->vlan_devices_arrays[vlan_proto_idx(vlan_proto)]
150 [vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
122 array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev; 151 array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev;
123} 152}
124 153
125/* Must be invoked with rcu_read_lock or with RTNL. */ 154/* Must be invoked with rcu_read_lock or with RTNL. */
126static inline struct net_device *vlan_find_dev(struct net_device *real_dev, 155static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
127 u16 vlan_id) 156 __be16 vlan_proto, u16 vlan_id)
128{ 157{
129 struct vlan_info *vlan_info = rcu_dereference_rtnl(real_dev->vlan_info); 158 struct vlan_info *vlan_info = rcu_dereference_rtnl(real_dev->vlan_info);
130 159
131 if (vlan_info) 160 if (vlan_info)
132 return vlan_group_get_device(&vlan_info->grp, vlan_id); 161 return vlan_group_get_device(&vlan_info->grp,
162 vlan_proto, vlan_id);
133 163
134 return NULL; 164 return NULL;
135} 165}
136 166
167#define vlan_group_for_each_dev(grp, i, dev) \
168 for ((i) = 0; i < VLAN_PROTO_NUM * VLAN_N_VID; i++) \
169 if (((dev) = __vlan_group_get_device((grp), (i) / VLAN_N_VID, \
170 (i) % VLAN_N_VID)))
171
137/* found in vlan_dev.c */ 172/* found in vlan_dev.c */
138void vlan_dev_set_ingress_priority(const struct net_device *dev, 173void vlan_dev_set_ingress_priority(const struct net_device *dev,
139 u32 skb_prio, u16 vlan_prio); 174 u32 skb_prio, u16 vlan_prio);
@@ -142,7 +177,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); 177int 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); 178void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
144 179
145int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id); 180int vlan_check_real_dev(struct net_device *real_dev,
181 __be16 protocol, u16 vlan_id);
146void vlan_setup(struct net_device *dev); 182void vlan_setup(struct net_device *dev);
147int register_vlan_dev(struct net_device *dev); 183int register_vlan_dev(struct net_device *dev);
148void unregister_vlan_dev(struct net_device *dev, struct list_head *head); 184void unregister_vlan_dev(struct net_device *dev, struct list_head *head);