Commit graph

1895 commits

Author SHA1 Message Date
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
Kristof Provost 470a2b3346 pf: convert DIOCSETSTATUSIF to netlink
While here also add a basic test case for it.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D44368
2024-03-19 16:30:08 +01:00
Kristof Provost c6f1116357 pf: fix dummynet + route-to
Ensure that we pick the correct dummynet pipe (i.e. forward vs. reverse
direction) when applying route-to.

We mark the processing as outbound so that dummynet will re-inject in
the correct phase of processing after it's done with the packet, but
that will cause us to pick the wrong pipe number. Reverse them so that
the incorrect decision ends up picking the correct pipe.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D44366
2024-03-19 16:29:29 +01:00
Kristof Provost 0ea0c02655 pf: avoid passing through dummynet multiple times
In some setups we end up with multiple states created for a single
packet, which in turn can mean we run the packet through dummynet
multiple times. That's not expected or intended. Mark each packet when
it goes through dummynet, and do not pass packet through dummynet if
they're marked as having already passed through.

See also:	https://redmine.pfsense.org/issues/14854
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D44365
2024-03-19 16:29:29 +01:00
Gleb Smirnoff 55951611e4 tests/unix_seqpacket: mk_pair_of_sockets() requires a valid argument
All callers do it right.  Don't be overprotective against a stupid
caller and thus don't look like a code that leaks a resource.

Reported by:	Coverity Scan
CID:		1539210
2024-03-11 07:50:29 -07:00
Dag-Erling Smørgrav 32b8aac6f9 tarfs: Factor out common test code.
MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D44227
2024-03-06 17:14:05 +01:00
Dag-Erling Smørgrav 0118b0c8e5 tarfs: Fix checksum calculation.
The checksum code assumed that struct ustar_header filled an entire
block and calculcated the checksum based on the size of the structure.
The header is in fact only 500 bytes long while the checksum covers
the entire block (“logical record” in POSIX terms).  Add padding and
an assertion, and clean up the checksum code.

MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D44226
2024-03-06 17:14:01 +01:00
Dag-Erling Smørgrav 38b3683592 tarfs: Fix two input validation issues.
* Reject hard or soft links with an empty target path.  Currently, a
  debugging kernel will hit an assertion in tarfs_lookup_path() while
  a non-debugging kernel will happily create a link to the mount root.

* Use a temporary variable to store the result of the link target path,
  and copy it to tnp->other only once we have found it to be valid.
  Otherwise we error out after creating a reference to the target but
  before incrementing the target's reference count, which results in a
  use-after-free situation in the cleanup code.

* Correctly return ENOENT from tarfs_lookup_path() if the requested
  path was not found and create_dirs is false.  Luckily, existing
  callers did not rely solely on the return value.

MFC after:	3 days
PR:		277360
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	sjg
Differential Revision:	https://reviews.freebsd.org/D44161
2024-03-06 17:13:42 +01:00
Kristof Provost fb995824b9 pf tests: IPv6 versions of the route-to/reply-to if-bound tests
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-03-01 09:39:44 +01:00
Kristof Provost 6460322a0a pf: support if-bound with reply-to
On reply-to we don't know what interface to bind to when we create
the state. Create any reply-to state as floating, but bind to the
appropriate interface once we're handling the reply.

See also:	https://redmine.pfsense.org/issues/15220
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-03-01 09:39:43 +01:00
Gleb Smirnoff 253d8a1f8a tests/unix_seqpacket: test that implied connect doesn't work
Applies both to SOCK_STREAM and SOCK_SEQPACKET.  Put the test in this file
as it is most advanced one.

Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D43854
2024-02-28 14:32:47 -08:00
Gleb Smirnoff 3bc122d270 tests/unix_seqpacket: test that data can be sent before accept(2)
This is undocumented feature of PF_UNIX/SOCK_STREAM and thus of
PF_UNIX/SOCK_SEQPACKET, too.  Put the test into this file, since this file
is most advanced and has all primitives to write this test in minimum
number of lines.

