OPNSense/src f48a139sys/netpfil/pf pf.c

pf: upstream test patch
DeltaFile
+8-2sys/netpfil/pf/pf.c
+8-21 files

OPNSense/src 327986bsys/netpfil/pf pf.c pf_ioctl.c

pf: do atomic load/store of timeout value
DeltaFile
+6-6sys/netpfil/pf/pf.c
+4-4sys/netpfil/pf/pf_ioctl.c
+1-1sys/netpfil/pf/if_pfsync.c
+11-113 files

OPNSense/src 0688f52sys/netpfil/pf pf.c

pf: add INVARIANTS visibility and use it to sidestep a panic

If this pans out we can still release the lock that we are supposed
to unlock here.  We do not know the reason why this happens yet,
but we avoid the risk of chasing a pointer which is no longer dependable.

Also add mutex owned and recursed state checks in the output and
avoid unlocking if we no longer own the lock.
DeltaFile
+38-4sys/netpfil/pf/pf.c
+38-41 files

OPNSense/src dc89a5dsys/netpfil/pf pf.c

pf: add INVARIANTS visibility and use it to sidestep a panic

If this pans out wer can still release the lock that we're supposed
to unlock here.  We do not know the reason and if the state is actually
still locked, but we avoid the risk of chasing a pointer which is no
longer dependable.

Also add mutex owned and recursed state checks in the output and
avoid unlocking if we no longer own the lock.
DeltaFile
+38-4sys/netpfil/pf/pf.c
+38-41 files

OPNSense/src 5145ef0sys/netpfil/pf pf.c

pf: add INVARIANTS visibility and use it to sidestep a panic

If this pans out wer can still release the lock that we're supposed
to unlock here.  We do not know the reason and if the state is actually
still locked, but we avoid the risk of chasing a pointer which is no
longer dependable.
DeltaFile
+24-4sys/netpfil/pf/pf.c
+24-41 files

OPNSense/src d61f5e3sys/netpfil/pf pf.c

Revert "pf: do a lock dance in pf_unlink_state()"

This reverts commit fd23892d390fe9c60cc1ae34e04153080d9e9e1b.

Issue appears to sit a bit deeper.
DeltaFile
+2-4sys/netpfil/pf/pf.c
+2-41 files

OPNSense/src fd23892sys/netpfil/pf pf.c

pf: do a lock dance in pf_unlink_state()

Both pf_test() and pf_test6() can end up in a panic while
executing PF_UNLOCK_STATE which points to the state being
removed while it is in use.

The PF_LOCK_STATE in the removal subroutine makes sure
that pf_test/pf_test6 are no longer holding the state
and we can safely test and set PFTM_UNLINK.

The other bits of the OpenBSD commit probably apply as well
but for now make sure that this particular panic comes to
and end.

Based on: https://github.com/openbsd/src/commit/9d9f4dc6c83
DeltaFile
+4-2sys/netpfil/pf/pf.c
+4-21 files

OPNSense/src 8bc2fd1sys/netinet in_pcb_var.h in_pcb.h

inpcb: Move the definition of struct inpcblbgroup to in_pcb_var.h

It's only needed for in_pcb.c and in6_pcb.c, so can go to the private
header.

No functional change intended.

Reported by:    glebius
MFC after:      2 weeks
Sponsored by:   Klara, Inc.
Sponsored by:   Stormshield

(cherry picked from commit ca94f92c23fd09b28ac3398657ae2ae9367bcdf5)
DeltaFile
+22-0sys/netinet/in_pcb_var.h
+0-22sys/netinet/in_pcb.h
+22-222 files

OPNSense/src f8f116asys/netinet in_pcb.c in_pcb.h, sys/netinet6 in6_pcb.c in6_pcb.h

inpcb: Add FIB-aware inpcb lookup

Allow protocol layers to look up an inpcb belonging to a particular FIB.
This is indicated by setting INPLOOKUP_FIB; if it is set, the FIB to be
used is obtained from the specificed mbuf or ifnet.

No functional change intended.

Reviewed by:    glebius, melifaro
MFC after:      2 weeks
Sponsored by:   Klara, Inc.
Sponsored by:   Stormshield
Differential Revision:  https://reviews.freebsd.org/D48662

(cherry picked from commit da806e8db685eead02bc67888b16ebac6badb6b6)
DeltaFile
+42-32sys/netinet/in_pcb.c
+42-29sys/netinet6/in6_pcb.c
+2-1sys/netinet/in_pcb.h
+1-1sys/netinet6/in6_pcb.h
+87-634 files

OPNSense/src b37c9c8sys/netinet in_pcb.c tcp_usrreq.c, sys/netinet6 in6_pcb.c udp6_usrreq.c

