Commit Graph

1551 Commits

Author SHA1 Message Date
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
Kristof Provost
afa77b6996 pf tests: improve pfsync:basic_defer test
Create state on output only, to ensure we trigger the defer code.

MFC after:	2 weeks
2023-02-03 09:39:21 +01:00
Dag-Erling Smørgrav
69d94f4c76 Add tarfs, a filesystem backed by tarballs.
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	pauamma, imp
Differential Revision:	https://reviews.freebsd.org/D37753
2023-02-02 18:19:29 +01:00
Dmitry Chagin
02f7670ed2 sched.h: Fix _S macros for better compatibility with glibc.
In e2650af157 was added "_S" macros for compatibility with glibc, but it's still
incompatible as under glibc the macros whose names end with "_S" operate on the
dynamically allocated CPU set(s) whose size is in bytes, not in bits.

While here remove limiting ifdef to non-kernel case.

Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D38110
MFC after:		1 week
2023-01-29 15:34:10 +03:00
Alexander V. Chernikov
20ea7f26e4 pytest: delete interfaces from inside the jail.
This change follows the approach used in 80fc25025f, to
 minimise the impact of the delayed interface migration.

MFC after:	2 weeks
2023-01-25 16:34:17 +00:00
Alexander V. Chernikov
864ea9abfb pytest: add an example test fetching test directory and ATF vars.
MFC after:	2 weeks
2023-01-25 13:55:33 +00:00
Kajetan Staszkiewicz
06012728be netpfil tests: improve pfsync_defer.py
Return different exit code depending on which failure was encountered.
The pfsync test expect a very particular failure, not just any.

MFC after:	1 week
Sponsored by:	InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D38123
2023-01-22 04:26:32 +01:00
Kajetan Staszkiewicz
f57218e469 netpfil tests: improve pft_ping.py
Multiple improvements to pft_ping.py:

* Automatically use IPv6 when IPv6 addresses are used, --ip6 is not needed.
* Building of ping requests and parsing of ping replies is done layer by
  layer. This way most arguments are available both for IPv6 and IPv4,
  for ICMP and TCP.
* Use argument groups for improved readability.
* Change ToS and TTL argument name to TC and HL to reflect the modern
  IPv6 nomenclature. The argument still set related IPv4 header fields
  properly.
* Instead of sniffing for the very specific case of duplicated packets,
  allow for sniffing on multiple interfaces.
* Report which sniffer has failed by setting bits of error code.
* Raise meaningful exceptions when irrecoverable errors happen.
* Make IPv4 fragmentation flags configurable.
* Make IPv6 HL / IPv4 TTL configurable.
* Make TCP MSS configurable.
* Make TCP sequence number configurable.
* Make ICMP payload size configurable.
* Add debug output.
* Move command line argument parsing out of network functions.
* Make the code somehow PEP-8 compliant.

MFC after:	1 week
Sponsored by:	InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D38122
2023-01-22 04:26:32 +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
Alexander V. Chernikov
0079d177ab netlink: allow creating sockets with SOCK_DGRAM.
Some existing applications setup Netlink socket with
SOCK_DGRAM instead of SOCK_RAW. Update the manpage to clarify
that the default way of creating the socket should be with
SOCK_RAW. Update the code to support both SOCK_RAW and SOCK_DGRAM.

Reviewed By: pauamma
Differential Revision: https://reviews.freebsd.org/D38075
2023-01-21 14:58:19 +00: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
228c632ab3 netlink: fix compatibility with older netlink applications.
Some apps try to provide only the non-zero part of the required message
 header instead of the full one. It happens when fetching routes or
 interface addresses, where the first header byte is the family.
This behavior is "illegal" under the "strict" Netlink socket option,
 however there are many applications out there doing things in the
 "old" way.

Support this usecase by copying the provided bytes into the temporary
 zero-filled header and running the parser on this header instead.

Reported by:	Goran Mekić <meka@tilda.center>
2023-01-16 12:21:40 +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
Kajetan Staszkiewicz
ddcdb534b7 pf tests: properly destroy renamed interfaces
The pfsync:pbr tests leaves  lot of interfaces when they finish, making
other tests slower due to long time of loading scapy from pft_ping.py
when more interfaces are present. When both sides of epair are assigned
to jails, they are both removed from created_interfaces.lst and thus
won't be removed during cleanup from this file. An interface assigned to
jail is stored in created_jails.lst but if it is renamed, it won't be
cleaned up either. Furthermore this test uses identical names for
multiple interfaces across multiple jails which after destroying those
jails adds to overall confusion.

