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.39 2008/09/17 07:51:59 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.
49 #include "opt_ethernet.h"
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/kernel.h>
54 #include <sys/malloc.h>
56 #include <sys/module.h>
57 #include <sys/queue.h>
58 #include <sys/socket.h>
59 #include <sys/sockio.h>
60 #include <sys/sysctl.h>
62 #include <sys/thread2.h>
65 #include <net/ethernet.h>
67 #include <net/if_arp.h>
68 #include <net/if_dl.h>
69 #include <net/if_types.h>
70 #include <net/ifq_var.h>
71 #include <net/if_clone.h>
72 #include <net/netmsg2.h>
75 #include <netinet/in.h>
76 #include <netinet/if_ether.h>
79 #include <net/vlan/if_vlan_var.h>
80 #include <net/vlan/if_vlan_ether.h>
84 struct vlan_mc_entry {
85 struct ether_addr mc_addr;
86 SLIST_ENTRY(vlan_mc_entry) mc_entries;
91 LIST_ENTRY(vlan_entry) ifv_link;
95 struct arpcom ifv_ac; /* make this an interface */
96 struct ifnet *ifv_p; /* parent inteface of this vlan */
99 uint16_t ifvm_proto; /* encapsulation ethertype */
100 uint16_t ifvm_tag; /* tag to apply on packets leaving if */
102 SLIST_HEAD(, vlan_mc_entry) vlan_mc_listhead;
103 LIST_ENTRY(ifvlan) ifv_list;
104 struct vlan_entry ifv_entries[1];
106 #define ifv_if ifv_ac.ac_if
107 #define ifv_tag ifv_mib.ifvm_tag
110 LIST_HEAD(, vlan_entry) vlan_list;
114 struct netmsg nv_nmsg;
115 struct ifvlan *nv_ifv;
116 struct ifnet *nv_ifp_p;
117 const char *nv_parent_name;
121 #define VLANNAME "vlan"
123 SYSCTL_DECL(_net_link);
124 SYSCTL_NODE(_net_link, IFT_L2VLAN, vlan, CTLFLAG_RW, 0, "IEEE 802.1Q VLAN");
125 SYSCTL_NODE(_net_link_vlan, PF_LINK, link, CTLFLAG_RW, 0, "for consistency");
127 static MALLOC_DEFINE(M_VLAN, "vlan", "802.1Q Virtual LAN Interface");
128 static LIST_HEAD(, ifvlan) ifv_list;
130 static int vlan_clone_create(struct if_clone *, int);
131 static void vlan_clone_destroy(struct ifnet *);
132 static void vlan_ifdetach(void *, struct ifnet *);
134 static void vlan_init(void *);
135 static void vlan_start(struct ifnet *);
136 static int vlan_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
137 static void vlan_input(struct mbuf *);
139 static void vlan_clrmulti(struct ifvlan *, struct ifnet *);
140 static int vlan_setmulti(struct ifvlan *, struct ifnet *);
141 static int vlan_config_multi(struct ifvlan *);
142 static int vlan_config(struct ifvlan *, const char *, uint16_t);
143 static int vlan_unconfig(struct ifvlan *);
144 static void vlan_link(struct ifvlan *, struct ifnet *);
145 static void vlan_unlink(struct ifvlan *, struct ifnet *);
147 static void vlan_config_dispatch(struct netmsg *);
148 static void vlan_unconfig_dispatch(struct netmsg *);
149 static void vlan_link_dispatch(struct netmsg *);
150 static void vlan_unlink_dispatch(struct netmsg *);
151 static void vlan_multi_dispatch(struct netmsg *);
152 static void vlan_ifdetach_dispatch(struct netmsg *);
154 static eventhandler_tag vlan_ifdetach_cookie;
155 static struct if_clone vlan_cloner =
156 IF_CLONE_INITIALIZER("vlan", vlan_clone_create, vlan_clone_destroy,
160 * Program our multicast filter. What we're actually doing is
161 * programming the multicast filter of the parent. This has the
162 * side effect of causing the parent interface to receive multicast
163 * traffic that it doesn't really want, which ends up being discarded
164 * later by the upper protocol layers. Unfortunately, there's no way
165 * to avoid this: there really is only one physical interface.
168 vlan_setmulti(struct ifvlan *ifv, struct ifnet *ifp_p)
170 struct ifmultiaddr *ifma, *rifma = NULL;
171 struct vlan_mc_entry *mc = NULL;
172 struct sockaddr_dl sdl;
173 struct ifnet *ifp = &ifv->ifv_if;
175 ASSERT_NOT_SERIALIZED(ifp->if_serializer);
178 * First, remove any existing filter entries.
180 vlan_clrmulti(ifv, ifp_p);
183 * Now program new ones.
185 bzero(&sdl, sizeof(sdl));
186 sdl.sdl_len = sizeof(sdl);
187 sdl.sdl_family = AF_LINK;
188 sdl.sdl_index = ifp_p->if_index;
189 sdl.sdl_type = IFT_ETHER;
190 sdl.sdl_alen = ETHER_ADDR_LEN;
192 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
195 if (ifma->ifma_addr->sa_family != AF_LINK)
199 mc = kmalloc(sizeof(struct vlan_mc_entry), M_VLAN, M_WAITOK);
200 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
201 &mc->mc_addr, ETHER_ADDR_LEN);
202 SLIST_INSERT_HEAD(&ifv->vlan_mc_listhead, mc, mc_entries);
204 /* Program the parent multicast filter */
205 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
206 LLADDR(&sdl), ETHER_ADDR_LEN);
207 error = if_addmulti(ifp_p, (struct sockaddr *)&sdl, &rifma);
215 vlan_clrmulti(struct ifvlan *ifv, struct ifnet *ifp_p)
217 struct vlan_mc_entry *mc;
218 struct sockaddr_dl sdl;
220 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
222 bzero(&sdl, sizeof(sdl));
223 sdl.sdl_len = sizeof(sdl);
224 sdl.sdl_family = AF_LINK;
225 sdl.sdl_index = ifp_p->if_index;
226 sdl.sdl_type = IFT_ETHER;
227 sdl.sdl_alen = ETHER_ADDR_LEN;
229 while ((mc = SLIST_FIRST(&ifv->vlan_mc_listhead)) != NULL) {
230 bcopy(&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
231 if_delmulti(ifp_p, (struct sockaddr *)&sdl); /* ignore error */
233 SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries);
239 vlan_modevent(module_t mod, int type, void *data)
243 LIST_INIT(&ifv_list);
244 vlan_input_p = vlan_input;
245 vlan_ifdetach_cookie =
246 EVENTHANDLER_REGISTER(ifnet_detach_event,
248 EVENTHANDLER_PRI_ANY);
249 if_clone_attach(&vlan_cloner);
253 if_clone_detach(&vlan_cloner);
255 EVENTHANDLER_DEREGISTER(ifnet_detach_event,
256 vlan_ifdetach_cookie);
257 while (!LIST_EMPTY(&ifv_list))
258 vlan_clone_destroy(&LIST_FIRST(&ifv_list)->ifv_if);
264 static moduledata_t vlan_mod = {
270 DECLARE_MODULE(if_vlan, vlan_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
273 vlan_ifdetach_dispatch(struct netmsg *nmsg)
275 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
276 struct ifnet *ifp_p = vmsg->nv_ifp_p;
277 struct vlan_trunk *vlantrunks, *trunk;
278 struct vlan_entry *ifve;
280 vlantrunks = ifp_p->if_vlantrunks;
281 if (vlantrunks == NULL)
283 trunk = &vlantrunks[mycpuid];
285 while (ifp_p->if_vlantrunks &&
286 (ifve = LIST_FIRST(&trunk->vlan_list)) != NULL)
287 vlan_unconfig(ifve->ifv);
289 lwkt_replymsg(&nmsg->nm_lmsg, 0);
293 vlan_ifdetach(void *arg __unused, struct ifnet *ifp)
295 struct netmsg_vlan vmsg;
298 ASSERT_NOT_SERIALIZED(ifp->if_serializer);
300 bzero(&vmsg, sizeof(vmsg));
301 nmsg = &vmsg.nv_nmsg;
303 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_ifdetach_dispatch);
306 lwkt_domsg(cpu_portfn(0), &nmsg->nm_lmsg, 0);
310 vlan_clone_create(struct if_clone *ifc, int unit)
316 vlan_size = sizeof(struct ifvlan)
317 + ((ncpus - 1) * sizeof(struct vlan_entry));
318 ifv = kmalloc(vlan_size, M_VLAN, M_WAITOK | M_ZERO);
319 SLIST_INIT(&ifv->vlan_mc_listhead);
320 for (i = 0; i < ncpus; ++i)
321 ifv->ifv_entries[i].ifv = ifv;
323 crit_enter(); /* XXX not MP safe */
324 LIST_INSERT_HEAD(&ifv_list, ifv, ifv_list);
329 if_initname(ifp, "vlan", unit);
330 /* NB: flags are not set here */
331 ifp->if_linkmib = &ifv->ifv_mib;
332 ifp->if_linkmiblen = sizeof ifv->ifv_mib;
333 /* NB: mtu is not set here */
335 ifp->if_init = vlan_init;
336 ifp->if_start = vlan_start;
337 ifp->if_ioctl = vlan_ioctl;
338 ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
339 ifq_set_ready(&ifp->if_snd);
340 ether_ifattach(ifp, ifv->ifv_ac.ac_enaddr, NULL);
341 /* Now undo some of the damage... */
342 ifp->if_data.ifi_type = IFT_L2VLAN;
343 ifp->if_data.ifi_hdrlen = EVL_ENCAPLEN;
349 vlan_clone_destroy(struct ifnet *ifp)
351 struct ifvlan *ifv = ifp->if_softc;
353 crit_enter(); /* XXX not MP safe */
354 LIST_REMOVE(ifv, ifv_list);
366 struct ifvlan *ifv = xsc;
367 struct ifnet *ifp = &ifv->ifv_if;
369 ASSERT_SERIALIZED(ifp->if_serializer);
371 if (ifv->ifv_p != NULL)
372 ifp->if_flags |= IFF_RUNNING;
376 vlan_start(struct ifnet *ifp)
378 struct ifvlan *ifv = ifp->if_softc;
379 struct ifnet *ifp_p = ifv->ifv_p;
382 ASSERT_SERIALIZED(ifp->if_serializer);
385 ifq_purge(&ifp->if_snd);
389 if ((ifp->if_flags & IFF_RUNNING) == 0)
393 struct netmsg_packet *nmp;
395 struct lwkt_port *port;
397 m = ifq_dequeue(&ifp->if_snd, NULL);
403 * Do not run parent's if_start() if the parent is not up,
404 * or parent's driver will cause a system crash.
406 if ((ifp_p->if_flags & (IFF_UP | IFF_RUNNING)) !=
407 (IFF_UP | IFF_RUNNING)) {
409 ifp->if_data.ifi_collisions++;
414 * We need some way to tell the interface where the packet
415 * came from so that it knows how to find the VLAN tag to
416 * use, so we set the ether_vlantag in the mbuf packet header
417 * to our vlan tag. We also set the M_VLANTAG flag in the
418 * mbuf to let the parent driver know that the ether_vlantag
421 m->m_pkthdr.ether_vlantag = ifv->ifv_tag;
422 m->m_flags |= M_VLANTAG;
424 nmp = &m->m_hdr.mh_netmsg;
425 nmsg = &nmp->nm_netmsg;
427 netmsg_init(nmsg, &netisr_apanic_rport, 0, vlan_start_dispatch);
429 nmsg->nm_lmsg.u.ms_resultp = ifp_p;
431 port = cpu_portfn(ifp_p->if_index % ncpus /* XXX */);
432 lwkt_sendmsg(port, &nmp->nm_netmsg.nm_lmsg);
438 vlan_input(struct mbuf *m)
440 struct ifvlan *ifv = NULL;
441 struct ifnet *rcvif, *ifp;
442 struct vlan_trunk *vlantrunks;
443 struct vlan_entry *entry;
445 rcvif = m->m_pkthdr.rcvif;
446 KKASSERT(m->m_flags & M_VLANTAG);
448 vlantrunks = rcvif->if_vlantrunks;
449 if (vlantrunks == NULL) {
455 crit_enter(); /* XXX Necessary? */
456 LIST_FOREACH(entry, &vlantrunks[mycpuid].vlan_list, ifv_link) {
457 if (entry->ifv->ifv_tag ==
458 EVL_VLANOFTAG(m->m_pkthdr.ether_vlantag)) {
466 * Packet is discarded if:
467 * - no corresponding vlan(4) interface
468 * - vlan(4) interface has not been completely set up yet,
469 * or is being destroyed (ifv->ifv_p != rcvif)
470 * - vlan(4) interface is not brought up
472 if (ifv == NULL || ifv->ifv_p != rcvif ||
473 (ifv->ifv_if.if_flags & IFF_UP) == 0) {
481 * Clear M_VLANTAG, before the packet is handed to
484 m->m_flags &= ~M_VLANTAG;
486 /* Change receiving interface */
487 m->m_pkthdr.rcvif = ifp;
489 /* Update statistics */
491 ifp->if_ibytes += m->m_pkthdr.len;
492 if (m->m_flags & (M_MCAST | M_BCAST))
497 if (ifp->if_flags & IFF_MONITOR) {
499 * Interface marked for monitoring; discard packet.
504 ether_input_oncpu(ifp, m);
508 vlan_link_dispatch(struct netmsg *nmsg)
510 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
511 struct ifvlan *ifv = vmsg->nv_ifv;
512 struct ifnet *ifp_p = vmsg->nv_ifp_p;
513 struct vlan_entry *entry;
514 struct vlan_trunk *vlantrunks, *trunk;
517 vlantrunks = ifp_p->if_vlantrunks;
518 KASSERT(vlantrunks != NULL,
519 ("vlan trunk has not been initialized yet\n"));
521 entry = &ifv->ifv_entries[cpu];
522 trunk = &vlantrunks[cpu];
525 LIST_INSERT_HEAD(&trunk->vlan_list, entry, ifv_link);
528 ifnet_forwardmsg(&nmsg->nm_lmsg, cpu + 1);
532 vlan_link(struct ifvlan *ifv, struct ifnet *ifp_p)
534 struct netmsg_vlan vmsg;
537 /* Assert in netisr0 */
538 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
540 if (ifp_p->if_vlantrunks == NULL) {
541 struct vlan_trunk *vlantrunks;
544 vlantrunks = kmalloc(sizeof(*vlantrunks) * ncpus, M_VLAN,
546 for (i = 0; i < ncpus; ++i)
547 LIST_INIT(&vlantrunks[i].vlan_list);
549 ifp_p->if_vlantrunks = vlantrunks;
552 bzero(&vmsg, sizeof(vmsg));
553 nmsg = &vmsg.nv_nmsg;
555 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_link_dispatch);
557 vmsg.nv_ifp_p = ifp_p;
559 ifnet_domsg(&nmsg->nm_lmsg, 0);
563 vlan_config_dispatch(struct netmsg *nmsg)
565 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
567 struct ifnet *ifp_p, *ifp;
568 struct sockaddr_dl *sdl1, *sdl2;
571 /* Assert in netisr0 */
573 ifp_p = ifunit(vmsg->nv_parent_name);
579 if (ifp_p->if_data.ifi_type != IFT_ETHER) {
580 error = EPROTONOSUPPORT;
592 /* Link vlan into parent's vlantrunk */
593 vlan_link(ifv, ifp_p);
595 lwkt_serialize_enter(ifp->if_serializer);
597 ifv->ifv_tag = vmsg->nv_vlantag;
598 if (ifp_p->if_capenable & IFCAP_VLAN_MTU)
599 ifp->if_mtu = ifp_p->if_mtu;
601 ifp->if_mtu = ifp_p->if_data.ifi_mtu - EVL_ENCAPLEN;
604 * Copy only a selected subset of flags from the parent.
605 * Other flags are none of our business.
607 ifp->if_flags = (ifp_p->if_flags &
608 (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT));
611 * Set up our ``Ethernet address'' to reflect the underlying
612 * physical interface's.
614 sdl1 = IF_LLSOCKADDR(ifp);
615 sdl2 = IF_LLSOCKADDR(ifp_p);
616 sdl1->sdl_type = IFT_ETHER;
617 sdl1->sdl_alen = ETHER_ADDR_LEN;
618 bcopy(LLADDR(sdl2), LLADDR(sdl1), ETHER_ADDR_LEN);
619 bcopy(LLADDR(sdl2), ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
622 * Release vlan's serializer before reprogramming parent's
623 * multicast filter to avoid possible dead lock.
625 lwkt_serialize_exit(ifp->if_serializer);
628 * Configure multicast addresses that may already be
629 * joined on the vlan device.
631 vlan_setmulti(ifv, ifp_p);
634 * Connect to parent after everything have been set up,
635 * so input/output could know that vlan is ready to go
640 lwkt_replymsg(&nmsg->nm_lmsg, error);
644 vlan_config(struct ifvlan *ifv, const char *parent_name, uint16_t vlantag)
646 struct netmsg_vlan vmsg;
649 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
651 bzero(&vmsg, sizeof(vmsg));
652 nmsg = &vmsg.nv_nmsg;
654 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_config_dispatch);
656 vmsg.nv_parent_name = parent_name;
657 vmsg.nv_vlantag = vlantag;
659 return lwkt_domsg(cpu_portfn(0), &nmsg->nm_lmsg, 0);
663 vlan_unlink_dispatch(struct netmsg *nmsg)
665 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
666 struct ifvlan *ifv = vmsg->nv_ifv;
667 struct vlan_entry *entry;
670 KASSERT(vmsg->nv_ifp_p->if_vlantrunks != NULL,
671 ("vlan trunk has not been initialized yet\n"));
672 entry = &ifv->ifv_entries[cpu];
675 LIST_REMOVE(entry, ifv_link);
678 ifnet_forwardmsg(&nmsg->nm_lmsg, cpu + 1);
682 vlan_unlink(struct ifvlan *ifv, struct ifnet *ifp_p)
684 struct vlan_trunk *vlantrunks = ifp_p->if_vlantrunks;
685 struct netmsg_vlan vmsg;
688 /* Assert in netisr0 */
689 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
691 KASSERT(ifp_p->if_vlantrunks != NULL,
692 ("vlan trunk has not been initialized yet\n"));
694 bzero(&vmsg, sizeof(vmsg));
695 nmsg = &vmsg.nv_nmsg;
697 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_unlink_dispatch);
699 vmsg.nv_ifp_p = ifp_p;
701 ifnet_domsg(&nmsg->nm_lmsg, 0);
704 if (LIST_EMPTY(&vlantrunks[mycpuid].vlan_list)) {
705 ifp_p->if_vlantrunks = NULL;
708 * Make that all protocol threads see if_vlantrunks change.
710 netmsg_service_sync();
711 kfree(vlantrunks, M_VLAN);
717 vlan_unconfig_dispatch(struct netmsg *nmsg)
719 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
720 struct sockaddr_dl *sdl;
722 struct ifnet *ifp_p, *ifp;
725 /* Assert in netisr0 */
730 if (ifp->if_flags & IFF_UP)
733 lwkt_serialize_enter(ifp->if_serializer);
735 ifp->if_flags &= ~IFF_RUNNING;
738 * Save parent ifnet pointer and disconnect from parent.
740 * This is done early in this function, so input/output could
741 * know that we are disconnecting.
747 * Release vlan's serializer before reprogramming parent's
748 * multicast filter to avoid possible dead lock.
750 lwkt_serialize_exit(ifp->if_serializer);
754 * Since the interface is being unconfigured, we need to
755 * empty the list of multicast groups that we may have joined
756 * while we were alive from the parent's list.
758 vlan_clrmulti(ifv, ifp_p);
761 lwkt_serialize_enter(ifp->if_serializer);
763 ifp->if_mtu = ETHERMTU;
765 /* Clear our MAC address. */
766 sdl = IF_LLSOCKADDR(ifp);
767 sdl->sdl_type = IFT_ETHER;
768 sdl->sdl_alen = ETHER_ADDR_LEN;
769 bzero(LLADDR(sdl), ETHER_ADDR_LEN);
770 bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
772 lwkt_serialize_exit(ifp->if_serializer);
774 /* Unlink vlan from parent's vlantrunk */
775 if (ifp_p != NULL && ifp_p->if_vlantrunks != NULL)
776 vlan_unlink(ifv, ifp_p);
779 lwkt_replymsg(&nmsg->nm_lmsg, error);
783 vlan_unconfig(struct ifvlan *ifv)
785 struct netmsg_vlan vmsg;
788 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
790 bzero(&vmsg, sizeof(vmsg));
791 nmsg = &vmsg.nv_nmsg;
793 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_unconfig_dispatch);
796 return lwkt_domsg(cpu_portfn(0), &nmsg->nm_lmsg, 0);
800 vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
802 struct ifvlan *ifv = ifp->if_softc;
803 struct ifreq *ifr = (struct ifreq *)data;
808 ASSERT_SERIALIZED(ifp->if_serializer);
815 * Release vlan interface's serializer to void
816 * possible dead lock.
818 lwkt_serialize_exit(ifp->if_serializer);
820 lwkt_serialize_enter(ifp_p->if_serializer);
821 error = ifp_p->if_ioctl(ifp_p, SIOCGIFMEDIA, data, cr);
822 lwkt_serialize_exit(ifp_p->if_serializer);
824 lwkt_serialize_enter(ifp->if_serializer);
826 if (ifv->ifv_p == NULL && ifv->ifv_p != ifp_p) {
828 * We are disconnected from the original
829 * parent interface or the parent interface
830 * is changed, after vlan interface's
831 * serializer is released.
836 /* Limit the result to the parent's current config. */
838 struct ifmediareq *ifmr;
840 ifmr = (struct ifmediareq *) data;
841 if (ifmr->ifm_count >= 1 && ifmr->ifm_ulist) {
843 error = copyout(&ifmr->ifm_current,
858 error = copyin(ifr->ifr_data, &vlr, sizeof vlr);
862 lwkt_serialize_exit(ifp->if_serializer);
863 if (vlr.vlr_parent[0] == '\0')
864 error = vlan_unconfig(ifv);
866 error = vlan_config(ifv, vlr.vlr_parent, vlr.vlr_tag);
867 lwkt_serialize_enter(ifp->if_serializer);
871 bzero(&vlr, sizeof(vlr));
873 strlcpy(vlr.vlr_parent, ifv->ifv_p->if_xname,
874 sizeof(vlr.vlr_parent));
875 vlr.vlr_tag = ifv->ifv_tag;
877 error = copyout(&vlr, ifr->ifr_data, sizeof vlr);
881 if (ifp->if_flags & IFF_UP)
884 ifp->if_flags &= ~IFF_RUNNING;
887 * We don't support promiscuous mode
888 * right now because it would require help from the
889 * underlying drivers, which hasn't been implemented.
891 if (ifr->ifr_flags & IFF_PROMISC) {
892 ifp->if_flags &= ~IFF_PROMISC;
899 lwkt_serialize_exit(ifp->if_serializer);
900 error = vlan_config_multi(ifv);
901 lwkt_serialize_enter(ifp->if_serializer);
905 error = ether_ioctl(ifp, cmd, data);
912 vlan_multi_dispatch(struct netmsg *nmsg)
914 struct netmsg_vlan *vmsg = (struct netmsg_vlan *)nmsg;
915 struct ifvlan *ifv = vmsg->nv_ifv;
919 * If we don't have a parent, just remember the membership for
922 if (ifv->ifv_p != NULL)
923 error = vlan_setmulti(ifv, ifv->ifv_p);
924 lwkt_replymsg(&nmsg->nm_lmsg, error);
928 vlan_config_multi(struct ifvlan *ifv)
930 struct netmsg_vlan vmsg;
933 ASSERT_NOT_SERIALIZED(ifv->ifv_if.if_serializer);
935 bzero(&vmsg, sizeof(vmsg));
936 nmsg = &vmsg.nv_nmsg;
938 netmsg_init(nmsg, &curthread->td_msgport, 0, vlan_multi_dispatch);
941 return lwkt_domsg(cpu_portfn(0), &nmsg->nm_lmsg, 0);