Skip to content

Commit 6a4f0db

Browse files
authored
*BSD fixes (#3810)
* FreeBSD - /dev/bpf cannot send packets to /dev/tun* and /dev/tap* * FreeBSD - unit test fixes * OpenBSD - unit test fixes * NetBSD - unit test fixes
1 parent c1e10af commit 6a4f0db

15 files changed

Lines changed: 84 additions & 30 deletions

File tree

.config/ci/openssl.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@
3838
"""
3939

4040
# Copy and edit
41-
with open(OPENSSL_CONFIG, 'rb') as fd:
42-
DATA = fd.read()
41+
try:
42+
with open(OPENSSL_CONFIG, 'rb') as fd:
43+
DATA = fd.read()
44+
except FileNotFoundError:
45+
DATA = b""
4346

4447
DATA = HEADER + DATA + FOOTER
4548

.config/ci/test.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,21 @@ then
3030
else
3131
UT_FLAGS+=" -K vcan_socket"
3232
fi
33-
elif [[ "$OSTYPE" = "darwin"* ]] || [ "$TRAVIS_OS_NAME" = "osx" ]
33+
elif [[ "$OSTYPE" = "darwin"* ]] || [ "$TRAVIS_OS_NAME" = "osx" ] || [[ "$OSTYPE" = "FreeBSD" ]] || [[ "$OSTYPE" = *"bsd"* ]]
3434
then
3535
OSTOX="bsd"
3636
# Travis CI in macOS 10.13+ can't load kexts. Need this for tuntaposx.
3737
UT_FLAGS+=" -K tun -K tap"
38+
if [[ "$OSTYPE" = "openbsd"* ]]
39+
then
40+
# Note: LibreSSL 3.6.* does not support X25519 according to
41+
# the cryptogaphy module source code
42+
UT_FLAGS+=" -K libressl"
43+
fi
44+
if [[ "$OSTYPE" = "netbsd" ]]
45+
then
46+
UT_FLAGS+=" -K not_netbsd"
47+
fi
3848
fi
3949

4050
# pypy
@@ -82,7 +92,7 @@ then
8292
fi
8393

8494
# Configure OpenSSL
85-
export OPENSSL_CONF=$(python `dirname $BASH_SOURCE`/openssl.py)
95+
export OPENSSL_CONF=$($PYTHON `dirname $BASH_SOURCE`/openssl.py)
8696

8797
# Dump vars (the others were already dumped in install.sh)
8898
echo UT_FLAGS=$UT_FLAGS

doc/vagrant_ci/Vagrantfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88

99
Vagrant.configure("2") do |config|
1010

11+
config.vm.provider "virtualbox" do |vb|
12+
vb.memory = 1024
13+
vb.cpus = 2
14+
end
15+
1116
config.vm.define "openbsd" do |bsd|
12-
bsd.vm.box = "generic/openbsd6"
17+
bsd.vm.box = "generic/openbsd7"
1318
bsd.vm.provision "shell", path: "provision_openbsd.sh"
1419
end
1520

1621
config.vm.define "freebsd" do |bsd|
17-
bsd.vm.box = "freebsd/FreeBSD-13.0-RELEASE"
22+
bsd.vm.box = "freebsd/FreeBSD-13.1-RELEASE"
1823
bsd.vm.provision "shell", path: "provision_freebsd.sh"
1924
end
2025

doc/vagrant_ci/provision_freebsd.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
# See https://scapy.net/ for more information
66
# Copyright (C) Philippe Biondi <phil@secdev.org>
77

8+
PACKAGES="git python2 python39 py39-virtualenv py39-pip py27-sqlite3 py39-sqlite3 bash rust sudo"
9+
810
pkg update
9-
pkg install --yes git python2 python3 py37-virtualenv py27-sqlite3 py37-sqlite3 bash rust
11+
pkg install --yes $PACKAGES
1012
bash
1113
git clone https://github.com/secdev/scapy
1214
cd scapy
1315
export PATH=/usr/local/bin/:$PATH
14-
virtualenv-3.7 -p python3.7 venv
16+
virtualenv-3.9 -p python3.9 venv
1517
source venv/bin/activate
1618
pip install tox
1719
chown -R vagrant:vagrant /home/vagrant/scapy

doc/vagrant_ci/provision_netbsd.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
# See https://scapy.net/ for more information
66
# Copyright (C) Philippe Biondi <phil@secdev.org>
77

8-
RELEASE="9.0_2020Q4"
8+
RELEASE="9.0_2022Q2"
9+
PACKAGES="git python27 python39 py39-virtualenv py27-sqlite3 py39-sqlite3 py39-expat rust mozilla-rootcerts-openssl"
910

1011
sudo -s
1112
unset PROMPT_COMMAND
1213
export PATH="/sbin:/usr/pkg/sbin:/usr/pkg/bin:$PATH"
1314
export PKG_PATH="http://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/${RELEASE}/All/"
1415
pkg_delete curl
15-
pkg_add git python27 python38 py38-virtualenv py27-sqlite3 py38-sqlite3 py38-expat rust mozilla-rootcerts-openssl
16+
pkg_add -u $PACKAGES
1617
git clone https://github.com/secdev/scapy
1718
cd scapy
18-
virtualenv-3.8 venv
19+
virtualenv-3.9 venv
1920
. venv/bin/activate
2021
pip install tox
2122
chown -R vagrant:vagrant ../scapy/

doc/vagrant_ci/provision_openbsd.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
# See https://scapy.net/ for more information
66
# Copyright (C) Philippe Biondi <phil@secdev.org>
77

8-
sudo pkg_add git python-2.7.18p0 python3 py-virtualenv
8+
PACKAGES="git python3 py3-virtualenv py3-cryptography"
9+
10+
sudo pkg_add $PACKAGES
911
sudo mkdir -p /usr/local/test/
1012
sudo chown -R vagrant:vagrant /usr/local/test/
1113
cd /usr/local/test/
1214
git clone https://github.com/secdev/scapy
1315
cd scapy
14-
virtualenv venv
16+
virtualenv --system-site-packages venv
1517
source venv/bin/activate
1618
pip install tox
1719
sudo chown -R vagrant:vagrant /usr/local/test/

scapy/arch/bpf/supersocket.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,15 @@ def send(self, pkt):
477477
# with Apple Silicon (M1).
478478
if DARWIN and iff.startswith('tun') and self.guessed_cls == Loopback:
479479
frame = raw(pkt)
480+
elif FREEBSD and (iff.startswith('tun') or iff.startswith('tap')):
481+
# On FreeBSD, the bpf manpage states that it is only possible
482+
# to write packets to Ethernet and SLIP network interfaces
483+
# using /dev/bpf
484+
#
485+
# Note: `open("/dev/tun0", "wb").write(raw(pkt())) should be
486+
# used
487+
warning("Cannot write to %s according to the documentation!", iff)
488+
return
480489
else:
481490
frame = raw(self.guessed_cls() / pkt)
482491

scapy/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
from scapy.config import conf
3737
from scapy.consts import DARWIN, OPENBSD, WINDOWS
38-
from scapy.data import MTU, DLT_EN10MB
38+
from scapy.data import MTU, DLT_EN10MB, DLT_RAW
3939
from scapy.compat import orb, plain_str, chb, bytes_base64,\
4040
base64_bytes, hex_bytes, lambda_tuple_converter, bytes_encode
4141
from scapy.error import log_runtime, Scapy_Exception, warning
@@ -2718,6 +2718,8 @@ def tcpdump(
27182718
try:
27192719
_, metadata = rd._read_packet()
27202720
linktype = metadata.linktype
2721+
if OPENBSD and linktype == 228:
2722+
linktype = DLT_RAW
27212723
except EOFError:
27222724
raise ValueError(
27232725
"Cannot get linktype from a PcapNg packet."

test/bpf.uts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ s.assigned_interface = conf.loopback_name
147147
s.send(IP(dst="8.8.8.8")/ICMP())
148148

149149
= L3bpfSocket - send and sniff on loopback
150-
~ needs_root
150+
~ needs_root not_netbsd
151+
152+
# Note: as of November 2022, it is not possible to send packet on lo0
153+
# using bpf on NetBSD 9.3
151154

152155
localhost_ip = conf.ifaces[conf.loopback_name].ips[4][0]
153156

test/configs/bsd.utsc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"test/windows.uts",
1616
"test/contrib/automotive/ecu_am.uts",
1717
"test/contrib/automotive/gm/gmlanutils.uts",
18+
"test/contrib/isotp_packet.uts",
1819
"test/contrib/isotpscan.uts"
1920
],
2021
"onlyfailed": true,
@@ -28,6 +29,8 @@
2829
"linux",
2930
"windows",
3031
"ipv6",
31-
"vcan_socket"
32+
"vcan_socket",
33+
"tun",
34+
"tap"
3235
]
3336
}

0 commit comments

Comments
 (0)