summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-08-07 02:30:23 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-08-07 02:30:23 +0200
commit5ca89b31210b249f79a1a5cd1a258c85fdb7970e (patch)
treee08c894ab12d68c215713317d841ac6de552e619 /src
parentae90406453eb894400a25e0557bb2c7bf19f06a4 (diff)
downloadfastd-5ca89b31210b249f79a1a5cd1a258c85fdb7970e.tar
fastd-5ca89b31210b249f79a1a5cd1a258c85fdb7970e.zip
Guard socket options not available on FreeBSD
Diffstat (limited to 'src')
-rw-r--r--src/config.c14
-rw-r--r--src/config.y5
-rw-r--r--src/fastd.h2
-rw-r--r--src/receive.c4
-rw-r--r--src/send.c6
-rw-r--r--src/socket.c7
6 files changed, 34 insertions, 4 deletions
diff --git a/src/config.c b/src/config.c
index 0decec8..3ee5a76 100644
--- a/src/config.c
+++ b/src/config.c
@@ -212,7 +212,12 @@ bool fastd_config_crypto(fastd_context_t *ctx, fastd_config_t *conf, const char
return false;
}
-void fastd_config_bind_address(fastd_context_t *ctx, fastd_config_t *conf, const fastd_peer_address_t *address, const char *bindtodev, bool default_v4, bool default_v6) {
+bool fastd_config_bind_address(fastd_context_t *ctx, fastd_config_t *conf, const fastd_peer_address_t *address, const char *bindtodev, bool default_v4, bool default_v6) {
+#ifndef USE_BINDTODEVICE
+ if (bindtodev)
+ return false;
+#endif
+
fastd_bind_address_t *addr = malloc(sizeof(fastd_bind_address_t));
addr->next = conf->bind_addrs;
conf->bind_addrs = addr;
@@ -228,6 +233,8 @@ void fastd_config_bind_address(fastd_context_t *ctx, fastd_config_t *conf, const
if (addr->addr.sa.sa_family != AF_INET && (default_v6 || !conf->bind_addr_default_v6))
conf->bind_addr_default_v6 = addr;
+
+ return true;
}
void fastd_config_peer_group_push(fastd_context_t *ctx, fastd_config_t *conf, const char *name) {
@@ -612,6 +619,11 @@ void fastd_configure(fastd_context_t *ctx, fastd_config_t *conf, int argc, char
if (!conf->peers && !has_peer_group_peer_dirs(conf->peer_group))
exit_error(ctx, "config error: neither fixed peers nor peer dirs have been configured");
+#ifndef USE_PMTU
+ if (conf->pmtu.set)
+ exit_error(ctx, "config error: setting pmtu is not supported on this system");
+#endif
+
configure_user(ctx, conf);
ctx->conf = conf;
diff --git a/src/config.y b/src/config.y
index 65e95b3..16f3437 100644
--- a/src/config.y
+++ b/src/config.y
@@ -259,7 +259,10 @@ interface: TOK_STRING { free(conf->ifname); conf->ifname = strdup($1->str); }
;
bind: bind_address maybe_bind_interface maybe_bind_default {
- fastd_config_bind_address(ctx, conf, &$1, $2 ? $2->str : NULL, $3 == AF_UNSPEC || $3 == AF_INET, $3 == AF_UNSPEC || $3 == AF_INET6);
+ if (!fastd_config_bind_address(ctx, conf, &$1, $2 ? $2->str : NULL, $3 == AF_UNSPEC || $3 == AF_INET, $3 == AF_UNSPEC || $3 == AF_INET6)) {
+ fastd_config_error(&@$, ctx, conf, filename, depth, "invalid bind directive");
+ YYERROR;
+ }
}
;
diff --git a/src/fastd.h b/src/fastd.h
index cda86a9..5399e90 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -337,7 +337,7 @@ bool fastd_config_protocol(fastd_context_t *ctx, fastd_config_t *conf, const cha
bool fastd_config_method(fastd_context_t *ctx, fastd_config_t *conf, const char *name);
bool fastd_config_crypto(fastd_context_t *ctx, fastd_config_t *conf, const char *alg, const char *impl);
bool fastd_config_add_log_file(fastd_context_t *ctx, fastd_config_t *conf, const char *name, int level);
-void fastd_config_bind_address(fastd_context_t *ctx, fastd_config_t *conf, const fastd_peer_address_t *address, const char *bindtodev, bool default_v4, bool default_v6);
+bool fastd_config_bind_address(fastd_context_t *ctx, fastd_config_t *conf, const fastd_peer_address_t *address, const char *bindtodev, bool default_v4, bool default_v6);
void fastd_config_peer_group_push(fastd_context_t *ctx, fastd_config_t *conf, const char *name);
void fastd_config_peer_group_pop(fastd_context_t *ctx, fastd_config_t *conf);
void fastd_config_release(fastd_context_t *ctx, fastd_config_t *conf);
diff --git a/src/receive.c b/src/receive.c
index fc835eb..bf4b93e 100644
--- a/src/receive.c
+++ b/src/receive.c
@@ -40,6 +40,7 @@ static inline void handle_socket_control(fastd_context_t *ctx, struct msghdr *me
if ((char*)cmsg + sizeof(*cmsg) > end)
return;
+#ifdef USE_PKTINFO
if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_PKTINFO) {
struct in_pktinfo *pktinfo = (struct in_pktinfo*)CMSG_DATA(cmsg);
if ((char*)pktinfo + sizeof(*pktinfo) > end)
@@ -51,6 +52,7 @@ static inline void handle_socket_control(fastd_context_t *ctx, struct msghdr *me
return;
}
+#endif
if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
struct in6_pktinfo *pktinfo = (struct in6_pktinfo*)CMSG_DATA(cmsg);
@@ -173,11 +175,13 @@ void fastd_receive(fastd_context_t *ctx, fastd_socket_t *sock) {
handle_socket_control(ctx, &message, sock, &local_addr);
+#ifdef USE_PKTINFO
if (!local_addr.sa.sa_family) {
pr_error(ctx, "received packet without packet info");
fastd_buffer_free(buffer);
return;
}
+#endif
fastd_peer_address_simplify(&recvaddr);
diff --git a/src/send.c b/src/send.c
index 4e0d77a..2868d4d 100644
--- a/src/send.c
+++ b/src/send.c
@@ -35,6 +35,7 @@ static inline void add_pktinfo(struct msghdr *msg, const fastd_peer_address_t *l
struct cmsghdr *cmsg = (struct cmsghdr*)((char*)msg->msg_control + msg->msg_controllen);
+#ifdef USE_PKTINFO
if (local_addr->sa.sa_family == AF_INET) {
cmsg->cmsg_level = IPPROTO_IP;
cmsg->cmsg_type = IP_PKTINFO;
@@ -44,8 +45,11 @@ static inline void add_pktinfo(struct msghdr *msg, const fastd_peer_address_t *l
struct in_pktinfo *pktinfo = (struct in_pktinfo*)CMSG_DATA(cmsg);
pktinfo->ipi_addr = local_addr->in.sin_addr;
+ return;
}
- else if (local_addr->sa.sa_family == AF_INET6) {
+#endif
+
+ if (local_addr->sa.sa_family == AF_INET6) {
cmsg->cmsg_level = IPPROTO_IPV6;
cmsg->cmsg_type = IPV6_PKTINFO;
cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
diff --git a/src/socket.c b/src/socket.c
index c53695b..c5356f7 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -61,10 +61,13 @@ static int bind_socket(fastd_context_t *ctx, const fastd_bind_address_t *addr, b
fastd_setfl(ctx, fd, O_NONBLOCK, 0);
int one = 1;
+
+#ifdef USE_PKTINFO
if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &one, sizeof(one))) {
pr_error_errno(ctx, "setsockopt: unable to set IP_PKTINFO");
goto error;
}
+#endif
if (af == AF_INET6) {
if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &one, sizeof(one))) {
@@ -73,6 +76,7 @@ static int bind_socket(fastd_context_t *ctx, const fastd_bind_address_t *addr, b
}
}
+#ifdef USE_BINDTODEVICE
if (addr->bindtodev) {
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, addr->bindtodev, strlen(addr->bindtodev))) {
if (warn)
@@ -80,7 +84,9 @@ static int bind_socket(fastd_context_t *ctx, const fastd_bind_address_t *addr, b
goto error;
}
}
+#endif
+#ifdef USE_PMTU
if (ctx->conf->pmtu.set) {
int pmtu = ctx->conf->pmtu.state ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
if (setsockopt(fd, IPPROTO_IP, IP_MTU_DISCOVER, &pmtu, sizeof(pmtu))) {
@@ -88,6 +94,7 @@ static int bind_socket(fastd_context_t *ctx, const fastd_bind_address_t *addr, b
goto error;
}
}
+#endif
fastd_peer_address_t bind_address = addr->addr;