inpcb: Add a flags parameter to in_pcbbind()

Add a flag, INPBIND_FIB, which means that the inpcb is local to its FIB
number.  When this flag is specified, duplicate bindings are permitted,
so long as each FIB contains at most one inpcb bound to the same
address/port.  If an inpcb is bound with this flag, it'll have the
INP_BOUNDFIB flag set.

No functional change intended.

Reviewed by:    glebius
MFC after:      2 weeks
Sponsored by:   Klara, Inc.
Sponsored by:   Stormshield
Differential Revision:  https://reviews.freebsd.org/D48661

(cherry picked from commit bbd0084baf7539c7042ce94f8c6770210f83f765)
DeltaFile
+25-12sys/netinet/in_pcb.c
+13-5sys/netinet6/in6_pcb.c
+5-5sys/netinet/tcp_usrreq.c
+5-4sys/netinet/in_pcb.h
+2-2sys/netinet/udp_usrreq.c
+2-2sys/netinet6/udp6_usrreq.c
+52-301 files not shown
+53-317 files

OPNSense/src 992d19dsys/netinet in_pcb.c in_pcb_var.h, sys/netinet6 in6_pcb.c in6_pcb.h

inpcb: Imbue in(6)_pcblookup_local() with a FIB parameter

This is to enable a mode where duplicate inpcb bindings are permitted,
and we want to look up an inpcb with a particular FIB.  Thus, add a
"fib" parameter to in_pcblookup() and related functions, and plumb it
through.

A fib value of RT_ALL_FIBS indicates that the lookup should ignore FIB
numbers when searching.  Otherwise, it should refer to a valid FIB
number, and the returned inpcb should belong to the specific FIB.  For
now, just add the fib parameter where needed, as there are several
layers to plumb through.

No functional change intended.

Reviewed by:    glebius
MFC after:      2 weeks
Sponsored by:   Klara, Inc.
Sponsored by:   Stormshield

    [3 lines not shown]
DeltaFile
+16-7sys/netinet/in_pcb.c
+13-7sys/netinet6/in6_pcb.c
+2-2sys/netinet/in_pcb_var.h
+1-1sys/netinet6/in6_pcb.h
+32-174 files

OPNSense/src 3b13309sys/netinet6 in6_pcb.h in6_pcb.c

inpcb: Constify address parameters to in6 pcb lookup routines

No functional change intended.

MFC after:      1 week
Sponsored by:   Klara, Inc.
Sponsored by:   Stormshield

(cherry picked from commit 52ef944b0f6f1df8eebe1cb877c6aadb1c247da0)
DeltaFile
+8-14sys/netinet6/in6_pcb.h
+8-8sys/netinet6/in6_pcb.c
+16-222 files

OPNSense/src 580dfe1sys/netinet6 in6.h in6.c

in6: Constify some sockaddr conversion functions

No functional change intended.

MFC after:      1 week
Sponsored by:   Klara, Inc.
Sponsored by:   Stormshield

(cherry picked from commit 3bb15ffc4ab4bfcd4c1bd700a64b3b5ed95389c3)
DeltaFile
+3-3sys/netinet6/in6.h
+2-2sys/netinet6/in6.c
+5-52 files

OPNSense/src a718536sys/netinet in_pcb.c, sys/netinet6 in6_pcb.c

inpcb: Further restrict binding to a port owned by a different UID

See commit 4f02a7d739b3 for more background.

I cannot see a good reason to continue ignoring mismatching UIDs when
binding to INADDR_ANY.  Looking at the sdr.V2.4a7n sources (mentioned in
bugzilla PR 7713), there is a CANT_MCAST_BIND hack wherein the
application binds to INADDR_ANY instead of a multicast address, but
CANT_MCAST_BIND isn't defined for FreeBSD builds.

It seems unlikely that we still have a use-case for allowing sockets
from different UIDs to bind to the same port when binding to the
unspecified address.  And, as noted in D47832, applications like sdr
would have been broken by the inverted SO_REUSEPORT check removed in
that revision, apparently without any bug reports.  Let's break
compatibility and simply disallow this case outright.

Also, add some comments, remove a hack in a regression test which tests
this funtionality, and add a new regression test to exercise the

    [8 lines not shown]
DeltaFile
+76-10tests/sys/netinet/socket_afinet.c
+9-2sys/netinet/in_pcb.c
+9-2sys/netinet6/in6_pcb.c
+94-143 files

OPNSense/src 707000fsys/netinet in_pcb.c, sys/netinet6 in6_pcb.c

inpcb: Close some SO_REUSEPORT_LB races

