summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2020-07-18 12:01:23 +0200
committerFelix Fietkau <nbd@nbd.name>2020-07-19 11:02:54 +0200
commit6086b63b4ca24ce4f23774d5ad49b5791f0b1705 (patch)
treef40d705740c70f5b5f74115998da7f78f582a278 /config.c
parent0e8cea0f2acdae3812f9603ee046055acd89d717 (diff)
downloadnetifd-6086b63b4ca24ce4f23774d5ad49b5791f0b1705.tar.gz
config: enable bridge vlan filtering by default for bridges that define VLANs
Only enables it if the config option is not present. It can still be disabled. Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'config.c')
-rw-r--r--config.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/config.c b/config.c
index a9f2651..526a20f 100644
--- a/config.c
+++ b/config.c
@@ -52,6 +52,49 @@ config_section_idx(struct uci_section *s)
return -1;
}
+static bool
+config_bridge_has_vlans(const char *br_name)
+{
+ struct uci_element *e;
+
+ uci_foreach_element(&uci_network->sections, e) {
+ struct uci_section *s = uci_to_section(e);
+ const char *name;
+
+ if (strcmp(s->type, "bridge-vlan") != 0)
+ continue;
+
+ name = uci_lookup_option_string(uci_ctx, s, "device");
+ if (!name)
+ continue;
+
+ if (!strcmp(name, br_name))
+ return true;
+ }
+
+ return false;
+}
+
+static void
+config_fixup_bridge_vlan_filtering(struct uci_section *s, const char *name)
+{
+ struct uci_ptr ptr = {
+ .p = s->package,
+ .s = s,
+ .option = "vlan_filtering",
+ .value = "1",
+ };
+
+ if (!config_bridge_has_vlans(name))
+ return;
+
+ uci_lookup_ptr(uci_ctx, &ptr, NULL, false);
+ if (ptr.o)
+ return;
+
+ uci_set(uci_ctx, &ptr);
+}
+
static int
config_parse_bridge_interface(struct uci_section *s, struct device_type *devtype)
{
@@ -61,6 +104,7 @@ config_parse_bridge_interface(struct uci_section *s, struct device_type *devtype
sprintf(name, "%s-%s", devtype->name_prefix, s->e.name);
blobmsg_add_string(&b, "name", name);
+ config_fixup_bridge_vlan_filtering(s, name);
uci_to_blob(&b, s, devtype->config_params);
if (!device_create(name, devtype, b.head)) {
D(INTERFACE, "Failed to create '%s' device for interface '%s'\n",
@@ -194,6 +238,9 @@ config_init_devices(void)
if (!params)
params = simple_device_type.config_params;
+ if (devtype && devtype->bridge_capability)
+ config_fixup_bridge_vlan_filtering(s, name);
+
blob_buf_init(&b, 0);
uci_to_blob(&b, s, params);
if (devtype) {