Commit graph

2021 commits

Author SHA1 Message Date
Christos Margiolis
433e270f34 sound: Refactor the format conversion framework
Merge the PCM_READ|WRITE_* macros defined in pcm/pcm.h, as well as the
intpcm_read|write_* macros defined in pcm/feeder_format.c, into six
inline functions: pcm_sample_read|write[_norm|calc](). The absence of
macro magic makes the code significantly easier to read, use and modify.

Since these functions take the input/output format as a parameter, get
rid of the read() and write() function pointers defined in struct
feed_format_info, as well as the feeder_format_read|write_op()
functions, and use the new read/write functions directly.

Sponsored by:	The FreeBSD Fondation
MFC after:	1 week
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D47932
2025-03-10 21:19:15 +01:00
Gleb Smirnoff
c7f803c71d inpcb: fix a panic with SO_REUSEPORT_LB + connect(2) misuse
This combination doesn't make any sense.  This socket option makes sense
only on a socket that is going to be a listening one.  There are two
options here: refuse connect(2) on a socket that has the option set
previously, or ignore (and clear) the option.  After some discussion on
phabricator, we have chosen the former, for safety and consistency
reasons.  Any programmer that runs this sequence is doing something wrong
and should be informed of that with appropriate error code.

Since connect(2) is a SUS API that has a defined set of error codes, none
of which corresponds to "a socket has non-standard incompatible socket
option set", we decided to return the same error that an already listening
socket would return.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D49150
2025-03-06 22:57:44 -08:00
Zhenlei Huang
5d8b48487a tests/netlink: Assert the route scope of interface's addresses
While here, add one additional IPv4 link-local address to test_46_nofilter
to cover the IPv4 RT_SCOPE_LINK case.

Reviewed by:	melifaro, #network
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D49226
2025-03-07 12:14:44 +08:00
John Baldwin
ecb3a7d43d netmap: Disable a buggy and unsafe test (sync_kloop_conflict)
This test starts two threads to verify that two concurrent threads
cannot enter the kernel loop on the same netmap context.  The test
even has a comment about a potential race condition where the first
thread enters the loop and is stopped before the second thread tries
to enter the loop.  It claims it is fixed by the use of a semaphore.
Unfortunately, the semaphore doesn't close the race.

In the CI setup for CHERI, we run the testsuite once a week against
various architectures using single CPU QEMU instances.  Across
multiple recent runs of the plain "aarch64" test the job ran for an
entire day before QEMU was killed by a timeout.  The last messages
logged were from this test:

734.881045 [1182] generic_netmap_attach     Emulated adapter for tap3312 created (prev was NULL)
734.882340 [ 321] generic_netmap_register   Emulated adapter for tap3312 activated
734.882675 [2224] netmap_csb_validate       csb_init for kring tap3312 RX0: head 0, cur 0, hwcur 0, hwtail 0
734.883042 [2224] netmap_csb_validate       csb_init for kring tap3312 TX0: head 0, cur 0, hwcur 0, hwtail 1023
734.915397 [ 820] netmap_sync_kloop         kloop busy_wait 1, direct_tx 0, direct_rx 0, na_could_sleep 0
736.901945 [ 820] netmap_sync_kloop         kloop busy_wait 1, direct_tx 0, direct_rx 0, na_could_sleep 0

From the timestamps, the synchronous kloop was entered twice 2 seconds
apart.  This corresponds to the 2 second timeout on the semaphore in
the test.  What appears to have happened is that th1 started and
entered the kernel where it spun in an endless busy loop.  This
starves th2 so it _never_ runs.  Once the semaphore times out, th1 is
preempted to run the main thread which invokes the ioctl to stop the
busy loop.  th1 then exits the loop and returns to userland to exit.
Only after this point does th2 actually run and execute the ioctl to
enter the kernel.  Since th1 has already exited, th2 doesn't error and
enters its own happy spin loop.  The main thread hangs forever in
pthread_join, and the process is unkillable (the busy loop in the
kernel doesn't check for any pending signals so kill -9 is ignored and
ineffective).

