Page MenuHomeFreeBSD

D60109.1796349259.diff
No OneTemporary

Authored By
Unknown
Size
9 KB
Referenced Files
None
Subscribers
None

D60109.1796349259.diff

diff --git a/sys/net/if_ovpn.c b/sys/net/if_ovpn.c
--- a/sys/net/if_ovpn.c
+++ b/sys/net/if_ovpn.c
@@ -1758,8 +1758,9 @@
OVPN_PEER_COUNTER_ADD(peer, pkt_in, 1);
OVPN_PEER_COUNTER_ADD(peer, bytes_in, m->m_pkthdr.len);
- /* Receive the packet on our interface. */
+ /* Receive the packet on our interface and FIB. */
m->m_pkthdr.rcvif = sc->ifp;
+ M_SETFIB(m, sc->ifp->if_fib);
/* Clear checksum flags in case the real hardware set them. */
m->m_pkthdr.csum_flags = 0;
diff --git a/tests/sys/common/Makefile b/tests/sys/common/Makefile
--- a/tests/sys/common/Makefile
+++ b/tests/sys/common/Makefile
@@ -1,5 +1,6 @@
PACKAGE= tests
TESTSDIR= ${TESTSBASE}/sys/common
+${PACKAGE}FILES+= fibs.subr
${PACKAGE}FILES+= vnet.subr
${PACKAGE}FILES+= divert.py
${PACKAGE}FILES+= sender.py
diff --git a/tests/sys/common/fibs.subr b/tests/sys/common/fibs.subr
new file mode 100644
--- /dev/null
+++ b/tests/sys/common/fibs.subr
@@ -0,0 +1,63 @@
+#
+# Copyright (c) 2014 Spectra Logic Corporation
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions, and the following disclaimer,
+# without modification.
+# 2. Redistributions in binary form must reproduce at minimum a disclaimer
+# substantially similar to the "NO WARRANTY" disclaimer below
+# ("Disclaimer") and any redistribution must be conditioned upon
+# including a substantially similar Disclaimer requirement for further
+# binary redistribution.
+#
+# NO WARRANTY
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGES.
+#
+# Authors: Alan Somers (Spectra Logic Corporation)
+#
+# From: e93e57d3da2e tests/sys/netinet/fibs_test.sh
+#
+
+# Asserts that net.add_addr_allfibs is set to the expected value.
+
+# parameter value The expected value of net.add_addr_allfibs
+fibs_assert_allfibs()
+{
+ VAL=$1
+ if [ ${VAL} != `sysctl -n net.add_addr_allfibs` ]; then
+ atf_skip "This test requires net.add_addr_allfibs=${VAL}"
+ fi
+}
+
+# Looks up one or more fibs from the configuration data and validates them.
+# Returns the results in the env varilables FIB0, FIB1, etc.
+
+# parameter numfibs The number of fibs to lookup
+fibs_get()
+{
+ NUMFIBS=$1
+ net_fibs=`sysctl -n net.fibs`
+ if [ $net_fibs -lt $(($NUMFIBS + 1)) ]; then
+ atf_check -o ignore sysctl net.fibs=$(($NUMFIBS + 1))
+ net_fibs=`sysctl -n net.fibs`
+ fi
+ i=0
+ while [ $i -lt "$NUMFIBS" ]; do
+ eval FIB${i}=$(($i + 1))
+ i=$(( $i + 1 ))
+ done
+}
diff --git a/tests/sys/net/if_ovpn/Makefile b/tests/sys/net/if_ovpn/Makefile
--- a/tests/sys/net/if_ovpn/Makefile
+++ b/tests/sys/net/if_ovpn/Makefile
@@ -3,6 +3,7 @@
PACKAGE= tests
TESTSDIR= ${TESTSBASE}/sys/net/if_ovpn
+BINDIR= ${TESTSDIR}
.if ${MK_PF} != "no"
ATF_TESTS_SH+= if_ovpn
@@ -10,9 +11,12 @@
TEST_METADATA.if_ovpn+= execenv_jail_params="vnet allow.raw_sockets"
.endif
ATF_TESTS_C+= if_ovpn_c
+ATF_TESTS_SH+= if_ovpn_fib
LIBADD+= nv
+SCRIPTS+= fib-updown
+
TESTS_SUBDIRS+= ccd
${PACKAGE}FILES+= \
diff --git a/tests/sys/net/if_ovpn/fib-updown b/tests/sys/net/if_ovpn/fib-updown
new file mode 100644
--- /dev/null
+++ b/tests/sys/net/if_ovpn/fib-updown
@@ -0,0 +1,42 @@
+#!/bin/sh
+# OpenVPN up/down script issuing ifconfig(8) with the FIB set via net.my_fibnum
+# Copyright (c) 2026 Marius Strobl <marius@FreeBSD.org>
+# SPDX-License-Identifier: BSD-2-Clause
+
+execfib() {
+ if [ "$#" -ne 1 ] || [ -z "$1" ]; then
+ return 1
+ fi
+ local cmd=$1
+ if [ `/sbin/sysctl -n net.fibs` ]; then
+ cmd="${cmd} fib `/sbin/sysctl -n net.my_fibnum`"
+ fi
+ eval "$cmd"
+}
+
+cmd="/sbin/ifconfig ${dev}"
+case "${script_type}" in
+up)
+ if [ -n "${ifconfig_local}" ]; then
+ addr=${ifconfig_local}
+ if [ -n "${ifconfig_remote}" ]; then
+ addr="${addr} ${ifconfig_remote} netmask 0xffffffff"
+ else
+ addr="${addr} netmask ${ifconfig_netmask}"
+ fi
+ execfib "${cmd} ${addr} mtu ${tun_mtu} up"
+ fi
+ if [ -n "${ifconfig_ipv6_local}" ]; then
+ addr="${ifconfig_ipv6_local}/${ifconfig_ipv6_netbits}"
+ execfib "${cmd} inet6 ${addr} mtu ${tun_mtu} up"
+ fi
+ ;;
+down)
+ if [ -n "${ifconfig_local}" ]; then
+ execfib "${cmd} ${ifconfig_local} -alias"
+ fi
+ if [ -n "${ifconfig_ipv6_local}" ]; then
+ execfib "${cmd} inet6 ${ifconfig_ipv6_local} -alias"
+ fi
+ ;;
+esac
diff --git a/tests/sys/net/if_ovpn/if_ovpn_fib.sh b/tests/sys/net/if_ovpn/if_ovpn_fib.sh
new file mode 100644
--- /dev/null
+++ b/tests/sys/net/if_ovpn/if_ovpn_fib.sh
@@ -0,0 +1,170 @@
+##
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2022 Rubicon Communications, LLC ("Netgate")
+# Copyright (c) 2026 Marius Strobl <marius@FreeBSD.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# From: 77f453e9f9ca tests/sys/net/if_ovpn/if_ovpn.sh
+# From: 512d3c3a2c63 tests/sys/net/if_ovpn/utils.subr
+
+. $(atf_get_srcdir)/utils.subr
+. $(atf_get_srcdir)/../../common/fibs.subr
+
+fib_start()
+{
+ fib=$1
+ cfg=$2
+
+ echo ${fib} >> ovpn_fibs.lst
+
+ echo "Start" >> ovpn_${fib}.log
+ echo "=====" >> ovpn_${fib}.log
+
+ echo "$cfg" > ovpn_${fib}.ovpn
+
+ echo "FIB $fib:"
+ echo "==========="
+ cat ovpn_${fib}.ovpn
+
+ #
+ # N. B.: OpenVPN won't destroy the tunnel interface during a
+ # graceful exit unless run as daemon or in foreground.
+ #
+ setfib $fib \
+ openvpn --config ovpn_${fib}.ovpn --daemon --log ovpn_${fib}.log \
+ --writepid ovpn_${fib}.pid
+}
+
+fib_shutdown()
+{
+ for fib in `cat ovpn_fibs.lst | sort -u`
+ do
+ kill -TERM `cat ovpn_${fib}.pid`
+ done
+}
+
+fib_cleanup()
+{
+ for fib in `cat ovpn_fibs.lst | sort -u`
+ do
+ cat ovpn_${fib}.log| sed s/^/\[${fib}\]\ /
+ done
+
+ vnet_cleanup
+}
+
+atf_test_case "fibtun" "cleanup"
+fibtun_head()
+{
+ atf_set descr 'Test non-default FIB on tunnel interface'
+ atf_set require.user root
+ atf_set require.progs openvpn
+}
+
+fibtun_body()
+{
+ ovpn_init
+
+ #
+ # N. B.: Executing this test jailed may hide the problem.
+ #
+ fibs_assert_allfibs 0
+ fibs_get 2
+ l=$(vnet_mkepair)
+ ifconfig ${l}a 192.0.2.1/24 fib ${FIB0} up
+ ifconfig ${l}b 192.0.2.2/24 fib ${FIB1} up
+
+ # Sanity check
+ atf_check -s exit:0 -o ignore setfib ${FIB0} ping -c 1 192.0.2.2
+
+ fib_start ${FIB0} "
+ dev ovpn0
+ dev-type tun
+ proto udp
+
+ cipher AES-256-GCM
+ auth SHA256
+
+ local 192.0.2.1
+ server 198.51.100.0 255.255.255.0
+
+ ca $(atf_get_srcdir)/ca.crt
+ cert $(atf_get_srcdir)/server.crt
+ key $(atf_get_srcdir)/server.key
+ dh $(atf_get_srcdir)/dh.pem
+
+ mode server
+ script-security 2
+ auth-user-pass-verify /usr/bin/true via-env
+ topology subnet
+
+ down-pre
+ ifconfig-noexec
+ up $(atf_get_srcdir)/fib-updown
+ down $(atf_get_srcdir)/fib-updown
+
+ keepalive 100 600
+ "
+ fib_start ${FIB1} "
+ dev tun0
+ dev-type tun
+
+ client
+
+ remote 192.0.2.1
+ auth-user-pass $(atf_get_srcdir)/user.pass
+
+ ca $(atf_get_srcdir)/ca.crt
+ cert $(atf_get_srcdir)/client.crt
+ key $(atf_get_srcdir)/client.key
+ dh $(atf_get_srcdir)/dh.pem
+
+ down-pre
+ ifconfig-noexec
+ script-security 2
+ up $(atf_get_srcdir)/fib-updown
+ down $(atf_get_srcdir)/fib-updown
+
+ keepalive 100 600
+ "
+
+ # Give the tunnel time to come up
+ sleep 10
+
+ setfib ${FIB1} ping -c 3 198.51.100.1
+ res=$?
+
+ fib_shutdown
+ atf_check_equal 0 $res
+}
+
+fibtun_cleanup()
+{
+ fib_cleanup
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case "fibtun"
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 4, 1:54 AM (18 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42193328
Default Alt Text
D60109.1796349259.diff (9 KB)

Event Timeline