summaryrefslogtreecommitdiffstats
path: root/src/network/tc/netem.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-01-05 10:35:19 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-01-05 11:45:16 +0100
commit16924f54af8876f6437ad6c87251ae92ebfba778 (patch)
tree7632a78ea58d1a834d9d7f852f70c2facf3e54fd /src/network/tc/netem.c
parentnetwork: split out neighbor_configure_message(), simplify logging (diff)
downloadsystemd-16924f54af8876f6437ad6c87251ae92ebfba778.tar.xz
systemd-16924f54af8876f6437ad6c87251ae92ebfba778.zip
network: move logging from tc .fill_message to the callers
Structured initialization is used a bit more. There were two kinds of log messages: about failed size calculations and about failed appends to the message. I "downgraded" the first type to log_debug, and moved the latter to the caller. This way there should be at most one high-priority message. I also changed sizeof(<type>) to sizeof(var) — there is less chance of select-and-paste error in the second form.
Diffstat (limited to 'src/network/tc/netem.c')
-rw-r--r--src/network/tc/netem.c22
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;
}