pydnstest: ADJUST raw_id option

parent deb32d6f
Pipeline #37094 passed with stage
in 1 minute and 26 seconds
......@@ -256,6 +256,7 @@ element modification to the DNS message
========== ===========================================================================================
copy_id query id + query domain name will be copied from incoming message [copy_id_bug]_
copy_query whole question section will be copied from incoming message
raw_id query id will be copied into the first two bytes of RAW answer
========== ===========================================================================================
.. [copy_id_bug] https://gitlab.labs.nic.cz/knot/deckard/issues/9
......@@ -331,7 +332,7 @@ able to process valid queries after getting series badly formed packets.
It is also possible to use ``RAW`` in conjuction with ``SECTION`` for the
purpose of responding with raw data to a query that matches the ``SECTION``.
Raw data is sent as is and isn't manipulated in any way (e.g. by ``ADJUST``).
It's possible to modify raw data to use query's ID by using ``ADJUST raw_id``.
One ``ENTRY`` can contain only one ``RAW`` section.
......
......@@ -33,7 +33,7 @@ let hex_re = /[0-9a-fA-F]+/
let match_option = "opcode" | "qtype" | "qcase" | "qname" | "subdomain" | "flags" | "rcode" | "question" | "answer" | "authority" | "additional" | "all" | "TCP" | "ttl"
let adjust_option = "copy_id" | "copy_query"
let adjust_option = "copy_id" | "copy_query" | "raw_id"
let reply_option = "QR" | "TC" | "AA" | "AD" | "RD" | "RA" | "CD" | "DO" | "NOERROR" | "FORMERR" | "SERVFAIL" | "NXDOMAIN" | "NOTIMP" | "REFUSED" | "YXDOMAIN" | "YXRRSET" | "NXRRSET" | "NOTAUTH" | "NOTZONE" | "BADVERS" | "BADSIG" | "BADKEY" | "BADTIME" | "BADMODE" | "BADNAME" | "BADALG" | "BADTRUNC" | "BADCOOKIE"
let step_option = "REPLY" | "QUERY" | "CHECK_ANSWER" | "CHECK_OUT_QUERY" | /TIME_PASSES[ \t]+ELAPSE/
......
......@@ -366,9 +366,17 @@ class Entry:
assert len(answer.additional) == len(self.message.additional)
return answer
def _adjust_raw_reply(self, query):
if 'raw_id' in self.adjust_fields:
assert len(self.raw_data) >= 2, "RAW message has to contain at least 2 bytes"
raw_answer = bytearray(self.raw_data)
struct.pack_into('!H', raw_answer, 0, query.id)
return bytes(raw_answer)
return self.raw_data
def reply(self, query):
if self.is_raw_data_entry:
return self.raw_data, True
return self._adjust_raw_reply(query), True
return self._adjust_reply(query), False
def set_edns(self, fields):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment