From da2aa5eb4565ea9f5dd2997884892b6ad5cc77c5 Mon Sep 17 00:00:00 2001 From: ae Date: Tue, 7 Oct 2014 08:19:21 +0000 Subject: [PATCH] MFC r272176: Keep list of lagg ports sorted by if_index. git-svn-id: svn://svn.freebsd.org/base/stable/9@272681 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/net/if_lagg.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sys/net/if_lagg.c b/sys/net/if_lagg.c index 9e502b219..81db8d0a2 100644 --- a/sys/net/if_lagg.c +++ b/sys/net/if_lagg.c @@ -523,7 +523,7 @@ static int lagg_port_create(struct lagg_softc *sc, struct ifnet *ifp) { struct lagg_softc *sc_ptr; - struct lagg_port *lp; + struct lagg_port *lp, *tlp; int error = 0; LAGG_WLOCK_ASSERT(sc); @@ -630,8 +630,18 @@ lagg_port_create(struct lagg_softc *sc, struct ifnet *ifp) lagg_port_lladdr(lp, IF_LLADDR(sc->sc_ifp)); } - /* Insert into the list of ports */ - SLIST_INSERT_HEAD(&sc->sc_ports, lp, lp_entries); + /* Insert into the list of ports. Keep ports sorted by if_index. */ + SLIST_FOREACH(tlp, &sc->sc_ports, lp_entries) { + if (tlp->lp_ifp->if_index < ifp->if_index && ( + SLIST_NEXT(tlp, lp_entries) == NULL || + SLIST_NEXT(tlp, lp_entries)->lp_ifp->if_index < + ifp->if_index)) + break; + } + if (tlp != NULL) + SLIST_INSERT_AFTER(tlp, lp, lp_entries); + else + SLIST_INSERT_HEAD(&sc->sc_ports, lp, lp_entries); sc->sc_count++; /* Update lagg capabilities */ -- 2.45.0