Module Name: src Committed By: ozaki-r Date: Wed Apr 18 03:49:44 UTC 2018
Modified Files: src/sys/net: if_bridge.c Log Message: Simplify bridge_rtnode_insert (NFC) To generate a diff of this commit: cvs rdiff -u -r1.150 -r1.151 src/sys/net/if_bridge.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if_bridge.c diff -u src/sys/net/if_bridge.c:1.150 src/sys/net/if_bridge.c:1.151 --- src/sys/net/if_bridge.c:1.150 Wed Apr 18 03:47:28 2018 +++ src/sys/net/if_bridge.c Wed Apr 18 03:49:44 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_bridge.c,v 1.150 2018/04/18 03:47:28 ozaki-r Exp $ */ +/* $NetBSD: if_bridge.c,v 1.151 2018/04/18 03:49:44 ozaki-r Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -80,7 +80,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.150 2018/04/18 03:47:28 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.151 2018/04/18 03:49:44 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_bridge_ipf.h" @@ -2422,40 +2422,25 @@ bridge_rtnode_lookup(struct bridge_softc static int bridge_rtnode_insert(struct bridge_softc *sc, struct bridge_rtnode *brt) { - struct bridge_rtnode *lbrt; + struct bridge_rtnode *lbrt, *prev = NULL; uint32_t hash; - int dir; KASSERT(BRIDGE_RT_LOCKED(sc)); hash = bridge_rthash(sc, brt->brt_addr); - - lbrt = LIST_FIRST(&sc->sc_rthash[hash]); - if (lbrt == NULL) { - LIST_INSERT_HEAD(&sc->sc_rthash[hash], brt, brt_hash); - goto out; - } - - do { - dir = memcmp(brt->brt_addr, lbrt->brt_addr, ETHER_ADDR_LEN); + LIST_FOREACH(lbrt, &sc->sc_rthash[hash], brt_hash) { + int dir = memcmp(brt->brt_addr, lbrt->brt_addr, ETHER_ADDR_LEN); if (dir == 0) return EEXIST; - if (dir > 0) { - LIST_INSERT_BEFORE(lbrt, brt, brt_hash); - goto out; - } - if (LIST_NEXT(lbrt, brt_hash) == NULL) { - LIST_INSERT_AFTER(lbrt, brt, brt_hash); - goto out; - } - lbrt = LIST_NEXT(lbrt, brt_hash); - } while (lbrt != NULL); - -#ifdef DIAGNOSTIC - panic("bridge_rtnode_insert: impossible"); -#endif + if (dir > 0) + break; + prev = lbrt; + } + if (prev == NULL) + LIST_INSERT_HEAD(&sc->sc_rthash[hash], brt, brt_hash); + else + LIST_INSERT_AFTER(prev, brt, brt_hash); - out: LIST_INSERT_HEAD(&sc->sc_rtlist, brt, brt_list); sc->sc_brtcnt++;