diff options
-rw-r--r-- | interface.c | 2 | ||||
-rw-r--r-- | interface.h | 1 | ||||
-rw-r--r-- | system-dummy.c | 11 | ||||
-rw-r--r-- | system-linux.c | 15 | ||||
-rw-r--r-- | system.h | 3 | ||||
-rw-r--r-- | ubus.c | 7 |
6 files changed, 39 insertions, 0 deletions
diff --git a/interface.c b/interface.c index 3820050..17cb754 100644 --- a/interface.c +++ b/interface.c @@ -9,6 +9,7 @@ #include "proto.h" #include "ubus.h" #include "config.h" +#include "system.h" struct vlist_tree interfaces; @@ -238,6 +239,7 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve return; iface->state = IFS_UP; + iface->start_time = system_get_rtime(); interface_event(iface, IFEV_UP); break; case IFPEV_DOWN: diff --git a/interface.h b/interface.h index 4d53c83..0e81304 100644 --- a/interface.h +++ b/interface.h @@ -48,6 +48,7 @@ struct interface { bool autostart; bool config_autostart; + time_t start_time; enum interface_state state; enum interface_config_state config_state; diff --git a/system-dummy.c b/system-dummy.c index 31bfac8..4c9a8fc 100644 --- a/system-dummy.c +++ b/system-dummy.c @@ -1,3 +1,4 @@ +#include <sys/time.h> #include <stdio.h> #include <string.h> @@ -165,3 +166,13 @@ int system_del_route(struct device *dev, struct device_route *route) D(SYSTEM, "route del %s%s%s\n", addr, gw, devstr); return 0; } + +time_t system_get_rtime(void) +{ + struct timeval tv; + + if (gettimeofday(&tv, NULL) == 0) + return tv.tv_sec; + + return 0; +} diff --git a/system-linux.c b/system-linux.c index 9f1aa9e..aba603f 100644 --- a/system-linux.c +++ b/system-linux.c @@ -1,6 +1,7 @@ #include <sys/socket.h> #include <sys/ioctl.h> #include <sys/stat.h> +#include <sys/syscall.h> #include <linux/rtnetlink.h> #include <linux/sockios.h> @@ -395,3 +396,17 @@ int system_del_route(struct device *dev, struct device_route *route) { return system_rt(dev, route, RTM_DELROUTE); } + +time_t system_get_rtime(void) +{ + struct timespec ts; + struct timeval tv; + + if (syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &ts) == 0) + return ts.tv_sec; + + if (gettimeofday(&tv, NULL) == 0) + return tv.tv_sec; + + return 0; +} @@ -1,6 +1,7 @@ #ifndef __NETIFD_SYSTEM_H #define __NETIFD_SYSTEM_H +#include <sys/time.h> #include <sys/socket.h> #include "device.h" #include "interface-ip.h" @@ -43,4 +44,6 @@ int system_del_address(struct device *dev, struct device_addr *addr); int system_add_route(struct device *dev, struct device_route *route); int system_del_route(struct device *dev, struct device_route *route); +time_t system_get_rtime(void); + #endif @@ -4,6 +4,7 @@ #include "interface.h" #include "proto.h" #include "ubus.h" +#include "system.h" static struct ubus_context *ctx = NULL; static struct blob_buf b; @@ -177,6 +178,12 @@ netifd_handle_status(struct ubus_context *ctx, struct ubus_object *obj, blobmsg_add_u8(&b, "pending", iface->state == IFS_SETUP); blobmsg_add_u8(&b, "available", iface->available); blobmsg_add_u8(&b, "autostart", iface->autostart); + + if (iface->state == IFS_UP) { + time_t cur = system_get_rtime(); + blobmsg_add_u32(&b, "uptime", cur - iface->start_time); + } + if (iface->main_dev.dev) { struct device *dev = iface->main_dev.dev; const char *field; |