From 14c93e2b93e26785fa7056e5bbb3f97f2e6cb3b9 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Wed, 1 Sep 2021 14:36:38 -0300 Subject: [PATCH] Unbound callbacks also need arguments reversed PR #1725 reversed argument orders but UnboundResolver was still using (from,to) ordering in its callbacks, which leaked through to make a wrong order in our reply function (which simply forwards arguments). This fixes that bug by making UnboundResolver callback argument order consistent (i.e. using to, from) with the PacketHandler argument order. --- llarp/dns/server.cpp | 2 +- llarp/dns/unbound_resolver.cpp | 8 ++++---- llarp/dns/unbound_resolver.hpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/llarp/dns/server.cpp b/llarp/dns/server.cpp index deeea0dbe..5c8d6b4ca 100644 --- a/llarp/dns/server.cpp +++ b/llarp/dns/server.cpp @@ -58,7 +58,7 @@ namespace llarp::dns return true; auto failFunc = [self = weak_from_this()]( - const SockAddr& from, const SockAddr& to, Message msg) { + const SockAddr& to, const SockAddr& from, Message msg) { if (auto this_ptr = self.lock()) this_ptr->SendServerMessageBufferTo(to, from, msg.ToBuffer()); }; diff --git a/llarp/dns/unbound_resolver.cpp b/llarp/dns/unbound_resolver.cpp index 90ebbbcd3..422a5c6fd 100644 --- a/llarp/dns/unbound_resolver.cpp +++ b/llarp/dns/unbound_resolver.cpp @@ -58,7 +58,7 @@ namespace llarp::dns { Message& msg = lookup->msg; msg.AddServFail(); - this_ptr->failFunc(lookup->resolverAddr, lookup->askerAddr, msg); + this_ptr->failFunc(lookup->askerAddr, lookup->resolverAddr, msg); ub_resolve_free(result); return; } @@ -73,7 +73,7 @@ namespace llarp::dns buf.cur = buf.base; hdr.Encode(&buf); - this_ptr->replyFunc(lookup->resolverAddr, lookup->askerAddr, std::move(pkt)); + this_ptr->replyFunc(lookup->askerAddr, lookup->resolverAddr, std::move(pkt)); ub_resolve_free(result); } @@ -145,7 +145,7 @@ namespace llarp::dns if (not unboundContext) { msg.AddServFail(); - failFunc(to, from, std::move(msg)); + failFunc(from, to, std::move(msg)); return; } @@ -163,7 +163,7 @@ namespace llarp::dns if (err != 0) { msg.AddServFail(); - failFunc(to, from, std::move(msg)); + failFunc(from, to, std::move(msg)); return; } } diff --git a/llarp/dns/unbound_resolver.hpp b/llarp/dns/unbound_resolver.hpp index e1861ab88..8d6605304 100644 --- a/llarp/dns/unbound_resolver.hpp +++ b/llarp/dns/unbound_resolver.hpp @@ -18,9 +18,9 @@ namespace llarp::dns { using ReplyFunction = - std::function; + std::function; using FailFunction = - std::function; + std::function; class UnboundResolver : public std::enable_shared_from_this {