Skip to content

Commit

Permalink
Merge pull request #4332 from rgacogne/auth-apply-non-local-bind-query
Browse files Browse the repository at this point in the history
auth: Apply `non-local-bind` to `query-local-address{,6}` when possible
  • Loading branch information
Habbie committed Sep 5, 2016
2 parents 633c082 + f688119 commit 0ce6a3c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pdns/mastercommunicator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ bool CommunicatorClass::justNotified(const DNSName &domain, const string &ip)

void CommunicatorClass::makeNotifySockets()
{
d_nsock4 = makeQuerySocket(ComboAddress(::arg()["query-local-address"]), true);
d_nsock4 = makeQuerySocket(ComboAddress(::arg()["query-local-address"]), true, ::arg().mustDo("non-local-bind"));
if(!::arg()["query-local-address6"].empty())
d_nsock6 = makeQuerySocket(ComboAddress(::arg()["query-local-address6"]), true);
d_nsock6 = makeQuerySocket(ComboAddress(::arg()["query-local-address6"]), true, ::arg().mustDo("non-local-bind"));
else
d_nsock6 = -1;
}
Expand Down
10 changes: 7 additions & 3 deletions pdns/resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include "gss_context.hh"
#include "namespaces.hh"

int makeQuerySocket(const ComboAddress& local, bool udpOrTCP)
int makeQuerySocket(const ComboAddress& local, bool udpOrTCP, bool nonLocalBind)
{
ComboAddress ourLocal(local);

Expand All @@ -64,6 +64,10 @@ int makeQuerySocket(const ComboAddress& local, bool udpOrTCP)
}

setCloseOnExec(sock);

if(nonLocalBind)
Utility::setBindAny(local.sin4.sin_family, sock);

if(udpOrTCP) {
// udp, try hard to bind an unpredictable port
int tries=10;
Expand Down Expand Up @@ -95,9 +99,9 @@ Resolver::Resolver()
locals["default4"] = -1;
locals["default6"] = -1;
try {
locals["default4"] = makeQuerySocket(ComboAddress(::arg()["query-local-address"]), true);
locals["default4"] = makeQuerySocket(ComboAddress(::arg()["query-local-address"]), true, ::arg().mustDo("non-local-bind"));
if(!::arg()["query-local-address6"].empty())
locals["default6"] = makeQuerySocket(ComboAddress(::arg()["query-local-address6"]), true);
locals["default6"] = makeQuerySocket(ComboAddress(::arg()["query-local-address6"]), true, ::arg().mustDo("non-local-bind"));
}
catch(...) {
if(locals["default4"]>=0)
Expand Down
2 changes: 1 addition & 1 deletion pdns/resolver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public:
};

// make an IPv4 or IPv6 query socket
int makeQuerySocket(const ComboAddress& local, bool udpOrTCP);
int makeQuerySocket(const ComboAddress& local, bool udpOrTCP, bool nonLocalBind=false);
//! Resolver class. Can be used synchronously and asynchronously, over IPv4 and over IPv6 (simultaneously)
class Resolver : public boost::noncopyable
{
Expand Down

0 comments on commit 0ce6a3c

Please sign in to comment.