if_vlan.c revision 83130
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: head/sys/net/if_vlan.c 83130 2001-09-06 02:40:43Z jlemon $
30 */
31
32/*
33 * if_vlan.c - pseudo-device driver for IEEE 802.1Q virtual LANs.
34 * Might be extended some day to also handle IEEE 802.1p priority
35 * tagging.  This is sort of sneaky in the implementation, since
36 * we need to pretend to be enough of an Ethernet implementation
37 * to make arp work.  The way we do this is by telling everyone
38 * that we are an Ethernet, and then catch the packets that
39 * ether_output() left on our output queue when it calls
40 * if_start(), rewrite them for use by the real outgoing interface,
41 * and ask it to send them.
42 *
43 *
44 * XXX It's incorrect to assume that we must always kludge up
45 * headers on the physical device's behalf: some devices support
46 * VLAN tag insertion and extraction in firmware. For these cases,
47 * one can change the behavior of the vlan interface by setting
48 * the LINK0 flag on it (that is setting the vlan interface's LINK0
49 * flag, _not_ the parent's LINK0 flag; we try to leave the parent
50 * alone). If the interface has the LINK0 flag set, then it will
51 * not modify the ethernet header on output, because the parent
52 * can do that for itself. On input, the parent can call vlan_input_tag()
53 * directly in order to supply us with an incoming mbuf and the vlan
54 * tag value that goes with it.
55 */
56
57#include "opt_inet.h"
58
59#include <sys/param.h>
60#include <sys/kernel.h>
61#include <sys/malloc.h>
62#include <sys/mbuf.h>
63#include <sys/module.h>
64#include <sys/queue.h>
65#include <sys/socket.h>
66#include <sys/sockio.h>
67#include <sys/sysctl.h>
68#include <sys/systm.h>
69#include <machine/bus.h>	/* XXX: Shouldn't really be required! */
70#include <sys/rman.h>
71
72#include <net/bpf.h>
73#include <net/ethernet.h>
74#include <net/if.h>
75#include <net/if_arp.h>
76#include <net/if_dl.h>
77#include <net/if_types.h>
78#include <net/if_vlan_var.h>
79
80#ifdef INET
81#include <netinet/in.h>
82#include <netinet/if_ether.h>
83#endif
84
85#define VLANNAME	"vlan"
86#define VLAN_MAXUNIT	0x7fff	/* ifp->if_unit is only 15 bits */
87
88SYSCTL_DECL(_net_link);
89SYSCTL_NODE(_net_link, IFT_L2VLAN, vlan, CTLFLAG_RW, 0, "IEEE 802.1Q VLAN");
90SYSCTL_NODE(_net_link_vlan, PF_LINK, link, CTLFLAG_RW, 0, "for consistency");
91
92static MALLOC_DEFINE(M_VLAN, "vlan", "802.1Q Virtual LAN Interface");
93static struct rman vlanunits[1];
94static LIST_HEAD(, ifvlan) ifv_list;
95
96static	int vlan_clone_create(struct if_clone *, int *);
97static	void vlan_clone_destroy(struct ifnet *);
98static	void vlan_start(struct ifnet *ifp);
99static	void vlan_ifinit(void *foo);
100static	int vlan_input(struct ether_header *eh, struct mbuf *m);
101static	int vlan_input_tag(struct ether_header *eh, struct mbuf *m,
102		u_int16_t t);
103static	int vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t addr);
104static	int vlan_setmulti(struct ifnet *ifp);
105static	int vlan_unconfig(struct ifnet *ifp);
106static	int vlan_config(struct ifvlan *ifv, struct ifnet *p);
107
108struct if_clone vlan_cloner =
109    IF_CLONE_INITIALIZER("vlan", vlan_clone_create, vlan_clone_destroy);
110
111/*
112 * Program our multicast filter. What we're actually doing is
113 * programming the multicast filter of the parent. This has the
114 * side effect of causing the parent interface to receive multicast
115 * traffic that it doesn't really want, which ends up being discarded
116 * later by the upper protocol layers. Unfortunately, there's no way
117 * to avoid this: there really is only one physical interface.
118 */
119static int
120vlan_setmulti(struct ifnet *ifp)
121{
122	struct ifnet		*ifp_p;
123	struct ifmultiaddr	*ifma, *rifma = NULL;
124	struct ifvlan		*sc;
125	struct vlan_mc_entry	*mc = NULL;
126	struct sockaddr_dl	sdl;
127	int			error;
128
129	/* Find the parent. */
130	sc = ifp->if_softc;
131	ifp_p = sc->ifv_p;
132
133	/*
134	 * If we don't have a parent, just remember the membership for
135	 * when we do.
136	 */
137	if (ifp_p == NULL)
138		return(0);
139
140	bzero((char *)&sdl, sizeof sdl);
141	sdl.sdl_len = sizeof sdl;
142	sdl.sdl_family = AF_LINK;
143	sdl.sdl_index = ifp_p->if_index;
144	sdl.sdl_type = IFT_ETHER;
145	sdl.sdl_alen = ETHER_ADDR_LEN;
146
147	/* First, remove any existing filter entries. */
148	while(SLIST_FIRST(&sc->vlan_mc_listhead) != NULL) {
149		mc = SLIST_FIRST(&sc->vlan_mc_listhead);
150		bcopy((char *)&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
151		error = if_delmulti(ifp_p, (struct sockaddr *)&sdl);
152		if (error)
153			return(error);
154		SLIST_REMOVE_HEAD(&sc->vlan_mc_listhead, mc_entries);
155		free(mc, M_VLAN);
156	}
157
158	/* Now program new ones. */
159	TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
160		if (ifma->ifma_addr->sa_family != AF_LINK)
161			continue;
162		mc = malloc(sizeof(struct vlan_mc_entry), M_VLAN, M_WAITOK);
163		bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
164		    (char *)&mc->mc_addr, ETHER_ADDR_LEN);
165		SLIST_INSERT_HEAD(&sc->vlan_mc_listhead, mc, mc_entries);
166		bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
167		    LLADDR(&sdl), ETHER_ADDR_LEN);
168		error = if_addmulti(ifp_p, (struct sockaddr *)&sdl, &rifma);
169		if (error)
170			return(error);
171	}
172
173	return(0);
174}
175
176static int
177vlan_modevent(module_t mod, int type, void *data)
178{
179	int err;
180
181	switch (type) {
182	case MOD_LOAD:
183		vlanunits->rm_type = RMAN_ARRAY;
184		vlanunits->rm_descr = "configurable if_vlan units";
185		err = rman_init(vlanunits);
186		if (err != 0)
187			return (err);
188		err = rman_manage_region(vlanunits, 0, VLAN_MAXUNIT);
189		if (err != 0) {
190			printf("%s: vlanunits: rman_manage_region: Failed %d\n",
191			    VLANNAME, err);
192			rman_fini(vlanunits);
193			return (err);
194		}
195		LIST_INIT(&ifv_list);
196		vlan_input_p = vlan_input;
197		vlan_input_tag_p = vlan_input_tag;
198		if_clone_attach(&vlan_cloner);
199		break;
200	case MOD_UNLOAD:
201		if_clone_detach(&vlan_cloner);
202		vlan_input_p = NULL;
203		vlan_input_tag_p = NULL;
204		while (!LIST_EMPTY(&ifv_list))
205			vlan_clone_destroy(&LIST_FIRST(&ifv_list)->ifv_if);
206		err = rman_fini(vlanunits);
207		if (err != 0)
208			 return (err);
209		break;
210	}
211	return 0;
212}
213
214static moduledata_t vlan_mod = {
215	"if_vlan",
216	vlan_modevent,
217	0
218};
219
220DECLARE_MODULE(if_vlan, vlan_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
221
222static int
223vlan_clone_create(struct if_clone *ifc, int *unit)
224{
225	struct resource *r;
226	struct ifvlan *ifv;
227	struct ifnet *ifp;
228	int s;
229
230	if (*unit > VLAN_MAXUNIT)
231		return (ENXIO);
232
233	if (*unit < 0) {
234		r  = rman_reserve_resource(vlanunits, 0, VLAN_MAXUNIT, 1,
235		    RF_ALLOCATED | RF_ACTIVE, NULL);
236		if (r == NULL)
237			return (ENOSPC);
238		*unit = rman_get_start(r);
239	} else {
240		r  = rman_reserve_resource(vlanunits, *unit, *unit, 1,
241		    RF_ALLOCATED | RF_ACTIVE, NULL);
242		if (r == NULL)
243			return (EEXIST);
244	}
245
246	ifv = malloc(sizeof(struct ifvlan), M_VLAN, M_WAITOK);
247	memset(ifv, 0, sizeof(struct ifvlan));
248	ifp = &ifv->ifv_if;
249	SLIST_INIT(&ifv->vlan_mc_listhead);
250
251	s = splnet();
252	LIST_INSERT_HEAD(&ifv_list, ifv, ifv_list);
253	splx(s);
254
255	ifp->if_softc = ifv;
256	ifp->if_name = "vlan";
257	ifp->if_unit = *unit;
258	ifv->r_unit = r;
259	/* NB: flags are not set here */
260	ifp->if_linkmib = &ifv->ifv_mib;
261	ifp->if_linkmiblen = sizeof ifv->ifv_mib;
262	/* NB: mtu is not set here */
263
264	ifp->if_init = vlan_ifinit;
265	ifp->if_start = vlan_start;
266	ifp->if_ioctl = vlan_ioctl;
267	ifp->if_output = ether_output;
268	ifp->if_snd.ifq_maxlen = ifqmaxlen;
269	ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
270	/* Now undo some of the damage... */
271	ifp->if_data.ifi_type = IFT_L2VLAN;
272	ifp->if_data.ifi_hdrlen = EVL_ENCAPLEN;
273
274	return (0);
275}
276
277static void
278vlan_clone_destroy(struct ifnet *ifp)
279{
280	struct ifvlan *ifv = ifp->if_softc;
281	int s;
282	int err;
283
284	s = splnet();
285	LIST_REMOVE(ifv, ifv_list);
286	vlan_unconfig(ifp);
287	splx(s);
288
289	ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
290
291	err = rman_release_resource(ifv->r_unit);
292	KASSERT(err == 0, ("Unexpected error freeing resource"));
293	free(ifv, M_VLAN);
294}
295
296static void
297vlan_ifinit(void *foo)
298{
299	return;
300}
301
302static void
303vlan_start(struct ifnet *ifp)
304{
305	struct ifvlan *ifv;
306	struct ifnet *p;
307	struct ether_vlan_header *evl;
308	struct mbuf *m;
309
310	ifv = ifp->if_softc;
311	p = ifv->ifv_p;
312
313	ifp->if_flags |= IFF_OACTIVE;
314	for (;;) {
315		IF_DEQUEUE(&ifp->if_snd, m);
316		if (m == 0)
317			break;
318		if (ifp->if_bpf)
319			bpf_mtap(ifp, m);
320
321		/*
322		 * Do not run parent's if_start() if the parent is not up,
323		 * or parent's driver will cause a system crash.
324		 */
325		if ((p->if_flags & (IFF_UP | IFF_RUNNING)) !=
326					(IFF_UP | IFF_RUNNING)) {
327			m_freem(m);
328			ifp->if_data.ifi_collisions++;
329			continue;
330		}
331
332		/*
333		 * If the LINK0 flag is set, it means the underlying interface
334		 * can do VLAN tag insertion itself and doesn't require us to
335	 	 * create a special header for it. In this case, we just pass
336		 * the packet along. However, we need some way to tell the
337		 * interface where the packet came from so that it knows how
338		 * to find the VLAN tag to use, so we set the rcvif in the
339		 * mbuf header to our ifnet.
340		 *
341		 * Note: we also set the M_PROTO1 flag in the mbuf to let
342		 * the parent driver know that the rcvif pointer is really
343		 * valid. We need to do this because sometimes mbufs will
344		 * be allocated by other parts of the system that contain
345		 * garbage in the rcvif pointer. Using the M_PROTO1 flag
346		 * lets the driver perform a proper sanity check and avoid
347		 * following potentially bogus rcvif pointers off into
348		 * never-never land.
349		 */
350		if (ifp->if_flags & IFF_LINK0) {
351			m->m_pkthdr.rcvif = ifp;
352			m->m_flags |= M_PROTO1;
353		} else {
354			M_PREPEND(m, EVL_ENCAPLEN, M_DONTWAIT);
355			if (m == NULL) {
356				printf("vlan%d: M_PREPEND failed", ifp->if_unit);
357				ifp->if_ierrors++;
358				continue;
359			}
360			/* M_PREPEND takes care of m_len, m_pkthdr.len for us */
361
362			m = m_pullup(m, ETHER_HDR_LEN + EVL_ENCAPLEN);
363			if (m == NULL) {
364				printf("vlan%d: m_pullup failed", ifp->if_unit);
365				ifp->if_ierrors++;
366				continue;
367			}
368
369			/*
370			 * Transform the Ethernet header into an Ethernet header
371			 * with 802.1Q encapsulation.
372			 */
373			bcopy(mtod(m, char *) + EVL_ENCAPLEN, mtod(m, char *),
374			      sizeof(struct ether_header));
375			evl = mtod(m, struct ether_vlan_header *);
376			evl->evl_proto = evl->evl_encap_proto;
377			evl->evl_encap_proto = htons(ETHERTYPE_VLAN);
378			evl->evl_tag = htons(ifv->ifv_tag);
379#ifdef DEBUG
380			printf("vlan_start: %*D\n", sizeof *evl,
381			    (unsigned char *)evl, ":");
382#endif
383		}
384
385		/*
386		 * Send it, precisely as ether_output() would have.
387		 * We are already running at splimp.
388		 */
389		if (IF_HANDOFF(&p->if_snd, m, p))
390			ifp->if_opackets++;
391		else
392			ifp->if_oerrors++;
393	}
394	ifp->if_flags &= ~IFF_OACTIVE;
395
396	return;
397}
398
399static int
400vlan_input_tag(struct ether_header *eh, struct mbuf *m, u_int16_t t)
401{
402	struct ifvlan *ifv;
403
404	for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
405	    ifv = LIST_NEXT(ifv, ifv_list)) {
406		if (ifv->ifv_tag == t)
407			break;
408	}
409
410	if (ifv !=NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
411		m_free(m);
412		return -1;	/* So the parent can take note */
413	}
414
415	/*
416	 * Having found a valid vlan interface corresponding to
417	 * the given source interface and vlan tag, run the
418	 * the real packet through ethert_input().
419	 */
420	m->m_pkthdr.rcvif = &ifv->ifv_if;
421
422	ifv->ifv_if.if_ipackets++;
423	ether_input(&ifv->ifv_if, eh, m);
424	return 0;
425}
426
427static int
428vlan_input(struct ether_header *eh, struct mbuf *m)
429{
430	struct ifvlan *ifv;
431
432	for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
433	    ifv = LIST_NEXT(ifv, ifv_list)) {
434		if (m->m_pkthdr.rcvif == ifv->ifv_p
435		    && (EVL_VLANOFTAG(ntohs(*mtod(m, u_int16_t *)))
436			== ifv->ifv_tag))
437			break;
438	}
439
440	if (ifv != NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
441		m_freem(m);
442		return -1;	/* so ether_input can take note */
443	}
444
445	/*
446	 * Having found a valid vlan interface corresponding to
447	 * the given source interface and vlan tag, remove the
448	 * encapsulation, and run the real packet through
449	 * ether_input() a second time (it had better be
450	 * reentrant!).
451	 */
452	m->m_pkthdr.rcvif = &ifv->ifv_if;
453	eh->ether_type = mtod(m, u_int16_t *)[1];
454	m->m_data += EVL_ENCAPLEN;
455	m->m_len -= EVL_ENCAPLEN;
456	m->m_pkthdr.len -= EVL_ENCAPLEN;
457
458	ifv->ifv_if.if_ipackets++;
459	ether_input(&ifv->ifv_if, eh, m);
460	return 0;
461}
462
463static int
464vlan_config(struct ifvlan *ifv, struct ifnet *p)
465{
466	struct ifaddr *ifa1, *ifa2;
467	struct sockaddr_dl *sdl1, *sdl2;
468
469	if (p->if_data.ifi_type != IFT_ETHER)
470		return EPROTONOSUPPORT;
471	if (ifv->ifv_p)
472		return EBUSY;
473	ifv->ifv_p = p;
474	if (p->if_data.ifi_hdrlen == sizeof(struct ether_vlan_header))
475		ifv->ifv_if.if_mtu = p->if_mtu;
476	else
477		ifv->ifv_if.if_mtu = p->if_data.ifi_mtu - EVL_ENCAPLEN;
478
479	/*
480	 * Copy only a selected subset of flags from the parent.
481	 * Other flags are none of our business.
482	 */
483	ifv->ifv_if.if_flags = (p->if_flags &
484	    (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT));
485
486	/*
487	 * Set up our ``Ethernet address'' to reflect the underlying
488	 * physical interface's.
489	 */
490	ifa1 = ifaddr_byindex(ifv->ifv_if.if_index);
491	ifa2 = ifaddr_byindex(p->if_index);
492	sdl1 = (struct sockaddr_dl *)ifa1->ifa_addr;
493	sdl2 = (struct sockaddr_dl *)ifa2->ifa_addr;
494	sdl1->sdl_type = IFT_ETHER;
495	sdl1->sdl_alen = ETHER_ADDR_LEN;
496	bcopy(LLADDR(sdl2), LLADDR(sdl1), ETHER_ADDR_LEN);
497	bcopy(LLADDR(sdl2), ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
498
499	/*
500	 * Configure multicast addresses that may already be
501	 * joined on the vlan device.
502	 */
503	(void)vlan_setmulti(&ifv->ifv_if);
504
505	return 0;
506}
507
508static int
509vlan_unconfig(struct ifnet *ifp)
510{
511	struct ifaddr *ifa;
512	struct sockaddr_dl *sdl;
513	struct vlan_mc_entry *mc;
514	struct ifvlan *ifv;
515	struct ifnet *p;
516	int error;
517
518	ifv = ifp->if_softc;
519	p = ifv->ifv_p;
520
521	if (p) {
522		struct sockaddr_dl sdl;
523
524		/*
525		 * Since the interface is being unconfigured, we need to
526		 * empty the list of multicast groups that we may have joined
527		 * while we were alive from the parent's list.
528		 */
529		bzero((char *)&sdl, sizeof sdl);
530		sdl.sdl_len = sizeof sdl;
531		sdl.sdl_family = AF_LINK;
532		sdl.sdl_index = p->if_index;
533		sdl.sdl_type = IFT_ETHER;
534		sdl.sdl_alen = ETHER_ADDR_LEN;
535
536		while(SLIST_FIRST(&ifv->vlan_mc_listhead) != NULL) {
537			mc = SLIST_FIRST(&ifv->vlan_mc_listhead);
538			bcopy((char *)&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
539			error = if_delmulti(p, (struct sockaddr *)&sdl);
540			if (error)
541				return(error);
542			SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries);
543			free(mc, M_VLAN);
544		}
545	}
546
547	/* Disconnect from parent. */
548	ifv->ifv_p = NULL;
549	ifv->ifv_if.if_mtu = ETHERMTU;
550
551	/* Clear our MAC address. */
552	ifa = ifaddr_byindex(ifv->ifv_if.if_index);
553	sdl = (struct sockaddr_dl *)ifa->ifa_addr;
554	sdl->sdl_type = IFT_ETHER;
555	sdl->sdl_alen = ETHER_ADDR_LEN;
556	bzero(LLADDR(sdl), ETHER_ADDR_LEN);
557	bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
558
559	return 0;
560}
561
562static int
563vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
564{
565	struct ifaddr *ifa;
566	struct ifnet *p;
567	struct ifreq *ifr;
568	struct ifvlan *ifv;
569	struct vlanreq vlr;
570	int error = 0;
571
572	ifr = (struct ifreq *)data;
573	ifa = (struct ifaddr *)data;
574	ifv = ifp->if_softc;
575
576	switch (cmd) {
577	case SIOCSIFADDR:
578		ifp->if_flags |= IFF_UP;
579
580		switch (ifa->ifa_addr->sa_family) {
581#ifdef INET
582		case AF_INET:
583			arp_ifinit(&ifv->ifv_ac, ifa);
584			break;
585#endif
586		default:
587			break;
588		}
589		break;
590
591	case SIOCGIFADDR:
592		{
593			struct sockaddr *sa;
594
595			sa = (struct sockaddr *) &ifr->ifr_data;
596			bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr,
597			      (caddr_t) sa->sa_data, ETHER_ADDR_LEN);
598		}
599		break;
600
601	case SIOCSIFMTU:
602		/*
603		 * Set the interface MTU.
604		 * This is bogus. The underlying interface might support
605	 	 * jumbo frames.
606		 */
607		if (ifr->ifr_mtu > ETHERMTU) {
608			error = EINVAL;
609		} else {
610			ifp->if_mtu = ifr->ifr_mtu;
611		}
612		break;
613
614	case SIOCSETVLAN:
615		error = copyin(ifr->ifr_data, &vlr, sizeof vlr);
616		if (error)
617			break;
618		if (vlr.vlr_parent[0] == '\0') {
619			vlan_unconfig(ifp);
620			if (ifp->if_flags & IFF_UP) {
621				int s = splimp();
622				if_down(ifp);
623				splx(s);
624			}
625			ifp->if_flags &= ~IFF_RUNNING;
626			break;
627		}
628		p = ifunit(vlr.vlr_parent);
629		if (p == 0) {
630			error = ENOENT;
631			break;
632		}
633		error = vlan_config(ifv, p);
634		if (error)
635			break;
636		ifv->ifv_tag = vlr.vlr_tag;
637		ifp->if_flags |= IFF_RUNNING;
638		break;
639
640	case SIOCGETVLAN:
641		bzero(&vlr, sizeof vlr);
642		if (ifv->ifv_p) {
643			snprintf(vlr.vlr_parent, sizeof(vlr.vlr_parent),
644			    "%s%d", ifv->ifv_p->if_name, ifv->ifv_p->if_unit);
645			vlr.vlr_tag = ifv->ifv_tag;
646		}
647		error = copyout(&vlr, ifr->ifr_data, sizeof vlr);
648		break;
649
650	case SIOCSIFFLAGS:
651		/*
652		 * We don't support promiscuous mode
653		 * right now because it would require help from the
654		 * underlying drivers, which hasn't been implemented.
655		 */
656		if (ifr->ifr_flags & (IFF_PROMISC)) {
657			ifp->if_flags &= ~(IFF_PROMISC);
658			error = EINVAL;
659		}
660		break;
661	case SIOCADDMULTI:
662	case SIOCDELMULTI:
663		error = vlan_setmulti(ifp);
664		break;
665	default:
666		error = EINVAL;
667	}
668	return error;
669}
670