Browse Source

rtnl_route: decode struct rta_mfc_stats and struct rtvia unconditionally

* rtnl_route.c (struct_rta_mfc_stats, struct_rtvia): New typedefs.
[HAVE_STRUCT_RTA_MFC_STATS]: Add a static_assert to check
that sizeof(struct rta_mfc_stats) has the expected value.
[HAVE_STRUCT_RTVIA]: Add a static_assert to check that sizeof(struct
rtvia) has the expected value.
(decode_rta_mfc_stats) [HAVE_STRUCT_RTA_MFC_STATS]: Remove guard.
(decode_rta_mfc_stats): Change the type of mfcs variable to
struct_rta_mfc_stats.
(decode_rtvia): Change the type of via variable to struct_rtvia.

References: https://bugzilla.redhat.com/show_bug.cgi?id=1758201
Eugene Syromyatnikov 1 month ago
parent
commit
c19aff23b0
1 changed files with 24 additions and 11 deletions
  1. 24
    11
      rtnl_route.c

+ 24
- 11
rtnl_route.c View File

@@ -26,6 +26,27 @@
26 26
 #include "xlat/rtnl_route_attrs.h"
27 27
 #include "xlat/rtnl_rta_metrics_attrs.h"
28 28
 
29
+/** Added by Linux commit v3.8-rc1~139^2~90 */
30
+typedef struct {
31
+	uint64_t mfcs_packets;
32
+	uint64_t mfcs_bytes;
33
+	uint64_t mfcs_wrong_if;
34
+} struct_rta_mfc_stats;
35
+
36
+typedef struct {
37
+	uint16_t /* __kernel_sa_family_t */ rtvia_family;
38
+	uint8_t rtvia_addr[0];
39
+} struct_rtvia;
40
+
41
+#ifdef HAVE_STRUCT_RTA_MFC_STATS
42
+static_assert(sizeof(struct_rta_mfc_stats) == sizeof(struct rta_mfc_stats),
43
+	      "Unexpected struct rta_mfc_stats, please update the decoder");
44
+#endif
45
+#ifdef HAVE_STRUCT_RTVIA
46
+static_assert(sizeof(struct_rtvia) == sizeof(struct rtvia),
47
+	      "Unexpected struct rtvia, please update the decoder");
48
+#endif
49
+
29 50
 bool
30 51
 decode_nla_rt_class(struct tcb *const tcp,
31 52
 		    const kernel_ulong_t addr,
@@ -138,8 +159,7 @@ decode_rta_mfc_stats(struct tcb *const tcp,
138 159
 		     const unsigned int len,
139 160
 		     const void *const opaque_data)
140 161
 {
141
-#ifdef HAVE_STRUCT_RTA_MFC_STATS
142
-	struct rta_mfc_stats mfcs;
162
+	struct_rta_mfc_stats mfcs;
143 163
 
144 164
 	if (len < sizeof(mfcs))
145 165
 		return false;
@@ -151,9 +171,6 @@ decode_rta_mfc_stats(struct tcb *const tcp,
151 171
 	}
152 172
 
153 173
 	return true;
154
-#else
155
-	return false;
156
-#endif
157 174
 }
158 175
 
159 176
 static bool
@@ -162,15 +179,14 @@ decode_rtvia(struct tcb *const tcp,
162 179
 	     const unsigned int len,
163 180
 	     const void *const opaque_data)
164 181
 {
165
-#ifdef HAVE_STRUCT_RTVIA
166
-	struct rtvia via;
182
+	struct_rtvia via;
167 183
 
168 184
 	if (len < sizeof(via))
169 185
 		return false;
170 186
 	else if (!umove_or_printaddr(tcp, addr, &via)) {
171 187
 		PRINT_FIELD_XVAL("{", via, rtvia_family, addrfams, "AF_???");
172 188
 
173
-		const unsigned int offset = offsetof(struct rtvia, rtvia_addr);
189
+		const unsigned int offset = offsetof(struct_rtvia, rtvia_addr);
174 190
 
175 191
 		if (len > offset) {
176 192
 			tprints(", ");
@@ -181,9 +197,6 @@ decode_rtvia(struct tcb *const tcp,
181 197
 	}
182 198
 
183 199
 	return true;
184
-#else
185
-	return false;
186
-#endif
187 200
 }
188 201
 
189 202
 static bool

Loading…
Cancel
Save