]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/8021q/vlan_dev.c
[VLAN/BRIDGE]: Fix "skb_pull_rcsum - Fatal exception in interrupt"
[mirror_ubuntu-artful-kernel.git] / net / 8021q / vlan_dev.c
CommitLineData
1da177e4
LT
1/* -*- linux-c -*-
2 * INET 802.1Q VLAN
3 * Ethernet-type device handling.
4 *
5 * Authors: Ben Greear <greearb@candelatech.com>
6 * Please send support related email to: vlan@scry.wanfear.com
7 * VLAN Home Page: http://www.candelatech.com/~greear/vlan.html
122952fc 8 *
1da177e4
LT
9 * Fixes: Mar 22 2001: Martin Bokaemper <mbokaemper@unispherenetworks.com>
10 * - reset skb->pkt_type on incoming packets when MAC was changed
11 * - see that changed MAC is saddr for outgoing packets
12 * Oct 20, 2001: Ard van Breeman:
13 * - Fix MC-list, finally.
14 * - Flush MC-list on VLAN destroy.
122952fc 15 *
1da177e4
LT
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
21 */
22
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>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <net/datalink.h>
32#include <net/p8022.h>
33#include <net/arp.h>
34
35#include "vlan.h"
36#include "vlanproc.h"
37#include <linux/if_vlan.h>
38#include <net/ip.h>
39
40/*
41 * Rebuild the Ethernet MAC header. This is called after an ARP
42 * (or in future other address resolution) has completed on this
43 * sk_buff. We now let ARP fill in the other fields.
44 *
45 * This routine CANNOT use cached dst->neigh!
46 * Really, it is used only when dst->neigh is wrong.
47 *
48 * TODO: This needs a checkup, I'm ignorant here. --BLG
49 */
50int vlan_dev_rebuild_header(struct sk_buff *skb)
51{
52 struct net_device *dev = skb->dev;
53 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)(skb->data);
54
55 switch (veth->h_vlan_encapsulated_proto) {
56#ifdef CONFIG_INET
57 case __constant_htons(ETH_P_IP):
58
59 /* TODO: Confirm this will work with VLAN headers... */
60 return arp_find(veth->h_dest, skb);
122952fc 61#endif
1da177e4
LT
62 default:
63 printk(VLAN_DBG
122952fc 64 "%s: unable to resolve type %X addresses.\n",
d136fe72 65 dev->name, ntohs(veth->h_vlan_encapsulated_proto));
122952fc 66
1da177e4
LT
67 memcpy(veth->h_source, dev->dev_addr, ETH_ALEN);
68 break;
3ff50b79 69 }
1da177e4
LT
70
71 return 0;
72}
73
74static inline struct sk_buff *vlan_check_reorder_header(struct sk_buff *skb)
75{
a4bf3af4 76 if (VLAN_DEV_INFO(skb->dev)->flags & VLAN_FLAG_REORDER_HDR) {
1da177e4
LT
77 if (skb_shared(skb) || skb_cloned(skb)) {
78 struct sk_buff *nskb = skb_copy(skb, GFP_ATOMIC);
79 kfree_skb(skb);
80 skb = nskb;
81 }
82 if (skb) {
83 /* Lifted from Gleb's VLAN code... */
84 memmove(skb->data - ETH_HLEN,
85 skb->data - VLAN_ETH_HLEN, 12);
b0e380b1 86 skb->mac_header += VLAN_HLEN;
1da177e4
LT
87 }
88 }
89
90 return skb;
91}
92
93/*
122952fc 94 * Determine the packet's protocol ID. The rule here is that we
1da177e4
LT
95 * assume 802.3 if the type field is short enough to be a length.
96 * This is normal practice and works for any 'now in use' protocol.
97 *
98 * Also, at this point we assume that we ARE dealing exclusively with
99 * VLAN packets, or packets that should be made into VLAN packets based
100 * on a default VLAN ID.
101 *
102 * NOTE: Should be similar to ethernet/eth.c.
103 *
104 * SANITY NOTE: This method is called when a packet is moving up the stack
105 * towards userland. To get here, it would have already passed
106 * through the ethernet/eth.c eth_type_trans() method.
107 * SANITY NOTE 2: We are referencing to the VLAN_HDR frields, which MAY be
108 * stored UNALIGNED in the memory. RISC systems don't like
109 * such cases very much...
110 * SANITY NOTE 2a: According to Dave Miller & Alexey, it will always be aligned,
111 * so there doesn't need to be any of the unaligned stuff. It has
112 * been commented out now... --Ben
113 *
114 */
115int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
122952fc 116 struct packet_type* ptype, struct net_device *orig_dev)
1da177e4
LT
117{
118 unsigned char *rawp = NULL;
e7c243c9 119 struct vlan_hdr *vhdr;
1da177e4
LT
120 unsigned short vid;
121 struct net_device_stats *stats;
122 unsigned short vlan_TCI;
3c3f8f25 123 __be16 proto;
1da177e4 124
e7c243c9
EP
125 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
126 return -1;
127
128 if (unlikely(!pskb_may_pull(skb, VLAN_HLEN))) {
129 kfree_skb(skb);
130 return -1;
131 }
132
133 vhdr = (struct vlan_hdr *)(skb->data);
134
1da177e4
LT
135 /* vlan_TCI = ntohs(get_unaligned(&vhdr->h_vlan_TCI)); */
136 vlan_TCI = ntohs(vhdr->h_vlan_TCI);
137
138 vid = (vlan_TCI & VLAN_VID_MASK);
139
140#ifdef VLAN_DEBUG
141 printk(VLAN_DBG "%s: skb: %p vlan_id: %hx\n",
142 __FUNCTION__, skb, vid);
143#endif
144
145 /* Ok, we will find the correct VLAN device, strip the header,
146 * and then go on as usual.
147 */
148
149 /* We have 12 bits of vlan ID.
150 *
151 * We must not drop allow preempt until we hold a
152 * reference to the device (netif_rx does that) or we
153 * fail.
154 */
155
156 rcu_read_lock();
157 skb->dev = __find_vlan_dev(dev, vid);
158 if (!skb->dev) {
159 rcu_read_unlock();
160
161#ifdef VLAN_DEBUG
162 printk(VLAN_DBG "%s: ERROR: No net_device for VID: %i on dev: %s [%i]\n",
163 __FUNCTION__, (unsigned int)(vid), dev->name, dev->ifindex);
164#endif
165 kfree_skb(skb);
166 return -1;
167 }
168
169 skb->dev->last_rx = jiffies;
170
171 /* Bump the rx counters for the VLAN device. */
172 stats = vlan_dev_get_stats(skb->dev);
173 stats->rx_packets++;
174 stats->rx_bytes += skb->len;
175
cbb042f9
HX
176 /* Take off the VLAN header (4 bytes currently) */
177 skb_pull_rcsum(skb, VLAN_HLEN);
a388442c 178
1da177e4
LT
179 /* Ok, lets check to make sure the device (dev) we
180 * came in on is what this VLAN is attached to.
181 */
182
183 if (dev != VLAN_DEV_INFO(skb->dev)->real_dev) {
184 rcu_read_unlock();
185
186#ifdef VLAN_DEBUG
187 printk(VLAN_DBG "%s: dropping skb: %p because came in on wrong device, dev: %s real_dev: %s, skb_dev: %s\n",
122952fc
YH
188 __FUNCTION__, skb, dev->name,
189 VLAN_DEV_INFO(skb->dev)->real_dev->name,
1da177e4
LT
190 skb->dev->name);
191#endif
192 kfree_skb(skb);
193 stats->rx_errors++;
194 return -1;
195 }
196
197 /*
198 * Deal with ingress priority mapping.
199 */
200 skb->priority = vlan_get_ingress_priority(skb->dev, ntohs(vhdr->h_vlan_TCI));
201
202#ifdef VLAN_DEBUG
203 printk(VLAN_DBG "%s: priority: %lu for TCI: %hu (hbo)\n",
122952fc 204 __FUNCTION__, (unsigned long)(skb->priority),
1da177e4
LT
205 ntohs(vhdr->h_vlan_TCI));
206#endif
207
208 /* The ethernet driver already did the pkt_type calculations
209 * for us...
210 */
211 switch (skb->pkt_type) {
212 case PACKET_BROADCAST: /* Yeah, stats collect these together.. */
213 // stats->broadcast ++; // no such counter :-(
214 break;
215
216 case PACKET_MULTICAST:
217 stats->multicast++;
218 break;
219
122952fc 220 case PACKET_OTHERHOST:
1da177e4
LT
221 /* Our lower layer thinks this is not local, let's make sure.
222 * This allows the VLAN to have a different MAC than the underlying
223 * device, and still route correctly.
224 */
d3f4a687 225 if (!compare_ether_addr(eth_hdr(skb)->h_dest, skb->dev->dev_addr)) {
1da177e4
LT
226 /* It is for our (changed) MAC-address! */
227 skb->pkt_type = PACKET_HOST;
228 }
229 break;
230 default:
231 break;
3ff50b79 232 }
1da177e4
LT
233
234 /* Was a VLAN packet, grab the encapsulated protocol, which the layer
235 * three protocols care about.
236 */
237 /* proto = get_unaligned(&vhdr->h_vlan_encapsulated_proto); */
238 proto = vhdr->h_vlan_encapsulated_proto;
239
240 skb->protocol = proto;
241 if (ntohs(proto) >= 1536) {
242 /* place it back on the queue to be handled by
243 * true layer 3 protocols.
244 */
245
246 /* See if we are configured to re-write the VLAN header
247 * to make it look like ethernet...
248 */
249 skb = vlan_check_reorder_header(skb);
250
251 /* Can be null if skb-clone fails when re-ordering */
252 if (skb) {
253 netif_rx(skb);
254 } else {
255 /* TODO: Add a more specific counter here. */
256 stats->rx_errors++;
257 }
258 rcu_read_unlock();
259 return 0;
260 }
261
262 rawp = skb->data;
263
264 /*
265 * This is a magic hack to spot IPX packets. Older Novell breaks
266 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
267 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
268 * won't work for fault tolerant netware but does for the rest.
269 */
270 if (*(unsigned short *)rawp == 0xFFFF) {
b93b7eeb 271 skb->protocol = htons(ETH_P_802_3);
1da177e4
LT
272 /* place it back on the queue to be handled by true layer 3 protocols.
273 */
274
275 /* See if we are configured to re-write the VLAN header
276 * to make it look like ethernet...
277 */
278 skb = vlan_check_reorder_header(skb);
279
280 /* Can be null if skb-clone fails when re-ordering */
281 if (skb) {
282 netif_rx(skb);
283 } else {
284 /* TODO: Add a more specific counter here. */
285 stats->rx_errors++;
286 }
287 rcu_read_unlock();
288 return 0;
289 }
290
291 /*
292 * Real 802.2 LLC
293 */
b93b7eeb 294 skb->protocol = htons(ETH_P_802_2);
1da177e4
LT
295 /* place it back on the queue to be handled by upper layer protocols.
296 */
297
298 /* See if we are configured to re-write the VLAN header
299 * to make it look like ethernet...
300 */
301 skb = vlan_check_reorder_header(skb);
302
303 /* Can be null if skb-clone fails when re-ordering */
304 if (skb) {
305 netif_rx(skb);
306 } else {
307 /* TODO: Add a more specific counter here. */
308 stats->rx_errors++;
309 }
310 rcu_read_unlock();
311 return 0;
312}
313
314static inline unsigned short vlan_dev_get_egress_qos_mask(struct net_device* dev,
315 struct sk_buff* skb)
316{
317 struct vlan_priority_tci_mapping *mp =
318 VLAN_DEV_INFO(dev)->egress_priority_map[(skb->priority & 0xF)];
319
320 while (mp) {
321 if (mp->priority == skb->priority) {
322 return mp->vlan_qos; /* This should already be shifted to mask
323 * correctly with the VLAN's TCI
324 */
325 }
326 mp = mp->next;
327 }
328 return 0;
329}
330
331/*
122952fc 332 * Create the VLAN header for an arbitrary protocol layer
1da177e4
LT
333 *
334 * saddr=NULL means use device source address
335 * daddr=NULL means leave destination address (eg unresolved arp)
336 *
337 * This is called when the SKB is moving down the stack towards the
338 * physical devices.
339 */
340int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
122952fc
YH
341 unsigned short type, void *daddr, void *saddr,
342 unsigned len)
1da177e4
LT
343{
344 struct vlan_hdr *vhdr;
345 unsigned short veth_TCI = 0;
346 int rc = 0;
347 int build_vlan_header = 0;
348 struct net_device *vdev = dev; /* save this for the bottom of the method */
349
350#ifdef VLAN_DEBUG
351 printk(VLAN_DBG "%s: skb: %p type: %hx len: %x vlan_id: %hx, daddr: %p\n",
352 __FUNCTION__, skb, type, len, VLAN_DEV_INFO(dev)->vlan_id, daddr);
353#endif
354
355 /* build vlan header only if re_order_header flag is NOT set. This
356 * fixes some programs that get confused when they see a VLAN device
357 * sending a frame that is VLAN encoded (the consensus is that the VLAN
358 * device should look completely like an Ethernet device when the
122952fc 359 * REORDER_HEADER flag is set) The drawback to this is some extra
1da177e4
LT
360 * header shuffling in the hard_start_xmit. Users can turn off this
361 * REORDER behaviour with the vconfig tool.
362 */
a4bf3af4
PM
363 if (!(VLAN_DEV_INFO(dev)->flags & VLAN_FLAG_REORDER_HDR))
364 build_vlan_header = 1;
1da177e4
LT
365
366 if (build_vlan_header) {
367 vhdr = (struct vlan_hdr *) skb_push(skb, VLAN_HLEN);
368
369 /* build the four bytes that make this a VLAN header. */
370
371 /* Now, construct the second two bytes. This field looks something
372 * like:
373 * usr_priority: 3 bits (high bits)
374 * CFI 1 bit
375 * VLAN ID 12 bits (low bits)
376 *
377 */
378 veth_TCI = VLAN_DEV_INFO(dev)->vlan_id;
379 veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb);
380
381 vhdr->h_vlan_TCI = htons(veth_TCI);
382
383 /*
384 * Set the protocol type.
385 * For a packet of type ETH_P_802_3 we put the length in here instead.
386 * It is up to the 802.2 layer to carry protocol information.
387 */
388
389 if (type != ETH_P_802_3) {
390 vhdr->h_vlan_encapsulated_proto = htons(type);
391 } else {
392 vhdr->h_vlan_encapsulated_proto = htons(len);
393 }
279e172a
JB
394
395 skb->protocol = htons(ETH_P_8021Q);
be8bd863 396 skb_reset_network_header(skb);
1da177e4
LT
397 }
398
399 /* Before delegating work to the lower layer, enter our MAC-address */
400 if (saddr == NULL)
401 saddr = dev->dev_addr;
402
403 dev = VLAN_DEV_INFO(dev)->real_dev;
404
405 /* MPLS can send us skbuffs w/out enough space. This check will grow the
406 * skb if it doesn't have enough headroom. Not a beautiful solution, so
407 * I'll tick a counter so that users can know it's happening... If they
408 * care...
409 */
410
411 /* NOTE: This may still break if the underlying device is not the final
412 * device (and thus there are more headers to add...) It should work for
413 * good-ole-ethernet though.
414 */
415 if (skb_headroom(skb) < dev->hard_header_len) {
416 struct sk_buff *sk_tmp = skb;
417 skb = skb_realloc_headroom(sk_tmp, dev->hard_header_len);
418 kfree_skb(sk_tmp);
419 if (skb == NULL) {
420 struct net_device_stats *stats = vlan_dev_get_stats(vdev);
421 stats->tx_dropped++;
422 return -ENOMEM;
423 }
424 VLAN_DEV_INFO(vdev)->cnt_inc_headroom_on_tx++;
425#ifdef VLAN_DEBUG
426 printk(VLAN_DBG "%s: %s: had to grow skb.\n", __FUNCTION__, vdev->name);
427#endif
428 }
429
430 if (build_vlan_header) {
431 /* Now make the underlying real hard header */
432 rc = dev->hard_header(skb, dev, ETH_P_8021Q, daddr, saddr, len + VLAN_HLEN);
433
434 if (rc > 0) {
435 rc += VLAN_HLEN;
436 } else if (rc < 0) {
437 rc -= VLAN_HLEN;
438 }
439 } else {
440 /* If here, then we'll just make a normal looking ethernet frame,
441 * but, the hard_start_xmit method will insert the tag (it has to
442 * be able to do this for bridged and other skbs that don't come
443 * down the protocol stack in an orderly manner.
444 */
445 rc = dev->hard_header(skb, dev, type, daddr, saddr, len);
446 }
447
448 return rc;
449}
450
451int vlan_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
452{
453 struct net_device_stats *stats = vlan_dev_get_stats(dev);
454 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)(skb->data);
455
456 /* Handle non-VLAN frames if they are sent to us, for example by DHCP.
457 *
458 * NOTE: THIS ASSUMES DIX ETHERNET, SPECIFICALLY NOT SUPPORTING
459 * OTHER THINGS LIKE FDDI/TokenRing/802.3 SNAPs...
460 */
461
b93b7eeb 462 if (veth->h_vlan_proto != htons(ETH_P_8021Q)) {
1da177e4
LT
463 int orig_headroom = skb_headroom(skb);
464 unsigned short veth_TCI;
465
466 /* This is not a VLAN frame...but we can fix that! */
467 VLAN_DEV_INFO(dev)->cnt_encap_on_xmit++;
468
469#ifdef VLAN_DEBUG
470 printk(VLAN_DBG "%s: proto to encap: 0x%hx (hbo)\n",
471 __FUNCTION__, htons(veth->h_vlan_proto));
472#endif
473 /* Construct the second two bytes. This field looks something
474 * like:
475 * usr_priority: 3 bits (high bits)
476 * CFI 1 bit
477 * VLAN ID 12 bits (low bits)
478 */
479 veth_TCI = VLAN_DEV_INFO(dev)->vlan_id;
480 veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb);
481
482 skb = __vlan_put_tag(skb, veth_TCI);
483 if (!skb) {
484 stats->tx_dropped++;
485 return 0;
486 }
487
488 if (orig_headroom < VLAN_HLEN) {
489 VLAN_DEV_INFO(dev)->cnt_inc_headroom_on_tx++;
490 }
491 }
492
493#ifdef VLAN_DEBUG
494 printk(VLAN_DBG "%s: about to send skb: %p to dev: %s\n",
495 __FUNCTION__, skb, skb->dev->name);
496 printk(VLAN_DBG " %2hx.%2hx.%2hx.%2xh.%2hx.%2hx %2hx.%2hx.%2hx.%2hx.%2hx.%2hx %4hx %4hx %4hx\n",
497 veth->h_dest[0], veth->h_dest[1], veth->h_dest[2], veth->h_dest[3], veth->h_dest[4], veth->h_dest[5],
498 veth->h_source[0], veth->h_source[1], veth->h_source[2], veth->h_source[3], veth->h_source[4], veth->h_source[5],
499 veth->h_vlan_proto, veth->h_vlan_TCI, veth->h_vlan_encapsulated_proto);
500#endif
501
502 stats->tx_packets++; /* for statics only */
503 stats->tx_bytes += skb->len;
504
505 skb->dev = VLAN_DEV_INFO(dev)->real_dev;
506 dev_queue_xmit(skb);
507
508 return 0;
509}
510
511int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
512{
513 struct net_device_stats *stats = vlan_dev_get_stats(dev);
514 unsigned short veth_TCI;
515
516 /* Construct the second two bytes. This field looks something
517 * like:
518 * usr_priority: 3 bits (high bits)
519 * CFI 1 bit
520 * VLAN ID 12 bits (low bits)
521 */
522 veth_TCI = VLAN_DEV_INFO(dev)->vlan_id;
523 veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb);
524 skb = __vlan_hwaccel_put_tag(skb, veth_TCI);
525
526 stats->tx_packets++;
527 stats->tx_bytes += skb->len;
528
529 skb->dev = VLAN_DEV_INFO(dev)->real_dev;
530 dev_queue_xmit(skb);
531
532 return 0;
533}
534
535int vlan_dev_change_mtu(struct net_device *dev, int new_mtu)
536{
537 /* TODO: gotta make sure the underlying layer can handle it,
538 * maybe an IFF_VLAN_CAPABLE flag for devices?
539 */
540 if (VLAN_DEV_INFO(dev)->real_dev->mtu < new_mtu)
541 return -ERANGE;
542
543 dev->mtu = new_mtu;
544
545 return 0;
546}
547
c17d8874
PM
548void vlan_dev_set_ingress_priority(const struct net_device *dev,
549 u32 skb_prio, short vlan_prio)
1da177e4 550{
b020cb48
PM
551 struct vlan_dev_info *vlan = VLAN_DEV_INFO(dev);
552
553 if (vlan->ingress_priority_map[vlan_prio & 0x7] && !skb_prio)
554 vlan->nr_ingress_mappings--;
555 else if (!vlan->ingress_priority_map[vlan_prio & 0x7] && skb_prio)
556 vlan->nr_ingress_mappings++;
557
558 vlan->ingress_priority_map[vlan_prio & 0x7] = skb_prio;
1da177e4
LT
559}
560
c17d8874
PM
561int vlan_dev_set_egress_priority(const struct net_device *dev,
562 u32 skb_prio, short vlan_prio)
1da177e4 563{
b020cb48 564 struct vlan_dev_info *vlan = VLAN_DEV_INFO(dev);
1da177e4
LT
565 struct vlan_priority_tci_mapping *mp = NULL;
566 struct vlan_priority_tci_mapping *np;
b020cb48 567 u32 vlan_qos = (vlan_prio << 13) & 0xE000;
122952fc 568
c17d8874 569 /* See if a priority mapping exists.. */
b020cb48 570 mp = vlan->egress_priority_map[skb_prio & 0xF];
c17d8874
PM
571 while (mp) {
572 if (mp->priority == skb_prio) {
b020cb48
PM
573 if (mp->vlan_qos && !vlan_qos)
574 vlan->nr_egress_mappings--;
575 else if (!mp->vlan_qos && vlan_qos)
576 vlan->nr_egress_mappings++;
577 mp->vlan_qos = vlan_qos;
c17d8874 578 return 0;
1da177e4 579 }
c17d8874 580 mp = mp->next;
1da177e4 581 }
c17d8874
PM
582
583 /* Create a new mapping then. */
b020cb48 584 mp = vlan->egress_priority_map[skb_prio & 0xF];
c17d8874
PM
585 np = kmalloc(sizeof(struct vlan_priority_tci_mapping), GFP_KERNEL);
586 if (!np)
587 return -ENOBUFS;
588
589 np->next = mp;
590 np->priority = skb_prio;
b020cb48
PM
591 np->vlan_qos = vlan_qos;
592 vlan->egress_priority_map[skb_prio & 0xF] = np;
593 if (vlan_qos)
594 vlan->nr_egress_mappings++;
c17d8874 595 return 0;
1da177e4
LT
596}
597
a4bf3af4 598/* Flags are defined in the vlan_flags enum in include/linux/if_vlan.h file. */
c17d8874
PM
599int vlan_dev_set_vlan_flag(const struct net_device *dev,
600 u32 flag, short flag_val)
1da177e4 601{
c17d8874 602 /* verify flag is supported */
a4bf3af4 603 if (flag == VLAN_FLAG_REORDER_HDR) {
c17d8874 604 if (flag_val) {
a4bf3af4 605 VLAN_DEV_INFO(dev)->flags |= VLAN_FLAG_REORDER_HDR;
1da177e4 606 } else {
a4bf3af4 607 VLAN_DEV_INFO(dev)->flags &= ~VLAN_FLAG_REORDER_HDR;
1da177e4 608 }
c17d8874 609 return 0;
1da177e4 610 }
c17d8874 611 printk(KERN_ERR "%s: flag %i is not valid.\n", __FUNCTION__, flag);
1da177e4
LT
612 return -EINVAL;
613}
614
c17d8874 615void vlan_dev_get_realdev_name(const struct net_device *dev, char *result)
1da177e4 616{
c17d8874 617 strncpy(result, VLAN_DEV_INFO(dev)->real_dev->name, 23);
1da177e4
LT
618}
619
c17d8874 620void vlan_dev_get_vid(const struct net_device *dev, unsigned short *result)
1da177e4 621{
c17d8874 622 *result = VLAN_DEV_INFO(dev)->vlan_id;
1da177e4
LT
623}
624
1da177e4
LT
625int vlan_dev_open(struct net_device *dev)
626{
8c979c26
PM
627 struct vlan_dev_info *vlan = VLAN_DEV_INFO(dev);
628 struct net_device *real_dev = vlan->real_dev;
629 int err;
630
631 if (!(real_dev->flags & IFF_UP))
1da177e4
LT
632 return -ENETDOWN;
633
8c979c26
PM
634 if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) {
635 err = dev_unicast_add(real_dev, dev->dev_addr, ETH_ALEN);
636 if (err < 0)
637 return err;
638 }
639 memcpy(vlan->real_dev_addr, real_dev->dev_addr, ETH_ALEN);
640
6c78dcbd
PM
641 if (dev->flags & IFF_ALLMULTI)
642 dev_set_allmulti(real_dev, 1);
643 if (dev->flags & IFF_PROMISC)
644 dev_set_promiscuity(real_dev, 1);
645
1da177e4
LT
646 return 0;
647}
648
649int vlan_dev_stop(struct net_device *dev)
650{
8c979c26
PM
651 struct net_device *real_dev = VLAN_DEV_INFO(dev)->real_dev;
652
56addd6e 653 dev_mc_unsync(real_dev, dev);
6c78dcbd
PM
654 if (dev->flags & IFF_ALLMULTI)
655 dev_set_allmulti(real_dev, -1);
656 if (dev->flags & IFF_PROMISC)
657 dev_set_promiscuity(real_dev, -1);
658
8c979c26
PM
659 if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr))
660 dev_unicast_delete(real_dev, dev->dev_addr, dev->addr_len);
661
1da177e4
LT
662 return 0;
663}
664
665int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
666{
667 struct net_device *real_dev = VLAN_DEV_INFO(dev)->real_dev;
668 struct ifreq ifrr;
669 int err = -EOPNOTSUPP;
670
671 strncpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
672 ifrr.ifr_ifru = ifr->ifr_ifru;
673
674 switch(cmd) {
675 case SIOCGMIIPHY:
676 case SIOCGMIIREG:
677 case SIOCSMIIREG:
122952fc 678 if (real_dev->do_ioctl && netif_device_present(real_dev))
1da177e4
LT
679 err = real_dev->do_ioctl(real_dev, &ifrr, cmd);
680 break;
1da177e4
LT
681 }
682
122952fc 683 if (!err)
1da177e4
LT
684 ifr->ifr_ifru = ifrr.ifr_ifru;
685
686 return err;
687}
688
6c78dcbd
PM
689void vlan_change_rx_flags(struct net_device *dev, int change)
690{
691 struct net_device *real_dev = VLAN_DEV_INFO(dev)->real_dev;
692
693 if (change & IFF_ALLMULTI)
694 dev_set_allmulti(real_dev, dev->flags & IFF_ALLMULTI ? 1 : -1);
695 if (change & IFF_PROMISC)
696 dev_set_promiscuity(real_dev, dev->flags & IFF_PROMISC ? 1 : -1);
697}
698
1da177e4
LT
699/** Taken from Gleb + Lennert's VLAN code, and modified... */
700void vlan_dev_set_multicast_list(struct net_device *vlan_dev)
701{
56addd6e 702 dev_mc_sync(VLAN_DEV_INFO(vlan_dev)->real_dev, vlan_dev);
1da177e4 703}