Factor out vlan_ether_ptap() from vlan_input_tag()
[dragonfly.git] / sys / net / vlan / if_vlan.c
1 /*
2  * Copyright 1998 Massachusetts Institute of Technology
3  *
4  * Permission to use, copy, modify, and distribute this software and
5  * its documentation for any purpose and without fee is hereby
6  * granted, provided that both the above copyright notice and this
7  * permission notice appear in all copies, that both the above
8  * copyright notice and this permission notice appear in all
9  * supporting documentation, and that the name of M.I.T. not be used
10  * in advertising or publicity pertaining to distribution of the
11  * software without specific, written prior permission.  M.I.T. makes
12  * no representations about the suitability of this software for any
13  * purpose.  It is provided "as is" without express or implied
14  * warranty.
15  * 
16  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
17  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20  * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD: src/sys/net/if_vlan.c,v 1.15.2.13 2003/02/14 22:25:58 fenner Exp $
30  * $DragonFly: src/sys/net/vlan/if_vlan.c,v 1.29 2008/03/10 11:44:57 sephe Exp $
31  */
32
33 /*
34  * if_vlan.c - pseudo-device driver for IEEE 802.1Q virtual LANs.
35  * Might be extended some day to also handle IEEE 802.1p priority
36  * tagging.  This is sort of sneaky in the implementation, since
37  * we need to pretend to be enough of an Ethernet implementation
38  * to make arp work.  The way we do this is by telling everyone
39  * that we are an Ethernet, and then catch the packets that
40  * ether_output() left on our output queue queue when it calls
41  * if_start(), rewrite them for use by the real outgoing interface,
42  * and ask it to send them.
43  *
44  *
45  * XXX It's incorrect to assume that we must always kludge up
46  * headers on the physical device's behalf: some devices support
47  * VLAN tag insertion and extraction in firmware. For these cases,
48  * one can change the behavior of the vlan interface by setting
49  * the LINK0 flag on it (that is setting the vlan interface's LINK0
50  * flag, _not_ the parent's LINK0 flag; we try to leave the parent
51  * alone). If the interface has the LINK0 flag set, then it will
52  * not modify the ethernet header on output, because the parent
53  * can do that for itself. On input, the parent can call vlan_input_tag()
54  * directly in order to supply us with an incoming mbuf and the vlan
55  * tag value that goes with it.
56  */
57
58 #ifndef NVLAN
59 #include "use_vlan.h"
60 #endif
61 #include "opt_inet.h"
62
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/kernel.h>
66 #include <sys/malloc.h>
67 #include <sys/mbuf.h>
68 #include <sys/module.h>
69 #include <sys/queue.h>
70 #include <sys/socket.h>
71 #include <sys/sockio.h>
72 #include <sys/sysctl.h>
73 #include <sys/bus.h>
74 #include <sys/thread2.h>
75
76 #include <net/bpf.h>
77 #include <net/ethernet.h>
78 #include <net/if.h>
79 #include <net/if_arp.h>
80 #include <net/if_dl.h>
81 #include <net/if_types.h>
82 #include <net/ifq_var.h>
83 #include <net/if_clone.h>
84 #include <net/netmsg2.h>
85
86 #ifdef INET
87 #include <netinet/in.h>
88 #include <netinet/if_ether.h>
89 #endif
90
91 #include <net/vlan/if_vlan_var.h>
92 #include <net/vlan/if_vlan_ether.h>
93
94 struct vlan_mc_entry {
95         struct ether_addr               mc_addr;
96         SLIST_ENTRY(vlan_mc_entry)      mc_entries;
97 };
98
99 struct  ifvlan {
100         struct  arpcom ifv_ac;  /* make this an interface */
101         struct  ifnet *ifv_p;   /* parent inteface of this vlan */
102         struct  ifv_linkmib {
103                 int     ifvm_parent;
104                 u_int16_t ifvm_proto; /* encapsulation ethertype */
105                 u_int16_t ifvm_tag; /* tag to apply on packets leaving if */
106         }       ifv_mib;
107         SLIST_HEAD(__vlan_mchead, vlan_mc_entry)        vlan_mc_listhead;
108         LIST_ENTRY(ifvlan) ifv_list;
109         struct resource *r_unit;        /* resource allocated for this unit */
110 };
111 #define ifv_if  ifv_ac.ac_if
112 #define ifv_tag ifv_mib.ifvm_tag
113
114 #define VLANNAME        "vlan"
115
116 SYSCTL_DECL(_net_link);
117 SYSCTL_NODE(_net_link, IFT_L2VLAN, vlan, CTLFLAG_RW, 0, "IEEE 802.1Q VLAN");
118 SYSCTL_NODE(_net_link_vlan, PF_LINK, link, CTLFLAG_RW, 0, "for consistency");
119
120 static MALLOC_DEFINE(M_VLAN, "vlan", "802.1Q Virtual LAN Interface");
121 static LIST_HEAD(, ifvlan) ifv_list;
122
123 static  int vlan_clone_create(struct if_clone *, int);
124 static  void vlan_clone_destroy(struct ifnet *);
125 static  void vlan_start(struct ifnet *ifp);
126 static  void vlan_ifinit(void *foo);
127 static  int vlan_input(const struct ether_header *eh, struct mbuf *m);
128 static  int vlan_input_tag(struct mbuf *m, uint16_t t);
129 static  int vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t addr,
130                 struct ucred *cr);
131 static  int vlan_setmulti(struct ifnet *ifp);
132 static  int vlan_unconfig(struct ifnet *ifp);
133 static  int vlan_config(struct ifvlan *ifv, struct ifnet *p);
134
135 struct if_clone vlan_cloner = IF_CLONE_INITIALIZER("vlan", vlan_clone_create,
136     vlan_clone_destroy, NVLAN, IF_MAXUNIT);
137
138 /*
139  * Program our multicast filter. What we're actually doing is
140  * programming the multicast filter of the parent. This has the
141  * side effect of causing the parent interface to receive multicast
142  * traffic that it doesn't really want, which ends up being discarded
143  * later by the upper protocol layers. Unfortunately, there's no way
144  * to avoid this: there really is only one physical interface.
145  */
146 static int
147 vlan_setmulti(struct ifnet *ifp)
148 {
149         struct ifnet            *ifp_p;
150         struct ifmultiaddr      *ifma, *rifma = NULL;
151         struct ifvlan           *sc;
152         struct vlan_mc_entry    *mc = NULL;
153         struct sockaddr_dl      sdl;
154         int                     error;
155
156         /* Find the parent. */
157         sc = ifp->if_softc;
158         ifp_p = sc->ifv_p;
159
160         /*
161          * If we don't have a parent, just remember the membership for
162          * when we do.
163          */
164         if (ifp_p == NULL)
165                 return(0);
166
167         bzero((char *)&sdl, sizeof sdl);
168         sdl.sdl_len = sizeof sdl;
169         sdl.sdl_family = AF_LINK;
170         sdl.sdl_index = ifp_p->if_index;
171         sdl.sdl_type = IFT_ETHER;
172         sdl.sdl_alen = ETHER_ADDR_LEN;
173
174         /* First, remove any existing filter entries. */
175         while(SLIST_FIRST(&sc->vlan_mc_listhead) != NULL) {
176                 mc = SLIST_FIRST(&sc->vlan_mc_listhead);
177                 bcopy((char *)&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
178                 error = if_delmulti(ifp_p, (struct sockaddr *)&sdl);
179                 if (error)
180                         return(error);
181                 SLIST_REMOVE_HEAD(&sc->vlan_mc_listhead, mc_entries);
182                 kfree(mc, M_VLAN);
183         }
184
185         /* Now program new ones. */
186         LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
187                 if (ifma->ifma_addr->sa_family != AF_LINK)
188                         continue;
189                 mc = kmalloc(sizeof(struct vlan_mc_entry), M_VLAN, M_WAITOK);
190                 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
191                     (char *)&mc->mc_addr, ETHER_ADDR_LEN);
192                 SLIST_INSERT_HEAD(&sc->vlan_mc_listhead, mc, mc_entries);
193                 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
194                     LLADDR(&sdl), ETHER_ADDR_LEN);
195                 error = if_addmulti(ifp_p, (struct sockaddr *)&sdl, &rifma);
196                 if (error)
197                         return(error);
198         }
199
200         return(0);
201 }
202
203 static int
204 vlan_modevent(module_t mod, int type, void *data) 
205
206
207         switch (type) { 
208         case MOD_LOAD: 
209                 LIST_INIT(&ifv_list);
210                 vlan_input_p = vlan_input;
211                 vlan_input_tag_p = vlan_input_tag;
212                 if_clone_attach(&vlan_cloner);
213                 break; 
214         case MOD_UNLOAD: 
215                 if_clone_detach(&vlan_cloner);
216                 vlan_input_p = NULL;
217                 vlan_input_tag_p = NULL;
218                 while (!LIST_EMPTY(&ifv_list))
219                         vlan_clone_destroy(&LIST_FIRST(&ifv_list)->ifv_if);
220                 break;
221         } 
222         return 0; 
223
224
225 static moduledata_t vlan_mod = { 
226         "if_vlan", 
227         vlan_modevent, 
228         0
229 }; 
230
231 DECLARE_MODULE(if_vlan, vlan_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
232
233 static int
234 vlan_clone_create(struct if_clone *ifc, int unit)
235 {
236         struct ifvlan *ifv;
237         struct ifnet *ifp;
238
239         ifv = kmalloc(sizeof(struct ifvlan), M_VLAN, M_WAITOK | M_ZERO);
240         ifp = &ifv->ifv_if;
241         SLIST_INIT(&ifv->vlan_mc_listhead);
242
243         crit_enter();
244         LIST_INSERT_HEAD(&ifv_list, ifv, ifv_list);
245         crit_exit();
246
247         ifp->if_softc = ifv;
248         if_initname(ifp, "vlan", unit);
249         /* NB: flags are not set here */
250         ifp->if_linkmib = &ifv->ifv_mib;
251         ifp->if_linkmiblen = sizeof ifv->ifv_mib;
252         /* NB: mtu is not set here */
253
254         ifp->if_init = vlan_ifinit;
255         ifp->if_start = vlan_start;
256         ifp->if_ioctl = vlan_ioctl;
257         ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
258         ifq_set_ready(&ifp->if_snd);
259         ether_ifattach(ifp, ifv->ifv_ac.ac_enaddr, NULL);
260         /* Now undo some of the damage... */
261         ifp->if_data.ifi_type = IFT_L2VLAN;
262         ifp->if_data.ifi_hdrlen = EVL_ENCAPLEN;
263
264         return (0);
265 }
266
267 static void
268 vlan_clone_destroy(struct ifnet *ifp)
269 {
270         struct ifvlan *ifv = ifp->if_softc;
271
272         crit_enter();
273
274         LIST_REMOVE(ifv, ifv_list);
275         vlan_unconfig(ifp);
276         ether_ifdetach(ifp);
277
278         crit_exit();
279
280         kfree(ifv, M_VLAN);
281 }
282
283 static void
284 vlan_ifinit(void *foo)
285 {
286         return;
287 }
288
289 static void
290 vlan_start(struct ifnet *ifp)
291 {
292         struct ifvlan *ifv;
293         struct ifnet *ifp_p;
294         struct mbuf *m;
295
296         ifv = ifp->if_softc;
297         ifp_p = ifv->ifv_p;
298
299         ifp->if_flags |= IFF_OACTIVE;
300         for (;;) {
301                 struct netmsg_packet *nmp;
302                 struct netmsg *nmsg;
303                 struct lwkt_port *port;
304
305                 m = ifq_dequeue(&ifp->if_snd, NULL);
306                 if (m == NULL)
307                         break;
308                 BPF_MTAP(ifp, m);
309
310                 /*
311                  * Do not run parent's if_start() if the parent is not up,
312                  * or parent's driver will cause a system crash.
313                  */
314                 if ((ifp_p->if_flags & (IFF_UP | IFF_RUNNING)) !=
315                     (IFF_UP | IFF_RUNNING)) {
316                         m_freem(m);
317                         ifp->if_data.ifi_collisions++;
318                         continue;
319                 }
320
321                 /*
322                  * We need some way to tell the interface where the packet
323                  * came from so that it knows how to find the VLAN tag to
324                  * use, so we set the ether_vlantag in the mbuf packet header
325                  * to our vlan tag.  We also set the M_VLANTAG flag in the
326                  * mbuf to let the parent driver know that the ether_vlantag
327                  * is really valid.
328                  */
329                 m->m_pkthdr.ether_vlantag = ifv->ifv_tag;
330                 m->m_flags |= M_VLANTAG;
331
332                 nmp = &m->m_hdr.mh_netmsg;
333                 nmsg = &nmp->nm_netmsg;
334
335                 netmsg_init(nmsg, &netisr_apanic_rport, 0, vlan_start_dispatch);
336                 nmp->nm_packet = m;
337                 nmsg->nm_lmsg.u.ms_resultp = ifp_p;
338
339                 port = cpu_portfn(ifp_p->if_index % ncpus /* XXX */);
340                 lwkt_sendmsg(port, &nmp->nm_netmsg.nm_lmsg);
341                 ifp->if_opackets++;
342         }
343         ifp->if_flags &= ~IFF_OACTIVE;
344 }
345
346 static int
347 vlan_input_tag(struct mbuf *m, uint16_t t)
348 {
349         struct bpf_if *bif;
350         struct ifvlan *ifv;
351         struct ifnet *rcvif;
352
353         rcvif = m->m_pkthdr.rcvif;
354
355         ASSERT_SERIALIZED(rcvif->if_serializer);
356
357         /*
358          * Fake up a header and send the packet to the physical interface's
359          * bpf tap if active.
360          */
361         if ((bif = rcvif->if_bpf) != NULL)
362                 vlan_ether_ptap(bif, m, t);
363
364         for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
365             ifv = LIST_NEXT(ifv, ifv_list)) {
366                 if (rcvif == ifv->ifv_p && ifv->ifv_tag == t)
367                         break;
368         }
369
370         if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
371                 m_freem(m);
372                 return -1;      /* So the parent can take note */
373         }
374
375         /*
376          * Having found a valid vlan interface corresponding to
377          * the given source interface and vlan tag, run the
378          * the real packet through ether_input().
379          */
380         m->m_pkthdr.rcvif = &ifv->ifv_if;
381
382         ifv->ifv_if.if_ipackets++;
383         lwkt_serialize_exit(rcvif->if_serializer);
384         lwkt_serialize_enter(ifv->ifv_if.if_serializer);
385         ether_input(&ifv->ifv_if, m);
386         lwkt_serialize_exit(ifv->ifv_if.if_serializer);
387         lwkt_serialize_enter(rcvif->if_serializer);
388         return 0;
389 }
390
391 static int
392 vlan_input(const struct ether_header *eh, struct mbuf *m)
393 {
394         struct ifvlan *ifv;
395         struct ifnet *rcvif;
396         struct ether_header eh_copy;
397
398         rcvif = m->m_pkthdr.rcvif;
399         ASSERT_SERIALIZED(rcvif->if_serializer);
400
401         for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
402             ifv = LIST_NEXT(ifv, ifv_list)) {
403                 if (rcvif == ifv->ifv_p
404                     && (EVL_VLANOFTAG(ntohs(*mtod(m, u_int16_t *)))
405                         == ifv->ifv_tag))
406                         break;
407         }
408
409         if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
410                 rcvif->if_noproto++;
411                 m_freem(m);
412                 return -1;      /* so ether_input can take note */
413         }
414
415         /*
416          * Having found a valid vlan interface corresponding to
417          * the given source interface and vlan tag, remove the
418          * remaining encapsulation (ether_vlan_header minus the ether_header
419          * that had already been removed) and run the real packet
420          * through ether_input() a second time (it had better be
421          * reentrant!).
422          */
423         eh_copy = *eh;
424         eh_copy.ether_type = mtod(m, u_int16_t *)[1];   /* evl_proto */
425         m->m_pkthdr.rcvif = &ifv->ifv_if;
426         m_adj(m, EVL_ENCAPLEN);
427         M_PREPEND(m, ETHER_HDR_LEN, MB_WAIT); 
428         *(struct ether_header *)mtod(m, void *) = eh_copy;
429
430         ifv->ifv_if.if_ipackets++;
431         lwkt_serialize_exit(rcvif->if_serializer);
432         lwkt_serialize_enter(ifv->ifv_if.if_serializer);
433         ether_input(&ifv->ifv_if, m);
434         lwkt_serialize_exit(ifv->ifv_if.if_serializer);
435         lwkt_serialize_enter(rcvif->if_serializer);
436         return 0;
437 }
438
439 static int
440 vlan_config(struct ifvlan *ifv, struct ifnet *p)
441 {
442         struct sockaddr_dl *sdl1, *sdl2;
443
444         if (p->if_data.ifi_type != IFT_ETHER)
445                 return EPROTONOSUPPORT;
446         if (ifv->ifv_p)
447                 return EBUSY;
448         ifv->ifv_p = p;
449         if (p->if_capenable & IFCAP_VLAN_MTU)
450                 ifv->ifv_if.if_mtu = p->if_mtu;
451         else
452                 ifv->ifv_if.if_mtu = p->if_data.ifi_mtu - EVL_ENCAPLEN;
453
454         /*
455          * Copy only a selected subset of flags from the parent.
456          * Other flags are none of our business.
457          */
458         ifv->ifv_if.if_flags = (p->if_flags &
459             (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT));
460
461         /*
462          * Set up our ``Ethernet address'' to reflect the underlying
463          * physical interface's.
464          */
465         sdl1 = IF_LLSOCKADDR(&ifv->ifv_if);
466         sdl2 = IF_LLSOCKADDR(p);
467         sdl1->sdl_type = IFT_ETHER;
468         sdl1->sdl_alen = ETHER_ADDR_LEN;
469         bcopy(LLADDR(sdl2), LLADDR(sdl1), ETHER_ADDR_LEN);
470         bcopy(LLADDR(sdl2), ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
471
472         /*
473          * Configure multicast addresses that may already be
474          * joined on the vlan device.
475          */
476         vlan_setmulti(&ifv->ifv_if);
477
478         return 0;
479 }
480
481 static int
482 vlan_unconfig(struct ifnet *ifp)
483 {
484         struct sockaddr_dl *sdl;
485         struct vlan_mc_entry *mc;
486         struct ifvlan *ifv;
487         struct ifnet *p;
488         int error;
489
490         ifv = ifp->if_softc;
491         p = ifv->ifv_p;
492
493         if (p) {
494                 struct sockaddr_dl sdl;
495
496                 /*
497                  * Since the interface is being unconfigured, we need to
498                  * empty the list of multicast groups that we may have joined
499                  * while we were alive from the parent's list.
500                  */
501                 bzero((char *)&sdl, sizeof sdl);
502                 sdl.sdl_len = sizeof sdl;
503                 sdl.sdl_family = AF_LINK;
504                 sdl.sdl_index = p->if_index;
505                 sdl.sdl_type = IFT_ETHER;
506                 sdl.sdl_alen = ETHER_ADDR_LEN;
507
508                 while(SLIST_FIRST(&ifv->vlan_mc_listhead) != NULL) {
509                         mc = SLIST_FIRST(&ifv->vlan_mc_listhead);
510                         bcopy((char *)&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
511                         error = if_delmulti(p, (struct sockaddr *)&sdl);
512                         if (error)
513                                 return(error);
514                         SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries);
515                         kfree(mc, M_VLAN);
516                 }
517         }
518
519         /* Disconnect from parent. */
520         ifv->ifv_p = NULL;
521         ifv->ifv_if.if_mtu = ETHERMTU;
522
523         /* Clear our MAC address. */
524         sdl = IF_LLSOCKADDR(&ifv->ifv_if);
525         sdl->sdl_type = IFT_ETHER;
526         sdl->sdl_alen = ETHER_ADDR_LEN;
527         bzero(LLADDR(sdl), ETHER_ADDR_LEN);
528         bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
529
530         return 0;
531 }
532
533 static int
534 vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
535 {
536         struct ifaddr *ifa;
537         struct ifnet *p;
538         struct ifreq *ifr;
539         struct ifvlan *ifv;
540         struct vlanreq vlr;
541         int error = 0;
542
543         ifr = (struct ifreq *)data;
544         ifa = (struct ifaddr *)data;
545         ifv = ifp->if_softc;
546
547         ASSERT_SERIALIZED(ifp->if_serializer);
548         crit_enter();
549
550         switch (cmd) {
551         case SIOCGIFMEDIA:
552                 if (ifv->ifv_p != NULL) {
553                         lwkt_serialize_exit(ifp->if_serializer);
554                         lwkt_serialize_enter(ifv->ifv_p->if_serializer);
555                         error = ifv->ifv_p->if_ioctl(ifv->ifv_p,
556                                                      SIOCGIFMEDIA, data, cr);
557                         lwkt_serialize_exit(ifv->ifv_p->if_serializer);
558                         lwkt_serialize_enter(ifp->if_serializer);
559                         /* Limit the result to the parent's current config. */
560                         if (error == 0) {
561                                 struct ifmediareq *ifmr;
562
563                                 ifmr = (struct ifmediareq *) data;
564                                 if (ifmr->ifm_count >= 1 && ifmr->ifm_ulist) {
565                                         ifmr->ifm_count = 1;
566                                         error = copyout(&ifmr->ifm_current,
567                                                 ifmr->ifm_ulist, 
568                                                 sizeof(int));
569                                 }
570                         }
571                 } else
572                         error = EINVAL;
573                 break;
574
575         case SIOCSIFMEDIA:
576                 error = EINVAL;
577                 break;
578
579         case SIOCSETVLAN:
580                 error = copyin(ifr->ifr_data, &vlr, sizeof vlr);
581                 if (error)
582                         break;
583                 if (vlr.vlr_parent[0] == '\0') {
584                         vlan_unconfig(ifp);
585                         if (ifp->if_flags & IFF_UP)
586                                 if_down(ifp);
587                         ifp->if_flags &= ~IFF_RUNNING;
588                         break;
589                 }
590                 p = ifunit(vlr.vlr_parent);
591                 if (p == 0) {
592                         error = ENOENT;
593                         break;
594                 }
595                 error = vlan_config(ifv, p);
596                 if (error)
597                         break;
598                 ifv->ifv_tag = vlr.vlr_tag;
599                 ifp->if_flags |= IFF_RUNNING;
600                 break;
601                 
602         case SIOCGETVLAN:
603                 bzero(&vlr, sizeof vlr);
604                 if (ifv->ifv_p) {
605                         strlcpy(vlr.vlr_parent, ifv->ifv_p->if_xname,
606                             sizeof(vlr.vlr_parent));
607                         vlr.vlr_tag = ifv->ifv_tag;
608                 }
609                 error = copyout(&vlr, ifr->ifr_data, sizeof vlr);
610                 break;
611                 
612         case SIOCSIFFLAGS:
613                 /*
614                  * We don't support promiscuous mode
615                  * right now because it would require help from the
616                  * underlying drivers, which hasn't been implemented.
617                  */
618                 if (ifr->ifr_flags & (IFF_PROMISC)) {
619                         ifp->if_flags &= ~(IFF_PROMISC);
620                         error = EINVAL;
621                 }
622                 break;
623
624         case SIOCADDMULTI:
625         case SIOCDELMULTI:
626                 error = vlan_setmulti(ifp);
627                 break;
628
629         default:
630                 error = ether_ioctl(ifp, cmd, data);
631                 break;
632         }
633
634         crit_exit();
635
636         return error;
637 }