For a long time, the inpcb lookup path has been lockless in the common
case: we use net_epoch to synchronize lookups.  However, the routines
which update lbgroups were not careful to synchronize with unlocked
lookups.  I believe that in the worst case this can result in spurious
connection aborts (I have a regression test case to exercise this), but
it's hard to be certain.

Modify in_pcblbgroup* routines to synchronize with unlocked lookup:
- When removing inpcbs from an lbgroup, do not shrink the array.
  The maximum number of lbgroup entries is INPCBLBGROUP_SIZMAX (256),
  and it doesn't seem worth the complexity to shrink the array when a
  socket is removed.
- When resizing an lbgroup, do not insert it into the hash table until
  it is fully initialized; otherwise lookups may observe a partially
  constructed lbgroup.
- When adding an inpcb to the group, increment the counter after adding
  the array entry, using a release store.  Otherwise it's possible for

    [10 lines not shown]
DeltaFile
+52-42sys/netinet/in_pcb.c
+11-2sys/netinet6/in6_pcb.c
+63-442 files

OPNSense/src 74986b4sys/netinet in_pcb.c, sys/netinet6 in6_pcb.c

inpcb: Remove bogus SO_REUSEPORT(_LB) checks in in_pcbbind()

This check for SO_REUSEPORT was added way back in commit 52b65dbe85faf.
Per the commit log, this commit restricted this port-stealing check to
unicast addresses, and then only if the existing socket does not have
SO_REUSEPORT set.  In other words, if there exists a socket bound to
INADDR_ANY, and we bind a socket to INADDR_ANY with the same port, then
the two sockets need not be owned by the same user if the existing
socket has SO_REUSEPORT set.

This is a surprising semantic; bugzilla PR 7713 gives some additional
context.  That PR makes a case for the behaviour described above when
binding to a multicast address.  But, the SO_REUSEPORT check is only
applied when binding to a non-multicast address, so it doesn't really
make sense.  In the PR the committer notes that "unicast applications
don't set SO_REUSEPORT", which makes some sense, but also refers to
"multicast applications that bind to INADDR_ANY", which sounds a bit
suspicious.


    [27 lines not shown]
DeltaFile
+239-1tests/sys/netinet/socket_afinet.c
+1-3sys/netinet6/in6_pcb.c
+1-3sys/netinet/in_pcb.c
+241-73 files

OPNSense/src 619cb9csys/netinet in_pcb.c, sys/netinet6 in6_pcb.c

inpcb: Fix the GENERIC-NODEBUG build

Fixes:  01f8ce83242d ("inpcb: Factor out parts of in6_pcbbind() and in_pcbbind_setup()")
(cherry picked from commit ffb3d384fc1d550a764def2c0cd034ac3a4f0b86)
DeltaFile
+1-2sys/netinet/in_pcb.c
+1-2sys/netinet6/in6_pcb.c
+2-42 files

OPNSense/src 4388cf9sys/netinet in_pcb.c, sys/netinet6 in6_pcb.c

inpcb: Factor out parts of in6_pcbbind() and in_pcbbind_setup()

A large portion of these functions just determines whether the inpcb can
bind to the address/port.  This portion has no side effects, so is a
good candidate to move into its own helper function.  This patch does
so, making the callers less complicated and reducing indentation.

While moving this code, also make some changes:
- Load socket options (SO_REUSEADDR etc.) only once.  There is nothing
  preventing another thread from toggling the socket options, so make
  this function easier to reason about by avoiding races.
- When checking whether the bind address is an interface address, make a
  separate sockaddr rather than temporarily modifying the one passed to
  in_pcbbind().

Reviewed by:    ae, glebius
MFC after:      1 month
Sponsored by:   Klara, Inc.
Sponsored by:   Stormshield

    [3 lines not shown]
DeltaFile
+145-117sys/netinet6/in6_pcb.c
+97-75sys/netinet/in_pcb.c
+242-1922 files

OPNSense/src ee086b1sys/netinet in_pcb.c

inpcb: Use NULL for VNET_SYSINIT's last arg, which is a pointer type

MFC after:      3 days

(cherry picked from commit ec6e7677a0dbfbcdb4b740b28a1105256f1fc93e)
DeltaFile
+1-1sys/netinet/in_pcb.c
+1-11 files

OPNSense/src 93844e2sys/netinet in_pcb.c, sys/netinet6 in6_pcb.c

inpcb: Make some cosmetic improvements to in_pcbbind()

- Use the local var "laddr" instead of sin->sin_addr in one block.
- Use in_nullhost() instead of explicit comparisons with INADDR_ANY.
- Combine multiple socket options checks into one.
- Fix indentation.
- Remove some unhelpful comments.