Differential Revision:	https://reviews.freebsd.org/D43853
2024-02-28 14:32:46 -08:00
Gleb Smirnoff 1f46c32c1f tests/unix_seqpacket: provide function that returns bound & listening sock
Use the function in mk_pair_of_sockets(), and in four existing tests -
'listen_bound', 'connect', 'shutdown_send' and 'shutdown_send_sigpipe'.
While here make mk_pair_of_sockets() return pointer to sockaddr_un instead
of path.  This also fixes bug of returning pointer to stack memory of
returning function.  However, the only caller that cares about this return
is temporarily ifdefed out.  No functional change intended.

Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D43852
2024-02-28 14:32:46 -08:00
Gleb Smirnoff d6ef9649dd tests/unix_seqpacket: remove EMSGSIZE tests
These tests were not testing conformance to the specification, rather than
the limitation of our implementation.  The specification doesn't say that
a SOCK_SEQPACKET shall ever return EMSGSIZE.  It says:

  The SOCK_SEQPACKET socket type is similar to the SOCK_STREAM type,
  and is also connection-oriented. The only difference between these
  types is that record boundaries are maintained using the
  SOCK_SEQPACKET type. A record can be sent using one or more output
  operations and received using one or more input operations, but a
  single operation never transfers parts of more than one record.
  Record boundaries are visible to the receiver via the MSG_EOR flag
  in the received message flags returned by the recvmsg() function. It
  is protocol-specific whether a maximum record size is imposed.

The EMSGSIZE is specified as 'message is too large to be sent all at once,
as the socket requires'.  Indeed existing implementation that has
unix/seqpacket marked as PR_ATOMIC has such a limitation.  But future
implementation won't have, thus remove the tests.

Reviewed by:		tuexen, asomers
Differential Revision:	https://reviews.freebsd.org/D43756
2024-02-28 14:32:46 -08:00
Gleb Smirnoff 152a6d410e socket tests: remove MSG_TRUNC test for unix/seqpacket
The PF_UNIX/SOCK_SEQPACKET was marked as PR_ATOMIC and that made
soreceive_generic() to treat it pretty much as a datagram socket.
However, POSIX says:

  The SOCK_SEQPACKET socket type is similar to the SOCK_STREAM type,
  and is also connection-oriented. The only difference between these
  types is that record boundaries are maintained using the
  SOCK_SEQPACKET type. A record can be sent using one or more output
  operations and received using one or more input operations, but a
  single operation never transfers parts of more than one record.
  Record boundaries are visible to the receiver via the MSG_EOR flag
  in the received message flags returned by the recvmsg() function. It
  is protocol-specific whether a maximum record size is imposed.

What the test was doing is checking if MSG_TRUNC would report the space
required to return up the end of next mbuf record in the socket buffer.
Apparently the test assumed that this boundary is defined by the write(2)
size on the peer socket.  This was true in test conditions, but I'm not
sure it would always be true - sbcompress() may merge mbufs. Anyway, the
mbuf boundaries are internal socket buffer implementation, they are not
SOCK_SEQPACKET records.  The records need to be explicitly marked with
MSG_EOR by sender, and the test definitely wasn't doing that.

Reviewed by:		tuexen, markj
Differential Revision:	https://reviews.freebsd.org/D43707
2024-02-28 14:32:46 -08:00
Kristof Provost 9566d92726 pf: fix packet-to-big for route-to as well
When we handle a packet via route-to (i.e. pf_route6()) we still need to
verify the MTU. However, we only run that check in the forwarding case.

Set the PFIL_FWD tag when running the pf_test6(PF_OUT) check from
pf_route6(). We are in fact forwarding, so should call the test function
as such. This will cause us to run the MTU check, and generate an ICMP6
packet-too-big error when required.

See also:	54c62e3e5d
See also:	f1c0030bb0
See also:	https://redmine.pfsense.org/issues/14290
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-02-27 14:38:38 +01:00
Konstantin Belousov 09dd7240ac sigsys test: correct count of delivered signals
When knob is zero, intent is that no SIGSYS signals are delivered.
Comparing zero to zero does not test much, we should compare the count
of delivered SIGSYSs to zero.

Reviewed by:	dchagin, imp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D44077
2024-02-25 10:11:49 +02:00
Gleb Smirnoff 4c6ceca9cc tests/fdgrowtable: perform the threaded test in a child process
The test needs to be performed in a new process that was forked with
RFCFDG flag.  The will guarantee that the table will start to grow from 20
file descriptors, no matter what kyua(1) or a bare shell was doing before
executing this test.  This should fix  repetitive test runs from a shell
as well as failures with kyua(1) in some environments.
2024-02-23 17:49:53 -08:00
Gleb Smirnoff 98ef51d549 Revert "tests/fdgrowtable: open more files in the threaded case"
This reverts commit fa6a02f50e.

