summaryrefslogtreecommitdiffstats
path: root/src/config.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-10-29 22:21:47 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-10-29 22:21:47 +0100
commit078b835209bd22b5cf3f497f2b06f3fad0a078ca (patch)
tree2704129741073ce83345cc3305fbf51a988d2842 /src/config.c
parentf5462bd63a1f6fc8879341c3eacd60e9824dec24 (diff)
downloadfastd-078b835209bd22b5cf3f497f2b06f3fad0a078ca.tar
fastd-078b835209bd22b5cf3f497f2b06f3fad0a078ca.zip
Add support for multiple binds
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/config.c b/src/config.c
index 4eee712..be67e2b 100644
--- a/src/config.c
+++ b/src/config.c
@@ -629,26 +629,34 @@ static void option_bind(fastd_context *ctx, fastd_config *conf, const char *arg)
l = 0;
}
- if (strcmp(addrstr, "any") == 0) {
- conf->bind_addr_in.sin_addr.s_addr = htonl(INADDR_ANY);
- conf->bind_addr_in.sin_port = htons(l);
+ fastd_bind_address *addr = calloc(1, sizeof(fastd_bind_address));
+ addr->next = conf->bind_addrs;
+ conf->bind_addrs = addr;
- conf->bind_addr_in6.sin6_addr = in6addr_any;
- conf->bind_addr_in6.sin6_port = htons(l);
+ if (strcmp(addrstr, "any") == 0) {
+ /* nothing to do */
}
else if (arg[0] == '[') {
- conf->bind_addr_in6.sin6_family = AF_INET6;
- if (inet_pton(AF_INET6, addrstr, &conf->bind_addr_in6.sin6_addr) != 1)
+ addr->addr.in6.sin6_family = AF_INET6;
+ addr->addr.in6.sin6_port = htons(l);
+
+ if (inet_pton(AF_INET6, addrstr, &addr->addr.in6.sin6_addr) != 1)
exit_error(ctx, "invalid bind address `%s'", addrstr);
- conf->bind_addr_in6.sin6_port = htons(l);
}
else {
- conf->bind_addr_in.sin_family = AF_INET;
- if (inet_pton(AF_INET, addrstr, &conf->bind_addr_in.sin_addr) != 1)
+ addr->addr.in.sin_family = AF_INET;
+ addr->addr.in.sin_port = htons(l);
+
+ if (inet_pton(AF_INET, addrstr, &addr->addr.in.sin_addr) != 1)
exit_error(ctx, "invalid bind address `%s'", addrstr);
- conf->bind_addr_in.sin_port = htons(l);
}
+ if (!conf->bind_addr_default_v4 && addr->addr.sa.sa_family != AF_INET6)
+ conf->bind_addr_default_v4 = addr;
+
+ if (!conf->bind_addr_default_v6 && addr->addr.sa.sa_family != AF_INET)
+ conf->bind_addr_default_v6 = addr;
+
free(addrstr);
}
@@ -886,6 +894,13 @@ void fastd_config_release(fastd_context *ctx, fastd_config *conf) {
conf->log_files = next;
}
+ while (conf->bind_addrs) {
+ fastd_bind_address *next = conf->bind_addrs->next;
+ free(conf->bind_addrs->bindtodev);
+ free(conf->bind_addrs);
+ conf->bind_addrs = next;
+ }
+
free(conf->ifname);
free(conf->secret);
free(conf->on_up);