pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/net/scapy scapy: add a patch to fix lo and utun use on...
details: https://anonhg.NetBSD.org/pkgsrc/rev/08f68f27ec1f
branches: trunk
changeset: 457124:08f68f27ec1f
user: gutteridge <gutteridge%pkgsrc.org@localhost>
date: Wed Aug 18 01:44:21 2021 +0000
description:
scapy: add a patch to fix lo and utun use on Darwin and FreeBSD
Tested on NetBSD to see if it made a useful difference for an example
in PR pkg/55446; it does not, but it was more revealing than before.
Adding in case it's of use for pkgsrc users on those other OSes. (I've
also added the corresponding test case, in case someone else is curious
about how this is applied.)
diffstat:
net/scapy/Makefile | 3 +-
net/scapy/distinfo | 5 +-
net/scapy/patches/patch-scapy_arch_bpf_supersocket.py | 46 ++++++++++++++++++-
net/scapy/patches/patch-test_bpf.uts | 31 ++++++++++++
4 files changed, 81 insertions(+), 4 deletions(-)
diffs (126 lines):
diff -r e226d0e7b55c -r 08f68f27ec1f net/scapy/Makefile
--- a/net/scapy/Makefile Tue Aug 17 17:45:53 2021 +0000
+++ b/net/scapy/Makefile Wed Aug 18 01:44:21 2021 +0000
@@ -1,6 +1,7 @@
-# $NetBSD: Makefile,v 1.35 2021/04/27 21:53:11 gutteridge Exp $
+# $NetBSD: Makefile,v 1.36 2021/08/18 01:44:21 gutteridge Exp $
DISTNAME= scapy-2.4.5
+PKGREVISION= 1
CATEGORIES= net
MASTER_SITES= ${MASTER_SITE_GITHUB:=secdev/}
GITHUB_TAG= v${PKGVERSION_NOREV}
diff -r e226d0e7b55c -r 08f68f27ec1f net/scapy/distinfo
--- a/net/scapy/distinfo Tue Aug 17 17:45:53 2021 +0000
+++ b/net/scapy/distinfo Wed Aug 18 01:44:21 2021 +0000
@@ -1,4 +1,4 @@
-$NetBSD: distinfo,v 1.15 2021/05/02 19:28:15 gutteridge Exp $
+$NetBSD: distinfo,v 1.16 2021/08/18 01:44:21 gutteridge Exp $
SHA1 (scapy-2.4.5.tar.gz) = 28f3a240cbbb3b6df45e239be8fbf5fb138591f6
RMD160 (scapy-2.4.5.tar.gz) = d0b23b55251802fab1f78e8e2f5170fc595d1a8e
@@ -6,6 +6,7 @@
Size (scapy-2.4.5.tar.gz) = 3323309 bytes
SHA1 (patch-ab) = a0ef3c66ed5578e53d76ee38f6931be9c293baa5
SHA1 (patch-ad) = bac7c72eff08608d4d73911a94bfc3125b8b53b6
-SHA1 (patch-scapy_arch_bpf_supersocket.py) = 4c11a8e9cd8212314cc3d881d906d83c893f1755
+SHA1 (patch-scapy_arch_bpf_supersocket.py) = 910c893fa3a90daffa14d8c963b65186fca313f8
SHA1 (patch-scapy_consts.py) = c897229e444d363e2aeea12cdd7264d3d275f4ab
+SHA1 (patch-test_bpf.uts) = 628c8da78c16ab5628eb2b9a5d10229c5de197f8
SHA1 (patch-test_run__tests) = cf152ca5a81652ff9fbfebf79d7f318e8d79e18e
diff -r e226d0e7b55c -r 08f68f27ec1f net/scapy/patches/patch-scapy_arch_bpf_supersocket.py
--- a/net/scapy/patches/patch-scapy_arch_bpf_supersocket.py Tue Aug 17 17:45:53 2021 +0000
+++ b/net/scapy/patches/patch-scapy_arch_bpf_supersocket.py Wed Aug 18 01:44:21 2021 +0000
@@ -1,8 +1,12 @@
-$NetBSD: patch-scapy_arch_bpf_supersocket.py,v 1.4 2021/04/27 21:53:11 gutteridge Exp $
+$NetBSD: patch-scapy_arch_bpf_supersocket.py,v 1.5 2021/08/18 01:44:21 gutteridge Exp $
Add DragonFly support.
+
Fix NetBSD 32-bit architecture alignment.
+Fix send() on loopback and utun devices for Darwin and FreeBSD.
+https://github.com/secdev/scapy/pull/3257
+
--- scapy/arch/bpf/supersocket.py.orig 2021-04-18 18:36:15.000000000 +0000
+++ scapy/arch/bpf/supersocket.py
@@ -18,7 +18,7 @@ from scapy.arch.bpf.consts import BIOCGB
@@ -37,3 +41,43 @@
bh_tstamp_offset = 16
else:
# struct bpf_hdr
+@@ -390,14 +393,31 @@ class L3bpfSocket(L2bpfSocket):
+ self.assigned_interface = iff
+
+ # Build the frame
+- if self.guessed_cls == Loopback:
+- # bpf(4) man page (from macOS, but also for BSD):
+- # "A packet can be sent out on the network by writing to a bpf
+- # file descriptor. [...] Currently only writes to Ethernets and
+- # SLIP links are supported"
+- #
+- # Headers are only mentioned for reads, not writes. tuntaposx's tun
+- # device reports as a "loopback" device, but it does IP.
++ #
++ # LINKTYPE_NULL / DLT_NULL (Loopback) is a special case. From the
++ # bpf(4) man page (from macOS/Darwin, but also for BSD):
++ #
++ # "A packet can be sent out on the network by writing to a bpf file
++ # descriptor. [...] Currently only writes to Ethernets and SLIP links
++ # are supported."
++ #
++ # Headers are only mentioned for reads, not writes, and it has the
++ # name "NULL" and id=0.
++ #
++ # The _correct_ behaviour appears to be that one should add a BSD
++ # Loopback header to every sent packet. This is needed by FreeBSD's
++ # if_lo, and Darwin's if_lo & if_utun.
++ #
++ # tuntaposx appears to have interpreted "NULL" as "no headers".
++ # Thankfully its interfaces have a different name (tunX) to Darwin's
++ # if_utun interfaces (utunX).
++ #
++ # There might be other drivers which make the same mistake as
++ # tuntaposx, but these are typically provided with VPN software, and
++ # Apple are breaking these kexts in a future version of macOS... so
++ # the problem will eventually go away. They already don't work on Macs
++ # with Apple Silicon (M1).
++ if DARWIN and iff.startswith('tun') and self.guessed_cls == Loopback:
+ frame = raw(pkt)
+ else:
+ frame = raw(self.guessed_cls() / pkt)
diff -r e226d0e7b55c -r 08f68f27ec1f net/scapy/patches/patch-test_bpf.uts
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/net/scapy/patches/patch-test_bpf.uts Wed Aug 18 01:44:21 2021 +0000
@@ -0,0 +1,31 @@
+$NetBSD: patch-test_bpf.uts,v 1.1 2021/08/18 01:44:21 gutteridge Exp $
+
+Fix send() on loopback and utun devices for Darwin and FreeBSD.
+https://github.com/secdev/scapy/pull/3257
+
+--- test/bpf.uts.orig 2021-04-18 18:36:15.000000000 +0000
++++ test/bpf.uts
+@@ -145,3 +145,23 @@ s.send(IP(dst="8.8.8.8")/ICMP())
+ s = L3bpfSocket()
+ s.assigned_interface = conf.loopback_name
+ s.send(IP(dst="8.8.8.8")/ICMP())
++
++= L3bpfSocket - send and sniff on loopback
++~ needs_root
++
++localhost_ip = conf.ifaces[conf.loopback_name].ips[4][0]
++
++def cb():
++ # Send a ping to the loopback IP.
++ s = L3bpfSocket(iface=conf.loopback_name)
++ s.send(IP(dst=localhost_ip)/ICMP(seq=1001))
++
++t = AsyncSniffer(iface=conf.loopback_name, started_callback=cb)
++t.start()
++time.sleep(1)
++t.stop()
++t.join(timeout=1)
++
++# We expect to see our packet and kernel's response.
++len(t.results.filter(lambda p: (
++ IP in p and ICMP in p and (p[IP].src == localhost_ip or p[IP].dst == localhost_ip) and p[ICMP].seq == 1001))) == 2
Home |
Main Index |
Thread Index |
Old Index