From: Felix Fietkau Date: Sat, 18 Jul 2020 10:01:23 +0000 (+0200) Subject: config: enable bridge vlan filtering by default for bridges that define VLANs X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=6086b63b4ca24ce4f23774d5ad49b5791f0b1705;p=project%2Fnetifd.git 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 --- 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) {