Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Tidy up bridge_input



details:   https://anonhg.NetBSD.org/src/rev/d920d531bb54
branches:  trunk
changeset: 330028:d920d531bb54
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Jun 18 09:20:46 2014 +0000

description:
Tidy up bridge_input

No functional change.

diffstat:

 sys/net/if_bridge.c |  66 ++++++++++++++++++++++++++++++----------------------
 1 files changed, 38 insertions(+), 28 deletions(-)

diffs (115 lines):

diff -r 25d2cc8c8774 -r d920d531bb54 sys/net/if_bridge.c
--- a/sys/net/if_bridge.c       Wed Jun 18 06:35:19 2014 +0000
+++ b/sys/net/if_bridge.c       Wed Jun 18 09:20:46 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_bridge.c,v 1.81 2014/06/17 10:39:46 ozaki-r Exp $   */
+/*     $NetBSD: if_bridge.c,v 1.82 2014/06/18 09:20:46 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.81 2014/06/17 10:39:46 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.82 2014/06/18 09:20:46 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bridge_ipf.h"
@@ -1569,6 +1569,36 @@
        KERNEL_UNLOCK_ONE(NULL);
 }
 
+static bool
+bstp_state_before_learning(struct bridge_iflist *bif)
+{
+       if (bif->bif_flags & IFBIF_STP) {
+               switch (bif->bif_state) {
+               case BSTP_IFSTATE_BLOCKING:
+               case BSTP_IFSTATE_LISTENING:
+               case BSTP_IFSTATE_DISABLED:
+                       return true;
+               }
+       }
+       return false;
+}
+
+static bool
+bridge_ourether(struct bridge_iflist *bif, struct ether_header *eh, int src)
+{
+       uint8_t *ether = src ? eh->ether_shost : eh->ether_dhost;
+
+       if (memcmp(CLLADDR(bif->bif_ifp->if_sadl), ether, ETHER_ADDR_LEN) == 0
+#if NCARP > 0
+           || (bif->bif_ifp->if_carp &&
+               carp_ourether(bif->bif_ifp->if_carp, eh, IFT_ETHER, src) != NULL)
+#endif /* NCARP > 0 */
+           )
+               return true;
+
+       return false;
+}
+
 /*
  * bridge_input:
  *
@@ -1614,10 +1644,7 @@
                                return;
                        }
 
-                       switch (bif->bif_state) {
-                       case BSTP_IFSTATE_BLOCKING:
-                       case BSTP_IFSTATE_LISTENING:
-                       case BSTP_IFSTATE_DISABLED:
+                       if (bstp_state_before_learning(bif)) {
                                ether_input(ifp, m);
                                return;
                        }
@@ -1643,14 +1670,9 @@
                return;
        }
 
-       if (bif->bif_flags & IFBIF_STP) {
-               switch (bif->bif_state) {
-               case BSTP_IFSTATE_BLOCKING:
-               case BSTP_IFSTATE_LISTENING:
-               case BSTP_IFSTATE_DISABLED:
-                       ether_input(ifp, m);
-                       return;
-               }
+       if (bstp_state_before_learning(bif)) {
+               ether_input(ifp, m);
+               return;
        }
 
        /*
@@ -1658,13 +1680,7 @@
         */
        LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
                /* It is destined for us. */
-               if (memcmp(CLLADDR(bif->bif_ifp->if_sadl), eh->ether_dhost,
-                   ETHER_ADDR_LEN) == 0
-#if NCARP > 0
-                   || (bif->bif_ifp->if_carp && carp_ourether(bif->bif_ifp->if_carp,
-                       eh, IFT_ETHER, 0) != NULL)
-#endif /* NCARP > 0 */
-                   ) {
+               if (bridge_ourether(bif, eh, 0)) {
                        if (bif->bif_flags & IFBIF_LEARNING)
                                (void) bridge_rtupdate(sc,
                                    eh->ether_shost, ifp, 0, IFBAF_DYNAMIC);
@@ -1674,13 +1690,7 @@
                }
 
                /* We just received a packet that we sent out. */
-               if (memcmp(CLLADDR(bif->bif_ifp->if_sadl), eh->ether_shost,
-                   ETHER_ADDR_LEN) == 0
-#if NCARP > 0
-                   || (bif->bif_ifp->if_carp && carp_ourether(bif->bif_ifp->if_carp,
-                       eh, IFT_ETHER, 1) != NULL)
-#endif /* NCARP > 0 */
-                   ) {
+               if (bridge_ourether(bif, eh, 1)) {
                        m_freem(m);
                        return;
                }



Home | Main Index | Thread Index | Old Index