Skip to content

Commit

Permalink
Auto clear DNS cache on set
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed Feb 13, 2024
1 parent bb36cec commit d612454
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scapy/layers/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ class DNSStrField(StrLenField):
"""

def h2i(self, pkt, x):
# Setting a DNSStrField manually (h2i) means any current compression will break
if (
pkt and
isinstance(pkt.parent, DNSCompressedPacket) and
pkt.parent.raw_packet_cache
):
pkt.parent.clear_cache()
if not x:
return b"."
x = bytes_encode(x)
Expand Down
9 changes: 9 additions & 0 deletions test/scapy/layers/dns.uts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ recompressed.an[3].rdlen = None

assert raw(recompressed) == raw(pkt)

= DNS cache clearance on sub change
~ dns

# GH4216
p = DNS(b'\x00\x00\x01\x00\x00\x00\x00\x02\x00\x00\x00\x00\x03H-1\x05local\x00\x00\x05\x00\x01\x00\x00\x00\x00\x00\x06\x03H-2\xc0\x10\xc0!\x00\x05\x00\x01\x00\x00\x00\x00\x00\x02\xc0\x0c')
p[DNS].an[0].rrname = 'H'
assert p.raw_packet_cache is None
assert bytes(p) == b'\x00\x00\x01\x00\x00\x00\x00\x02\x00\x00\x00\x00\x01H\x00\x00\x05\x00\x01\x00\x00\x00\x00\x00\x0b\x03H-2\x05local\x00\x03H-2\x05local\x00\x00\x05\x00\x01\x00\x00\x00\x00\x00\x0b\x03H-1\x05local\x00'

= DNS frames with MX records
~ dns

Expand Down

0 comments on commit d612454

Please sign in to comment.