Skip to content

Commit f8db4f5

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

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

scapy/layers/dns.py

Lines changed: 7 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,8 @@ 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(ClientSubnetv6("", "", lambda p: p.source_plen or 32). \
587+
_pack_subnet(x, pkt))
586588

587589

588590
class ClientSubnetv6(ClientSubnetv4):
@@ -604,13 +606,13 @@ class EDNS0ClientSubnet(_EDNS0Dummy):
604606
ByteField("scope_plen", 0),
605607
MultipleTypeField(
606608
[(ClientSubnetv4("address", "192.168.0.0",
607-
length_from=lambda p: p.source_plen),
609+
length_from=lambda p: p.source_plen or 16),
608610
lambda pkt: pkt.family == 1),
609611
(ClientSubnetv6("address", "2001:db8::",
610-
length_from=lambda p: p.source_plen),
612+
length_from=lambda p: p.source_plen or 32),
611613
lambda pkt: pkt.family == 2)],
612614
ClientSubnetv4("address", "192.168.0.0",
613-
length_from=lambda p: p.source_plen))]
615+
length_from=lambda p: p.source_plen or 32))]
614616

615617

616618
class EDNS0COOKIE(_EDNS0Dummy):

0 commit comments

Comments
 (0)