aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Machata <petrm@nvidia.com>2022-05-31 13:35:48 +0200
committerStephen Hemminger <stephen@networkplumber.org>2022-06-01 16:01:14 -0700
commit11e41a635cfab54e8e02fbff2a03715467e77ae9 (patch)
tree59eb2f25124e8f96dd399d5730b798ca194c1682
parentb1521ec002e1d2c72404aa9e4d7734c541260a7c (diff)
downloadiproute2-11e41a635cfab54e8e02fbff2a03715467e77ae9.tar.gz
ip: Convert non-constant initializers to macros
As per the C standard, "expressions in an initializer for an object that has static or thread storage duration shall be constant expressions". Aggregate objects are not constant expressions. Newer GCC doesn't mind, but older GCC and LLVM do. Therefore convert to a macro. And since all these macros will look very similar, extract a generic helper, IPSTATS_STAT_DESC_XSTATS_LEAF, which takes the leaf name as an argument and initializes the rest as appropriate for an xstats descriptor. Reported-by: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r--ip/ip_common.h7
-rw-r--r--ip/iplink_bond.c11
-rw-r--r--ip/iplink_bridge.c22
3 files changed, 13 insertions, 27 deletions
diff --git a/ip/ip_common.h b/ip/ip_common.h
index ffa633e09..c4cb1bcb1 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -205,6 +205,13 @@ void ipstats_stat_desc_pack_xstats(struct ipstats_stat_dump_filters *filters,
int ipstats_stat_desc_show_xstats(struct ipstats_stat_show_attrs *attrs,
const struct ipstats_stat_desc *desc);
+#define IPSTATS_STAT_DESC_XSTATS_LEAF(NAME) { \
+ .name = (NAME), \
+ .kind = IPSTATS_STAT_DESC_KIND_LEAF, \
+ .show = &ipstats_stat_desc_show_xstats, \
+ .pack = &ipstats_stat_desc_pack_xstats, \
+ }
+
#ifndef INFINITY_LIFE_TIME
#define INFINITY_LIFE_TIME 0xFFFFFFFFU
#endif
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
index 15db19a3d..7943499e0 100644
--- a/ip/iplink_bond.c
+++ b/ip/iplink_bond.c
@@ -923,16 +923,9 @@ struct link_util bond_link_util = {
.print_ifla_xstats = bond_print_xstats,
};
-static const struct ipstats_stat_desc ipstats_stat_desc_bond_tmpl_lacp = {
- .name = "802.3ad",
- .kind = IPSTATS_STAT_DESC_KIND_LEAF,
- .show = &ipstats_stat_desc_show_xstats,
- .pack = &ipstats_stat_desc_pack_xstats,
-};
-
static const struct ipstats_stat_desc_xstats
ipstats_stat_desc_xstats_bond_lacp = {
- .desc = ipstats_stat_desc_bond_tmpl_lacp,
+ .desc = IPSTATS_STAT_DESC_XSTATS_LEAF("802.3ad"),
.xstats_at = IFLA_STATS_LINK_XSTATS,
.link_type_at = LINK_XSTATS_TYPE_BOND,
.inner_max = BOND_XSTATS_MAX,
@@ -954,7 +947,7 @@ const struct ipstats_stat_desc ipstats_stat_desc_xstats_bond_group = {
static const struct ipstats_stat_desc_xstats
ipstats_stat_desc_xstats_slave_bond_lacp = {
- .desc = ipstats_stat_desc_bond_tmpl_lacp,
+ .desc = IPSTATS_STAT_DESC_XSTATS_LEAF("802.3ad"),
.xstats_at = IFLA_STATS_LINK_XSTATS_SLAVE,
.link_type_at = LINK_XSTATS_TYPE_BOND,
.inner_max = BOND_XSTATS_MAX,
diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c
index 3feb6109f..0f950d377 100644
--- a/ip/iplink_bridge.c
+++ b/ip/iplink_bridge.c
@@ -937,23 +937,9 @@ struct link_util bridge_link_util = {
.print_ifla_xstats = bridge_print_xstats,
};
-static const struct ipstats_stat_desc ipstats_stat_desc_bridge_tmpl_stp = {
- .name = "stp",
- .kind = IPSTATS_STAT_DESC_KIND_LEAF,
- .show = &ipstats_stat_desc_show_xstats,
- .pack = &ipstats_stat_desc_pack_xstats,
-};
-
-static const struct ipstats_stat_desc ipstats_stat_desc_bridge_tmpl_mcast = {
- .name = "mcast",
- .kind = IPSTATS_STAT_DESC_KIND_LEAF,
- .show = &ipstats_stat_desc_show_xstats,
- .pack = &ipstats_stat_desc_pack_xstats,
-};
-
static const struct ipstats_stat_desc_xstats
ipstats_stat_desc_xstats_bridge_stp = {
- .desc = ipstats_stat_desc_bridge_tmpl_stp,
+ .desc = IPSTATS_STAT_DESC_XSTATS_LEAF("stp"),
.xstats_at = IFLA_STATS_LINK_XSTATS,
.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
.inner_max = BRIDGE_XSTATS_MAX,
@@ -963,7 +949,7 @@ ipstats_stat_desc_xstats_bridge_stp = {
static const struct ipstats_stat_desc_xstats
ipstats_stat_desc_xstats_bridge_mcast = {
- .desc = ipstats_stat_desc_bridge_tmpl_mcast,
+ .desc = IPSTATS_STAT_DESC_XSTATS_LEAF("mcast"),
.xstats_at = IFLA_STATS_LINK_XSTATS,
.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
.inner_max = BRIDGE_XSTATS_MAX,
@@ -986,7 +972,7 @@ const struct ipstats_stat_desc ipstats_stat_desc_xstats_bridge_group = {
static const struct ipstats_stat_desc_xstats
ipstats_stat_desc_xstats_slave_bridge_stp = {
- .desc = ipstats_stat_desc_bridge_tmpl_stp,
+ .desc = IPSTATS_STAT_DESC_XSTATS_LEAF("stp"),
.xstats_at = IFLA_STATS_LINK_XSTATS_SLAVE,
.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
.inner_max = BRIDGE_XSTATS_MAX,
@@ -996,7 +982,7 @@ ipstats_stat_desc_xstats_slave_bridge_stp = {
static const struct ipstats_stat_desc_xstats
ipstats_stat_desc_xstats_slave_bridge_mcast = {
- .desc = ipstats_stat_desc_bridge_tmpl_mcast,
+ .desc = IPSTATS_STAT_DESC_XSTATS_LEAF("mcast"),
.xstats_at = IFLA_STATS_LINK_XSTATS_SLAVE,
.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
.inner_max = BRIDGE_XSTATS_MAX,