Browse Source

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
Eugene Syromyatnikov 1 month ago
parent
commit
55c18c05b8
1 changed files with 87 additions and 17 deletions
  1. 87
    17
      rtnl_link.c

+ 87
- 17
rtnl_link.c View File

@@ -42,15 +42,95 @@
42 42
 #include "xlat/tun_device_types.h"
43 43
 #include "xlat/xdp_flags.h"
44 44
 
45
+typedef struct {
46
+	uint32_t rx_packets;
47
+	uint32_t tx_packets;
48
+	uint32_t rx_bytes;
49
+	uint32_t tx_bytes;
50
+	uint32_t rx_errors;
51
+	uint32_t tx_errors;
52
+	uint32_t rx_dropped;
53
+	uint32_t tx_dropped;
54
+	uint32_t multicast;
55
+	uint32_t collisions;
56
+	uint32_t rx_length_errors;
57
+	uint32_t rx_over_errors;
58
+	uint32_t rx_crc_errors;
59
+	uint32_t rx_frame_errors;
60
+	uint32_t rx_fifo_errors;
61
+	uint32_t rx_missed_errors;
62
+	uint32_t tx_aborted_errors;
63
+	uint32_t tx_carrier_errors;
64
+	uint32_t tx_fifo_errors;
65
+	uint32_t tx_heartbeat_errors;
66
+	uint32_t tx_window_errors;
67
+	uint32_t rx_compressed;
68
+	uint32_t tx_compressed;
69
+	uint32_t rx_nohandler; /**< Added by v4.6-rc1~91^2~329^2~2 */
70
+} struct_rtnl_link_stats;
71
+
72
+/** Added by Linux commit v2.6.35-rc1~473^2~759 */
73
+typedef struct {
74
+	uint64_t rx_packets;
75
+	uint64_t tx_packets;
76
+	uint64_t rx_bytes;
77
+	uint64_t tx_bytes;
78
+	uint64_t rx_errors;
79
+	uint64_t tx_errors;
80
+	uint64_t rx_dropped;
81
+	uint64_t tx_dropped;
82
+	uint64_t multicast;
83
+	uint64_t collisions;
84
+	uint64_t rx_length_errors;
85
+	uint64_t rx_over_errors;
86
+	uint64_t rx_crc_errors;
87
+	uint64_t rx_frame_errors;
88
+	uint64_t rx_fifo_errors;
89
+	uint64_t rx_missed_errors;
90
+	uint64_t tx_aborted_errors;
91
+	uint64_t tx_carrier_errors;
92
+	uint64_t tx_fifo_errors;
93
+	uint64_t tx_heartbeat_errors;
94
+	uint64_t tx_window_errors;
95
+	uint64_t rx_compressed;
96
+	uint64_t tx_compressed;
97
+	uint64_t rx_nohandler; /**< Added by v4.6-rc1~91^2~329^2~2 */
98
+} struct_rtnl_link_stats64;
99
+
100
+/** Added by Linux commit v2.6.35-rc1~473^2~33 */
101
+typedef struct {
102
+	uint8_t vsi_mgr_id;
103
+	uint8_t vsi_type_id[3];
104
+	uint8_t vsi_type_version;
105
+	uint8_t pad[3];
106
+} struct_ifla_port_vsi;
107
+
108
+#ifdef HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER
109
+static_assert(sizeof(struct_rtnl_link_stats)
110
+	      == sizeof(struct rtnl_link_stats),
111
+	      "struct rtnl_link_stats size mismatch"
112
+	      ", please update the decoder");
113
+#endif
114
+#ifdef HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER
115
+static_assert(sizeof(struct_rtnl_link_stats64)
116
+	      == sizeof(struct rtnl_link_stats64),
117
+	      "struct rtnl_link_stats64 size mismatch"
118
+	      ", please update the decoder");
119
+#endif
120
+#ifdef HAVE_STRUCT_IFLA_PORT_VSI
121
+static_assert(sizeof(struct_ifla_port_vsi) == sizeof(struct ifla_port_vsi),
122
+	      "struct ifla_port_vsi size mismatch, please update the decoder");
123
+#endif
124
+
45 125
 static bool
46 126
 decode_rtnl_link_stats(struct tcb *const tcp,
47 127
 		       const kernel_ulong_t addr,
48 128
 		       const unsigned int len,
49 129
 		       const void *const opaque_data)
50 130
 {
51
-	struct rtnl_link_stats st;
131
+	struct_rtnl_link_stats st;
52 132
 	const unsigned int min_size =
53
-		offsetofend(struct rtnl_link_stats, tx_compressed);
133
+		offsetofend(struct_rtnl_link_stats, tx_compressed);
54 134
 	const unsigned int def_size = sizeof(st);
55 135
 	const unsigned int size =
56 136
 		(len >= def_size) ? def_size :
@@ -86,10 +166,9 @@ decode_rtnl_link_stats(struct tcb *const tcp,
86 166
 
87 167
 		PRINT_FIELD_U(", ", st, rx_compressed);
88 168
 		PRINT_FIELD_U(", ", st, tx_compressed);
89
-#ifdef HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER
169
+
90 170
 		if (len >= def_size)
91 171
 			PRINT_FIELD_U(", ", st, rx_nohandler);
92
-#endif
93 172
 		tprints("}");
94 173
 	}
95 174
 
@@ -422,10 +501,9 @@ decode_rtnl_link_stats64(struct tcb *const tcp,
422 501
 			 const unsigned int len,
423 502
 			 const void *const opaque_data)
424 503
 {
425
-#ifdef HAVE_STRUCT_RTNL_LINK_STATS64
426
-	struct rtnl_link_stats64 st;
504
+	struct_rtnl_link_stats64 st;
427 505
 	const unsigned int min_size =
428
-		offsetofend(struct rtnl_link_stats64, tx_compressed);
506
+		offsetofend(struct_rtnl_link_stats64, tx_compressed);
429 507
 	const unsigned int def_size = sizeof(st);
430 508
 	const unsigned int size =
431 509
 		(len >= def_size) ? def_size :
@@ -461,17 +539,13 @@ decode_rtnl_link_stats64(struct tcb *const tcp,
461 539
 
462 540
 		PRINT_FIELD_U(", ", st, rx_compressed);
463 541
 		PRINT_FIELD_U(", ", st, tx_compressed);
464
-# ifdef HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER
542
+
465 543
 		if (len >= def_size)
466 544
 			PRINT_FIELD_U(", ", st, rx_nohandler);
467
-# endif
468 545
 		tprints("}");
469 546
 	}
470 547
 
471 548
 	return true;
472
-#else
473
-	return false;
474
-#endif
475 549
 }
476 550
 
477 551
 static bool
@@ -480,8 +554,7 @@ decode_ifla_port_vsi(struct tcb *const tcp,
480 554
 		     const unsigned int len,
481 555
 		     const void *const opaque_data)
482 556
 {
483
-#ifdef HAVE_STRUCT_IFLA_PORT_VSI
484
-	struct ifla_port_vsi vsi;
557
+	struct_ifla_port_vsi vsi;
485 558
 
486 559
 	if (len < sizeof(vsi))
487 560
 		return false;
@@ -494,9 +567,6 @@ decode_ifla_port_vsi(struct tcb *const tcp,
494 567
 	}
495 568
 
496 569
 	return true;
497
-#else
498
-	return false;
499
-#endif
500 570
 }
501 571
 
502 572
 static const nla_decoder_t ifla_port_nla_decoders[] = {

Loading…
Cancel
Save