To address this issue a new function is provided for renaming interfaces
in jails and storing their new names in created_jails.lst for deletion
during cleanup.

MFC after:	1 week
Sponsored by:	InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D38024
2023-01-16 07:23:07 +01:00
Kristof Provost
dc698b2cd5 pf tests: test fast port re-use with syncookies
When a src/dst ip/port tuple is re-used before the pf state fully
expires we clean up the state and create a new one, unless syncookies
are enabled.

Test this, by running two back-to-back nc sessions, with a fixed source
port. Move the interface and IP to a different (vnet) jail, to trick the
network stack into letting us do this.

MFC after:      2 weeks
Event:          Aberdeen hackathon 2022
Differential Revision:  https://reviews.freebsd.org/D36886
2023-01-13 23:14:17 +01:00
Jose Luis Duran
4856aeaaed tests: Add an IPv4 loopback address of 127.0.0.1/8 to the lo0
interface by default when creating VNETSs using pytest.

Reviewed By: asomers
Differential Revision: https://reviews.freebsd.org/D38021
2023-01-11 14:34:41 +00:00
Alexander V. Chernikov
9408f36627 testing: fix skipping netlink tests if netlink module is not loaded. 2023-01-08 19:52:22 +00:00
Alexander V. Chernikov
c1871a3372 netlink: improve RTM_GETADDR handling.
* Allow filtering by ifa_family & ifa_index.
* Add common RTM_<NEW|DEL|GET>ADDR parser
* Add tests verifying RTM_GETADDR filtering behaviour & output
* Factor out common netlink socket test methods into NetlinkTestTemplate
* Add NLMSG_DONE message handler

Reviewed By: pauamma
Differential Revision: https://reviews.freebsd.org/D37970
2023-01-08 15:06:34 +00:00
Gleb Smirnoff
c3ca3fa7d3 tests: add test for ipfw fwd localaddr,port
Checks basic forward to local address, also with presence of
a listener that matches original port (see aab8c844b9). Based
on non-ATF test case written by Pavel Polyakov.

Reviewed by:		kp, melifaro
Differential revision:	https://reviews.freebsd.org/D37960
2023-01-06 12:17:42 -08:00
Alexander V. Chernikov
8161b823d7 testing: add python test examples
Simplify the adoption of python tests by proving some examples,
 utilising commonly-used patterns.

Differential Revision: https://reviews.freebsd.org/D37902
Reviewed by:	asomers
MFC after:	2 weeks
2023-01-01 15:29:29 +00:00
Alexander V. Chernikov
bb60d265c9 testing: fix tests without cleanup in pytest.
It was broken by 89ffac3b01,
which added "cleanup" method to the base test class,
 resulting in reporting cleanup for all of the tests.
2023-01-01 14:11:18 +00:00
Alexander V. Chernikov
89ffac3b01 testing: allow custom test cleanup handlers in pytest
In order to provide more flexibility for the test writers,
add per-test-method cleanups in addition to the per-class cleanups.

Now the test 'test_one' can perform cleanup by either defining
per-class 'cleanup' method (typically used in VNET classes) and
per-test method 'cleanup_test_one'. The latter has preference.
In order to handle paramatrization, testid is passed as a single
 argument to both of the methods.

MFC after:	2 weeks
2022-12-31 16:27:27 +00:00
Alexander V. Chernikov
f63825ff21 testing: improve python vnet wrapper.
* Derive jail name from class name and method name, instead of just
method name. This change reduces the chances of different tests
clashing.
 Old: 'jail_test_one'. New: 'pytest:TestExampleSimplest:test_one'
* Simplify vnetX_handler() method signature by skipping obj_map (unused)
 and pipe. The latter can be accessed as the vnet property.
* Add `send_object()` method as a pair to the `wait_object` inside the
 VnetTestTemplate class.
* Add `test_id` property to the BaseTest method. Previously it was
 provided only for the VnetTestTemplate class. This change makes
 the identifier easily accessible for all users.

MFC after:	2 weeks
2022-12-29 19:59:11 +00:00
Jose Luis Duran
eaeebfcb38 pytest: silence deprecation warning in the pytest atf wrapper
Convert `pytest.mark` decorator to the `pytest.hookimpl()` one,
 as suggested by the
 https://docs.pytest.org/en/latest/deprecations.html#configuring-hook-specs-impls-using-markers