It makes the test less probable to fail, but it doesn't fix the
root issue - that on entry the parent process may have already
a large file descriptor table.
2024-02-23 17:47:29 -08:00
Tom Jones 3db693f7da pf: Correct SPDX identifier
Pointed out by: Mike Karels <karels@FreeBSD.org>
2024-02-23 15:58:38 +00:00
Tom Jones b9870ba93e pf: Add a TCP rdr test on IPv6
Reviewed by:    kp
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision: https://reviews.freebsd.org/D42105
2024-02-23 13:47:35 +00:00
Gleb Smirnoff e53b83a849 tests/sigsys: initialize parameter passed to sysctlbyname() 2024-02-20 14:37:45 -08:00
Gleb Smirnoff 3ac001620e tests/fdgrowtable: remove always true check
We are always the parent in this code path.
2024-02-20 14:31:06 -08:00
Gleb Smirnoff fa6a02f50e tests/fdgrowtable: open more files in the threaded case
This should fix the test failing on some machines/conditions/runs.  This
won't fix failures in standalone run, but should fix kyua(1) runs.
Currently with standalone run it will usually fail because the 40-sized
allocation is skipped (see details below).

This matches what forking test does: open 128 files in the parent and 128
in the child.  There should actually be no difference where and when the
files are open, but let's mimic the forking test, and open more files in
the spawned thread.  Also opening from two different contexts adds a bit
more entropy to the test.

What the test does it checks that fdgrowtable() has been called at least
three tmes for the test process, and the old tables are still on the free
list as long as other execution contexts exist.  Under kyua(1) control the
first call grows the table from 20 to 40, but the original table of 20 is
an embedded one, thus is not put on the free list.  Passing 40 open files
the table grows to 128 and first old table lands on the free list. Passing
128 open file the table grows to 256 and a second old table lands on the
free list.  After that the test would pass.  The threaded test was one
open file off before this fix sometimes.
2024-02-20 14:31:06 -08:00
Gleb Smirnoff 1968d71647 tests/arp: test arp -s/-S work
Install permanent entry, try to modify it, check that
net.link.ether.inet.log_arp_permanent_modify works.
2024-02-20 10:32:03 -08:00
Gleb Smirnoff 28bc1822b7 tests/arp: when checking 'arp -d' check that entry is removed
Previous check trusted the "entry was deleted" output of the command.
Improved check does additional request to make sure that entry is not
returned.
2024-02-20 10:32:03 -08:00
Gleb Smirnoff bc9107f8c4 socket tests: add listener_wakeup
This test runs several scenarios when sleep(9) on a listen(2)ing socket is
interrupted by shutdown(2) or by close(2).  What should happen in that
case is not specified, neither is documented.  However, there is certain
behavior that we have and this test makes sure it is preserved.  There is
software that relies on it, see bug 227259.  This test is based on
submission with this bug, bugzilla attachment 192260.

The test checks TCP and unix(4) stream socket behavior and SCTP can be
added easily if needed.

The test passes on FreeBSD 11 to 15.  It won't pass on FreeBSD 10,
although the wakeup behavior of shutdown(2) is the same, but it doesn't
return error.

PR:	227259
2024-02-15 10:48:44 -08:00
Ed Maste 8d1348f55a path_test: fix cap_rights_init usage
Capability rights passed to cap_rights_* are not simple bitmaks and
cannot be ORed together in general (although it will work for certain
subsets of rights).

PR:		277057
Fixes:		e5e1d9c7b7 ("path_test: Add a test case for...")
Sponsored by:	The FreeBSD Foundation
2024-02-15 08:58:39 -05:00
Yen-Cheng Chang 664812f734
Fix grammar error in test/sys/file/closefrom_test.c
Event:		Advanced UNIX Programming Course (Fall’23) at NTHU.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/973
2024-02-13 12:33:06 +08:00
Gleb Smirnoff 3ad0f9a584 tests/unix_passfd: add a comment for send_a_lot
Explain why SOCK_DGRAM and SOCK_STREAM differ in this edge case.  While
here improve output in case of a failure.
2024-02-08 09:00:41 -08:00
Gleb Smirnoff 1e68b8d9a9 tests/unix_passfd: test that control mixed with data creates records
If socket has data interleaved with control it would never allow to read
two pieces of data, neither two pieces of control with one recvmsg(2).  In
other words, presence of control makes a SOCK_STREAM socket behave like
SOCK_SEQPACKET, where control marks the records. This is not a documented
or specified behavior, but this is how it worked always for BSD sockets.
If you look closer at it, this actually makes a lot of sense, as if it
were the opposite both the kernel code and an application code would
become way more complex.

The change made recvfd_payload() to return received length and requires
caller to do ATF_REQUIRE() itself.  This required a small change to
existing test rights_creds_payload.  It also refactors a bit f28532a0f3,
pushing two identical calls out of TEST_PROTO ifdef.

