summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c13
-rw-r--r--src/fastd.c25
2 files changed, 21 insertions, 17 deletions
diff --git a/src/config.c b/src/config.c
index 5fa1591..b745251 100644
--- a/src/config.c
+++ b/src/config.c
@@ -491,19 +491,6 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con
}
}
- if (conf->n_floating && conf->bind_addr_in.sin_family == AF_UNSPEC
- && conf->bind_addr_in6.sin6_family == AF_UNSPEC) {
- conf->bind_addr_in.sin_family = AF_INET;
- conf->bind_addr_in6.sin6_family = AF_INET6;
- }
- else {
- if (conf->n_v4)
- conf->bind_addr_in.sin_family = AF_INET;
-
- if (conf->n_v6)
- conf->bind_addr_in6.sin6_family = AF_INET6;
- }
-
if (conf->mode == MODE_TUN && (!conf->peers || conf->peers->next))
exit_error(ctx, "config error: for tun mode exactly one peer must be configured");
diff --git a/src/fastd.c b/src/fastd.c
index 21e5027..939c651 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -77,13 +77,30 @@ static void init_tuntap(fastd_context *ctx) {
}
static void init_socket(fastd_context *ctx) {
- if (ctx->conf->bind_addr_in.sin_family == AF_INET) {
+ struct sockaddr_in addr_in = ctx->conf->bind_addr_in;
+ struct sockaddr_in6 addr_in6 = ctx->conf->bind_addr_in6;
+
+ if (addr_in.sin_family == AF_UNSPEC && addr_in6.sin6_family == AF_UNSPEC) {
+ if (ctx->conf->n_floating || ctx->conf->n_v4)
+ addr_in.sin_family = AF_INET;
+
+ if (ctx->conf->n_floating || ctx->conf->n_v6)
+ addr_in6.sin6_family = AF_INET6;
+ }
+
+ if (addr_in.sin_family == AF_UNSPEC && ctx->conf->n_v4)
+ pr_warn(ctx, "there are IPv4 peers defined, but bind is explicitly set to IPv6");
+
+ if (addr_in6.sin6_family == AF_UNSPEC && ctx->conf->n_v6)
+ pr_warn(ctx, "there are IPv6 peers defined, but bind is explicitly set to IPv4");
+
+ if (addr_in.sin_family == AF_INET) {
pr_debug(ctx, "Initializing IPv4 socket...");
if ((ctx->sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
exit_errno(ctx, "socket");
- if (bind(ctx->sockfd, (struct sockaddr*)&ctx->conf->bind_addr_in, sizeof(struct sockaddr_in)))
+ if (bind(ctx->sockfd, (struct sockaddr*)&addr_in, sizeof(struct sockaddr_in)))
exit_errno(ctx, "bind");
pr_debug(ctx, "IPv4 socket initialized.");
@@ -92,7 +109,7 @@ static void init_socket(fastd_context *ctx) {
ctx->sockfd = -1;
}
- if (ctx->conf->bind_addr_in6.sin6_family == AF_INET6) {
+ if (addr_in6.sin6_family == AF_INET6) {
pr_debug(ctx, "Initializing IPv6 socket...");
if ((ctx->sock6fd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
@@ -106,7 +123,7 @@ static void init_socket(fastd_context *ctx) {
if (setsockopt(ctx->sock6fd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val)))
exit_errno(ctx, "setsockopt");
- if (bind(ctx->sock6fd, (struct sockaddr*)&ctx->conf->bind_addr_in6, sizeof(struct sockaddr_in6)))
+ if (bind(ctx->sock6fd, (struct sockaddr*)&addr_in6, sizeof(struct sockaddr_in6)))
exit_errno(ctx, "bind");
pr_debug(ctx, "IPv6 socket initialized.");