bridge: Make bridge_pick_local_hw_addr() easier to reason.
authorJustin Pettit <jpettit@nicira.com>
Fri, 26 Aug 2011 22:05:53 +0000 (15:05 -0700)
committerJustin Pettit <jpettit@nicira.com>
Fri, 26 Aug 2011 22:24:17 +0000 (15:24 -0700)
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

index d99d6a1cd4746e5c6ad4c3635827f63ac7265234..2bfd926e265db120b9c827c096ae86b227b08cc9 100644 (file)
@@ -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));
     }
 }