From: dmachard <5562930+dmachard@users.noreply.github.com> Date: Mon, 18 Sep 2023 16:25:26 +0000 (+0200) Subject: dnsdist: add lua binding to downstream addr X-Git-Tag: rec-5.0.0-alpha2~56^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0cfda14990dd9dd9e231f319360bb32aa818ff33;p=thirdparty%2Fpdns.git dnsdist: add lua binding to downstream addr --- diff --git a/pdns/dnsdist-lua-bindings-dnsquestion.cc b/pdns/dnsdist-lua-bindings-dnsquestion.cc index f71a9bbf4d..7427f18f6d 100644 --- a/pdns/dnsdist-lua-bindings-dnsquestion.cc +++ b/pdns/dnsdist-lua-bindings-dnsquestion.cc @@ -500,5 +500,16 @@ private: auto query = dnsdist::getInternalQueryFromDQ(dr, false); return dnsdist::queueQueryResumptionEvent(std::move(query)); }); + + luaCtx.registerMember("selectedBackend", + []( const DNSResponse& dr) -> const ComboAddress { + if (dr.d_downstream == nullptr) { + return ComboAddress(); + } else { + return dr.d_downstream->d_config.remote; + } + }, + [](DNSResponse& dr, const ComboAddress newSelectedBackend) { (void) newSelectedBackend; } + ); #endif /* DISABLE_NON_FFI_DQ_BINDINGS */ } diff --git a/pdns/dnsdistdist/docs/reference/dq.rst b/pdns/dnsdistdist/docs/reference/dq.rst index ef9c531b3e..1d301588eb 100644 --- a/pdns/dnsdistdist/docs/reference/dq.rst +++ b/pdns/dnsdistdist/docs/reference/dq.rst @@ -403,7 +403,15 @@ DNSResponse object - ``useECS`` If the value is really needed while the response is being processed, it is possible to set a tag while the query is processed, as tags will be passed to the response object. - It also has one additional method: + The DNSResponse object has one additional attribute: + + .. attribute:: DNSResponse.selectedBackend + + .. versionadded:: 1.9.0 + + :ref:`ComboAddress` of the selected backend. + + It also has additional methods: .. method:: DNSResponse:editTTLs(func)