Commit Graph
2007 Commits
Author SHA1 Message Date
Michael Vogt 5d82ecc0e3 libsystemd-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-27 11:23:40 +01:00
Daan De Meyer 9d844012bc sd-dhcp-client: several trivial cleanups (#41256) 2026-03-22 20:00:33 +01:00
Yu Watanabe 55f2fdd508 dhcp: fix user class and vendor specific option assignment
The commit 6d7cb9a6b8 fixes the assignment
of the these options when specified through SendOption=. However, it
breaks when specified through UserClass= or SendVendorOption=.

When UserClass= or SendVendorOption= is specified, the option length is
calculated from the sd_dhcp_client.user_class or .vendor_options. Hence,
we can use 0 for the length in that case.

Follow-up for 6d7cb9a6b8.
2026-03-22 19:40:54 +01:00
Yu Watanabe 26f769bea3 sd-dhcp-client: propagate errors in client_initialize_{io,time}_events()
Call client_stop() on error and return 0 only on callback.
Normal non-callback functions should propagate errors.

This also makes client_initialize_time_events() use
event_reset_time_relative().
2026-03-22 03:34:43 +09:00
Yu Watanabe ad4d2ae619 sd-dhcp-client: voidify client_initialize()
It never fails.
2026-03-22 03:34:43 +09:00
Yu Watanabe 2fb192d237 sd-dhcp-client: drop disabled FORCERENEW message support
FORCERENEW message support has been disabled so long time for security
concern. Most other implementations of DHCP server/client neither
support FORCERENEW. Let's completely drop relevant code.
2026-03-22 03:34:43 +09:00
Yu Watanabe ddded65d41 sd-dhcp-client: add missing error checks 2026-03-22 03:34:43 +09:00
Yu Watanabe 0c68816c56 sd-dhcp-client: add missing assertion 2026-03-22 03:34:43 +09:00
Yu Watanabe ced607506d sd-dhcp-client: coding style fix 2026-03-22 03:34:43 +09:00
Yu Watanabe bd1d1e61eb fuzz-dhcp-client: modernize test code 2026-03-22 02:26:18 +09:00
Yu Watanabe f0387aa666 test-dhcp-client: modernize test code 2026-03-22 02:26:15 +09:00
Yu Watanabe fce03832fa test-dhcp-client: fix packet length and checksum in IP header 2026-03-21 05:21:28 +09:00
Lennart Poettering 2c74a91cb8 sd-json: when parsing optionally insist top-level variant is object or array
Typically, the top-level JSON object has to be an object, in any json
document we parse, hence let's add a simple way to enforce that.

Make use of this in various places.

(Note, various other JSON parsers insist on this logic right from the
beginning, but I actually thinking making this insisting optional like
this patch does it is the cleaner approach)
2026-03-20 15:34:56 +01:00
Lennart Poettering 1b364f8b53 sd-ndisc: fix address family check
Issue reported by zhengg-research
2026-03-11 18:25:28 +01:00
Yu Watanabe 6eaa5ba322 sd-dhcp-client: several fixlets for sending RELEASE or DECLINE
- Extract common logic to client_send_release_or_decline().
- Do not send DECLINE message on BOOTP protocol.
- Drop redundant assignment of chaddr, as it is already set by
  client_message_init() -> dhcp_message_init().
- Do not assign acquired address in ciaddr field of DECLINE message,
  but use Requested IP Address option.
- Broadcast DECLINE message, rather than unicast.
- Set server identifier in both cases.

Fixes #39299.
2026-03-11 08:45:24 +09:00
Nandakumar Raghavan 6d7cb9a6b8 networkd: fix for networkd crash when client sends Option 82 via SendOption=
When a DHCP client uses SendOption=82:string:..., option_append() calls
the SD_DHCP_OPTION_RELAY_AGENT_INFORMATION case which was written for
the server relay path. It casts optval to sd_dhcp_server* and calls
strlen() on its members, but optval is actually raw binary data from
the client, causing SIGSEGV. The same is applicable when option 43 and
option 77 are passed to SendOption.

Fix by checking optlen > 0 and appending the option as a plain TLV,
skipping the server-specific relay agent logic.
2026-03-10 18:29:59 +01:00
Yu Watanabe 8903e6b5f7 tree-wide: suppress misc-use-internal-linkage warnings
Suppress warnings like the following from clang tidy:
```
../src/boot/addon.c:11:19: error: function 'efi_main' can be made static to enforce internal linkage [misc-use-internal-linkage,-warnings-as-errors]
   11 | EFIAPI EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *system_table);
      |                   ^
```

Some warnings are suppressed simply by setting comments to ignore the warning,
some are by making global variables static, or include a suitable header.
2026-03-05 20:23:24 +01:00
Frantisek Sumsal 90f5d2a202 tree-wide: various fixlets suggested by Coccinelle 2026-03-05 10:27:58 +01:00
Skye Soss 13db63e920 network: add DHCPv6 message types to string table (#40912)
Adds the DHCPv6 message types ADDR-REG-INFORM and
ADDR-REG-REPLY to the DHCPv6 message types string table.

Follow-up for 1e55da38aa.
2026-03-03 01:50:12 +09:00
Mike Yuan 41615d59fa various: port manual goto cleanup to CLEANUP_TMPFILE_AT 2026-02-11 02:39:26 +01:00
gvenugo3 cf27c70d70 networkd-json: add human-readable address strings for IP addresses
Add JSON_BUILD_PAIR_IN_ADDR_WITH_STRING, JSON_BUILD_PAIR_IN6_ADDR_WITH_STRING,
and JSON_BUILD_PAIR_IN4_ADDR_WITH_STRING macros (plus _NON_NULL variants) that
emit both the binary address array and a human-readable string representation.

For example, an address field now emits both:
  "Address": [192, 168, 1, 1]
  "AddressString": "192.168.1.1"

This improves usability of the JSON/Varlink output for debugging and tooling
that consumes networkd state.

Updated networkd-json.c to use these new macros for addresses, neighbors,
nexthops, routes, routing policy rules, DNS servers, NTP servers, SIP servers,
domains, DHCPv6 prefixes, and link-local addresses.

Also updated the Varlink interface definitions to include the new string fields.
2026-02-04 10:34:30 +01:00
Yu Watanabe 68c7004236 network/dhcp4: send release message before stopping the client
Otherwise, the socket is already closed and sending release will be
anyway skipped.

With this patch, release message is sent before stopping the client.
```
Jan 20 18:29:41 systemd[1]: Stopping systemd-networkd.service - Network Management...
Jan 20 18:29:41 systemd-networkd[3821255]: wlp59s0: DHCPv4 client: RELEASE
Jan 20 18:29:41 systemd-networkd[3821255]: wlp59s0: DHCPv4 client: STOPPED
Jan 20 18:29:41 systemd-networkd[3821255]: wlp59s0: DHCP lease lost
```

Fixes #39299.
2026-01-21 15:50:35 +01:00
Daan De Meyer aec52c1e6e string-table: Introduce DECLARE_STRING_TABLE_LOOKUP() and friends
Let's introduce these for the following two reasons:
- Using them makes sure the parameter names match between declaration
  and definition (if both use the corresponding macros).
- They make sure developers can't forget the _const_ and _pure_
  attributes for the declarations.

This commit also includes some include sorting fixes
2026-01-02 04:05:45 +09:00
Yu Watanabe 93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Daan De Meyer 6a9f0641cd tree-wide: Fix declaration/definition parameter name mismatches 2025-11-26 19:02:31 +09:00
Daan De Meyer 9a6a8f35eb tree-wide: Small fixes for various clang-tidy warnings 2025-11-26 16:22:00 +09:00
Daan De Meyer 87fbd33372 clang-tidy: Fix all remaining misc-include-cleaner violations
- Remove unused includes
- Add common false positive headers to misc-include-cleaner.IgnoreHeaders
- Add IWYU pragma keep for uncommon false positive headers
2025-11-22 10:19:41 +01:00
Zbigniew Jędrzejewski-Szmek 5220bb8c3f meson: automatically add 'extract' to 'sources'
In all cases, everything that we list in 'extract', we also list in
'sources'. We can simplify things by automatically appending the first
list to the second.

In the listings, move 'extract' key right below 'sources', since now
they are both "sources", just with slightly different meanings.
2025-11-20 10:03:48 +09:00
Chris Down 77a92e97eb tree-wide: several cleanups (#39746) 2025-11-16 15:40:39 +08:00
Yu Watanabe 5a943bae12 network-internal: do not save partially parsed values 2025-11-16 14:01:28 +09:00
Yu Watanabe af70b7521f sd-dhcp-lease: use the last hostname option when multiple hostname is specified 2025-11-16 10:50:34 +09:00
Yu Watanabe a6c61b4adc sd-dhcp-lease: drop ret_ prefixes from the parsers 2025-11-16 10:49:59 +09:00
Lennart Poettering 4408db6908 sd-dhcp-server: add api to get address from hostname, based on lease data 2025-11-15 07:44:24 +01:00
Chris Down 7f9c0c31d2 sd-dhcp-server: Add Hostname= option to static leases
This adds a new `Hostname=` option to the [DHCPServerStaticLease]
section in .network files, allowing an administrator to assign a
specific hostname to a client receiving a static lease.

We automatically select the correct DHCP option to use based on the
format of the provided string:

- Single DNS labels are sent as Option 12.
- Names with multiple DNS labels are sent as Option 81 in wire format.

Fixes: #39634
2025-11-14 07:50:13 +09:00
Yu Watanabe 5bb9063505 musl: hostname-util: introduce LINUX_HOST_NAME_MAX
glibc defines HOST_NAME_MAX as 64 and our code rely on that, but musl
defines the constant as 255. Let's provide our own definition for the
maximum length.
2025-11-13 08:02:05 +09:00
Yu Watanabe ecf3c8702d test-ndisc-rs: drop unused verbose flag and log in the debug level 2025-11-10 20:49:21 +09:00
Yu Watanabe bb1c5449fb sd-dns-resolver: move header to src/systemd
This also adds missing license header.

Follow-up for ee2108dcd5.
2025-11-05 05:16:34 +09:00
Mike Yuan fbc9f0dd4e libsystemd-network/sd-lldp-tx: use SD_JSON_BUILD_PAIR_ID128 2025-10-22 14:44:50 +02:00
Yu Watanabe d19294e92a sd-dhcp-server: fix conditions for checking if static address is assigned to another host
Even if a static lease may be configured for a host, another address may
be previously assigned to the host. Let's not refuse to assign the
static lease to the host even in that case.

Fixes an issue reported at
https://github.com/systemd/systemd/issues/35781#issuecomment-3369545753.
2025-10-20 11:45:45 +01:00
Lennart Poettering 5751b236a5 resolved: move DNS RR/key/answer/question/packet tools to shared/
We want to reuse these generic DNS concepts in resolved hook
implementations, hence move them to shared code.

(This also enables us to immediately remove som SVCB record handling
duplicate definitions.)

No real code changes, just some moving around of things.
2025-10-20 10:35:23 +02:00
Daan De Meyer f102bc3e5f tree-wide: Introduce sd-forward.h and shared-forward.h headers
Let's not leak details from src/shared and src/libsystemd into
src/basic, even though you can't actually do anything useful with
just forward declarations from src/shared.

The sd-forward.h header is put in src/libsystemd/sd-common as we
don't have a directory for shared internal headers for libsystemd
yet.

Let's also rename forward.h to basic-forward.h to keep things
self-explanatory.
2025-10-16 17:00:29 +02:00
Govind Venugopal 3eb7b881bd network: add DHCP server domain name option support (#39260)
Implements DHCP option 15 (Domain Name) for systemd-networkd's DHCP
server, allowing administrators to configure the DNS default domain that
clients should use.

This addresses the feature request in issue #37077, where users needed
to manually configure domain names using
SendOption=15:string:example.com as a workaround.

This adds two new configuration options to the [DHCPServer] section:
- EmitDomain= (boolean): whether to send domain name to clients
- Domain= (string): the domain name to send (e.g., "example.com")

Example configuration:
  [DHCPServer] EmitDomain=yes Domain=example.com

This eliminates the need for manual workarounds using
SendOption=15:string:...

Fixes #37077
2025-10-15 11:20:41 +02:00
Daan De Meyer 9adb4685df tree-wide: Remove unused includes 2025-09-19 14:46:55 +02:00
ssoss 1e55da38aa network: add new DHCPv6 message types and options
Gives enum definitions for the DHCPv6 options from RFC9527 and RFC 9686
and the new message types defined in RFC 9686.
2025-07-31 05:41:53 +09:00
Zbigniew Jędrzejewski-Szmek dcccbe049c tree-wide: several fixlets for log message and comment (#38263) 2025-07-23 10:17:33 +02:00
Yu Watanabe 3eb5402b5c networkd/dhcp6: Add support for IPv6 SIP servers (#38269)
This pull-request adds support for IPv6 SIP servers, which can be
obtained from DHCPv6 options.

[RFC3319](https://www.rfc-editor.org/rfc/rfc3319.html) defines two
options for this: option 21 (SIP Servers Domain Name List) and option 22
(SIP Servers IPv6 Address List).

systemd-networkd currently only supports IPv4 SIP servers, but ISPs like
NTT EAST provide IPv6 SIP servers. Exposing this in the D-Bus API would
allow other programs, such as downstream DHCPv6 servers, to utilize it.

Usage:

```
[DHCPv6]
UseSIP=yes
```

Partial output of `run0 systemd-networkd-tests.py
NetworkdDHCPClientTests.test_dhcp_client_use_sip`:

```console
> networkctl status veth99
● 17: veth99
                 NetDev File: /run/systemd/network/25-veth.netdev
                   Link File: /usr/lib/systemd/network/99-default.link
                Network File: /run/systemd/network/25-dhcp-client.network
                              └─/run/systemd/network/25-dhcp-client.network.d/override.conf
                       State: routable (configured)
                Online state: online
                        Type: ether
                        Kind: veth
                      Driver: veth
            Hardware Address: 12:34:56:78:9a:bc
                         MTU: 1500 (min: 68, max: 65535)
                       QDisc: noqueue
IPv6 Address Generation Mode: eui64
    Number of Queues (Tx/Rx): 2/2
            Auto negotiation: no
                       Speed: 10Gbps
                      Duplex: full
                        Port: tp
                     Address: 192.168.5.181 (DHCPv4 via 192.168.5.1)
                              2600::15
                              fe80::1034:56ff:fe78:9abc
                     Gateway: 192.168.5.1
                              fe80::1034:56ff:fe78:9abd
                         SIP: 192.168.5.1
                              2600::1
                              foo.example.com
           Activation Policy: up
         Required For Online: yes
            DHCPv4 Client ID: IAID:0x7ec6b6c/DUID
          DHCPv6 Client IAID: 0x7ec6b6c
          DHCPv6 Client DUID: DUID-EN/Vendor:0000ab11617740de1342c3a2
```
2025-07-23 08:09:06 +09:00
haxibami d2191515ba sd-dhcp6-client: add SIP server domain support 2025-07-22 16:54:08 +09:00
haxibami 551bfe7738 sd-dhcp6-client: add SIP server address support 2025-07-22 16:31:52 +09:00
Yu Watanabe 7f6086d530 tree-wide: do not use %m with SYNTHETIC_ERRNO() 2025-07-22 03:05:54 +09:00
Beniamino Galvani 8f5eaeb143 sd-dhcp6-lease: fix calculation of t2
sd_dhcp6_lease_get_t2() was returning t1, and so the client was going directly
to the rebind state skipping the lease renewal.

Reported-by: Jaime Caamano <jcaamano@redhat.com>
Fixes: 394fac52d0 ("sd-dhcp6-client: introduce sd_dhcp6_lease_get_t1() and friends")
2025-07-22 02:15:43 +09:00