Commit Graph

130 Commits

Author SHA1 Message Date
Kristof Provost
480ad40553 vnet tests: check for if_bridge.ko
A number of tests create a bridge, but did not check if if_bridge.ko is loaded.

We usually get away with that, because `ifconfig bridge create` autoloads the
module, but if we run the tests in a jail (e.g. because of kyua's upcoming
execenv.jail.params feature) we can't load the module and these tests can fail.

Check if the module is loaded, skip the test if it is not.

Reviewed by:	markj
MFC after:	1 week
Event:		Kitchener-Waterloo Hackathon 202406
Differential Revision:	https://reviews.freebsd.org/D45487
2024-06-04 22:16:56 +02:00
Kristof Provost
bdd12889ea if_vlan: handle VID conflicts
If we fail to change the vlan id we have to undo the removal (and vlan id
change) in the error path. Otherwise we'll have removed the vlan object from the
hash table, and have the wrong vlan id as well. Subsequent modification attempts
will then try to remove an entry which doesn't exist, and panic.

Undo the vlan id modification if the insertion in the hash table fails, and
re-insert it under the original vlan id.

PR:		279195
Reviewed by:	zlei
MFC atfer:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D45285
2024-05-22 09:08:02 +02:00
Zhenlei Huang
76df3c57a0 ifconfig: Redo fix vlan/vlanproto reconfiguration
When the if_vlan(4) interface has not been fully configured, i.e., a
bare interface without a physical interface associated with it,
retrieving the current settings of it and unconditionally overwriting
`params` will result in losing vlandev settings in `params`. That will
lead to failing to associate the if_vlan(4) interface with the requested
physical interface and the false report 'both vlan and vlandev must be
specified'.

Fix that by checking if the vlan interface has been fully configured.

The basic VLAN test is slightly modified to cover this case.

PR:		279181
Reviewed by:	kp
Tested by:	Mike Tancsa <mike@sentex.net>
Fixes:		b82b8055ad ifconfig: fix vlan/vlanproto reconfiguration
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D45283
2024-05-22 00:35:01 +08:00
Kristof Provost
59a6666ec9 if_ovpn: cope with loops
User misconfiguration may lead to routing loops where we try to send the tunnel
packet into the tunnel. This eventually leads to stack overflows and panics.

Avoid this using if_tunnel_check_nesting(), which will drop the packet if we're
looping or we hit three layers of nested tunnels.

MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-05-13 12:11:06 +02:00
Gleb Smirnoff
0089d83b3a lagg: enable tests that stress the configuration changes
I wasn't able to reproduce a crash in several runs.  Might be that
48698ead6f or earlier changes have closed the races.  In case crashes
with just enabled tests are registered, I will either work on them or
disable tests again.
2024-05-06 15:27:32 -07:00
Gleb Smirnoff
570685971c lagg: propagate up/down to the children
Based on the old submission from asomers@.  With modern state of locking
in lagg(4), the patch got much simplier.  Enable the test that was
waiting for this change.

PR:			226144
Reviewed by:		asomers
Differential Revision:	https://reviews.freebsd.org/D44605
2024-05-06 15:27:32 -07:00
Mark Johnston
c0f1323241 wg tests: Add a simple regression test case for netmap support
MFC after:	1 month
Sponsored by:	Klara, Inc.
Sponsored by:	Zenarmor
2024-04-20 12:04:42 -04:00
Kristof Provost
e08b44339b if_ovpn tests: test large packets in IPv6 tunnel
There's a report of MTU issues over IPv6 DCO tunnels.
Extend the 4in6 test to send a series of pings with different sizes, as
well as transfer a large file.

No issues were found, but we may as well extend the test case.

PR:		276838
2024-03-22 09:00:05 +01:00
Gleb Smirnoff
6ee181b9d5 tests/net: enable if_clone_test:epair_ipv6_up_stress
The panic mentioned was fixed in f5a365e51f.

PR:	225438
2024-01-10 20:51:53 -08:00
Michael Gmelin
3d36053ca6 libifconfig: Fix bridge status member list
When this functionality was moved to libifconfig in 3dfbda3401,
the end of list calculation was modified for unknown reasons, practically
limiting the number of bridge member returned to (about) 102.

This patch changes the calculation back to what it was originally and
adds a unit test to verify it works as expected.

