@@ -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
@@ -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,
@@ -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,
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> --- ip/ip_common.h | 7 +++++++ ip/iplink_bond.c | 11 ++--------- ip/iplink_bridge.c | 22 ++++------------------ 3 files changed, 13 insertions(+), 27 deletions(-)