Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vlan: Don't store VLAN tag in cb

Use a real skb member to store the skb to avoid clashes with qdiscs,
which are allowed to use the cb area themselves. As currently only real
devices that consume the skb set the NETIF_F_HW_VLAN_TX flag, no explicit
invalidation is neccessary.

The new member fills a hole on 64 bit, the skb layout changes from:

__u32 mark; /* 172 4 */
sk_buff_data_t transport_header; /* 176 4 */
sk_buff_data_t network_header; /* 180 4 */
sk_buff_data_t mac_header; /* 184 4 */
sk_buff_data_t tail; /* 188 4 */
/* --- cacheline 3 boundary (192 bytes) --- */
sk_buff_data_t end; /* 192 4 */

/* XXX 4 bytes hole, try to pack */

to

__u32 mark; /* 172 4 */
__u16 vlan_tci; /* 176 2 */

/* XXX 2 bytes hole, try to pack */

sk_buff_data_t transport_header; /* 180 4 */
sk_buff_data_t network_header; /* 184 4 */

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Patrick McHardy and committed by
David S. Miller
6aa895b0 968edbe1

+13 -24
+7 -24
include/linux/if_vlan.h
··· 105 105 array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev; 106 106 } 107 107 108 - /* VLAN tx hw acceleration helpers. */ 109 - struct vlan_skb_tx_cookie { 110 - u32 magic; 111 - u32 vlan_tag; 112 - }; 113 - 114 - #define VLAN_TX_COOKIE_MAGIC 0x564c414e /* "VLAN" in ascii. */ 115 - #define VLAN_TX_SKB_CB(__skb) ((struct vlan_skb_tx_cookie *)&((__skb)->cb[0])) 116 - #define vlan_tx_tag_present(__skb) \ 117 - (VLAN_TX_SKB_CB(__skb)->magic == VLAN_TX_COOKIE_MAGIC) 118 - #define vlan_tx_tag_get(__skb) (VLAN_TX_SKB_CB(__skb)->vlan_tag) 108 + #define vlan_tx_tag_present(__skb) ((__skb)->vlan_tci) 109 + #define vlan_tx_tag_get(__skb) ((__skb)->vlan_tci) 119 110 120 111 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) 121 112 extern struct net_device *vlan_dev_real_dev(const struct net_device *dev); ··· 201 210 * @skb: skbuff to tag 202 211 * @vlan_tci: VLAN TCI to insert 203 212 * 204 - * Puts the VLAN TCI in @skb->cb[] and lets the device do the rest 213 + * Puts the VLAN TCI in @skb->vlan_tci and lets the device do the rest 205 214 */ 206 215 static inline struct sk_buff *__vlan_hwaccel_put_tag(struct sk_buff *skb, 207 216 u16 vlan_tci) 208 217 { 209 - struct vlan_skb_tx_cookie *cookie; 210 - 211 - cookie = VLAN_TX_SKB_CB(skb); 212 - cookie->magic = VLAN_TX_COOKIE_MAGIC; 213 - cookie->vlan_tag = vlan_tci; 214 - 218 + skb->vlan_tci = vlan_tci; 215 219 return skb; 216 220 } 217 221 ··· 253 267 * @skb: skbuff to query 254 268 * @vlan_tci: buffer to store vlaue 255 269 * 256 - * Returns error if @skb->cb[] is not set correctly 270 + * Returns error if @skb->vlan_tci is not set correctly 257 271 */ 258 272 static inline int __vlan_hwaccel_get_tag(const struct sk_buff *skb, 259 273 u16 *vlan_tci) 260 274 { 261 - struct vlan_skb_tx_cookie *cookie; 262 - 263 - cookie = VLAN_TX_SKB_CB(skb); 264 - if (cookie->magic == VLAN_TX_COOKIE_MAGIC) { 265 - *vlan_tci = cookie->vlan_tag; 275 + if (vlan_tx_tag_present(skb)) { 276 + *vlan_tci = skb->vlan_tci; 266 277 return 0; 267 278 } else { 268 279 *vlan_tci = 0;
+3
include/linux/skbuff.h
··· 246 246 * @dma_cookie: a cookie to one of several possible DMA operations 247 247 * done by skb DMA functions 248 248 * @secmark: security marking 249 + * @vlan_tci: vlan tag control information 249 250 */ 250 251 251 252 struct sk_buff { ··· 326 325 #endif 327 326 328 327 __u32 mark; 328 + 329 + __u16 vlan_tci; 329 330 330 331 sk_buff_data_t transport_header; 331 332 sk_buff_data_t network_header;
+3
net/core/skbuff.c
··· 459 459 new->tc_verd = old->tc_verd; 460 460 #endif 461 461 #endif 462 + new->vlan_tci = old->vlan_tci; 463 + 462 464 skb_copy_secmark(new, old); 463 465 } 464 466 ··· 2288 2286 skb_copy_queue_mapping(nskb, skb); 2289 2287 nskb->priority = skb->priority; 2290 2288 nskb->protocol = skb->protocol; 2289 + nskb->vlan_tci = skb->vlan_tci; 2291 2290 nskb->dst = dst_clone(skb->dst); 2292 2291 memcpy(nskb->cb, skb->cb, sizeof(skb->cb)); 2293 2292 nskb->pkt_type = skb->pkt_type;