From 8875f2d067b84a40731983fd495f3e0e4daa493b Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 2 May 2013 15:26:47 +0200 Subject: [PATCH] Record device-network relation in state file, fix zone hotplug events --- options.c | 7 +++++++ options.h | 2 +- utils.c | 9 ++++++--- zones.c | 27 +++++++-------------------- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/options.c b/options.c index 47cd727..26aeefe 100644 --- a/options.c +++ b/options.c @@ -203,6 +203,7 @@ fw3_parse_limit(void *ptr, const char *val, bool is_list) bool fw3_parse_device(void *ptr, const char *val, bool is_list) { + char *p; struct fw3_device dev = { }; if (*val == '*') @@ -219,6 +220,12 @@ fw3_parse_device(void *ptr, const char *val, bool is_list) while (isspace(*++val)); } + if ((p = strchr(val, '@')) != NULL) + { + *p++ = 0; + snprintf(dev.network, sizeof(dev.network), "%s", p); + } + if (*val) snprintf(dev.name, sizeof(dev.name), "%s", val); else diff --git a/options.h b/options.h index 5678451..0a22cb6 100644 --- a/options.h +++ b/options.h @@ -147,7 +147,7 @@ struct fw3_device bool any; bool invert; char name[32]; - struct fw3_device *network; + char network[32]; }; struct fw3_address diff --git a/utils.c b/utils.c index 409ae43..f08443e 100644 --- a/utils.c +++ b/utils.c @@ -470,7 +470,10 @@ write_zone_uci(struct uci_context *ctx, struct fw3_zone *z, if (dev->invert) p += sprintf(p, "!"); - p += sprintf(p, "%s", dev->name); + if (*dev->network) + p += sprintf(p, "%s@%s", dev->name, dev->network); + else + p += sprintf(p, "%s", dev->name); ptr.value = buf; uci_add_list(ctx, &ptr); @@ -670,7 +673,7 @@ fw3_hotplug(bool add, void *zone, void *device) struct fw3_zone *z = zone; struct fw3_device *d = device; - if (!d->network) + if (!*d->network) return false; switch (fork()) @@ -694,7 +697,7 @@ fw3_hotplug(bool add, void *zone, void *device) clearenv(); setenv("ACTION", add ? "add" : "remove", 1); setenv("ZONE", z->name, 1); - setenv("INTERFACE", d->network->name, 1); + setenv("INTERFACE", d->network, 1); setenv("DEVICE", d->name, 1); execl(FW3_HOTPLUG, FW3_HOTPLUG, "firewall", NULL); diff --git a/zones.c b/zones.c index 55f2e6c..b0fcaee 100644 --- a/zones.c +++ b/zones.c @@ -132,7 +132,7 @@ resolve_networks(struct uci_element *e, struct fw3_zone *zone) continue; } - tmp->network = net; + snprintf(tmp->network, sizeof(tmp->network), "%s", net->name); list_add_tail(&tmp->list, &zone->devices); } } @@ -530,30 +530,17 @@ fw3_hotplug_zones(struct fw3_state *state, bool add) struct fw3_zone *z; struct fw3_device *d; - if (add) + list_for_each_entry(z, &state->zones, list) { - list_for_each_entry(z, &state->zones, list) + if (add != hasbit(z->flags[0], FW3_FLAG_HOTPLUG)) { - if (!hasbit(z->flags[0], FW3_FLAG_HOTPLUG)) - { - list_for_each_entry(d, &z->devices, list) - fw3_hotplug(add, z, d); + list_for_each_entry(d, &z->devices, list) + fw3_hotplug(add, z, d); + if (add) setbit(z->flags[0], FW3_FLAG_HOTPLUG); - } - } - } - else - { - list_for_each_entry(z, &state->zones, list) - { - if (hasbit(z->flags[0], FW3_FLAG_HOTPLUG)) - { - list_for_each_entry(d, &z->devices, list) - fw3_hotplug(add, z, d); - + else delbit(z->flags[0], FW3_FLAG_HOTPLUG); - } } } } -- 2.11.0