-/* $OpenBSD: if_vlan.c,v 1.104 2014/05/05 10:00:45 henning Exp $ */
+/* $OpenBSD: if_vlan.c,v 1.105 2014/05/14 21:48:50 henning Exp $ */
/*
* Copyright 1998 Massachusetts Institute of Technology
int
vlan_clone_create(struct if_clone *ifc, int unit)
{
- struct ifvlan *ifv;
- struct ifnet *ifp;
+ struct ifvlan *ifv;
+ struct ifnet *ifp;
- ifv = malloc(sizeof(*ifv), M_DEVBUF, M_NOWAIT|M_ZERO);
- if (!ifv)
+ if ((ifv = malloc(sizeof(*ifv), M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
return (ENOMEM);
LIST_INIT(&ifv->vlan_mc_listhead);
int
vlan_clone_destroy(struct ifnet *ifp)
{
- struct ifvlan *ifv = ifp->if_softc;
+ struct ifvlan *ifv = ifp->if_softc;
vlan_unconfig(ifp, NULL);
ether_ifdetach(ifp);
if_detach(ifp);
-
free(ifv, M_DEVBUF);
return (0);
}
void
vlan_ifdetach(void *ptr)
{
- struct ifvlan *ifv = (struct ifvlan *)ptr;
-
+ struct ifvlan *ifv = ptr;
vlan_clone_destroy(&ifv->ifv_if);
}
void
vlan_start(struct ifnet *ifp)
{
- struct ifvlan *ifv;
- struct ifnet *p;
- struct mbuf *m;
- int error;
+ struct ifvlan *ifv;
+ struct ifnet *p;
+ struct mbuf *m;
+ int error;
ifv = ifp->if_softc;
p = ifv->ifv_p;
if ((p->if_flags & (IFF_UP|IFF_RUNNING)) !=
(IFF_UP|IFF_RUNNING)) {
IF_DROP(&p->if_snd);
- /* XXX stats */
ifp->if_oerrors++;
m_freem(m);
continue;
ifp->if_opackets++;
if_start(p);
}
-
- return;
}
/*
int
vlan_input(struct ether_header *eh, struct mbuf *m)
{
- struct ifvlan *ifv;
- struct ifnet *ifp = m->m_pkthdr.rcvif;
- struct vlan_taghash *tagh;
- u_int tag;
- u_int16_t etype;
+ struct ifvlan *ifv;
+ struct ifnet *ifp = m->m_pkthdr.rcvif;
+ struct vlan_taghash *tagh;
+ u_int tag;
+ u_int16_t etype;
if (m->m_flags & M_VLANTAG) {
etype = ETHERTYPE_VLAN;
#if NBPFILTER > 0
if (ifv->ifv_if.if_bpf)
- bpf_mtap_hdr(ifv->ifv_if.if_bpf, (char *)eh, ETHER_HDR_LEN,
- m, BPF_DIRECTION_IN);
+ bpf_mtap_hdr(ifv->ifv_if.if_bpf, (char *)eh, ETHER_HDR_LEN, m,
+ BPF_DIRECTION_IN);
#endif
/*
if ((m->m_flags & (M_BCAST|M_MCAST)) == 0 &&
(ifp->if_flags & IFF_PROMISC) &&
(ifv->ifv_if.if_flags & IFF_PROMISC) == 0) {
- struct arpcom *ac = &ifv->ifv_ac;
- if (bcmp(ac->ac_enaddr, eh->ether_dhost, ETHER_ADDR_LEN)) {
+ if (bcmp(&ifv->ifv_ac.ac_enaddr, eh->ether_dhost,
+ ETHER_ADDR_LEN)) {
m_freem(m);
return (0);
}
int
vlan_config(struct ifvlan *ifv, struct ifnet *p, u_int16_t tag)
{
- struct sockaddr_dl *sdl1, *sdl2;
- struct vlan_taghash *tagh;
- u_int flags;
- int s;
+ struct sockaddr_dl *sdl1, *sdl2;
+ struct vlan_taghash *tagh;
+ u_int flags;
+ int s;
if (p->if_type != IFT_ETHER)
return EPROTONOSUPPORT;
/* Remember existing interface flags and reset the interface */
flags = ifv->ifv_flags;
vlan_unconfig(&ifv->ifv_if, p);
-
ifv->ifv_p = p;
+ ifv->ifv_if.if_baudrate = p->if_baudrate;
if (p->if_capabilities & IFCAP_VLAN_MTU)
ifv->ifv_if.if_mtu = p->if_mtu;
- else {
- /*
- * This will be incompatible with strict
- * 802.1Q implementations
- */
+ else
ifv->ifv_if.if_mtu = p->if_mtu - EVL_ENCAPLEN;
-#ifdef DIAGNOSTIC
- printf("%s: initialized with non-standard mtu %u (parent %s)\n",
- ifv->ifv_if.if_xname, ifv->ifv_if.if_mtu,
- ifv->ifv_p->if_xname);
-#endif
- }
ifv->ifv_if.if_flags = p->if_flags &
(IFF_UP | IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
vlan_set_promisc(&ifv->ifv_if);
}
- /*
- * Inherit baudrate from the parent. An SNMP agent would use this
- * information.
- */
- ifv->ifv_if.if_baudrate = p->if_baudrate;
-
/*
* If the parent interface can do hardware-assisted
* VLAN encapsulation, then propagate its hardware-
vlan_vlandev_state(ifv);
splx(s);
- return 0;
+ return (0);
}
int
vlan_unconfig(struct ifnet *ifp, struct ifnet *newp)
{
- struct sockaddr_dl *sdl;
- struct ifvlan *ifv;
- struct ifnet *p;
- int s;
+ struct sockaddr_dl *sdl;
+ struct ifvlan *ifv;
+ struct ifnet *p;
+ int s;
ifv = ifp->if_softc;
- p = ifv->ifv_p;
- if (p == NULL)
+ if ((p = ifv->ifv_p) == NULL)
return 0;
/* Unset promisc mode on the interface and its parent */
bzero(LLADDR(sdl), ETHER_ADDR_LEN);
bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
- return 0;
+ return (0);
}
void
vlan_vlandev_state(void *v)
{
- struct ifvlan *ifv = v;
+ struct ifvlan *ifv = v;
if (ifv->ifv_if.if_link_state == ifv->ifv_p->if_link_state)
return;
int
vlan_set_promisc(struct ifnet *ifp)
{
- struct ifvlan *ifv = ifp->if_softc;
- int error = 0;
+ struct ifvlan *ifv = ifp->if_softc;
+ int error = 0;
if ((ifp->if_flags & IFF_PROMISC) != 0) {
- if ((ifv->ifv_flags & IFVF_PROMISC) == 0) {
- error = ifpromisc(ifv->ifv_p, 1);
- if (error == 0)
+ if ((ifv->ifv_flags & IFVF_PROMISC) == 0)
+ if ((error = ifpromisc(ifv->ifv_p, 1)) == 0)
ifv->ifv_flags |= IFVF_PROMISC;
- }
} else {
- if ((ifv->ifv_flags & IFVF_PROMISC) != 0) {
- error = ifpromisc(ifv->ifv_p, 0);
- if (error == 0)
+ if ((ifv->ifv_flags & IFVF_PROMISC) != 0)
+ if ((error = ifpromisc(ifv->ifv_p, 0)) == 0)
ifv->ifv_flags &= ~IFVF_PROMISC;
- }
}
-
return (0);
}
int
vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
- struct proc *p = curproc; /* XXX */
- struct ifaddr *ifa;
- struct ifnet *pr;
- struct ifreq *ifr;
- struct ifvlan *ifv;
- struct vlanreq vlr;
- int error = 0, p_mtu = 0, s;
+ struct proc *p = curproc; /* XXX */
+ struct ifaddr *ifa;
+ struct ifnet *pr;
+ struct ifreq *ifr;
+ struct ifvlan *ifv;
+ struct vlanreq vlr;
+ int error = 0, p_mtu = 0, s;
ifr = (struct ifreq *)data;
ifa = (struct ifaddr *)data;
case SIOCSIFADDR:
if (ifv->ifv_p != NULL) {
ifp->if_flags |= IFF_UP;
-
- switch (ifa->ifa_addr->sa_family) {
#ifdef INET
- case AF_INET:
+ if (ifa->ifa_addr->sa_family == AF_INET)
arp_ifinit(&ifv->ifv_ac, ifa);
- break;
#endif
- default:
- break;
- }
- } else {
+ } else
error = EINVAL;
- }
break;
case SIOCGIFADDR:
{
- struct sockaddr *sa;
+ struct sockaddr *sa;
- sa = (struct sockaddr *) &ifr->ifr_data;
+ sa = (struct sockaddr *)&ifr->ifr_data;
bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr,
(caddr_t) sa->sa_data, ETHER_ADDR_LEN);
}
int
vlan_ether_addmulti(struct ifvlan *ifv, struct ifreq *ifr)
{
- struct ifnet *ifp = ifv->ifv_p; /* Parent. */
- struct vlan_mc_entry *mc;
- u_int8_t addrlo[ETHER_ADDR_LEN], addrhi[ETHER_ADDR_LEN];
- int error;
-
- /* XXX: sa_len is too small for such comparison
- if (ifr->ifr_addr.sa_len > sizeof(struct sockaddr_storage))
- return (EINVAL);
- */
+ struct ifnet *ifp = ifv->ifv_p;
+ struct vlan_mc_entry *mc;
+ u_int8_t addrlo[ETHER_ADDR_LEN], addrhi[ETHER_ADDR_LEN];
+ int error;
error = ether_addmulti(ifr, (struct arpcom *)&ifv->ifv_ac);
if (error != ENETRESET)
* about it. Also, remember this multicast address so that
* we can delete them on unconfigure.
*/
- mc = malloc(sizeof(*mc), M_DEVBUF, M_NOWAIT);
- if (mc == NULL) {
+ if ((mc = malloc(sizeof(*mc), M_DEVBUF, M_NOWAIT)) == NULL) {
error = ENOMEM;
goto alloc_failed;
}
memcpy(&mc->mc_addr, &ifr->ifr_addr, ifr->ifr_addr.sa_len);
LIST_INSERT_HEAD(&ifv->vlan_mc_listhead, mc, mc_entries);
- error = (*ifp->if_ioctl)(ifp, SIOCADDMULTI, (caddr_t)ifr);
- if (error != 0)
+ if ((error = (*ifp->if_ioctl)(ifp, SIOCADDMULTI, (caddr_t)ifr)) != 0)
goto ioctl_failed;
return (error);
int
vlan_ether_delmulti(struct ifvlan *ifv, struct ifreq *ifr)
{
- struct ifnet *ifp = ifv->ifv_p; /* Parent. */
- struct ether_multi *enm;
- struct vlan_mc_entry *mc;
- u_int8_t addrlo[ETHER_ADDR_LEN], addrhi[ETHER_ADDR_LEN];
- int error;
+ struct ifnet *ifp = ifv->ifv_p;
+ struct ether_multi *enm;
+ struct vlan_mc_entry *mc;
+ u_int8_t addrlo[ETHER_ADDR_LEN], addrhi[ETHER_ADDR_LEN];
+ int error;
/*
* Find a key to lookup vlan_mc_entry. We have to do this
if (mc == NULL)
return (EINVAL);
- error = ether_delmulti(ifr, (struct arpcom *)&ifv->ifv_ac);
- if (error != ENETRESET)
+ if ((error = ether_delmulti(ifr, (struct arpcom *)&ifv->ifv_ac)) != 0)
return (error);
/* We no longer use this multicast address. Tell parent so. */
- error = (*ifp->if_ioctl)(ifp, SIOCDELMULTI, (caddr_t)ifr);
- if (error == 0) {
+ if ((error = (*ifp->if_ioctl)(ifp, SIOCDELMULTI, (caddr_t)ifr)) != 0) {
/* And forget about this address. */
LIST_REMOVE(mc, mc_entries);
free(mc, M_DEVBUF);
void
vlan_ether_purgemulti(struct ifvlan *ifv)
{
- struct ifnet *ifp = ifv->ifv_p; /* Parent. */
- struct vlan_mc_entry *mc;
+ struct ifnet *ifp = ifv->ifv_p;
+ struct vlan_mc_entry *mc;
union {
struct ifreq ifreq;
struct {
- char ifr_name[IFNAMSIZ];
- struct sockaddr_storage ifr_ss;
+ char ifr_name[IFNAMSIZ];
+ struct sockaddr_storage ifr_ss;
} ifreq_storage;
} ifreq;
- struct ifreq *ifr = &ifreq.ifreq;
+ struct ifreq *ifr = &ifreq.ifreq;
memcpy(ifr->ifr_name, ifp->if_xname, IFNAMSIZ);
while ((mc = LIST_FIRST(&ifv->vlan_mc_listhead)) != NULL) {
void
vlan_ether_resetmulti(struct ifvlan *ifv, struct ifnet *p)
{
- struct ifnet *ifp = ifv->ifv_p; /* Parent. */
- struct vlan_mc_entry *mc;
+ struct ifnet *ifp = ifv->ifv_p;
+ struct vlan_mc_entry *mc;
union {
struct ifreq ifreq;
struct {
- char ifr_name[IFNAMSIZ];
- struct sockaddr_storage ifr_ss;
+ char ifr_name[IFNAMSIZ];
+ struct sockaddr_storage ifr_ss;
} ifreq_storage;
} ifreq;
- struct ifreq *ifr = &ifreq.ifreq;
+ struct ifreq *ifr = &ifreq.ifreq;
if (p == NULL) {
vlan_ether_purgemulti(ifv);