]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Apply suggestions from Charles-Henri (thanks!) 12022/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 6 Oct 2022 16:06:35 +0000 (18:06 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 10 Oct 2022 07:57:08 +0000 (09:57 +0200)
pdns/dnsdistdist/dnsdist-lua-bindings-dnsparser.cc
pdns/dnsdistdist/dnsdist-lua-ffi.cc
pdns/dnsdistdist/docs/reference/dnsparser.rst

index dc8f3c273d6e34ad9b5ed29132426b9bf8d02c4f..606220ef83386b70d6e74418e670713ac2cf19fc 100644 (file)
@@ -37,7 +37,7 @@ void setupLuaBindingsDNSParser(LuaContext& luaCtx)
   luaCtx.registerMember<dnsheader(dnsdist::DNSPacketOverlay::*)>(std::string("dh"), [](const dnsdist::DNSPacketOverlay& overlay) { return overlay.d_header; });
 
   luaCtx.registerFunction<uint16_t (dnsdist::DNSPacketOverlay::*)(uint8_t) const>("getRecordsCountInSection", [](const dnsdist::DNSPacketOverlay& overlay, uint8_t section) -> uint16_t {
-    if (section > 3) {
+    if (section > DNSResourceRecord::ADDITIONAL) {
       return 0;
     }
     uint16_t count = 0;
index 54606b081cc0430066b456d2f701053056d34715..9ff6a2d429cbfd2d4a84f465a526e31e42d32ce9 100644 (file)
@@ -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;
   }
 
index 41bb396618179a1035ba5c24674c4860406844c4..1b07bf672d8cd7d6b99aceea13453ba023100af7 100644 (file)
@@ -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.