if_geneve: Fix nexthop reference imbalance on output
geneve_encap4() and geneve_encap6() look up the nexthop of the outer
packet without a reference and pass it to ip_output() or ip6_output()
in a route on the stack. When the output routine drops the nexthop of
that route, because a pfil hook asked for a new lookup or the nexthop
is no longer valid, it releases a reference that was never taken. It
then stores a referenced nexthop in the route, which the caller never
releases.
Set RT_NH_NOREF on these routes, so that ip_output() and ip6_output()
neither release nor reference a nexthop for them.
Reviewed by: pouria, zlei
Fixes: e44d2e941e8e ("if_geneve: Add Support for Geneve...")
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D61952
if_vxlan: Fix nexthop reference imbalance on output
When the inner frame asks for checksum offload or TSO, vxlan_encap4()
and vxlan_encap6() look up the nexthop of the outer packet without a
reference, to check the capabilities of the outgoing interface, and
pass it to ip_output() or ip6_output() in a route on the stack. When
the output routine drops the nexthop of that route, because a pfil
hook asked for a new lookup or the nexthop is no longer valid, it
releases a reference that was never taken. It then stores a
referenced nexthop in the route, which the caller never releases.
Set RT_NH_NOREF on these routes, so that ip_output() and ip6_output()
neither release nor reference a nexthop for them.
Reviewed by: pouria, zlei
Fixes: b092fd6c973d ("if_vxlan(4): add support for...")
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D61958
ip_forward: Do not reference the nexthop
ip_forward() looked the route up with NHR_REF and released the nexthop
on every exit. The function runs in the network epoch, and nexthops are
destroyed through NET_EPOCH_CALL(), so the nexthop stays valid until
ip_forward() returns without a reference, as ip_tryforward() already
relies on. The reference costs two atomic operations per packet on a
counter that every CPU forwarding to that nexthop shares.
Look the nexthop up without NHR_REF, and set RT_NH_NOREF on the
on-stack route, so that ip_output() neither releases that nexthop nor
references one it looks up itself.
On a four-core router that encrypts what it forwards into one ESP
tunnel, this takes 60-byte packets from 913 to 970 kpps, and the CPU
time for packets dropped by a blackhole route goes down by 18 %.
No functional change intended.
[4 lines not shown]
routing: Add RT_NH_NOREF for routes that do not reference the nexthop
A route that is used within one network epoch section does not need a
reference on its nexthop: nexthops are destroyed through
NET_EPOCH_CALL(), so a nexthop looked up in the section stays valid
until the section ends. ip_output() and ip6_output() have no way to
know that a route is used like this. When they drop the nexthop of the
route they are given, because it is no longer valid or a pfil hook
asked for a new lookup, they release it, and they store a referenced
nexthop in its place.
Add a route flag, RT_NH_NOREF, which the owner of a route sets to say
that the nexthop of the route is not to be referenced. The flag is set
before the route is first used and is never cleared. RO_NHFREE() and
RO_INVALIDATE_CACHE() drop the nexthop of such a route without
releasing it. ip_output(), and cache_route(), which looks up the
nexthop for ip6_output(), look up a new one without NHR_REF.
The flag must not be set on a route that outlives the epoch section it
[7 lines not shown]
bsdconfig: finish wlanconfig SSID join and wpa_supplicant(5) editing
Complete the wireless network menu, which since its 2013 introduction
stopped just short of usefulness: it could scan the airwaves and list
networks configured in wpa_supplicant.conf(5), but selecting a scanned
network did nothing, the configuration editor displayed values it could
not change, and nothing was ever written back to disk. All three
XXXDT-unfinished paths are now implemented.
Selecting an unmarked ([ ]) entry joins that network. The security
type is derived from the wpa_cli(8) scan_results flags (PSK, SAE, EAP,
WEP, or open) and the user is prompted accordingly: passphrases and
keys through an obscured password box with validation (8-63 character
passphrase or 64-digit hex pre-shared key; 5/13 character ASCII or
10/26 digit hex WEP key), EAP through identity and password prompts.
The resulting network block is appended to wpa_supplicant.conf(5) with
priority=5 and wpa_supplicant(8) is reloaded via wpa_cli(8)
reconfigure, so the join both takes effect immediately and survives a
reboot. Manually Connect, which previously dead-ended in the editor
[44 lines not shown]
nd6: Do not make SLAAC addresses usable with ifdisabled
Setting TENTATIVE was what made these addresses unusable, because
TENTATIVE is part of IN6_IFF_NOTREADY.
keep setting TENTATIVE in nd6_timer() and nd6_ioctl() to not making
them usable.
Reported by: llm-postcr
Fixes: c7cd7e7fad57 ("nd6: Add support for Optimistic DAD (RFC 4429)")
Differential Revision: https://reviews.freebsd.org/D55229
rtnetlink: Fix IFA_F_PERMANENT and IFA_F_DADFAILED flags
in6_flags_to_nl() sets IFA_F_PERMANENT/IFA_F_DADFAILED flags on
the function argument, not nl_flags, so netlink never reports them.
Reported by: llm-postcr
Fixes: 30d0fc6f3391 ("netlink: export more IPv6 ifa info")
MFC after: 3 days
dnode_sync: Relax constraint on indirect freeing
One of the roles of the dnode sync thread is freeing. There are two
modes of this operation: freeing a portion of an object, and freeing
the object itself.
Freeing is handled by `free_children()`. This function verifies that
if the dnode has children there must be at least one marked as dirty
before proceeding to recursively free the tree of block pointers.
As described in a comment, this VERIFY is overly strict. In practice,
children may not be marked as dirty when the dnode itself is being
freed. Relax the VERIFY slightly by avoiding the VERIFY when indirect
blocks are to be immediately freed, to more closely match the comment
motivating the VERIFY.
While here, clarify the logic of the test by using VERIFY_IMPLY instead
of chaining multiple tests.
[9 lines not shown]
libsysdecode: Avoid non-portable \> word end boundary in mktables
Whilst we bootstrap our own sed when building on non-FreeBSD, it uses
the system regex(3) implementation, and so inherits its extensions, not
our own. Our implementation and glibc's both include this extension to
POSIX, but macOS's does not, and so even with our bootstrap sed we
cannot use the \> extension when built and run on macOS.
Unfortunately, there is no alternative form we can use; whilst macOS
implements [[:>:]] as an extension that provides this same feature, and
so do we, the regex(3) implementation in glibc does not, and the only
alternative glibc offers is \b, which neither us nor macOS implement.
We could make the form used conditional on the OS, but that starts to
get messy once other Linux libcs enter the picture, which in theory we
somewhat support.
Rewrite both uses to avoid the need for \>. For gen_table, use a pattern
to match the identifier that is precisely the (non-extended) C99
[27 lines not shown]
sound: Unlock the channel when chn_reset() fails in dsp_chn_alloc()
If chn_reset() fails, dsp_chn_alloc() returns with the channel lock
held, dsp_open() calls dsp_close() as part of its cdevpriv error path,
and this causes both a mutex recursion on the channel lock in
dsp_close(), as well a lock order reversal.
Approved by: re (cperciva)
Fixes: 02d4eeabfd73 ("sound: Allocate vchans on-demand")
Reported by: llm-postcr
MFC after: Immediately
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D61793
(cherry picked from commit 01a8cd5ebe9368fd115fb5060bcb1e60d1bbdf1f)
(cherry picked from commit 55b89b7b529f1c37a749adadb11aba4f8e9e51ca)
snd_dummy: Do not use dummy_chan_io() as mpu401's interrupt handler
dummy_chan_io() runs with sc->lock held, but mpu401 calls its handler
from a callout with no mutex associated with it, so writing to the MIDI
device node caused a panic.
Give mpu401 its own handler, and leave MIDI to mpu401's timer instead of
the PCM callout.
Approved by: re (cperciva)
Fixes: e963472ef853 ("snd_dummy: Initial MIDI support")
Sponsored by: The FreeBSD Foundation
(cherry picked from commit c8d1c94741231d95964b91910880769019478854)
(cherry picked from commit 5541489df676c9723cac2d665bb4e6705cc3ce53)
snd_uaudio: Fix the MIDI TX round-robin
Nothing advances curr_cable, so umidi_bulk_write_callback() only
services cable 0, which is a problem on MIDI devices with more than one
jack.
Approved by: re (cperciva)
Fixes: 039477d3e7e7 ("snd_uaudio: Simplify chan->curr_cable calculation in uaudio_bulk_write_callback()")
Sponsored by: The FreeBSD Foundation
MFC after: 1 day
(cherry picked from commit f58613868b50dfd6c2adc7128ea60d7b276fdbf1)
(cherry picked from commit 6f80968093eccb5f9de1cfffd5a45c2163b605b4)
snd_uaudio: Do not touch mixer_lock when there is no mixer
Using the mixer lock unconditionally panics because the lock is
uninitialized on devices with no audio interfaces, for instance
MIDI-only keyboards.
Approved by: re (cperciva)
Fixes: 9a00e0b8ca56 ("snd_uaudio: Do not use snd_mixer->lock as mixer_lock")
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D61506
(cherry picked from commit dabd959b17597ad790327020a667ced9a05d7499)
(cherry picked from commit 682a7750f6c07bc367e573fc9fdfa90eb8e5bf9f)
sysrc: Add "unchanged" messages
When a value would not change, emit a message indicating such. This
aligns with sysconf which does the same thing.
While here, add missing loop hygiene; unset loop variables after loop
to avoid potential later misuse.
Reviewed by: kfv
Differential Revision: https://reviews.freebsd.org/D61742
sysrc: Support special characters in file names
Previously, passing -f "abc'123" (for example) would break sysrc.
Support special characters such as single-quote, double-quote,
dollar sign, backtick, asterisk, and more.
It was previously impossible to handle file names with glob
characters. If you absolutely need to use a glob to expand a list
of potential files for `-f' you can still do it in two ways:
sysrc -f "$( echo glob )" ...
RC_CONFS=$( echo glob ) sysrc ...
While here, clean up trailing whitespace on 3 lines.
Reviewed by: kfv
Differential Revision: https://reviews.freebsd.org/D61740
sysrc: Accept values that contain a newline
awk -v rejects a newline in the value, and the old writer treated that
failure as an empty edit. The temporary file then held only the new
assignment, so the rest of the configuration was lost.
Pass the value in the environment and replace the last assignment by
joining that line through end of file. A quoted newline stays with the
value, and the text after it stays after the closer. If awk exits
above 1, leave the file alone. sh -n still refuses a value that would
break the quotes.
PR: 283729
MFC after: 2 weeks
Reviewed by: kfv
Differential Revision: https://reviews.freebsd.org/D61743
sysrc: Send -c output to stderr instead of stdout
This aligns with sysconf's `-c' while also adding a default output of
`value differs' (suppressed with `-q').
While here, replace f_err with warn() where appropriate.
Reviewed by: kfv
Differential Revision: https://reviews.freebsd.org/D61741
sysrc: Change -l/-L to list files one per-line
This makes -l and -L consistent with sysconf target -l/-L such that:
sysconf rc -l # or -L (in turn calls sysrc -l or -L)
sysconf lo -l # or -L (lo valid short-hand for loader)
similarly produce one file per-line. This is instead of the former
behavior where sysrc -l/-L (and thus sysconf rc -l/-L) produced one
long line with each path separated my a single space.
Reviewed by: kfv
Differential Revision: https://reviews.freebsd.org/D61739
sysrc: Fix -e output
The sysrc(8) man-page states that `-e' is used to "print query results
as sh(1) compatible syntax".
Flags such as `-v' when combined with `-e' could make the output
incompatible with sh(1).
This is a breaking change that should not be MFC'd because it both
alters certain output formats and also fixes a bug that others may
have relied upon. When changing value of an existing variable, the
`-e' output would produce syntax that would revert the change:
$name="$before" # -> $after
This change improves the output of `-e' to:
_$name="$before" $name="$after"
[29 lines not shown]
sysrc: Add more sanity checks
Potentially a breaking change for some folks. MFC discouraged.
This aligns sysrc with the same sanity checks performed by sysconf.
It reduces the chance of POLA violations when people use `sysconf rc'
(where sysrc is hooked into sysconf as the rc target provider).
However, some shell scripts calling out to sysrc may have relied on
some of the leniency that is now cause for exit. For example, using
`-x' with assignments (such as `sysrc -x foo=bar' which now generates
the error `-x does not take a value' -- the same error produced when
you try `sysconf loader -x foo=bar').
Reviewed by: kfv
Differential Revision: https://reviews.freebsd.org/D61735