Reviwed by:		markj
Differential Revision:	https://reviews.freebsd.org/D43724
2024-02-08 09:00:41 -08:00
Gleb Smirnoff 45eae45d91 tests/unix_passfd: fix typos - assignment instead of comparison
This typos were actually hiding a kernel bug, see 541e6a989c.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D43734
2024-02-08 09:00:37 -08:00
Alan Somers 55b80e2ca5 fusefs: fix invalid value for st_birthtime.tv_nsec
If a file system's on-disk format does not support st_birthtime, it
isn't clear what value it should return in stat(2).  Neither our man
page nor the OpenGroup specifies.  But our convention for UFS and
msdosfs is to return { .tv_sec = -1, .tv_nsec = 0 }.  fusefs is
different.  It returns { .tv_sec = -1, .tv_nsec = -1 }.  It's done that
ever since the initial import in SVN r241519.

Most software apparently handles this just fine.  It must, because we've
had no complaints.  But the Rust standard library will panic when
reading such a timestamp during std::fs::metadata, even if the caller
doesn't care about that particular value.  That's a separate bug, and
should be fixed.

Change our invalid value to match msdosfs and ufs, pacifying the Rust
standard library.

PR:		276602
MFC after:	1 week
Sponsored by:	Axcient
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D43590
2024-02-04 14:01:06 -07:00
Gleb Smirnoff 70f5c6e34f tests/netinet: push variable 'sin' into function scope
This should fix build with GCC 13.

Fixes:	861274c9f8
2024-02-02 21:09:02 -08:00
Kristof Provost b8ef285f6c pf: ensure dummynet gets the correct direction after route-to
If we apply a route-to to an inbound packet pf_route() may hand that
packet over to dummynet. Dummynet may then delay the packet, and later
re-inject it. This re-injection (in dummynet_send()) needs to know
if the packet was inbound or outbound, to call the correct path for
continued processing.

That's done based on the pf_pdesc we pass along (through
pf_dummynet_route() and pf_pdesc_to_dnflow()). In the case of pf_route()
on inbound packets that may be wrong, because we're called in the input
path, and didn't update pf_pdesc->dir.

This can manifest in issues with fragmented packets. For example, a
fragmented packet will be re-fragmented in pf_route(), and if dummynet
makes different decisions for some of the fragments (that is, it delays
some and allows others to pass through directly) this will break.

The packets that pass through dummynet without delay will be transmitted
correctly (through the ifp->if_output() call in pf_route()), but
the delayed packets will be re-injected in the input path (and not
the output path, as they should be). These packets will pass through
pf_test(PF_IN) as they're tagged PF_MTAG_FLAG_DUMMYNET. However,
this tag is then removed and the packet will be routed and enter
pf_test(PF_OUT) where pf_reassemble() will hold them indefinitely
(as some fragments have been transmitted directly, and will never hit
pf_test(PF_OUT)).

The fix is simple: we must update pf_pfdesc->dir to PF_OUT before we
pass the packet to dummynet.

See also:	https://redmine.pfsense.org/issues/15156
Reviewed by:	rcm
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-02-02 17:55:16 +01:00
Gleb Smirnoff 861274c9f8 tests/netinet: add a demo of TCP implied connect
The TCP implied connect is an artifact left after T/TCP.  To my surprise
it still works, hence the existence of this test.  Please read this email
first:

https://lists.freebsd.org/pipermail/freebsd-net/2010-August/026311.html

An interesting fact that this test takes 220 - 240 milliseconds to
execute on my Threadripper PRO.  Flipping the '#if 0' to '#if 1' in the
test, thus bringing it back to normal connect(2), would speed the test up
a hundred times and I guess all this time is fork+exec of the test.
2024-02-01 13:43:36 -08:00
Gleb Smirnoff 702c481847 socket tests: improve error message 2024-02-01 13:37:26 -08:00
Kristof Provost 31828075e4 pf: bind route-to states to their route-to interface
When we route-to the state should be bound to the route-to interface,
not the default route interface. However, we should only do so for
outbound traffic, because inbound traffic should bind on the arriving
interface, not the one we eventually transmit on.

Explicitly check for this in BOUND_IFACE().

We must also extend pf_find_state(), because subsequent packets within
the established state will attempt to match the original interface, not
the route-to interface.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43589
2024-01-29 14:10:26 +01:00
Mark Johnston 001c48b413 netinet tests: Make test jail names unique
Otherwise we get spurious test failures when running tests in parallel.
The intent here was to name jails after the tests, but this was done
incorrectly in a couple of places.

MFC after:	1 week
2024-01-27 13:51:37 -05:00
Mark Johnston 3f73fbb0ac netinet6 tests: Restore an atf_check invocation
This one has been commented out since the initial commit, but doesn't
appear to pose any problems.

MFC after:	1 week
2024-01-27 13:51:14 -05:00
Mark Johnston f546326595 kqueue tests: Add a regression test
Based on the test case submitted by Andreas Bock for PR 275286.

