]> granicus.if.org Git - pdns/commitdiff
dnsdist: Also apply SO_BINDTODEVICE to TCP sockets
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 4 Oct 2019 08:44:33 +0000 (10:44 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 4 Oct 2019 08:44:33 +0000 (10:44 +0200)
pdns/dnsdist-tcp.cc

index 403fbf601768370e17769bb603f07ae736c72a69..a387bee4e7f9c9f1c2de9c86c598e0432a8505df 100644 (file)
@@ -79,6 +79,12 @@ static std::unique_ptr<Socket> setupTCPDownstream(shared_ptr<DownstreamState>& d
         if (ds->ipBindAddrNoPort) {
           SSetsockopt(result->getHandle(), SOL_IP, IP_BIND_ADDRESS_NO_PORT, 1);
         }
+#endif
+#ifdef SO_BINDTODEVICE
+        int res = setsockopt(result->getHandle(), SOL_SOCKET, SO_BINDTODEVICE, ds->sourceItfName.c_str(), ds->sourceItfName.length());
+        if (res != 0) {
+          vinfolog("Error setting up the interface on backend TCP socket '%s': %s", ds->getNameWithAddr(), stringerror());
+        }
 #endif
         result->bind(ds->sourceAddr, false);
       }