summaryrefslogtreecommitdiff
path: root/sys/net/trunklacp.c
diff options
context:
space:
mode:
authorBrad Smith <brad@cvs.openbsd.org>2008-12-01 10:40:58 +0000
committerBrad Smith <brad@cvs.openbsd.org>2008-12-01 10:40:58 +0000
commit4fffbd14bc03746b7ef02fc8c8132fcc5d37434b (patch)
tree53af6b3546e5ba263d9ab1a861f62f5f292aa86a /sys/net/trunklacp.c
parent485277f07e8b4b0cbe0a2436acecb42affa85813 (diff)
A bit more cleanup.
ok mpf@
Diffstat (limited to 'sys/net/trunklacp.c')
-rw-r--r--sys/net/trunklacp.c170
1 files changed, 63 insertions, 107 deletions
diff --git a/sys/net/trunklacp.c b/sys/net/trunklacp.c
index 517c126222a..38d52bc5d69 100644
--- a/sys/net/trunklacp.c
+++ b/sys/net/trunklacp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: trunklacp.c,v 1.8 2008/11/08 01:00:01 mpf Exp $ */
+/* $OpenBSD: trunklacp.c,v 1.9 2008/12/01 10:40:57 brad Exp $ */
/* $NetBSD: ieee8023ad_lacp.c,v 1.3 2005/12/11 12:24:54 christos Exp $ */
/* $FreeBSD:ieee8023ad_lacp.c,v 1.15 2008/03/16 19:25:30 thompsa Exp $ */
@@ -276,9 +276,8 @@ lacp_pdu_input(struct lacp_port *lp, struct ether_header *eh, struct mbuf *m)
* the future protocol revisions.
*/
#if 0
- if (du->ldu_sph.sph_version != 1) {
+ if (du->ldu_sph.sph_version != 1)
goto bad;
- }
#endif
/*
@@ -286,9 +285,8 @@ lacp_pdu_input(struct lacp_port *lp, struct ether_header *eh, struct mbuf *m)
* future protocol revisions. (IEEE 802.3-2005 43.4.12)
*/
if (tlv_check(du, sizeof(*du), &du->ldu_tlv_actor,
- lacp_info_tlv_template, 0)) {
+ lacp_info_tlv_template, 0))
goto bad;
- }
#if defined(LACP_DEBUG)
LACP_DPRINTF((lp, "lacpdu receive\n"));
@@ -370,9 +368,8 @@ lacp_xmit_lacpdu(struct lacp_port *lp)
int error;
m = m_gethdr(M_DONTWAIT, MT_DATA);
- if (m == NULL) {
+ if (m == NULL)
return (ENOMEM);
- }
m->m_len = m->m_pkthdr.len = sizeof(*eh) + sizeof(*du);
eh = mtod(m, struct ether_header *);
@@ -426,9 +423,8 @@ lacp_xmit_marker(struct lacp_port *lp)
int error;
m = m_gethdr(M_DONTWAIT, MT_DATA);
- if (m == NULL) {
+ if (m == NULL)
return (ENOMEM);
- }
m->m_len = m->m_pkthdr.len = sizeof(*eh) + sizeof(*mdu);
eh = mtod(m, struct ether_header *);
@@ -564,9 +560,8 @@ lacp_port_destroy(struct trunk_port *tp)
struct lacp_port *lp = LACP_PORT(tp);
int i;
- for (i = 0; i < LACP_NTIMER; i++) {
+ for (i = 0; i < LACP_NTIMER; i++)
LACP_TIMER_DISARM(lp, i);
- }
lacp_disable_collecting(lp);
lacp_disable_distributing(lp);
@@ -651,9 +646,8 @@ lacp_disable_distributing(struct lacp_port *lp)
char buf[LACP_LAGIDSTR_MAX+1];
#endif /* defined(LACP_DEBUG) */
- if (la == NULL || (lp->lp_state & LACP_STATE_DISTRIBUTING) == 0) {
+ if (la == NULL || (lp->lp_state & LACP_STATE_DISTRIBUTING) == 0)
return;
- }
KASSERT(!TAILQ_EMPTY(&la->la_ports));
KASSERT(la->la_nports > 0);
@@ -686,9 +680,8 @@ lacp_enable_distributing(struct lacp_port *lp)
char buf[LACP_LAGIDSTR_MAX+1];
#endif /* defined(LACP_DEBUG) */
- if ((lp->lp_state & LACP_STATE_DISTRIBUTING) != 0) {
+ if ((lp->lp_state & LACP_STATE_DISTRIBUTING) != 0)
return;
- }
LACP_DPRINTF((lp, "enable distributing on aggregator %s, "
"nports %d -> %d\n",
@@ -816,9 +809,8 @@ lacp_suppress_distributing(struct lacp_softc *lsc, struct lacp_aggregator *la)
{
struct lacp_port *lp;
- if (lsc->lsc_active_aggregator != la) {
+ if (lsc->lsc_active_aggregator != la)
return;
- }
LACP_DPRINTF((NULL, "%s\n", __func__));
lsc->lsc_suppress_distributing = 1;
@@ -863,9 +855,8 @@ lacp_aggregator_bandwidth(struct lacp_aggregator *la)
u_int64_t speed;
lp = TAILQ_FIRST(&la->la_ports);
- if (lp == NULL) {
+ if (lp == NULL)
return (0);
- }
speed = lp->lp_ifp->if_baudrate;
speed *= la->la_nports;
@@ -896,9 +887,8 @@ lacp_select_active_aggregator(struct lacp_softc *lsc)
TAILQ_FOREACH(la, &lsc->lsc_aggregators, la_q) {
u_int64_t speed;
- if (la->la_nports == 0) {
+ if (la->la_nports == 0)
continue;
- }
speed = lacp_aggregator_bandwidth(la);
LACP_DPRINTF((NULL, "%s, speed=%jd, nports=%d\n",
@@ -930,9 +920,9 @@ lacp_select_active_aggregator(struct lacp_softc *lsc)
LACP_DPRINTF((NULL, "old %s\n",
lacp_format_lagid_aggregator(lsc->lsc_active_aggregator,
buf, sizeof(buf))));
- } else {
+ } else
LACP_DPRINTF((NULL, "active aggregator not changed\n"));
- }
+
LACP_DPRINTF((NULL, "new %s\n",
lacp_format_lagid_aggregator(best_la, buf, sizeof(buf))));
#endif /* defined(LACP_DEBUG) */
@@ -940,9 +930,8 @@ lacp_select_active_aggregator(struct lacp_softc *lsc)
if (lsc->lsc_active_aggregator != best_la) {
lsc->lsc_active_aggregator = best_la;
lacp_update_portmap(lsc);
- if (best_la) {
+ if (best_la)
lacp_suppress_distributing(lsc, best_la);
- }
}
}
@@ -1061,9 +1050,8 @@ lacp_aggregator_delref(struct lacp_softc *lsc, struct lacp_aggregator *la)
KASSERT(la->la_refcnt > la->la_nports);
la->la_refcnt--;
- if (la->la_refcnt > 0) {
+ if (la->la_refcnt > 0)
return;
- }
KASSERT(la->la_refcnt == 0);
KASSERT(lsc->lsc_active_aggregator != la);
@@ -1122,21 +1110,17 @@ lacp_aggregator_is_compatible(const struct lacp_aggregator *la,
const struct lacp_port *lp)
{
if (!(lp->lp_state & LACP_STATE_AGGREGATION) ||
- !(lp->lp_partner.lip_state & LACP_STATE_AGGREGATION)) {
+ !(lp->lp_partner.lip_state & LACP_STATE_AGGREGATION))
return (0);
- }
- if (!(la->la_actor.lip_state & LACP_STATE_AGGREGATION)) {
+ if (!(la->la_actor.lip_state & LACP_STATE_AGGREGATION))
return (0);
- }
- if (!lacp_peerinfo_is_compatible(&la->la_partner, &lp->lp_partner)) {
+ if (!lacp_peerinfo_is_compatible(&la->la_partner, &lp->lp_partner))
return (0);
- }
- if (!lacp_peerinfo_is_compatible(&la->la_actor, &lp->lp_actor)) {
+ if (!lacp_peerinfo_is_compatible(&la->la_actor, &lp->lp_actor))
return (0);
- }
return (1);
}
@@ -1146,13 +1130,11 @@ lacp_peerinfo_is_compatible(const struct lacp_peerinfo *a,
const struct lacp_peerinfo *b)
{
if (memcmp(&a->lip_systemid, &b->lip_systemid,
- sizeof(a->lip_systemid))) {
+ sizeof(a->lip_systemid)))
return (0);
- }
- if (memcmp(&a->lip_key, &b->lip_key, sizeof(a->lip_key))) {
+ if (memcmp(&a->lip_key, &b->lip_key, sizeof(a->lip_key)))
return (0);
- }
return (1);
}
@@ -1187,9 +1169,8 @@ lacp_select(struct lacp_port *lp)
char buf[LACP_LAGIDSTR_MAX+1];
#endif
- if (lp->lp_aggregator) {
+ if (lp->lp_aggregator)
return;
- }
KASSERT(!LACP_TIMER_ISARMED(lp, LACP_TIMER_WAIT_WHILE));
@@ -1198,9 +1179,8 @@ lacp_select(struct lacp_port *lp)
buf, sizeof(buf))));
TAILQ_FOREACH(la, &lsc->lsc_aggregators, la_q) {
- if (lacp_aggregator_is_compatible(la, lp)) {
+ if (lacp_aggregator_is_compatible(la, lp))
break;
- }
}
if (la == NULL) {
@@ -1242,9 +1222,8 @@ lacp_unselect(struct lacp_port *lp)
KASSERT(!LACP_TIMER_ISARMED(lp, LACP_TIMER_WAIT_WHILE));
- if (la == NULL) {
+ if (la == NULL)
return;
- }
lp->lp_aggregator = NULL;
lacp_aggregator_delref(lsc, la);
@@ -1270,45 +1249,39 @@ re_eval:
new_state = lp->lp_mux_state;
switch (lp->lp_mux_state) {
case LACP_MUX_DETACHED:
- if (selected != LACP_UNSELECTED) {
+ if (selected != LACP_UNSELECTED)
new_state = LACP_MUX_WAITING;
- }
break;
case LACP_MUX_WAITING:
KASSERT(la->la_pending > 0 ||
!LACP_TIMER_ISARMED(lp, LACP_TIMER_WAIT_WHILE));
- if (selected == LACP_SELECTED && la->la_pending == 0) {
+ if (selected == LACP_SELECTED && la->la_pending == 0)
new_state = LACP_MUX_ATTACHED;
- } else if (selected == LACP_UNSELECTED) {
+ else if (selected == LACP_UNSELECTED)
new_state = LACP_MUX_DETACHED;
- }
break;
case LACP_MUX_ATTACHED:
- if (selected == LACP_SELECTED && p_sync) {
+ if (selected == LACP_SELECTED && p_sync)
new_state = LACP_MUX_COLLECTING;
- } else if (selected != LACP_SELECTED) {
+ else if (selected != LACP_SELECTED)
new_state = LACP_MUX_DETACHED;
- }
break;
case LACP_MUX_COLLECTING:
- if (selected == LACP_SELECTED && p_sync && p_collecting) {
+ if (selected == LACP_SELECTED && p_sync && p_collecting)
new_state = LACP_MUX_DISTRIBUTING;
- } else if (selected != LACP_SELECTED || !p_sync) {
+ else if (selected != LACP_SELECTED || !p_sync)
new_state = LACP_MUX_ATTACHED;
- }
break;
case LACP_MUX_DISTRIBUTING:
- if (selected != LACP_SELECTED || !p_sync || !p_collecting) {
+ if (selected != LACP_SELECTED || !p_sync || !p_collecting)
new_state = LACP_MUX_COLLECTING;
- }
break;
default:
panic("%s: unknown state", __func__);
}
- if (lp->lp_mux_state == new_state) {
+ if (lp->lp_mux_state == new_state)
return;
- }
lacp_set_mux(lp, new_state);
goto re_eval;
@@ -1319,9 +1292,8 @@ lacp_set_mux(struct lacp_port *lp, enum lacp_mux_state new_state)
{
struct lacp_aggregator *la = lp->lp_aggregator;
- if (lp->lp_mux_state == new_state) {
+ if (lp->lp_mux_state == new_state)
return;
- }
switch (new_state) {
case LACP_MUX_DETACHED:
@@ -1387,9 +1359,8 @@ void
lacp_sm_ptx_update_timeout(struct lacp_port *lp, u_int8_t oldpstate)
{
if (LACP_STATE_EQ(oldpstate, lp->lp_partner.lip_state,
- LACP_STATE_TIMEOUT)) {
+ LACP_STATE_TIMEOUT))
return;
- }
LACP_DPRINTF((lp, "partner timeout changed\n"));
@@ -1404,9 +1375,8 @@ lacp_sm_ptx_update_timeout(struct lacp_port *lp, u_int8_t oldpstate)
LACP_TIMER_DISARM(lp, LACP_TIMER_PERIODIC);
/* if timeout has been shortened, assert NTT. */
- if ((lp->lp_partner.lip_state & LACP_STATE_TIMEOUT)) {
+ if ((lp->lp_partner.lip_state & LACP_STATE_TIMEOUT))
lacp_sm_assert_ntt(lp);
- }
}
void
@@ -1422,9 +1392,8 @@ lacp_sm_ptx_tx_schedule(struct lacp_port *lp)
return;
}
- if (LACP_TIMER_ISARMED(lp, LACP_TIMER_PERIODIC)) {
+ if (LACP_TIMER_ISARMED(lp, LACP_TIMER_PERIODIC))
return;
- }
timeout = (lp->lp_partner.lip_state & LACP_STATE_TIMEOUT) ?
LACP_FAST_PERIODIC_TIME : LACP_SLOW_PERIODIC_TIME;
@@ -1444,15 +1413,13 @@ lacp_sm_rx(struct lacp_port *lp, const struct lacpdu *du)
int timeout;
/* check LACP_DISABLED first */
- if (!(lp->lp_state & LACP_STATE_AGGREGATION)) {
+ if (!(lp->lp_state & LACP_STATE_AGGREGATION))
return;
- }
/* check loopback condition. */
if (!lacp_compare_systemid(&du->ldu_actor.lip_systemid,
- &lp->lp_actor.lip_systemid)) {
+ &lp->lp_actor.lip_systemid))
return;
- }
/*
* EXPIRED, DEFAULTED, CURRENT -> CURRENT
@@ -1520,9 +1487,8 @@ lacp_sm_rx_record_pdu(struct lacp_port *lp, const struct lacpdu *du)
!lacp_compare_peerinfo(&lp->lp_actor, &du->ldu_partner))
|| (du->ldu_partner.lip_state & LACP_STATE_AGGREGATION) == 0)) {
/* XXX nothing? */
- } else {
+ } else
lp->lp_partner.lip_state &= ~LACP_STATE_SYNC;
- }
lp->lp_state &= ~LACP_STATE_DEFAULTED;
@@ -1609,9 +1575,8 @@ lacp_sm_tx(struct lacp_port *lp)
lp->lp_flags &= ~LACP_PORT_NTT;
}
- if (!(lp->lp_flags & LACP_PORT_NTT)) {
+ if (!(lp->lp_flags & LACP_PORT_NTT))
return;
- }
/* Rate limit to 3 PDUs per LACP_FAST_PERIODIC_TIME */
if (ppsratecheck(&lp->lp_last_lacpdu, &lp->lp_lacpdu_sent,
@@ -1622,12 +1587,11 @@ lacp_sm_tx(struct lacp_port *lp)
error = lacp_xmit_lacpdu(lp);
- if (error == 0) {
+ if (error == 0)
lp->lp_flags &= ~LACP_PORT_NTT;
- } else {
+ else
LACP_DPRINTF((lp, "lacpdu transmit failure, error %d\n",
error));
- }
}
void
@@ -1643,12 +1607,11 @@ lacp_run_timers(struct lacp_port *lp)
for (i = 0; i < LACP_NTIMER; i++) {
KASSERT(lp->lp_timer[i] >= 0);
- if (lp->lp_timer[i] == 0) {
+ if (lp->lp_timer[i] == 0)
continue;
- } else if (--lp->lp_timer[i] <= 0) {
- if (lacp_timer_funcs[i]) {
+ else if (--lp->lp_timer[i] <= 0) {
+ if (lacp_timer_funcs[i])
(*lacp_timer_funcs[i])(lp);
- }
}
}
}
@@ -1663,38 +1626,33 @@ lacp_marker_input(struct lacp_port *lp, struct ether_header *eh, struct mbuf *m)
int error = 0;
int pending = 0;
- if (m->m_pkthdr.len != sizeof(*mdu)) {
+ if (m->m_pkthdr.len != sizeof(*mdu))
goto bad;
- }
- if ((m->m_flags & M_MCAST) == 0) {
+ if ((m->m_flags & M_MCAST) == 0)
goto bad;
- }
if (m->m_len < sizeof(*mdu)) {
m = m_pullup(m, sizeof(*mdu));
- if (m == NULL) {
+ if (m == NULL)
return (ENOMEM);
- }
}
mdu = mtod(m, struct markerdu *);
if (memcmp(&eh->ether_dhost,
- &ethermulticastaddr_slowprotocols, ETHER_ADDR_LEN)) {
+ &ethermulticastaddr_slowprotocols, ETHER_ADDR_LEN))
goto bad;
- }
- if (mdu->mdu_sph.sph_version != 1) {
+ if (mdu->mdu_sph.sph_version != 1)
goto bad;
- }
switch (mdu->mdu_tlv.tlv_type) {
case MARKER_TYPE_INFO:
if (tlv_check(mdu, sizeof(*mdu), &mdu->mdu_tlv,
- marker_info_tlv_template, 1)) {
+ marker_info_tlv_template, 1))
goto bad;
- }
+
mdu->mdu_tlv.tlv_type = MARKER_TYPE_RESPONSE;
memcpy(&eh->ether_dhost,
&ethermulticastaddr_slowprotocols, ETHER_ADDR_LEN);
@@ -1705,9 +1663,9 @@ lacp_marker_input(struct lacp_port *lp, struct ether_header *eh, struct mbuf *m)
case MARKER_TYPE_RESPONSE:
if (tlv_check(mdu, sizeof(*mdu), &mdu->mdu_tlv,
- marker_response_tlv_template, 1)) {
+ marker_response_tlv_template, 1))
goto bad;
- }
+
LACP_DPRINTF((lp, "marker response, port=%u, sys=%6D, id=%u\n",
ntohs(mdu->mdu_info.mi_rq_port), mdu->mdu_info.mi_rq_system,
":", ntohl(mdu->mdu_info.mi_rq_xid)));
@@ -1754,16 +1712,16 @@ tlv_check(const void *p, size_t size, const struct tlvhdr *tlv,
const struct tlv_template *tmpl, int check_type)
{
while (/* CONSTCOND */ 1) {
- if ((const char *)tlv - (const char *)p + sizeof(*tlv) > size) {
+ if ((const char *)tlv - (const char *)p + sizeof(*tlv) > size)
return (EINVAL);
- }
+
if ((check_type && tlv->tlv_type != tmpl->tmpl_type) ||
- tlv->tlv_length != tmpl->tmpl_length) {
+ tlv->tlv_length != tmpl->tmpl_length)
return (EINVAL);
- }
- if (tmpl->tmpl_type == 0) {
+
+ if (tmpl->tmpl_type == 0)
break;
- }
+
tlv = (const struct tlvhdr *)
((const char *)tlv + tlv->tlv_length);
tmpl++;
@@ -1856,9 +1814,8 @@ const char *
lacp_format_lagid_aggregator(const struct lacp_aggregator *la,
char *buf, size_t buflen)
{
- if (la == NULL) {
+ if (la == NULL)
return ("(none)");
- }
return (lacp_format_lagid(&la->la_actor, &la->la_partner, buf, buflen));
}
@@ -1893,9 +1850,8 @@ lacp_dprintf(const struct lacp_port *lp, const char *fmt, ...)
{
va_list va;
- if (lp) {
+ if (lp)
printf("%s: ", lp->lp_ifp->if_xname);
- }
va_start(va, fmt);
vprintf(fmt, va);