diff options
Diffstat (limited to 'net/8021q/vlan_dev.c')
-rw-r--r-- | net/8021q/vlan_dev.c | 298 |
1 files changed, 133 insertions, 165 deletions
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 5d055c242ed8..f42bc2b26b85 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c | |||
@@ -21,21 +21,15 @@ | |||
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/mm.h> | ||
25 | #include <linux/in.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <asm/uaccess.h> /* for copy_from_user */ | ||
28 | #include <linux/skbuff.h> | 24 | #include <linux/skbuff.h> |
29 | #include <linux/netdevice.h> | 25 | #include <linux/netdevice.h> |
30 | #include <linux/etherdevice.h> | 26 | #include <linux/etherdevice.h> |
31 | #include <net/datalink.h> | 27 | #include <linux/ethtool.h> |
32 | #include <net/p8022.h> | ||
33 | #include <net/arp.h> | 28 | #include <net/arp.h> |
34 | 29 | ||
35 | #include "vlan.h" | 30 | #include "vlan.h" |
36 | #include "vlanproc.h" | 31 | #include "vlanproc.h" |
37 | #include <linux/if_vlan.h> | 32 | #include <linux/if_vlan.h> |
38 | #include <net/ip.h> | ||
39 | 33 | ||
40 | /* | 34 | /* |
41 | * Rebuild the Ethernet MAC header. This is called after an ARP | 35 | * Rebuild the Ethernet MAC header. This is called after an ARP |
@@ -73,11 +67,8 @@ static int vlan_dev_rebuild_header(struct sk_buff *skb) | |||
73 | static inline struct sk_buff *vlan_check_reorder_header(struct sk_buff *skb) | 67 | static inline struct sk_buff *vlan_check_reorder_header(struct sk_buff *skb) |
74 | { | 68 | { |
75 | if (vlan_dev_info(skb->dev)->flags & VLAN_FLAG_REORDER_HDR) { | 69 | if (vlan_dev_info(skb->dev)->flags & VLAN_FLAG_REORDER_HDR) { |
76 | if (skb_shared(skb) || skb_cloned(skb)) { | 70 | if (skb_cow(skb, skb_headroom(skb)) < 0) |
77 | struct sk_buff *nskb = skb_copy(skb, GFP_ATOMIC); | 71 | skb = NULL; |
78 | kfree_skb(skb); | ||
79 | skb = nskb; | ||
80 | } | ||
81 | if (skb) { | 72 | if (skb) { |
82 | /* Lifted from Gleb's VLAN code... */ | 73 | /* Lifted from Gleb's VLAN code... */ |
83 | memmove(skb->data - ETH_HLEN, | 74 | memmove(skb->data - ETH_HLEN, |
@@ -149,9 +140,9 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev, | |||
149 | struct packet_type *ptype, struct net_device *orig_dev) | 140 | struct packet_type *ptype, struct net_device *orig_dev) |
150 | { | 141 | { |
151 | struct vlan_hdr *vhdr; | 142 | struct vlan_hdr *vhdr; |
152 | unsigned short vid; | ||
153 | struct net_device_stats *stats; | 143 | struct net_device_stats *stats; |
154 | unsigned short vlan_TCI; | 144 | u16 vlan_id; |
145 | u16 vlan_tci; | ||
155 | 146 | ||
156 | skb = skb_share_check(skb, GFP_ATOMIC); | 147 | skb = skb_share_check(skb, GFP_ATOMIC); |
157 | if (skb == NULL) | 148 | if (skb == NULL) |
@@ -161,14 +152,14 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev, | |||
161 | goto err_free; | 152 | goto err_free; |
162 | 153 | ||
163 | vhdr = (struct vlan_hdr *)skb->data; | 154 | vhdr = (struct vlan_hdr *)skb->data; |
164 | vlan_TCI = ntohs(vhdr->h_vlan_TCI); | 155 | vlan_tci = ntohs(vhdr->h_vlan_TCI); |
165 | vid = (vlan_TCI & VLAN_VID_MASK); | 156 | vlan_id = vlan_tci & VLAN_VID_MASK; |
166 | 157 | ||
167 | rcu_read_lock(); | 158 | rcu_read_lock(); |
168 | skb->dev = __find_vlan_dev(dev, vid); | 159 | skb->dev = __find_vlan_dev(dev, vlan_id); |
169 | if (!skb->dev) { | 160 | if (!skb->dev) { |
170 | pr_debug("%s: ERROR: No net_device for VID: %u on dev: %s\n", | 161 | pr_debug("%s: ERROR: No net_device for VID: %u on dev: %s\n", |
171 | __func__, (unsigned int)vid, dev->name); | 162 | __func__, vlan_id, dev->name); |
172 | goto err_unlock; | 163 | goto err_unlock; |
173 | } | 164 | } |
174 | 165 | ||
@@ -180,11 +171,10 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev, | |||
180 | 171 | ||
181 | skb_pull_rcsum(skb, VLAN_HLEN); | 172 | skb_pull_rcsum(skb, VLAN_HLEN); |
182 | 173 | ||
183 | skb->priority = vlan_get_ingress_priority(skb->dev, | 174 | skb->priority = vlan_get_ingress_priority(skb->dev, vlan_tci); |
184 | ntohs(vhdr->h_vlan_TCI)); | ||
185 | 175 | ||
186 | pr_debug("%s: priority: %u for TCI: %hu\n", | 176 | pr_debug("%s: priority: %u for TCI: %hu\n", |
187 | __func__, skb->priority, ntohs(vhdr->h_vlan_TCI)); | 177 | __func__, skb->priority, vlan_tci); |
188 | 178 | ||
189 | switch (skb->pkt_type) { | 179 | switch (skb->pkt_type) { |
190 | case PACKET_BROADCAST: /* Yeah, stats collect these together.. */ | 180 | case PACKET_BROADCAST: /* Yeah, stats collect these together.. */ |
@@ -227,7 +217,7 @@ err_free: | |||
227 | return NET_RX_DROP; | 217 | return NET_RX_DROP; |
228 | } | 218 | } |
229 | 219 | ||
230 | static inline unsigned short | 220 | static inline u16 |
231 | vlan_dev_get_egress_qos_mask(struct net_device *dev, struct sk_buff *skb) | 221 | vlan_dev_get_egress_qos_mask(struct net_device *dev, struct sk_buff *skb) |
232 | { | 222 | { |
233 | struct vlan_priority_tci_mapping *mp; | 223 | struct vlan_priority_tci_mapping *mp; |
@@ -259,103 +249,44 @@ static int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev, | |||
259 | unsigned int len) | 249 | unsigned int len) |
260 | { | 250 | { |
261 | struct vlan_hdr *vhdr; | 251 | struct vlan_hdr *vhdr; |
262 | unsigned short veth_TCI = 0; | 252 | unsigned int vhdrlen = 0; |
263 | int rc = 0; | 253 | u16 vlan_tci = 0; |
264 | int build_vlan_header = 0; | 254 | int rc; |
265 | struct net_device *vdev = dev; | ||
266 | |||
267 | pr_debug("%s: skb: %p type: %hx len: %u vlan_id: %hx, daddr: %p\n", | ||
268 | __func__, skb, type, len, vlan_dev_info(dev)->vlan_id, | ||
269 | daddr); | ||
270 | |||
271 | /* build vlan header only if re_order_header flag is NOT set. This | ||
272 | * fixes some programs that get confused when they see a VLAN device | ||
273 | * sending a frame that is VLAN encoded (the consensus is that the VLAN | ||
274 | * device should look completely like an Ethernet device when the | ||
275 | * REORDER_HEADER flag is set) The drawback to this is some extra | ||
276 | * header shuffling in the hard_start_xmit. Users can turn off this | ||
277 | * REORDER behaviour with the vconfig tool. | ||
278 | */ | ||
279 | if (!(vlan_dev_info(dev)->flags & VLAN_FLAG_REORDER_HDR)) | ||
280 | build_vlan_header = 1; | ||
281 | 255 | ||
282 | if (build_vlan_header) { | 256 | if (WARN_ON(skb_headroom(skb) < dev->hard_header_len)) |
283 | vhdr = (struct vlan_hdr *) skb_push(skb, VLAN_HLEN); | 257 | return -ENOSPC; |
284 | 258 | ||
285 | /* build the four bytes that make this a VLAN header. */ | 259 | if (!(vlan_dev_info(dev)->flags & VLAN_FLAG_REORDER_HDR)) { |
286 | 260 | vhdr = (struct vlan_hdr *) skb_push(skb, VLAN_HLEN); | |
287 | /* Now, construct the second two bytes. This field looks | ||
288 | * something like: | ||
289 | * usr_priority: 3 bits (high bits) | ||
290 | * CFI 1 bit | ||
291 | * VLAN ID 12 bits (low bits) | ||
292 | * | ||
293 | */ | ||
294 | veth_TCI = vlan_dev_info(dev)->vlan_id; | ||
295 | veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb); | ||
296 | 261 | ||
297 | vhdr->h_vlan_TCI = htons(veth_TCI); | 262 | vlan_tci = vlan_dev_info(dev)->vlan_id; |
263 | vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb); | ||
264 | vhdr->h_vlan_TCI = htons(vlan_tci); | ||
298 | 265 | ||
299 | /* | 266 | /* |
300 | * Set the protocol type. For a packet of type ETH_P_802_3 we | 267 | * Set the protocol type. For a packet of type ETH_P_802_3 we |
301 | * put the length in here instead. It is up to the 802.2 | 268 | * put the length in here instead. It is up to the 802.2 |
302 | * layer to carry protocol information. | 269 | * layer to carry protocol information. |
303 | */ | 270 | */ |
304 | |||
305 | if (type != ETH_P_802_3) | 271 | if (type != ETH_P_802_3) |
306 | vhdr->h_vlan_encapsulated_proto = htons(type); | 272 | vhdr->h_vlan_encapsulated_proto = htons(type); |
307 | else | 273 | else |
308 | vhdr->h_vlan_encapsulated_proto = htons(len); | 274 | vhdr->h_vlan_encapsulated_proto = htons(len); |
309 | 275 | ||
310 | skb->protocol = htons(ETH_P_8021Q); | 276 | skb->protocol = htons(ETH_P_8021Q); |
311 | skb_reset_network_header(skb); | 277 | type = ETH_P_8021Q; |
278 | vhdrlen = VLAN_HLEN; | ||
312 | } | 279 | } |
313 | 280 | ||
314 | /* Before delegating work to the lower layer, enter our MAC-address */ | 281 | /* Before delegating work to the lower layer, enter our MAC-address */ |
315 | if (saddr == NULL) | 282 | if (saddr == NULL) |
316 | saddr = dev->dev_addr; | 283 | saddr = dev->dev_addr; |
317 | 284 | ||
285 | /* Now make the underlying real hard header */ | ||
318 | dev = vlan_dev_info(dev)->real_dev; | 286 | dev = vlan_dev_info(dev)->real_dev; |
319 | 287 | rc = dev_hard_header(skb, dev, type, daddr, saddr, len + vhdrlen); | |
320 | /* MPLS can send us skbuffs w/out enough space. This check will grow | 288 | if (rc > 0) |
321 | * the skb if it doesn't have enough headroom. Not a beautiful solution, | 289 | rc += vhdrlen; |
322 | * so I'll tick a counter so that users can know it's happening... | ||
323 | * If they care... | ||
324 | */ | ||
325 | |||
326 | /* NOTE: This may still break if the underlying device is not the final | ||
327 | * device (and thus there are more headers to add...) It should work for | ||
328 | * good-ole-ethernet though. | ||
329 | */ | ||
330 | if (skb_headroom(skb) < dev->hard_header_len) { | ||
331 | struct sk_buff *sk_tmp = skb; | ||
332 | skb = skb_realloc_headroom(sk_tmp, dev->hard_header_len); | ||
333 | kfree_skb(sk_tmp); | ||
334 | if (skb == NULL) { | ||
335 | struct net_device_stats *stats = &vdev->stats; | ||
336 | stats->tx_dropped++; | ||
337 | return -ENOMEM; | ||
338 | } | ||
339 | vlan_dev_info(vdev)->cnt_inc_headroom_on_tx++; | ||
340 | pr_debug("%s: %s: had to grow skb\n", __func__, vdev->name); | ||
341 | } | ||
342 | |||
343 | if (build_vlan_header) { | ||
344 | /* Now make the underlying real hard header */ | ||
345 | rc = dev_hard_header(skb, dev, ETH_P_8021Q, daddr, saddr, | ||
346 | len + VLAN_HLEN); | ||
347 | if (rc > 0) | ||
348 | rc += VLAN_HLEN; | ||
349 | else if (rc < 0) | ||
350 | rc -= VLAN_HLEN; | ||
351 | } else | ||
352 | /* If here, then we'll just make a normal looking ethernet | ||
353 | * frame, but, the hard_start_xmit method will insert the tag | ||
354 | * (it has to be able to do this for bridged and other skbs | ||
355 | * that don't come down the protocol stack in an orderly manner. | ||
356 | */ | ||
357 | rc = dev_hard_header(skb, dev, type, daddr, saddr, len); | ||
358 | |||
359 | return rc; | 290 | return rc; |
360 | } | 291 | } |
361 | 292 | ||
@@ -369,78 +300,49 @@ static int vlan_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
369 | * NOTE: THIS ASSUMES DIX ETHERNET, SPECIFICALLY NOT SUPPORTING | 300 | * NOTE: THIS ASSUMES DIX ETHERNET, SPECIFICALLY NOT SUPPORTING |
370 | * OTHER THINGS LIKE FDDI/TokenRing/802.3 SNAPs... | 301 | * OTHER THINGS LIKE FDDI/TokenRing/802.3 SNAPs... |
371 | */ | 302 | */ |
372 | |||
373 | if (veth->h_vlan_proto != htons(ETH_P_8021Q) || | 303 | if (veth->h_vlan_proto != htons(ETH_P_8021Q) || |
374 | vlan_dev_info(dev)->flags & VLAN_FLAG_REORDER_HDR) { | 304 | vlan_dev_info(dev)->flags & VLAN_FLAG_REORDER_HDR) { |
375 | int orig_headroom = skb_headroom(skb); | 305 | unsigned int orig_headroom = skb_headroom(skb); |
376 | unsigned short veth_TCI; | 306 | u16 vlan_tci; |
377 | 307 | ||
378 | /* This is not a VLAN frame...but we can fix that! */ | ||
379 | vlan_dev_info(dev)->cnt_encap_on_xmit++; | 308 | vlan_dev_info(dev)->cnt_encap_on_xmit++; |
380 | 309 | ||
381 | pr_debug("%s: proto to encap: 0x%hx\n", | 310 | vlan_tci = vlan_dev_info(dev)->vlan_id; |
382 | __func__, ntohs(veth->h_vlan_proto)); | 311 | vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb); |
383 | /* Construct the second two bytes. This field looks something | 312 | skb = __vlan_put_tag(skb, vlan_tci); |
384 | * like: | ||
385 | * usr_priority: 3 bits (high bits) | ||
386 | * CFI 1 bit | ||
387 | * VLAN ID 12 bits (low bits) | ||
388 | */ | ||
389 | veth_TCI = vlan_dev_info(dev)->vlan_id; | ||
390 | veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb); | ||
391 | |||
392 | skb = __vlan_put_tag(skb, veth_TCI); | ||
393 | if (!skb) { | 313 | if (!skb) { |
394 | stats->tx_dropped++; | 314 | stats->tx_dropped++; |
395 | return 0; | 315 | return NETDEV_TX_OK; |
396 | } | 316 | } |
397 | 317 | ||
398 | if (orig_headroom < VLAN_HLEN) | 318 | if (orig_headroom < VLAN_HLEN) |
399 | vlan_dev_info(dev)->cnt_inc_headroom_on_tx++; | 319 | vlan_dev_info(dev)->cnt_inc_headroom_on_tx++; |
400 | } | 320 | } |
401 | 321 | ||
402 | pr_debug("%s: about to send skb: %p to dev: %s\n", | 322 | stats->tx_packets++; |
403 | __func__, skb, skb->dev->name); | ||
404 | pr_debug(" " MAC_FMT " " MAC_FMT " %4hx %4hx %4hx\n", | ||
405 | veth->h_dest[0], veth->h_dest[1], veth->h_dest[2], | ||
406 | veth->h_dest[3], veth->h_dest[4], veth->h_dest[5], | ||
407 | veth->h_source[0], veth->h_source[1], veth->h_source[2], | ||
408 | veth->h_source[3], veth->h_source[4], veth->h_source[5], | ||
409 | veth->h_vlan_proto, veth->h_vlan_TCI, | ||
410 | veth->h_vlan_encapsulated_proto); | ||
411 | |||
412 | stats->tx_packets++; /* for statics only */ | ||
413 | stats->tx_bytes += skb->len; | 323 | stats->tx_bytes += skb->len; |
414 | 324 | ||
415 | skb->dev = vlan_dev_info(dev)->real_dev; | 325 | skb->dev = vlan_dev_info(dev)->real_dev; |
416 | dev_queue_xmit(skb); | 326 | dev_queue_xmit(skb); |
417 | 327 | return NETDEV_TX_OK; | |
418 | return 0; | ||
419 | } | 328 | } |
420 | 329 | ||
421 | static int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, | 330 | static int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, |
422 | struct net_device *dev) | 331 | struct net_device *dev) |
423 | { | 332 | { |
424 | struct net_device_stats *stats = &dev->stats; | 333 | struct net_device_stats *stats = &dev->stats; |
425 | unsigned short veth_TCI; | 334 | u16 vlan_tci; |
426 | 335 | ||
427 | /* Construct the second two bytes. This field looks something | 336 | vlan_tci = vlan_dev_info(dev)->vlan_id; |
428 | * like: | 337 | vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb); |
429 | * usr_priority: 3 bits (high bits) | 338 | skb = __vlan_hwaccel_put_tag(skb, vlan_tci); |
430 | * CFI 1 bit | ||
431 | * VLAN ID 12 bits (low bits) | ||
432 | */ | ||
433 | veth_TCI = vlan_dev_info(dev)->vlan_id; | ||
434 | veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb); | ||
435 | skb = __vlan_hwaccel_put_tag(skb, veth_TCI); | ||
436 | 339 | ||
437 | stats->tx_packets++; | 340 | stats->tx_packets++; |
438 | stats->tx_bytes += skb->len; | 341 | stats->tx_bytes += skb->len; |
439 | 342 | ||
440 | skb->dev = vlan_dev_info(dev)->real_dev; | 343 | skb->dev = vlan_dev_info(dev)->real_dev; |
441 | dev_queue_xmit(skb); | 344 | dev_queue_xmit(skb); |
442 | 345 | return NETDEV_TX_OK; | |
443 | return 0; | ||
444 | } | 346 | } |
445 | 347 | ||
446 | static int vlan_dev_change_mtu(struct net_device *dev, int new_mtu) | 348 | static int vlan_dev_change_mtu(struct net_device *dev, int new_mtu) |
@@ -457,7 +359,7 @@ static int vlan_dev_change_mtu(struct net_device *dev, int new_mtu) | |||
457 | } | 359 | } |
458 | 360 | ||
459 | void vlan_dev_set_ingress_priority(const struct net_device *dev, | 361 | void vlan_dev_set_ingress_priority(const struct net_device *dev, |
460 | u32 skb_prio, short vlan_prio) | 362 | u32 skb_prio, u16 vlan_prio) |
461 | { | 363 | { |
462 | struct vlan_dev_info *vlan = vlan_dev_info(dev); | 364 | struct vlan_dev_info *vlan = vlan_dev_info(dev); |
463 | 365 | ||
@@ -470,7 +372,7 @@ void vlan_dev_set_ingress_priority(const struct net_device *dev, | |||
470 | } | 372 | } |
471 | 373 | ||
472 | int vlan_dev_set_egress_priority(const struct net_device *dev, | 374 | int vlan_dev_set_egress_priority(const struct net_device *dev, |
473 | u32 skb_prio, short vlan_prio) | 375 | u32 skb_prio, u16 vlan_prio) |
474 | { | 376 | { |
475 | struct vlan_dev_info *vlan = vlan_dev_info(dev); | 377 | struct vlan_dev_info *vlan = vlan_dev_info(dev); |
476 | struct vlan_priority_tci_mapping *mp = NULL; | 378 | struct vlan_priority_tci_mapping *mp = NULL; |
@@ -507,18 +409,23 @@ int vlan_dev_set_egress_priority(const struct net_device *dev, | |||
507 | } | 409 | } |
508 | 410 | ||
509 | /* Flags are defined in the vlan_flags enum in include/linux/if_vlan.h file. */ | 411 | /* Flags are defined in the vlan_flags enum in include/linux/if_vlan.h file. */ |
510 | int vlan_dev_set_vlan_flag(const struct net_device *dev, | 412 | int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask) |
511 | u32 flag, short flag_val) | ||
512 | { | 413 | { |
513 | /* verify flag is supported */ | 414 | struct vlan_dev_info *vlan = vlan_dev_info(dev); |
514 | if (flag == VLAN_FLAG_REORDER_HDR) { | 415 | u32 old_flags = vlan->flags; |
515 | if (flag_val) | 416 | |
516 | vlan_dev_info(dev)->flags |= VLAN_FLAG_REORDER_HDR; | 417 | if (mask & ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP)) |
418 | return -EINVAL; | ||
419 | |||
420 | vlan->flags = (old_flags & ~mask) | (flags & mask); | ||
421 | |||
422 | if (netif_running(dev) && (vlan->flags ^ old_flags) & VLAN_FLAG_GVRP) { | ||
423 | if (vlan->flags & VLAN_FLAG_GVRP) | ||
424 | vlan_gvrp_request_join(dev); | ||
517 | else | 425 | else |
518 | vlan_dev_info(dev)->flags &= ~VLAN_FLAG_REORDER_HDR; | 426 | vlan_gvrp_request_leave(dev); |
519 | return 0; | ||
520 | } | 427 | } |
521 | return -EINVAL; | 428 | return 0; |
522 | } | 429 | } |
523 | 430 | ||
524 | void vlan_dev_get_realdev_name(const struct net_device *dev, char *result) | 431 | void vlan_dev_get_realdev_name(const struct net_device *dev, char *result) |
@@ -526,11 +433,6 @@ void vlan_dev_get_realdev_name(const struct net_device *dev, char *result) | |||
526 | strncpy(result, vlan_dev_info(dev)->real_dev->name, 23); | 433 | strncpy(result, vlan_dev_info(dev)->real_dev->name, 23); |
527 | } | 434 | } |
528 | 435 | ||
529 | void vlan_dev_get_vid(const struct net_device *dev, unsigned short *result) | ||
530 | { | ||
531 | *result = vlan_dev_info(dev)->vlan_id; | ||
532 | } | ||
533 | |||
534 | static int vlan_dev_open(struct net_device *dev) | 436 | static int vlan_dev_open(struct net_device *dev) |
535 | { | 437 | { |
536 | struct vlan_dev_info *vlan = vlan_dev_info(dev); | 438 | struct vlan_dev_info *vlan = vlan_dev_info(dev); |
@@ -543,21 +445,44 @@ static int vlan_dev_open(struct net_device *dev) | |||
543 | if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) { | 445 | if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) { |
544 | err = dev_unicast_add(real_dev, dev->dev_addr, ETH_ALEN); | 446 | err = dev_unicast_add(real_dev, dev->dev_addr, ETH_ALEN); |
545 | if (err < 0) | 447 | if (err < 0) |
546 | return err; | 448 | goto out; |
449 | } | ||
450 | |||
451 | if (dev->flags & IFF_ALLMULTI) { | ||
452 | err = dev_set_allmulti(real_dev, 1); | ||
453 | if (err < 0) | ||
454 | goto del_unicast; | ||
547 | } | 455 | } |
456 | if (dev->flags & IFF_PROMISC) { | ||
457 | err = dev_set_promiscuity(real_dev, 1); | ||
458 | if (err < 0) | ||
459 | goto clear_allmulti; | ||
460 | } | ||
461 | |||
548 | memcpy(vlan->real_dev_addr, real_dev->dev_addr, ETH_ALEN); | 462 | memcpy(vlan->real_dev_addr, real_dev->dev_addr, ETH_ALEN); |
549 | 463 | ||
550 | if (dev->flags & IFF_ALLMULTI) | 464 | if (vlan->flags & VLAN_FLAG_GVRP) |
551 | dev_set_allmulti(real_dev, 1); | 465 | vlan_gvrp_request_join(dev); |
552 | if (dev->flags & IFF_PROMISC) | ||
553 | dev_set_promiscuity(real_dev, 1); | ||
554 | 466 | ||
555 | return 0; | 467 | return 0; |
468 | |||
469 | clear_allmulti: | ||
470 | if (dev->flags & IFF_ALLMULTI) | ||
471 | dev_set_allmulti(real_dev, -1); | ||
472 | del_unicast: | ||
473 | if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) | ||
474 | dev_unicast_delete(real_dev, dev->dev_addr, ETH_ALEN); | ||
475 | out: | ||
476 | return err; | ||
556 | } | 477 | } |
557 | 478 | ||
558 | static int vlan_dev_stop(struct net_device *dev) | 479 | static int vlan_dev_stop(struct net_device *dev) |
559 | { | 480 | { |
560 | struct net_device *real_dev = vlan_dev_info(dev)->real_dev; | 481 | struct vlan_dev_info *vlan = vlan_dev_info(dev); |
482 | struct net_device *real_dev = vlan->real_dev; | ||
483 | |||
484 | if (vlan->flags & VLAN_FLAG_GVRP) | ||
485 | vlan_gvrp_request_leave(dev); | ||
561 | 486 | ||
562 | dev_mc_unsync(real_dev, dev); | 487 | dev_mc_unsync(real_dev, dev); |
563 | dev_unicast_unsync(real_dev, dev); | 488 | dev_unicast_unsync(real_dev, dev); |
@@ -645,6 +570,20 @@ static void vlan_dev_set_rx_mode(struct net_device *vlan_dev) | |||
645 | */ | 570 | */ |
646 | static struct lock_class_key vlan_netdev_xmit_lock_key; | 571 | static struct lock_class_key vlan_netdev_xmit_lock_key; |
647 | 572 | ||
573 | static void vlan_dev_set_lockdep_one(struct net_device *dev, | ||
574 | struct netdev_queue *txq, | ||
575 | void *_subclass) | ||
576 | { | ||
577 | lockdep_set_class_and_subclass(&txq->_xmit_lock, | ||
578 | &vlan_netdev_xmit_lock_key, | ||
579 | *(int *)_subclass); | ||
580 | } | ||
581 | |||
582 | static void vlan_dev_set_lockdep_class(struct net_device *dev, int subclass) | ||
583 | { | ||
584 | netdev_for_each_tx_queue(dev, vlan_dev_set_lockdep_one, &subclass); | ||
585 | } | ||
586 | |||
648 | static const struct header_ops vlan_header_ops = { | 587 | static const struct header_ops vlan_header_ops = { |
649 | .create = vlan_dev_hard_header, | 588 | .create = vlan_dev_hard_header, |
650 | .rebuild = vlan_dev_rebuild_header, | 589 | .rebuild = vlan_dev_rebuild_header, |
@@ -683,11 +622,10 @@ static int vlan_dev_init(struct net_device *dev) | |||
683 | dev->hard_start_xmit = vlan_dev_hard_start_xmit; | 622 | dev->hard_start_xmit = vlan_dev_hard_start_xmit; |
684 | } | 623 | } |
685 | 624 | ||
686 | if (real_dev->priv_flags & IFF_802_1Q_VLAN) | 625 | if (is_vlan_dev(real_dev)) |
687 | subclass = 1; | 626 | subclass = 1; |
688 | 627 | ||
689 | lockdep_set_class_and_subclass(&dev->_xmit_lock, | 628 | vlan_dev_set_lockdep_class(dev, subclass); |
690 | &vlan_netdev_xmit_lock_key, subclass); | ||
691 | return 0; | 629 | return 0; |
692 | } | 630 | } |
693 | 631 | ||
@@ -705,6 +643,35 @@ static void vlan_dev_uninit(struct net_device *dev) | |||
705 | } | 643 | } |
706 | } | 644 | } |
707 | 645 | ||
646 | static u32 vlan_ethtool_get_rx_csum(struct net_device *dev) | ||
647 | { | ||
648 | const struct vlan_dev_info *vlan = vlan_dev_info(dev); | ||
649 | struct net_device *real_dev = vlan->real_dev; | ||
650 | |||
651 | if (real_dev->ethtool_ops == NULL || | ||
652 | real_dev->ethtool_ops->get_rx_csum == NULL) | ||
653 | return 0; | ||
654 | return real_dev->ethtool_ops->get_rx_csum(real_dev); | ||
655 | } | ||
656 | |||
657 | static u32 vlan_ethtool_get_flags(struct net_device *dev) | ||
658 | { | ||
659 | const struct vlan_dev_info *vlan = vlan_dev_info(dev); | ||
660 | struct net_device *real_dev = vlan->real_dev; | ||
661 | |||
662 | if (!(real_dev->features & NETIF_F_HW_VLAN_RX) || | ||
663 | real_dev->ethtool_ops == NULL || | ||
664 | real_dev->ethtool_ops->get_flags == NULL) | ||
665 | return 0; | ||
666 | return real_dev->ethtool_ops->get_flags(real_dev); | ||
667 | } | ||
668 | |||
669 | static const struct ethtool_ops vlan_ethtool_ops = { | ||
670 | .get_link = ethtool_op_get_link, | ||
671 | .get_rx_csum = vlan_ethtool_get_rx_csum, | ||
672 | .get_flags = vlan_ethtool_get_flags, | ||
673 | }; | ||
674 | |||
708 | void vlan_setup(struct net_device *dev) | 675 | void vlan_setup(struct net_device *dev) |
709 | { | 676 | { |
710 | ether_setup(dev); | 677 | ether_setup(dev); |
@@ -723,6 +690,7 @@ void vlan_setup(struct net_device *dev) | |||
723 | dev->change_rx_flags = vlan_dev_change_rx_flags; | 690 | dev->change_rx_flags = vlan_dev_change_rx_flags; |
724 | dev->do_ioctl = vlan_dev_ioctl; | 691 | dev->do_ioctl = vlan_dev_ioctl; |
725 | dev->destructor = free_netdev; | 692 | dev->destructor = free_netdev; |
693 | dev->ethtool_ops = &vlan_ethtool_ops; | ||
726 | 694 | ||
727 | memset(dev->broadcast, 0, ETH_ALEN); | 695 | memset(dev->broadcast, 0, ETH_ALEN); |
728 | } | 696 | } |