diff --git a/netdev.c b/netdev.c index a512022..98e3d57 100644 --- a/netdev.c +++ b/netdev.c @@ -146,7 +146,7 @@ static int get_counter_delta(__u32 new, __u32 old) } void -iface_dump(void) +iface_dump(int delta) { struct iface *iface; @@ -176,28 +176,43 @@ iface_dump(void) blobmsg_close_array(&b, d); } - d = blobmsg_open_table(&b, "stats"); - blobmsg_add_u32(&b, "rx_packets", - get_counter_delta(iface->stats.rx_packets, iface->stats_old.rx_packets)); - blobmsg_add_u32(&b, "tx_packets", - get_counter_delta(iface->stats.tx_packets, iface->stats_old.tx_packets)); - blobmsg_add_u32(&b, "rx_bytes", - get_counter_delta(iface->stats.rx_bytes, iface->stats_old.rx_bytes)); - blobmsg_add_u32(&b, "tx_bytes", - get_counter_delta(iface->stats.tx_bytes, iface->stats_old.tx_bytes)); - blobmsg_add_u32(&b, "rx_errors", - get_counter_delta(iface->stats.rx_errors, iface->stats_old.rx_errors)); - blobmsg_add_u32(&b, "tx_errors", - get_counter_delta(iface->stats.tx_errors, iface->stats_old.tx_errors)); - blobmsg_add_u32(&b, "rx_dropped", - get_counter_delta(iface->stats.rx_dropped, iface->stats_old.rx_dropped)); - blobmsg_add_u32(&b, "tx_dropped", - get_counter_delta(iface->stats.tx_dropped, iface->stats_old.tx_dropped)); - blobmsg_add_u32(&b, "multicast", - get_counter_delta(iface->stats.multicast, iface->stats_old.multicast)); - blobmsg_add_u32(&b, "collisions", - get_counter_delta(iface->stats.collisions, iface->stats_old.collisions)); + d = blobmsg_open_table(&b, "counters"); + blobmsg_add_u32(&b, "rx_packets", iface->stats.rx_packets); + blobmsg_add_u32(&b, "tx_packets", iface->stats.tx_packets); + blobmsg_add_u32(&b, "rx_bytes", iface->stats.rx_bytes); + blobmsg_add_u32(&b, "tx_bytes", iface->stats.tx_bytes); + blobmsg_add_u32(&b, "rx_errors", iface->stats.rx_errors); + blobmsg_add_u32(&b, "tx_errors", iface->stats.tx_errors); + blobmsg_add_u32(&b, "rx_dropped", iface->stats.rx_dropped); + blobmsg_add_u32(&b, "tx_dropped", iface->stats.tx_dropped); + blobmsg_add_u32(&b, "multicast", iface->stats.multicast); + blobmsg_add_u32(&b, "collisions", iface->stats.collisions); blobmsg_close_table(&b, d); + + if (delta) { + d = blobmsg_open_table(&b, "deltas"); + blobmsg_add_u32(&b, "rx_packets", + get_counter_delta(iface->stats.rx_packets, iface->stats_old.rx_packets)); + blobmsg_add_u32(&b, "tx_packets", + get_counter_delta(iface->stats.tx_packets, iface->stats_old.tx_packets)); + blobmsg_add_u32(&b, "rx_bytes", + get_counter_delta(iface->stats.rx_bytes, iface->stats_old.rx_bytes)); + blobmsg_add_u32(&b, "tx_bytes", + get_counter_delta(iface->stats.tx_bytes, iface->stats_old.tx_bytes)); + blobmsg_add_u32(&b, "rx_errors", + get_counter_delta(iface->stats.rx_errors, iface->stats_old.rx_errors)); + blobmsg_add_u32(&b, "tx_errors", + get_counter_delta(iface->stats.tx_errors, iface->stats_old.tx_errors)); + blobmsg_add_u32(&b, "rx_dropped", + get_counter_delta(iface->stats.rx_dropped, iface->stats_old.rx_dropped)); + blobmsg_add_u32(&b, "tx_dropped", + get_counter_delta(iface->stats.tx_dropped, iface->stats_old.tx_dropped)); + blobmsg_add_u32(&b, "multicast", + get_counter_delta(iface->stats.multicast, iface->stats_old.multicast)); + blobmsg_add_u32(&b, "collisions", + get_counter_delta(iface->stats.collisions, iface->stats_old.collisions)); + blobmsg_close_table(&b, d); + } memcpy(&iface->stats_old, &iface->stats, sizeof(iface->stats)); bridge_dump_if(iface->name); diff --git a/ubus.c b/ubus.c index 176b353..10e8aa7 100644 --- a/ubus.c +++ b/ubus.c @@ -67,7 +67,24 @@ ubus_port_cb(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - iface_dump(); + enum { + DUMP_DELTA, + __DUMP_MAX + }; + + static const struct blobmsg_policy dump_policy[__DUMP_MAX] = { + [DUMP_DELTA] = { .name = "delta", .type = BLOBMSG_TYPE_INT32 }, + }; + + struct blob_attr *tb[__DUMP_MAX]; + int delta = 0; + + blobmsg_parse(dump_policy, __DUMP_MAX, tb, blob_data(msg), blob_len(msg)); + + if (tb[DUMP_DELTA]) + delta = blobmsg_get_u32(tb[DUMP_DELTA]); + + iface_dump(delta); ubus_send_reply(ctx, req, b.head); return UBUS_STATUS_OK; diff --git a/udevmand.h b/udevmand.h index c1244af..3781a47 100644 --- a/udevmand.h +++ b/udevmand.h @@ -140,4 +140,4 @@ char *interface_resolve(char *device); void ethers_init(void); -void iface_dump(void); +void iface_dump(int delta);