if_vlan.c revision 84931
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 84931 2001-10-14 20:17:53Z fjoe $
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 (m->m_pkthdr.rcvif == ifv->ifv_p
407		    && ifv->ifv_tag == t)
408			break;
409	}
410
411	if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
412		m_free(m);
413		return -1;	/* So the parent can take note */
414	}
415
416	/*
417	 * Having found a valid vlan interface corresponding to
418	 * the given source interface and vlan tag, run the
419	 * the real packet through ether_input().
420	 */
421	m->m_pkthdr.rcvif = &ifv->ifv_if;
422
423	ifv->ifv_if.if_ipackets++;
424	ether_input(&ifv->ifv_if, eh, m);
425	return 0;
426}
427
428static int
429vlan_input(struct ether_header *eh, struct mbuf *m)
430{
431	struct ifvlan *ifv;
432
433	for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
434	    ifv = LIST_NEXT(ifv, ifv_list)) {
435		if (m->m_pkthdr.rcvif == ifv->ifv_p
436		    && (EVL_VLANOFTAG(ntohs(*mtod(m, u_int16_t *)))
437			== ifv->ifv_tag))
438			break;
439	}
440
441	if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
442		m_freem(m);
443		return -1;	/* so ether_input can take note */
444	}
445
446	/*
447	 * Having found a valid vlan interface corresponding to
448	 * the given source interface and vlan tag, remove the
449	 * encapsulation, and run the real packet through
450	 * ether_input() a second time (it had better be
451	 * reentrant!).
452	 */
453	m->m_pkthdr.rcvif = &ifv->ifv_if;
454	eh->ether_type = mtod(m, u_int16_t *)[1];
455	m->m_data += EVL_ENCAPLEN;
456	m->m_len -= EVL_ENCAPLEN;
457	m->m_pkthdr.len -= EVL_ENCAPLEN;
458
459	ifv->ifv_if.if_ipackets++;
460	ether_input(&ifv->ifv_if, eh, m);
461	return 0;
462}
463
464static int
465vlan_config(struct ifvlan *ifv, struct ifnet *p)
466{
467	struct ifaddr *ifa1, *ifa2;
468	struct sockaddr_dl *sdl1, *sdl2;
469
470	if (p->if_data.ifi_type != IFT_ETHER)
471		return EPROTONOSUPPORT;
472	if (ifv->ifv_p)
473		return EBUSY;
474	ifv->ifv_p = p;
475	if (p->if_data.ifi_hdrlen == sizeof(struct ether_vlan_header))
476		ifv->ifv_if.if_mtu = p->if_mtu;
477	else
478		ifv->ifv_if.if_mtu = p->if_data.ifi_mtu - EVL_ENCAPLEN;
479
480	/*
481	 * Copy only a selected subset of flags from the parent.
482	 * Other flags are none of our business.
483	 */
484	ifv->ifv_if.if_flags = (p->if_flags &
485	    (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT));
486
487	/*
488	 * Set up our ``Ethernet address'' to reflect the underlying
489	 * physical interface's.
490	 */
491	ifa1 = ifaddr_byindex(ifv->ifv_if.if_index);
492	ifa2 = ifaddr_byindex(p->if_index);
493	sdl1 = (struct sockaddr_dl *)ifa1->ifa_addr;
494	sdl2 = (struct sockaddr_dl *)ifa2->ifa_addr;
495	sdl1->sdl_type = IFT_ETHER;
496	sdl1->sdl_alen = ETHER_ADDR_LEN;
497	bcopy(LLADDR(sdl2), LLADDR(sdl1), ETHER_ADDR_LEN);
498	bcopy(LLADDR(sdl2), ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
499
500	/*
501	 * Configure multicast addresses that may already be
502	 * joined on the vlan device.
503	 */
504	(void)vlan_setmulti(&ifv->ifv_if);
505
506	return 0;
507}
508
509static int
510vlan_unconfig(struct ifnet *ifp)
511{
512	struct ifaddr *ifa;
513	struct sockaddr_dl *sdl;
514	struct vlan_mc_entry *mc;
515	struct ifvlan *ifv;
516	struct ifnet *p;
517	int error;
518
519	ifv = ifp->if_softc;
520	p = ifv->ifv_p;
521
522	if (p) {
523		struct sockaddr_dl sdl;
524
525		/*
526		 * Since the interface is being unconfigured, we need to
527		 * empty the list of multicast groups that we may have joined
528		 * while we were alive from the parent's list.
529		 */
530		bzero((char *)&sdl, sizeof sdl);
531		sdl.sdl_len = sizeof sdl;
532		sdl.sdl_family = AF_LINK;
533		sdl.sdl_index = p->if_index;
534		sdl.sdl_type = IFT_ETHER;
535		sdl.sdl_alen = ETHER_ADDR_LEN;
536
537		while(SLIST_FIRST(&ifv->vlan_mc_listhead) != NULL) {
538			mc = SLIST_FIRST(&ifv->vlan_mc_listhead);
539			bcopy((char *)&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
540			error = if_delmulti(p, (struct sockaddr *)&sdl);
541			if (error)
542				return(error);
543			SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries);
544			free(mc, M_VLAN);
545		}
546	}
547
548	/* Disconnect from parent. */
549	ifv->ifv_p = NULL;
550	ifv->ifv_if.if_mtu = ETHERMTU;
551
552	/* Clear our MAC address. */
553	ifa = ifaddr_byindex(ifv->ifv_if.if_index);
554	sdl = (struct sockaddr_dl *)ifa->ifa_addr;
555	sdl->sdl_type = IFT_ETHER;
556	sdl->sdl_alen = ETHER_ADDR_LEN;
557	bzero(LLADDR(sdl), ETHER_ADDR_LEN);
558	bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
559
560	return 0;
561}
562
563static int
564vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
565{
566	struct ifaddr *ifa;
567	struct ifnet *p;
568	struct ifreq *ifr;
569	struct ifvlan *ifv;
570	struct vlanreq vlr;
571	int error = 0;
572
573	ifr = (struct ifreq *)data;
574	ifa = (struct ifaddr *)data;
575	ifv = ifp->if_softc;
576
577	switch (cmd) {
578	case SIOCSIFADDR:
579		ifp->if_flags |= IFF_UP;
580
581		switch (ifa->ifa_addr->sa_family) {
582#ifdef INET
583		case AF_INET:
584			arp_ifinit(&ifv->ifv_if, ifa);
585			break;
586#endif
587		default:
588			break;
589		}
590		break;
591
592	case SIOCGIFADDR:
593		{
594			struct sockaddr *sa;
595
596			sa = (struct sockaddr *) &ifr->ifr_data;
597			bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr,
598			      (caddr_t) sa->sa_data, ETHER_ADDR_LEN);
599		}
600		break;
601
602	case SIOCSIFMTU:
603		/*
604		 * Set the interface MTU.
605		 * This is bogus. The underlying interface might support
606	 	 * jumbo frames.
607		 */
608		if (ifr->ifr_mtu > ETHERMTU) {
609			error = EINVAL;
610		} else {
611			ifp->if_mtu = ifr->ifr_mtu;
612		}
613		break;
614
615	case SIOCSETVLAN:
616		error = copyin(ifr->ifr_data, &vlr, sizeof vlr);
617		if (error)
618			break;
619		if (vlr.vlr_parent[0] == '\0') {
620			vlan_unconfig(ifp);
621			if (ifp->if_flags & IFF_UP) {
622				int s = splimp();
623				if_down(ifp);
624				splx(s);
625			}
626			ifp->if_flags &= ~IFF_RUNNING;
627			break;
628		}
629		p = ifunit(vlr.vlr_parent);
630		if (p == 0) {
631			error = ENOENT;
632			break;
633		}
634		error = vlan_config(ifv, p);
635		if (error)
636			break;
637		ifv->ifv_tag = vlr.vlr_tag;
638		ifp->if_flags |= IFF_RUNNING;
639		break;
640
641	case SIOCGETVLAN:
642		bzero(&vlr, sizeof vlr);
643		if (ifv->ifv_p) {
644			snprintf(vlr.vlr_parent, sizeof(vlr.vlr_parent),
645			    "%s%d", ifv->ifv_p->if_name, ifv->ifv_p->if_unit);
646			vlr.vlr_tag = ifv->ifv_tag;
647		}
648		error = copyout(&vlr, ifr->ifr_data, sizeof vlr);
649		break;
650
651	case SIOCSIFFLAGS:
652		/*
653		 * We don't support promiscuous mode
654		 * right now because it would require help from the
655		 * underlying drivers, which hasn't been implemented.
656		 */
657		if (ifr->ifr_flags & (IFF_PROMISC)) {
658			ifp->if_flags &= ~(IFF_PROMISC);
659			error = EINVAL;
660		}
661		break;
662	case SIOCADDMULTI:
663	case SIOCDELMULTI:
664		error = vlan_setmulti(ifp);
665		break;
666	default:
667		error = EINVAL;
668	}
669	return error;
670}
671