mirror of
https://github.com/openvswitch/ovs
synced 2025-10-25 15:07:05 +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:
@@ -96,7 +96,7 @@ enum ofp10_port_features {
|
||||
/* Description of a physical port */
|
||||
struct ofp10_phy_port {
|
||||
ovs_be16 port_no;
|
||||
uint8_t hw_addr[OFP_ETH_ALEN];
|
||||
struct eth_addr hw_addr;
|
||||
char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
|
||||
|
||||
ovs_be32 config; /* Bitmap of OFPPC_* and OFPPC10_* flags. */
|
||||
@@ -114,11 +114,10 @@ OFP_ASSERT(sizeof(struct ofp10_phy_port) == 48);
|
||||
/* Modify behavior of the physical port */
|
||||
struct ofp10_port_mod {
|
||||
ovs_be16 port_no;
|
||||
uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
|
||||
configurable. This is used to
|
||||
sanity-check the request, so it must
|
||||
be the same as returned in an
|
||||
ofp10_phy_port struct. */
|
||||
struct eth_addr hw_addr; /* The hardware address is not configurable. This
|
||||
is used to sanity-check the request, so it must
|
||||
be the same as returned in an ofp10_phy_port
|
||||
struct. */
|
||||
|
||||
ovs_be32 config; /* Bitmap of OFPPC_* flags. */
|
||||
ovs_be32 mask; /* Bitmap of OFPPC_* flags to be changed. */
|
||||
@@ -234,8 +233,8 @@ enum ofp10_flow_wildcards {
|
||||
struct ofp10_match {
|
||||
ovs_be32 wildcards; /* Wildcard fields. */
|
||||
ovs_be16 in_port; /* Input switch port. */
|
||||
uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */
|
||||
uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */
|
||||
struct eth_addr dl_src; /* Ethernet source address. */
|
||||
struct eth_addr dl_dst; /* Ethernet destination address. */
|
||||
ovs_be16 dl_vlan; /* Input VLAN. */
|
||||
uint8_t dl_vlan_pcp; /* Input VLAN priority. */
|
||||
uint8_t pad1[1]; /* Align to 64-bits. */
|
||||
|
||||
@@ -110,7 +110,7 @@ enum ofp11_port_features {
|
||||
struct ofp11_port {
|
||||
ovs_be32 port_no;
|
||||
uint8_t pad[4];
|
||||
uint8_t hw_addr[OFP_ETH_ALEN];
|
||||
struct eth_addr hw_addr;
|
||||
uint8_t pad2[2]; /* Align to 64 bits. */
|
||||
char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
|
||||
|
||||
@@ -133,11 +133,10 @@ OFP_ASSERT(sizeof(struct ofp11_port) == 64);
|
||||
struct ofp11_port_mod {
|
||||
ovs_be32 port_no;
|
||||
uint8_t pad[4];
|
||||
uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
|
||||
configurable. This is used to
|
||||
sanity-check the request, so it must
|
||||
be the same as returned in an
|
||||
ofp11_port struct. */
|
||||
struct eth_addr hw_addr; /* The hardware address is not configurable. This
|
||||
is used to sanity-check the request, so it must
|
||||
be the same as returned in an ofp11_port
|
||||
struct. */
|
||||
uint8_t pad2[2]; /* Pad to 64 bits. */
|
||||
ovs_be32 config; /* Bitmap of OFPPC_* flags. */
|
||||
ovs_be32 mask; /* Bitmap of OFPPC_* flags to be changed. */
|
||||
@@ -194,10 +193,10 @@ struct ofp11_match {
|
||||
struct ofp11_match_header omh;
|
||||
ovs_be32 in_port; /* Input switch port. */
|
||||
ovs_be32 wildcards; /* Wildcard fields. */
|
||||
uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */
|
||||
uint8_t dl_src_mask[OFP_ETH_ALEN]; /* Ethernet source address mask. */
|
||||
uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */
|
||||
uint8_t dl_dst_mask[OFP_ETH_ALEN]; /* Ethernet destination address mask. */
|
||||
struct eth_addr dl_src; /* Ethernet source address. */
|
||||
struct eth_addr dl_src_mask; /* Ethernet source address mask. */
|
||||
struct eth_addr dl_dst; /* Ethernet destination address. */
|
||||
struct eth_addr dl_dst_mask; /* Ethernet destination address mask. */
|
||||
ovs_be16 dl_vlan; /* Input VLAN id. */
|
||||
uint8_t dl_vlan_pcp; /* Input VLAN priority. */
|
||||
uint8_t pad1[1]; /* Align to 32-bits */
|
||||
|
||||
@@ -72,7 +72,7 @@ struct ofp14_port {
|
||||
ovs_be32 port_no;
|
||||
ovs_be16 length;
|
||||
uint8_t pad[2];
|
||||
uint8_t hw_addr[OFP_ETH_ALEN];
|
||||
struct eth_addr hw_addr;
|
||||
uint8_t pad2[2]; /* Align to 64 bits. */
|
||||
char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
|
||||
|
||||
@@ -106,7 +106,7 @@ OFP_ASSERT(sizeof(struct ofp14_port_mod_prop_ethernet) == 8);
|
||||
struct ofp14_port_mod {
|
||||
ovs_be32 port_no;
|
||||
uint8_t pad[4];
|
||||
uint8_t hw_addr[OFP_ETH_ALEN];
|
||||
struct eth_addr hw_addr;
|
||||
uint8_t pad2[2];
|
||||
ovs_be32 config; /* Bitmap of OFPPC_* flags. */
|
||||
ovs_be32 mask; /* Bitmap of OFPPC_* flags to be changed. */
|
||||
|
||||
@@ -113,8 +113,6 @@ enum ofp_version {
|
||||
#define OFP_OLD_PORT 6633
|
||||
#define OFP_PORT 6653
|
||||
|
||||
#define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
|
||||
|
||||
#define OFP_DEFAULT_MISS_SEND_LEN 128
|
||||
|
||||
/* Values below this cutoff are 802.3 packets and the two bytes
|
||||
|
||||
Reference in New Issue
Block a user