diff options
Diffstat (limited to 'src/network/tc/netem.c')
-rw-r--r-- | src/network/tc/netem.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/network/tc/netem.c b/src/network/tc/netem.c index 2d86d53125..d4c452675e 100644 --- a/src/network/tc/netem.c +++ b/src/network/tc/netem.c @@ -14,9 +14,6 @@ #include "tc-util.h" static int network_emulator_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { - struct tc_netem_qopt opt = { - .limit = 1000, - }; NetworkEmulator *ne; int r; @@ -24,16 +21,13 @@ static int network_emulator_fill_message(Link *link, QDisc *qdisc, sd_netlink_me assert(qdisc); assert(req); - ne = NETEM(qdisc); - - if (ne->limit > 0) - opt.limit = ne->limit; + assert_se(ne = NETEM(qdisc)); - if (ne->loss > 0) - opt.loss = ne->loss; - - if (ne->duplicate > 0) - opt.duplicate = ne->duplicate; + struct tc_netem_qopt opt = { + .limit = ne->limit > 0 ? ne->limit : 1000, + .loss = ne->loss, + .duplicate = ne->duplicate, + }; if (ne->delay != USEC_INFINITY) { r = tc_time_to_tick(ne->delay, &opt.latency); @@ -47,9 +41,9 @@ static int network_emulator_fill_message(Link *link, QDisc *qdisc, sd_netlink_me return log_link_error_errno(link, r, "Failed to calculate jitter in TCA_OPTION: %m"); } - r = sd_netlink_message_append_data(req, TCA_OPTIONS, &opt, sizeof(struct tc_netem_qopt)); + r = sd_netlink_message_append_data(req, TCA_OPTIONS, &opt, sizeof(opt)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_OPTION attribute: %m"); + return r; return 0; } |