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>
67 #include <netinet/in.h>
68 #include <netinet/if_ether.h>
71 #define VLANNAME "vlan"
73 struct vlan_mc_entry {
74 struct ether_addr mc_addr;
75 SLIST_ENTRY(vlan_mc_entry) mc_entries;
79 struct ifnet *ifv_ifp;
80 struct ifnet *ifv_p; /* parent inteface of this vlan */
81 int ifv_pflags; /* special flags we have set on parent */
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;
93 #define ifv_tag ifv_mib.ifvm_tag
94 #define ifv_encaplen ifv_mib.ifvm_encaplen
95 #define ifv_mtufudge ifv_mib.ifvm_mtufudge
96 #define ifv_mintu ifv_mib.ifvm_mintu
98 /* Special flags we should propagate to parent */
101 int (*func)(struct ifnet *, int);
103 {IFF_PROMISC, ifpromisc},
104 {IFF_ALLMULTI, if_allmulti},
108 SYSCTL_DECL(_net_link);
109 SYSCTL_NODE(_net_link, IFT_L2VLAN, vlan, CTLFLAG_RW, 0, "IEEE 802.1Q VLAN");
110 SYSCTL_NODE(_net_link_vlan, PF_LINK, link, CTLFLAG_RW, 0, "for consistency");
112 static MALLOC_DEFINE(M_VLAN, VLANNAME, "802.1Q Virtual LAN Interface");
113 static LIST_HEAD(, ifvlan) ifv_list;
116 * Locking: one lock is used to guard both the ifv_list and modification
117 * to vlan data structures. We are rather conservative here; probably
118 * more than necessary.
120 static struct mtx ifv_mtx;
121 #define VLAN_LOCK_INIT() mtx_init(&ifv_mtx, VLANNAME, NULL, MTX_DEF)
122 #define VLAN_LOCK_DESTROY() mtx_destroy(&ifv_mtx)
123 #define VLAN_LOCK_ASSERT() mtx_assert(&ifv_mtx, MA_OWNED)
124 #define VLAN_LOCK() mtx_lock(&ifv_mtx)
125 #define VLAN_UNLOCK() mtx_unlock(&ifv_mtx)
127 static void vlan_start(struct ifnet *ifp);
128 static void vlan_ifinit(void *foo);
129 static void vlan_input(struct ifnet *ifp, struct mbuf *m);
130 static int vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t addr);
131 static int vlan_setflag(struct ifnet *ifp, int flag, int status,
132 int (*func)(struct ifnet *, int));
133 static int vlan_setflags(struct ifnet *ifp, int status);
134 static int vlan_setmulti(struct ifnet *ifp);
135 static int vlan_unconfig(struct ifnet *ifp);
136 static int vlan_config(struct ifvlan *ifv, struct ifnet *p);
137 static void vlan_link_state(struct ifnet *ifp, int link);
139 static struct ifnet *vlan_clone_match_ethertag(struct if_clone *,
140 const char *, int *);
141 static int vlan_clone_match(struct if_clone *, const char *);
142 static int vlan_clone_create(struct if_clone *, char *, size_t);
143 static int vlan_clone_destroy(struct if_clone *, struct ifnet *);
145 static struct if_clone vlan_cloner = IFC_CLONE_INITIALIZER(VLANNAME, NULL,
146 IF_MAXUNIT, NULL, vlan_clone_match, vlan_clone_create, vlan_clone_destroy);
149 * Program our multicast filter. What we're actually doing is
150 * programming the multicast filter of the parent. This has the
151 * side effect of causing the parent interface to receive multicast
152 * traffic that it doesn't really want, which ends up being discarded
153 * later by the upper protocol layers. Unfortunately, there's no way
154 * to avoid this: there really is only one physical interface.
156 * XXX: There is a possible race here if more than one thread is
157 * modifying the multicast state of the vlan interface at the same time.
160 vlan_setmulti(struct ifnet *ifp)
163 struct ifmultiaddr *ifma, *rifma = NULL;
165 struct vlan_mc_entry *mc = NULL;
166 struct sockaddr_dl sdl;
169 /*VLAN_LOCK_ASSERT();*/
171 /* Find the parent. */
176 * If we don't have a parent, just remember the membership for
182 bzero((char *)&sdl, sizeof(sdl));
183 sdl.sdl_len = sizeof(sdl);
184 sdl.sdl_family = AF_LINK;
185 sdl.sdl_index = ifp_p->if_index;
186 sdl.sdl_type = IFT_ETHER;
187 sdl.sdl_alen = ETHER_ADDR_LEN;
189 /* First, remove any existing filter entries. */
190 while (SLIST_FIRST(&sc->vlan_mc_listhead) != NULL) {
191 mc = SLIST_FIRST(&sc->vlan_mc_listhead);
192 bcopy((char *)&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
193 error = if_delmulti(ifp_p, (struct sockaddr *)&sdl);
196 SLIST_REMOVE_HEAD(&sc->vlan_mc_listhead, mc_entries);
200 /* Now program new ones. */
201 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
202 if (ifma->ifma_addr->sa_family != AF_LINK)
204 mc = malloc(sizeof(struct vlan_mc_entry), M_VLAN, M_NOWAIT);
207 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
208 (char *)&mc->mc_addr, ETHER_ADDR_LEN);
209 SLIST_INSERT_HEAD(&sc->vlan_mc_listhead, mc, mc_entries);
210 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
211 LLADDR(&sdl), ETHER_ADDR_LEN);
212 error = if_addmulti(ifp_p, (struct sockaddr *)&sdl, &rifma);
221 * VLAN support can be loaded as a module. The only place in the
222 * system that's intimately aware of this is ether_input. We hook
223 * into this code through vlan_input_p which is defined there and
224 * set here. Noone else in the system should be aware of this so
225 * we use an explicit reference here.
227 * NB: Noone should ever need to check if vlan_input_p is null or
228 * not. This is because interfaces have a count of the number
229 * of active vlans (if_nvlans) and this should never be bumped
230 * except by vlan_config--which is in this module so therefore
231 * the module must be loaded and vlan_input_p must be non-NULL.
233 extern void (*vlan_input_p)(struct ifnet *, struct mbuf *);
235 /* For if_link_state_change() eyes only... */
236 extern void (*vlan_link_state_p)(struct ifnet *, int);
239 vlan_modevent(module_t mod, int type, void *data)
244 LIST_INIT(&ifv_list);
246 vlan_input_p = vlan_input;
247 vlan_link_state_p = vlan_link_state;
248 if_clone_attach(&vlan_cloner);
251 if_clone_detach(&vlan_cloner);
253 vlan_link_state_p = NULL;
262 static moduledata_t vlan_mod = {
268 DECLARE_MODULE(if_vlan, vlan_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
269 MODULE_DEPEND(if_vlan, miibus, 1, 1, 1);
271 static struct ifnet *
272 vlan_clone_match_ethertag(struct if_clone *ifc, const char *name, int *tag)
278 /* Check for <etherif>.<vlan> style interface names. */
280 TAILQ_FOREACH(ifp, &ifnet, if_link) {
281 if (ifp->if_type != IFT_ETHER)
283 if (strncmp(ifp->if_xname, name, strlen(ifp->if_xname)) != 0)
285 cp = name + strlen(ifp->if_xname);
288 for(; *cp != '\0'; cp++) {
289 if (*cp < '0' || *cp > '9')
291 t = (t * 10) + (*cp - '0');
303 vlan_clone_match(struct if_clone *ifc, const char *name)
307 if (vlan_clone_match_ethertag(ifc, name, NULL) != NULL)
310 if (strncmp(VLANNAME, name, strlen(VLANNAME)) != 0)
312 for (cp = name + 4; *cp != '\0'; cp++) {
313 if (*cp < '0' || *cp > '9')
321 vlan_clone_create(struct if_clone *ifc, char *name, size_t len)
332 u_char eaddr[6] = {0,0,0,0,0,0};
334 if ((p = vlan_clone_match_ethertag(ifc, name, &tag)) != NULL) {
340 * Don't let the caller set up a VLAN tag with
341 * anything except VLID bits.
343 if (tag & ~EVL_VLID_MASK)
348 error = ifc_name2unit(name, &unit);
352 wildcard = (unit < 0);
355 error = ifc_alloc_unit(ifc, &unit);
359 /* In the wildcard case, we need to update the name. */
361 for (dp = name; *dp != '\0'; dp++);
362 if (snprintf(dp, len - (dp-name), "%d", unit) >
363 len - (dp-name) - 1) {
364 panic("%s: interface name too long", __func__);
368 ifv = malloc(sizeof(struct ifvlan), M_VLAN, M_WAITOK | M_ZERO);
369 ifp = ifv->ifv_ifp = if_alloc(IFT_ETHER);
371 ifc_free_unit(ifc, unit);
375 SLIST_INIT(&ifv->vlan_mc_listhead);
379 * Set the name manually rather than using if_initname because
380 * we don't conform to the default naming convention for interfaces.
382 strlcpy(ifp->if_xname, name, IFNAMSIZ);
383 ifp->if_dname = ifc->ifc_name;
384 ifp->if_dunit = unit;
385 /* NB: flags are not set here */
386 ifp->if_linkmib = &ifv->ifv_mib;
387 ifp->if_linkmiblen = sizeof(ifv->ifv_mib);
388 /* NB: mtu is not set here */
390 ifp->if_init = vlan_ifinit;
391 ifp->if_start = vlan_start;
392 ifp->if_ioctl = vlan_ioctl;
393 ifp->if_snd.ifq_maxlen = ifqmaxlen;
394 ether_ifattach(ifp, eaddr);
395 /* Now undo some of the damage... */
396 ifp->if_baudrate = 0;
397 ifp->if_type = IFT_L2VLAN;
398 ifp->if_hdrlen = ETHER_VLAN_ENCAP_LEN;
401 LIST_INSERT_HEAD(&ifv_list, ifv, ifv_list);
406 error = vlan_config(ifv, p);
409 * Since we've partialy failed, we need to back
410 * out all the way, otherwise userland could get
411 * confused. Thus, we destroy the interface.
413 LIST_REMOVE(ifv, ifv_list);
417 if_free_type(ifp, IFT_ETHER);
423 ifp->if_drv_flags |= IFF_DRV_RUNNING;
426 /* Update flags on the parent, if necessary. */
427 vlan_setflags(ifp, 1);
434 vlan_clone_destroy(struct if_clone *ifc, struct ifnet *ifp)
437 struct ifvlan *ifv = ifp->if_softc;
439 unit = ifp->if_dunit;
442 LIST_REMOVE(ifv, ifv_list);
447 if_free_type(ifp, IFT_ETHER);
451 ifc_free_unit(ifc, unit);
457 * The ifp->if_init entry point for vlan(4) is a no-op.
460 vlan_ifinit(void *foo)
466 * The if_start method for vlan(4) interface. It doesn't
467 * raises the IFF_DRV_OACTIVE flag, since it is called
468 * only from IFQ_HANDOFF() macro in ether_output_frame().
469 * If the interface queue is full, and vlan_start() is
470 * not called, the queue would never get emptied and
471 * interface would stall forever.
474 vlan_start(struct ifnet *ifp)
478 struct ether_vlan_header *evl;
486 IF_DEQUEUE(&ifp->if_snd, m);
492 * Do not run parent's if_start() if the parent is not up,
493 * or parent's driver will cause a system crash.
495 if (!((p->if_flags & IFF_UP) &&
496 (p->if_drv_flags & IFF_DRV_RUNNING))) {
498 ifp->if_collisions++;
503 * If underlying interface can do VLAN tag insertion itself,
504 * just pass the packet along. However, we need some way to
505 * tell the interface where the packet came from so that it
506 * knows how to find the VLAN tag to use, so we attach a
507 * packet tag that holds it.
509 if (p->if_capenable & IFCAP_VLAN_HWTAGGING) {
510 struct m_tag *mtag = m_tag_alloc(MTAG_VLAN,
519 VLAN_TAG_VALUE(mtag) = ifv->ifv_tag;
520 m_tag_prepend(m, mtag);
521 m->m_flags |= M_VLANTAG;
523 M_PREPEND(m, ifv->ifv_encaplen, M_DONTWAIT);
526 "unable to prepend VLAN header\n");
530 /* M_PREPEND takes care of m_len, m_pkthdr.len for us */
532 if (m->m_len < sizeof(*evl)) {
533 m = m_pullup(m, sizeof(*evl));
536 "cannot pullup VLAN header\n");
543 * Transform the Ethernet header into an Ethernet header
544 * with 802.1Q encapsulation.
546 bcopy(mtod(m, char *) + ifv->ifv_encaplen,
547 mtod(m, char *), ETHER_HDR_LEN);
548 evl = mtod(m, struct ether_vlan_header *);
549 evl->evl_proto = evl->evl_encap_proto;
550 evl->evl_encap_proto = htons(ETHERTYPE_VLAN);
551 evl->evl_tag = htons(ifv->ifv_tag);
553 printf("%s: %*D\n", __func__, (int)sizeof(*evl),
554 (unsigned char *)evl, ":");
559 * Send it, precisely as ether_output() would have.
560 * We are already running at splimp.
562 IFQ_HANDOFF(p, m, error);
571 vlan_input(struct ifnet *ifp, struct mbuf *m)
573 struct ether_vlan_header *evl;
578 if (m->m_flags & M_VLANTAG) {
580 * Packet is tagged, but m contains a normal
581 * Ethernet frame; the tag is stored out-of-band.
583 mtag = m_tag_locate(m, MTAG_VLAN, MTAG_VLAN_TAG, NULL);
584 KASSERT(mtag != NULL,
585 ("%s: M_VLANTAG without m_tag", __func__));
586 tag = EVL_VLANOFTAG(VLAN_TAG_VALUE(mtag));
587 m_tag_delete(m, mtag);
588 m->m_flags &= ~M_VLANTAG;
591 * Packet is tagged in-band as specified by 802.1q.
594 switch (ifp->if_type) {
596 if (m->m_len < sizeof(*evl) &&
597 (m = m_pullup(m, sizeof(*evl))) == NULL) {
598 if_printf(ifp, "cannot pullup VLAN header\n");
601 evl = mtod(m, struct ether_vlan_header *);
602 KASSERT(ntohs(evl->evl_encap_proto) == ETHERTYPE_VLAN,
603 ("%s: bad encapsulation protocol (%u)",
604 __func__, ntohs(evl->evl_encap_proto)));
606 tag = EVL_VLANOFTAG(ntohs(evl->evl_tag));
609 * Restore the original ethertype. We'll remove
610 * the encapsulation after we've found the vlan
611 * interface corresponding to the tag.
613 evl->evl_encap_proto = evl->evl_proto;
618 panic("%s: unsupported if_type (%u)",
619 __func__, ifp->if_type);
626 LIST_FOREACH(ifv, &ifv_list, ifv_list)
627 if (ifp == ifv->ifv_p && tag == ifv->ifv_tag)
630 if (ifv == NULL || (ifv->ifv_ifp->if_flags & IFF_UP) == 0) {
635 printf("%s: tag %d, no interface\n", __func__, tag);
639 VLAN_UNLOCK(); /* XXX extend below? */
641 printf("%s: tag %d, parent %s\n", __func__, tag, ifv->ifv_p->if_xname);
646 * Packet had an in-line encapsulation header;
647 * remove it. The original header has already
648 * been fixed up above.
650 bcopy(mtod(m, caddr_t),
651 mtod(m, caddr_t) + ETHER_VLAN_ENCAP_LEN,
653 m_adj(m, ETHER_VLAN_ENCAP_LEN);
656 m->m_pkthdr.rcvif = ifv->ifv_ifp;
657 ifv->ifv_ifp->if_ipackets++;
659 /* Pass it back through the parent's input routine. */
660 (*ifp->if_input)(ifv->ifv_ifp, m);
664 vlan_config(struct ifvlan *ifv, struct ifnet *p)
670 if (p->if_type != IFT_ETHER)
671 return (EPROTONOSUPPORT);
675 ifv->ifv_encaplen = ETHER_VLAN_ENCAP_LEN;
676 ifv->ifv_mintu = ETHERMIN;
680 * The active VLAN counter on the parent is used
681 * at various places to see if there is a vlan(4)
682 * attached to this physical interface.
687 * If the parent supports the VLAN_MTU capability,
688 * i.e. can Tx/Rx larger than ETHER_MAX_LEN frames,
691 if (p->if_capenable & IFCAP_VLAN_MTU) {
693 * No need to fudge the MTU since the parent can
694 * handle extended frames.
696 ifv->ifv_mtufudge = 0;
699 * Fudge the MTU by the encapsulation size. This
700 * makes us incompatible with strictly compliant
701 * 802.1Q implementations, but allows us to use
702 * the feature with other NetBSD implementations,
703 * which might still be useful.
705 ifv->ifv_mtufudge = ifv->ifv_encaplen;
710 ifp->if_mtu = p->if_mtu - ifv->ifv_mtufudge;
711 ifv->ifv_ifp->if_baudrate = p->if_baudrate;
713 * Copy only a selected subset of flags from the parent.
714 * Other flags are none of our business.
716 #define VLAN_COPY_FLAGS \
717 (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT)
718 ifp->if_flags &= ~VLAN_COPY_FLAGS;
719 ifp->if_flags |= p->if_flags & VLAN_COPY_FLAGS;
720 #undef VLAN_COPY_FLAGS
722 ifp->if_link_state = p->if_link_state;
726 * Not ready yet. We need notification from the parent
727 * when hw checksumming flags in its if_capenable change.
728 * Flags set in if_capabilities only are useless.
731 * If the parent interface can do hardware-assisted
732 * VLAN encapsulation, then propagate its hardware-
733 * assisted checksumming flags.
735 if (p->if_capabilities & IFCAP_VLAN_HWTAGGING)
736 ifp->if_capabilities |= p->if_capabilities & IFCAP_HWCSUM;
740 * Set up our ``Ethernet address'' to reflect the underlying
741 * physical interface's.
743 bcopy(IF_LLADDR(p), IF_LLADDR(ifp), ETHER_ADDR_LEN);
746 * Configure multicast addresses that may already be
747 * joined on the vlan device.
749 (void)vlan_setmulti(ifp); /* XXX: VLAN lock held */
755 vlan_unconfig(struct ifnet *ifp)
757 struct vlan_mc_entry *mc;
768 struct sockaddr_dl sdl;
771 * Since the interface is being unconfigured, we need to
772 * empty the list of multicast groups that we may have joined
773 * while we were alive from the parent's list.
775 bzero((char *)&sdl, sizeof(sdl));
776 sdl.sdl_len = sizeof(sdl);
777 sdl.sdl_family = AF_LINK;
778 sdl.sdl_index = p->if_index;
779 sdl.sdl_type = IFT_ETHER;
780 sdl.sdl_alen = ETHER_ADDR_LEN;
782 while(SLIST_FIRST(&ifv->vlan_mc_listhead) != NULL) {
783 mc = SLIST_FIRST(&ifv->vlan_mc_listhead);
784 bcopy((char *)&mc->mc_addr, LLADDR(&sdl),
786 error = if_delmulti(p, (struct sockaddr *)&sdl);
789 SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries);
793 vlan_setflags(ifp, 0); /* clear special flags on parent */
797 /* Disconnect from parent. */
799 if_printf(ifp, "%s: ifv_pflags unclean\n", __func__);
801 ifv->ifv_ifp->if_mtu = ETHERMTU; /* XXX why not 0? */
802 ifv->ifv_ifp->if_link_state = LINK_STATE_UNKNOWN;
804 /* Clear our MAC address. */
805 bzero(IF_LLADDR(ifv->ifv_ifp), ETHER_ADDR_LEN);
810 /* Handle a reference counted flag that should be set on the parent as well */
812 vlan_setflag(struct ifnet *ifp, int flag, int status,
813 int (*func)(struct ifnet *, int))
818 /* XXX VLAN_LOCK_ASSERT(); */
821 status = status ? (ifp->if_flags & flag) : 0;
822 /* Now "status" contains the flag value or 0 */
825 * See if recorded parent's status is different from what
826 * we want it to be. If it is, flip it. We record parent's
827 * status in ifv_pflags so that we won't clear parent's flag
828 * we haven't set. In fact, we don't clear or set parent's
829 * flags directly, but get or release references to them.
830 * That's why we can be sure that recorded flags still are
831 * in accord with actual parent's flags.
833 if (status != (ifv->ifv_pflags & flag)) {
834 error = (*func)(ifv->ifv_p, status);
837 ifv->ifv_pflags &= ~flag;
838 ifv->ifv_pflags |= status;
844 * Handle IFF_* flags that require certain changes on the parent:
845 * if "status" is true, update parent's flags respective to our if_flags;
846 * if "status" is false, forcedly clear the flags set on parent.
849 vlan_setflags(struct ifnet *ifp, int status)
853 for (i = 0; vlan_pflags[i].flag; i++) {
854 error = vlan_setflag(ifp, vlan_pflags[i].flag,
855 status, vlan_pflags[i].func);
862 /* Inform all vlans that their parent has changed link state */
864 vlan_link_state(struct ifnet *ifp, int link)
869 LIST_FOREACH(ifv, &ifv_list, ifv_list) {
870 if (ifv->ifv_p == ifp)
871 if_link_state_change(ifv->ifv_ifp,
872 ifv->ifv_p->if_link_state);
878 vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
887 ifr = (struct ifreq *)data;
888 ifa = (struct ifaddr *)data;
893 ifp->if_flags |= IFF_UP;
895 switch (ifa->ifa_addr->sa_family) {
898 arp_ifinit(ifv->ifv_ifp, ifa);
910 sa = (struct sockaddr *) &ifr->ifr_data;
911 bcopy(IF_LLADDR(ifp), (caddr_t)sa->sa_data,
918 if (ifv->ifv_p != NULL) {
919 error = (*ifv->ifv_p->if_ioctl)(ifv->ifv_p,
922 /* Limit the result to the parent's current config. */
924 struct ifmediareq *ifmr;
926 ifmr = (struct ifmediareq *)data;
927 if (ifmr->ifm_count >= 1 && ifmr->ifm_ulist) {
929 error = copyout(&ifmr->ifm_current,
946 * Set the interface MTU.
949 if (ifv->ifv_p != NULL) {
951 (ifv->ifv_p->if_mtu - ifv->ifv_mtufudge) ||
953 (ifv->ifv_mintu - ifv->ifv_mtufudge))
956 ifp->if_mtu = ifr->ifr_mtu;
963 error = copyin(ifr->ifr_data, &vlr, sizeof(vlr));
966 if (vlr.vlr_parent[0] == '\0') {
969 if (ifp->if_flags & IFF_UP)
971 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
975 p = ifunit(vlr.vlr_parent);
981 * Don't let the caller set up a VLAN tag with
982 * anything except VLID bits.
984 if (vlr.vlr_tag & ~EVL_VLID_MASK) {
989 error = vlan_config(ifv, p);
994 ifv->ifv_tag = vlr.vlr_tag;
995 ifp->if_drv_flags |= IFF_DRV_RUNNING;
998 /* Update flags on the parent, if necessary. */
999 vlan_setflags(ifp, 1);
1003 bzero(&vlr, sizeof(vlr));
1006 strlcpy(vlr.vlr_parent, ifv->ifv_p->if_xname,
1007 sizeof(vlr.vlr_parent));
1008 vlr.vlr_tag = ifv->ifv_tag;
1011 error = copyout(&vlr, ifr->ifr_data, sizeof(vlr));
1016 * We should propagate selected flags to the parent,
1017 * e.g., promiscuous mode.
1019 if (ifv->ifv_p != NULL)
1020 error = vlan_setflags(ifp, 1);
1026 error = vlan_setmulti(ifp);