Commit Graph
5869 Commits
Author SHA1 Message Date
Yu Watanabe 30b14a0886 dhcp: use struct iovec_wrapper to manage user class 2026-05-12 20:06:28 +09:00
Yu Watanabe 431ec1b145 dhcp: use TLV object to manage extra and vendor options
Note, previously we replaced the previous option with the same option code with
new one. But, DHCP message can have multiple options with same option code.
Hence, this make the conf parser not replace, but append new one.
2026-05-12 20:06:28 +09:00
Zbigniew Jędrzejewski-Szmek 62a489fbf9 tree-wide: rename unref_and_replace_full to unref_and_replace_new_ref
We have a number of *_unref_and_replace macros. One could think that
they are like the various free_and_replace variants, but they actually
create a new ref to the passed object. The free_and_replace variants
take ownership of the argument. This inconsistency is surprising. Rename
all those functions to have "_new_ref" at the end to make the difference
clear.
2026-05-08 11:14:13 +02:00
Zbigniew Jędrzejewski-Szmek f6363a0b1d Another batch of conversions to option and verb macros (#41881) 2026-05-06 12:39:36 +02:00
Diego Viola 5d17215c7e treewide: fix typos in the entire codebase
Signed-off-by: Diego Viola <diego.viola@gmail.com>
2026-05-05 17:22:26 +02:00
Zbigniew Jędrzejewski-Szmek 203409bb9f networkctl: use proper errno in mesage
$ build/networkctl --lines=4883284838483883838383
Failed to parse --lines setting '4883284838483883838383': Numerical result out of range
2026-05-05 13:49:52 +02:00
Zbigniew Jędrzejewski-Szmek c97084d5b0 networkctl: convert to OPTION and VERB macros
--help output is identical except for common options strings and
whitespace.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-05 13:49:52 +02:00
Zbigniew Jędrzejewski-Szmek d5301b635f networkd-wait-online: convert to OPTION macros
Also fix a latent bug in parse_interface_with_operstate_range() where
the global 'optarg' was used instead of the 'str' parameter when
extracting the interface name; with getopt removed they would have
diverged.

The help strings are adjusted a bit to be grammatical and short so
that the table formatting is easier.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-05 13:49:51 +02:00
Zbigniew Jędrzejewski-Szmek 4ce94c3bb4 test-modem-manager-mock: convert to OPTION macros
--help and --version are moved to the beginning of the option list.
This is the usual location. Custom '-v' alias for --version is dropped.
It is not used by anything and it's better to follow the usual style.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-05 13:49:51 +02:00
Lennart Poettering 99ce7a0770 options: get rid of "on_error" parameter to FOREACH_OPTION
I am really not a fan of full code lines passed to macros as parameters.
Let's get rid of the 3rd parameter of FOREACH_OPTION() hence:

1. Let's return errors just as a regular value (though a negative one),
   that can be handled via a OPTION_ERROR case statement for the switch.
   This normalizes handling of the error, just like any other event
   returned by the option parser.

2. In order to avoid exploding the amount of boilerplate in each use
   (that just propagates the error on OPTION_ERROR), let's then
   introduce an explicit FOREACH_OPTION_OR_RETURN(), that returns from
   the calling function on its own (and makes that clear in the name).

Together this cleans up, normalizes the logic and shortens the code.
2026-04-30 11:12:33 +01:00
Zbigniew Jędrzejewski-Szmek 5ff0ccaf8b tree-wide: change option_parse() to return option and arg via internal state
It was requested to make the 'c', 'opt', and 'arg' params the same, i.e.
defined through the FOREACH_OPTION macro. But we can't do that easily,
because 'c' was defined in the for loop definition, and we can only
define variables of the same type in that way. Also, in some cases we
need only 'c', in other cases with need 'c' and 'arg, in some cases 'c'
and 'opt', and in other cases all three. We'd need to either
conditionalize or mark those variables with _unused_ to deal with
compiler warnings. But a different approach works quite nicely: add
state.opt and state.arg to show the current option and it's argument.
(The short names are picked on purpose to reduce verbosity since those
are used a lot.)
2026-04-27 11:33:10 +02:00
Yu Watanabe bb5b2f9e5a sd-dhcp-client: simplify the implementation of IPv6 Only mode support
This drop delay after ACK, as it has many problems. See comment in
sd_dhcp_client_is_waiting_for_ipv6_connectivity() for more details.
This way, the logic becomes much much simpler.

Also, do not restart the client if we lost IPv6 connectivity in
sd_dhcp_client side, but restart the client by networkd. As,
sd_dhcp_client does not know if we can start the client or not,
e.g., the interface may be currently down.
2026-04-24 07:40:08 +09:00
João Taveira Araújo bbadd35596 networkd: allow route table names for VRF.Table=
Allow `[VRF] Table=` to accept route table names in addition to
numeric table identifiers. These may be predefined route table names
or names configured with `networkd.conf` `RouteTable=`.

There was an earlier attempt to make `VRF.Table=` accept names in
f98dd1e707, but it wired the setting to
`config_parse_route_table()`. That parser was a `[Route]` section
parser, not a generic scalar parser for netdevs: it expected
network/route parser state and created a `Route` object. It was
therefore reverted by 40352cf0c1.

This commit replaces the uint32 parser with
`manager_get_route_table_from_string()`, the generic table parser
already used by route/rule, DHCP/RA `RouteTable=`, and WireGuard
`RouteTable=` in `.netdev` files. The VRF semantics stay
unchanged. The commit retains the existing behavior of the
deprecated `TableId=` field.

Co-developed-by: OpenAI Codex <codex@openai.com>
2026-04-23 22:06:12 +02:00
Zbigniew Jędrzejewski-Szmek 39c5bee7c1 network-generator: convert to the new option parser
--help is the same except for whitespace.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 19:13:44 +02:00
Daan De Meyer d49f3f287a dlopen: take log_level argument and log in fallback stubs
Every dlopen_xxx() helper now takes an int log_level argument. It is
passed through to dlopen_many_sym_or_warn() (which in turn propagates it
to dlopen_verbose() for the library-not-installed case), and is used by
the fallback stub when support for the library is not compiled in to
emit a "<lib> support is not compiled in." message at the caller's level.
Callers pass LOG_DEBUG when gracefully degrading, or a higher level when
the failure should surface, and no longer need to log redundantly at the
call site.

As part of this, dlopen_bpf_full() (which already took a log_level) is
merged into dlopen_bpf() rather than keeping both.

The static inline fallbacks used to live in the headers, which required
pulling log.h in from every header that declared a dlopen_xxx(). Move
them into the .c files instead: the declaration is always outside the
#if HAVE_XXX block, the impl sits outside the outer #if HAVE_XXX wrap
with its own internal #if HAVE_XXX/#else/#endif, and apparmor-util.c,
idn-util.c, libmount-util.c and pam-util.c are now always compiled so
they can host their stubs.
2026-04-22 17:41:42 +02:00
Daan De Meyer e6fc73350f bpf: move all programs into src/bpf/ and consolidate meson logic
The six .bpf.c files and their shared .bpf.h headers now live directly
under src/bpf/, rather than scattered across src/core/bpf/<prog>/,
src/network/bpf/<prog>/ and src/nsresourced/bpf/<prog>/.

All BPF compilation logic — the BPF_FRAMEWORK determination (clang/gcc/
bpftool/llvm-strip lookups), flag and command construction, vmlinux.h
handling, the bpf_programs list and the loop that builds the unstripped
object, the stripped object and the skeleton header for each program —
moves into src/bpf/meson.build. The top-level meson.build only keeps
option handling and the libbpf dependency. subdir('src/bpf') is pulled
up before config.h generation so that BPF_FRAMEWORK, HAVE_VMLINUX_H and
ENABLE_SYSCTL_BPF land in conf in time.

Skeleton wrapper headers (<prog>-skel.h) are now emitted by a
configure_file() template (src/bpf/bpf-skel-wrapper.h.in) at meson
setup, replacing the previously checked-in shims of the same name.

Consumer #include paths are flattened:
"bpf/<prog>/<prog>-skel.h" becomes "<prog>-skel.h",
"bpf/<prog>/<prog>-api.bpf.h" becomes "<prog>-api.bpf.h". src/bpf is
added to includes so the shared BPF headers resolve.

sysctl-write-event.h, now shared between userspace (networkd-sysctl.c)
and BPF (sysctl-monitor.bpf.c) from a single location, gains guarded
includes so pid_t and uint64_t resolve on both sides: vmlinux.h in the
BPF case (selected via __bpf__), stdint.h + sys/types.h otherwise.
2026-04-22 16:49:36 +02:00
Daan De Meyer b5f219d834 networkd: Add IPv4SrcValidMark= support (#41364)
Closes https://github.com/systemd/systemd/issues/40643
2026-04-22 15:48:50 +02:00
Daan De Meyer 7bd76a4456 networkd: expose DHCP server pool size and offset via DBus (#41137) 2026-04-22 15:41:43 +02:00
Lennart Poettering 112f5317d1 resolved: let's generate enum fields properly too
AFAICS none of the enums here uses dashes, hence this should not
actually have any effect except for being more correct.
2026-04-20 09:36:09 +02:00
Lennart Poettering 40ab0df557 networkd: gnerate proper underscored enums in varlink interface
AFAICS none of the states actually user dashes/underscores, but let's
prepare for the future and be fully correct here.
2026-04-20 09:36:09 +02:00
Yu Watanabe 1c8158412f network/json: drop unnecessary return value assignment 2026-04-18 01:35:17 +09:00
Yu Watanabe 7756f0434c network/json: fix error handling 2026-04-18 01:35:17 +09:00
Jonathan Davies f921f13225 networkd: add DHCPServer PoolSize and PoolOffset DBus properties
Closes https://github.com/systemd/systemd/issues/30011
2026-04-15 14:20:32 +00:00
Michael Vogt bd141bd818 many: fix remaining check-pointer-deref issues
The updated parsing_hacks.h file uncovered a bunch of extra
things that the check-pointer-deref coccinelle script flags.

This commit fixes them to make the tree check-pointer-deref clean.
2026-04-12 15:27:15 +02:00
Zbigniew Jędrzejewski-Szmek b8514cff52 libsystemd-network: use DEFINE_POINTER_ARRAY_FREE_FUNC, rename cleanup function 2026-04-10 15:08:02 +02:00
noxiouz 69b6e950e2 networkd-wwan: drop unreachable unknown-bearer fallback path
bearer_get_by_path() only succeeds when both modem and bearer are found.
On failure, trying bearer_new_and_initialize(modem, path) was
unreachable and relied on a modem value that is not returned on that
path.

Treat unknown bearers as no-op and rely on modem_map_bearers() for
association during initialization.

Co-developed-by: Codex (GPT-5) <noreply@openai.com>
2026-04-08 17:28:19 +02:00
noxiouz b5a1ecb8fc networkd-wwan: handle link_get_by_name() errors in modem_simple_connect()
modem_simple_connect() ignored the return value of link_get_by_name()
and then checked link for NULL. Since the helper only sets the output
pointer on success, that could read an indeterminate value.

Check and log the return code directly with log_debug_errno().

Co-developed-by: Codex (GPT-5) <noreply@openai.com>
2026-04-08 13:59:32 +02:00
noxiouz 34649c6f55 networkd: keep static lease section valid on MACAddress= reset
config_parse_dhcp_static_lease_hwaddr() uses a cleanup helper that marks
a lease section invalid unless ownership is taken.

Add TAKE_PTR(lease) on the empty-rvalue reset path so subsequent valid
MACAddress= assignments in the same section are not dropped.

Co-developed-by: Codex (GPT-5) <noreply@openai.com>
2026-04-08 13:57:39 +02:00
Zbigniew Jędrzejewski-Szmek ca745e1914 Convert more programs to the new option and verb parsers (#41458) 2026-04-04 10:21:14 +02:00
Zbigniew Jędrzejewski-Szmek 1008583c91 tree-wide: print error if table_print() fails
We generally want to print an error message if table_print()
fails. Add a helper function for this and use it consistently.
This does one of the three things depending on the call site:
- a no-change reformatting of the code
- change from a custom message to the generic one
- addition of the error message where previously none was printed

In the third case, the actual use impact is very small, since the
table formatting is very unlikely to fail. But if it did, we would
often return an error without any message whatsoever, which we
never want to do.
2026-04-03 13:05:03 +02:00
Zbigniew Jędrzejewski-Szmek 0ce5a8fb4e tree-wide: drop flush&check step after table printing
Almost all callers of table_print() specify stdout or NULL (equivalent
to stdout) as the output stream. Simplify things by not requiring the
the stream to be specified.

In almost all cases, the printing of the table is surrounded by normal
printfs() that don't do explicit flushing and for which we don't check
the output stream status. Let's simplify most callers and skip this
step. The reason is not so much to avoid the extra step itself, but
instead to avoid the _handling_ of the potential failure. We generally
only want to print an error message for ENOMEM and other "internal"
errors, so strictly speaking we should filter out the errors from the
stream. By skipping the flush&check step we implicitly do this.
2026-04-03 13:04:40 +02:00
Yaping Li 39ce1ee990 report: follow up to review comments on #40619
Address review comments on
https://github.com/systemd/systemd/pull/40619#discussion_r2810892362
2026-04-02 21:48:31 -07:00
Lennart Poettering 5f598576b8 network-generator: support BOOTIF= and rd.bootif=0 options (#41028)
The network generator currently supports many of the options described
by dracut.cmdline(7), but not everything.

This commit adds support for the BOOTIF= option (and the related
rd.bootif= option) used in PXE setups.

This is implemented by treating BOOTIF as a special name/placeholder
when used as an interface name, and expecting a MAC address to be set in
the BOOTIF= parameter. The resulting .network file then uses MACAddress=
in the [Match] section, instead of Name=.
2026-04-02 16:17:11 +02:00
Luca Boccassi 34ff7243e1 networkd: fix assert with IPFamily=both in MobileNetwork conf and add minimal mock for test coverage (#41402) 2026-04-02 12:28:04 +01:00
Daan De Meyer 526b8eeb5d More assorted coverity fixes (#41413) 2026-03-30 23:34:44 +02:00
Nick Rosbrook cceddc41fd network-generator: support BOOTIF= and rd.bootif=0 options
The network generator currently supports many of the options described
by dracut.cmdline(7), but not everything.

This commit adds support for the BOOTIF= option (and the related
rd.bootif= option) used in PXE setups.

This is implemented by treating BOOTIF as a special name/placeholder
when used as an interface name, and expecting a MAC address to be set in
the BOOTIF= parameter. The resulting .network file then uses MACAddress=
in the [Match] section, instead of Name=.
2026-03-30 10:48:55 -04:00
Michael Vogt 3e9eaf45f0 network: make check-pointer-deref clean
Add the needed assert changes to make the code clean
for the new check-pointer-deref script.
2026-03-30 13:36:00 +02:00
Luca Boccassi 3fd6774633 networkd-ndisc: add assert for DNSSL allocation overflow safety
Coverity flags ALIGN(sizeof(NDiscDNSSL)) + strlen(*j) + 1 as a
potential overflow. Domain names are protocol-bounded but add an
assert to make this explicit for static analyzers.

CID#1548066

Follow-up for 1e7a0e21c9
2026-03-30 09:37:31 +01:00
ssahani 2f69c8e712 networkd: Add docs and tests for IPv4SrcValidMark=
Document the new setting in systemd.network(5) man page
and add coverage in the networkd integration tests.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-30 06:25:00 +05:30
Luca Boccassi abe3d570f8 test: add a mock ModemManager for basic coverage of sd-networkd's integration
Just the minimal setup and test case required to cover
https://github.com/systemd/systemd/issues/41389 for now, can be
expanded in the future

Boring boilerplate is bot-made, don't @ me

Co-developed-by: Claude Opus 4.6 noreply@anthropic.com
2026-03-28 15:19:21 +00:00
Luca Boccassi e0ab84e21b networkd: fix assert with IPFamily=both in MobileNetwork conf
Fixes https://github.com/systemd/systemd/issues/41389

Follow-up for f8a4c3d375
2026-03-28 14:47:34 +00:00
ssahani 1fcb88b234 networkd: Add IPv4SrcValidMark= support
Add support for configuring net.ipv4.conf.<iface>.src_valid_mark
via the [Network] section in .network files.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-27 09:22:06 +05:30
noxiouzandClaude Opus 4.6 7d5ec30862 network: add unmanaged interface checks to Link.Renew and Link.ForceRenew Varlink methods
The D-Bus counterparts (bus_link_method_renew, bus_link_method_force_renew)
reject calls on unmanaged interfaces with BUS_ERROR_UNMANAGED_INTERFACE,
but the Varlink methods silently succeed. Add the same guard to both
Varlink methods, returning io.systemd.Network.Link.InterfaceUnmanaged,
and declare the error in the IDL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-19 11:50:45 +00:00
noxiouz 1416d3b69c networkctl: drop unused functions
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 22:55:52 +00:00
noxiouzandYu Watanabe 689e45a6cd networkctl: use io.systemd.Network.Link.Describe() Varlink method
This makes networkctl fetch bit-rate statistics and offered DHCP
leases via Link.Describe() method instead of D-Bus.

Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 22:55:52 +00:00
noxiouz e90ea94392 network: add io.systemd.Network.Link.Describe() Varlink method
The handler returns the JSON produced by link_build_json().

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 22:55:52 +00:00
noxiouzandYu Watanabe 54e8ea6552 networkctl: use io.systemd.service.Reload() method
Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 22:55:52 +00:00
noxiouz 6627dfe425 network: implement io.systemd.service.Reload() in networkd
Bind networkd's reload handler to the generic io.systemd.service.Reload
method.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 22:55:52 +00:00
Yu Watanabe dde311ba14 networkctl: use new varlink methods
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 22:55:52 +00:00
noxiouz 506890fa0d network: add io.systemd.Network.Link.Reconfigure() Varlink method
The handler calls link_reconfigure_full() with UNCONDITIONALLY|CLEANLY
flags and defers the Varlink reply until reconfiguration completes.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 22:55:52 +00:00