PR:		275286
MFC after:	2 weeks
2024-01-27 13:51:13 -05:00
Jamie Gritton ab0841bdbe jail: expose children.max and children.cur via sysctl
Submitted by:	Igor Ostapenko <igor.ostapenko_pm.me>
Differential Revision:	<https://reviews.freebsd.org/D43565>
2024-01-26 09:45:40 -08:00
Gleb Smirnoff b32d49cfba tests: fix typo in a comment 2024-01-25 22:19:59 -08:00
Kristof Provost 63a5fe8343 pflow: limit to no more than 128 flow exporters
While there are no inherent limits to the number of exporters we're
likely to scale rather badly to very large numbers. There's also no
obvious use case for more than a handful. Limit to 128 exporters to
prevent foot-shooting.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-22 18:02:10 +01:00
Kristof Provost 484e977f24 pflow: observation domain is an unsigned integer
Ensure we print it as such, rather than as a signed integer, as that
would lead to confusion.

Reported by:	Jim Pingle <jimp@netgate.com>
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-22 18:02:10 +01:00
Kristof Provost 57c50d6b36 pf tests: test ICMP6 packet too big with binat
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43500
2024-01-22 13:49:56 +01:00
Alan Somers 39f5d8dd1b fusefs: fix some memory leaks in the tests
MFC after:	2 weeks
2024-01-19 10:44:32 -07:00
Alan Somers 8bae22bbbe fusefs: prefer new/delete over malloc/free
MFC after:	2 weeks
Reviewed by:	kib
Differential Revision: https://reviews.freebsd.org/D43464
2024-01-17 15:49:41 -07:00
Kristof Provost d086b9f77c pf tests: test per-rule pflow
Test that we can enable pflow on a per-rule basis.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-16 09:45:55 +01:00
Kristof Provost c4d97a9487 pf tests: test pflow NAT state information
pflow(4) now also exports NAT session creation/destruction information.
Test that this works as expected.

While here improve the parsing of ipfix (i.e. pflowproto 10) a bit, and
check more information for the existing state information exports.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43117
2024-01-16 09:45:55 +01:00
Kristof Provost 34276498fa pf tests: verify pflow over IPv6
Test that we can send netflow information over IPv6.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43115
2024-01-16 09:45:55 +01:00
Kristof Provost 85b71dcfc9 pflow: allow observation domain to be configured
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43113
2024-01-16 09:45:54 +01:00
Kristof Provost 6bd36d1cf4 pf tests: pflow functionality test
Test that we actually send netflow messages when configured to do so.
We do not yet inspect the generated netflow messages.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43111
2024-01-16 09:45:54 +01:00
Kristof Provost fb0c74685f pf tests: initial pflow test case
Basic creation, validation and cleanup test for the new pflow interface.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D43109
2024-01-16 09:45:54 +01:00
Kyle Evans 30189156d3 kern: pts: do not special case closed slave side
This would previously return 1 if the slave side of the pts was closed
to force an application to read() from it and observe the EOF, but it's
not clear why and this is inconsistent both with how we handle devices
with similar mechanics (like pipes) and also with other kernels, such as
OpenBSD/NetBSD and Linux.

PR:             239604
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D43457
2024-01-15 20:55:59 -06:00
Alan Somers daf26f9350 fusefs: more consistent operand ordering in io.cc
MFC after:	2 weeks
2024-01-15 16:16:40 -07:00
Alan Somers 1c909c300b fusefs: fix an interaction between copy_file_range and mmap
If a copy_file_range operation tries to read from a page that was
previously written via mmap, that page must be flushed first.

MFC after:	2 weeks
Reviewed by:	kib
Differential Revision: https://reviews.freebsd.org/D43451
2024-01-15 14:57:15 -07:00
Kristof Provost 3f9a6e0b85 pf tests: dummynet + nat fragmentation test
Ensure that we do the right thing when we reassemble fragmented packet
and send it through a dummynet pipe.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-15 14:02:02 +01:00
Kristof Provost 24c0058a9b pf tests: test reassembly with dummynet
Ensure that if we pass packets through a dummynet pipe we still
reassemble as expected.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-15 14:02:02 +01:00
Alan Somers 6b1c534927 Add a regression test for PR 276191.
The bug isn't fusefs-specific, but this is the easiest way to reproduce
it.

PR:		276191
MFC after:	1 week
MFC with:	bdb46c21a3
Differential Revision:  https://reviews.freebsd.org/D43446
Reviewed by: 	kib
2024-01-13 15:47:16 -07:00
Gleb Smirnoff e007b89e9d tests: add a test for shutdown(2) on a datagram socket 2024-01-12 02:04:04 -08:00
Gleb Smirnoff 26caf57e0b tests/netlink: improve recently added netlink_socket:membership
Change sequence of syscalls: instead of "add, delete, check, check"
run sequence "add, check, delete, check".  Seems to make more sense.

