vswitch: Consistently set Nicira OUI.
authorJesse Gross <jesse@nicira.com>
Mon, 1 Feb 2010 23:20:22 +0000 (18:20 -0500)
committerJesse Gross <jesse@nicira.com>
Mon, 8 Feb 2010 20:01:20 +0000 (15:01 -0500)
In places where a random Ethernet address needs to be generated we
are inconsistent about setting an OUI.  This sets an OUI everywhere
to allow the source of packets to be easily identified.

lib/packets.h
ofproto/fail-open.c
ofproto/ofproto.c
vswitchd/bridge.c

index f61c20c..6513f64 100644 (file)
@@ -44,7 +44,10 @@ static inline bool eth_addr_is_multicast(const uint8_t ea[6])
 }
 static inline bool eth_addr_is_local(const uint8_t ea[6]) 
 {
-    return ea[0] & 2;
+    /* Local if it is either a locally administered address or a Nicira random
+     * address. */
+    return !!(ea[0] & 2)
+       || (ea[0] == 0x00 && ea[1] == 0x23 && ea[2] == 0x20 && !!(ea[3] & 0x80));
 }
 static inline bool eth_addr_is_zero(const uint8_t ea[6]) 
 {
@@ -83,6 +86,18 @@ static inline void eth_addr_random(uint8_t ea[ETH_ADDR_LEN])
     random_bytes(ea, ETH_ADDR_LEN);
     eth_addr_mark_random(ea);
 }
+static inline void eth_addr_nicira_random(uint8_t ea[ETH_ADDR_LEN])
+{
+    eth_addr_random(ea);
+
+    /* Set the OUI to the Nicira one. */
+    ea[0] = 0x00;
+    ea[1] = 0x23;
+    ea[2] = 0x20;
+
+    /* Set the top bit to indicate random Nicira address. */
+    ea[3] |= 0x80;
+}
 /* Returns true if 'ea' is a reserved multicast address, that a bridge must
  * never forward, false otherwise. */
 static inline bool eth_addr_is_reserved(const uint8_t ea[ETH_ADDR_LEN])
index 48f7069..54a91cd 100644 (file)
@@ -99,7 +99,7 @@ send_bogus_packet_in(struct fail_open *fo)
 
     /* Compose ofp_packet_in. */
     ofpbuf_init(&b, 128);
-    eth_addr_random(mac);
+    eth_addr_nicira_random(mac);
     compose_benign_packet(&b, "Open vSwitch Controller Probe", 0xa033, mac);
     opi = make_packet_in(pktbuf_get_null(), OFPP_LOCAL, OFPR_NO_MATCH, &b, 64);
     ofpbuf_uninit(&b);
index c44762c..ecab2ad 100644 (file)
@@ -3458,10 +3458,7 @@ static uint64_t
 pick_fallback_dpid(void)
 {
     uint8_t ea[ETH_ADDR_LEN];
-    eth_addr_random(ea);
-    ea[0] = 0x00;               /* Set Nicira OUI. */
-    ea[1] = 0x23;
-    ea[2] = 0x20;
+    eth_addr_nicira_random(ea);
     return eth_addr_to_uint64(ea);
 }
 \f
index 766475b..e945ca8 100644 (file)
@@ -1157,7 +1157,7 @@ bridge_create(const struct ovsrec_bridge *br_cfg)
     br->cfg = br_cfg;
     br->ml = mac_learning_create();
     br->sent_config_request = false;
-    eth_addr_random(br->default_ea);
+    eth_addr_nicira_random(br->default_ea);
 
     port_array_init(&br->ifaces);