Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnsdist: Add Lua helpers to look into the content of DNS payloads #12022

Merged
merged 6 commits into from
Oct 10, 2022

Conversation

rgacogne
Copy link
Member

Short description

This PR provides regular and FFI bindings allowing to look at the DNS records contained in a DNS payload. There is no parsing of the rdata (content) of the DNS records, though, and at this point this is not something we want to add.

Checklist

I have:

  • read the CONTRIBUTING.md document
  • compiled this code
  • tested this code
  • included documentation (including possible behaviour changes)
  • documented the code
  • added or modified regression test(s)
  • added or modified unit test(s)

print(overlay.qname)
print(overlay.qtype)
print(overlay.qclass)
local count = overlay:getRecordsCountInSection(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local count = overlay:getRecordsCountInSection(1)
local count = overlay:getRecordsCountInSection(DNSSection.Answer)

.. 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (section > 3) {
if (section > DNSResourceRecord::ADDITIONAL) {

If it doesn't need an extra include ?


uint16_t dnsdist_ffi_dnspacket_get_records_count_in_section(const dnsdist_ffi_dnspacket_t* packet, uint8_t section)
{
if (packet == nullptr || section > 3) {
Copy link
Member

@chbruyand chbruyand Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (packet == nullptr || section > 3) {
if (packet == nullptr || section > DNSResourceRecord::ADDITIONAL) {


bool dnsdist_ffi_dnspacket_parse(const char* packet, size_t packetSize, dnsdist_ffi_dnspacket_t** out)
{
if (out == nullptr || packetSize < sizeof(dnsheader)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (out == nullptr || packetSize < sizeof(dnsheader)) {
if (packet == nullptr || out == nullptr || packetSize < sizeof(dnsheader)) {

Copy link
Member

@chbruyand chbruyand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nits, but LGTM otherwise !

@chbruyand chbruyand self-requested a review October 10, 2022 07:06
@rgacogne rgacogne force-pushed the ddist-dnsparser-helpers branch from 8beac1d to 3230f6c Compare October 10, 2022 07:57
@rgacogne rgacogne merged commit 720ce3d into PowerDNS:master Oct 10, 2022
@rgacogne rgacogne deleted the ddist-dnsparser-helpers branch October 10, 2022 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants