These macros expand to constants of type struct eth_addr and struct eth_addr64, respectively, and make it more convenient to initialize or assign to an Ethernet address object.
Signed-off-by: Ben Pfaff <[email protected]> --- include/openvswitch/types.h | 11 +++++++++++ lib/cfm.c | 6 ++---- lib/lldp/lldp-tlv.h | 4 +--- lib/ovs-lldp.c | 3 +-- lib/packets.h | 14 +++++++------- tests/test-aa.c | 6 +++--- tests/test-classifier.c | 10 ++++++---- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/include/openvswitch/types.h b/include/openvswitch/types.h index f7e1c07dd8b0..d5792c3b2233 100644 --- a/include/openvswitch/types.h +++ b/include/openvswitch/types.h @@ -168,6 +168,11 @@ struct eth_addr { }; }; +/* Ethernet address constant, e.g. ETH_ADDR_C(01,23,45,67,89,ab) is + * 01:23:45:67:89:ab. */ +#define ETH_ADDR_C(A,B,C,D,E,F) (struct eth_addr) \ + { { .ea = { 0x##A, 0x##B, 0x##C, 0x##D, 0x##E, 0x##F } } } + /* Similar to struct eth_addr, for EUI-64 addresses. */ struct eth_addr64 { union { @@ -176,6 +181,12 @@ struct eth_addr64 { }; }; +/* EUI-64 address constant, e.g. ETH_ADDR_C(01,23,45,67,89,ab,cd,ef) is + * 01:23:45:67:89:ab:cd:ef. */ +#define ETH_ADDR64_C(A,B,C,D,E,F,G,H) (struct eth_addr64) \ + { { .ea64 = { 0x##A, 0x##B, 0x##C, 0x##D, \ + 0x##E, 0x##F, 0x##G, 0x##H} } } + #ifdef __cplusplus } #endif diff --git a/lib/cfm.c b/lib/cfm.c index 984ff11a1a79..19957a968d3a 100644 --- a/lib/cfm.c +++ b/lib/cfm.c @@ -45,10 +45,8 @@ VLOG_DEFINE_THIS_MODULE(cfm); #define CFM_MAX_RMPS 256 /* Ethernet destination address of CCM packets. */ -static const struct eth_addr eth_addr_ccm = { - { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x30 } } }; -static const struct eth_addr eth_addr_ccm_x = { - { { 0x01, 0x23, 0x20, 0x00, 0x00, 0x30 } } }; +static const struct eth_addr eth_addr_ccm = ETH_ADDR_C(01,80,c2,00,00,30); +static const struct eth_addr eth_addr_ccm_x = ETH_ADDR_C(01,23,20,00,00,30); #define ETH_TYPE_CFM 0x8902 diff --git a/lib/lldp/lldp-tlv.h b/lib/lldp/lldp-tlv.h index f54493d19b7b..1e666fdacc94 100644 --- a/lib/lldp/lldp-tlv.h +++ b/lib/lldp/lldp-tlv.h @@ -18,9 +18,7 @@ #ifndef _LLDP_TLV_H #define _LLDP_TLV_H -#define LLDP_MULTICAST_ADDR { \ - { { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e } } \ -} +#define LLDP_MULTICAST_ADDR ETH_ADDR_C(01,80,c2,00,00,0e) #define LLDP_TLV_END 0 #define LLDP_TLV_CHASSIS_ID 1 diff --git a/lib/ovs-lldp.c b/lib/ovs-lldp.c index 43dd06d6f249..a056ace93ff1 100644 --- a/lib/ovs-lldp.c +++ b/lib/ovs-lldp.c @@ -726,8 +726,7 @@ lldp_put_packet(struct lldp *lldp, struct dp_packet *packet, { struct lldpd *mylldpd = lldp->lldpd; struct lldpd_hardware *hw = lldpd_first_hardware(mylldpd); - static const struct eth_addr eth_addr_lldp = - { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0e } } }; + static const struct eth_addr eth_addr_lldp = ETH_ADDR_C(01,80,c2,00,00,0e); ovs_mutex_lock(&mutex); diff --git a/lib/packets.h b/lib/packets.h index 461f488a875d..13ea46da256a 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -176,24 +176,24 @@ bool dpid_from_string(const char *s, uint64_t *dpidp); #define ETH_ADDR_LEN 6 static const struct eth_addr eth_addr_broadcast OVS_UNUSED - = { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } }; + = ETH_ADDR_C(ff,ff,ff,ff,ff,ff); static const struct eth_addr eth_addr_exact OVS_UNUSED - = { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } }; + = ETH_ADDR_C(ff,ff,ff,ff,ff,ff); static const struct eth_addr eth_addr_zero OVS_UNUSED - = { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }; + = ETH_ADDR_C(00,00,00,00,00,00); static const struct eth_addr64 eth_addr64_zero OVS_UNUSED - = { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }; + = ETH_ADDR64_C(00,00,00,00,00,00,00,00); static const struct eth_addr eth_addr_stp OVS_UNUSED - = { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x00 } } }; + = ETH_ADDR_C(01,80,c2,00,00,00); static const struct eth_addr eth_addr_lacp OVS_UNUSED - = { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x02 } } }; + = ETH_ADDR_C(01,80,c2,00,00,02); static const struct eth_addr eth_addr_bfd OVS_UNUSED - = { { { 0x00, 0x23, 0x20, 0x00, 0x00, 0x01 } } }; + = ETH_ADDR_C(00,23,20,00,00,01); static inline bool eth_addr_is_broadcast(const struct eth_addr a) { diff --git a/tests/test-aa.c b/tests/test-aa.c index 2c26fc5273b3..1290ca8c9a7c 100644 --- a/tests/test-aa.c +++ b/tests/test-aa.c @@ -26,11 +26,11 @@ #define ETH_TYPE_LLDP 0x88cc /* Dummy MAC addresses */ -static const struct eth_addr chassis_mac = { { { 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad } } }; -static const struct eth_addr eth_src = { { { 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad } } }; +static const struct eth_addr chassis_mac = ETH_ADDR_C(5e,10,8e,e7,84,ad); +static const struct eth_addr eth_src = ETH_ADDR_C(5e,10,8e,e7,84,ad); /* LLDP multicast address */ -static const struct eth_addr eth_addr_lldp = { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0e } } }; +static const struct eth_addr eth_addr_lldp = ETH_ADDR_C(01,80,c2,00,00,0e); /* Count of tests run */ static int num_tests = 0; diff --git a/tests/test-classifier.c b/tests/test-classifier.c index 33de3db3c5ee..edaf4a393382 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -316,11 +316,13 @@ static ovs_be16 tp_src_values[] = { CONSTANT_HTONS(49362), CONSTANT_HTONS(80) }; static ovs_be16 tp_dst_values[] = { CONSTANT_HTONS(6667), CONSTANT_HTONS(22) }; static struct eth_addr dl_src_values[] = { - { { { 0x00, 0x02, 0xe3, 0x0f, 0x80, 0xa4 } } }, - { { { 0x5e, 0x33, 0x7f, 0x5f, 0x1e, 0x99 } } } }; + ETH_ADDR_C(00,02,e3,0f,80,a4), + ETH_ADDR_C(5e,33,7f,5f,1e,99) +}; static struct eth_addr dl_dst_values[] = { - { { { 0x4a, 0x27, 0x71, 0xae, 0x64, 0xc1 } } }, - { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } } }; + ETH_ADDR_C(4a,27,71,ae,64,c1), + ETH_ADDR_C(ff,ff,ff,ff,ff,ff) +}; static uint8_t nw_proto_values[] = { IPPROTO_TCP, IPPROTO_ICMP }; static uint8_t nw_dscp_values[] = { 48, 0 }; -- 2.10.2 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