Do minimal parsing of incoming messages: find the IPv4 address there
and compare it to the original.
2024-01-10 20:51:53 -08:00
Gleb Smirnoff effa0f6c0a tests/netlink: mark a test that requires tun(4) 2024-01-10 20:51:53 -08: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
Gleb Smirnoff 8338ea1d3c tests/netlink: add minimal test for a group writer
Subscribe a socket for RTNLGRP_IPV4_ROUTE announcements, add & delete
a route and check that announcements came in.
2024-01-09 16:56:51 -08:00
Brooks Davis 8e2c2992da socket_msg_trunc: allocate a large enough buffer
Allocate 9000 bytes to match the largest requsted size.  Add a check to
prevent the list of sizes and buffer size from getting out of sync
again.

Reviewed by:	markj
Found with:	CheriBSD
Differential Revision:	https://reviews.freebsd.org/D43340
2024-01-09 22:59:29 +00:00
Kristof Provost 32df0124f4 pf tests: ensure that pflog shows malformed packets as blocked, not passed
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-01-04 23:08:08 +01:00
Brooks Davis a9174861ea posixshm largepage_mmap: fix a racy test
You can't ever safely map a single page and then map a superpage sized
mapping over it with MAP_FIXED.  Even in a single-threaded program, ASLR
might mean you land too close to another mapping and on CheriBSD we
don't allow the initial reservation to grow because doing so requires
program changes that are hard to automate.

To avoid this, map the entire region we want to use upfront.

Reviewed by:	markj
Obtained from:	CheriBSD
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D43282
2024-01-03 16:39:53 +00:00
Gleb Smirnoff 17083b94a9 netlink: use protocol specific receive buffer
Implement Netlink socket receive buffer as a simple TAILQ of nl_buf's,
same part of struct sockbuf that is used for send buffer already.
This shaves a lot of code and a lot of extra processing.  The pcb rids
of the I/O queues as the socket buffer is exactly the queue.  The
message writer is simplified a lot, as we now always deal with linear
buf.  Notion of different buffer types goes away as way as different
kinds of writers.  The only things remaining are: a socket writer and
a group writer.
The impact on the network stack is that we no longer use mbufs, so
a workaround from d187154750 disappears.

Note on message throttling.  Now the taskqueue throttling mechanism
needs to look at both socket buffers protected by their respective
locks and on flags in the pcb that are protected by the pcb lock.
There is definitely some room for optimization, but this changes tries
to preserve as much as possible.

Note on new nl_soreceive().  It emulates soreceive_generic().  It
must undergo further optimization, see large comment put in there.

Note on tests/sys/netlink/test_netlink_message_writer.py. This test
boiled down almost to nothing with mbufs removed.  However, I left
it with minimal functionality (it basically checks that allocating N
bytes we get N bytes) as it is one of not so many examples of ktest
framework that allows to test KPIs with python.

Note on Linux support. It got much simplier: Netlink message writer
loses notion of Linux support lifetime, it is same regardless of
process ABI.  On socket write from Linux process we perform
conversion immediately in nl_receive_message() and on an output
conversion to Linux happens in in nl_send_one(). XXX: both
conversions use M_NOWAIT allocation, which used to be the case
before this change, too.

Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D42524
2024-01-02 13:04:01 -08:00
Gleb Smirnoff 0ad011ecec tests/netlink: add netlink socket buffer test
With upcoming protocol specific socket buffer for Netlink we need some
additional tests that cover basic socket operations, w/o much of actual
Netlink knowledge.  Following tests are performed:

1) Overflow.  If an application keeps sending messages to the kernel,
but doesn't read out the replies, then first the receive buffer shall
fill and after that further messages from applications will be queued
on the send buffer until it is filled.  After that socket operations
should block.  However, reading from the receive buffer some data should
wake up the taskqueue and the send buffer should start draining again.

2) Peek & trunc.  Check that socket correctly reports amount of readable
data with MSG_PEEK & MSG_TRUNC.  This is typical pattern of Netlink apps.

3) Sizes. Check that zero size read doesn't affect the socket, undersize
read will return one truncated message and the message is removed from
the buffer.  Check that large buffer will be filled in one read, without
any boundaries imposed by internal representation of the buffer.  Check
that any meaningful read is amended with control data if requested so.

Reviewed by:		melifaro
Differential Revision:	https://reviews.freebsd.org/D42525
2024-01-02 13:03:49 -08:00
Mark Johnston 8b57b2a98b frag6 tests: Serialize
I'm not sure exactly why, but these tests consistently fail when run in
parallel.  Serialize them for now.

