Skip to content

Commit 9af0e85

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

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

scapy/layers/dns.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ 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)._pack_subnet(x, pkt)
576576

577577
def i2len(self, pkt, x):
578578
# type: (Packet, Any) -> int
@@ -582,7 +582,7 @@ def i2len(self, pkt, x):
582582
return len(self._pack_subnet(x, pkt))
583583
except (OSError, socket.error):
584584
pkt.family = 2
585-
return len(ClientSubnetv6("", "")._pack_subnet(x, pkt))
585+
return len(ClientSubnetv6("", "", lambda p: p.source_plen or 32)._pack_subnet(x, pkt))
586586

587587

588588
class ClientSubnetv6(ClientSubnetv4):
@@ -604,13 +604,13 @@ class EDNS0ClientSubnet(_EDNS0Dummy):
604604
ByteField("scope_plen", 0),
605605
MultipleTypeField(
606606
[(ClientSubnetv4("address", "192.168.0.0",
607-
length_from=lambda p: p.source_plen),
607+
length_from=lambda p: p.source_plen or 16),
608608
lambda pkt: pkt.family == 1),
609609
(ClientSubnetv6("address", "2001:db8::",
610-
length_from=lambda p: p.source_plen),
610+
length_from=lambda p: p.source_plen or 32),
611611
lambda pkt: pkt.family == 2)],
612612
ClientSubnetv4("address", "192.168.0.0",
613-
length_from=lambda p: p.source_plen))]
613+
length_from=lambda p: p.source_plen or 32))]
614614

615615

616616
class EDNS0COOKIE(_EDNS0Dummy):

0 commit comments

Comments
 (0)