Reported by:	Patrick M. Hausen (via ML)
Reviewed by:	kp
Approved by:	kp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43135
2023-12-21 16:50:27 +01:00
Warner Losh
6dced2c635 tests: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:01 -07:00
Kristof Provost
956a463114 if_ovpn tests: fix ra test
Client one is supposed to be assigend 198.51.100.2, but sometimes it
loses the race and the address ends up assigned to client two. When this
happened one would try to ping itself, which failed because the loopback
interface isn't up.

Ideally we'd generate static address assignments, but that would
complicate the test. Activate loopback interfaces so the test always
passes, and just try to ping both possible addresses.

MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-10-05 09:48:49 +02:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh
b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Kristof Provost
92c23f6d9c vlan: fix setting flags on a QinQ interface
Setting vlan flags needlessly takes the exclusive VLAN_XLOCK().

If we have stacked vlan devices (i.e. QinQ) and we set vlan flags (e.g.
IFF_PROMISC) we call rtnl_handle_ifevent() to send a notification about
the interface.
This ends up calling SIOCGIFMEDIA, which requires the VLAN_SLOCK().
Trying to take that one with the VLAN_XLOCK() held deadlocks us.

There's no need for the exclusive lock though, as we're only accessing
parent/trunk information, not modifying it, so a shared lock is
sufficient.

While here also add a test case for this issue.

Backtrace:
	shared lock of (sx) vlan_sx @ /usr/src/sys/net/if_vlan.c:2192
	while exclusively locked from /usr/src/sys/net/if_vlan.c:2307
	panic: excl->share
	cpuid = 29
	time = 1683873033
	KDB: stack backtrace:
	db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe015d4ad4b0
	vpanic() at vpanic+0x152/frame 0xfffffe015d4ad500
	panic() at panic+0x43/frame 0xfffffe015d4ad560
	witness_checkorder() at witness_checkorder+0xcb5/frame 0xfffffe015d4ad720
	_sx_slock_int() at _sx_slock_int+0x67/frame 0xfffffe015d4ad760
	vlan_ioctl() at vlan_ioctl+0xf8/frame 0xfffffe015d4ad7c0
	dump_iface() at dump_iface+0x12f/frame 0xfffffe015d4ad840
	rtnl_handle_ifevent() at rtnl_handle_ifevent+0xab/frame 0xfffffe015d4ad8c0
	if_setflag() at if_setflag+0xf6/frame 0xfffffe015d4ad930
	ifpromisc() at ifpromisc+0x2a/frame 0xfffffe015d4ad960
	vlan_setflags() at vlan_setflags+0x60/frame 0xfffffe015d4ad990
	vlan_ioctl() at vlan_ioctl+0x216/frame 0xfffffe015d4ad9f0
	if_setflag() at if_setflag+0xe4/frame 0xfffffe015d4ada60
	ifpromisc() at ifpromisc+0x2a/frame 0xfffffe015d4ada90
	bridge_ioctl_add() at bridge_ioctl_add+0x499/frame 0xfffffe015d4adb10
	bridge_ioctl() at bridge_ioctl+0x328/frame 0xfffffe015d4adbc0
	ifioctl() at ifioctl+0x972/frame 0xfffffe015d4adcc0
	kern_ioctl() at kern_ioctl+0x1fe/frame 0xfffffe015d4add30
	sys_ioctl() at sys_ioctl+0x154/frame 0xfffffe015d4ade00
	amd64_syscall() at amd64_syscall+0x140/frame 0xfffffe015d4adf30
	fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe015d4adf30
	--- syscall (54, FreeBSD ELF64, ioctl), rip = 0x22b0f0ef8d8a, rsp = 0x22b0ec63f2c8, rbp = 0x22b0ec63f380 ---
	KDB: enter: panic
	[ thread pid 5715 tid 101132 ]

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-05-12 11:12:51 +02:00
Kristof Provost
f76df4718d if_ovpn tests: fix route_to test case
* Move the .254 address to the tunnel device so we reply through the
  tunnel.
* Remove the network route to 'break' routing, which we then 'fix' with
  pf's route-to, which is the functionality we wanted to test in the
  first place.

Reported by:	markj
Sponsored by:   Rubicon Communications, LLC ("Netgate")
2023-05-08 17:44:47 +02:00
Kristof Provost
f97802a35e bridge tests: test cross-vlan bridging
Ensure that the bridge takes VLAN IDs into account when learning
addresses.

PR:		270559
Differential Revision:	https://reviews.freebsd.org/D39379
2023-04-14 13:17:02 +02:00
Kristof Provost
d116b8430b epair tests: test PCP tagged packets
PR:		270736
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D39483
2023-04-10 15:55:53 +02:00
Mark Johnston
196f390121 if_ovpn tests: Serialize
These tests reuse jail names and so cannot run in parallel.

