#include "proto.h"
#include "ubus.h"
#include "config.h"
+#include "system.h"
struct vlist_tree interfaces;
return;
iface->state = IFS_UP;
+ iface->start_time = system_get_rtime();
interface_event(iface, IFEV_UP);
break;
case IFPEV_DOWN:
bool autostart;
bool config_autostart;
+ time_t start_time;
enum interface_state state;
enum interface_config_state config_state;
+#include <sys/time.h>
#include <stdio.h>
#include <string.h>
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;
+}
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
+#include <sys/syscall.h>
#include <linux/rtnetlink.h>
#include <linux/sockios.h>
{
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;
+}
#ifndef __NETIFD_SYSTEM_H
#define __NETIFD_SYSTEM_H
+#include <sys/time.h>
#include <sys/socket.h>
#include "device.h"
#include "interface-ip.h"
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
#include "interface.h"
#include "proto.h"
#include "ubus.h"
+#include "system.h"
static struct ubus_context *ctx = NULL;
static struct blob_buf b;
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;