I don't see a way to fix this test, so I've just disabled it.  There
is no good way to ensurce concurrency on a single CPU system when one
thread wants to sit in a spin loop.  Someone should fix the netmap
kloop to respond to kill -9 in which case kyua could perhaps at least
timeout the individual test process and kill it.

Reviewed by:	vmaffione
Obtained from:	CheriBSD
Sponsored by:	AFRL, DARPA
Differential Revision:	https://reviews.freebsd.org/D49220
2025-03-06 13:22:25 -05:00
Kristof Provost
6e7f24e0a5 pf: fix nat64 ICMP translation
Fix more incorrect use of the iih pointer, this time causing corruption in nat64
translated ICMP error messages.
Extend the relevant test case to catch this bug.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D49231
2025-03-05 10:37:57 +01:00
Kristof Provost
2f77491169 pf tests: test ICMP error translation with nat64
Ensure that when we translate an ICMPv4 to ICMPv6 message we set the correct
source IP address.

PR:		284944
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D49144
2025-03-05 10:37:57 +01:00
Kyle Evans
2bef0d54f7 kern: wg: remove overly-restrictive address family check
IPv4 packets can be routed via an IPv6 nexthop, so the handling of the
parsed address family is more strict than it needs to be.  If we have a
valid header that matches a known peer, then we have no reason to
decline the packet.

Convert it to an assertion that it matches the destination as viewed by
the stack below it, instead.  `dst` may be the gateway instead of the
destination in the case of a nexthop, so the `af` assignment must be
switched to use the destination in all cases.

Add a test case that approximates a setup like in the PR and
demonstrates the issue.

PR:		284857
Reviewed by:	markj (earlier version), zlei
Differential Revision:	https://reviews.freebsd.org/D49172
2025-03-04 13:57:34 -06:00
Kristof Provost
f32a255044 pf tests: test source-hash and random on empty table or interface without address
Attempt to provoke the crashes fixed by the previous commit.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-03-03 17:07:17 +01:00
Kristof Provost
f8bd05add2 pf tests: add missing pflog_init to pflog:rdr_action
Without it we tried to run the test even if pflog wasn't loaded.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-03-03 13:51:27 +01:00
Jose Luis Duran
c46af893cd
tests: Require python3 when using Scapy
python3 is a symbolic link that points to the current python 3.X
version.

It is possible for a system to have python (python 3.X) without the
python3 (symlink) package.

Test scripts that use Scapy are invoked using python3, so add it as a
required program.

Reviewed by:	ngie, asomers
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D49007
2025-03-03 07:52:33 +00:00
Kajetan Staszkiewicz
f6f116cdbd pf: Make af-to work on outbound interface
Currently af-to works only on inbound interface by creating a reversed
NAT state key which is used to match traffic returning on the outbound
interface.

Such limitation is not necessary. When an af-to state is created
for an outbound rule do not reverse the NAT state key, making it work
just like if it was created for a normal NAT rule. Depending on firewall
design it might be easier and more natural to use af-to on the outbound
interface.

Reviewed by:		kp
Approved by:		kp (mentor)
Sponsored by:		InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D49122
2025-02-27 16:28:27 +01:00
Kristof Provost
41265f65a5 pf: cope with IPv6 gateways for an IPv4 route in nat64
It's possible for an IPv4 next hop to be specified as an IPv6 address. This
broke pf's route lookup in pf_route(), which is required for nat64.

Handle this case just like ip_tryforward(): use the struct sockaddr from the
struct nhop_object, and mark a struct route to indicate if_output() has to use
the gateway.

Add a test case for this.

