Commit Graph
1987 Commits
Author SHA1 Message Date
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
Yu Watanabe 4f18ff2e29 tree-wide: include unistd.h where necessary
We use symbols provided by unistd.h without including it. E.g.
open(), close(), read(), write(), access(), symlink(), unlink(), rmdir(),
fsync(), syncfs(), lseek(), ftruncate(), fchown(), dup2(), pipe2(),
getuid(), getgid(), gettid(), getppid(), pipe2(), execv(), _exit(),
environ, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, F_OK, and their
friends and variants, so on.

Currently, unistd.h is indirectly included mainly in the following two paths:
- through missing_syscall.h, which is planned to covert to .c file.
- through signal.h -> bits/sigstksz.h, which is new since glibc-2.34.
  Note, signal.h is included by sd-eevent.h. So, many source files
  indirectly include unistd.h if newer glibc is used.

Currently, our baseline on glibc is 2.31. We need to support glibc older
than 2.34, but unfortunately, we do not have any CI environments with
such old glibc. CIFuzz uses glibc-2.31, but it builds only fuzzers, and
many files are even not compiled.
2025-06-30 09:19:15 +02:00
Yu Watanabe 92b64168f6 sd-lldp: replace ETHERTYPE_LLDP with ETH_P_LLDP
ETH_P_LLDP is defined in linux/if_ether.h.
2025-06-19 19:08:45 +09:00
Yu Watanabe b6f96f635f sd-lldp-tx: introduce sd_lldp_tx_describe() to dump current settings 2025-06-18 01:51:16 +09:00
Yu Watanabe 4c45437b60 sd-lldp-rx: also dump received MUD URL 2025-06-18 00:53:24 +09:00
Yu Watanabe 898513783e sd-lldp-tx: allow to emit VLAN ID 2025-06-18 00:53:24 +09:00
Yu Watanabe 0597109ddf sd-lldp-tx: append capabilities before MUD URL
No functional change, but let's append vendor specific informations
after others to sort the TLVs with their type.
2025-06-18 00:53:24 +09:00
Yu Watanabe 27546b769c sd-lldp-tx: do not expose machine ID by default
Previously, systemd-networkd sent machine ID as chassis ID.
Let's use application specific machine ID.

This is a kind of backward compat breaking. Hence, this also introduces
the support of $SD_LLDP_SEND_MACHINE_ID environment variable.

Closes #37613.
2025-06-18 00:53:20 +09:00
Yu Watanabe 98b02dd7e7 sd-dhcp-server: reopen fd only when it is valid
Fixes a bug in 11b88419ae.
2025-06-14 02:53:31 +09:00
Colin FosterandAvram Dorfman 2871f967cc test-dhcp-client: add test for bootp clients
Verify that BOOTP replies are successfully handled by the sd-dhcp-client
when configured for BOOTP.

Co-authored-by: Avram Dorfman <dorfman@est.org>
2025-06-13 14:15:04 +09:00
4ad29bad7b sd-dhcp-client: add ability to support bootp
BOOTP can be used to sign a static IP to clients. Instead of using the
four message exchange, and Option 53 (DHCP Message Type) there is only a
two message exchange. This adds the support for this exchange.

Co-authored-by: Avram Dorfman <dorfman@est.org>
Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
2025-06-13 14:14:33 +09:00
Yu Watanabe 98a9b0f92a sd-dhcp-client: move comment to relevant place 2025-06-13 13:35:21 +09:00
Yu Watanabe 556f641fb5 dhcp: several coding style cleanups
- rename arguments for storing results,
- reorder arguments to move ret_xyz at the end,
- add several missing assertions.
2025-06-13 13:35:21 +09:00
Colin Foster be40a31f5c dhcp: relocate type field
The type field is a DHCP-specific parameter. Relocate the parameter so
there is a clearer separation between DHCP and BOOTP parameters.
2025-06-13 13:35:21 +09:00
Yu Watanabe 6c2558a2fc tree-wide: allow building with -Wgnu-variable-sized-type-not-at-end option for clang (#37499)
Follow-up for #36993.
Closes #37497.
2025-06-07 01:02:38 +09:00
Lorenzo Arena 6b78f13b7e network: test-lldp-rx: set more variable as static const 2025-06-06 09:35:11 +02:00
Lorenzo Arena 496b21ab8e sd-lldp-rx: add VLAN ID parsing
Closes #28354.
2025-06-06 09:35:11 +02:00
Yu Watanabe fda47cd92b sd-dhcp: explicitly set buffer size of each type 2025-06-04 13:13:14 +09:00
Daan De Meyer 5cdf13c70c libsystemd: Clean up includes
For libsystemd's headers, the changes made depend on whether the
header is installed or not. For installed headers, the only change
made is that commonly included headers were moved to _sd-common.h.
For these headers, there should be no noticeable change in behavior
when including them. For non-installed headers, includes were replaced
with forward declarations where possible as usual.

Split out of #37344.
2025-05-25 03:40:24 +09:00
Daan De Meyer 1e35e81b2c tree-wide: Clean up includes
Preparation for cleaning up includes in src/shared.
2025-05-22 21:10:15 +02:00
Daan De Meyer e97cd0ca9f icmp6-packet: Fix typo 2025-05-21 10:37:18 +02:00