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