]> git.proxmox.com Git - mirror_ovs.git/commitdiff
types: New macros ETH_ADDR_C and ETH_ADDR64_C.
authorBen Pfaff <blp@ovn.org>
Tue, 28 Nov 2017 23:32:24 +0000 (15:32 -0800)
committerBen Pfaff <blp@ovn.org>
Wed, 29 Nov 2017 21:27:16 +0000 (13:27 -0800)
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 <blp@ovn.org>
Acked-by: Mark Michelson <mmichels@redhat.com>
include/openvswitch/types.h
lib/cfm.c
lib/lldp/lldp-tlv.h
lib/ovs-lldp.c
lib/packets.h
tests/test-aa.c
tests/test-classifier.c

index f7e1c07dd8b05fb6a28fbb527b70f9be6b4933b9..d5792c3b22334bdf0c5d57bf3c9f2da4ea82362c 100644 (file)
@@ -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
index 984ff11a1a79929ae8e688d6e171ccfa90e21124..19957a968d3a002ac25bb583ed20b22223674998 100644 (file)
--- 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
 
index f54493d19b7b9f19cebc55e37a25f2d0a449a773..1e666fdacc9427e6cc4e9643e799a97b8674f412 100644 (file)
@@ -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
index 43dd06d6f2497e601c06e63ecf97dffcf9c7e36c..a056ace93ff15dcb3d75e2e600ea6b6e80d1adee 100644 (file)
@@ -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);
 
index 461f488a875df0f9d5fb5c4b3f33e6d2f5508814..13ea46da256af5d3f0bbf2fabb43b8102aac41c9 100644 (file)
@@ -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)
 {
index 2c26fc5273b38560cf385824c06fc1a3d1e1bbf5..1290ca8c9a7c6137cecb53e1816859a2ce4d99ae 100644 (file)
 #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;
index 33de3db3c5ee3342bf3b38b01a87bd63af6b8f8c..edaf4a393382ef399d5d42cb934308dd396598de 100644 (file)
@@ -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 };