]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Bind to the requested src interface without a src address in auto-discovery... 11696/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 22 Jun 2022 11:36:47 +0000 (13:36 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 22 Jun 2022 11:36:47 +0000 (13:36 +0200)
pdns/dnsdistdist/dnsdist-discovery.cc

index 5cca42b15f2c25e40689e599b10108173706292e..51a634c26efce717ab2f5b300d49f1721fde387f 100644 (file)
@@ -254,6 +254,13 @@ bool ServiceDiscovery::getDiscoveredConfig(const UpgradeableBackend& upgradeable
 
     Socket sock(addr.sin4.sin_family, SOCK_STREAM);
     sock.setNonBlocking();
+
+#ifdef SO_BINDTODEVICE
+    if (!backend->d_config.sourceItfName.empty()) {
+      setsockopt(sock.getHandle(), SOL_SOCKET, SO_BINDTODEVICE, backend->d_config.sourceItfName.c_str(), backend->d_config.sourceItfName.length());
+    }
+#endif
+
     if (!IsAnyAddress(backend->d_config.sourceAddr)) {
       sock.setReuseAddr();
 #ifdef IP_BIND_ADDRESS_NO_PORT
@@ -261,12 +268,6 @@ bool ServiceDiscovery::getDiscoveredConfig(const UpgradeableBackend& upgradeable
         SSetsockopt(sock.getHandle(), SOL_IP, IP_BIND_ADDRESS_NO_PORT, 1);
       }
 #endif
-
-      if (!backend->d_config.sourceItfName.empty()) {
-#ifdef SO_BINDTODEVICE
-        setsockopt(sock.getHandle(), SOL_SOCKET, SO_BINDTODEVICE, backend->d_config.sourceItfName.c_str(), backend->d_config.sourceItfName.length());
-#endif
-      }
       sock.bind(backend->d_config.sourceAddr);
     }
     sock.connect(addr, backend->d_config.tcpConnectTimeout);