summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2014-05-14 21:48:51 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2014-05-14 21:48:51 +0000
commit939d777cf861c607d7ea372a6c7d5a7b10fc7aa5 (patch)
treebec5cdd3bbcd6dd40223431b720d3046a0842bf1 /sys
parenta92a372e193d4f3f133a56ed835be97db257b42f (diff)
improve style - basically, what my fingers did at Marrakesh airport when
waiting for the flight home from m2k14. ok reyk
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if_vlan.c190
1 files changed, 73 insertions, 117 deletions
diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c
index 3a58d4d6e3f..300f55738de 100644
--- a/sys/net/if_vlan.c
+++ b/sys/net/if_vlan.c
@@ -1,4 +1,4 @@
-/* $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
@@ -124,11 +124,10 @@ vlanattach(int count)
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);
@@ -160,12 +159,11 @@ vlan_clone_create(struct if_clone *ifc, int unit)
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);
}
@@ -173,8 +171,7 @@ vlan_clone_destroy(struct ifnet *ifp)
void
vlan_ifdetach(void *ptr)
{
- struct ifvlan *ifv = (struct ifvlan *)ptr;
-
+ struct ifvlan *ifv = ptr;
vlan_clone_destroy(&ifv->ifv_if);
}
@@ -193,10 +190,10 @@ vlan_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
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;
@@ -209,7 +206,6 @@ vlan_start(struct ifnet *ifp)
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;
@@ -237,8 +233,6 @@ vlan_start(struct ifnet *ifp)
ifp->if_opackets++;
if_start(p);
}
-
- return;
}
/*
@@ -247,11 +241,11 @@ vlan_start(struct ifnet *ifp)
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;
@@ -304,8 +298,8 @@ vlan_input(struct ether_header *eh, struct mbuf *m)
#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
/*
@@ -315,8 +309,8 @@ vlan_input(struct ether_header *eh, struct mbuf *m)
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);
}
@@ -331,10 +325,10 @@ vlan_input(struct ether_header *eh, struct mbuf *m)
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;
@@ -344,23 +338,13 @@ vlan_config(struct ifvlan *ifv, struct ifnet *p, u_int16_t tag)
/* 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);
@@ -372,12 +356,6 @@ vlan_config(struct ifvlan *ifv, struct ifnet *p, u_int16_t tag)
}
/*
- * 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-
* assisted checksumming flags.
@@ -423,20 +401,19 @@ vlan_config(struct ifvlan *ifv, struct ifnet *p, u_int16_t tag)
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 */
@@ -477,13 +454,13 @@ vlan_unconfig(struct ifnet *ifp, struct ifnet *newp)
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;
@@ -496,36 +473,31 @@ vlan_vlandev_state(void *v)
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;
@@ -535,26 +507,19 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t 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);
}
@@ -649,15 +614,10 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
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)
@@ -668,8 +628,7 @@ vlan_ether_addmulti(struct ifvlan *ifv, struct ifreq *ifr)
* 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;
}
@@ -683,8 +642,7 @@ vlan_ether_addmulti(struct ifvlan *ifv, struct ifreq *ifr)
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);
@@ -701,11 +659,11 @@ vlan_ether_addmulti(struct ifvlan *ifv, struct ifreq *ifr)
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
@@ -725,13 +683,11 @@ vlan_ether_delmulti(struct ifvlan *ifv, struct ifreq *ifr)
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);
@@ -747,16 +703,16 @@ vlan_ether_delmulti(struct ifvlan *ifv, struct ifreq *ifr)
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) {
@@ -770,16 +726,16 @@ vlan_ether_purgemulti(struct ifvlan *ifv)
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);