lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230822140417.44504-2-francois.michel@uclouvain.be>
Date: Tue, 22 Aug 2023 16:04:02 +0200
From: francois.michel@...ouvain.be
To:
Cc: netdev@...r.kernel.org,
	stephen@...workplumber.org,
	Francois Michel <francois.michel@...ouvain.be>
Subject: [PATCH iproute2-next 1/2] tc: support the netem seed parameter for loss and corruption events

From: François Michel <francois.michel@...ouvain.be>

Signed-off-by: François Michel <francois.michel@...ouvain.be>
---
 include/uapi/linux/pkt_sched.h |  1 +
 tc/q_netem.c                   | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h
index 00f6ff0a..3f85ae57 100644
--- a/include/uapi/linux/pkt_sched.h
+++ b/include/uapi/linux/pkt_sched.h
@@ -603,6 +603,7 @@ enum {
 	TCA_NETEM_JITTER64,
 	TCA_NETEM_SLOT,
 	TCA_NETEM_SLOT_DIST,
+	TCA_NETEM_PRNG_SEED,
 	__TCA_NETEM_MAX,
 };
 
diff --git a/tc/q_netem.c b/tc/q_netem.c
index 8ace2b61..6d48081a 100644
--- a/tc/q_netem.c
+++ b/tc/q_netem.c
@@ -31,6 +31,7 @@ static void explain(void)
 		"                 [ loss random PERCENT [CORRELATION]]\n"
 		"                 [ loss state P13 [P31 [P32 [P23 P14]]]\n"
 		"                 [ loss gemodel PERCENT [R [1-H [1-K]]]\n"
+		"                 [ seed SEED \n]"
 		"                 [ ecn ]\n"
 		"                 [ reorder PERCENT [CORRELATION] [ gap DISTANCE ]]\n"
 		"                 [ rate RATE [PACKETOVERHEAD] [CELLSIZE] [CELLOVERHEAD]]\n"
@@ -208,6 +209,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 	__u16 loss_type = NETEM_LOSS_UNSPEC;
 	int present[__TCA_NETEM_MAX] = {};
 	__u64 rate64 = 0;
+	__u64 seed = 0;
 
 	for ( ; argc > 0; --argc, ++argv) {
 		if (matches(*argv, "limit") == 0) {
@@ -363,6 +365,13 @@ random_loss_model:
 					*argv);
 				return -1;
 			}
+		} else if (matches(*argv, "seed") == 0) {
+			NEXT_ARG();
+			present[TCA_NETEM_PRNG_SEED] = 1;
+			if (get_u64(&seed, *argv, 10)) {
+				explain1("seed");
+				return -1;
+			}
 		} else if (matches(*argv, "ecn") == 0) {
 			present[TCA_NETEM_ECN] = 1;
 		} else if (matches(*argv, "reorder") == 0) {
@@ -627,6 +636,12 @@ random_loss_model:
 			return -1;
 	}
 
+	if (present[TCA_NETEM_PRNG_SEED] &&
+	    addattr_l(n, 1024, TCA_NETEM_PRNG_SEED, &seed,
+		      sizeof(seed)) < 0)
+		return -1;
+
+
 	if (dist_data) {
 		if (addattr_l(n, MAX_DIST * sizeof(dist_data[0]),
 			      TCA_NETEM_DELAY_DIST,
@@ -657,6 +672,8 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	struct tc_netem_qopt qopt;
 	const struct tc_netem_rate *rate = NULL;
 	const struct tc_netem_slot *slot = NULL;
+	bool seed_present = false;
+	__u64 seed = 0;
 	int len;
 	__u64 rate64 = 0;
 
@@ -722,6 +739,12 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 				return -1;
 			slot = RTA_DATA(tb[TCA_NETEM_SLOT]);
 		}
+		if (tb[TCA_NETEM_PRNG_SEED]) {
+			if (RTA_PAYLOAD(tb[TCA_NETEM_PRNG_SEED]) < sizeof(seed))
+				return -1;
+			seed_present = true;
+			seed = rta_getattr_u64(tb[TCA_NETEM_PRNG_SEED]);
+		}
 	}
 
 	print_uint(PRINT_ANY, "limit", "limit %d", qopt.limit);
@@ -795,6 +818,9 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 		close_json_object();
 	}
 
+	if (seed_present)
+		print_u64(PRINT_ANY, "seed", " seed %llu", seed);
+
 	if (rate && rate->rate) {
 		open_json_object("rate");
 		rate64 = rate64 ? : rate->rate;
-- 
2.41.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