From 70150daf2fd88a84f80044a9589e97942b85c25b Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Mon, 1 Feb 2010 18:20:22 -0500 Subject: [PATCH] vswitch: Consistently set Nicira OUI. 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 | 17 ++++++++++++++++- ofproto/fail-open.c | 2 +- ofproto/ofproto.c | 5 +---- vswitchd/bridge.c | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/packets.h b/lib/packets.h index f61c20ca..6513f64b 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -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]) diff --git a/ofproto/fail-open.c b/ofproto/fail-open.c index 48f70694..54a91cdf 100644 --- a/ofproto/fail-open.c +++ b/ofproto/fail-open.c @@ -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); diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index c44762c4..ecab2ad8 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -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); } diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 766475bd..e945ca84 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -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); -- 2.30.2