Differential Revision: https://reviews.freebsd.org/D37884
MFC after:	2 weeks
2022-12-28 15:53:48 +00:00
Gleb Smirnoff
5e4ae3061f tests/divert: use PF_DIVERT
Now all Python ports has been patched to support PF_DIVERT, and
Python kinda promises to add support in 3.12 [1].

This reverts commit 322b5b7c16.

[1] https://github.com/python/cpython/pull/96536#issuecomment-1303974686
2022-12-26 12:02:45 -08:00
Alexander V. Chernikov
f2c8381fce netlink: add snl(3) - simple netlink library
Reviewed by:	bapt, pauamma
Differential Revision: https://reviews.freebsd.org/D37736
2022-12-23 15:03:13 +00:00
John Baldwin
3845cce70d ktls_tests: Ignore errors from close for receive error tests.
For tests that send invalid data to a TLS socket to trigger read
errors the kernel may end up dropping the connection before close is
called at the conclusion of the test resulting in spurious ECONNRESET
errors from close.  Ignore any errors from close for these tests.

PR:		268390
Reported by:	olivier, Michal Gulbicki <michalx.gulbicki@intel.com>
Reviewed by:	markj
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37717
2022-12-20 11:38:28 -08:00
John Baldwin
f0c143b356 ktls_tests: Ignore spurious errors from shutdown(2).
For some of the "bad size" tests, the remote end can notice the error
and drop the connection before the test program returns from write to
call shutdown.  In that case, shutdown fails with ENOTCONN.  Permit
these ENOTCONN errors without failing the test.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37693
2022-12-20 11:38:07 -08: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
Alexander V. Chernikov
3873bdc2f2 netlink: connect netlink tests to the build
Reviewed By: ngie
Differential Revision: https://reviews.freebsd.org/D37708
2022-12-16 12:02:50 +00:00
John Baldwin
883d1742d3 ktls_tests: Log more details when a test fails.
- Make use of ATF_REQUIRE_INTEQ to log the values of integers for
  unexpected mismatches.

- Use ATF_REQUIRE_MSG in a few more places to log values when a
  requirement fails.

- Consistently use ATF_REQUIRE_ERRNO when checking for an expected
  errno value.

Reviewed by:	markj
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37691
2022-12-15 12:06:09 -08:00
Alexander V. Chernikov
80f03e63d6 netlink: improve interface handling
* Separate interface creation from interface modification code
* Support setting some interface attributes (ifdescr, mtu, up/down, promisc)
* Improve interaction with the cloners requiring to parse/write custom
 interface attributes
* Add bitmask-based way of checking if the attribute is present in the
message
* Don't use multipart RTM_GETLINK replies when searching for the
specific interface names
* Use ENODEV instead of ENOENT in case of failed RTM_GETLINK search
* Add python netlink test helpers
* Add some netlink interface tests

Differential Revision: https://reviews.freebsd.org/D37668
2022-12-14 19:52:35 +00:00
Kristof Provost
654e8d84ec pf tests: check that we clean up unused kifs
The previous commit fixed a memory leak, where we'd fail to clean up
removed groups (and interfaces).
Check that we now clean those up as expected.

MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D37570
2022-12-14 10:19:01 +01:00
John Baldwin
1656007e4c ptrace_test: Remove another MIPS remnant. 2022-12-13 14:51:52 -08:00
Konstantin Belousov
91ddfd352f posixshm_test: add naive page accounting test
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37097
2022-12-09 14:17:12 +02:00
Konstantin Belousov
f1f030246f posixshm_test: small style fixes
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37097
2022-12-09 14:17:12 +02:00
John Baldwin
70bb22868d ktls_test: Add debug option to hexdump keys, nonces, and buffers.
Reviewed by:	markj
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37509
2022-12-07 16:57:28 -08:00
Gleb Smirnoff
78ec113617 tests/netinet: mark more tests that require python 2022-12-07 11:51:49 -08:00
John Baldwin
8dd8d56d95 posixshm_test: Fix sign mismatches in ?: results.
GCC 12's -Wsign-compare complains if the two alternative results of
the ?: operator are differently signed.  Cast the small, sub-page
off_t values to size_t to quiet the warning.

Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D37539
2022-12-04 16:31:05 -08:00
John Baldwin
f4db390553 netmap tests: Reset ctx->nmctx to NULL in nmreq_parsing.
This avoids leaking a pointer to the on-stack test_nmctx which
triggers a -Wdangling-pointer warning from GCC.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D37536
2022-12-04 16:29:25 -08:00
Kristof Provost
7a6bcfb44d pf tests: test that reassembly is or is not performed as expected
We can now tell scrub rules to not reassemble packets. Test that this
affects packets being passed or dropped as expected.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-11-28 20:19:12 +01:00
John Baldwin
65bd3adbed ktls: Add tests for receiving corrupted or invalid records.
These should all trigger errors when reading from the socket.