This is in preparation for some simplification and bug-fixing.

No functional change intended.

Reviewed by:    glebius
MFC after:      2 weeks
Sponsored by:   Klara, Inc.
Sponsored by:   Stormshield
Differential Revision:  https://reviews.freebsd.org/D47451

(cherry picked from commit 45a77bf23fa2f36bf2169f7ba2a33b31f4c35adb)
DeltaFile
+20-24sys/netinet/in_pcb.c
+8-11sys/netinet6/in6_pcb.c
+28-352 files

OPNSense/src 7e198d2sys/netinet in_pcb.c, sys/netinet6 in6_pcb.c

inpcb: Remove some unused parameters in internal hash lookup functions

in_pcblookup_hash_wild_* looks up unconnected inpcbs, so there is no
point in passing the foreign address and port, and indeed those
parameters are not used.  So, remove them.

No functional change intended.

MFC after:      1 week
Sponsored by:   Klara, Inc.
Sponsored by:   Stormshield
Differential Revision:  https://reviews.freebsd.org/D47385

(cherry picked from commit 21d7ac8c79a34cf3b7205d0c32014ee39f1f28ab)
DeltaFile
+8-9sys/netinet/in_pcb.c
+6-8sys/netinet6/in6_pcb.c
+14-172 files

OPNSense/src 42b3611sys/netinet in.c

netinet: Update a comment for in_localip()

The function in_localip() was changed to return bool but the comment was
left unchanged.

Fixes:  c8ee75f2315e Use network epoch to protect local IPv4 addresses hash
MFC after:      3 days

(cherry picked from commit a5e380e51cdba64a392846a4eeda000f948f42ce)
DeltaFile
+1-1sys/netinet/in.c
+1-11 files

OPNSense/src 2eeb556sys/net if_lagg.c

lagg: Use static initializers

MFC after:      1 week

(cherry picked from commit 36ebdd0155d07fc53375fb212d9ca80158dde350)
DeltaFile
+2-2sys/net/if_lagg.c
+2-21 files

OPNSense/src 3e10fbcsys/contrib/dev/iwlwifi/mvm tx.c

iwlwifi: adjust a debug comment referring to a PR

A FreeBSD specific comment asked people to report to a PR if they see
this.  By now we got enough feedback and also left this in a release.
Simply point to the PR so people can check the status but not longer
ask to submit a report to the PR.

Sponsored by:   The FreeBSD Foundation
PR:             274382

(cherry picked from commit 4a4eee553307a2e02c6ed4796d575bfce2857049)
DeltaFile
+2-2sys/contrib/dev/iwlwifi/mvm/tx.c
+2-21 files

OPNSense/src 2d3b2eelib/libifconfig libifconfig_sfp.c

ifconfig: fix reporting optics on most 100g interfaces

This fixes a bug where optics on 100G and faster NICs
were not properly reported.

(cherry picked from commit 709348c21351a783ff0025519d1f7cf884771077)
DeltaFile
+1-0lib/libifconfig/libifconfig_sfp.c
+1-01 files

OPNSense/src 8fd42f3sys/netinet6 in6_cksum.c in6.h

ip6_cksum.c: generalize in6_cksum_partial() to allow L2 headers in passed mbuf

(cherry picked from commit fcf81de12f27d34a5c18168fd0c756c371a62076)
DeltaFile
+17-8sys/netinet6/in6_cksum.c
+2-0sys/netinet6/in6.h
+19-82 files

OPNSense/src f13a5e0sys/netinet6 nd6.c

inet6: add the missing lock acquire to nd6_get_llentry

Reported by:    Lexi Winter
PR:             282378
Sponsored by:   Rubicon Communications, LLC ("Netgate")

(cherry picked from commit d6138a65405f697715189363b2b18581e7abd982)
DeltaFile
+1-0sys/netinet6/nd6.c
+1-01 files

OPNSense/src 82710e0sys/net if.c

ifnet: fix the teardown process of an interface

Taken from: https://reviews.freebsd.org/D49359
DeltaFile
+29-2sys/net/if.c
+29-21 files

OPNSense/src ba418a9sys/net vnet.c

vnet: Use static initializers

MFC after:      1 week

(cherry picked from commit 23f453ae34c29b99f892da18db44ce4292ccb7c3)
DeltaFile
+1-2sys/net/vnet.c
+1-21 files

OPNSense/src f944a04sys/netinet tcp_ratelimit.c

tcp_ratelimit: Use static initializers

MFC after:      1 week

(cherry picked from commit 09de37310313d87942fc5349914be46b9cb8c808)
DeltaFile
+3-6sys/netinet/tcp_ratelimit.c
+3-61 files