make ip-transparent option work on OpenBSD

Florian Obser <[email protected]>
Newsgroups gmane.network.dns.nsd.general
Message-ID <[email protected]>
OpenBSD supports SO_BINDANY socket option from BSD/OS since 2008.

The same diff was sent to OpenBSD in 2016 by Delan Azabani but I was
not aware and basically came up with the same one.

( https://marc.info/?l=openbsd-tech&m=147747266305927&w=2 )

As far as I know it had not been submitted to nsd.

Thanks,
Florian

Index: server.c
===================================================================
--- server.c	(revision 4787)
+++ server.c	(working copy)
@@ -561,7 +561,7 @@
 {
 	struct addrinfo* addr;
 	size_t i;
-#if defined(SO_REUSEPORT) || defined(SO_REUSEADDR) || (defined(INET6) && (defined(IPV6_V6ONLY) || defined(IPV6_USE_MIN_MTU) || defined(IPV6_MTU) || defined(IP_TRANSPARENT)) || defined(IP_FREEBIND))
+#if defined(SO_REUSEPORT) || defined(SO_REUSEADDR) || (defined(INET6) && (defined(IPV6_V6ONLY) || defined(IPV6_USE_MIN_MTU) || defined(IPV6_MTU) || defined(IP_TRANSPARENT)) || defined(IP_FREEBIND) || defined(SO_BINDANY))
 	int on = 1;
 #endif
 
@@ -751,6 +751,12 @@
 					strerror(errno));
 			}
 #endif /* IP_TRANSPARENT */
+#ifdef SO_BINDANY
+			if (setsockopt(nsd->udp[i].s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on)) < 0) {
+				log_msg(LOG_ERR, "setsockopt(...,SO_BINDANY, ...) failed for udp: %s",
+					strerror(errno));
+			}
+#endif /* SO_BINDANY */
 		}
 
 		if (bind(nsd->udp[i].s, (struct sockaddr *) addr->ai_addr, addr->ai_addrlen) != 0) {
@@ -881,6 +887,12 @@
 					strerror(errno));
 			}
 #endif /* IP_TRANSPARENT */
+#ifdef SO_BINDANY
+			if (setsockopt(nsd->tcp[i].s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on)) < 0) {
+				log_msg(LOG_ERR, "setsockopt(...,SO_BINDANY, ...) failed for tcp: %s",
+					strerror(errno));
+			}
+#endif /* SO_BINDANY */
 		}
 
 		if (bind(nsd->tcp[i].s, (struct sockaddr *) addr->ai_addr, addr->ai_addrlen) != 0) {


-- 
I'm not entirely sure you are real.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.