summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau2024-11-08 09:33:35 +0000
committerFelix Fietkau2024-11-08 09:33:45 +0000
commit34eb11eb6f5c62de480d6192f0ca840093127fee (patch)
tree9b76570a25f8976b4dfffdaca4453f5c6094c947
parent992d33cb42a6e70d98a65f55fb9d000de0fd613b (diff)
device/interface: add "tags" attribute from config to status dump
This allows annotating interfaces/devices in the config in a way that can be queried through status. One example use case is to mark wifi interfaces for use with specific services without having to explicitly reference sections from elsewhere. Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--device.c9
-rw-r--r--device.h2
-rw-r--r--interface.c4
-rw-r--r--interface.h1
-rw-r--r--ubus.c2
5 files changed, 18 insertions, 0 deletions
diff --git a/device.c b/device.c
index 0ec3409..06f52cc 100644
--- a/device.c
+++ b/device.c
@@ -75,6 +75,7 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
[DEV_ATTR_GRO] = { .name = "gro", .type = BLOBMSG_TYPE_BOOL },
[DEV_ATTR_MASTER] = { .name = "conduit", .type = BLOBMSG_TYPE_STRING },
[DEV_ATTR_EEE] = { .name = "eee", .type = BLOBMSG_TYPE_BOOL },
+ [DEV_ATTR_TAGS] = { .name = "tags", .type = BLOBMSG_TYPE_ARRAY },
};
const struct uci_blob_param_list device_attr_list = {
@@ -585,6 +586,10 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
free(dev->config_auth_vlans);
dev->config_auth_vlans = cur ? blob_memdup(cur) : NULL;
+ cur = tb[DEV_ATTR_TAGS];
+ free(dev->tags);
+ dev->tags = cur ? blob_memdup(cur) : NULL;
+
device_set_extra_vlans(dev, tb[DEV_ATTR_VLAN]);
device_set_disabled(dev, disabled);
}
@@ -1085,6 +1090,7 @@ device_free(struct device *dev)
free(dev->auth_vlans);
free(dev->config);
device_cleanup(dev);
+ free(dev->tags);
free(dev->config_auth_vlans);
free(dev->extra_vlan);
dev->type->free(dev);
@@ -1351,6 +1357,9 @@ device_dump_status(struct blob_buf *b, struct device *dev)
blobmsg_add_u8(b, "carrier", !!dev->link_active);
blobmsg_add_u8(b, "auth_status", !!dev->auth_status);
+ if (dev->tags)
+ blobmsg_add_blob(b, dev->tags);
+
if (dev->type->dump_info)
dev->type->dump_info(dev, b);
else
diff --git a/device.h b/device.h
index 1c01b58..bda204c 100644
--- a/device.h
+++ b/device.h
@@ -72,6 +72,7 @@ enum {
DEV_ATTR_GRO,
DEV_ATTR_MASTER,
DEV_ATTR_EEE,
+ DEV_ATTR_TAGS,
__DEV_ATTR_MAX,
};
@@ -250,6 +251,7 @@ struct device {
struct kvlist vlan_aliases;
struct blob_attr *config_auth_vlans;
struct blob_attr *auth_vlans;
+ struct blob_attr *tags;
char ifname[IFNAMSIZ];
int ifindex;
diff --git a/interface.c b/interface.c
index 923b5b3..3fcfc79 100644
--- a/interface.c
+++ b/interface.c
@@ -57,6 +57,7 @@ enum {
IFACE_ATTR_IP6IFACEID,
IFACE_ATTR_FORCE_LINK,
IFACE_ATTR_IP6WEIGHT,
+ IFACE_ATTR_TAGS,
IFACE_ATTR_MAX
};
@@ -87,6 +88,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
[IFACE_ATTR_IP6IFACEID] = { .name = "ip6ifaceid", .type = BLOBMSG_TYPE_STRING },
[IFACE_ATTR_FORCE_LINK] = { .name = "force_link", .type = BLOBMSG_TYPE_BOOL },
[IFACE_ATTR_IP6WEIGHT] = { .name = "ip6weight", .type = BLOBMSG_TYPE_INT32 },
+ [IFACE_ATTR_TAGS] = { .name = "tags", .type = BLOBMSG_TYPE_ARRAY },
};
const struct uci_blob_param_list interface_attr_list = {
@@ -978,6 +980,7 @@ static bool __interface_add(struct interface *iface, struct blob_attr *config, b
}
iface->config = config;
+ iface->tags = tb[IFACE_ATTR_TAGS];
vlist_add(&interfaces, &iface->node, iface->name);
if (name) {
@@ -1321,6 +1324,7 @@ interface_change_config(struct interface *if_old, struct interface *if_new)
})
if_old->config = if_new->config;
+ if_old->tags = if_new->tags;
if (if_old->config_autostart != if_new->config_autostart) {
if (if_old->config_autostart)
reload = true;
diff --git a/interface.h b/interface.h
index 122864f..08d74eb 100644
--- a/interface.h
+++ b/interface.h
@@ -145,6 +145,7 @@ struct interface {
struct device_user l3_dev;
struct blob_attr *config;
+ struct blob_attr *tags;
/* primary protocol state */
const struct proto_handler *proto_handler;
diff --git a/ubus.c b/ubus.c
index 3c3a7dc..5ab1884 100644
--- a/ubus.c
+++ b/ubus.c
@@ -838,6 +838,8 @@ netifd_dump_status(struct interface *iface)
if (iface->jail_device)
blobmsg_add_string(&b, "jail_device", iface->jail_device);
+ if (iface->tags)
+ blobmsg_add_blob(&b, iface->tags);
if (iface->state == IFS_UP) {
if (iface->updated) {