diff options
Diffstat (limited to 'include/linux/if_vlan.h')
-rw-r--r-- | include/linux/if_vlan.h | 93 |
1 files changed, 84 insertions, 9 deletions
diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h index 3d870fda8c4f..affa27380b72 100644 --- a/include/linux/if_vlan.h +++ b/include/linux/if_vlan.h | |||
@@ -16,6 +16,7 @@ | |||
16 | #ifdef __KERNEL__ | 16 | #ifdef __KERNEL__ |
17 | #include <linux/netdevice.h> | 17 | #include <linux/netdevice.h> |
18 | #include <linux/etherdevice.h> | 18 | #include <linux/etherdevice.h> |
19 | #include <linux/rtnetlink.h> | ||
19 | 20 | ||
20 | #define VLAN_HLEN 4 /* The additional bytes (on top of the Ethernet header) | 21 | #define VLAN_HLEN 4 /* The additional bytes (on top of the Ethernet header) |
21 | * that VLAN requires. | 22 | * that VLAN requires. |
@@ -68,6 +69,7 @@ static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb) | |||
68 | #define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator */ | 69 | #define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator */ |
69 | #define VLAN_TAG_PRESENT VLAN_CFI_MASK | 70 | #define VLAN_TAG_PRESENT VLAN_CFI_MASK |
70 | #define VLAN_VID_MASK 0x0fff /* VLAN Identifier */ | 71 | #define VLAN_VID_MASK 0x0fff /* VLAN Identifier */ |
72 | #define VLAN_N_VID 4096 | ||
71 | 73 | ||
72 | /* found in socket.c */ | 74 | /* found in socket.c */ |
73 | extern void vlan_ioctl_set(int (*hook)(struct net *, void __user *)); | 75 | extern void vlan_ioctl_set(int (*hook)(struct net *, void __user *)); |
@@ -76,16 +78,14 @@ extern void vlan_ioctl_set(int (*hook)(struct net *, void __user *)); | |||
76 | * depends on completely exhausting the VLAN identifier space. Thus | 78 | * depends on completely exhausting the VLAN identifier space. Thus |
77 | * it gives constant time look-up, but in many cases it wastes memory. | 79 | * it gives constant time look-up, but in many cases it wastes memory. |
78 | */ | 80 | */ |
79 | #define VLAN_GROUP_ARRAY_LEN 4096 | ||
80 | #define VLAN_GROUP_ARRAY_SPLIT_PARTS 8 | 81 | #define VLAN_GROUP_ARRAY_SPLIT_PARTS 8 |
81 | #define VLAN_GROUP_ARRAY_PART_LEN (VLAN_GROUP_ARRAY_LEN/VLAN_GROUP_ARRAY_SPLIT_PARTS) | 82 | #define VLAN_GROUP_ARRAY_PART_LEN (VLAN_N_VID/VLAN_GROUP_ARRAY_SPLIT_PARTS) |
82 | 83 | ||
83 | struct vlan_group { | 84 | struct vlan_group { |
84 | struct net_device *real_dev; /* The ethernet(like) device | 85 | struct net_device *real_dev; /* The ethernet(like) device |
85 | * the vlan is attached to. | 86 | * the vlan is attached to. |
86 | */ | 87 | */ |
87 | unsigned int nr_vlans; | 88 | unsigned int nr_vlans; |
88 | int killall; | ||
89 | struct hlist_node hlist; /* linked list */ | 89 | struct hlist_node hlist; /* linked list */ |
90 | struct net_device **vlan_devices_arrays[VLAN_GROUP_ARRAY_SPLIT_PARTS]; | 90 | struct net_device **vlan_devices_arrays[VLAN_GROUP_ARRAY_SPLIT_PARTS]; |
91 | struct rcu_head rcu; | 91 | struct rcu_head rcu; |
@@ -110,16 +110,34 @@ static inline void vlan_group_set_device(struct vlan_group *vg, | |||
110 | array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev; | 110 | array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev; |
111 | } | 111 | } |
112 | 112 | ||
113 | static inline int is_vlan_dev(struct net_device *dev) | ||
114 | { | ||
115 | return dev->priv_flags & IFF_802_1Q_VLAN; | ||
116 | } | ||
117 | |||
113 | #define vlan_tx_tag_present(__skb) ((__skb)->vlan_tci & VLAN_TAG_PRESENT) | 118 | #define vlan_tx_tag_present(__skb) ((__skb)->vlan_tci & VLAN_TAG_PRESENT) |
114 | #define vlan_tx_tag_get(__skb) ((__skb)->vlan_tci & ~VLAN_TAG_PRESENT) | 119 | #define vlan_tx_tag_get(__skb) ((__skb)->vlan_tci & ~VLAN_TAG_PRESENT) |
115 | 120 | ||
116 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) | 121 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
122 | /* Must be invoked with rcu_read_lock or with RTNL. */ | ||
123 | static inline struct net_device *vlan_find_dev(struct net_device *real_dev, | ||
124 | u16 vlan_id) | ||
125 | { | ||
126 | struct vlan_group *grp = rcu_dereference_rtnl(real_dev->vlgrp); | ||
127 | |||
128 | if (grp) | ||
129 | return vlan_group_get_device(grp, vlan_id); | ||
130 | |||
131 | return NULL; | ||
132 | } | ||
133 | |||
117 | extern struct net_device *vlan_dev_real_dev(const struct net_device *dev); | 134 | extern struct net_device *vlan_dev_real_dev(const struct net_device *dev); |
118 | extern u16 vlan_dev_vlan_id(const struct net_device *dev); | 135 | extern u16 vlan_dev_vlan_id(const struct net_device *dev); |
119 | 136 | ||
120 | extern int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp, | 137 | extern int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp, |
121 | u16 vlan_tci, int polling); | 138 | u16 vlan_tci, int polling); |
122 | extern int vlan_hwaccel_do_receive(struct sk_buff *skb); | 139 | extern bool vlan_do_receive(struct sk_buff **skb); |
140 | extern struct sk_buff *vlan_untag(struct sk_buff *skb); | ||
123 | extern gro_result_t | 141 | extern gro_result_t |
124 | vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp, | 142 | vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp, |
125 | unsigned int vlan_tci, struct sk_buff *skb); | 143 | unsigned int vlan_tci, struct sk_buff *skb); |
@@ -128,6 +146,12 @@ vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp, | |||
128 | unsigned int vlan_tci); | 146 | unsigned int vlan_tci); |
129 | 147 | ||
130 | #else | 148 | #else |
149 | static inline struct net_device *vlan_find_dev(struct net_device *real_dev, | ||
150 | u16 vlan_id) | ||
151 | { | ||
152 | return NULL; | ||
153 | } | ||
154 | |||
131 | static inline struct net_device *vlan_dev_real_dev(const struct net_device *dev) | 155 | static inline struct net_device *vlan_dev_real_dev(const struct net_device *dev) |
132 | { | 156 | { |
133 | BUG(); | 157 | BUG(); |
@@ -147,9 +171,16 @@ static inline int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp, | |||
147 | return NET_XMIT_SUCCESS; | 171 | return NET_XMIT_SUCCESS; |
148 | } | 172 | } |
149 | 173 | ||
150 | static inline int vlan_hwaccel_do_receive(struct sk_buff *skb) | 174 | static inline bool vlan_do_receive(struct sk_buff **skb) |
151 | { | 175 | { |
152 | return 0; | 176 | if ((*skb)->vlan_tci & VLAN_VID_MASK) |
177 | (*skb)->pkt_type = PACKET_OTHERHOST; | ||
178 | return false; | ||
179 | } | ||
180 | |||
181 | static inline struct sk_buff *vlan_untag(struct sk_buff *skb) | ||
182 | { | ||
183 | return skb; | ||
153 | } | 184 | } |
154 | 185 | ||
155 | static inline gro_result_t | 186 | static inline gro_result_t |
@@ -194,7 +225,7 @@ static inline int vlan_hwaccel_receive_skb(struct sk_buff *skb, | |||
194 | } | 225 | } |
195 | 226 | ||
196 | /** | 227 | /** |
197 | * __vlan_put_tag - regular VLAN tag inserting | 228 | * vlan_insert_tag - regular VLAN tag inserting |
198 | * @skb: skbuff to tag | 229 | * @skb: skbuff to tag |
199 | * @vlan_tci: VLAN TCI to insert | 230 | * @vlan_tci: VLAN TCI to insert |
200 | * | 231 | * |
@@ -203,8 +234,10 @@ static inline int vlan_hwaccel_receive_skb(struct sk_buff *skb, | |||
203 | * | 234 | * |
204 | * Following the skb_unshare() example, in case of error, the calling function | 235 | * Following the skb_unshare() example, in case of error, the calling function |
205 | * doesn't have to worry about freeing the original skb. | 236 | * doesn't have to worry about freeing the original skb. |
237 | * | ||
238 | * Does not change skb->protocol so this function can be used during receive. | ||
206 | */ | 239 | */ |
207 | static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb, u16 vlan_tci) | 240 | static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb, u16 vlan_tci) |
208 | { | 241 | { |
209 | struct vlan_ethhdr *veth; | 242 | struct vlan_ethhdr *veth; |
210 | 243 | ||
@@ -224,8 +257,25 @@ static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb, u16 vlan_tci) | |||
224 | /* now, the TCI */ | 257 | /* now, the TCI */ |
225 | veth->h_vlan_TCI = htons(vlan_tci); | 258 | veth->h_vlan_TCI = htons(vlan_tci); |
226 | 259 | ||
227 | skb->protocol = htons(ETH_P_8021Q); | 260 | return skb; |
261 | } | ||
228 | 262 | ||
263 | /** | ||
264 | * __vlan_put_tag - regular VLAN tag inserting | ||
265 | * @skb: skbuff to tag | ||
266 | * @vlan_tci: VLAN TCI to insert | ||
267 | * | ||
268 | * Inserts the VLAN tag into @skb as part of the payload | ||
269 | * Returns a VLAN tagged skb. If a new skb is created, @skb is freed. | ||
270 | * | ||
271 | * Following the skb_unshare() example, in case of error, the calling function | ||
272 | * doesn't have to worry about freeing the original skb. | ||
273 | */ | ||
274 | static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb, u16 vlan_tci) | ||
275 | { | ||
276 | skb = vlan_insert_tag(skb, vlan_tci); | ||
277 | if (skb) | ||
278 | skb->protocol = htons(ETH_P_8021Q); | ||
229 | return skb; | 279 | return skb; |
230 | } | 280 | } |
231 | 281 | ||
@@ -318,6 +368,31 @@ static inline int vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci) | |||
318 | } | 368 | } |
319 | } | 369 | } |
320 | 370 | ||
371 | /** | ||
372 | * vlan_get_protocol - get protocol EtherType. | ||
373 | * @skb: skbuff to query | ||
374 | * | ||
375 | * Returns the EtherType of the packet, regardless of whether it is | ||
376 | * vlan encapsulated (normal or hardware accelerated) or not. | ||
377 | */ | ||
378 | static inline __be16 vlan_get_protocol(const struct sk_buff *skb) | ||
379 | { | ||
380 | __be16 protocol = 0; | ||
381 | |||
382 | if (vlan_tx_tag_present(skb) || | ||
383 | skb->protocol != cpu_to_be16(ETH_P_8021Q)) | ||
384 | protocol = skb->protocol; | ||
385 | else { | ||
386 | __be16 proto, *protop; | ||
387 | protop = skb_header_pointer(skb, offsetof(struct vlan_ethhdr, | ||
388 | h_vlan_encapsulated_proto), | ||
389 | sizeof(proto), &proto); | ||
390 | if (likely(protop)) | ||
391 | protocol = *protop; | ||
392 | } | ||
393 | |||
394 | return protocol; | ||
395 | } | ||
321 | #endif /* __KERNEL__ */ | 396 | #endif /* __KERNEL__ */ |
322 | 397 | ||
323 | /* VLAN IOCTLs are found in sockios.h */ | 398 | /* VLAN IOCTLs are found in sockios.h */ |