summaryrefslogtreecommitdiff
path: root/ofproto/ofproto-dpif-monitor.c
diff options
context:
space:
mode:
authorJarno Rajahalme <jrajahalme@nicira.com>2015-08-28 14:55:11 -0700
committerJarno Rajahalme <jrajahalme@nicira.com>2015-08-28 14:55:11 -0700
commit74ff3298c8806bb09d0c7e40a25b889ab7564769 (patch)
treeeb79e22f9460a0699825569a14710e393ee3358d /ofproto/ofproto-dpif-monitor.c
parentd8ef07e70995e56005e3bc55b86cdb7d0e2066e5 (diff)
downloadopenvswitch-74ff3298c8806bb09d0c7e40a25b889ab7564769.tar.gz
userspace: Define and use struct eth_addr.
Define struct eth_addr and use it instead of a uint8_t array for all ethernet addresses in OVS userspace. The struct is always the right size, and it can be assigned without an explicit memcpy, which makes code more readable. "struct eth_addr" is a good type name for this as many utility functions are already named accordingly. struct eth_addr can be accessed as bytes as well as ovs_be16's, which makes the struct 16-bit aligned. All use seems to be 16-bit aligned, so some algorithms on the ethernet addresses can be made a bit more efficient making use of this fact. As the struct fits into a register (in 64-bit systems) we pass it by value when possible. This patch also changes the few uses of Linux specific ETH_ALEN to OVS's own ETH_ADDR_LEN, and removes the OFP_ETH_ALEN, as it is no longer needed. This work stemmed from a desire to make all struct flow members assignable for unrelated exploration purposes. However, I think this might be a nice code readability improvement by itself. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Diffstat (limited to 'ofproto/ofproto-dpif-monitor.c')
-rw-r--r--ofproto/ofproto-dpif-monitor.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/ofproto/ofproto-dpif-monitor.c b/ofproto/ofproto-dpif-monitor.c
index 252a5d8b7..054840016 100644
--- a/ofproto/ofproto-dpif-monitor.c
+++ b/ofproto/ofproto-dpif-monitor.c
@@ -53,7 +53,7 @@ struct mport {
struct cfm *cfm; /* Reference to cfm. */
struct bfd *bfd; /* Reference to bfd. */
struct lldp *lldp; /* Reference to lldp. */
- uint8_t hw_addr[OFP_ETH_ALEN]; /* Hardware address. */
+ struct eth_addr hw_addr; /* Hardware address. */
};
/* Entry of the 'send_soon' list. Contains the pointer to the
@@ -88,12 +88,13 @@ static void monitor_run(void);
static void monitor_mport_run(struct mport *, struct dp_packet *);
static void mport_register(const struct ofport_dpif *, struct bfd *,
- struct cfm *, struct lldp *, uint8_t[ETH_ADDR_LEN])
+ struct cfm *, struct lldp *,
+ const struct eth_addr *)
OVS_REQUIRES(monitor_mutex);
static void mport_unregister(const struct ofport_dpif *)
OVS_REQUIRES(monitor_mutex);
static void mport_update(struct mport *, struct bfd *, struct cfm *,
- struct lldp *, uint8_t[ETH_ADDR_LEN])
+ struct lldp *, const struct eth_addr *)
OVS_REQUIRES(monitor_mutex);
static struct mport *mport_find(const struct ofport_dpif *)
OVS_REQUIRES(monitor_mutex);
@@ -118,7 +119,8 @@ mport_find(const struct ofport_dpif *ofport) OVS_REQUIRES(monitor_mutex)
* if it doesn't exist. Otherwise, just updates its fields. */
static void
mport_register(const struct ofport_dpif *ofport, struct bfd *bfd,
- struct cfm *cfm, struct lldp *lldp, uint8_t *hw_addr)
+ struct cfm *cfm, struct lldp *lldp,
+ const struct eth_addr *hw_addr)
OVS_REQUIRES(monitor_mutex)
{
struct mport *mport = mport_find(ofport);
@@ -150,7 +152,7 @@ mport_unregister(const struct ofport_dpif *ofport)
/* Updates the fields of an existing mport struct. */
static void
mport_update(struct mport *mport, struct bfd *bfd, struct cfm *cfm,
- struct lldp *lldp, uint8_t hw_addr[ETH_ADDR_LEN])
+ struct lldp *lldp, const struct eth_addr *hw_addr)
OVS_REQUIRES(monitor_mutex)
{
ovs_assert(mport);
@@ -167,8 +169,8 @@ mport_update(struct mport *mport, struct bfd *bfd, struct cfm *cfm,
lldp_unref(mport->lldp);
mport->lldp = lldp_ref(lldp);
}
- if (hw_addr && memcmp(mport->hw_addr, hw_addr, ETH_ADDR_LEN)) {
- memcpy(mport->hw_addr, hw_addr, ETH_ADDR_LEN);
+ if (hw_addr && !eth_addr_equals(mport->hw_addr, *hw_addr)) {
+ mport->hw_addr = *hw_addr;
}
/* If bfd/cfm/lldp is added or reconfigured, move the mport on top of the heap
* so that the monitor thread can run the mport next time it wakes up. */
@@ -316,7 +318,7 @@ void
ofproto_dpif_monitor_port_update(const struct ofport_dpif *ofport,
struct bfd *bfd, struct cfm *cfm,
struct lldp *lldp,
- uint8_t hw_addr[ETH_ADDR_LEN])
+ const struct eth_addr *hw_addr)
{
ovs_mutex_lock(&monitor_mutex);
if (!cfm && !bfd && !lldp) {