summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrenato <renato@openbsd.org>2016-05-23 18:43:28 +0000
committerrenato <renato@openbsd.org>2016-05-23 18:43:28 +0000
commit3ef9ea36df866157356d31fd649d5e1ec675df17 (patch)
tree1fb6d33544ab337ad03dd4762cad3fc155a780d1
parentEnable changing the router-id via config reload. (diff)
downloadwireguard-openbsd-3ef9ea36df866157356d31fd649d5e1ec675df17.tar.xz
wireguard-openbsd-3ef9ea36df866157356d31fd649d5e1ec675df17.zip
Use SO_BINDANY before binding sockets to the transport-address.
This allows ldpd to start on a system without any IP address and bind to the transport-address successfully. Without this patch, we'd need to monitor the new addresses from the kernel and create the network sockets only when the transport-address is available in the system.
-rw-r--r--usr.sbin/ldpd/ldpd.h3
-rw-r--r--usr.sbin/ldpd/socket.c18
2 files changed, 19 insertions, 2 deletions
diff --git a/usr.sbin/ldpd/ldpd.h b/usr.sbin/ldpd/ldpd.h
index 7e961a7e30a..b95fb966e63 100644
--- a/usr.sbin/ldpd/ldpd.h
+++ b/usr.sbin/ldpd/ldpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpd.h,v 1.68 2016/05/23 18:40:15 renato Exp $ */
+/* $OpenBSD: ldpd.h,v 1.69 2016/05/23 18:43:28 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -508,6 +508,7 @@ void evbuf_clear(struct evbuf *);
int ldp_create_socket(enum socket_type);
void sock_set_recvbuf(int);
int sock_set_reuse(int, int);
+int sock_set_bindany(int, int);
int sock_set_ipv4_mcast_ttl(int, uint8_t);
int sock_set_ipv4_tos(int, int);
int sock_set_ipv4_recvif(int, int);
diff --git a/usr.sbin/ldpd/socket.c b/usr.sbin/ldpd/socket.c
index 1b5fc54e639..f4e1120faab 100644
--- a/usr.sbin/ldpd/socket.c
+++ b/usr.sbin/ldpd/socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: socket.c,v 1.4 2016/05/23 18:33:56 renato Exp $ */
+/* $OpenBSD: socket.c,v 1.5 2016/05/23 18:43:28 renato Exp $ */
/*
* Copyright (c) 2016 Renato Westphal <renato@openbsd.org>
@@ -73,6 +73,10 @@ ldp_create_socket(enum socket_type type)
case LDP_SOCKET_EDISC:
case LDP_SOCKET_SESSION:
local_sa.sin_addr = ldpd_conf->trans_addr;
+ if (sock_set_bindany(fd, 1) == -1) {
+ close(fd);
+ return (-1);
+ }
break;
}
if (sock_set_reuse(fd, 1) == -1) {
@@ -157,6 +161,18 @@ sock_set_reuse(int fd, int enable)
}
int
+sock_set_bindany(int fd, int enable)
+{
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDANY, &enable,
+ sizeof(int)) < 0) {
+ log_warn("%s: error setting SO_BINDANY", __func__);
+ return (-1);
+ }
+
+ return (0);
+}
+
+int
sock_set_ipv4_mcast_ttl(int fd, uint8_t ttl)
{
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL,