From 5946a21ca6682f5c5a99ef8d94b3f35c4001cee0 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Fri, 11 Sep 2026 03:23:24 +0000 Subject: [PATCH] pfroute: filter out routing messages with RTF_LLDATA those routing messages contain MAC addresses and end up without source candidates. Without this patch scapy fails with ``` >>> sr1(IPv6()/UDP(dport=5353)/DNS(qd=[DNSQR(qname='vbox.local',qtype='ALL')])) ... File ~/scapy/scapy/layers/inet6.py:341, in IPv6.route(self) 339 if isinstance(dst, (Gen, list)): 340 dst = next(iter(dst)) --> 341 return conf.route6.route(dst, dev=scope) File ~/scapy/scapy/route6.py:273, in Route6.route(self, dst, dev, verbose) 271 if in6_isincluded(dst, p, plen): 272 paths.append((plen, me, (iface, cset, gw))) --> 273 elif (in6_ismlladdr(dst) and in6_islladdr(p) and in6_islladdr(cset[0])): # noqa: E501 274 paths.append((plen, me, (iface, cset, gw))) 276 if not paths: IndexError: list index out of range ``` ``` >>> sr1(IPv6(dst='fe80::2%wm0')/ICMPv6EchoRequest()) Begin emission ERROR: --- Error sending packets Traceback (most recent call last): File "/root/scapy/scapy/sendrecv.py", line 280, in _sndrcv_snd self.hsent.setdefault(p.hashret(), []).append(p) ~~~~~~~~~^^ File "/root/scapy/scapy/layers/inet6.py", line 440, in hashret ss = inet_pton(socket.AF_INET6, ss) File "/root/scapy/scapy/pton_ntop.py", line 92, in inet_pton return socket.inet_pton(af, addr) ~~~~~~~~~~~~~~~~^^^^^^^^^^ OSError: illegal IP address string passed to inet_pton ``` AI-Assisted: no --- scapy/arch/bpf/pfroute.py | 4 ++++ test/regression.uts | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scapy/arch/bpf/pfroute.py b/scapy/arch/bpf/pfroute.py index 48ac739ff0c..6bbff0e7992 100644 --- a/scapy/arch/bpf/pfroute.py +++ b/scapy/arch/bpf/pfroute.py @@ -1042,6 +1042,8 @@ def read_routes(): if DARWIN and flags.RTF_WASCLONED and msg.rtm_parentflags.RTF_PRCLONING: # OSX needs filtering continue + if NETBSD and flags.RTF_LLDATA: + continue addrs = msg.rtm_addrs net = 0 mask = 0xFFFFFFFF @@ -1138,6 +1140,8 @@ def read_routes6(): if DARWIN and flags.RTF_WASCLONED and msg.rtm_parentflags.RTF_PRCLONING: # OSX needs filtering continue + if NETBSD and flags.RTF_LLDATA: + continue addrs = msg.rtm_addrs prefix = "::" plen = 128 diff --git a/test/regression.uts b/test/regression.uts index c1e673c4510..6cde4479336 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -3443,7 +3443,6 @@ assert routes == [ (2130706433, 4294967295, '0.0.0.0', 'lo0', '127.0.0.1', 1), (2887237632, 4294963200, '0.0.0.0', 'hvn0', '172.23.207.191', 1), (2887241663, 4294967295, '0.0.0.0', 'lo0', '172.23.207.191', 1), - (2887237633, 4294967295, '0.0.0.0', 'hvn0', '', 1), (3758096384, 4026531840, '0.0.0.0', 'hvn0', '172.23.207.191', 250), (3758096384, 4026531840, '0.0.0.0', 'lo0', '127.0.0.1', 250) ] @@ -3508,8 +3507,6 @@ assert routes == [ (167772687, 4294967295, '0.0.0.0', 'lo0', '10.0.2.15', 1), (2130706432, 4278190080, '127.0.0.1', 'lo0', '127.0.0.1', 1), (2130706433, 4294967295, '0.0.0.0', 'lo0', '127.0.0.1', 1), - (167772674, 4294967295, '0.0.0.0', 'wm0', '', 1), - (167772675, 4294967295, '0.0.0.0', 'wm0', '', 1), (3758096384, 4026531840, '0.0.0.0', 'wm0', '10.0.2.15', 250), (3758096384, 4026531840, '0.0.0.0', 'lo0', '127.0.0.1', 250) ] @@ -3563,8 +3560,6 @@ assert routes == [ ('ff01::', 32, '::1', 'lo0', ['::1'], 1), ('ff02::', 32, '::', 'wm0', ['fe80::a00:27ff:feed:60bb'], 1), ('ff02::', 32, '::1', 'lo0', ['::1'], 1), - ('fe80::2', 128, '::', 'wm0', [], 1), - ('fd17:625c:f037:2::3', 128, '::', 'wm0', [], 1), ('ff00::', 8, '::',