Blob Blame History Raw
From 76f5cf99f83f38ce23be29ea470d4da3d525c859 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Thu, 17 Oct 2019 15:50:09 +0200
Subject: [PATCH 66/76] rtnl_neightbl: always decode struct ndt_config and
 struct ndt_stats

* rtnl_neightbl.c (struct_ndt_config, struct_ndt_stats): New typedefs.
[HAVE_STRUCT_NDT_CONFIG]: New static_assert to check
that sizeof(struct ndt_config) has the expected value.
[HAVE_STRUCT_NDT_STATS]: New static_assert to check
that sizeof(struct ndt_stats) has the expected value.
(decode_ndt_config) [HAVE_STRUCT_NDT_CONFIG]: Remove guard.
(decode_ndt_config): Change the type of ndtc variable
to struct_ndt_config.
(decode_ndt_stats) [HAVE_STRUCT_NDT_STATS]: Remove guard.
(decode_ndt_stats): Change the type of ndtst variable
to struct_ndt_stats.

References: https://bugzilla.redhat.com/show_bug.cgi?id=1758201
---
 rtnl_neightbl.c | 50 ++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 12 deletions(-)

diff --git a/rtnl_neightbl.c b/rtnl_neightbl.c
index f9f5756..0f5d6eb 100644
--- a/rtnl_neightbl.c
+++ b/rtnl_neightbl.c
@@ -21,14 +21,49 @@
 #include "xlat/rtnl_neightbl_attrs.h"
 #include "xlat/rtnl_neightbl_parms_attrs.h"
 
+typedef struct {
+	uint16_t ndtc_key_len;
+	uint16_t ndtc_entry_size;
+	uint32_t ndtc_entries;
+	uint32_t ndtc_last_flush;
+	uint32_t ndtc_last_rand;
+	uint32_t ndtc_hash_rnd;
+	uint32_t ndtc_hash_mask;
+	uint32_t ndtc_hash_chain_gc;
+	uint32_t ndtc_proxy_qlen;
+} struct_ndt_config;
+
+typedef struct {
+	uint64_t ndts_allocs;
+	uint64_t ndts_destroys;
+	uint64_t ndts_hash_grows;
+	uint64_t ndts_res_failed;
+	uint64_t ndts_lookups;
+	uint64_t ndts_hits;
+	uint64_t ndts_rcv_probes_mcast;
+	uint64_t ndts_rcv_probes_ucast;
+	uint64_t ndts_periodic_gc_runs;
+	uint64_t ndts_forced_gc_runs;
+	uint64_t ndts_table_fulls; /**< Added by v4.3-rc1~96^2~202 */
+} struct_ndt_stats;
+
+# ifdef HAVE_STRUCT_NDT_CONFIG
+static_assert(sizeof(struct ndt_config) == sizeof(struct_ndt_config),
+	      "Unexpected struct ndt_config size, please update the decoder");
+# endif
+# ifdef HAVE_STRUCT_NDT_STATS
+static_assert(sizeof(struct ndt_stats) <= sizeof(struct_ndt_stats),
+	      "Unexpected struct ndt_stats size, please update the decoder");
+# endif
+
+
 static bool
 decode_ndt_config(struct tcb *const tcp,
 		  const kernel_ulong_t addr,
 		  const unsigned int len,
 		  const void *const opaque_data)
 {
-#ifdef HAVE_STRUCT_NDT_CONFIG
-	struct ndt_config ndtc;
+	struct_ndt_config ndtc;
 
 	if (len < sizeof(ndtc))
 		return false;
@@ -46,9 +81,6 @@ decode_ndt_config(struct tcb *const tcp,
 	}
 
 	return true;
-#else
-	return false;
-#endif
 }
 
 static const nla_decoder_t ndt_parms_nla_decoders[] = {
@@ -91,8 +123,7 @@ decode_ndt_stats(struct tcb *const tcp,
 		 const unsigned int len,
 		 const void *const opaque_data)
 {
-#ifdef HAVE_STRUCT_NDT_STATS
-	struct ndt_stats ndtst;
+	struct_ndt_stats ndtst;
 	const unsigned int min_size =
 		offsetofend(struct ndt_stats, ndts_forced_gc_runs);
 	const unsigned int def_size = sizeof(ndtst);
@@ -114,17 +145,12 @@ decode_ndt_stats(struct tcb *const tcp,
 		PRINT_FIELD_U(", ", ndtst, ndts_rcv_probes_ucast);
 		PRINT_FIELD_U(", ", ndtst, ndts_periodic_gc_runs);
 		PRINT_FIELD_U(", ", ndtst, ndts_forced_gc_runs);
-# ifdef HAVE_STRUCT_NDT_STATS_NDTS_TABLE_FULLS
 		if (len >= def_size)
 			PRINT_FIELD_U(", ", ndtst, ndts_table_fulls);
-# endif
 		tprints("}");
 	}
 
 	return true;
-#else
-	return false;
-#endif
 }
 
 static const nla_decoder_t ndtmsg_nla_decoders[] = {
-- 
2.1.4