2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

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>
This commit is contained in:
Jarno Rajahalme
2015-08-28 14:55:11 -07:00
parent d8ef07e709
commit 74ff3298c8
79 changed files with 696 additions and 764 deletions

View File

@@ -105,7 +105,7 @@ struct netdev_dummy {
/* Protects all members below. */
struct ovs_mutex mutex OVS_ACQ_AFTER(dummy_list_mutex);
uint8_t hwaddr[ETH_ADDR_LEN] OVS_GUARDED;
struct eth_addr hwaddr OVS_GUARDED;
int mtu OVS_GUARDED;
struct netdev_stats stats OVS_GUARDED;
enum netdev_flags flags OVS_GUARDED;
@@ -651,12 +651,12 @@ netdev_dummy_construct(struct netdev *netdev_)
ovs_mutex_init(&netdev->mutex);
ovs_mutex_lock(&netdev->mutex);
netdev->hwaddr[0] = 0xaa;
netdev->hwaddr[1] = 0x55;
netdev->hwaddr[2] = n >> 24;
netdev->hwaddr[3] = n >> 16;
netdev->hwaddr[4] = n >> 8;
netdev->hwaddr[5] = n;
netdev->hwaddr.ea[0] = 0xaa;
netdev->hwaddr.ea[1] = 0x55;
netdev->hwaddr.ea[2] = n >> 24;
netdev->hwaddr.ea[3] = n >> 16;
netdev->hwaddr.ea[4] = n >> 8;
netdev->hwaddr.ea[5] = n;
netdev->mtu = 1500;
netdev->flags = 0;
netdev->ifindex = -EOPNOTSUPP;
@@ -970,14 +970,13 @@ netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
}
static int
netdev_dummy_set_etheraddr(struct netdev *netdev,
const uint8_t mac[ETH_ADDR_LEN])
netdev_dummy_set_etheraddr(struct netdev *netdev, const struct eth_addr mac)
{
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
ovs_mutex_lock(&dev->mutex);
if (!eth_addr_equals(dev->hwaddr, mac)) {
memcpy(dev->hwaddr, mac, ETH_ADDR_LEN);
dev->hwaddr = mac;
netdev_change_seq_changed(netdev);
}
ovs_mutex_unlock(&dev->mutex);
@@ -986,13 +985,12 @@ netdev_dummy_set_etheraddr(struct netdev *netdev,
}
static int
netdev_dummy_get_etheraddr(const struct netdev *netdev,
uint8_t mac[ETH_ADDR_LEN])
netdev_dummy_get_etheraddr(const struct netdev *netdev, struct eth_addr *mac)
{
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
ovs_mutex_lock(&dev->mutex);
memcpy(mac, dev->hwaddr, ETH_ADDR_LEN);
*mac = dev->hwaddr;
ovs_mutex_unlock(&dev->mutex);
return 0;