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;
|
||||
}
|
||||
|
||||
@@ -411,6 +411,13 @@ static SD_VARLINK_DEFINE_STRUCT_TYPE(
|
||||
SD_VARLINK_FIELD_COMMENT("Static DHCP leases configured for specific clients"),
|
||||
SD_VARLINK_DEFINE_FIELD_BY_TYPE(StaticLeases, DHCPServerLease, SD_VARLINK_ARRAY|SD_VARLINK_NULLABLE));
|
||||
|
||||
static SD_VARLINK_DEFINE_STRUCT_TYPE(
|
||||
BitRates,
|
||||
SD_VARLINK_FIELD_COMMENT("Transmit bitrate in bits per second"),
|
||||
SD_VARLINK_DEFINE_FIELD(TxBitRate, SD_VARLINK_INT, 0),
|
||||
SD_VARLINK_FIELD_COMMENT("Receive bitrate in bits per second"),
|
||||
SD_VARLINK_DEFINE_FIELD(RxBitRate, SD_VARLINK_INT, 0));
|
||||
|
||||
static SD_VARLINK_DEFINE_STRUCT_TYPE(
|
||||
Interface,
|
||||
SD_VARLINK_FIELD_COMMENT("Network interface index"),
|
||||
@@ -533,7 +540,9 @@ static SD_VARLINK_DEFINE_STRUCT_TYPE(
|
||||
SD_VARLINK_FIELD_COMMENT("DHCPv6 client configuration and lease information"),
|
||||
SD_VARLINK_DEFINE_FIELD_BY_TYPE(DHCPv6Client, DHCPv6Client, SD_VARLINK_NULLABLE),
|
||||
SD_VARLINK_FIELD_COMMENT("LLDP transmit configuration for this interface"),
|
||||
SD_VARLINK_DEFINE_FIELD_BY_TYPE(LLDP, LLDPNeighbor, SD_VARLINK_NULLABLE));
|
||||
SD_VARLINK_DEFINE_FIELD_BY_TYPE(LLDP, LLDPNeighbor, SD_VARLINK_NULLABLE),
|
||||
SD_VARLINK_FIELD_COMMENT("Current transmit/receive bitrates from speed meter"),
|
||||
SD_VARLINK_DEFINE_FIELD_BY_TYPE(BitRates, BitRates, SD_VARLINK_NULLABLE));
|
||||
|
||||
static SD_VARLINK_DEFINE_METHOD(
|
||||
Describe,
|
||||
@@ -604,6 +613,7 @@ SD_VARLINK_DEFINE_INTERFACE(
|
||||
&vl_method_GetLLDPNeighbors,
|
||||
&vl_method_SetPersistentStorage,
|
||||
&vl_type_Address,
|
||||
&vl_type_BitRates,
|
||||
&vl_type_DHCPLease,
|
||||
&vl_type_DHCPServer,
|
||||
&vl_type_DHCPServerLease,
|
||||
|
||||
Reference in New Issue
Block a user