From: François Michel Date: Wed, 23 Aug 2023 10:01:09 +0000 (+0200) Subject: tc: support the netem seed parameter for loss and corruption events X-Git-Tag: v6.6.0~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a67cf9a2523c2180fbdaeb9faaae853112b4a9b7;p=thirdparty%2Fiproute2.git tc: support the netem seed parameter for loss and corruption events Signed-off-by: François Michel Signed-off-by: David Ahern --- diff --git a/tc/q_netem.c b/tc/q_netem.c index 8ace2b614..febddd495 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); @@ -823,6 +846,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); + print_bool(PRINT_JSON, "ecn", NULL, ecn); if (ecn) print_bool(PRINT_FP, NULL, " ecn ", ecn);