MFC after:	1 week
2023-03-30 19:35:59 -04:00
Alexander V. Chernikov
badcb3fd57 routing: fix panic when adding an interface route to the p2p interface
without and inet/inet6 addresses attached.

MFC after:      3 days
2023-03-29 20:28:24 +00:00
Mark Johnston
a7ba32e6bc tun tests: Fix cleanup definitions
Without this, vnet jails for the tests don't get torn down.

Fixes:	fe701c39e8 ("if_tun: Add basic connectivity test with nc tun support")
2023-03-16 13:27:24 -04:00
Kristof Provost
69361b8785 if_ovpn tests: skip the if_ovpn_c test if if_ovpn.ko isn't loaded
Skip the test (rather than loading it) if if_ovpn.ko isn't loaded. Match
the behaviour of other tests.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-03-01 10:07:34 +01:00
Kyle Evans
e63dcbe7a2 wg: tests: remove an obsolete workaround
PR 254212 was resolved to avoid issues with not having IPv6 addresses
present in the jail, so we can safely drop this workaround now...

Reviewed by:	jhb, markj
Differential Revision:	https://reviews.freebsd.org/D37755
2023-02-12 23:59:46 -06:00
Kyle Evans
96f4ab2663 wg: add a test for the home jail socket feature
This adds a test for a semantic that we added to mirror a feature of
the Linux implementation w/ netns: if a wg interface is moved into a
jail, we still create the socket in the context of the home vnet.  With
this added, one can actually create vnet jails that only have a wg
tunnel to the outside world providing network connectivity without any
epairs in the setup.

Reviewed by:	jhb, markj (both earlier version)
Differential Revision:	https://reviews.freebsd.org/D37755
2023-02-12 23:59:35 -06:00
Olivier Cochard
d22c5c42e8 Skip if_wg regression tests if module doesn't exist
Approved by:	jhb
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D38406
2023-02-07 00:06:48 +01:00
Kajetan Staszkiewicz
a39dedeb31 netpfil tests: improve sniffer.py
Multiple improvements to sniffer.py:

* Remove ambiguity of configuring recvif, it must be now explicitly specified.
* Don't catch exceptions around creating the sniffer, let it properly
  fail and display the whole stack trace.
* Count correct packets so that duplicates can be found.

MFC after:	1 week
Sponsored by:	InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D38120
2023-01-22 04:26:32 +01:00
Tom Jones
fe701c39e8 if_tun: Add basic connectivity test with nc tun support
Reviewed by:    kevans
Sponsored by:   Zenarmor
Sponsored by:   OPNsense
Sponsored by:   Klara, Inc.
Differential Revision:  https://reviews.freebsd.org/D37435
2023-01-17 10:05:50 +00:00
Alexander V. Chernikov
42904794b8 rtsock: fix socket closure.
Currently `close(2)` erroneously return `EOPNOTSUPP` for `PF_ROUTE` sockets.
It happened after making rtsock socket implementation self-contained (
36b10ac2cd ). Rtsock code marks socket as connected in `rts_attach()`.
`soclose()` tries to disconnect such socket using `.pr_disconnect` callback.
Rtsock does not implement this callback, resulting in the default method being
substituted. This default method returns `ENOTSUPP`, failing `soclose()` logic.

This diff restores the previous behaviour by adding custom `pr_disconnect()`
returning `ENOTCONN`.

Reviewed by:	glebius
Differential Revision: https://reviews.freebsd.org/D38059
2023-01-16 10:49:45 +00:00
John Baldwin
8fb9739615 wg: Re-add basic if_wg(4) tests.
These were originally added in commit
74ae3f3e33 but have been updated to use
wg(8).

Reviewed by:	kevans, markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37400
2022-12-16 12:01:26 -08:00
Kristof Provost
832c8a58e1 if_ovpn tests: add aes-128-gcm test case
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-11-11 11:17:39 +01:00
Kristof Provost
e838ed7ca1 if_ovpn tests: fix typo in test description
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-11-10 14:34:25 +01:00
Kristof Provost
e1274b5b26 bridge tests: re-enable span test
The root cause of the intermittent span test failures has been
identified as a race between sending the packet and starting the bpf
capture.
This is now resolved, so the test can be re-enabled.

