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
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.40 2008/09/17 08:51:30 sephe Exp $
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.
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/kernel.h>
53 #include <sys/malloc.h>
55 #include <sys/module.h>
56 #include <sys/queue.h>
57 #include <sys/socket.h>
58 #include <sys/sockio.h>
59 #include <sys/sysctl.h>
61 #include <sys/thread2.h>
64 #include <net/ethernet.h>
66 #include <net/if_arp.h>
67 #include <net/if_dl.h>
68 #include <net/if_types.h>
69 #include <net/ifq_var.h>
70 #include <net/if_clone.h>
71 #include <net/netmsg2.h>
74 #include <netinet/in.h>
75 #include <netinet/if_ether.h>
78 #include <net/vlan/if_vlan_var.h>
79 #include <net/vlan/if_vlan_ether.h>
83 struct vlan_mc_entry {
84 struct ether_addr mc_addr;
85 SLIST_ENTRY(vlan_mc_entry) mc_entries;
90 LIST_ENTRY(vlan_entry) ifv_link;
94 struct arpcom ifv_ac; /* make this an interface */
95 struct ifnet *ifv_p; /* parent inteface of this vlan */
98 uint16_t ifvm_proto; /* encapsulation ethertype */
99 uint16_t ifvm_tag; /* tag to apply on packets leaving if */
101 SLIST_HEAD(, vlan_mc_entry) vlan_mc_listhead;
102 LIST_ENTRY(ifvlan) ifv_list;
103 struct vlan_entry ifv_entries[1];
105 #define ifv_if ifv_ac.ac_if
106 #define ifv_tag ifv_mib.ifvm_tag
109 LIST_HEAD(, vlan_entry) vlan_list;
113 struct netmsg nv_nmsg;
114 struct ifvlan *nv_ifv;
115 struct ifnet *nv_ifp_p;
116 const char *nv_parent_name;
120 #define VLANNAME "vlan"
122 SYSCTL_DECL(_net_link);
123 SYSCTL_NODE(_net_link, IFT_L2VLAN, vlan, CTLFLAG_RW, 0, "IEEE 802.1Q VLAN");
124 SYSCTL_NODE(_net_link_vlan, PF_LINK, link, CTLFLAG_RW, 0, "for consistency");
126 static MALLOC_DEFINE(M_VLAN, "vlan", "802.1Q Virtual LAN Interface");
127 static LIST_HEAD(, ifvlan) ifv_list;
129 static int vlan_clone_create(struct if_clone *, int);
130 static void vlan_clone_destroy(struct ifnet *);
131 static void vlan_ifdetach(void *, struct ifnet *);
133 static void vlan_init(void *);
134 static void vlan_start(struct ifnet *);
135 static int vlan_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
136 static void vlan_input(struct mbuf *);
138 static void vlan_clrmulti(struct ifvlan *, struct ifnet *);
139 static int vlan_setmulti(struct ifvlan *, struct ifnet *);
140 static int vlan_config_multi(struct ifvlan *);
141 static int vlan_config(struct ifvlan *, const char *, uint16_t);
142 static int vlan_unconfig(struct ifvlan *);
143 static void vlan_link(struct ifvlan *, struct ifnet *);
144 static void vlan_unlink(struct ifvlan *, struct ifnet *);
146 static void vlan_config_dispatch(struct netmsg *);
147 static void vlan_unconfig_dispatch(struct netmsg *);
148 static void vlan_link_dispatch(struct netmsg *);
149 static void vlan_unlink_dispatch(struct netmsg *);
150 static void vlan_multi_dispatch(struct netmsg *);
151 static void vlan_ifdetach_dispatch(struct netmsg *);
153 static eventhandler_tag vlan_ifdetach_cookie;
154 static struct if_clone vlan_cloner =
155 IF_CLONE_INITIALIZER("vlan", vlan_clone_create, vlan_clone_destroy,
159 * Program our multicast filter. What we're actually doing is
160 * programming the multicast filter of the parent. This has the
161 * side effect of causing the parent interface to receive multicast
162 * traffic that it doesn't really want, which ends up being discarded
163 * later by the upper protocol layers. Unfortunately, there's no way
164 * to avoid this: there really is only one physical interface.
167 vlan_setmulti(struct ifvlan *ifv, struct ifnet *ifp_p)
169 struct ifmultiaddr *ifma, *rifma = NULL;
170 struct vlan_mc_entry *mc = NULL;
171 struct sockaddr_dl sdl;
172 struct ifnet *ifp = &ifv->ifv_if;
174 ASSERT_NOT_SERIALIZED(ifp->if_serializer);
177 * First, remove any existing filter entries.
179 vlan_clrmulti(ifv, ifp_p);
182 * Now program new ones.
184 bzero(&sdl, sizeof(sdl));
185 sdl.sdl_len = sizeof(sdl);
186 sdl.sdl_family = AF_LINK;
187 sdl.sdl_index = ifp_p->if_index;
188 sdl.sdl_type = IFT_ETHER;
189 sdl.sdl_alen = ETHER_ADDR_LEN;
191 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
194 if (ifma->ifma_addr->sa_family != AF_LINK)
198 mc = kmalloc(sizeof(struct vlan_mc_entry), M_VLAN, M_WAITOK);
199 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
200 &mc->mc_addr, ETHER_ADDR_LEN);
201 SLIST_INSERT_HEAD(&ifv->vlan_mc_listhead, mc, mc_entries);
203 /* Program the parent multicast filter */
204 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
205 LLADDR(&sdl), ETHER_ADDR_LEN);
206 error = if_addmulti(ifp_p, (struct sockaddr *)&sdl, &rifma);
214 vlan_clrmulti(struct ifvlan *ifv, struct ifnet *ifp_p)
216 struct vlan_mc_entry *mc;
217 struct sockaddr_dl sdl;
219 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
221 bzero(&sdl, sizeof(sdl));
222 sdl.sdl_len = sizeof(sdl);
223 sdl.sdl_family = AF_LINK;
224 sdl.sdl_index = ifp_p->if_index;
225 sdl.sdl_type = IFT_ETHER;
226 sdl.sdl_alen = ETHER_ADDR_LEN;
228 while ((mc = SLIST_FIRST(&ifv->vlan_mc_listhead)) != NULL) {
229 bcopy(&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
230 if_delmulti(ifp_p, (struct sockaddr *)&sdl); /* ignore error */
232 SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries);
238 vlan_modevent(module_t mod, int type, void *data)
242 LIST_INIT(&ifv_list);
243 vlan_input_p = vlan_input;
244 vlan_ifdetach_cookie =
245 EVENTHANDLER_REGISTER(ifnet_detach_event,
247 EVENTHANDLER_PRI_ANY);
248 if_clone_attach(&vlan_cloner);
252 if_clone_detach(&vlan_cloner);
254 EVENTHANDLER_DEREGISTER(ifnet_detach_event,
255 vlan_ifdetach_cookie);
256 while (!LIST_EMPTY(&ifv_list))
257 vlan_clone_destroy(&LIST_FIRST(&ifv_list)->ifv_if);
263 static moduledata_t vlan_mod = {
269 DECLARE_MODULE(if_vlan, vlan_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
272 vlan_ifdetach_dispatch(struct netmsg *nmsg)
274 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
275 struct ifnet *ifp_p = vmsg->nv_ifp_p;
276 struct vlan_trunk *vlantrunks, *trunk;
277 struct vlan_entry *ifve;
279 vlantrunks = ifp_p->if_vlantrunks;
280 if (vlantrunks == NULL)
282 trunk = &vlantrunks[mycpuid];
284 while (ifp_p->if_vlantrunks &&
285 (ifve = LIST_FIRST(&trunk->vlan_list)) != NULL)
286 vlan_unconfig(ifve->ifv);
288 lwkt_replymsg(&nmsg->nm_lmsg, 0);
292 vlan_ifdetach(void *arg __unused, struct ifnet *ifp)
294 struct netmsg_vlan vmsg;
297 ASSERT_NOT_SERIALIZED(ifp->if_serializer);
299 bzero(&vmsg, sizeof(vmsg));
300 nmsg = &vmsg.nv_nmsg;
302 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_ifdetach_dispatch);
305 lwkt_domsg(cpu_portfn(0), &nmsg->nm_lmsg, 0);
309 vlan_clone_create(struct if_clone *ifc, int unit)
315 vlan_size = sizeof(struct ifvlan)
316 + ((ncpus - 1) * sizeof(struct vlan_entry));
317 ifv = kmalloc(vlan_size, M_VLAN, M_WAITOK | M_ZERO);
318 SLIST_INIT(&ifv->vlan_mc_listhead);
319 for (i = 0; i < ncpus; ++i)
320 ifv->ifv_entries[i].ifv = ifv;
322 crit_enter(); /* XXX not MP safe */
323 LIST_INSERT_HEAD(&ifv_list, ifv, ifv_list);
328 if_initname(ifp, "vlan", unit);
329 /* NB: flags are not set here */
330 ifp->if_linkmib = &ifv->ifv_mib;
331 ifp->if_linkmiblen = sizeof ifv->ifv_mib;
332 /* NB: mtu is not set here */
334 ifp->if_init = vlan_init;
335 ifp->if_start = vlan_start;
336 ifp->if_ioctl = vlan_ioctl;
337 ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
338 ifq_set_ready(&ifp->if_snd);
339 ether_ifattach(ifp, ifv->ifv_ac.ac_enaddr, NULL);
340 /* Now undo some of the damage... */
341 ifp->if_data.ifi_type = IFT_L2VLAN;
342 ifp->if_data.ifi_hdrlen = EVL_ENCAPLEN;
348 vlan_clone_destroy(struct ifnet *ifp)
350 struct ifvlan *ifv = ifp->if_softc;
352 crit_enter(); /* XXX not MP safe */
353 LIST_REMOVE(ifv, ifv_list);
365 struct ifvlan *ifv = xsc;
366 struct ifnet *ifp = &ifv->ifv_if;
368 ASSERT_SERIALIZED(ifp->if_serializer);
370 if (ifv->ifv_p != NULL)
371 ifp->if_flags |= IFF_RUNNING;
375 vlan_start(struct ifnet *ifp)
377 struct ifvlan *ifv = ifp->if_softc;
378 struct ifnet *ifp_p = ifv->ifv_p;
381 ASSERT_SERIALIZED(ifp->if_serializer);
384 ifq_purge(&ifp->if_snd);
388 if ((ifp->if_flags & IFF_RUNNING) == 0)
392 struct netmsg_packet *nmp;
394 struct lwkt_port *port;
396 m = ifq_dequeue(&ifp->if_snd, NULL);
402 * Do not run parent's if_start() if the parent is not up,
403 * or parent's driver will cause a system crash.
405 if ((ifp_p->if_flags & (IFF_UP | IFF_RUNNING)) !=
406 (IFF_UP | IFF_RUNNING)) {
408 ifp->if_data.ifi_collisions++;
413 * We need some way to tell the interface where the packet
414 * came from so that it knows how to find the VLAN tag to
415 * use, so we set the ether_vlantag in the mbuf packet header
416 * to our vlan tag. We also set the M_VLANTAG flag in the
417 * mbuf to let the parent driver know that the ether_vlantag
420 m->m_pkthdr.ether_vlantag = ifv->ifv_tag;
421 m->m_flags |= M_VLANTAG;
423 nmp = &m->m_hdr.mh_netmsg;
424 nmsg = &nmp->nm_netmsg;
426 netmsg_init(nmsg, &netisr_apanic_rport, 0, vlan_start_dispatch);
428 nmsg->nm_lmsg.u.ms_resultp = ifp_p;
430 port = cpu_portfn(ifp_p->if_index % ncpus /* XXX */);
431 lwkt_sendmsg(port, &nmp->nm_netmsg.nm_lmsg);
437 vlan_input(struct mbuf *m)
439 struct ifvlan *ifv = NULL;
440 struct ifnet *rcvif, *ifp;
441 struct vlan_trunk *vlantrunks;
442 struct vlan_entry *entry;
444 rcvif = m->m_pkthdr.rcvif;
445 KKASSERT(m->m_flags & M_VLANTAG);
447 vlantrunks = rcvif->if_vlantrunks;
448 if (vlantrunks == NULL) {
454 crit_enter(); /* XXX Necessary? */
455 LIST_FOREACH(entry, &vlantrunks[mycpuid].vlan_list, ifv_link) {
456 if (entry->ifv->ifv_tag ==
457 EVL_VLANOFTAG(m->m_pkthdr.ether_vlantag)) {
465 * Packet is discarded if:
466 * - no corresponding vlan(4) interface
467 * - vlan(4) interface has not been completely set up yet,
468 * or is being destroyed (ifv->ifv_p != rcvif)
469 * - vlan(4) interface is not brought up
471 if (ifv == NULL || ifv->ifv_p != rcvif ||
472 (ifv->ifv_if.if_flags & IFF_UP) == 0) {
480 * Clear M_VLANTAG, before the packet is handed to
483 m->m_flags &= ~M_VLANTAG;
485 /* Change receiving interface */
486 m->m_pkthdr.rcvif = ifp;
488 /* Update statistics */
490 ifp->if_ibytes += m->m_pkthdr.len;
491 if (m->m_flags & (M_MCAST | M_BCAST))
496 if (ifp->if_flags & IFF_MONITOR) {
498 * Interface marked for monitoring; discard packet.
503 ether_input_oncpu(ifp, m);
507 vlan_link_dispatch(struct netmsg *nmsg)
509 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
510 struct ifvlan *ifv = vmsg->nv_ifv;
511 struct ifnet *ifp_p = vmsg->nv_ifp_p;
512 struct vlan_entry *entry;
513 struct vlan_trunk *vlantrunks, *trunk;
516 vlantrunks = ifp_p->if_vlantrunks;
517 KASSERT(vlantrunks != NULL,
518 ("vlan trunk has not been initialized yet\n"));
520 entry = &ifv->ifv_entries[cpu];
521 trunk = &vlantrunks[cpu];
524 LIST_INSERT_HEAD(&trunk->vlan_list, entry, ifv_link);
527 ifnet_forwardmsg(&nmsg->nm_lmsg, cpu + 1);
531 vlan_link(struct ifvlan *ifv, struct ifnet *ifp_p)
533 struct netmsg_vlan vmsg;
536 /* Assert in netisr0 */
537 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
539 if (ifp_p->if_vlantrunks == NULL) {
540 struct vlan_trunk *vlantrunks;
543 vlantrunks = kmalloc(sizeof(*vlantrunks) * ncpus, M_VLAN,
545 for (i = 0; i < ncpus; ++i)
546 LIST_INIT(&vlantrunks[i].vlan_list);
548 ifp_p->if_vlantrunks = vlantrunks;
551 bzero(&vmsg, sizeof(vmsg));
552 nmsg = &vmsg.nv_nmsg;
554 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_link_dispatch);
556 vmsg.nv_ifp_p = ifp_p;
558 ifnet_domsg(&nmsg->nm_lmsg, 0);
562 vlan_config_dispatch(struct netmsg *nmsg)
564 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
566 struct ifnet *ifp_p, *ifp;
567 struct sockaddr_dl *sdl1, *sdl2;
570 /* Assert in netisr0 */
572 ifp_p = ifunit(vmsg->nv_parent_name);
578 if (ifp_p->if_data.ifi_type != IFT_ETHER) {
579 error = EPROTONOSUPPORT;
591 /* Link vlan into parent's vlantrunk */
592 vlan_link(ifv, ifp_p);
594 lwkt_serialize_enter(ifp->if_serializer);
596 ifv->ifv_tag = vmsg->nv_vlantag;
597 if (ifp_p->if_capenable & IFCAP_VLAN_MTU)
598 ifp->if_mtu = ifp_p->if_mtu;
600 ifp->if_mtu = ifp_p->if_data.ifi_mtu - EVL_ENCAPLEN;
603 * Copy only a selected subset of flags from the parent.
604 * Other flags are none of our business.
606 ifp->if_flags = (ifp_p->if_flags &
607 (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT));
610 * Set up our ``Ethernet address'' to reflect the underlying
611 * physical interface's.
613 sdl1 = IF_LLSOCKADDR(ifp);
614 sdl2 = IF_LLSOCKADDR(ifp_p);
615 sdl1->sdl_type = IFT_ETHER;
616 sdl1->sdl_alen = ETHER_ADDR_LEN;
617 bcopy(LLADDR(sdl2), LLADDR(sdl1), ETHER_ADDR_LEN);
618 bcopy(LLADDR(sdl2), ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
621 * Release vlan's serializer before reprogramming parent's
622 * multicast filter to avoid possible dead lock.
624 lwkt_serialize_exit(ifp->if_serializer);
627 * Configure multicast addresses that may already be
628 * joined on the vlan device.
630 vlan_setmulti(ifv, ifp_p);
633 * Connect to parent after everything have been set up,
634 * so input/output could know that vlan is ready to go
639 lwkt_replymsg(&nmsg->nm_lmsg, error);
643 vlan_config(struct ifvlan *ifv, const char *parent_name, uint16_t vlantag)
645 struct netmsg_vlan vmsg;
648 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
650 bzero(&vmsg, sizeof(vmsg));
651 nmsg = &vmsg.nv_nmsg;
653 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_config_dispatch);
655 vmsg.nv_parent_name = parent_name;
656 vmsg.nv_vlantag = vlantag;
658 return lwkt_domsg(cpu_portfn(0), &nmsg->nm_lmsg, 0);
662 vlan_unlink_dispatch(struct netmsg *nmsg)
664 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
665 struct ifvlan *ifv = vmsg->nv_ifv;
666 struct vlan_entry *entry;
669 KASSERT(vmsg->nv_ifp_p->if_vlantrunks != NULL,
670 ("vlan trunk has not been initialized yet\n"));
671 entry = &ifv->ifv_entries[cpu];
674 LIST_REMOVE(entry, ifv_link);
677 ifnet_forwardmsg(&nmsg->nm_lmsg, cpu + 1);
681 vlan_unlink(struct ifvlan *ifv, struct ifnet *ifp_p)
683 struct vlan_trunk *vlantrunks = ifp_p->if_vlantrunks;
684 struct netmsg_vlan vmsg;
687 /* Assert in netisr0 */
688 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
690 KASSERT(ifp_p->if_vlantrunks != NULL,
691 ("vlan trunk has not been initialized yet\n"));
693 bzero(&vmsg, sizeof(vmsg));
694 nmsg = &vmsg.nv_nmsg;
696 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_unlink_dispatch);
698 vmsg.nv_ifp_p = ifp_p;
700 ifnet_domsg(&nmsg->nm_lmsg, 0);
703 if (LIST_EMPTY(&vlantrunks[mycpuid].vlan_list)) {
704 ifp_p->if_vlantrunks = NULL;
707 * Make that all protocol threads see if_vlantrunks change.
709 netmsg_service_sync();
710 kfree(vlantrunks, M_VLAN);
716 vlan_unconfig_dispatch(struct netmsg *nmsg)
718 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
719 struct sockaddr_dl *sdl;
721 struct ifnet *ifp_p, *ifp;
724 /* Assert in netisr0 */
729 if (ifp->if_flags & IFF_UP)
732 lwkt_serialize_enter(ifp->if_serializer);
734 ifp->if_flags &= ~IFF_RUNNING;
737 * Save parent ifnet pointer and disconnect from parent.
739 * This is done early in this function, so input/output could
740 * know that we are disconnecting.
746 * Release vlan's serializer before reprogramming parent's
747 * multicast filter to avoid possible dead lock.
749 lwkt_serialize_exit(ifp->if_serializer);
753 * Since the interface is being unconfigured, we need to
754 * empty the list of multicast groups that we may have joined
755 * while we were alive from the parent's list.
757 vlan_clrmulti(ifv, ifp_p);
760 lwkt_serialize_enter(ifp->if_serializer);
762 ifp->if_mtu = ETHERMTU;
764 /* Clear our MAC address. */
765 sdl = IF_LLSOCKADDR(ifp);
766 sdl->sdl_type = IFT_ETHER;
767 sdl->sdl_alen = ETHER_ADDR_LEN;
768 bzero(LLADDR(sdl), ETHER_ADDR_LEN);
769 bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
771 lwkt_serialize_exit(ifp->if_serializer);
773 /* Unlink vlan from parent's vlantrunk */
774 if (ifp_p != NULL && ifp_p->if_vlantrunks != NULL)
775 vlan_unlink(ifv, ifp_p);
778 lwkt_replymsg(&nmsg->nm_lmsg, error);
782 vlan_unconfig(struct ifvlan *ifv)
784 struct netmsg_vlan vmsg;
787 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
789 bzero(&vmsg, sizeof(vmsg));
790 nmsg = &vmsg.nv_nmsg;
792 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_unconfig_dispatch);
795 return lwkt_domsg(cpu_portfn(0), &nmsg->nm_lmsg, 0);
799 vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
801 struct ifvlan *ifv = ifp->if_softc;
802 struct ifreq *ifr = (struct ifreq *)data;
807 ASSERT_SERIALIZED(ifp->if_serializer);
814 * Release vlan interface's serializer to void
815 * possible dead lock.
817 lwkt_serialize_exit(ifp->if_serializer);
819 lwkt_serialize_enter(ifp_p->if_serializer);
820 error = ifp_p->if_ioctl(ifp_p, SIOCGIFMEDIA, data, cr);
821 lwkt_serialize_exit(ifp_p->if_serializer);
823 lwkt_serialize_enter(ifp->if_serializer);
825 if (ifv->ifv_p == NULL && ifv->ifv_p != ifp_p) {
827 * We are disconnected from the original
828 * parent interface or the parent interface
829 * is changed, after vlan interface's
830 * serializer is released.
835 /* Limit the result to the parent's current config. */
837 struct ifmediareq *ifmr;
839 ifmr = (struct ifmediareq *) data;
840 if (ifmr->ifm_count >= 1 && ifmr->ifm_ulist) {
842 error = copyout(&ifmr->ifm_current,
857 error = copyin(ifr->ifr_data, &vlr, sizeof vlr);
861 lwkt_serialize_exit(ifp->if_serializer);
862 if (vlr.vlr_parent[0] == '\0')
863 error = vlan_unconfig(ifv);
865 error = vlan_config(ifv, vlr.vlr_parent, vlr.vlr_tag);
866 lwkt_serialize_enter(ifp->if_serializer);
870 bzero(&vlr, sizeof(vlr));
872 strlcpy(vlr.vlr_parent, ifv->ifv_p->if_xname,
873 sizeof(vlr.vlr_parent));
874 vlr.vlr_tag = ifv->ifv_tag;
876 error = copyout(&vlr, ifr->ifr_data, sizeof vlr);
880 if (ifp->if_flags & IFF_UP)
883 ifp->if_flags &= ~IFF_RUNNING;
886 * We don't support promiscuous mode
887 * right now because it would require help from the
888 * underlying drivers, which hasn't been implemented.
890 if (ifr->ifr_flags & IFF_PROMISC) {
891 ifp->if_flags &= ~IFF_PROMISC;
898 lwkt_serialize_exit(ifp->if_serializer);
899 error = vlan_config_multi(ifv);
900 lwkt_serialize_enter(ifp->if_serializer);
904 error = ether_ioctl(ifp, cmd, data);
911 vlan_multi_dispatch(struct netmsg *nmsg)
913 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
914 struct ifvlan *ifv = vmsg->nv_ifv;
918 * If we don't have a parent, just remember the membership for
921 if (ifv->ifv_p != NULL)
922 error = vlan_setmulti(ifv, ifv->ifv_p);
923 lwkt_replymsg(&nmsg->nm_lmsg, error);
927 vlan_config_multi(struct ifvlan *ifv)
929 struct netmsg_vlan vmsg;
932 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
934 bzero(&vmsg, sizeof(vmsg));
935 nmsg = &vmsg.nv_nmsg;
937 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_multi_dispatch);
940 return lwkt_domsg(cpu_portfn(0), &nmsg->nm_lmsg, 0);