#ifndef NVLAN
#include "use_vlan.h"
#endif
#include "opt_inet.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/module.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/sysctl.h>
#include <sys/bus.h>
#include <sys/thread2.h>
#include <net/bpf.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/ifq_var.h>
#include <net/if_clone.h>
#include <net/netmsg2.h>
#include <net/netisr2.h>
#ifdef INET
#include <netinet/in.h>
#include <netinet/if_ether.h>
#endif
#include <net/vlan/if_vlan_var.h>
#include <net/vlan/if_vlan_ether.h>
struct ifvlan;
struct vlan_mc_entry {
struct ether_addr mc_addr;
SLIST_ENTRY(vlan_mc_entry) mc_entries;
};
struct vlan_entry {
struct ifvlan *ifv;
LIST_ENTRY(vlan_entry) ifv_link;
};
struct ifvlan {
struct arpcom ifv_ac;
struct ifnet *ifv_p;
int ifv_pflags;
struct ifv_linkmib {
int ifvm_parent;
uint16_t ifvm_proto;
uint16_t ifvm_tag;
} ifv_mib;
SLIST_HEAD(, vlan_mc_entry) vlan_mc_listhead;
LIST_ENTRY(ifvlan) ifv_list;
struct vlan_entry ifv_entries[1];
};
#define ifv_if ifv_ac.ac_if
#define ifv_tag ifv_mib.ifvm_tag
struct vlan_trunk {
LIST_HEAD(, vlan_entry) vlan_list;
};
struct netmsg_vlan {
struct netmsg_base base;
struct ifvlan *nv_ifv;
struct ifnet *nv_ifp_p;
const char *nv_parent_name;
uint16_t nv_vlantag;
};
#define VLANNAME "vlan"
SYSCTL_DECL(_net_link);
SYSCTL_NODE(_net_link, IFT_L2VLAN, vlan, CTLFLAG_RW, 0, "IEEE 802.1Q VLAN");
SYSCTL_NODE(_net_link_vlan, PF_LINK, link, CTLFLAG_RW, 0, "for consistency");
static MALLOC_DEFINE(M_VLAN, "vlan", "802.1Q Virtual LAN Interface");
static LIST_HEAD(, ifvlan) ifv_list;
static int vlan_clone_create(struct if_clone *, int, caddr_t, caddr_t);
static int vlan_clone_destroy(struct ifnet *);
static void vlan_ifdetach(void *, struct ifnet *);
static void vlan_init(void *);
static void vlan_start(struct ifnet *, struct ifaltq_subque *);
static int vlan_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
static void vlan_input(struct mbuf *);
static int vlan_setflags(struct ifvlan *, struct ifnet *, int);
static int vlan_setflag(struct ifvlan *, struct ifnet *, int, int,
int (*)(struct ifnet *, int));
static int vlan_config_flags(struct ifvlan *ifv);
static void vlan_clrmulti(struct ifvlan *, struct ifnet *);
static int vlan_setmulti(struct ifvlan *, struct ifnet *);
static int vlan_config_multi(struct ifvlan *);
static int vlan_config(struct ifvlan *, const char *, uint16_t);
static int vlan_unconfig(struct ifvlan *);
static void vlan_link(struct ifvlan *, struct ifnet *);
static void vlan_unlink(struct ifvlan *, struct ifnet *);
static void vlan_config_dispatch(netmsg_t);
static void vlan_unconfig_dispatch(netmsg_t);
static void vlan_link_dispatch(netmsg_t);
static void vlan_unlink_dispatch(netmsg_t);
static void vlan_multi_dispatch(netmsg_t);
static void vlan_flags_dispatch(netmsg_t);
static void vlan_ifdetach_dispatch(netmsg_t);
static struct {
int flag;
int (*func)(struct ifnet *, int);
} vlan_pflags[] = {
{ IFF_PROMISC, ifpromisc },
{ IFF_ALLMULTI, if_allmulti },
{ 0, NULL }
};
static eventhandler_tag vlan_ifdetach_cookie;
static struct if_clone vlan_cloner =
IF_CLONE_INITIALIZER("vlan", vlan_clone_create, vlan_clone_destroy,
NVLAN, IF_MAXUNIT);
static int
vlan_setflags(struct ifvlan *ifv, struct ifnet *ifp_p, int set)
{
int error, i;
ASSERT_IFNET_NOT_SERIALIZED_ALL(&ifv->ifv_if);
for (i = 0; vlan_pflags[i].func != NULL; i++) {
error = vlan_setflag(ifv, ifp_p, vlan_pflags[i].flag,
set, vlan_pflags[i].func);
if (error)
return error;
}
return 0;
}
static int
vlan_setflag(struct ifvlan *ifv, struct ifnet *ifp_p, int flag, int set,
int (*func)(struct ifnet *, int))
{
struct ifnet *ifp = &ifv->ifv_if;
int error, ifv_flag;
ASSERT_IFNET_NOT_SERIALIZED_ALL(ifp);
ifv_flag = set ? (ifp->if_flags & flag) : 0;
if (ifv_flag != (ifv->ifv_pflags & flag)) {
error = func(ifp_p, ifv_flag);
if (error)
return error;
ifv->ifv_pflags &= ~flag;
ifv->ifv_pflags |= ifv_flag;
}
return 0;
}
static int
vlan_setmulti(struct ifvlan *ifv, struct ifnet *ifp_p)
{
struct ifmultiaddr *ifma;
struct vlan_mc_entry *mc = NULL;
struct sockaddr_dl sdl;
struct ifnet *ifp = &ifv->ifv_if;
ASSERT_IFNET_NOT_SERIALIZED_ALL(ifp);
vlan_clrmulti(ifv, ifp_p);
ifnet_serialize_all(ifp);
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
mc = kmalloc(sizeof(struct vlan_mc_entry), M_VLAN, M_WAITOK);
bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
&mc->mc_addr, ETHER_ADDR_LEN);
SLIST_INSERT_HEAD(&ifv->vlan_mc_listhead, mc, mc_entries);
}
ifnet_deserialize_all(ifp);
bzero(&sdl, sizeof(sdl));
sdl.sdl_len = sizeof(sdl);
sdl.sdl_family = AF_LINK;
sdl.sdl_index = ifp_p->if_index;
sdl.sdl_type = IFT_ETHER;
sdl.sdl_alen = ETHER_ADDR_LEN;
SLIST_FOREACH(mc, &ifv->vlan_mc_listhead, mc_entries) {
int error;
bcopy(&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
error = if_addmulti(ifp_p, (struct sockaddr *)&sdl, NULL);
if (error) {
return error;
}
}
return 0;
}
static void
vlan_clrmulti(struct ifvlan *ifv, struct ifnet *ifp_p)
{
struct vlan_mc_entry *mc;
struct sockaddr_dl sdl;
ASSERT_IFNET_NOT_SERIALIZED_ALL(&ifv->ifv_if);
bzero(&sdl, sizeof(sdl));
sdl.sdl_len = sizeof(sdl);
sdl.sdl_family = AF_LINK;
sdl.sdl_index = ifp_p->if_index;
sdl.sdl_type = IFT_ETHER;
sdl.sdl_alen = ETHER_ADDR_LEN;
while ((mc = SLIST_FIRST(&ifv->vlan_mc_listhead)) != NULL) {
bcopy(&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN);
if_delmulti(ifp_p, (struct sockaddr *)&sdl);
SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries);
kfree(mc, M_VLAN);
}
}
static int
vlan_modevent(module_t mod, int type, void *data)
{
switch (type) {
case MOD_LOAD:
LIST_INIT(&ifv_list);
vlan_input_p = vlan_input;
vlan_ifdetach_cookie =
EVENTHANDLER_REGISTER(ifnet_detach_event,
vlan_ifdetach, NULL,
EVENTHANDLER_PRI_ANY);
if_clone_attach(&vlan_cloner);
break;
case MOD_UNLOAD:
if_clone_detach(&vlan_cloner);
vlan_input_p = NULL;
netmsg_service_sync();
EVENTHANDLER_DEREGISTER(ifnet_detach_event,
vlan_ifdetach_cookie);
while (!LIST_EMPTY(&ifv_list))
vlan_clone_destroy(&LIST_FIRST(&ifv_list)->ifv_if);
break;
}
return 0;
}
static moduledata_t vlan_mod = {
"if_vlan",
vlan_modevent,
0
};
DECLARE_MODULE(if_vlan, vlan_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
static void
vlan_ifdetach_dispatch(netmsg_t msg)
{
struct netmsg_vlan *vmsg = (struct netmsg_vlan *)msg;
struct ifnet *ifp_p = vmsg->nv_ifp_p;
struct vlan_trunk *vlantrunks, *trunk;
struct vlan_entry *ifve;
vlantrunks = ifp_p->if_vlantrunks;
if (vlantrunks == NULL)
goto reply;
trunk = &vlantrunks[mycpuid];
while (ifp_p->if_vlantrunks &&
(ifve = LIST_FIRST(&trunk->vlan_list)) != NULL)
{
vlan_unconfig(ifve->ifv);
}
reply:
lwkt_replymsg(&vmsg->base.lmsg, 0);
}
static void
vlan_ifdetach(void *arg __unused, struct ifnet *ifp)
{
struct netmsg_vlan vmsg;
ASSERT_IFNET_NOT_SERIALIZED_ALL(ifp);
bzero(&vmsg, sizeof(vmsg));
netmsg_init(&vmsg.base, NULL, &curthread->td_msgport,
0, vlan_ifdetach_dispatch);
vmsg.nv_ifp_p = ifp;
lwkt_domsg(netisr_cpuport(0), &vmsg.base.lmsg, 0);
}
static int
vlan_clone_create(struct if_clone *ifc, int unit,
caddr_t params __unused, caddr_t data __unused)
{
struct ifvlan *ifv;
struct ifnet *ifp;
int vlan_size, i;
vlan_size = sizeof(struct ifvlan)
+ ((netisr_ncpus - 1) * sizeof(struct vlan_entry));
ifv = kmalloc(vlan_size, M_VLAN, M_WAITOK | M_ZERO);
SLIST_INIT(&ifv->vlan_mc_listhead);
for (i = 0; i < netisr_ncpus; ++i)
ifv->ifv_entries[i].ifv = ifv;
crit_enter();
LIST_INSERT_HEAD(&ifv_list, ifv, ifv_list);
crit_exit();
ifp = &ifv->ifv_if;
ifp->if_softc = ifv;
if_initname(ifp, "vlan", unit);
ifp->if_linkmib = &ifv->ifv_mib;
ifp->if_linkmiblen = sizeof ifv->ifv_mib;
ifp->if_init = vlan_init;
ifp->if_start = vlan_start;
ifp->if_ioctl = vlan_ioctl;
ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
ifq_set_ready(&ifp->if_snd);
ether_ifattach(ifp, ifv->ifv_ac.ac_enaddr, NULL);
ifp->if_data.ifi_type = IFT_L2VLAN;
ifp->if_data.ifi_hdrlen = EVL_ENCAPLEN;
return (0);
}
static int
vlan_clone_destroy(struct ifnet *ifp)
{
struct ifvlan *ifv = ifp->if_softc;
crit_enter();
LIST_REMOVE(ifv, ifv_list);
crit_exit();
vlan_unconfig(ifv);
ether_ifdetach(ifp);
kfree(ifv, M_VLAN);
return 0;
}
static void
vlan_init(void *xsc)
{
struct ifvlan *ifv = xsc;
struct ifnet *ifp = &ifv->ifv_if;
ASSERT_IFNET_SERIALIZED_ALL(ifp);
if (ifv->ifv_p != NULL)
ifp->if_flags |= IFF_RUNNING;
}
static void
vlan_start(struct ifnet *ifp, struct ifaltq_subque *ifsq)
{
struct ifvlan *ifv = ifp->if_softc;
struct ifnet *ifp_p = ifv->ifv_p;
struct mbuf *m;
lwkt_port_t p_port;
ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq);
ASSERT_ALTQ_SQ_SERIALIZED_HW(ifsq);
if (ifp_p == NULL) {
ifsq_purge(ifsq);
return;
}
if ((ifp->if_flags & IFF_RUNNING) == 0)
return;
p_port = netisr_cpuport(
ifsq_get_cpuid(ifq_get_subq_default(&ifp_p->if_snd)));
for (;;) {
struct netmsg_packet *nmp;
m = ifsq_dequeue(ifsq);
if (m == NULL)
break;
BPF_MTAP(ifp, m);
if ((ifp_p->if_flags & (IFF_UP | IFF_RUNNING)) !=
(IFF_UP | IFF_RUNNING)) {
m_freem(m);
IFNET_STAT_INC(ifp, collisions, 1);
continue;
}
m->m_pkthdr.ether_vlantag = ifv->ifv_tag;
m->m_flags |= M_VLANTAG;
nmp = &m->m_hdr.mh_netmsg;
netmsg_init(&nmp->base, NULL, &netisr_apanic_rport,
0, vlan_start_dispatch);
nmp->nm_packet = m;
nmp->base.lmsg.u.ms_resultp = ifp_p;
lwkt_sendmsg(p_port, &nmp->base.lmsg);
IFNET_STAT_INC(ifp, opackets, 1);
}
}
static void
vlan_input(struct mbuf *m)
{
struct ifvlan *ifv = NULL;
struct ifnet *rcvif;
struct vlan_trunk *vlantrunks;
struct vlan_entry *entry;
int cpuid = mycpuid;
ASSERT_NETISR_NCPUS(cpuid);
rcvif = m->m_pkthdr.rcvif;
KKASSERT(m->m_flags & M_VLANTAG);
vlantrunks = rcvif->if_vlantrunks;
cpu_ccfence();
if (vlantrunks == NULL) {
IFNET_STAT_INC(rcvif, noproto, 1);
m_freem(m);
return;
}
LIST_FOREACH(entry, &vlantrunks[cpuid].vlan_list, ifv_link) {
if (entry->ifv->ifv_tag ==
EVL_VLANOFTAG(m->m_pkthdr.ether_vlantag))
{
ifv = entry->ifv;
break;
}
}
if (ifv == NULL || ifv->ifv_p != rcvif) {
IFNET_STAT_INC(rcvif, noproto, 1);
m_freem(m);
return;
}
m->m_flags &= ~M_VLANTAG;
ether_reinput_oncpu(&ifv->ifv_if, m, REINPUT_RUNBPF);
}
static void
vlan_link_dispatch(netmsg_t msg)
{
struct netmsg_vlan *vmsg = (struct netmsg_vlan *)msg;
struct ifvlan *ifv = vmsg->nv_ifv;
struct ifnet *ifp_p = vmsg->nv_ifp_p;
struct vlan_entry *entry;
struct vlan_trunk *vlantrunks, *trunk;
int cpu = mycpuid;
vlantrunks = ifp_p->if_vlantrunks;
KASSERT(vlantrunks != NULL,
("vlan trunk has not been initialized yet"));
entry = &ifv->ifv_entries[cpu];
trunk = &vlantrunks[cpu];
crit_enter();
LIST_INSERT_HEAD(&trunk->vlan_list, entry, ifv_link);
crit_exit();
netisr_forwardmsg(&vmsg->base, cpu + 1);
}
static void
vlan_link(struct ifvlan *ifv, struct ifnet *ifp_p)
{
struct netmsg_vlan vmsg;
ASSERT_IFNET_NOT_SERIALIZED_ALL(&ifv->ifv_if);
if (ifp_p->if_vlantrunks == NULL) {
struct vlan_trunk *vlantrunks;
int i;
vlantrunks = kmalloc(sizeof(*vlantrunks) * netisr_ncpus,
M_VLAN,
M_WAITOK | M_ZERO);
for (i = 0; i < netisr_ncpus; ++i)
LIST_INIT(&vlantrunks[i].vlan_list);
ifp_p->if_vlantrunks = vlantrunks;
}
bzero(&vmsg, sizeof(vmsg));
netmsg_init(&vmsg.base, NULL, &curthread->td_msgport,
0, vlan_link_dispatch);
vmsg.nv_ifv = ifv;
vmsg.nv_ifp_p = ifp_p;
netisr_domsg(&vmsg.base, 0);
}
static void
vlan_config_dispatch(netmsg_t msg)
{
struct netmsg_vlan *vmsg = (struct netmsg_vlan *)msg;
struct ifvlan *ifv;
struct ifnet *ifp_p, *ifp;
struct sockaddr_dl *sdl1, *sdl2;
int error;
ifp_p = ifunit_netisr(vmsg->nv_parent_name);
if (ifp_p == NULL) {
error = ENOENT;
goto reply;
}
if (ifp_p->if_data.ifi_type != IFT_ETHER) {
error = EPROTONOSUPPORT;
goto reply;
}
ifv = vmsg->nv_ifv;
ifp = &ifv->ifv_if;
if (ifv->ifv_p) {
error = EBUSY;
goto reply;
}
vlan_link(ifv, ifp_p);
ifnet_serialize_all(ifp);
ifv->ifv_tag = vmsg->nv_vlantag;
if (ifp_p->if_capenable & IFCAP_VLAN_MTU)
ifp->if_mtu = ifp_p->if_mtu;
else
ifp->if_mtu = ifp_p->if_data.ifi_mtu - EVL_ENCAPLEN;
#define VLAN_INHERIT_FLAGS (IFF_BROADCAST | IFF_MULTICAST | \
IFF_SIMPLEX | IFF_POINTOPOINT)
ifp->if_flags &= ~VLAN_INHERIT_FLAGS;
ifp->if_flags |= (ifp_p->if_flags & VLAN_INHERIT_FLAGS);
#undef VLAN_INHERIT_FLAGS
sdl1 = IF_LLSOCKADDR(ifp);
sdl2 = IF_LLSOCKADDR(ifp_p);
sdl1->sdl_type = IFT_ETHER;
sdl1->sdl_alen = ETHER_ADDR_LEN;
bcopy(LLADDR(sdl2), LLADDR(sdl1), ETHER_ADDR_LEN);
bcopy(LLADDR(sdl2), ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
ifnet_deserialize_all(ifp);
vlan_setmulti(ifv, ifp_p);
vlan_setflags(ifv, ifp_p, 1);
ifv->ifv_p = ifp_p;
error = 0;
reply:
lwkt_replymsg(&vmsg->base.lmsg, error);
}
static int
vlan_config(struct ifvlan *ifv, const char *parent_name, uint16_t vlantag)
{
struct netmsg_vlan vmsg;
ASSERT_IFNET_NOT_SERIALIZED_ALL(&ifv->ifv_if);
bzero(&vmsg, sizeof(vmsg));
netmsg_init(&vmsg.base, NULL, &curthread->td_msgport,
0, vlan_config_dispatch);
vmsg.nv_ifv = ifv;
vmsg.nv_parent_name = parent_name;
vmsg.nv_vlantag = vlantag;
return lwkt_domsg(netisr_cpuport(0), &vmsg.base.lmsg, 0);
}
static void
vlan_unlink_dispatch(netmsg_t msg)
{
struct netmsg_vlan *vmsg = (struct netmsg_vlan *)msg;
struct ifvlan *ifv = vmsg->nv_ifv;
struct vlan_entry *entry;
int cpu = mycpuid;
KASSERT(vmsg->nv_ifp_p->if_vlantrunks != NULL,
("vlan trunk has not been initialized yet"));
entry = &ifv->ifv_entries[cpu];
crit_enter();
LIST_REMOVE(entry, ifv_link);
crit_exit();
netisr_forwardmsg(&vmsg->base, cpu + 1);
}
static void
vlan_unlink(struct ifvlan *ifv, struct ifnet *ifp_p)
{
struct vlan_trunk *vlantrunks = ifp_p->if_vlantrunks;
struct netmsg_vlan vmsg;
ASSERT_IFNET_NOT_SERIALIZED_ALL(&ifv->ifv_if);
KASSERT(ifp_p->if_vlantrunks != NULL,
("vlan trunk has not been initialized yet"));
bzero(&vmsg, sizeof(vmsg));
netmsg_init(&vmsg.base, NULL, &curthread->td_msgport,
0, vlan_unlink_dispatch);
vmsg.nv_ifv = ifv;
vmsg.nv_ifp_p = ifp_p;
netisr_domsg(&vmsg.base, 0);
crit_enter();
if (LIST_EMPTY(&vlantrunks[mycpuid].vlan_list)) {
ifp_p->if_vlantrunks = NULL;
netmsg_service_sync();
kfree(vlantrunks, M_VLAN);
}
crit_exit();
}
static void
vlan_unconfig_dispatch(netmsg_t msg)
{
struct netmsg_vlan *vmsg = (struct netmsg_vlan *)msg;
struct sockaddr_dl *sdl;
struct ifvlan *ifv;
struct ifnet *ifp_p, *ifp;
int error;
ifv = vmsg->nv_ifv;
ifp = &ifv->ifv_if;
if (ifp->if_flags & IFF_UP)
if_down(ifp);
ifnet_serialize_all(ifp);
ifp->if_flags &= ~IFF_RUNNING;
ifp_p = ifv->ifv_p;
ifv->ifv_p = NULL;
ifnet_deserialize_all(ifp);
if (ifp_p) {
vlan_clrmulti(ifv, ifp_p);
vlan_setflags(ifv, ifp_p, 0);
}
ifnet_serialize_all(ifp);
ifp->if_mtu = ETHERMTU;
sdl = IF_LLSOCKADDR(ifp);
sdl->sdl_type = IFT_ETHER;
sdl->sdl_alen = ETHER_ADDR_LEN;
bzero(LLADDR(sdl), ETHER_ADDR_LEN);
bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
ifnet_deserialize_all(ifp);
if (ifp_p != NULL && ifp_p->if_vlantrunks != NULL)
vlan_unlink(ifv, ifp_p);
error = 0;
lwkt_replymsg(&vmsg->base.lmsg, error);
}
static int
vlan_unconfig(struct ifvlan *ifv)
{
struct netmsg_vlan vmsg;
ASSERT_IFNET_NOT_SERIALIZED_ALL(&ifv->ifv_if);
bzero(&vmsg, sizeof(vmsg));
netmsg_init(&vmsg.base, NULL, &curthread->td_msgport,
0, vlan_unconfig_dispatch);
vmsg.nv_ifv = ifv;
return lwkt_domsg(netisr_cpuport(0), &vmsg.base.lmsg, 0);
}
static int
vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
{
struct ifvlan *ifv = ifp->if_softc;
struct ifreq *ifr = (struct ifreq *)data;
struct ifnet *ifp_p;
struct vlanreq vlr;
int error = 0;
ASSERT_IFNET_SERIALIZED_ALL(ifp);
switch (cmd) {
case SIOCGIFMEDIA:
ifp_p = ifv->ifv_p;
if (ifp_p != NULL) {
ifnet_deserialize_all(ifp);
ifnet_serialize_all(ifp_p);
error = ifp_p->if_ioctl(ifp_p, SIOCGIFMEDIA, data, cr);
ifnet_deserialize_all(ifp_p);
ifnet_serialize_all(ifp);
if (ifv->ifv_p == NULL || ifv->ifv_p != ifp_p) {
error = EINVAL;
}
if (error == 0) {
struct ifmediareq *ifmr;
ifmr = (struct ifmediareq *) data;
if (ifmr->ifm_count >= 1 && ifmr->ifm_ulist) {
ifmr->ifm_count = 1;
error = copyout(&ifmr->ifm_current,
ifmr->ifm_ulist,
sizeof(int));
}
}
} else {
error = EINVAL;
}
break;
case SIOCSIFMEDIA:
error = EINVAL;
break;
case SIOCSETVLAN:
error = copyin(ifr->ifr_data, &vlr, sizeof vlr);
if (error)
break;
ifnet_deserialize_all(ifp);
if (vlr.vlr_parent[0] == '\0')
error = vlan_unconfig(ifv);
else
error = vlan_config(ifv, vlr.vlr_parent, vlr.vlr_tag);
ifnet_serialize_all(ifp);
break;
case SIOCGETVLAN:
bzero(&vlr, sizeof(vlr));
if (ifv->ifv_p) {
strlcpy(vlr.vlr_parent, ifv->ifv_p->if_xname,
sizeof(vlr.vlr_parent));
vlr.vlr_tag = ifv->ifv_tag;
}
error = copyout(&vlr, ifr->ifr_data, sizeof vlr);
break;
case SIOCSIFFLAGS:
if (ifp->if_flags & IFF_UP)
ifp->if_init(ifp);
else
ifp->if_flags &= ~IFF_RUNNING;
ifnet_deserialize_all(ifp);
error = vlan_config_flags(ifv);
ifnet_serialize_all(ifp);
break;
case SIOCADDMULTI:
case SIOCDELMULTI:
ifnet_deserialize_all(ifp);
error = vlan_config_multi(ifv);
ifnet_serialize_all(ifp);
break;
default:
error = ether_ioctl(ifp, cmd, data);
break;
}
return error;
}
static void
vlan_multi_dispatch(netmsg_t msg)
{
struct netmsg_vlan *vmsg = (struct netmsg_vlan *)msg;
struct ifvlan *ifv = vmsg->nv_ifv;
int error = 0;
if (ifv->ifv_p != NULL)
error = vlan_setmulti(ifv, ifv->ifv_p);
lwkt_replymsg(&vmsg->base.lmsg, error);
}
static int
vlan_config_multi(struct ifvlan *ifv)
{
struct netmsg_vlan vmsg;
ASSERT_IFNET_NOT_SERIALIZED_ALL(&ifv->ifv_if);
bzero(&vmsg, sizeof(vmsg));
netmsg_init(&vmsg.base, NULL, &curthread->td_msgport,
0, vlan_multi_dispatch);
vmsg.nv_ifv = ifv;
return lwkt_domsg(netisr_cpuport(0), &vmsg.base.lmsg, 0);
}
static void
vlan_flags_dispatch(netmsg_t msg)
{
struct netmsg_vlan *vmsg = (struct netmsg_vlan *)msg;
struct ifvlan *ifv = vmsg->nv_ifv;
int error = 0;
if (ifv->ifv_p != NULL)
error = vlan_setflags(ifv, ifv->ifv_p, 1);
lwkt_replymsg(&vmsg->base.lmsg, error);
}
static int
vlan_config_flags(struct ifvlan *ifv)
{
struct netmsg_vlan vmsg;
ASSERT_IFNET_NOT_SERIALIZED_ALL(&ifv->ifv_if);
bzero(&vmsg, sizeof(vmsg));
netmsg_init(&vmsg.base, NULL, &curthread->td_msgport,
0, vlan_flags_dispatch);
vmsg.nv_ifv = ifv;
return lwkt_domsg(netisr_cpuport(0), &vmsg.base.lmsg, 0);
}