PR:		284946
Reviewed by:	zlei
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D49095
2025-02-25 09:32:34 +01:00
Kristof Provost
9bdb3272f7 pf tests: remove stray debug log line
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-25 09:32:33 +01:00
Mark Johnston
8b3d2c19d3 inpcb: Fix reuseport lbgroup array resizing
in_pcblisten() moves an inpcb from the per-group list into the array, at
which point it becomes visible to inpcb lookups in the datapath.  It
assumes that there is space in the array for this, but that's not
guaranteed, since in_pcbinslbgrouphash() doesn't reserve space in the
array if the inpcb isn't associated with a listening socket.

We could resize the array in in_pcblisten(), but that would introduce a
failure case where there currently is none.  Instead, keep track of the
number of pending inpcbs as well, and modify in_pcbinslbgrouphash() to
reserve space for each pending (i.e., not-yet-listening) inpcb.

Add a regression test.

Reviewed by:	glebius
Reported by:	netchild
Fixes:		7cbb6b6e28 ("inpcb: Close some SO_REUSEPORT_LB races, part 2")
Differential Revision:	https://reviews.freebsd.org/D49100
2025-02-23 16:20:12 +00:00
Zhenlei Huang
93fbdef51a tests: carp: Update test case unicast_v4 to catch PR 284872
In the current test case unicast_v4, host one acts as a router, but it
uses if_bridge(4) to verify the reachability to CARP master.
Unfortunately, if_bridge(4) brings the two CARP hosts into the same
broadcast domain, thus with an unusual (undocumented) setup, one host
is in unicast mode but another one in multicast, or two hosts are both
in multicast mode, the test case can falsely report success.

Fix that by propagating route via routed(8).

PR 284872 shows that CARP(4) happens to send packets with multicast
destination when the unicast peer address is in the range x.x.x.224 ~
x.x.x.239. Update the peer address in test case to catch that bug.

PR:		284872
Reviewed by:	kp
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D49076
2025-02-23 03:26:32 +08:00
Gleb Smirnoff
ad77d3177f tests/netinet: add few tests for sending a broadcast packet
1) Set SO_BROADCAST and send to INADDR_BROADCAST.
2) Set SO_BROADCAST, set IP_ONESBCAST and cycle through broadcast capable
   interfaces sending a datagram on each.
3) Set SO_BROADCAST and send to local broadcast address.

For each test we bind a second socket to check whether the broadcast
is actually received.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D49040
2025-02-21 18:11:12 -08:00
Kristof Provost
921c9c7bcc pf tests: test new log(matches) behaviour
Ensure that a log(matches, to pflog1) sends all future matches to pflog1.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-21 09:11:03 +01:00
Kristof Provost
c2346c3d3a pf: support source-hash and random with tables and dynifs, not just pools
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@

Obtained from:	OpenBSD, reyk <reyk@openbsd.org>, 252a05523f
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-20 09:25:51 +01:00
Kristof Provost
86f2641b99 pf: fix icmp-in-icmp handling with if-bound states
When we receive an ICMP packet containing another ICMP packet we look up the
original ICMP state. This is done through a second struct pf_pdesc ('pd2'),
containing relevant information (i.e. addresses, type, id, ..).
pd2 did not contain the network interface ('kif'), leading to state lookup
failures. This only affected if-bound mode, because floating states match all
interfaces.

Set kif in pd2.

Extend the icmp.py:test_fragmentation_needed test case to use if-bound mode. It
already checked that we handled icmp-in-icmp correctly.

PR:		284866
MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-19 14:34:45 +01:00
Florian Walpen
6672831bda sound tests: Fix downshift calculation in pcm_read_write test
In some situations the feeders in the sound module lower the pcm sample
resolution through a downshift of the sample value. The pcm_read_write
test implements this operation with an arithmetic division to avoid
implementation defined or architecture specific behavior. Due to
different rounding, the test produced marginally different sample
values, which made the test fail on 32 bit architectures. Correct this.

