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