Commit graph

1833 commits

Author SHA1 Message Date
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