The module declaration is necessary for 'kldstat -m' to see it,
and the rc(8) uses that to detect presence of ipfw_nat.
NB: the module(9) KPI lacks a way to declare a module without
providing an empty handler and no SYSINITs.
Reported by: ambrisko
Fixes: 9bcc1e97dd
A typical caching proxy problem is port allocation to backends. We
usually have a few of them, with thousands connections to each. Upon
creation of a new connection we need to find a new unique local port for
the peer:port. This is achieved by linear search in in_pcb_lport_dest().
The closer we get to the port exhaustion the more expensive this loop is.
It needs to be executed tens thousands of times to find a port or fail.
Address the problem by adding advisory negative cache that is lazily
allocated upon first conflict. Once the cache is in action we skip trying
those ports that are already marked in the cache. During the search we
may encounter a cache allocated by other lookup. In this case the caches
are merged into one. The expectation is that under a stable heavy load we
are going to stabilize at a very low number of allocated caches, ideally
one per peer:port. The cache is a bitset of IPPORT_MAX, which makes it 8k.
Unfortunately metadata pushes allocation size to 16k UMA bucket. However,
the expectation is that we are going to have a very few allocated, thus
current decision is to not create a separate UMA zone.
Differential Revision: https://reviews.freebsd.org/D58290
The state expiration may lead to freeing rules, which requires this lock.
Since the lock is sleepable, move the expiry routine from callout context
to a taskqueue. This also should have a positive effect of not running
expensive function as a callout.
Fixes: e3caa360d5
Reviewed by: pouria
Differential Revision: https://reviews.freebsd.org/D60869
Rename tcp_sndbuf_autoscale() to tcp_autosndbuf(). This matches
complementary tcp_autorcvbuf() that was factored out as a separate
function a few months before tcp_sndbuf_autoscale() was. Move the large
comment to the header of the function. Use unsigned types for all sizing
sysctls and variables and use bool for the switching sysctl. Add a
comment above net.inet.tcp.sendbuf_auto_lowat (default to off) providing a
reference to its origins. Add DTrace probe tcp::send-autoresize,
complementary to the existing tcp::receive-autoresize.
Rack has its own function, just enable the DTrace probe there.
Reviewed by: tuexen
Differential Revision: https://reviews.freebsd.org/D60732
Run the entire function under the socket buffer lock. Make it responsible
to set the new limit or clear SB_AUTOSIZE in case of a failure. Use
unsigned type for newsize, that matches both the sb_hiwat type and min()
argument types. Make byte counter in the tcpcb unsigned, too. Make the
sizing tunables unsigned, and make the switching tunable a boolean. Don't
execute Dtrace probe in case of a failure. Simplify the Dtrace probe to
report only relevant information, the previous probe looked more like a
leftover from a debugging session.
Reviewed by: tuexen
Differential Revision: https://reviews.freebsd.org/D60731
This code was disabled for 8 years already. It used to produce very
predictable hash without a salt, and that made the dynamic state engine an
easy DoS attack vector. No chance we will ever use it again.
Leverage the fact that m_pullup() in an inline function in mbuf.h and let
compiler to do all optimizations.
Mostly mechanical changes, but in few cases surrounding lines are brought
to style(9). In netinet6, a few input functions changed to set the
input/output `struct mbuf **` pointer to NULL at a single place.
Reviewed by: pouria, zlei, gallatin
Differential Revision: https://reviews.freebsd.org/D60689
Implement a most typical use of m_pullup() as an inline and leave only the
heavy part as a function. A sweeping change to make benefit of the new
version follows.
Reviewed by: pouria, zlei, gallatin
Differential Revision: https://reviews.freebsd.org/D60688
The clear intent here is to do m_pullup() if we _don't_ have two bytes.
Before the fix: a) m_pullup() was always called and did nothing; b) if a
node was ever supplied with a fragmented but otherwise correct mbuf, then
it would not handle PROT_LCP as intended.
Noticed by: zlei
Reviewed by: zlei, eugen_grosbein.net
Differential Revision: https://reviews.freebsd.org/D60788
Fixes: 28903f396a
caddr_t is a typedef for a character pointer (char *) that originated in
Version 7 Unix, released by AT&T in 1979. It became obsolete in 1989,
when ANSI C introduced void *.
What's left:
* ioctl(9) KPI still uses caddr_t, thus network related ioctl method
still use it.
* if_clone KPI, to be done separately.
* bpf(4), to be done separately.
* SCTP, let maintainers decide.
* iflib(4), let maintainers decide.
Reviewed by: zlei
Differential Revision: https://reviews.freebsd.org/D60738
caddr_t is a typedef for a character pointer (char *) that originated in
Version 7 Unix, released by AT&T in 1979. It became obsolete in 1989,
when ANSI C introduced void *.
There is a lot of code that uses m->m_data for arithmetics, thus we can't
switch it to void * easily. Let's at least stop proliferation of caddr_t.
We have developers that are twice younger than obsoletion of this type.
Reviewed by: zlei, tuexen, adrian
Differential Revision: https://reviews.freebsd.org/D60736
Make them all belong to SI_SUB_PROTO_FIREWALL and explicitly specify
order. Prefer SYSINIT() over modevent, for those subsystems that don't
have dependencies. All subsystems just depend on the main module and they
don't depend on each other, except dummynet which also has submodules.
Thus, keep DECLARE_MODULE() only for the main module and dummynet.
Differential Revision: https://reviews.freebsd.org/D60685
It was temporarily reduced in af78195e00 in 1994 to hide some bugs with
signed short overflow. We believe all these bugs were sorted out by
today. :)
Note that earlier ba582a82b0 reduced the MTU be rounded to a longword
with a reference "NFS likes it to be rounded". We have had several
refactors of the NFS code since that.
Reviewed by: pouria, zlei, tuexen
Differential Revision: https://reviews.freebsd.org/D59450
First, record the original lowat value and later in the wait/EAGAIN loop
look at the original value, rather than on the value that we just faked.
This eliminates some blank syscalls, where socket was reported as writable
and immediate write instantly fails. In my testing the ratio of such
syscalls was really small, under 2%, however in a different scenario this
negative effect can be more profound.
Second, cap the lowat growth to 1/2 of original socket buffer size, rather
than to current size. The problem was there before, but it became more
profound after 587c6c1215.
Note: we are considering to evaluate if the lowat hack is needed at all.
Reviewed by: tuexen
Differential Revision: https://reviews.freebsd.org/D60106
The check against V_tcp_sendspace is not a correct one, as a buffer may
grow larger than the initial value. The conjunction was always false up
until 587c6c1215, and only after it the bug surfaced.
If we already grow our buffer past the value stored in the hostcache,
prefer our value.
Reviewed by: tuexen
Differential Revision: https://reviews.freebsd.org/D60105
These are leftovers from last import from Luigi Rizzo in 2013, that were
never compiled checked since and lots of changes have had happened since
and more changes to come. Let's not pretend ipfw is buildable on
something else than FreeBSD nor it can be compiled for userland.
Reviewed by: lytboris_gmail.com
Differential Revision: https://reviews.freebsd.org/D59427
The 'void *ulp' is still in action, but where possible prefer a typed
pointer. Get rid of associated pre-processor macros.
Differential Revision: https://reviews.freebsd.org/D59435
In the prologue, where we check if the argument is a memory or an mbuf
chain, do not set 'struct ip *ip' pointer. However, set the 'struct
ether_header *eh' pointer there and set Etherner header length in 'ehlen'.
Side effect of this refactor is that now Layer 2 hooks may send mbufs with
ETHERTYPE_VLAN frames. However, current network stack doesn't do that.
Write a new PULLUP() macro that would take type of the argument to
determine how much to pull. Unlike PULLUP_TO() this macro can take typed
pointer. This will allow to get rid of 'void *ulp' and bunch of casting
macros in the next change. Use local bool variable to see if we need to
unlock upon jump to pullup_failed. Embed pointer update into the branch
of the macro, where pointers indeed need an update.
Use new PULLUP() macro to pullup initial 'struct ip *ip' and 'struct
ip6_hdr *ip6'. This removes max_protohdr sized pullup, that previously
tried to pull more than an unmapped mbuf could yield, fixing a bug covered
by the testcase sys/netpfil/ipfw/unmapped.
Reviewed by: gallatin
Differential Revision: https://reviews.freebsd.org/D59426
Rest of multicast related kernel structures live in in6?_var.h and this
piece of ip6?_var.h was anyway requiring in6?_var.h to be included before.
Differential Revision: https://reviews.freebsd.org/D55963
The code has been there since introduction of the TCP hostcache
in 97d8d152c2 in 2003, but was turned off.
Reviewed by: tuexen, cc
Differential Revision: https://reviews.freebsd.org/D59452
If a buffer ring experiences drops, then system is definitely starving in
CPU resources. Having an extra cache miss on a racy shared variable
increment doesn't help.
Reviewed by: gallatin
Differential Revision: https://reviews.freebsd.org/D59495
This is type agnostic locked callout initializer. The callout_init_mtx()
and etc remain for compatibility.
Reviewed by: kib, markj
Differential Revision: https://reviews.freebsd.org/D59456
Application may set sin_port to some value. Although this value is not
used by SOCK_RAW, it breaks a check that the address is available. A
perfect fix would be not use sockaddrs for ifaddrs, but that would be a
bigger change.
PR: 298366
Reviewed by: pouria, bnovkov, adrian
Differential Revision: https://reviews.freebsd.org/D59570
Fixes: 948ad32ae1
The syncache entry holds one TCPS_SYN_RECEIVED count that normally is
transferred to the the newborn tp. Upon failure syncache_socket() shall
not use TCPSTATES_INC/TCPSTATES_DEC (see 5050df3f4a why). But when
syncache_socket() fails in_pcbconnect(), it calls tcp_discardcb() to free
resources that were just allocated by tcp_newtcpcb() and this
tcp_discardcb() would do TCPSTATES_DEC(tp->t_state). The t_state is
TCPS_CLOSED at this point.
Make tcp_discardcb() symmetrical to tcp_newtcpcb() - not responsible for
the TCPSTATES. Make the caller responsible for state count book keeping.
Reviewed by: tuexen
Fixes: 3703e1a73e
Differential Revision: https://reviews.freebsd.org/D59325
Remove a note about "data of a different type". This was a bug that was
fixed in FreeBSD 15. Instead put an exact quote from SUS that lists
allowed cases of a short read with MSG_WAITALL. See discussion in D57511.
The initializer just needs working malloc(9) and two constants that
are set at hammer_time().
Fixes: 648fa3558c
Reviewed by: avg, markj
Differential Revision: https://reviews.freebsd.org/D58714
The entropy will be collected in intr_event_schedule_thread() for event
handlers that are marked as entropy sources. The quality of entropy
provided by SWI wasn't great anyway.
Reviewed by: cem, ngie
Differential Revision: https://reviews.freebsd.org/D58829
Since the kernel environment has its own dependencies, lurking at the end
of the SI_SUB_KMEM sequence appeared to be fragile. Provide own subsystem
for it. The init_dynamic_kenv() goes SI_ORDER_FIRST, and two modules that
depend on it go SI_ORDER_ANY.
PR: 297492
Reviewed by: imp, markj, emaste
Differential Revision: https://reviews.freebsd.org/D58836
This allows to parse ACPI tables and initialize VM domains before
SI_SUB_VM w/o a hack.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D58713
This allows to initialize mp_maxid, mp_ncpus and register APICs at the
most early stage, guaranteeing that those values will already be available
at SI_SUB_TUNABLES.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D58712
Working on cleansing use of (SI_SUB_FOO + 1) construct through the kernel
I found a repeating pattern. Often a developer adds a module that depends
on certain subsystem to be fully instantiated and they want to put their
module SYSINIT right at the end of the SI_SUB_FOO. Such module usually
expects that nothing else within this subsystem shall depend on the
module.
The problem with SI_ORDER_ANY which practically was "the last" until this
change is that it is used very widely and people treat it literally as
"any", well, because this is what the name says. This lead to many parts
that could have dependencies later to be added as SI_ORDER_ANY.
So, our developer with the new subsystem that depends on SI_SUB_FOO has
three options:
1) Use SI_ORDER_ANY, but grep around ther kernel for other SI_SUB_FOO
entries to make sure that no dependencies are set to SI_ORDER_ANY. And in
case they are, shift them up and recheck if dependencies of those
dependencies are met.
2) Take next subsystem in sysinit list. However, the next one can be
SI_SUB_BAR, that is completely irrelevant from SI_SUB_FOO, and our
developer doesn't want to put his module's SYSINIT into SI_SUB_BAR, cause
it is ugly.
3) Use the (SI_SUB_FOO + 1) construct that violates -Werror=assign-enum.
The SI_ORDER_LAST solves this hard choice. If you know that nothing is
going to depend on your module within SI_SUB_FOO, but you depend on
SI_SUB_FOO, just use SI_ORDER_LAST.
Reviewed by: markj, emaste
Differential Revision: https://reviews.freebsd.org/D58709
Initialize all three hashes (exact, wild, load balance group) with a per-
bucket lock. Nothing changes for the packet lookup KPI - it still uses
SMR section for thread safety. But connect(2) and bind(2) operations gain
parallelism now.
The main concept is that as we lookup inpcb database for editing, we are
accumulating bucket locks necessary to accomplish the operation. Once all
lookups are complete and we are good to go, the inpcb is inserted (or
moved) and accumulated lock context is released.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D58131
Add tests where first socket and second socket are bound to different
addresses, e.g. first specific and second wildcard and vice versa.
Mark success with SO_REUSEPORT on the second socket as a bug suspect.
Mark failure to bind to INADDR_ANY in presence of other UID's specific
bound socket to the same port as probably too strict.
Differential Revision: https://reviews.freebsd.org/D58088
Allows to add tests to the table where the second socket doesn't take
address from the first. No functional change yet, all tests test the same
conditions.
Differential Revision: https://reviews.freebsd.org/D58087
The test has 6 dimensions: address family, socket type, socket option on
the first socket, socket option on the second socket, is first socket
bound to specific address or wildcard and is the second socket priveleged
or not. Before the change 3 dimensions are implemented as 3 nested for()
loops, 2 dimensions are implemented as repetitions in the test body and
one dimension as two actions in the innermost loop.
I'm about to add one more dimension: whether the second socket is bound to
a specific address or wildcard instead of using first socket's
getsockopt(2) result. Also, there is a change under discussion that would
make SOCK_STREAM sockets behave different to SOCK_DGRAM. That would break
result consistency in the dimensions of socket type.
We expect that consistency in the dimension of address families shall
never break, thus this one remains a for() loop. The priveleged & non-
privileged bind(2) attempts also remain as two actions, but expected
results are in the table. The rest of dimensions are unrolled into a
table, which at the moment has quite a lot of lines with identical
results. However, as more tests are added and SOCK_STREAM behavior
changes, the table will get more mixed results. Also, reading a test that
is written in a declarative manner a table is much easier and modifying it
is more resistent to accidential breakage.
Differential Revision: https://reviews.freebsd.org/D58085
No functional change, as current callers either don't check the return
value or check it against OCS_HW_RTN_SUCCESS only.
Found with: clang -Werror=assign-enum
This should assist setups that connect a lot of nodes to ipfw: and then
distribute traffic with ipfw(4) tablearg feature.
Reviewed by: pouria
Differential Revision: https://reviews.freebsd.org/D58547
This removes just one level of #define mess that is needed to reach into
an inpcbs IPv4 address. And makes the declaration easier to read. No
functional change.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D58273
Since malloc(9) even with M_NOWAIT is forbidden when we hold a spinlock,
we can't print detailed lock tree as the operation tries to allocate
memory.
Fixes: fb4b0c9119
A mistake from 90ea8e89d9 is that in6_pcblookup_internal() was skipped
for an inpcb that had unspecified local address. This is incorrect, as
such inpcb could have already have a port set, and in_pcb_lport_dest()
shall not be called on such inpcb. That could lead to creation of an
alised connection in the database.
This makes the function almost identical to in_pcbconnect(). While here,
fix minor bug of missing INP_ANONPORT. This flag has no use in kernel,
but affects netstat(1) output in certain mode.
Fixes: 90ea8e89d9
Reviewed by: pouria
Differential Revision: https://reviews.freebsd.org/D57987
The historical design of sockets is that on a re-connect the disconnect is
performed at the socket layer in soconnectat(). Since SMP times this is
known to be racy and the function has appopriate comment. I missed that
in the recent change. The pr_connect method should normally expect the
socket to be already disconnected, however should be able to handle a race
where socket is actually connected. Convert the check that incorrectly
tried to handle normal path of re-connect into check that handles the
race.
Reported by: markj
Fixes: ece716c5d3
Just avoid repeating the test program name in every test case name.
No functional change.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D56727
- Test SOCK_DGRAM (UDP) sockets.
- Test binding to 0:port and to a addr:port in presence of connected socket
using the port.
Differential Revision: https://reviews.freebsd.org/D56707
There is no need to reference node in its constructor, the framework
already granted us a reference. This extraneous reference was later given
back on socket detach. However, if node is destroyed before the socket,
the node was leaked. This leak was harmless until VIMAGE, where
vnet_netgraph_uninit() would cycle through all nodes and shut them down
expecting them to not exist after the shutdown.
Fixes: 1928437497
- so_pcb can't be non-NULL in pr_attach.
- so_pcb can't be NULL in all other methods.
- Short circuit data socket attach down to the common attach.
- Short circuit both detach methods down to common one.
- Inline control socket attach.
- Inline control pr_bind.
- Inline data pr_connect.
- Rely on pr_connect_notsupp() for control connect(2).
- Don't use cast on so_pcb, it is void *.
Should be no functional change.
If the inpcb is already bound to a local address, there is no reason to
call in6_pcbladdr(). If the inpcb is already bound to a local port, there
is no reason to call in_pcb_lport_dest(). In the opposite case, if the
inpcb is not bound, and we are about to choose a non-conflicting local
addr:port, then there is no reason to call in6_pcblookup_internal().
This change makes in6_pcbconnect() to look much more alike the IPv4
in_pcbconnect(). I tracked this strange logic all the way down to initial
KAME import and failed to find any reasoning for it.
Reviewed by: pouria
Differential Revision: https://reviews.freebsd.org/D57534
This makes it possible to list unix(4) protocols in -P, which was not
possible before. Update the manual page and provide an example.
In 'struct sock' make member proto a pointer into the protocols table
instead of a number. This removes namespace collision that mixed
IPPROTO_TCP and etc with SOCK_STREAM and etc. There were no known bugs
due to this collision, though.
Preserve all current UI bugs for possible combinations of protocol
selection options. Should be no UI changes outside the improved -P.
Reviewed by: pouria, tuexen
Differential Revision: https://reviews.freebsd.org/D57508
This removes requirement for existence of obsolete IPPROTO_DIVERT in
<netinet/in.h> and the 'divert' entry in /etc/protocols.
Also, this avoids running through the nsdispatch(3) machinery on startup,
cutting down about 20 syscalls, three of which are open(2). The code of
sockstat(1) itself is also reduced.
The only UI change for a normal execution is that now the divert(4)
sockets are reported as "divert4" instead of "div4". The prefix "4"
itself is also incorrect, as divert(4) is not a part of IPv4. This will
be addressed in a separate change.
There is small UI change for incorrect runs. Previously protocols listed
in /etc/protocols, but not supported, would err out like this:
# sockstat -P ggp
sockstat: protocol 3 not supported
And non-existent protocols would err out like this:
# sockstat -P foo
sockstat: cap_getprotobyname: No error: 0 USER COMMAND
PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
Now both cases will consistently err:
sockstat: protocol foo not supported
Reviewed by: pouria, tuexen
Differential Revision: https://reviews.freebsd.org/D57507
The only possible way to exercise in_pcbrehash() is to bind(2) and then
connect(2). The second branch was a dead code since fdb987bebd.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D57241
This is a refactor of 228c632ab3. First, move compatibility one level
up, where we yet work with the full header. Second, move this rarely
executed code outside of the inline function. Should be no functional
change.
Reviewed by: pouria, melifaro
Differential Revision: https://reviews.freebsd.org/D56915
Understand zero size as instruction to not allocate the hash. Do not
allocate both hashes for rawip(4). There are no functional changes to TCP
or UDP.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D56705
The 'hash' subword doesn't bring any additional information. All inpcb
lookup functions operate on hashes.
For lookup functions that work on either exact hash or wild hash just
perform s/hash_//. Rename in_pcblookup_hash() into
in_pcblookup_with_lock(), emphasizing its difference to
in_pcblookup_smr(). Rename in_pcblookup_hash_locked() to
in_pcblookup_internal(), as it doesn't return a locked inpcb and is used
only for internal purposes. Note that the IPv6 sibling of this function
already lives by name in6_pcblookup_internal(). Some future changes will
make such naming more justified.
No functional change.
Reviewed by: pouria, markj
Differential Revision: https://reviews.freebsd.org/D56482
The RPC client is more of a class rather than an instance. RPCs from
different VNETs are served by the same client. This makes the kgss layer
fully transparent to VIMAGE and not even required to be aware of it.
It is responsibility of the rpcsec_gss module to have curvnet set on the
calling thread when doing RPC calls via kgssapi.
This change should enable proper operation of an NFS server with gssd(8)
in a VIMAGE jail.
PR: 294501
Reviewed by: rmacklem
Differential Revision: https://reviews.freebsd.org/D56562
These RPC methods correctly acquire the kgss_gssd_handle later with call
to kgss_gssd_client().
Reviewed by: rmacklem
Differential Revision: https://reviews.freebsd.org/D56561