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