summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-11-19 11:26:32 +0100
committerThomas Haller <thaller@redhat.com>2020-11-19 20:10:33 +0100
commitf125d821be467c71325c598de604cb75f49c2a14 (patch)
tree9dea92dc411e0a2155a4562146316d2ca90c2049
parent0db10dd5a7d3de3093fb8efc82eaf8141ae2c21e (diff)
downloadNetworkManager-f125d821be467c71325c598de604cb75f49c2a14.tar.gz
shared: improve NM_ETHER_ADDR_INIT() helper macro
The macro should require exactly 6 parameters (for the 6 bytes of the address). On the other hand, we also should be able to use a macro like NM_ETHER_ADDR_INIT(NM_BRIDGE_GROUP_ADDRESS_DEF_BIN) To get that work properly, we need to expand the variadic macro once. Also, cast the result to the struct type. With this, it can not only be used for initialization, but also for assignment and temporary variables.
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h15
-rw-r--r--src/devices/nm-device-bridge.c2
2 files changed, 13 insertions, 4 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 2848ce860a..dd094a2cbd 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -93,11 +93,20 @@ typedef struct {
(x)->ether_addr_octet[0], (x)->ether_addr_octet[1], (x)->ether_addr_octet[2], \
(x)->ether_addr_octet[3], (x)->ether_addr_octet[4], (x)->ether_addr_octet[5]
-#define NM_ETHER_ADDR_INIT(...) \
- { \
- .ether_addr_octet = {__VA_ARGS__}, \
+#define _NM_ETHER_ADDR_INIT(a0, a1, a2, a3, a4, a5) \
+ { \
+ .ether_addr_octet = { \
+ (a0), \
+ (a1), \
+ (a2), \
+ (a3), \
+ (a4), \
+ (a5), \
+ }, \
}
+#define NM_ETHER_ADDR_INIT(...) ((NMEtherAddr) _NM_ETHER_ADDR_INIT(__VA_ARGS__))
+
static inline int
nm_ether_addr_cmp(const NMEtherAddr *a, const NMEtherAddr *b)
{
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c
index 4f2d3f30e0..64a530a26b 100644
--- a/src/devices/nm-device-bridge.c
+++ b/src/devices/nm-device-bridge.c
@@ -169,7 +169,7 @@ static void
to_sysfs_group_address_sys(const char *group_address, NMEtherAddr *out_addr)
{
if (group_address == NULL) {
- *out_addr = (NMEtherAddr) NM_ETHER_ADDR_INIT(NM_BRIDGE_GROUP_ADDRESS_DEF_BIN);
+ *out_addr = NM_ETHER_ADDR_INIT(NM_BRIDGE_GROUP_ADDRESS_DEF_BIN);
return;
}
if (!nm_utils_hwaddr_aton(group_address, out_addr, ETH_ALEN))