The DNSQuestion (dq) object

A DNSQuestion or dq object is available in several hooks and Lua actions. This object contains details about the current state of the question. This state can be modified from the various hooks.

The DNSQuestion object has several attributes, many of them read-only:

class DNSQuestion
DNSQuestion.dh

The DNSHeader (dh) object of this query.

DNSQuestion.ecsOverride

Whether an existing ECS value should be overridden, settable.

DNSQuestion.ecsPrefixLength

The ECS prefix length to use, settable.

DNSQuestion.len

The length of the qname.

DNSQuestion.localaddr

ComboAddress of the local bind this question was received on.

DNSQuestion.opcode

Integer describing the OPCODE of the packet. Can be matched against OPCode.

DNSQuestion.qclass

QClass (as an unsigned integer) of this question. Can be compared against QClass.

DNSQuestion.qname

DNSName of this question.

DNSQuestion.qtype

QType (as an unsigned integer) of this question. Can be compared against dnsdist.A, dnsdist.AAAA etc.

DNSQuestion.remoteaddr

ComboAddress of the remote client.

DNSQuestion.rcode

RCode (as an unsigned integer) of this question. Can be compared against RCode

DNSQuestion.size

The total size of the buffer starting at DNSQuestion.dh.

DNSQuestion.skipCache

Whether to skip cache lookup / storing the answer for this question, settable.

DNSQuestion.tcp

Whether the query have been received over TCP.

DNSQuestion.useECS

Whether to send ECS to the backend, settable.

It also supports the following methods:

classmethod DNSQuestion:getDO() → bool

New in version 1.2.0.

Get the value of the DNSSEC OK bit.

Returns:true if the DO bit was set, false otherwise
classmethod DNSQuestion:getTag(key) → string

New in version 1.2.0.

Get the value of a tag stored into the DNSQuestion object.

Parameters:key (string) – The tag’s key
Returns:A table of tags, using strings as keys and values
classmethod DNSQuestion:getTagArray() → table

New in version 1.2.0.

Get all the tags stored into the DNSQuestion object.

Returns:The tag’s value if it was set, an empty string otherwise
classmethod DNSQuestion:sendTrap(reason)

New in version 1.2.0.

Send an SNMP trap.

Parameters:reason (string) – An optional string describing the reason why this trap was sent
classmethod DNSQuestion:setTag(key, value)

New in version 1.2.0.

Set a tag into the DNSQuestion object.

Parameters:
  • key (string) – The tag’s key
  • value (string) – The tag’s value
classmethod DNSQuestion:setTagArray(tags)

New in version 1.2.0.

Set an array of tags into the DNSQuestion object.

Parameters:tags (table) – A table of tags, using strings as keys and values

DNSResponse object

class DNSResponse

This object has all the functions and members of a DNSQuestion and some more

classmethod DNSResponse:editTTLs(func)

The function func is invoked for every entry in the answer, authority and additional section.

func points to a function with the following prototype: myFunc(section, qclass, qtype, ttl)

All parameters to func are integers:

  • section is the section in the packet and can be compared to DNS Section
  • qclass is the QClass of the record. Can be compared to QClass
  • qtype is the QType of the record. Can be e.g. compared to dnsdist.A, dnsdist.AAAA and the like.
  • ttl is the current TTL

This function must return an integer with the new TTL. Setting this TTL to 0 to leaves it unchanged

Parameters:func (string) – The function to call to edit TTLs.

DNSHeader (dh) object

class DNSHeader

This object holds a representation of a DNS packet’s header.

classmethod DNSHeader:getRD() → bool

Get recursion desired flag.

classmethod DNSHeader:setRD(rd)

Set recursion desired flag.

Parameters:rd (bool) – State of the RD flag
classmethod DNSHeader:setTC(tc)

Set truncation flag (TC).

Parameters:tc (bool) – State of the TC flag
classmethod DNSHeader:setQR(qr)

Set Query/Response flag. Setting QR to true means “This is an answer packet”.

Parameters:qr (bool) – State of the QR flag
classmethod DNSHeader:getCD() → bool

Get checking disabled flag.

classmethod DNSHeader:setCD(cd)

Set checking disabled flag.

Parameters:cd (bool) – State of the CD flag