Skip to content

Commit 636c2bd

Browse files
committed
dns: add EDNS0 Padding option
https://datatracker.ietf.org/doc/html/rfc7830 specifies the EDNS(0) "Padding" option, which allows DNS clients and servers to pad request and response messages by a variable number of octets. It was cross-checked with TShark ``` >>> tdecode(Ether()/IP()/UDP()/DNS(ar=[DNSRROPT(rdata=[EDNS0PADDING(padding=b'\x00')])])) ... Option: PADDING Option Code: PADDING (12) Option Length: 1 Option Data: 00 Padding: 00 ```
1 parent f4a2ca4 commit 636c2bd

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

scapy/layers/dns.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def i2m(self, pkt, s):
439439

440440
edns0types = {0: "Reserved", 1: "LLQ", 2: "UL", 3: "NSID", 4: "Owner",
441441
5: "DAU", 6: "DHU", 7: "N3U", 8: "edns-client-subnet", 10: "COOKIE",
442-
15: "Extended DNS Error"}
442+
12: "Padding", 15: "Extended DNS Error"}
443443

444444

445445
class _EDNS0Dummy(Packet):
@@ -626,6 +626,16 @@ class EDNS0COOKIE(_EDNS0Dummy):
626626
length_from=lambda pkt: max(0, pkt.optlen - 8))]
627627

628628

629+
# RFC 7830 - EDNS0 Padding Option
630+
631+
class EDNS0PADDING(_EDNS0Dummy):
632+
name = "DNS EDNS0 Padding"
633+
fields_desc = [ShortEnumField("optcode", 12, edns0types),
634+
FieldLenField("optlen", None, length_of="padding", fmt="!H"),
635+
StrLenField("padding", "",
636+
length_from=lambda pkt: pkt.optlen)]
637+
638+
629639
# RFC 8914 - Extended DNS Errors
630640

631641
# https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#extended-dns-error-codes
@@ -681,6 +691,7 @@ class EDNS0ExtendedDNSError(_EDNS0Dummy):
681691
7: EDNS0N3U,
682692
8: EDNS0ClientSubnet,
683693
10: EDNS0COOKIE,
694+
12: EDNS0PADDING,
684695
15: EDNS0ExtendedDNSError,
685696
}
686697

test/scapy/layers/dns_edns0.uts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,31 @@ assert p.client_cookie == b'\x01' * 8
182182
assert p.server_cookie == b'\x02' * 16
183183

184184

185+
+ EDNS0 - Padding
186+
187+
= Basic instantiation & dissection
188+
189+
b = b'\x00\x0c\x00\x00'
190+
191+
p = EDNS0PADDING()
192+
assert raw(p) == b
193+
194+
p = EDNS0PADDING(b)
195+
assert p.optcode == 12
196+
assert p.optlen == 0
197+
assert p.padding == b''
198+
199+
b = b'\x00\x0c\x00\x03\x00\x01\x02'
200+
201+
p = EDNS0PADDING(padding=b'\x00\x01\x02')
202+
assert raw(p) == b
203+
204+
p = EDNS0PADDING(b)
205+
assert p.optcode == 12
206+
assert p.optlen == 3
207+
assert p.padding == b'\x00\x01\x02'
208+
209+
185210
+ EDNS0 - Extended DNS Error
186211

187212
= Basic instantiation & dissection

0 commit comments

Comments
 (0)