From 1466967ffa3e408b709d5e84932616787b2853ac Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 22 Jan 2012 19:09:50 +0100 Subject: [PATCH] show mtu, macaddr and txqueuelen from cached device settings --- device.c | 27 +++++++++++++++++++++++++++ system-linux.c | 2 -- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/device.c b/device.c index f5a719a..84e6528 100644 --- a/device.c +++ b/device.c @@ -175,6 +175,22 @@ static const struct device_type alias_device_type = { .free = alias_device_free, }; +static void +device_merge_settings(struct device *dev, struct device_settings *n) +{ + struct device_settings *os = &dev->orig_settings; + struct device_settings *s = &dev->settings; + + memset(n, 0, sizeof(*n)); + n->mtu = s->flags & DEV_OPT_MTU ? s->mtu : os->mtu; + n->txqueuelen = s->flags & DEV_OPT_TXQUEUELEN ? + s->txqueuelen : os->txqueuelen; + memcpy(n->macaddr, + (s->flags & DEV_OPT_MACADDR ? s->macaddr : os->macaddr), + sizeof(n->macaddr)); + n->flags = s->flags | os->flags; +} + void device_init_settings(struct device *dev, struct blob_attr **tb) { @@ -652,6 +668,7 @@ device_create(const char *name, const struct device_type *type, void device_dump_status(struct blob_buf *b, struct device *dev) { + struct device_settings st; void *c, *s; if (!dev) { @@ -676,6 +693,16 @@ device_dump_status(struct blob_buf *b, struct device *dev) else system_if_dump_info(dev, b); + if (dev->active) { + device_merge_settings(dev, &st); + if (st.flags & DEV_OPT_MTU) + blobmsg_add_u32(b, "mtu", st.mtu); + if (st.flags & DEV_OPT_MACADDR) + blobmsg_add_string(b, "macaddr", ether_ntoa((struct ether_addr *) st.macaddr)); + if (st.flags & DEV_OPT_TXQUEUELEN) + blobmsg_add_u32(b, "txqueuelen", st.txqueuelen); + } + s = blobmsg_open_table(b, "statistics"); if (dev->type->dump_stats) dev->type->dump_stats(dev, b); diff --git a/system-linux.c b/system-linux.c index 4fa0ead..34d7cae 100644 --- a/system-linux.c +++ b/system-linux.c @@ -746,8 +746,6 @@ system_if_dump_info(struct device *dev, struct blob_buf *b) if (read_int_file(dir_fd, "carrier", &val)) blobmsg_add_u8(b, "link", !!val); - if (read_string_file(dir_fd, "address", buf, sizeof(buf))) - blobmsg_add_string(b, "macaddr", buf); memset(&ecmd, 0, sizeof(ecmd)); memset(&ifr, 0, sizeof(ifr)); -- 2.25.1