]> granicus.if.org Git - strace/commitdiff
rtnl_link: use internal rtnl_link_stats* and ifla_port_vsi definitions
authorEugene Syromyatnikov <evgsyr@gmail.com>
Thu, 10 Oct 2019 09:08:51 +0000 (11:08 +0200)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Sat, 19 Oct 2019 15:58:22 +0000 (17:58 +0200)
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

index 02df768f45236fcc00f18c8b30c55d086a78d85e..e1f2caacbadfb5041632a034ca4e88350fae5bc2 100644 (file)
 #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("}");
        }
 
@@ -422,10 +501,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 :
@@ -461,17 +539,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
@@ -480,8 +554,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;
@@ -494,9 +567,6 @@ decode_ifla_port_vsi(struct tcb *const tcp,
        }
 
        return true;
-#else
-       return false;
-#endif
 }
 
 static const nla_decoder_t ifla_port_nla_decoders[] = {