summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2016-11-16 11:54:43 +0100
committerGitHub <noreply@github.com>2016-11-16 11:54:43 +0100
commita3e1706720608c90a919be10d0df5a5a4a0edd55 (patch)
tree84d55d0f2812639ee318de32f7b4d21b349abd64
parent6ef79bcdc5b36a8adc6e077ec050aa6084f68854 (diff)
parent0b8a13ab51551f4a6a67f7f52a22256d6e15ba90 (diff)
Merge pull request #1248 from SaberUK/master+listen
Allow listeners to be able to listen on unavailable addresses.
-rw-r--r--docs/conf/inspircd.conf.example6
-rw-r--r--src/listensocket.cpp14
2 files changed, 20 insertions, 0 deletions
diff --git a/docs/conf/inspircd.conf.example b/docs/conf/inspircd.conf.example
index 7883ca6d3..a24510956 100644
--- a/docs/conf/inspircd.conf.example
+++ b/docs/conf/inspircd.conf.example
@@ -171,6 +171,12 @@
# To change it on a running bind, you'll have to comment it out,
# rehash, comment it in and rehash again.
defer="0"
+
+ # free: When this is enabled the listener will be created regardless of
+ # whether the interface that provides the bind address is available. This
+ # is useful for if you are starting InspIRCd on boot when the server may
+ # not have brought the network interfaces up yet.
+ free="no"
>
<bind address="" port="6660-6669" type="clients">
diff --git a/src/listensocket.cpp b/src/listensocket.cpp
index 13aebf75f..d09f5e624 100644
--- a/src/listensocket.cpp
+++ b/src/listensocket.cpp
@@ -54,6 +54,20 @@ ListenSocket::ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_t
}
#endif
+ if (tag->getBool("free"))
+ {
+ socklen_t enable = 1;
+#if defined IP_FREEBIND // Linux 2.4+
+ setsockopt(fd, SOL_IP, IP_FREEBIND, &enable, sizeof(enable));
+#elif defined IP_BINDANY // FreeBSD
+ setsockopt(fd, IPPROTO_IP, IP_BINDANY, &enable, sizeof(enable));
+#elif defined SO_BINDANY // NetBSD/OpenBSD
+ setsockopt(fd, SOL_SOCKET, SO_BINDANY, &enable, sizeof(enable));
+#else
+ (void)enable;
+#endif
+ }
+
SocketEngine::SetReuse(fd);
int rv = SocketEngine::Bind(this->fd, bind_to);
if (rv >= 0)