[PATCH 2/3] netifd: ubus: call system_get_rtime only once per dump call
Jonas Lochmann
openwrt at jonaslochmann.de
Sat Dec 27 11:31:45 PST 2025
This ensures that all relative times are consistent with each other
Signed-off-by: Jonas Lochmann <openwrt at jonaslochmann.de>
---
ubus.c | 47 ++++++++++++++++++++++-------------------------
1 file changed, 22 insertions(+), 25 deletions(-)
diff --git a/ubus.c b/ubus.c
index 64bd874..778fb10 100644
--- a/ubus.c
+++ b/ubus.c
@@ -515,7 +515,7 @@ netifd_add_interface_errors(struct blob_buf *b, struct interface *iface)
}
static void
-interface_ip_dump_address_list(struct interface_ip_settings *ip, bool v6, bool enabled)
+interface_ip_dump_address_list(struct interface_ip_settings *ip, time_t now, bool v6, bool enabled)
{
struct device_addr *addr;
char *buf;
@@ -523,7 +523,6 @@ interface_ip_dump_address_list(struct interface_ip_settings *ip, bool v6, bool e
int buflen = 128;
int af;
- time_t now = system_get_rtime();
vlist_for_each_element(&ip->addr, addr, node) {
if (addr->enabled != enabled)
continue;
@@ -605,7 +604,7 @@ interface_ip_dump_neighbor_list(struct interface_ip_settings *ip, bool enabled)
}
static void
-interface_ip_dump_route_list(struct interface_ip_settings *ip, bool enabled)
+interface_ip_dump_route_list(struct interface_ip_settings *ip, time_t now, bool enabled)
{
struct device_route *route;
int buflen = 128;
@@ -613,7 +612,6 @@ interface_ip_dump_route_list(struct interface_ip_settings *ip, bool enabled)
void *r;
int af;
- time_t now = system_get_rtime();
vlist_for_each_element(&ip->route, route, node) {
if (route->enabled != enabled)
continue;
@@ -667,14 +665,13 @@ interface_ip_dump_route_list(struct interface_ip_settings *ip, bool enabled)
static void
-interface_ip_dump_prefix_list(struct interface_ip_settings *ip)
+interface_ip_dump_prefix_list(struct interface_ip_settings *ip, time_t now)
{
struct device_prefix *prefix;
char *buf;
void *a, *c;
const int buflen = INET6_ADDRSTRLEN;
- time_t now = system_get_rtime();
vlist_for_each_element(&ip->prefix, prefix, node) {
a = blobmsg_open_table(&b, NULL);
@@ -723,12 +720,11 @@ interface_ip_dump_prefix_list(struct interface_ip_settings *ip)
static void
-interface_ip_dump_prefix_assignment_list(struct interface *iface)
+interface_ip_dump_prefix_assignment_list(struct interface *iface, time_t now)
{
void *a;
char *buf;
const int buflen = INET6_ADDRSTRLEN;
- time_t now = system_get_rtime();
struct device_prefix *prefix;
list_for_each_entry(prefix, &prefixes, head) {
@@ -810,6 +806,8 @@ netifd_dump_status(struct interface *iface)
struct device *dev;
void *a, *inactive;
+ time_t now = system_get_rtime();
+
blobmsg_add_u8(&b, "up", iface->state == IFS_UP);
blobmsg_add_u8(&b, "pending", iface->state == IFS_SETUP);
blobmsg_add_u8(&b, "available", iface->available);
@@ -817,8 +815,7 @@ netifd_dump_status(struct interface *iface)
blobmsg_add_u8(&b, "dynamic", iface->dynamic);
if (iface->state == IFS_UP) {
- time_t cur = system_get_rtime();
- blobmsg_add_u32(&b, "uptime", cur - iface->start_time);
+ blobmsg_add_u32(&b, "uptime", now - iface->start_time);
if (iface->l3_dev.dev)
blobmsg_add_string(&b, "l3_device", iface->l3_dev.dev->ifname);
}
@@ -865,23 +862,23 @@ netifd_dump_status(struct interface *iface)
if (iface->assignment_weight)
blobmsg_add_u32(&b, "ip6weight", iface->assignment_weight);
a = blobmsg_open_array(&b, "ipv4-address");
- interface_ip_dump_address_list(&iface->config_ip, false, true);
- interface_ip_dump_address_list(&iface->proto_ip, false, true);
+ interface_ip_dump_address_list(&iface->config_ip, now, false, true);
+ interface_ip_dump_address_list(&iface->proto_ip, now, false, true);
blobmsg_close_array(&b, a);
a = blobmsg_open_array(&b, "ipv6-address");
- interface_ip_dump_address_list(&iface->config_ip, true, true);
- interface_ip_dump_address_list(&iface->proto_ip, true, true);
+ interface_ip_dump_address_list(&iface->config_ip, now, true, true);
+ interface_ip_dump_address_list(&iface->proto_ip, now, true, true);
blobmsg_close_array(&b, a);
a = blobmsg_open_array(&b, "ipv6-prefix");
- interface_ip_dump_prefix_list(&iface->config_ip);
- interface_ip_dump_prefix_list(&iface->proto_ip);
+ interface_ip_dump_prefix_list(&iface->config_ip, now);
+ interface_ip_dump_prefix_list(&iface->proto_ip, now);
blobmsg_close_array(&b, a);
a = blobmsg_open_array(&b, "ipv6-prefix-assignment");
- interface_ip_dump_prefix_assignment_list(iface);
+ interface_ip_dump_prefix_assignment_list(iface, now);
blobmsg_close_array(&b, a);
a = blobmsg_open_array(&b, "route");
- interface_ip_dump_route_list(&iface->config_ip, true);
- interface_ip_dump_route_list(&iface->proto_ip, true);
+ interface_ip_dump_route_list(&iface->config_ip, now, true);
+ interface_ip_dump_route_list(&iface->proto_ip, now, true);
blobmsg_close_array(&b, a);
a = blobmsg_open_array(&b, "dns-server");
interface_ip_dump_dns_server_list(&iface->config_ip, true);
@@ -898,16 +895,16 @@ netifd_dump_status(struct interface *iface)
inactive = blobmsg_open_table(&b, "inactive");
a = blobmsg_open_array(&b, "ipv4-address");
- interface_ip_dump_address_list(&iface->config_ip, false, false);
- interface_ip_dump_address_list(&iface->proto_ip, false, false);
+ interface_ip_dump_address_list(&iface->config_ip, now, false, false);
+ interface_ip_dump_address_list(&iface->proto_ip, now, false, false);
blobmsg_close_array(&b, a);
a = blobmsg_open_array(&b, "ipv6-address");
- interface_ip_dump_address_list(&iface->config_ip, true, false);
- interface_ip_dump_address_list(&iface->proto_ip, true, false);
+ interface_ip_dump_address_list(&iface->config_ip, now, true, false);
+ interface_ip_dump_address_list(&iface->proto_ip, now, true, false);
blobmsg_close_array(&b, a);
a = blobmsg_open_array(&b, "route");
- interface_ip_dump_route_list(&iface->config_ip, false);
- interface_ip_dump_route_list(&iface->proto_ip, false);
+ interface_ip_dump_route_list(&iface->config_ip, now, false);
+ interface_ip_dump_route_list(&iface->proto_ip, now, false);
blobmsg_close_array(&b, a);
a = blobmsg_open_array(&b, "dns-server");
interface_ip_dump_dns_server_list(&iface->config_ip, false);
--
2.47.3
More information about the openwrt-devel
mailing list