mirror of
https://github.com/openvswitch/ovs
synced 2025-09-05 08:45:23 +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:
@@ -106,4 +106,14 @@ typedef uint32_t OVS_BITWISE ofp11_port_t;
|
||||
#define ODP_PORT_C(X) ((OVS_FORCE odp_port_t) (X))
|
||||
#define OFP11_PORT_C(X) ((OVS_FORCE ofp11_port_t) (X))
|
||||
|
||||
/* Using this stuct instead of a bare array makes an ethernet address field
|
||||
* assignable. The size of the array is also part of the type, so it is easier
|
||||
* to deal with. */
|
||||
struct eth_addr {
|
||||
union {
|
||||
uint8_t ea[6];
|
||||
ovs_be16 be16[3];
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* openvswitch/types.h */
|
||||
|
Reference in New Issue
Block a user