network: add BitRates field to link_build_json() and the Varlink IDL

Expose the speed meter transmit/receive rates as a BitRates struct in
the per-link JSON output and the io.systemd.Network Varlink IDL.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
noxiouz
2026-03-18 22:55:52 +00:00
parent f9ebd7bb06
commit 872feaa006
2 changed files with 26 additions and 1 deletions
+15
View File
@@ -26,6 +26,7 @@
#include "networkd-route.h"
#include "networkd-route-util.h"
#include "networkd-routing-policy-rule.h"
#include "networkd-speed-meter.h"
#include "networkd-wwan.h"
#include "ordered-set.h"
#include "set.h"
@@ -1639,6 +1640,20 @@ int link_build_json(Link *link, sd_json_variant **ret) {
if (r < 0)
return r;
/* Append BitRates if speed meter is active */
uint64_t tx, rx;
link_get_bit_rates(link, &tx, &rx);
if (tx != UINT64_MAX && rx != UINT64_MAX) {
r = sd_json_variant_merge_objectbo(
&v,
SD_JSON_BUILD_PAIR("BitRates",
SD_JSON_BUILD_OBJECT(
SD_JSON_BUILD_PAIR_UNSIGNED("TxBitRate", tx),
SD_JSON_BUILD_PAIR_UNSIGNED("RxBitRate", rx))));
if (r < 0)
return r;
}
*ret = TAKE_PTR(v);
return 0;
}