PR:		260461
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-11-02 11:59:11 +01:00
Kristof Provost
713efe0542 if_ovpn tests: fix timeout test case
Use the management interface to work out if we've timed out the client,
rather than looking for an openvpn process to die (with incorrect
syntax).

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-10-18 10:12:23 +02:00
Kristof Provost
188e069670 if_ovpn tests: test explicit exit notifications
Test that when a client exits the server notices this, even without
keepalive traffic.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-10-18 10:12:22 +02:00
Kristof Provost
76e1c9c671 if_ovpn: fix address family check when traffic class bits are set
When the tunneled (IPv6) traffic had traffic class bits set (but only >=
16) the packet got lost on the receive side.

This happened because the address family check in ovpn_get_af() failed
to mask correctly, so the version check didn't match, causing us to drop
the packet.

While here also extend the existing 6-in-6 test case to trigger this
issue.

PR:		266598
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-09-26 13:54:20 +02:00
Kristof Provost
eed634d113 if_ovpn tests: fix WITHOUT_PF
At least one if_ovpn.sh test relies on pf, so the file includes
netpfil/pf/utils.subr, which doesn't exist if WITHOUT_PF is set.

Do not install the if_ovpn.sh tests if pf is disabled.

Suggested by:	Olivier Cochard-Labbé <olivier@freebsd.org>
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-08-18 11:25:51 +02:00
Dimitry Andric
ab28cc352b Adjust function definition in if_ovpn_c.c to avoid clang 15 warning
With clang 15, the following -Werror warning is produced:

    tests/sys/net/if_ovpn/if_ovpn_c.c:19:14: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    fake_sockaddr()
		 ^
		  void

This is because fake_sockaddr() is declared with a (void) argument list,
but defined with an empty argument list. Make the definition match the
declaration.

MFC after:      3 days
2022-08-14 13:11:52 +02:00
Kristof Provost
248da7940a if_ovpn tests: Test using a TCP socket for DCO
This used to trigger panics, so try to reproduce it.
Create an if_ovpn interface, set a new peer on it with a TCP fd (as
opposed to the expected UDP) and ensure that this is rejected.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-08-11 10:40:03 +02:00
Kristof Provost
b77d581535 if_ovpn tests: remote access test case
Add a (multi-client) test case where we route traffic beyond the ovpn
server, onto a shared LAN.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-08-09 15:14:14 +02:00
Alexander V. Chernikov
7064c94a02 tests: add routing tests for switching between same prefixes
Differential Revision: https://reviews.freebsd.org/D36055
MFC after:	2 weeks
2022-08-07 19:45:25 +00:00
Mark Johnston
121e120883 bridge tests: Tests using pft_ping.py require scapy
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-08-04 09:41:52 -04:00
Kristof Provost
cfee1417fb if_vlan tests: Test changing vlan ID
We can now change the vlan ID of an if_vlan interface without
disassociating it from the parent interface.

Test that this works.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D35847
2022-07-21 18:36:01 +02:00
Kristof Provost
6ba6c05cb2 if_ovpn: deal with short packets
If we receive a UDP packet (directed towards an active OpenVPN socket)
which is too short to contain an OpenVPN header ('struct
ovpn_wire_header') we wound up making m_copydata() read outside the
mbuf, and panicking the machine.

Explicitly check that the packet is long enough to copy the data we're
interested in. If it's not we will pass the packet to userspace, just
like we'd do for an unknown peer.

Extend a test case to provoke this situation.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-07-05 19:27:00 +02:00
Kristof Provost
5fb35badc0 if_ovpn tests: IPv4-mapped IPv6 address test
OpenVPN uses IPv4-mapped IPv6 addresses by default (if we don't specify
'proto udp4', or an IPv4 address to bind to). Test that this works.

Sponsored by:   Rubicon Communications, LLC ("Netgate")
2022-07-01 10:02:32 +02:00
Kristof Provost
1e5ef2a7e1 if_ovpn tests: extend multi_client test with an iroute test
OpenVPN allows us to push routes for client networks with the 'iroute'
directive. Test that this works as expected.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-06-28 13:51:41 +02:00
Kristof Provost
a7a273546e if_ovpn tests: test multiple simultaneous clients
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-06-28 13:51:41 +02:00
Kristof Provost
2fc1fc66c7 if_ovpn tests: Test if_ovpn when there's no route
In client mode (i.e. if there's only one peer) we should be able to
route to the correct peer even if the routing table is incorrect.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-06-28 13:51:30 +02:00
Kristof Provost
f8b1ddbfb1 if_ovpn tests: tunnel with CHACHA20-POLY1305
Sponsored by:   Rubicon Communications, LLC ("Netgate")
2022-06-28 13:51:24 +02:00