2 * Copyright 1998 Massachusetts Institute of Technology
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
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
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.
46 #include <sys/param.h>
47 #include <sys/kernel.h>
48 #include <sys/malloc.h>
50 #include <sys/module.h>
51 #include <sys/queue.h>
52 #include <sys/socket.h>
53 #include <sys/sockio.h>
54 #include <sys/sysctl.h>
55 #include <sys/systm.h>
58 #include <net/ethernet.h>
60 #include <net/if_clone.h>
61 #include <net/if_arp.h>
62 #include <net/if_dl.h>
63 #include <net/if_types.h>
64 #include <net/if_vlan_var.h>
65 #include <net/route.h>
68 #include <netinet/in.h>
69 #include <netinet/if_ether.h>
72 #define VLANNAME "vlan"
74 struct vlan_mc_entry {
75 struct ether_addr mc_addr;
76 SLIST_ENTRY(vlan_mc_entry) mc_entries;
80 struct arpcom ifv_ac; /* make this an interface */
81 struct ifnet *ifv_p; /* parent inteface of this vlan */
84 int ifvm_encaplen; /* encapsulation length */
85 int ifvm_mtufudge; /* MTU fudged by this much */
86 int ifvm_mintu; /* min transmission unit */
87 u_int16_t ifvm_proto; /* encapsulation ethertype */
88 u_int16_t ifvm_tag; /* tag to apply on packets leaving if */
90 SLIST_HEAD(__vlan_mchead, vlan_mc_entry) vlan_mc_listhead;
91 LIST_ENTRY(ifvlan) ifv_list;
94 #define ifv_if ifv_ac.ac_if
95 #define ifv_tag ifv_mib.ifvm_tag
96 #define ifv_encaplen ifv_mib.ifvm_encaplen
97 #define ifv_mtufudge ifv_mib.ifvm_mtufudge
98 #define ifv_mintu ifv_mib.ifvm_mintu
100 #define IFVF_PROMISC 0x01 /* promiscuous mode enabled */
102 SYSCTL_DECL(_net_link);
103 SYSCTL_NODE(_net_link, IFT_L2VLAN, vlan, CTLFLAG_RW, 0, "IEEE 802.1Q VLAN");
104 SYSCTL_NODE(_net_link_vlan, PF_LINK, link, CTLFLAG_RW, 0, "for consistency");
106 static MALLOC_DEFINE(M_VLAN, VLANNAME, "802.1Q Virtual LAN Interface");
107 static LIST_HEAD(, ifvlan) ifv_list;
110 * Locking: one lock is used to guard both the ifv_list and modification
111 * to vlan data structures. We are rather conservative here; probably
112 * more than necessary.
114 static struct mtx ifv_mtx;
115 #define VLAN_LOCK_INIT() mtx_init(&ifv_mtx, VLANNAME, NULL, MTX_DEF)
116 #define VLAN_LOCK_DESTROY() mtx_destroy(&ifv_mtx)
117 #define VLAN_LOCK_ASSERT() mtx_assert(&ifv_mtx, MA_OWNED)
118 #define VLAN_LOCK() mtx_lock(&ifv_mtx)
119 #define VLAN_UNLOCK() mtx_unlock(&ifv_mtx)
121 static void vlan_start(struct ifnet *ifp);
122 static void vlan_ifinit(void *foo);
123 static void vlan_input(struct ifnet *ifp, struct mbuf *m);
124 static int vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t addr);
125 static int vlan_setmulti(struct ifnet *ifp);
126 static int vlan_unconfig(struct ifnet *ifp);
127 static int vlan_config(struct ifvlan *ifv, struct ifnet *p);
128 static void vlan_link_state(struct ifnet *ifp, int link);
129 static int vlan_set_promisc(struct ifnet *ifp);
131 static struct ifnet *vlan_clone_match_ethertag(struct if_clone *,
132 const char *, int *);
133 static int vlan_clone_match(struct if_clone *, const char *);
134 static int vlan_clone_create(struct if_clone *, char *, size_t);
135 static int vlan_clone_destroy(struct if_clone *, struct ifnet *);
137 struct if_clone vlan_cloner = IFC_CLONE_INITIALIZER(VLANNAME, NULL, IF_MAXUNIT,
138 NULL, vlan_clone_match, vlan_clone_create, vlan_clone_destroy);
141 * Program our multicast filter. What we're actually doing is
142 * programming the multicast filter of the parent. This has the
143 * side effect of causing the parent interface to receive multicast
144 * traffic that it doesn't really want, which ends up being discarded
145 * later by the upper protocol layers. Unfortunately, there's no way
146 * to avoid this: there really is only one physical interface.
148 * XXX: There is a possible race here if more than one thread is
149 * modifying the multicast state of the vlan interface at the same time.
152 vlan_setmulti(struct ifnet *ifp)
155 struct ifmultiaddr *ifma, *rifma = NULL;
157 struct vlan_mc_entry *mc = NULL;
158 struct sockaddr_dl sdl;
161 /*VLAN_LOCK_ASSERT();*/
163 /* Find the parent. */
168 * If we don't have a parent, just remember the membership for
174 bzero((char *)&sdl, sizeof(sdl));
175 sdl.sdl_len = sizeof(sdl);
176 sdl.sdl_family = AF_LINK;
177 sdl.sdl_index = ifp_p->if_index;
178 sdl.sdl_type = IFT_ETHER;
179 sdl.sdl_alen = ETHER_ADDR_LEN;
181 /* First, remove any existing filter entries. */
182 while (SLIST_FIRST(&sc->vlan_mc_listhead) != NULL) {
183 mc = SLIST_FIRST(&sc->vlan_mc_listhead);
184 bcopy((char *)&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
185 error = if_delmulti(ifp_p, (struct sockaddr *)&sdl);
188 SLIST_REMOVE_HEAD(&sc->vlan_mc_listhead, mc_entries);
192 /* Now program new ones. */
193 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
194 if (ifma->ifma_addr->sa_family != AF_LINK)
196 mc = malloc(sizeof(struct vlan_mc_entry), M_VLAN, M_NOWAIT);
199 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
200 (char *)&mc->mc_addr, ETHER_ADDR_LEN);
201 SLIST_INSERT_HEAD(&sc->vlan_mc_listhead, mc, mc_entries);
202 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
203 LLADDR(&sdl), ETHER_ADDR_LEN);
204 error = if_addmulti(ifp_p, (struct sockaddr *)&sdl, &rifma);
213 * VLAN support can be loaded as a module. The only place in the
214 * system that's intimately aware of this is ether_input. We hook
215 * into this code through vlan_input_p which is defined there and
216 * set here. Noone else in the system should be aware of this so
217 * we use an explicit reference here.
219 * NB: Noone should ever need to check if vlan_input_p is null or
220 * not. This is because interfaces have a count of the number
221 * of active vlans (if_nvlans) and this should never be bumped
222 * except by vlan_config--which is in this module so therefore
223 * the module must be loaded and vlan_input_p must be non-NULL.
225 extern void (*vlan_input_p)(struct ifnet *, struct mbuf *);
227 /* For MII eyes only... */
228 extern void (*vlan_link_state_p)(struct ifnet *, int);
231 vlan_modevent(module_t mod, int type, void *data)
236 LIST_INIT(&ifv_list);
238 vlan_input_p = vlan_input;
239 vlan_link_state_p = vlan_link_state;
240 if_clone_attach(&vlan_cloner);
243 if_clone_detach(&vlan_cloner);
245 vlan_link_state_p = NULL;
246 while (!LIST_EMPTY(&ifv_list))
247 vlan_clone_destroy(&vlan_cloner,
248 &LIST_FIRST(&ifv_list)->ifv_if);
257 static moduledata_t vlan_mod = {
263 DECLARE_MODULE(if_vlan, vlan_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
264 MODULE_DEPEND(if_vlan, miibus, 1, 1, 1);
266 static struct ifnet *
267 vlan_clone_match_ethertag(struct if_clone *ifc, const char *name, int *tag)
273 /* Check for <etherif>.<vlan> style interface names. */
275 TAILQ_FOREACH(ifp, &ifnet, if_link) {
276 if (ifp->if_type != IFT_ETHER)
278 if (strncmp(ifp->if_xname, name, strlen(ifp->if_xname)) != 0)
280 cp = name + strlen(ifp->if_xname);
283 for(; *cp != '\0'; cp++) {
284 if (*cp < '0' || *cp > '9')
286 t = (t * 10) + (*cp - '0');
298 vlan_clone_match(struct if_clone *ifc, const char *name)
302 if (vlan_clone_match_ethertag(ifc, name, NULL) != NULL)
305 if (strncmp(VLANNAME, name, strlen(VLANNAME)) != 0)
307 for (cp = name + 4; *cp != '\0'; cp++) {
308 if (*cp < '0' || *cp > '9')
316 vlan_clone_create(struct if_clone *ifc, char *name, size_t len)
328 if ((p = vlan_clone_match_ethertag(ifc, name, &tag)) != NULL) {
334 * Don't let the caller set up a VLAN tag with
335 * anything except VLID bits.
337 if (tag & ~EVL_VLID_MASK)
342 error = ifc_name2unit(name, &unit);
346 wildcard = (unit < 0);
349 error = ifc_alloc_unit(ifc, &unit);
353 /* In the wildcard case, we need to update the name. */
355 for (dp = name; *dp != '\0'; dp++);
356 if (snprintf(dp, len - (dp-name), "%d", unit) >
357 len - (dp-name) - 1) {
358 panic("%s: interface name too long", __func__);
362 ifv = malloc(sizeof(struct ifvlan), M_VLAN, M_WAITOK | M_ZERO);
364 SLIST_INIT(&ifv->vlan_mc_listhead);
368 * Set the name manually rather then using if_initname because
369 * we don't conform to the default naming convention for interfaces.
371 strlcpy(ifp->if_xname, name, IFNAMSIZ);
372 ifp->if_dname = ifc->ifc_name;
373 ifp->if_dunit = unit;
374 /* NB: flags are not set here */
375 ifp->if_linkmib = &ifv->ifv_mib;
376 ifp->if_linkmiblen = sizeof(ifv->ifv_mib);
377 /* NB: mtu is not set here */
379 ifp->if_init = vlan_ifinit;
380 ifp->if_start = vlan_start;
381 ifp->if_ioctl = vlan_ioctl;
382 ifp->if_snd.ifq_maxlen = ifqmaxlen;
383 ether_ifattach(ifp, ifv->ifv_ac.ac_enaddr);
384 /* Now undo some of the damage... */
385 ifp->if_baudrate = 0;
386 ifp->if_type = IFT_L2VLAN;
387 ifp->if_hdrlen = ETHER_VLAN_ENCAP_LEN;
390 LIST_INSERT_HEAD(&ifv_list, ifv, ifv_list);
395 error = vlan_config(ifv, p);
398 * Since we've partialy failed, we need to back
399 * out all the way, otherwise userland could get
400 * confused. Thus, we destroy the interface.
402 LIST_REMOVE(ifv, ifv_list);
411 ifp->if_flags |= IFF_RUNNING;
414 /* Update promiscuous mode, if necessary. */
415 vlan_set_promisc(ifp);
422 vlan_clone_destroy(struct if_clone *ifc, struct ifnet *ifp)
425 struct ifvlan *ifv = ifp->if_softc;
427 unit = ifp->if_dunit;
430 LIST_REMOVE(ifv, ifv_list);
438 ifc_free_unit(ifc, unit);
444 * The ifp->if_init entry point for vlan(4) is a no-op.
447 vlan_ifinit(void *foo)
453 vlan_start(struct ifnet *ifp)
457 struct ether_vlan_header *evl;
464 ifp->if_flags |= IFF_OACTIVE;
466 IF_DEQUEUE(&ifp->if_snd, m);
472 * Do not run parent's if_start() if the parent is not up,
473 * or parent's driver will cause a system crash.
475 if ((p->if_flags & (IFF_UP | IFF_RUNNING)) !=
476 (IFF_UP | IFF_RUNNING)) {
478 ifp->if_collisions++;
483 * If underlying interface can do VLAN tag insertion itself,
484 * just pass the packet along. However, we need some way to
485 * tell the interface where the packet came from so that it
486 * knows how to find the VLAN tag to use, so we attach a
487 * packet tag that holds it.
489 if (p->if_capenable & IFCAP_VLAN_HWTAGGING) {
490 struct m_tag *mtag = m_tag_alloc(MTAG_VLAN,
499 *(u_int*)(mtag + 1) = ifv->ifv_tag;
500 m_tag_prepend(m, mtag);
502 M_PREPEND(m, ifv->ifv_encaplen, M_DONTWAIT);
505 "unable to prepend VLAN header\n");
509 /* M_PREPEND takes care of m_len, m_pkthdr.len for us */
511 if (m->m_len < sizeof(*evl)) {
512 m = m_pullup(m, sizeof(*evl));
515 "cannot pullup VLAN header\n");
522 * Transform the Ethernet header into an Ethernet header
523 * with 802.1Q encapsulation.
525 bcopy(mtod(m, char *) + ifv->ifv_encaplen,
526 mtod(m, char *), ETHER_HDR_LEN);
527 evl = mtod(m, struct ether_vlan_header *);
528 evl->evl_proto = evl->evl_encap_proto;
529 evl->evl_encap_proto = htons(ETHERTYPE_VLAN);
530 evl->evl_tag = htons(ifv->ifv_tag);
532 printf("vlan_start: %*D\n", (int)sizeof(*evl),
533 (unsigned char *)evl, ":");
538 * Send it, precisely as ether_output() would have.
539 * We are already running at splimp.
541 IFQ_HANDOFF(p, m, error);
547 ifp->if_flags &= ~IFF_OACTIVE;
551 vlan_input(struct ifnet *ifp, struct mbuf *m)
553 struct ether_vlan_header *evl;
558 mtag = m_tag_locate(m, MTAG_VLAN, MTAG_VLAN_TAG, NULL);
561 * Packet is tagged, m contains a normal
562 * Ethernet frame; the tag is stored out-of-band.
564 tag = EVL_VLANOFTAG(VLAN_TAG_VALUE(mtag));
565 m_tag_delete(m, mtag);
567 switch (ifp->if_type) {
569 if (m->m_len < sizeof(*evl) &&
570 (m = m_pullup(m, sizeof(*evl))) == NULL) {
571 if_printf(ifp, "cannot pullup VLAN header\n");
574 evl = mtod(m, struct ether_vlan_header *);
575 KASSERT(ntohs(evl->evl_encap_proto) == ETHERTYPE_VLAN,
576 ("vlan_input: bad encapsulated protocols (%u)",
577 ntohs(evl->evl_encap_proto)));
579 tag = EVL_VLANOFTAG(ntohs(evl->evl_tag));
582 * Restore the original ethertype. We'll remove
583 * the encapsulation after we've found the vlan
584 * interface corresponding to the tag.
586 evl->evl_encap_proto = evl->evl_proto;
591 panic("vlan_input: unsupported if type %u",
599 LIST_FOREACH(ifv, &ifv_list, ifv_list)
600 if (ifp == ifv->ifv_p && tag == ifv->ifv_tag)
603 if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) {
608 printf("vlan_input: tag %d, no interface\n", tag);
612 VLAN_UNLOCK(); /* XXX extend below? */
614 printf("vlan_input: tag %d, parent %s\n", tag, ifv->ifv_p->if_xname);
619 * Packet had an in-line encapsulation header;
620 * remove it. The original header has already
621 * been fixed up above.
623 bcopy(mtod(m, caddr_t),
624 mtod(m, caddr_t) + ETHER_VLAN_ENCAP_LEN,
626 m_adj(m, ETHER_VLAN_ENCAP_LEN);
629 m->m_pkthdr.rcvif = &ifv->ifv_if;
630 ifv->ifv_if.if_ipackets++;
632 /* Pass it back through the parent's input routine. */
633 (*ifp->if_input)(&ifv->ifv_if, m);
637 vlan_config(struct ifvlan *ifv, struct ifnet *p)
639 struct ifaddr *ifa1, *ifa2;
640 struct sockaddr_dl *sdl1, *sdl2;
644 if (p->if_data.ifi_type != IFT_ETHER)
645 return (EPROTONOSUPPORT);
649 ifv->ifv_encaplen = ETHER_VLAN_ENCAP_LEN;
650 ifv->ifv_mintu = ETHERMIN;
654 * The active VLAN counter on the parent is used
655 * at various places to see if there is a vlan(4)
656 * attached to this physical interface.
661 * If the parent supports the VLAN_MTU capability,
662 * i.e. can Tx/Rx larger than ETHER_MAX_LEN frames,
665 if (p->if_capenable & IFCAP_VLAN_MTU) {
667 * No need to fudge the MTU since the parent can
668 * handle extended frames.
670 ifv->ifv_mtufudge = 0;
673 * Fudge the MTU by the encapsulation size. This
674 * makes us incompatible with strictly compliant
675 * 802.1Q implementations, but allows us to use
676 * the feature with other NetBSD implementations,
677 * which might still be useful.
679 ifv->ifv_mtufudge = ifv->ifv_encaplen;
683 ifv->ifv_if.if_mtu = p->if_mtu - ifv->ifv_mtufudge;
685 * Copy only a selected subset of flags from the parent.
686 * Other flags are none of our business.
688 ifv->ifv_if.if_flags = (p->if_flags &
689 (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT));
690 ifv->ifv_if.if_link_state = p->if_link_state;
694 * Not ready yet. We need notification from the parent
695 * when hw checksumming flags in its if_capenable change.
696 * Flags set in if_capabilities only are useless.
699 * If the parent interface can do hardware-assisted
700 * VLAN encapsulation, then propagate its hardware-
701 * assisted checksumming flags.
703 if (p->if_capabilities & IFCAP_VLAN_HWTAGGING)
704 ifv->ifv_if.if_capabilities |= p->if_capabilities & IFCAP_HWCSUM;
708 * Set up our ``Ethernet address'' to reflect the underlying
709 * physical interface's.
711 ifa1 = ifaddr_byindex(ifv->ifv_if.if_index);
712 ifa2 = ifaddr_byindex(p->if_index);
713 sdl1 = (struct sockaddr_dl *)ifa1->ifa_addr;
714 sdl2 = (struct sockaddr_dl *)ifa2->ifa_addr;
715 sdl1->sdl_type = IFT_ETHER;
716 sdl1->sdl_alen = ETHER_ADDR_LEN;
717 bcopy(LLADDR(sdl2), LLADDR(sdl1), ETHER_ADDR_LEN);
718 bcopy(LLADDR(sdl2), ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
721 * Configure multicast addresses that may already be
722 * joined on the vlan device.
724 (void)vlan_setmulti(&ifv->ifv_if); /* XXX: VLAN lock held */
730 vlan_unconfig(struct ifnet *ifp)
733 struct sockaddr_dl *sdl;
734 struct vlan_mc_entry *mc;
745 struct sockaddr_dl sdl;
748 * Since the interface is being unconfigured, we need to
749 * empty the list of multicast groups that we may have joined
750 * while we were alive from the parent's list.
752 bzero((char *)&sdl, sizeof(sdl));
753 sdl.sdl_len = sizeof(sdl);
754 sdl.sdl_family = AF_LINK;
755 sdl.sdl_index = p->if_index;
756 sdl.sdl_type = IFT_ETHER;
757 sdl.sdl_alen = ETHER_ADDR_LEN;
759 while(SLIST_FIRST(&ifv->vlan_mc_listhead) != NULL) {
760 mc = SLIST_FIRST(&ifv->vlan_mc_listhead);
761 bcopy((char *)&mc->mc_addr, LLADDR(&sdl),
763 error = if_delmulti(p, (struct sockaddr *)&sdl);
766 SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries);
773 /* Disconnect from parent. */
775 ifv->ifv_if.if_mtu = ETHERMTU; /* XXX why not 0? */
777 ifv->ifv_if.if_link_state = LINK_STATE_UNKNOWN;
779 /* Clear our MAC address. */
780 ifa = ifaddr_byindex(ifv->ifv_if.if_index);
781 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
782 sdl->sdl_type = IFT_ETHER;
783 sdl->sdl_alen = ETHER_ADDR_LEN;
784 bzero(LLADDR(sdl), ETHER_ADDR_LEN);
785 bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
791 vlan_set_promisc(struct ifnet *ifp)
793 struct ifvlan *ifv = ifp->if_softc;
796 if ((ifp->if_flags & IFF_PROMISC) != 0) {
797 if ((ifv->ifv_flags & IFVF_PROMISC) == 0) {
798 error = ifpromisc(ifv->ifv_p, 1);
800 ifv->ifv_flags |= IFVF_PROMISC;
803 if ((ifv->ifv_flags & IFVF_PROMISC) != 0) {
804 error = ifpromisc(ifv->ifv_p, 0);
806 ifv->ifv_flags &= ~IFVF_PROMISC;
813 /* Inform all vlans that their parent has changed link state */
815 vlan_link_state(struct ifnet *ifp, int link)
820 LIST_FOREACH(ifv, &ifv_list, ifv_list) {
821 if (ifv->ifv_p == ifp) {
822 ifv->ifv_if.if_link_state = ifv->ifv_p->if_link_state;
823 rt_ifmsg(&(ifv->ifv_if));
824 KNOTE_UNLOCKED(&ifp->if_klist, link);
831 vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
840 ifr = (struct ifreq *)data;
841 ifa = (struct ifaddr *)data;
846 ifp->if_flags |= IFF_UP;
848 switch (ifa->ifa_addr->sa_family) {
851 arp_ifinit(&ifv->ifv_if, ifa);
863 sa = (struct sockaddr *) &ifr->ifr_data;
864 bcopy(IFP2AC(ifp)->ac_enaddr, (caddr_t)sa->sa_data,
871 if (ifv->ifv_p != NULL) {
872 error = (*ifv->ifv_p->if_ioctl)(ifv->ifv_p,
875 /* Limit the result to the parent's current config. */
877 struct ifmediareq *ifmr;
879 ifmr = (struct ifmediareq *)data;
880 if (ifmr->ifm_count >= 1 && ifmr->ifm_ulist) {
882 error = copyout(&ifmr->ifm_current,
899 * Set the interface MTU.
902 if (ifv->ifv_p != NULL) {
904 (ifv->ifv_p->if_mtu - ifv->ifv_mtufudge) ||
906 (ifv->ifv_mintu - ifv->ifv_mtufudge))
909 ifp->if_mtu = ifr->ifr_mtu;
916 error = copyin(ifr->ifr_data, &vlr, sizeof(vlr));
919 if (vlr.vlr_parent[0] == '\0') {
922 if (ifp->if_flags & IFF_UP)
924 ifp->if_flags &= ~IFF_RUNNING;
928 p = ifunit(vlr.vlr_parent);
934 * Don't let the caller set up a VLAN tag with
935 * anything except VLID bits.
937 if (vlr.vlr_tag & ~EVL_VLID_MASK) {
942 error = vlan_config(ifv, p);
947 ifv->ifv_tag = vlr.vlr_tag;
948 ifp->if_flags |= IFF_RUNNING;
951 /* Update promiscuous mode, if necessary. */
952 vlan_set_promisc(ifp);
956 bzero(&vlr, sizeof(vlr));
959 strlcpy(vlr.vlr_parent, ifv->ifv_p->if_xname,
960 sizeof(vlr.vlr_parent));
961 vlr.vlr_tag = ifv->ifv_tag;
964 error = copyout(&vlr, ifr->ifr_data, sizeof(vlr));
969 * For promiscuous mode, we enable promiscuous mode on
970 * the parent if we need promiscuous on the VLAN interface.
972 if (ifv->ifv_p != NULL)
973 error = vlan_set_promisc(ifp);
979 error = vlan_setmulti(ifp);