[ovs-dev] [PATCH] bridge: Make bridge_pick_local_hw_addr() easier to reason.

Justin Pettit jpettit at nicira.com
Fri Aug 26 15:10:54 PDT 2011


The use of eth_addr_is_multicast() to see if a reasonable address was
found always caused me momentary confusion.  This commit uses a flag
instead, and also saves a bit of unnecessary array reading and writing.
---
 vswitchd/bridge.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index d99d6a1..2bfd926 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -1004,6 +1004,7 @@ bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN],
 {
     const char *hwaddr;
     struct port *port;
+    bool found_addr = false;
     int error;
 
     *hw_addr_iface = NULL;
@@ -1023,7 +1024,6 @@ bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN],
 
     /* Otherwise choose the minimum non-local MAC address among all of the
      * interfaces. */
-    memset(ea, 0xff, ETH_ADDR_LEN);
     HMAP_FOR_EACH (port, hmap_node, &br->ports) {
         uint8_t iface_ea[ETH_ADDR_LEN];
         struct iface *candidate;
@@ -1081,16 +1081,17 @@ bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN],
         {
             memcpy(ea, iface_ea, ETH_ADDR_LEN);
             *hw_addr_iface = iface;
+            found_addr = true;
         }
     }
-    if (eth_addr_is_multicast(ea)) {
+    if (found_addr) {
+        VLOG_DBG("bridge %s: using bridge Ethernet address "ETH_ADDR_FMT,
+                 br->name, ETH_ADDR_ARGS(ea));
+    } else {
         memcpy(ea, br->default_ea, ETH_ADDR_LEN);
         *hw_addr_iface = NULL;
         VLOG_WARN("bridge %s: using default bridge Ethernet "
                   "address "ETH_ADDR_FMT, br->name, ETH_ADDR_ARGS(ea));
-    } else {
-        VLOG_DBG("bridge %s: using bridge Ethernet address "ETH_ADDR_FMT,
-                 br->name, ETH_ADDR_ARGS(ea));
     }
 }
 
-- 
1.7.1




More information about the dev mailing list