Tests include truncated records (socket closed early on the other
side), corrupted records (bits flipped in explicit IVs, ciphertext, or
MAC), invalid header fields, and various invalid record lengths.

Reviewed by:	markj
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37373
2022-11-15 12:03:19 -08:00
John Baldwin
64811651aa ktls: Add tests for software AES-CBC decryption for TLS 1.1+.
Reviewed by:	markj
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37371
2022-11-15 12:02:28 -08:00
Eric van Gyzen
11ed0a95bf zfs tests: stop writing to arbitrary devices
TL;DR:  Three ZFS tests created ZFS pools on all unmounted devices listed
in /etc/fstab, corrupting their contents.  Stop that.

Imagine my surprise when the ESP on my main dev/test VM would "randomly"
become corrupted, making it unbootable.  Three tests collect various devices
from the system and try to add them to a test pool.  The test expects this
to fail because it _assumes_ these devices are in use and ZFS will correctly
reject the request.

My /etc/fstab has two entries for devices in /dev:

    /dev/gpt/swap0  none        swap    sw,trimonce,late
    /dev/gpt/esp0   /boot/efi   msdosfs rw,noauto

Note the `noauto` on the ESP.  In a remarkable example of irony, I chose
this because it should keep the ESP more protected from corruption;
in fact, mounting it would have protected it from this case.

The tests added all of these devices to a test pool in a _single command_,
expecting the command to fail.  The swap device was in use, so the command
correctly failed, but the ESP was added and therefore corrupted.  However,
since the command correctly failed, the test didn't notice the ESP problem.
If each device had been added with its own command, the test _might_ have
noticed that one of them incorrectly succeeded.  However, two of these
tests would not have noticed:

hotspare_create_001_neg was incorrectly specified as needing the Solaris
dumpadm command, so it was skipped.  _Some_ of the test needs that command,
but it checks for its presence and runs fine without it.

Due to bug 241070, zpool_add_005_pos was marked as an expected failure.
Due to the coarse level of integration with ATF, this test would still
"pass" even if it failed for the wrong reason.  I wrote bug 267554 to
reconsider the use of atf_expect_fail in these tests.

Let's further consider the use of various devices found around the system.
In addition to devices in /etc/fstab, the tests also used mounted devices
listed by the `mount` command.  If ZFS behaves correctly, it will refuse
to added mounted devices and swap devices to a pool.  However, these are
unit tests used by developers to ensure that ZFS still works after they
modify it, so it's reasonable to expect ZFS to do the _wrong_ thing
sometimes.  Using random host devices is unsafe.

Fix the root problem by using only the disks provided via the "disks"
variable in kyua.conf.  Use one to create a UFS file system and mount it.
Use another as a swap device.  Use a third as a dump device, but expect
it to fail due to bug 241070.

While I'm here:

Due to commit 6b6e2954dd, we can simply add a second dump device and
remove it in cleanup.  We no longer need to save, replace, and restore the
pre-existing dump device.

The cleanup_devices function used `camcontrol inquiry` to distinguish disks
from other devices, such as partitions.  That works fine for SCSI, but not
for ATA or VirtIO block.  Use `geom disk list` instead.

PR:		241070
PR:		267554
Reviewed by:	asomers
Sponsored by:	Dell Inc.
Differential Revision:	https://reviews.freebsd.org/D37257
2022-11-11 14:43:47 -06:00
Kristof Provost
c90b9a5ebb netpfil tests: add dummynet fq_codel test case
fq_codel was broken due to a missing m_rcvif_serialize() in the enqueue
path.
Add a simple test case to ensure it at least passes traffic.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-11-11 11:55:59 +01: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
Ed Maste
185efcc376 tests: also remove sparc64 case
Followup to commit d6273acf56, which removed MIPS.

Reported by:	mhorne
2022-11-08 18:55:00 -05:00
Ed Maste
d6273acf56 tests: retire now-unused MIPS case 2022-11-08 09:17:53 -05:00
Kristof Provost
a7222b3cc3 pf tests: bridge-to test case
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D37194
2022-11-02 15:45:23 +01:00