Reported by:	CI
Fixes:		27ef5d48c7 ("sound: Unit test the pcm sample read and write macros")
MFC after:	1 week
Reviewed by:	christos, markj
Differential revision:	https://reviews.freebsd.org/D48926
2025-02-18 21:37:17 +02:00
Gleb Smirnoff
4f274f849b tests/netinet: add few tests for unconnected UDP socket
1) Test that getsockname() on a socket that experienced a sendto(2)
   returns allocated port.
2) Same as 1), but jailed.  Make sure IP address was also selected.
3) Test that IP_SENDSRCADDR/IP_RECVDSTADDR work.
4) Regression test for bug 274009.
2025-02-17 15:28:51 -08:00
Jose Luis Duran
1f1963bd32
pf tests: Remove Scapy as a required program
Scapy is not needed to run this test.  Remove it from the required
programs list.

Reviewed by:	kp
Approved by:	emaste (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D49006
2025-02-17 19:57:00 +00:00
Jose Luis Duran
ec60176e7d
netinet6 tests: Add Scapy as a required program
The ra.py script requires Scapy.  Invoke it using the python3 symlink.
While technically, at the moment, python points to python3, and python3
points to the current version of python, it is recommended to use
python3.  No functional change intended.

Add the Scapy requirement in the header of each test that makes use of
it.

Reviewed by:	kp
Approved by:	emaste (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D49005
2025-02-17 19:56:59 +00:00
Jose Luis Duran
cf4a4e4fab
pf tests: Add Scapy as a required program
The utils.subr file includes a couple of subroutines
(ping_dummy_check_request and ping_server_check_reply) that require
Scapy.

Add this requirement in the header of each test that makes use of them.

Reported by:	Jenkins
Reviewed by:	kp
Approved by:	emaste (mentor)
Fixes:	07e070ef08 ("pf: Add support for multiple source node types")
Differential Revision:	https://reviews.freebsd.org/D49004
2025-02-17 19:56:47 +00:00
Kristof Provost
26a7be91ad pf tests: basic 'any' interface test case
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-14 18:47:53 +01:00
Franco Fichtner
685fb42538 pf: Log the intended action when a NAT rule matches a packet
When a packet matches a binat/nat/rdr rule, pf logs the match.  The log
metadata includes the rule's action on the packet, e.g., PF_PASS.  NAT
rules have their own actions: PF_BINAT, PF_NAT, PF_RDR.

Before commit 948e8413ab ("pflog: pass the action to pflog directly"),
pflog_packet() would obtain the action from the rule definition, whereas
after that commit the action is passed as a parameter.  When a NAT rule
matches, we want to log the rule action, but after that commit, PF_PASS
is hard-coded.  Restore the previous behaviour.

Add a regression test which installs a redirect, logs packets matching
the redirect rule, and verifies that the corresponding pflog entry
includes the correct action.

Reviewed by:	kp
Fixes:		948e8413ab ("pflog: pass the action to pflog directly")
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	OPNsense
Differential Revision:	https://reviews.freebsd.org/D48911
2025-02-14 15:24:15 +00:00
Kajetan Staszkiewicz
07e070ef08 pf: Add support for multiple source node types
For every state pf creates up to two source nodes: a limiting one
struct pf_kstate -> src_node and a NAT one struct pf_kstate -> nat_src_node.
The limiting source node is tracking information needed for limits using
max-src-states and max-src-nodes and the NAT source node is tracking NAT
rules only.

On closer inspection some issues emerge:
- For route-to rules the redirection decision is stored in the limiting source
  node. Thus sticky-address and source limiting can't be used separately.
- Global source tracking, as promised in the man page, is totally absent from
  the code. Pfctl is capable of setting flags PFRULE_SRCTRACK (enable source
  tracking) and PFRULE_RULESRCTRACK (make source tracking per rule). The kernel
  code checks PFRULE_SRCTRACK but ignores PFRULE_RULESRCTRACK. That makes
  source tracking work per-rule only.

This patch is based on OpenBSD approach where source nodes have a type and each
state has an array of source node pointers indexed by source node type
instead of just two pointers. The conditions for limiting are applied
only to source nodes of PF_SN_LIMIT type. For global limit tracking
source nodes are attached to the default rule.

Reviewed by:		kp
Approved by:		kp (mentor)
Sponsored by:		InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D39880
2025-02-13 15:59:12 +01:00
Kristof Provost
26fb3871b7 pf tests: add basic ! received-on test case
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-13 13:38:45 +01:00
Kristof Provost
90ef7a0b23 pf tests: test 'quick' for match rules
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-13 13:38:43 +01:00
Kristof Provost
e736f6df1e pf tests: fix test skipping when pf is not loaded
Two test cases in table.sh didn't call pft_init and thus didn't skip if pf is
not loaded.
The fragmentation_pass:v6_route_to test had the test body in the cleanup
function, so got run even when pf was not loaded.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-12 20:38:39 +01:00
Kristof Provost
d11a19654a pf tests: verify that table counters work on match rules
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-12 20:38:39 +01:00
Jose Luis Duran
65cc5af1cf
sys tests: Add scapy as a required program
These atf-python tests rely on scapy to run.
Add it as a required program.

Reported by:	glebius, kp
Reviewed by:	kp
Approved by:	emaste (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D48946
2025-02-12 14:40:43 +00:00
Jose Luis Duran
50f18a9b26
netinet tests: Move import
Move the import of 'Sniffer', which depends on scapy into the test so we
don't try (and fail) to import it unless scapy is installed.

Reviewed by:	kp, emaste
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D48945
2025-02-12 14:38:09 +00:00
Kristof Provost
6c795ce1df pf tests: verify that a nested anchor does not clear the quick flag
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-12 09:29:09 +01:00
Gleb Smirnoff
1b2636e535 tests/unix_stream: fix signedness error
Fixes:	bc7ee0b52a
2025-02-11 11:07:41 -08:00
Jose Luis Duran
e295e0b8cf
tests: Add scapy as a required program
The utils.subr file includes a couple of subroutines
(ping_dummy_check_request and ping_server_check_reply) that require
scapy.

Add this requirement in the header of each test that makes use of them.

Reported by:	Jenkins
Reviewed by:	kp, ngie
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D48917
2025-02-11 16:59:51 +00:00
Kristof Provost
db100bd930 pf tests: add more fragmentation test cases
Add more test cases for pf fragment hole counter.  Also look into
final fragment of echo reply and check total length of IP packet.

MFC after:	1 week
Obtained from:	OpenBSD, bluhm <bluhm@openbsd.org>, 640736615b
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-11 11:32:22 +01:00
Gleb Smirnoff
bc7ee0b52a tests/unix_stream: add test that checks a full socket isn't writable 2025-02-10 14:01:16 -08:00
Mark Johnston
c2de0116c8 vmm tests: Check for /dev/vmmctl to decide if vmm is initialized
If vmm.ko is loaded but fails initialization, it doesn't get
automatically unloaded, so the tests will not skip themselves and will
instead fail outright.

MFC after:	1 week
2025-02-08 16:05:37 +00:00
Mark Johnston
400ce6248b fibs_multibind_test: Explicitly cast the checksum value
Otherwise gcc warns about the (intentionall) truncated value and raises
an error.

Fixes:	7034563f8e ("tests: Add some FIB multibind test cases")
2025-02-08 16:05:37 +00:00
Mark Johnston
7034563f8e tests: Add some FIB multibind test cases
Reviewed by:	glebius
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48665
2025-02-06 14:16:04 +00:00
Kristof Provost
0cd95355a5 pf tests: extend set-tos test
Verify that we can set-tos on pass rules, and that this still works even if a
'scrub' option is present on the pass rule.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-02-05 21:06:54 +01:00
Kristof Provost
fffedd81a4 pf: send ICMP destination unreachable fragmentation needed when appropriate
Just like we do for IPv6, generate an ICMP fragmentation needed packet if we're
going to need fragmenation for IPv4 as well (i.e. DF is set). Do so before full
processing, so we generate it with pre-NAT addreses, just as we do for IPv6.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D48805
2025-02-04 21:56:06 +01:00
Gleb Smirnoff
c2aa91745e netstat: restore printing the "default" keyword, provide -nn option
Avoid POLA breakage and preserve output standard that really predates
the FreeBSD project itself.  There are scripts in the wild that rely
on the behavior.

Provide option to specify -nn twice to have a completely numeric
output of the routing tables.

Fixes:	9206c79961
This reverts commit e090646d6f.

Reviewed by:		zlei, gallatin, melifaro, allanjude, markj, emaste
Differential Revision:	https://reviews.freebsd.org/D48729
2025-02-03 10:09:58 -08:00
Mark Johnston
63efd7f5ac socket tests: Add a test which calls listen() twice on an lb socket
This exercises commit 06bf119f26 ("sockets/tcp: quick fix for
regression with SO_REUSEPORT_LB")

Reviewed by:	glebius
MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48702
2025-01-28 14:22:20 +00:00
Kristof Provost
7a372bded8 pf: make reply-to work with nat64
Just like route-to reply-to is problematic when used in combination with nat64.

In the normal (i.e. without nat64) flow we return immediately from pf_route().
However, with nat64 we need to continue and do a route lookup. In that case
we should not make the extra pf_test(PF_OUT) call to remain similar to the
non-nat64 flow.

We also have to fix the interface binding. We can only bind to the interface
after we've done the route lookup, not before.

Add a funcional test case, and a test for pfctl's rule printing.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-01-24 11:20:31 +01:00
Kristof Provost
ca0e693453 pf: cope with route-to on af-to rules
af-to uses pf_route() and pf_route6(), which caused issues when af-to and
route-to were combined in a single rule.
Extend the relevant functions to cope with this and add test cases.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-01-24 11:20:30 +01:00
Kristof Provost
af33f86e6a carp: don't unintentionally revert to multicast mode
PR:		284140
MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2025-01-24 11:20:30 +01:00
Mark Johnston
2f8a6bb087 divert tests: Stop skipping ipdivert_ip6_output_remote_success
It passes after commit ce52baebd3 ("icmp6: Fix ICMP6 message type
counters").

PR:		279975
Sponsored by:	Klara, Inc.
2025-01-23 19:03:29 +00:00
Mark Johnston
7cbb6b6e28 inpcb: Close some SO_REUSEPORT_LB races, part 2
Suppose a thread is adds a socket to an existing TCP lbgroup that is
actively accepting connections.  It has to do the following operations:
1. set SO_REUSEPORT_LB on the socket
2. bind() the socket to the shared address/port
3. call listen()

Step 2 makes the inpcb visible to incoming connection requests.
However, at this point the inpcb cannot accept new connections.  If
in_pcblookup() matches it, the remote end will see ECONNREFUSED even
when other listening sockets are present in the lbgroup.  This means
that dynamically adding inpcbs to an lbgroup (e.g., by starting up new
workers) can trigger spurious connection failures for no good reason.
(A similar problem exists when removing inpcbs from an lbgroup, but that
is harder to fix and is not addressed by this patch; see the review for
a bit more commentary.)

Fix this by augmenting each lbgroup with a linked list of inpcbs that
are pending a listen() call.  When adding an inpcb to an lbgroup, keep
the inpcb on this list if listen() hasn't been called, so it is not yet
visible to the lookup path.  Then, add a new in_pcblisten() routine which
makes the inpcb visible within the lbgroup now that it's safe to let it
handle new connections.

Add a regression test which verifies that we don't get spurious
connection errors while adding sockets to an LB group.

Reviewed by:	glebius
MFC after:	1 month
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48544
2025-01-23 17:12:10 +00:00