From: Ethan Jackson Date: Wed, 26 Jan 2011 00:20:08 +0000 (-0800) Subject: packets: Add eth_addr_compare_3way function. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=130f6e5faa6190ca00000ebcb627e2d4ca3d4b37;p=openvswitch packets: Add eth_addr_compare_3way function. This commit adds eth_addr_compare_3way() which behaves like memcmp for Ethernet addresses. --- diff --git a/lib/packets.h b/lib/packets.h index 3ff3babf..38f98fb0 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -60,10 +60,15 @@ static inline bool eth_addr_is_zero(const uint8_t ea[6]) { return !(ea[0] | ea[1] | ea[2] | ea[3] | ea[4] | ea[5]); } +static inline int eth_addr_compare_3way(const uint8_t a[ETH_ADDR_LEN], + const uint8_t b[ETH_ADDR_LEN]) +{ + return memcmp(a, b, ETH_ADDR_LEN); +} static inline bool eth_addr_equals(const uint8_t a[ETH_ADDR_LEN], const uint8_t b[ETH_ADDR_LEN]) { - return !memcmp(a, b, ETH_ADDR_LEN); + return !eth_addr_compare_3way(a, b); } static inline uint64_t eth_addr_to_uint64(const uint8_t ea[ETH_ADDR_LEN]) { diff --git a/ofproto/in-band.c b/ofproto/in-band.c index be4a7e89..952ff8b1 100644 --- a/ofproto/in-band.c +++ b/ofproto/in-band.c @@ -641,7 +641,7 @@ compare_addrs(const void *a_, const void *b_) static int compare_macs(const void *a, const void *b) { - return memcmp(a, b, ETH_ADDR_LEN); + return eth_addr_compare_3way(a, b); } void diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index fab61947..3637ec65 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -1000,7 +1000,7 @@ bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN], !eth_addr_is_local(iface_ea) && !eth_addr_is_reserved(iface_ea) && !eth_addr_is_zero(iface_ea) && - memcmp(iface_ea, ea, ETH_ADDR_LEN) < 0) + eth_addr_compare_3way(iface_ea, ea) < 0) { memcpy(ea, iface_ea, ETH_ADDR_LEN); *hw_addr_iface = iface;