if_vlan.c revision 85005
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 85005 2001-10-15 19:21:01Z fenner $
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_baudrate = 0;
272	ifp->if_data.ifi_type = IFT_L2VLAN;
273	ifp->if_data.ifi_hdrlen = EVL_ENCAPLEN;
274
275	return (0);
276}
277
278static void
279vlan_clone_destroy(struct ifnet *ifp)
280{
281	struct ifvlan *ifv = ifp->if_softc;
282	int s;
283	int err;
284
285	s = splnet();
286	LIST_REMOVE(ifv, ifv_list);
287	vlan_unconfig(ifp);
288	splx(s);
289
290	ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
291
292	err = rman_release_resource(ifv->r_unit);
293	KASSERT(err == 0, ("Unexpected error freeing resource"));
294	free(ifv, M_VLAN);
295}
296
297static void
298vlan_ifinit(void *foo)
299{
300	return;
301}
302
303static void
304vlan_start(struct ifnet *ifp)
305{
306	struct ifvlan *ifv;
307	struct ifnet *p;
308	struct ether_vlan_header *evl;
309	struct mbuf *m;
310
311	ifv = ifp->if_softc;
312	p = ifv->ifv_p;
313
314	ifp->if_flags |= IFF_OACTIVE;
315	for (;;) {
316		IF_DEQUEUE(&ifp->if_snd, m);
317		if (m == 0)
318			break;
319		if (ifp->if_bpf)
320			bpf_mtap(ifp, m);
321
322		/*
323		 * Do not run parent's if_start() if the parent is not up,
324		 * or parent's driver will cause a system crash.
325		 */
326		if ((p->if_flags & (IFF_UP | IFF_RUNNING)) !=
327					(IFF_UP | IFF_RUNNING)) {
328			m_freem(m);
329			ifp->if_data.ifi_collisions++;
330			continue;
331		}
332
333		/*
334		 * If the LINK0 flag is set, it means the underlying interface
335		 * can do VLAN tag insertion itself and doesn't require us to
336	 	 * create a special header for it. In this case, we just pass
337		 * the packet along. However, we need some way to tell the
338		 * interface where the packet came from so that it knows how
339		 * to find the VLAN tag to use, so we set the rcvif in the
340		 * mbuf header to our ifnet.
341		 *
342		 * Note: we also set the M_PROTO1 flag in the mbuf to let
343		 * the parent driver know that the rcvif pointer is really
344		 * valid. We need to do this because sometimes mbufs will
345		 * be allocated by other parts of the system that contain
346		 * garbage in the rcvif pointer. Using the M_PROTO1 flag
347		 * lets the driver perform a proper sanity check and avoid
348		 * following potentially bogus rcvif pointers off into
349		 * never-never land.
350		 */
351		if (ifp->if_flags & IFF_LINK0) {
352			m->m_pkthdr.rcvif = ifp;
353			m->m_flags |= M_PROTO1;
354		} else {
355			M_PREPEND(m, EVL_ENCAPLEN, M_DONTWAIT);
356			if (m == NULL) {
357				printf("vlan%d: M_PREPEND failed", ifp->if_unit);
358				ifp->if_ierrors++;
359				continue;
360			}
361			/* M_PREPEND takes care of m_len, m_pkthdr.len for us */
362
363			m = m_pullup(m, ETHER_HDR_LEN + EVL_ENCAPLEN);
364			if (m == NULL) {
365				printf("vlan%d: m_pullup failed", ifp->if_unit);
366				ifp->if_ierrors++;
367				continue;
368			}
369
370			/*
371			 * Transform the Ethernet header into an Ethernet header
372			 * with 802.1Q encapsulation.
373			 */
374			bcopy(mtod(m, char *) + EVL_ENCAPLEN, mtod(m, char *),
375			      sizeof(struct ether_header));
376			evl = mtod(m, struct ether_vlan_header *);
377			evl->evl_proto = evl->evl_encap_proto;
378			evl->evl_encap_proto = htons(ETHERTYPE_VLAN);
379			evl->evl_tag = htons(ifv->ifv_tag);
380#ifdef DEBUG
381			printf("vlan_start: %*D\n", sizeof *evl,
382			    (unsigned char *)evl, ":");
383#endif
384		}
385
386		/*
387		 * Send it, precisely as ether_output() would have.
388		 * We are already running at splimp.
389		 */
390		if (IF_HANDOFF(&p->if_snd, m, p))
391			ifp->if_opackets++;
392		else
393			ifp->if_oerrors++;
394	}
395	ifp->if_flags &= ~IFF_OACTIVE;
396
397	return;
398}
399
400static int
401vlan_input_tag(struct ether_header *eh, struct mbuf *m, u_int16_t t)
402{
403	struct ifvlan *ifv;
404
405	for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
406	    ifv = LIST_NEXT(ifv, ifv_list)) {
407		if (m->m_pkthdr.rcvif == ifv->ifv_p
408		    && ifv->ifv_tag == t)
409			break;
410	}
411
412	if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
413		m_free(m);
414		return -1;	/* So the parent can take note */
415	}
416
417	/*
418	 * Having found a valid vlan interface corresponding to
419	 * the given source interface and vlan tag, run the
420	 * the real packet through ether_input().
421	 */
422	m->m_pkthdr.rcvif = &ifv->ifv_if;
423
424	ifv->ifv_if.if_ipackets++;
425	ether_input(&ifv->ifv_if, eh, m);
426	return 0;
427}
428
429static int
430vlan_input(struct ether_header *eh, struct mbuf *m)
431{
432	struct ifvlan *ifv;
433
434	for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
435	    ifv = LIST_NEXT(ifv, ifv_list)) {
436		if (m->m_pkthdr.rcvif == ifv->ifv_p
437		    && (EVL_VLANOFTAG(ntohs(*mtod(m, u_int16_t *)))
438			== ifv->ifv_tag))
439			break;
440	}
441
442	if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
443		m_freem(m);
444		return -1;	/* so ether_input can take note */
445	}
446
447	/*
448	 * Having found a valid vlan interface corresponding to
449	 * the given source interface and vlan tag, remove the
450	 * encapsulation, and run the real packet through
451	 * ether_input() a second time (it had better be
452	 * reentrant!).
453	 */
454	m->m_pkthdr.rcvif = &ifv->ifv_if;
455	eh->ether_type = mtod(m, u_int16_t *)[1];
456	m->m_data += EVL_ENCAPLEN;
457	m->m_len -= EVL_ENCAPLEN;
458	m->m_pkthdr.len -= EVL_ENCAPLEN;
459
460	ifv->ifv_if.if_ipackets++;
461	ether_input(&ifv->ifv_if, eh, m);
462	return 0;
463}
464
465static int
466vlan_config(struct ifvlan *ifv, struct ifnet *p)
467{
468	struct ifaddr *ifa1, *ifa2;
469	struct sockaddr_dl *sdl1, *sdl2;
470
471	if (p->if_data.ifi_type != IFT_ETHER)
472		return EPROTONOSUPPORT;
473	if (ifv->ifv_p)
474		return EBUSY;
475	ifv->ifv_p = p;
476	if (p->if_data.ifi_hdrlen == sizeof(struct ether_vlan_header))
477		ifv->ifv_if.if_mtu = p->if_mtu;
478	else
479		ifv->ifv_if.if_mtu = p->if_data.ifi_mtu - EVL_ENCAPLEN;
480
481	/*
482	 * Copy only a selected subset of flags from the parent.
483	 * Other flags are none of our business.
484	 */
485	ifv->ifv_if.if_flags = (p->if_flags &
486	    (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT));
487
488	/*
489	 * Set up our ``Ethernet address'' to reflect the underlying
490	 * physical interface's.
491	 */
492	ifa1 = ifaddr_byindex(ifv->ifv_if.if_index);
493	ifa2 = ifaddr_byindex(p->if_index);
494	sdl1 = (struct sockaddr_dl *)ifa1->ifa_addr;
495	sdl2 = (struct sockaddr_dl *)ifa2->ifa_addr;
496	sdl1->sdl_type = IFT_ETHER;
497	sdl1->sdl_alen = ETHER_ADDR_LEN;
498	bcopy(LLADDR(sdl2), LLADDR(sdl1), ETHER_ADDR_LEN);
499	bcopy(LLADDR(sdl2), ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
500
501	/*
502	 * Configure multicast addresses that may already be
503	 * joined on the vlan device.
504	 */
505	(void)vlan_setmulti(&ifv->ifv_if);
506
507	return 0;
508}
509
510static int
511vlan_unconfig(struct ifnet *ifp)
512{
513	struct ifaddr *ifa;
514	struct sockaddr_dl *sdl;
515	struct vlan_mc_entry *mc;
516	struct ifvlan *ifv;
517	struct ifnet *p;
518	int error;
519
520	ifv = ifp->if_softc;
521	p = ifv->ifv_p;
522
523	if (p) {
524		struct sockaddr_dl sdl;
525
526		/*
527		 * Since the interface is being unconfigured, we need to
528		 * empty the list of multicast groups that we may have joined
529		 * while we were alive from the parent's list.
530		 */
531		bzero((char *)&sdl, sizeof sdl);
532		sdl.sdl_len = sizeof sdl;
533		sdl.sdl_family = AF_LINK;
534		sdl.sdl_index = p->if_index;
535		sdl.sdl_type = IFT_ETHER;
536		sdl.sdl_alen = ETHER_ADDR_LEN;
537
538		while(SLIST_FIRST(&ifv->vlan_mc_listhead) != NULL) {
539			mc = SLIST_FIRST(&ifv->vlan_mc_listhead);
540			bcopy((char *)&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
541			error = if_delmulti(p, (struct sockaddr *)&sdl);
542			if (error)
543				return(error);
544			SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries);
545			free(mc, M_VLAN);
546		}
547	}
548
549	/* Disconnect from parent. */
550	ifv->ifv_p = NULL;
551	ifv->ifv_if.if_mtu = ETHERMTU;
552
553	/* Clear our MAC address. */
554	ifa = ifaddr_byindex(ifv->ifv_if.if_index);
555	sdl = (struct sockaddr_dl *)ifa->ifa_addr;
556	sdl->sdl_type = IFT_ETHER;
557	sdl->sdl_alen = ETHER_ADDR_LEN;
558	bzero(LLADDR(sdl), ETHER_ADDR_LEN);
559	bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
560
561	return 0;
562}
563
564static int
565vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
566{
567	struct ifaddr *ifa;
568	struct ifnet *p;
569	struct ifreq *ifr;
570	struct ifvlan *ifv;
571	struct vlanreq vlr;
572	int error = 0;
573
574	ifr = (struct ifreq *)data;
575	ifa = (struct ifaddr *)data;
576	ifv = ifp->if_softc;
577
578	switch (cmd) {
579	case SIOCSIFADDR:
580		ifp->if_flags |= IFF_UP;
581
582		switch (ifa->ifa_addr->sa_family) {
583#ifdef INET
584		case AF_INET:
585			arp_ifinit(&ifv->ifv_if, ifa);
586			break;
587#endif
588		default:
589			break;
590		}
591		break;
592
593	case SIOCGIFADDR:
594		{
595			struct sockaddr *sa;
596
597			sa = (struct sockaddr *) &ifr->ifr_data;
598			bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr,
599			      (caddr_t) sa->sa_data, ETHER_ADDR_LEN);
600		}
601		break;
602
603	case SIOCSIFMTU:
604		/*
605		 * Set the interface MTU.
606		 * This is bogus. The underlying interface might support
607	 	 * jumbo frames.
608		 */
609		if (ifr->ifr_mtu > ETHERMTU) {
610			error = EINVAL;
611		} else {
612			ifp->if_mtu = ifr->ifr_mtu;
613		}
614		break;
615
616	case SIOCSETVLAN:
617		error = copyin(ifr->ifr_data, &vlr, sizeof vlr);
618		if (error)
619			break;
620		if (vlr.vlr_parent[0] == '\0') {
621			vlan_unconfig(ifp);
622			if (ifp->if_flags & IFF_UP) {
623				int s = splimp();
624				if_down(ifp);
625				splx(s);
626			}
627			ifp->if_flags &= ~IFF_RUNNING;
628			break;
629		}
630		p = ifunit(vlr.vlr_parent);
631		if (p == 0) {
632			error = ENOENT;
633			break;
634		}
635		error = vlan_config(ifv, p);
636		if (error)
637			break;
638		ifv->ifv_tag = vlr.vlr_tag;
639		ifp->if_flags |= IFF_RUNNING;
640		break;
641
642	case SIOCGETVLAN:
643		bzero(&vlr, sizeof vlr);
644		if (ifv->ifv_p) {
645			snprintf(vlr.vlr_parent, sizeof(vlr.vlr_parent),
646			    "%s%d", ifv->ifv_p->if_name, ifv->ifv_p->if_unit);
647			vlr.vlr_tag = ifv->ifv_tag;
648		}
649		error = copyout(&vlr, ifr->ifr_data, sizeof vlr);
650		break;
651
652	case SIOCSIFFLAGS:
653		/*
654		 * We don't support promiscuous mode
655		 * right now because it would require help from the
656		 * underlying drivers, which hasn't been implemented.
657		 */
658		if (ifr->ifr_flags & (IFF_PROMISC)) {
659			ifp->if_flags &= ~(IFF_PROMISC);
660			error = EINVAL;
661		}
662		break;
663	case SIOCADDMULTI:
664	case SIOCDELMULTI:
665		error = vlan_setmulti(ifp);
666		break;
667	default:
668		error = EINVAL;
669	}
670	return error;
671}
672