Commit 4072d97d authored by François Michel's avatar François Michel Committed by Jakub Kicinski

netem: add prng attribute to netem_sched_data

Add prng attribute to struct netem_sched_data and
allows setting the seed of the PRNG through netlink
using the new TCA_NETEM_PRNG_SEED attribute.
The PRNG attribute is not actually used yet.
Signed-off-by: default avatarFrançois Michel <francois.michel@uclouvain.be>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Acked-by: default avatarStephen Hemminger <stephen@networkplumber.org>
Link: https://lore.kernel.org/r/20230815092348.1449179-2-francois.michel@uclouvain.beSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent a5e5b2cd
...@@ -603,6 +603,7 @@ enum { ...@@ -603,6 +603,7 @@ enum {
TCA_NETEM_JITTER64, TCA_NETEM_JITTER64,
TCA_NETEM_SLOT, TCA_NETEM_SLOT,
TCA_NETEM_SLOT_DIST, TCA_NETEM_SLOT_DIST,
TCA_NETEM_PRNG_SEED,
__TCA_NETEM_MAX, __TCA_NETEM_MAX,
}; };
......
...@@ -105,6 +105,11 @@ struct netem_sched_data { ...@@ -105,6 +105,11 @@ struct netem_sched_data {
u32 rho; u32 rho;
} delay_cor, loss_cor, dup_cor, reorder_cor, corrupt_cor; } delay_cor, loss_cor, dup_cor, reorder_cor, corrupt_cor;
struct prng {
u64 seed;
struct rnd_state prng_state;
} prng;
struct disttable *delay_dist; struct disttable *delay_dist;
enum { enum {
...@@ -922,6 +927,7 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = { ...@@ -922,6 +927,7 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
[TCA_NETEM_LATENCY64] = { .type = NLA_S64 }, [TCA_NETEM_LATENCY64] = { .type = NLA_S64 },
[TCA_NETEM_JITTER64] = { .type = NLA_S64 }, [TCA_NETEM_JITTER64] = { .type = NLA_S64 },
[TCA_NETEM_SLOT] = { .len = sizeof(struct tc_netem_slot) }, [TCA_NETEM_SLOT] = { .len = sizeof(struct tc_netem_slot) },
[TCA_NETEM_PRNG_SEED] = { .type = NLA_U64 },
}; };
static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla, static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
...@@ -1040,6 +1046,12 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt, ...@@ -1040,6 +1046,12 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt,
/* capping jitter to the range acceptable by tabledist() */ /* capping jitter to the range acceptable by tabledist() */
q->jitter = min_t(s64, abs(q->jitter), INT_MAX); q->jitter = min_t(s64, abs(q->jitter), INT_MAX);
if (tb[TCA_NETEM_PRNG_SEED])
q->prng.seed = nla_get_u64(tb[TCA_NETEM_PRNG_SEED]);
else
q->prng.seed = get_random_u64();
prandom_seed_state(&q->prng.prng_state, q->prng.seed);
unlock: unlock:
sch_tree_unlock(sch); sch_tree_unlock(sch);
...@@ -1203,6 +1215,10 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -1203,6 +1215,10 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
goto nla_put_failure; goto nla_put_failure;
} }
if (nla_put_u64_64bit(skb, TCA_NETEM_PRNG_SEED, q->prng.seed,
TCA_NETEM_PAD))
goto nla_put_failure;
return nla_nest_end(skb, nla); return nla_nest_end(skb, nla);
nla_put_failure: nla_put_failure:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment