From: Remi Gacogne Date: Thu, 6 Oct 2022 16:06:35 +0000 (+0200) Subject: dnsdist: Apply suggestions from Charles-Henri (thanks!) X-Git-Tag: dnsdist-1.8.0-rc1~283^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F12022%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Apply suggestions from Charles-Henri (thanks!) --- diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-dnsparser.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-dnsparser.cc index dc8f3c273d..606220ef83 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-dnsparser.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-dnsparser.cc @@ -37,7 +37,7 @@ void setupLuaBindingsDNSParser(LuaContext& luaCtx) luaCtx.registerMember(std::string("dh"), [](const dnsdist::DNSPacketOverlay& overlay) { return overlay.d_header; }); luaCtx.registerFunction("getRecordsCountInSection", [](const dnsdist::DNSPacketOverlay& overlay, uint8_t section) -> uint16_t { - if (section > 3) { + if (section > DNSResourceRecord::ADDITIONAL) { return 0; } uint16_t count = 0; diff --git a/pdns/dnsdistdist/dnsdist-lua-ffi.cc b/pdns/dnsdistdist/dnsdist-lua-ffi.cc index 54606b081c..9ff6a2d429 100644 --- a/pdns/dnsdistdist/dnsdist-lua-ffi.cc +++ b/pdns/dnsdistdist/dnsdist-lua-ffi.cc @@ -1133,7 +1133,7 @@ struct dnsdist_ffi_dnspacket_t bool dnsdist_ffi_dnspacket_parse(const char* packet, size_t packetSize, dnsdist_ffi_dnspacket_t** out) { - if (out == nullptr || packetSize < sizeof(dnsheader)) { + if (packet == nullptr || out == nullptr || packetSize < sizeof(dnsheader)) { return false; } @@ -1179,7 +1179,7 @@ uint16_t dnsdist_ffi_dnspacket_get_qclass(const dnsdist_ffi_dnspacket_t* packet) uint16_t dnsdist_ffi_dnspacket_get_records_count_in_section(const dnsdist_ffi_dnspacket_t* packet, uint8_t section) { - if (packet == nullptr || section > 3) { + if (packet == nullptr || section > DNSResourceRecord::ADDITIONAL) { return 0; } diff --git a/pdns/dnsdistdist/docs/reference/dnsparser.rst b/pdns/dnsdistdist/docs/reference/dnsparser.rst index 41bb396618..1b07bf672d 100644 --- a/pdns/dnsdistdist/docs/reference/dnsparser.rst +++ b/pdns/dnsdistdist/docs/reference/dnsparser.rst @@ -16,7 +16,7 @@ and then to create a :class:`DNSPacketOverlay` object: print(overlay.qname) print(overlay.qtype) print(overlay.qclass) - local count = overlay:getRecordsCountInSection(1) + local count = overlay:getRecordsCountInSection(DNSSection.Answer) print(count) for idx=0, count-1 do local record = overlay:getRecord(idx) @@ -67,7 +67,7 @@ and then to create a :class:`DNSPacketOverlay` object: .. method:: DNSPacketOverlay:getRecordsCountInSection(section) -> int Returns the number of records in the ANSWER (1), AUTHORITY (2) and - ADDITIONAL (3) section of this packet. The number of records in the + ADDITIONAL (3) :ref:`DNSSection` of this packet. The number of records in the QUESTION (0) is always set to 0, look at the dnsheader if you need the actual qdcount.