From be67f0080a317a7089cde75a6011ac5bb78aae5b Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Thu, 10 Oct 2019 11:08:51 +0200 Subject: [PATCH 63/76] rtnl_link: use internal rtnl_link_stats* and ifla_port_vsi definitions Define substitutes for struct rtnl_link_stats, struct rtnl_link_stats64, and struct ifla_port_vsi internally. Add a static_assert that informs about future growth of the structures provided by the kernel headers. * rtnl_link.c (struct_rtnl_link_stats, struct_rtnl_link_stats64, struct_ifla_port_vsi): New typedefs. [HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER]: Add a static_assert to check that sizeof(struct rtnl_link_stats) has the expected value. [HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER]: Add a static_assert to check that sizeof(struct rtnl_link_stats) has the expected value. [HAVE_STRUCT_IFLA_PORT_VSI]: Add a static_assert to check that sizeof(struct ifla_port_vsi) has the expected value. (decode_rtnl_link_stats) [HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER]: Remove guard. (decode_rtnl_link_stats): Change the type of st variable to struct_rtnl_link_stats; use struct_rtnl_link_stats in offsetofend statement for min_size definition. (decode_rtnl_link_stats64) [HAVE_STRUCT_RTNL_LINK_STATS64, HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER]: Remove guards. (decode_rtnl_link_stats64): Change the type of st variable to struct_rtnl_link_stats64. (decode_ifla_port_vsi) [HAVE_STRUCT_IFLA_PORT_VSI]: Remove guard. (decode_ifla_port_vsi): Change the type of vsi variable to struct_ifla_port_vsi. References: https://bugzilla.redhat.com/show_bug.cgi?id=1758201 --- rtnl_link.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 87 insertions(+), 17 deletions(-) diff --git a/rtnl_link.c b/rtnl_link.c index 92bc1e0..5ab3d03 100644 --- a/rtnl_link.c +++ b/rtnl_link.c @@ -42,15 +42,95 @@ #include "xlat/tun_device_types.h" #include "xlat/xdp_flags.h" +typedef struct { + uint32_t rx_packets; + uint32_t tx_packets; + uint32_t rx_bytes; + uint32_t tx_bytes; + uint32_t rx_errors; + uint32_t tx_errors; + uint32_t rx_dropped; + uint32_t tx_dropped; + uint32_t multicast; + uint32_t collisions; + uint32_t rx_length_errors; + uint32_t rx_over_errors; + uint32_t rx_crc_errors; + uint32_t rx_frame_errors; + uint32_t rx_fifo_errors; + uint32_t rx_missed_errors; + uint32_t tx_aborted_errors; + uint32_t tx_carrier_errors; + uint32_t tx_fifo_errors; + uint32_t tx_heartbeat_errors; + uint32_t tx_window_errors; + uint32_t rx_compressed; + uint32_t tx_compressed; + uint32_t rx_nohandler; /**< Added by v4.6-rc1~91^2~329^2~2 */ +} struct_rtnl_link_stats; + +/** Added by Linux commit v2.6.35-rc1~473^2~759 */ +typedef struct { + uint64_t rx_packets; + uint64_t tx_packets; + uint64_t rx_bytes; + uint64_t tx_bytes; + uint64_t rx_errors; + uint64_t tx_errors; + uint64_t rx_dropped; + uint64_t tx_dropped; + uint64_t multicast; + uint64_t collisions; + uint64_t rx_length_errors; + uint64_t rx_over_errors; + uint64_t rx_crc_errors; + uint64_t rx_frame_errors; + uint64_t rx_fifo_errors; + uint64_t rx_missed_errors; + uint64_t tx_aborted_errors; + uint64_t tx_carrier_errors; + uint64_t tx_fifo_errors; + uint64_t tx_heartbeat_errors; + uint64_t tx_window_errors; + uint64_t rx_compressed; + uint64_t tx_compressed; + uint64_t rx_nohandler; /**< Added by v4.6-rc1~91^2~329^2~2 */ +} struct_rtnl_link_stats64; + +/** Added by Linux commit v2.6.35-rc1~473^2~33 */ +typedef struct { + uint8_t vsi_mgr_id; + uint8_t vsi_type_id[3]; + uint8_t vsi_type_version; + uint8_t pad[3]; +} struct_ifla_port_vsi; + +#ifdef HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER +static_assert(sizeof(struct_rtnl_link_stats) + == sizeof(struct rtnl_link_stats), + "struct rtnl_link_stats size mismatch" + ", please update the decoder"); +#endif +#ifdef HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER +static_assert(sizeof(struct_rtnl_link_stats64) + == sizeof(struct rtnl_link_stats64), + "struct rtnl_link_stats64 size mismatch" + ", please update the decoder"); +#endif +#ifdef HAVE_STRUCT_IFLA_PORT_VSI +static_assert(sizeof(struct_ifla_port_vsi) == sizeof(struct ifla_port_vsi), + "struct ifla_port_vsi size mismatch, please update the decoder"); +#endif + static bool decode_rtnl_link_stats(struct tcb *const tcp, const kernel_ulong_t addr, const unsigned int len, const void *const opaque_data) { - struct rtnl_link_stats st; + struct_rtnl_link_stats st; const unsigned int min_size = - offsetofend(struct rtnl_link_stats, tx_compressed); + offsetofend(struct_rtnl_link_stats, tx_compressed); const unsigned int def_size = sizeof(st); const unsigned int size = (len >= def_size) ? def_size : @@ -86,10 +166,9 @@ decode_rtnl_link_stats(struct tcb *const tcp, PRINT_FIELD_U(", ", st, rx_compressed); PRINT_FIELD_U(", ", st, tx_compressed); -#ifdef HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER + if (len >= def_size) PRINT_FIELD_U(", ", st, rx_nohandler); -#endif tprints("}"); } @@ -424,10 +503,9 @@ decode_rtnl_link_stats64(struct tcb *const tcp, const unsigned int len, const void *const opaque_data) { -#ifdef HAVE_STRUCT_RTNL_LINK_STATS64 - struct rtnl_link_stats64 st; + struct_rtnl_link_stats64 st; const unsigned int min_size = - offsetofend(struct rtnl_link_stats64, tx_compressed); + offsetofend(struct_rtnl_link_stats64, tx_compressed); const unsigned int def_size = sizeof(st); const unsigned int size = (len >= def_size) ? def_size : @@ -463,17 +541,13 @@ decode_rtnl_link_stats64(struct tcb *const tcp, PRINT_FIELD_U(", ", st, rx_compressed); PRINT_FIELD_U(", ", st, tx_compressed); -# ifdef HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER + if (len >= def_size) PRINT_FIELD_U(", ", st, rx_nohandler); -# endif tprints("}"); } return true; -#else - return false; -#endif } static bool @@ -482,8 +556,7 @@ decode_ifla_port_vsi(struct tcb *const tcp, const unsigned int len, const void *const opaque_data) { -#ifdef HAVE_STRUCT_IFLA_PORT_VSI - struct ifla_port_vsi vsi; + struct_ifla_port_vsi vsi; if (len < sizeof(vsi)) return false; @@ -496,9 +569,6 @@ decode_ifla_port_vsi(struct tcb *const tcp, } return true; -#else - return false; -#endif } static const nla_decoder_t ifla_port_nla_decoders[] = { -- 2.1.4