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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user