Author: ae
Date: Fri Sep 26 12:42:06 2014
New Revision: 272176
URL: http://svnweb.freebsd.org/changeset/base/272176

Log:
  Keep list of lagg ports sorted by if_index.
  
  Obtained from:        Yandex LLC
  MFC after:    1 week
  Sponsored by: Yandex LLC

Modified:
  head/sys/net/if_lagg.c

Modified: head/sys/net/if_lagg.c
==============================================================================
--- head/sys/net/if_lagg.c      Fri Sep 26 12:35:58 2014        (r272175)
+++ head/sys/net/if_lagg.c      Fri Sep 26 12:42:06 2014        (r272176)
@@ -601,7 +601,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);
@@ -708,8 +708,18 @@ lagg_port_create(struct lagg_softc *sc, 
                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 */
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to