Skip to content

Commit 923b03d

Browse files
committed
fix(dns): default source_plen to /24 for IPv4 and /48 for IPv6 when None in EDNS0ClientSubnet
1 parent 72d7f9d commit 923b03d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

scapy/layers/dns.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,8 @@ def i2m(self, pkt, x):
572572
return self._pack_subnet(x, pkt)
573573
except (OSError, socket.error):
574574
pkt.family = 2
575-
return ClientSubnetv6("", "")._pack_subnet(x, pkt)
575+
return ClientSubnetv6("", "", lambda p: p.source_plen or 32). \
576+
_pack_subnet(x, pkt)
576577

577578
def i2len(self, pkt, x):
578579
# type: (Packet, Any) -> int
@@ -582,7 +583,10 @@ def i2len(self, pkt, x):
582583
return len(self._pack_subnet(x, pkt))
583584
except (OSError, socket.error):
584585
pkt.family = 2
585-
return len(ClientSubnetv6("", "")._pack_subnet(x, pkt))
586+
return len(
587+
ClientSubnetv6(
588+
"", "", lambda p: p.source_plen or 32
589+
)._pack_subnet(x, pkt))
586590

587591

588592
class ClientSubnetv6(ClientSubnetv4):
@@ -604,13 +608,13 @@ class EDNS0ClientSubnet(_EDNS0Dummy):
604608
ByteField("scope_plen", 0),
605609
MultipleTypeField(
606610
[(ClientSubnetv4("address", "192.168.0.0",
607-
length_from=lambda p: p.source_plen),
611+
length_from=lambda p: p.source_plen or 16),
608612
lambda pkt: pkt.family == 1),
609613
(ClientSubnetv6("address", "2001:db8::",
610-
length_from=lambda p: p.source_plen),
614+
length_from=lambda p: p.source_plen or 32),
611615
lambda pkt: pkt.family == 2)],
612616
ClientSubnetv4("address", "192.168.0.0",
613-
length_from=lambda p: p.source_plen))]
617+
length_from=lambda p: p.source_plen or 32))]
614618

615619

616620
class EDNS0COOKIE(_EDNS0Dummy):

0 commit comments

Comments
 (0)