Index: if_aggr.c =================================================================== RCS file: /cvs/src/sys/net/if_aggr.c,v retrieving revision 1.19 diff -u -p -r1.19 if_aggr.c --- if_aggr.c 5 Aug 2019 10:42:51 -0000 1.19 +++ if_aggr.c 17 Mar 2020 03:22:45 -0000 @@ -1,4 +1,4 @@ -/* $OpenBSD: if_aggr.c,v 1.19 2019/08/05 10:42:51 dlg Exp $ */ +/* $OpenBSD: if_aggr.c,v 1.28 2020/03/11 07:01:42 dlg Exp $ */ /* * Copyright (c) 2019 The University of Queensland @@ -307,7 +307,7 @@ struct aggr_multiaddr { unsigned int m_refs; uint8_t m_addrlo[ETHER_ADDR_LEN]; uint8_t m_addrhi[ETHER_ADDR_LEN]; - struct sockaddr m_addr; + struct sockaddr_storage m_addr; }; TAILQ_HEAD(aggr_multiaddrs, aggr_multiaddr); @@ -1022,8 +1022,7 @@ aggr_set_options(struct aggr_softc *sc, break; case TRUNK_OPT_LACP_TIMEOUT: - if (opt->lacp_timeout > nitems(aggr_periodic_times) || - aggr_periodic_times[opt->lacp_timeout] == 0) + if (opt->lacp_timeout >= nitems(aggr_periodic_times)) return (EINVAL); aggr_set_lacp_timeout(sc, opt->lacp_timeout); @@ -1131,7 +1130,7 @@ aggr_add_port(struct aggr_softc *sc, con TAILQ_FOREACH(ma, &sc->sc_multiaddrs, m_entry) { if (aggr_multi(sc, p, ma, SIOCADDMULTI) != 0) { log(LOG_WARNING, "%s %s: " - "unable to add multicast address", + "unable to add multicast address\n", ifp->if_xname, ifp0->if_xname); } } @@ -1180,18 +1179,18 @@ aggr_add_port(struct aggr_softc *sc, con unmtu: if (aggr_p_set_mtu(p, p->p_mtu) != 0) { - log(LOG_WARNING, "%s add %s: unable to reset mtu %u", + log(LOG_WARNING, "%s add %s: unable to reset mtu %u\n", ifp->if_xname, ifp0->if_xname, p->p_mtu); } resetlladdr: if (aggr_p_setlladdr(p, p->p_lladdr) != 0) { - log(LOG_WARNING, "%s add %s: unable to reset lladdr", + log(LOG_WARNING, "%s add %s: unable to reset lladdr\n", ifp->if_xname, ifp0->if_xname); } ungroup: if (aggr_group(sc, p, SIOCDELMULTI) != 0) { log(LOG_WARNING, "%s add %s: " - "unable to remove LACP group address", + "unable to remove LACP group address\n", ifp->if_xname, ifp0->if_xname); } free: @@ -1373,6 +1372,7 @@ aggr_p_dtor(struct aggr_softc *sc, struc struct arpcom *ac0 = (struct arpcom *)ifp0; struct aggr_multiaddr *ma; enum aggr_port_selected selected; + int error; DPRINTF(sc, "%s %s %s: destroying port\n", ifp->if_xname, ifp0->if_xname, op); @@ -1399,32 +1399,40 @@ aggr_p_dtor(struct aggr_softc *sc, struc sc->sc_nports--; TAILQ_FOREACH(ma, &sc->sc_multiaddrs, m_entry) { - if (aggr_multi(sc, p, ma, SIOCDELMULTI) != 0) { + error = aggr_multi(sc, p, ma, SIOCDELMULTI); + if (error != 0) { log(LOG_WARNING, "%s %s %s: " - "unable to remove multicast address", - ifp->if_xname, op, ifp0->if_xname); + "unable to remove multicast address (%d)\n", + ifp->if_xname, op, ifp0->if_xname, error); } } - if (sc->sc_promisc && ifpromisc(ifp0, 0) != 0) { - log(LOG_WARNING, "%s %s %s: unable to disable promisc", - ifp->if_xname, op, ifp0->if_xname); + if (sc->sc_promisc) { + error = ifpromisc(ifp0, 0); + if (error != 0) { + log(LOG_WARNING, "%s %s %s: " + "unable to disable promisc (%d)\n", + ifp->if_xname, op, ifp0->if_xname, error); + } } - if (aggr_p_set_mtu(p, p->p_mtu) != 0) { - log(LOG_WARNING, "%s %s %s: unable to restore mtu %u", - ifp->if_xname, op, ifp0->if_xname, p->p_mtu); + error = aggr_p_set_mtu(p, p->p_mtu); + if (error != 0) { + log(LOG_WARNING, "%s %s %s: unable to restore mtu %u (%d)\n", + ifp->if_xname, op, ifp0->if_xname, p->p_mtu, error); } - if (aggr_p_setlladdr(p, p->p_lladdr) != 0) { - log(LOG_WARNING, "%s %s %s: unable to restore lladdr", - ifp->if_xname, op, ifp0->if_xname); + error = aggr_p_setlladdr(p, p->p_lladdr); + if (error != 0) { + log(LOG_WARNING, "%s %s %s: unable to restore lladdr (%d)\n", + ifp->if_xname, op, ifp0->if_xname, error); } - if (aggr_group(sc, p, SIOCDELMULTI) != 0) { + error = aggr_group(sc, p, SIOCDELMULTI); + if (error != 0) { log(LOG_WARNING, "%s %s %s: " - "unable to remove LACP group address", - ifp->if_xname, op, ifp0->if_xname); + "unable to remove LACP group address (%d)\n", + ifp->if_xname, op, ifp0->if_xname, error); } hook_disestablish(ifp0->if_detachhooks, p->p_dcookie); @@ -2401,8 +2409,7 @@ aggr_up(struct aggr_softc *sc) TAILQ_FOREACH(p, &sc->sc_ports, p_entry) { aggr_rxm(sc, p, LACP_RXM_E_LACP_ENABLED); - - aggr_selection_logic(sc, p); + aggr_p_linkch(p); } /* start the Periodic Transmission machine */ @@ -2435,11 +2442,12 @@ aggr_iff(struct aggr_softc *sc) struct ifnet *ifp0 = p->p_ifp0; if (ifpromisc(ifp0, promisc) != 0) { log(LOG_WARNING, "%s iff %s: " - "unable to turn promisc %s", + "unable to turn promisc %s\n", ifp->if_xname, ifp0->if_xname, promisc ? "on" : "off"); } } + rw_exit_read(&sc->sc_lock); sc->sc_promisc = promisc; } @@ -2488,7 +2496,7 @@ aggr_set_lladdr(struct aggr_softc *sc, c if (aggr_p_setlladdr(p, lladdr) != 0) { struct ifnet *ifp0 = p->p_ifp0; log(LOG_WARNING, "%s setlladdr %s: " - "unable to set lladdr", + "unable to set lladdr\n", ifp->if_xname, ifp0->if_xname); } } @@ -2511,7 +2519,7 @@ aggr_set_mtu(struct aggr_softc *sc, uint TAILQ_FOREACH(p, &sc->sc_ports, p_entry) { if (aggr_p_set_mtu(p, mtu) != 0) { struct ifnet *ifp0 = p->p_ifp0; - log(LOG_WARNING, "%s %s: unable to set mtu %u", + log(LOG_WARNING, "%s %s: unable to set mtu %u\n", ifp->if_xname, ifp0->if_xname, mtu); } } @@ -2546,15 +2554,18 @@ aggr_multi(struct aggr_softc *sc, struct const struct aggr_multiaddr *ma, u_long cmd) { struct ifnet *ifp0 = p->p_ifp0; - struct ifreq ifr; + struct { + char if_name[IFNAMSIZ]; + struct sockaddr_storage if_addr; + } ifr; memset(&ifr, 0, sizeof(ifr)); /* make it convincing */ - CTASSERT(sizeof(ifr.ifr_name) == sizeof(ifp0->if_xname)); - memcpy(ifr.ifr_name, ifp0->if_xname, sizeof(ifr.ifr_name)); + CTASSERT(sizeof(ifr.if_name) == sizeof(ifp0->if_xname)); + memcpy(ifr.if_name, ifp0->if_xname, sizeof(ifr.if_name)); - ifr.ifr_addr = ma->m_addr; + ifr.if_addr = ma->m_addr; return ((*p->p_ioctl)(ifp0, cmd, (caddr_t)&ifr)); } @@ -2816,12 +2827,12 @@ aggr_multi_add(struct aggr_softc *sc, st } } - ma = malloc(sizeof(*ma), M_DEVBUF, M_WAITOK|M_CANFAIL); + ma = malloc(sizeof(*ma), M_DEVBUF, M_WAITOK|M_CANFAIL|M_ZERO); if (ma == NULL) return (ENOMEM); ma->m_refs = 1; - ma->m_addr = ifr->ifr_addr; + memcpy(&ma->m_addr, &ifr->ifr_addr, ifr->ifr_addr.sa_len); memcpy(ma->m_addrlo, addrlo, sizeof(ma->m_addrlo)); memcpy(ma->m_addrhi, addrhi, sizeof(ma->m_addrhi)); TAILQ_INSERT_TAIL(&sc->sc_multiaddrs, ma, m_entry); @@ -2831,7 +2842,7 @@ aggr_multi_add(struct aggr_softc *sc, st if (aggr_multi(sc, p, ma, SIOCADDMULTI) != 0) { log(LOG_WARNING, "%s %s: " - "unable to add multicast address", + "unable to add multicast address\n", ifp->if_xname, ifp0->if_xname); } } @@ -2871,7 +2882,7 @@ aggr_multi_del(struct aggr_softc *sc, st if (aggr_multi(sc, p, ma, SIOCDELMULTI) != 0) { log(LOG_WARNING, "%s %s: " - "unable to delete multicast address", + "unable to delete multicast address\n", ifp->if_xname, ifp0->if_xname); } }