MFC after:	1 week
2023-12-31 11:22:45 -05:00
Vincenzo Maffione ee5804da11 netmap: fix unit tests
After ad874544d9, interface name
validation has been removed, resulting in two unit tests failures.
Drop the failing tests since they no longer apply.

Reported by:	markj
2023-12-29 07:46:46 +00:00
Dimitry Andric dc0b4094ab Silence VLA extension warnings in fusefs tests
Building tests/sys/fs/fusefs with clang 18 results the following
warning:

  tests/sys/fs/fusefs/cache.cc:145:14: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension]
    145 |         uint8_t buf[bufsize];
        |                     ^~~~~~~

Because we do not particularly care that this is a clang extension,
suppress the warning.

MFC after:	3 days
2023-12-21 23:45:52 +01: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
Kristof Provost c2e0b604a3 netinet tests: test that we send IGMP join/leave packets as expected
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-12-19 17:47:41 +01:00
Richard Scheffenegger 31cf66d755 dummynet: add simple gilbert-elliott channel model
Have a simple Gilbert-Elliott channel model in
dummynet to mimick correlated loss behavior of
realistic environments. This allows simpler testing
of burst-loss environments.

Reviewed By:           tuexen, kp, pauamma_gundo.com, #manpages
Sponsored by:          NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D42980
2023-12-17 13:20:45 +01:00
Kristof Provost 8fab83d2c5 pf tests: fix typos in the abort_v6 test case head / cleanup function name
MFC after:	1 week
2023-12-14 10:23:41 +01:00
Kristof Provost 4c84c69ba3 pf tests: test that we validate sequence numbers on TCP RST
MFC after:	3 days
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-12-05 21:03:49 +01:00
Jose Luis Duran 5b36076d28 zfs tests: Silence clang warning
"assigning to 'pattern_t *' from 'const pattern_t *' discards qualifiers"

Reviewed by:	asomers
Reported by:	clang
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42791
2023-12-04 12:22:14 -05:00
Gleb Smirnoff cfb1e92912 sockets: don't malloc/free sockaddr memory on accept(2)
Let the accept functions provide stack memory for protocols to fill it in.
Generic code should provide sockaddr_storage, specialized code may provide
smaller structure.

While rewriting accept(2) make 'addrlen' a true in/out parameter, reporting
required length in case if provided length was insufficient.  Our manual
page accept(2) and POSIX don't explicitly require that, but one can read
the text as they do.  Linux also does that. Update tests accordingly.

Reviewed by:		rscheff, tuexen, zlei, dchagin
Differential Revision:	https://reviews.freebsd.org/D42635
2023-11-30 08:30:55 -08:00
Alan Somers d565784a7e zfsd: fault disks that generate too many I/O delay events
If ZFS reports that a disk had at least 8 I/O operations over 60s that
were each delayed by at least 30s (implying a queue depth > 4 or I/O
aggregation, obviously), fault that disk.  Disks that respond this
slowly can degrade the entire system's performance.

MFC after:	2 weeks
Sponsored by:	Axcient
Reviewed by:	delphij
Differential Revision: https://reviews.freebsd.org/D42825
2023-11-29 07:51:11 -07:00
Jose Luis Duran 1db64f8936
netlink: Add tests when adding an interface route
Add tests for adding a route using an interface only (without an IP
address).

Reviewed by:	rcm
Approved by:	kp (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D41436
2023-11-28 16:53:00 -05:00
Gleb Smirnoff d2de66a90d ng_socket: with getsockname() return node ID for unnamed node
Reviewed by:		afedorov
Differential Revision:	https://reviews.freebsd.org/D42691
2023-11-27 20:11:38 -08:00
Gleb Smirnoff 4064a1108b netgraph: increase size of sockaddr_ng to match maximum node name
The ng_socket(4) node already writes more than declared size of the
struct at least in the in ng_getsockaddr().  Make size match size of
a node name.  The value is pasted instead of including ng_message.h
into ng_socket.h.  This is external API and we want to keep it stable
even if NG_NODESIZ is redefined in a kernel build.

Reviewed by:		afedorov
Differential Revision:	https://reviews.freebsd.org/D42690
2023-11-27 20:10:52 -08:00
Warner Losh 8b923102f9 Revert "cdefs: Remove __func__ define"
This reverts commit 17a238a15f. There were
too many other changes accidentally mixed in.

Sponsored by:		Netflix
2023-11-27 14:59:54 -07:00
Gleb Smirnoff 96950419f1 tests: don't run atf_* in a subshell
Shell limitation is that a classic function call via $() is a subshell
and atf-sh(3) commands won't work as epxected there.  Subsequently,
atf_skip inside a function won't skip a test.  The test will fail later.

A working approach is to pass desired variable name as argument to
a function and don't run subshell.

Reviewed by:		ngie
Differential Revision:	https://reviews.freebsd.org/D42646
Fixes:			ea82362219
2023-11-27 13:15:59 -08:00
Kristof Provost 1d723c1e56 pf tests: test recursive printing of labels
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-11-27 21:37:33 +01:00
Warner Losh 17a238a15f cdefs: Remove __func__ define
We require an ANSI-C compiler to build the base system. It's required
that __func__ work. Remove this define since the only known problem
compilers are ancient history (gcc 2.6 from 1994, almost pre-dating the
project). 3rd party code that used this define will now need to provide
it via some other means when using non-ansi-c compilers.

PR: 275221 (exp-run)
Sponsored by:		Netflix
2023-11-26 22:24:02 -07:00
Warner Losh b88ca6ee16 cdefs: Remove CC_SUPPORTS macros, they are unused
Remove __CC_SUPPORTS_INLINE, __CC_SUPPORTS___INLINE__,
__CC_SUPPORTS___FUNC__, __CC_SUPPORTS_WARNING,
__CC_SUPPORTS_VARADIC_XXX, __CC_SUPPORTS_DYNAMIC_ARRAY_INIT: they are
unused. Also remove them from the generated cryptodevh.py script.

Retain, for the moment, __CC_SUPPORTS___INLINE, since it's used in this
file.

PR: 275221 (exp-run)
Sponsored by:		Netflix
2023-11-26 22:24:02 -07:00
Warner Losh a83d4fe9cb cdefs: Remove some builtin defines, they are unused
Remove __GNUCLIKE_BUILTIN_NEXT_ARG, __GNUCLIKE_MATH_BUILTIN_RELOPS,
__GNUCLIKE_BUILTIN_MEMCPY: they are unused. Also remove them from the
generated cryptodevh.py script.

PR: 275221 (exp-run)
Sponsored by:		Netflix
2023-11-26 22:24:02 -07:00
Warner Losh 9e55552208 cdefs: Remove vararg related defines, they are unused.
Remove __GNUCLIKE_BUILTIN_VARARGS, __GNUCLIKE_BUILTIN_STDARG,
__GNUCLIKE_BUILTIN_VAALIST, __GNUC_VA_LIST_COMPATIBILITY: they are
unused. Also remove them from the generated cryptodevh.py script.

PR: 275221 (exp-run)
Sponsored by:		Netflix
2023-11-26 22:24:02 -07:00
Warner Losh eaaa7ca0c3 cdefs: Remove __GNUCLIKE_BUILTIN_CONSTANT_P, it's unused
__GNUCLIKE_BUILTIN_CONSTANT_P is unused, remove it. Also remove it from
the generated cryptodevh.py script.

PR: 275221 (exp-run)
Sponsored by:		Netflix
2023-11-26 22:24:02 -07:00
Warner Losh d2ec42ca57 cdefs: Remove __GNUCLIKE_CTOR_SECTION_HANDLING, it's unused
__GNUCLIKE_CTOR_SECTION_HANDLING is unused, remove it. Also remove it
from the generated cryptodevh.py script.

PR: 275221 (exp-run)
Sponsored by:		Netflix
2023-11-26 22:24:02 -07:00
Warner Losh 45aa39f884 cdefs: Remove __GNUCLIKE___SECTION, it's unused.
__GNUCLIKE___SECTION is unused, remove it. Also remove it from the
generated cryptodevh.py script.

PR: 275221 (exp-run)
Sponsored by:		Netflix
2023-11-26 22:24:01 -07: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
Warner Losh ac00d4d59b tests: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:30 -07:00
Dag-Erling Smørgrav c56f45f2a9 bitstring: Support large bit strings.
Replace int with either size_t or ssize_t (depending on context) in
order to support bit strings up to SSIZE_MAX bits in length.  Since
some of the arguments that need to change type are pointers, we must
resort to light preprocessor trickery to avoid breaking existing code.

MFC after:	3 weeks
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D42698
2023-11-22 23:30:03 +01:00
Gleb Smirnoff 367e8adb4b tests/netgraph: start ng_socket test suite
Just one check now, check node name.
2023-11-20 14:36:58 -08:00
Igor Ostapenko b453e3f755 pf tests: fix name and description of divert-to cases
Reflect the correct order of events for dummynet+ipdivert.
2023-11-20 12:30:18 +01:00
Warner Losh cc02e98a95 cdefs: Remove __GNUCLIKE_ASM
It's no longer used in the tree.

Exp Run PR:		275123
Sponsored by:		Netflix
2023-11-19 19:36:46 -07:00