Commit Graph
100 Commits
Author SHA1 Message Date
Yu Watanabe bb83c7c633 test: add test case that journal file with unreferenced _BOOT_ID data
For issue #29275.
2023-09-26 13:26:22 +09:00
Yu Watanabe 304cb08f84 sd-journal: always fallback to find entry by realtime
Consider the following situation:
- There are two journal files (x and y), that contains entries for two boots (X and Y).
- The journal file x contains entries of the boot X, and y contains
  entries of Y.
- Nevertheless x does not contains entries of boot Y, it contains
  the _BOOT_ID= data object of boot Y. Of course, the data object is not
  referenced by any entries in the journal file x.

In such situation, when the current location of sd_journal is the head
of journal y, that is, the first entry of the boot Y,
sd_journal_previous() failed without this change, and
'journalctl --boot -NUM' for boot X failed.

Fixes #29275.
2023-09-26 13:26:22 +09:00
Yu Watanabe 7c1784db83 test: add tests for journal_find_boot_by_offset() and friends 2023-09-26 13:26:22 +09:00
Yu Watanabe 0141b2143d logs-show: use sd_journal_step_one() 2023-09-26 13:26:22 +09:00
Yu Watanabe 8081939d1d logs-show: move journal_find_boot_by_offset() and friends from journalctl.c 2023-09-26 13:26:22 +09:00
Yu Watanabe f5257facb9 journalctl: several cleanups for find_boot_by_offset()/_by_id()
- their names are prefixed with "journal_",
- make them not directly use global variables,
- simplifies the loop counter in find_boot_by_offset().
2023-09-26 13:26:22 +09:00
Yu Watanabe 1eede15851 sd-journal: refuse to write entry without boot ID
To make journal entries always contain valid boot ID.
2023-09-26 13:26:22 +09:00
Yu Watanabe b761ae0fca sd-journal: boot_id is always non-NULL
The two callers of journal_file_append_entry_internal() always pass
non-NULL boot ID.
2023-09-26 13:26:22 +09:00
Yu Watanabe 6ea51363c8 sd-journal: also verify tail_entry_boot_id and friends in journal_file_verify_header()
Then, we can drop the redundant check in journal_file_read_tail_timestamp().
2023-09-26 13:26:22 +09:00
Yu Watanabe 1fa2ebbec4 test: fix header verification 2023-09-26 13:26:22 +09:00
Yu Watanabe f9edbb80e9 sd-dhcp-client: split out client_parse_message()
No functional change, just refactoring and preparation for later
commits.
2023-09-23 01:38:21 +09:00
Yu Watanabe db849df5a1 sd-dhcp-client: introduce dhcp_lease_unref_and_replace() 2023-09-23 01:38:21 +09:00
Yu Watanabe 8fc725052a sd-dhcp-client: do not set fallback subnet mask if it is already set 2023-09-23 01:38:21 +09:00
Yu Watanabe 2ff1e23036 sd-dhcp-client: split out client_enter_requesting()
No functional change, just refactoring and preparation for later
commits.
2023-09-23 01:38:21 +09:00
Yu Watanabe 525717b87c sd-dhcp-client: split out client_enter_bound()
No functional change, just refactoring and preparation for later
commits.
2023-09-23 01:38:21 +09:00
Yu Watanabe 6197db53ba sd-ndisc: make sd_ndisc return time values in usec
This also introduces sd_ndisc_router_get_lifetime_timestamp() and
friends that return timestamp rather than timespan.
2023-09-23 01:34:56 +09:00
Yu Watanabe c650d4cdef sd-journal: refuse entry objects with an empty boot ID
Otherwise, e.g. sd_journal_get_monotonic_usec() return an empty boot ID
when called for such a broken entry object.

Such a broken object may be stored when the system was not cleanly shutdown.

Fixes #29167.
2023-09-22 08:05:53 +02:00
Yu Watanabe 3231f624e6 sd-ndisc: rename function arguments for storing results 2023-09-22 02:17:31 +09:00
Yu Watanabe 60415c1360 network: split out link_get_address_states()
No functional change, just refactoring and preparation for later
commits.
2023-09-21 11:31:43 +01:00
Yu Watanabe afb81a0c05 sd-event: drop unnecessary call of sd_event_now() when requested relative time is zero 2023-09-21 11:03:37 +02:00
Yu Watanabe 511d96d3b7 sd-dhcp-client: use unaligned_be32_sec_to_usec()
Note, previously, we set 1 second if the time value is zero.
But the adjustment is dropped now, as for the lifetime we have explicit
check that the message has non-zero lifetime, and for T1 and T2 we have
better adjustment in client_set_lease_timeouts().
2023-09-21 09:52:03 +01:00
Yu Watanabe d08ff4506c sd-device: include missing alloc-util.h
unref_and_replace_full() is defined in alloc-util.h.
2023-09-21 14:28:55 +08:00
Yu Watanabe 8ff992d1a2 test-ndisc-ra: add tests for recently added functions 2023-09-21 04:01:24 +09:00
Yu Watanabe eca280c8c0 sd-radv: make sd_radv always take timespan in usec 2023-09-21 04:01:14 +09:00
Yu Watanabe 394fac52d0 sd-dhcp6-client: introduce sd_dhcp6_lease_get_t1() and friends 2023-09-21 03:59:00 +09:00
Yu Watanabe 9132cbd5ad sd-dhcp6-client: use be32_sec_to_usec() at more places 2023-09-21 03:59:00 +09:00
Yu Watanabe d8ec95c7ff sd-dhcp6-client: rework IA_NA or IA_PD getters
This splits sd_dhcp6_lease_get_address() into small pieces,
and introduce FOREACH_DHCP6_ADDRESS() macro.
Also, the lifetimes provided by _get_address_lifetime() are now in usec,
and _get_address_lifetime_timestamp() provides timestamp.

The same change is also applied for IA_PD.
2023-09-21 03:59:00 +09:00
Yu Watanabe fb70992d39 sd-dhcp6-client: introduce sd_dhcp6_lease_has_pd_prefix() and friend
No functional change, just refactoring.
2023-09-21 03:59:00 +09:00
Yu Watanabe 4aa33df845 sd-journal: also clear saved direction on seek
Otherwise, sd_journal_previous() -> real_journal_next(DIRECTION_UP) ->
next_beyond_location() wrongly handles that previously we hit EOF of
the file, and returns 0 without finding a matching entry.

Fixes #29216.
2023-09-21 01:59:21 +09:00
Yu Watanabe 45689fd265 test: add more testcases for seeking journal entries
This is mostly for issue #29216.
2023-09-21 01:58:43 +09:00
Yu Watanabe 836809d179 test: check return value of sd_journal_next() and friends 2023-09-21 01:57:55 +09:00
Yu Watanabe a00076113b sd-dhcp-server: store lifetime and friends in usec_t 2023-09-20 05:04:03 +09:00
Yu Watanabe ca515c961b libsystemd-network: introduce several helper functions to handle time values
These will be used in later commits.
2023-09-20 05:04:03 +09:00
Yu Watanabe d5adff70c0 test-network: add test for multiple IPv6 null addresses
This also merges test_address_null() into test_address_static().
2023-09-18 10:22:08 +09:00
Yu Watanabe 6174dc7d96 network: allow to configure multiple IPv6 null addresses with different prefix length
Previously, even if a .network file contains multiple IPv6 null
addresses with different prefix length, only the first setting is applied,
as the remainings are deduped in network_drop_invalid_addresses().

Even though the kernel allows us to change the prefix length of an existing
IPv6 address, we cannot safely change the prefix length of an address
that is originally requested as a null address, as the prefix of the
address may conflict with other addresses if we change it.

We already prohibit to change the prefix length of an existing IPv6
address that is originally requested as a null address. So, we can
safely allow to configure multiple IPv6 addresses from null addresses by
relaxing the dedup logic. The dedup is govern by the hash_ops. This adds
a special handling for IPv6 null addresses.
2023-09-18 10:22:08 +09:00
Yu Watanabe 381e3cc68b network: rename address_prefix() -> address_ipv4_prefix()
This also makes the function use in4_addr_is_set() and in4_addr_mask()
for readability.
2023-09-18 10:19:51 +09:00
Yu Watanabe 52af8e5ef9 network: drop _fallthrough_ in address_{hash,compare}_func()
No functional change, just refactoring and preparation for later commit.
2023-09-18 10:16:53 +09:00
Yu Watanabe 345ed22ef9 Merge pull request #29197 from takaswie/topic/hwdb/ieee1394-unit-function
hwdb: ieee1394 unit function: fulfill Weiss Engieering FireWire models
2023-09-17 07:23:38 +02:00
Yu Watanabe b9962da63f network/sr-iov: move common parts to link_set_sr_iov_ifindices()
This also adds several debugging logs.
No functional change, just refactoring.
2023-09-08 20:09:15 +09:00
Yu Watanabe 4b12a8dd33 network/sr-iov: ignore -EINVAL in reading dev_port sysfs attribute
Fixes #27369.
2023-09-08 20:08:18 +09:00
Yu Watanabe 47f1ce1677 test-network: add testcase for [DHCPServer] ServerAddress= with null address 2023-09-08 20:03:40 +09:00
Yu Watanabe e443a88a9a man: update [DHCPServer] ServerAddress= 2023-09-08 20:03:40 +09:00
Yu Watanabe a0dfce0a3f network: allow to set null address for [DHCPServer] ServerAddress=
And refuse a link-local address.

With the previous commit, now ServerAddress= can take a null address,
but the config parser refused that. Let's allow that now.
2023-09-08 20:03:40 +09:00
Yu Watanabe 5459e11d39 network: find DHCP server address only on loading .network file
Previously, we periodically search suitable address for DHCP server,
1. when .network file is loaded,
2. when checking if we can configure sd_dhcp_server object,
3. when configuring sd_dhcp_server.

Especially, the step 2 may be triggered several times.

This makes, when .network file is loaded, find a corresponding Address
object, add a new Address object if not found, then save the found or
added Address object. So, it is not necessary to find address again on
configuring sd_dhcp_server object.
2023-09-08 20:03:40 +09:00
Yu Watanabe 26f8847102 network: call network_adjust_dhcp_server() from network_drop_invalid_addresses()
We need to find a suitable static address for the DHCP server.
So, all static addresses must be verified before network_adjust_dhcp_server()
is called. For safety, let's call it from network_drop_invalid_addresses().

No functional change, just refactoring and preparation for later
commits.
2023-09-08 20:03:40 +09:00
Yu Watanabe e63c6e9ffa conf-parser: introduce ordered_hashmap_by_section_find_unused_line() 2023-09-08 12:55:44 +09:00
Yu Watanabe d9171a230d conf-parser: check overflow in hashmap_find_free_section_line()
Also, this also renames the function, and makes it optionally takes
a filename.
2023-09-08 12:55:44 +09:00
Yu Watanabe 08ca764d0a conf-parser: modernize config_section_new()
- add assertions,
- rename argument to store result.
2023-09-08 12:55:44 +09:00
Yu Watanabe 7bf9e0d5f6 hashmap: introduce HASHMAP_BASE_FOREACH() and friend 2023-09-08 12:55:44 +09:00
Yu Watanabe f7f5028edc network: drop duplicated check
The same check is in network_adjust_dhcp_server().
2023-09-08 06:41:37 +09:00
Yu Watanabe 0ae8ff50ac network: drop duplicated address_set_broadcast()
It will be called later in link_request_address().
2023-09-08 06:41:37 +09:00
Yu Watanabe 1e1225614c core/credential,mount: re-read /proc/self/mountinfo before invoking umount command
When a unit has credentials, stopping the service unmounts the credentials
directory. On shutdown, stopping the service and the corresponding mount
unit may be done mostly simultaneously, and if we invoke umount command soon
after umount() being called on stopping the service, the mount unit will
fail.

This makes Mount.invalidated_state flag set when umount() is called for a path,
and re-read /proc/self/mouninfo before invoking umount command if the flag is set.

Fixes #25527.
Replaces #26959.
2023-09-07 01:05:13 +09:00
Yu Watanabe 25033cca08 test-execute: check credentials can be read on ExecStartPost= and friends
Prompted by
https://github.com/systemd/systemd/pull/28787#issuecomment-1690614202.
2023-09-07 00:53:28 +09:00
Yu Watanabe 133e4de23f core/exec-credential: introduce exec_context_get_credential_directory() helper function
No functional change, just refactoring.
2023-09-07 00:53:28 +09:00
Yu Watanabe 43962c30fb core: rename credential.[ch] -> exec-credential.[ch]
Also rename setup_credentials() -> exec_setup_credentials().

Addresses the post-merge review
https://github.com/systemd/systemd/pull/28787#pullrequestreview-1592065048.
2023-09-07 00:53:28 +09:00
Yu Watanabe 73ff4d48de Revert "core: do not leak mount for credentials directory if mount namespace is enabled"
This reverts commits
- 9ae3624889
  "test-execute: add tests for credentials directory with mount namespace"↲
- 94fe4cf255
  "core: do not leak mount for credentials directory if mount namespace is enabled",
- 7241b9cd72
  "core/credential: make setup_credentials() return path to credentials directory",
- fbaf3b23ae
  "core: set $CREDENTIALS_DIRECTORY only when we set up credentials"

Before the commits, credentials directory set up on ExecStart= was kept
on e.g. ExecStop=. But, with the changes, if a service requests a
private mount namespace, the credentials directory is discarded after
ExecStart= is finished.

Let's revert the change, and find better way later.

Addresses the post-merge comment
https://github.com/systemd/systemd/pull/28787#issuecomment-1690614202.
2023-09-07 00:53:28 +09:00
Yu Watanabe 468018703c core: allow to run generators without sandboxing on qemu-user
When running on non-native userland architecture via systemd-nspawn
and qemu-user-static QEMU-emulator, clone() with CLONE_NEWNS fails with
EINVAL.

Fixes #28901.

[zjs: add a comment in the code]
2023-09-06 13:18:50 +01:00
Yu Watanabe 5546506650 Merge pull request #29088 from yuwata/libsystemd-network-headers
libsystemd-network: split headers
2023-09-06 08:27:28 +09:00
Yu Watanabe 754d27e098 Merge pull request #29094 from yuwata/network-dbus-doc
man: update documents for network DBus interfaces
2023-09-06 08:25:35 +09:00
Yu Watanabe b386ff3651 sd-dhcp6-client: split out sd-dhcp6-protocol.h 2023-09-06 06:14:55 +09:00
Yu Watanabe 1f3a52d5b8 sd-dhcp-server: fix typo in arguments 2023-09-06 06:14:28 +09:00
Yu Watanabe 409f014e23 sd-dhcp: split out sd-dhcp-protocol.h from sd-dhcp-client.h 2023-09-06 06:14:15 +09:00
Yu Watanabe 18fe822101 meson: sort headers 2023-09-06 06:12:29 +09:00
Yu Watanabe 1d5db7b9f3 man: mention DBus interfaces for DHCP clients
Follow-up for #28896.
2023-09-06 06:05:55 +09:00
Yu Watanabe 0f9a2b802b network/ndisc: split out ndisc_router_process_icmp6_ratelimit()
Otherwise, if ndisc_router_process_default() return earlier, e.g.
when Network.ipv6_accept_ra_use_gateway is false, then the
ratelimit is not applied.
2023-09-05 22:03:34 +01:00
Yu Watanabe 53dff954d3 network: reorder bus implementations
Otherwise, in the man page, DHCPServer interface is listed in the Link
object.
2023-09-06 06:01:31 +09:00
Yu Watanabe 0ad8d953de sd-dhcp-client: introduce sd_dhcp_lease_has_6rd() helper function
No functional change, just refactoring.
2023-09-06 02:02:21 +09:00
Yu Watanabe a93538e892 dhcp: introduce sd_dhcp_lease_get_timestamp()
And drop sd_dhcp_client_get_lease_timestamp().

Also, this introduce sd_dhcp_lease_get_lifetime_timestamp() and friends,
which provides timestamp of the lifetime and so on, while
sd_dhcp_lease_get_lifetime() provides timestamp.
2023-09-06 02:02:21 +09:00
Yu Watanabe 7cd0755198 time-util: introduce triple_timestamp_from_boottime() 2023-09-06 02:02:21 +09:00
Yu Watanabe 5fde4d37d4 sd-dhcp-client: store lifetime and friends in usec_t 2023-09-06 02:02:21 +09:00
Yu Watanabe 4df16cd018 network/ndisc: refuse too many PREF64 prefixes
Follow-up for 6e8f5e4c1f.

Addresses https://github.com/systemd/systemd/pull/29009#issuecomment-1705700926.
2023-09-06 01:22:43 +09:00
Yu Watanabe fabea9c092 network/ndisc: drop outdated PREF64 prefixes
Follow-up for 6e8f5e4c1f.

Addresses https://github.com/systemd/systemd/pull/29009#issuecomment-1705741844.
2023-09-06 01:22:43 +09:00
Yu Watanabe a832087979 Merge pull request #29023 from pelaufer/dhcp-prefix-dbus
Add dhcp client prefix lease information to networkd json output
2023-09-05 00:16:19 +09:00
Yu Watanabe 8b1bd20722 Merge pull request #29052 from yuwata/icmp6-util-cleanups
icmp6-util: several cleanups and fixlets
2023-09-05 00:15:23 +09:00
Yu Watanabe 690afe79dd test: extract dummy icmp6 utils for tests
This extracts common implementation of dummy icmp6 utils used by tests.
2023-09-04 21:54:51 +09:00
Yu Watanabe 4961f56646 icmp6-util: make icmp6_receive() accept the null source address
Fixes #29050.
2023-09-04 21:54:43 +09:00
Yu Watanabe 5121163832 icmp6-util: several cleanups for icmp6_receive()
- Rename the argument for storing the sender address,
- allow to call it with NULL for ret_xyz,
- reduce needless copy of timestamp when the message does not have
  timestamp.
2023-09-04 21:52:55 +09:00
Yu Watanabe 47d8770aac Merge pull request #28896 from pelaufer/dhcp_dbus_notify
Add DHCP client state and change notification to networkd dbus interface
2023-09-04 21:48:43 +09:00
Yu Watanabe 4674f407b2 sd-ndisc,sd-radv: fix use of uninitialized value
When icmp6_receive() fails, then the source address is not initialized yet.
2023-09-04 19:31:40 +09:00
Yu Watanabe 218f3738d8 network/ndisc: drop captive portals with zero lifetime earlier
This also adds a comment about that we use the main lifetime for captive
portals.
2023-09-02 22:25:17 +09:00
Yu Watanabe 2b4fca55d0 Revert "network: ndisc - drop routes of lifetime 0"
This reverts commit 4ccd48cb26.

From RFC 4861 section 4.2.
> The Router Lifetime applies only to the router's usefulness as a default
> router; it does not apply to information contained in other message fields
> or options.  Options that need time limits for their information include
> their own lifetime fields.

Hence, based on the lifetime field of the message header, we should not
drop any other information.
Note that, in ndisc_router_process_default(), we have already dropp the
default gateway when the lifetime is zero. Hence, we can safely drop the
change.
2023-09-02 14:34:56 +09:00
Yu Watanabe c97f268f29 man: mention version info for NFTSet= setting
Follow-up for fc289dd0ad.
2023-09-01 13:29:27 +01:00
Yu Watanabe 1d4c874d3c Merge pull request #24570 from topimiettinen/nft-sets-v2
network: firewall integration with NFT sets
2023-09-01 20:13:39 +09:00
Yu Watanabe 3b981f7428 Revert "test-dhcp-client: add temporary workaround for assertion failure"
This reverts commit 1686c884bf.

The issue should be fixed by the previous commit. Let's drop the
workaround.
2023-08-30 17:37:22 +09:00
Yu Watanabe 5e2a89d84b sd-dhcp-client: ensure IAID and DUID being set on start
After b2851e8d62, if IAID and DUID are not
set on start, calling sd_dhcp_client_set_iaid_duid_en() in
client_message_init() triggers assertion, as the client is already
running at the stage. Let's set IAID and DUID earlier.

Fixes #28990.
2023-08-30 17:37:03 +09:00
Yu Watanabe b2851e8d62 sd-dhcp-client: make client initially in stopped state
Previously, DHCP_STATE_STOPPED and DHCP_STATE_INIT are both handled as
not-running. Moreover, previously after sd_dhcp_client_start() is
called, the client still in INIT state (and thus handled as not-running)
even if its internal timer event sources are initialized.

Let's make only STOPPED state handled as not-running, and make the
client initially in STOPPED state.

Prompted by #28896.
2023-08-28 10:25:14 +01:00
Yu Watanabe 927e20fa49 nspawn: check validity of the internal interface name only explicitly specified
Follow-up for 2f091b1b49.

Fixes #28844.
2023-08-24 15:55:32 +02:00
Yu Watanabe 6df82d128c network/ndisc: use the first captive portal in each RA
To handle malicious RA packets gracefully.

Also prompted by https://github.com/systemd/systemd/pull/28285#issuecomment-1627585140.
2023-08-24 20:01:08 +09:00
Yu Watanabe bf943a9d49 network/ndisc: do not store too many captive portals provided through RA
Prompted by https://github.com/systemd/systemd/pull/28285#issuecomment-1627585140.
2023-08-24 19:59:34 +09:00
Yu Watanabe 80500bb5d4 network/dhcp: make DUIDType= take an arbitrary integer
Closes #26745.
2023-08-24 19:55:27 +09:00
Yu Watanabe 2da796cabb dhcp: DUID-EN identifier has variable length
Also make `array[0]` -> `array[]`.

See RFC 8415, section 11.3.
2023-08-24 19:52:35 +09:00
Yu Watanabe 9291496011 network/dhcp: fix maximal DUID data size
The maximum DUID size is 128, but that includes type specified.
Hence, the maximal data size is 126.
2023-08-24 19:50:37 +09:00
Yu Watanabe 53488ea352 network: introduce per DUID type setters
No functional change, just refactoring.
2023-08-24 19:50:36 +09:00
Yu Watanabe 6ed69be98a Revert "network: DHCP6 client- Allow to send manual DUID"
This reverts commits 89e73ce86f and
543d2a4d45.

The commit assign "custom" to fixed DUID type 5. When making DUID fully
configurable, the type number should be also configurable. Also, the
fully custom DUID should be acceptable for DHCPv4.
2023-08-24 19:50:36 +09:00
Yu Watanabe 244f518f1d Merge pull request #28764 from yuwata/core-namespace
core/namespace: cleanups
2023-08-23 12:43:29 +09:00
Yu Watanabe 856532ef01 Merge pull request #28926 from yuwata/bsod-cleanups
bsod: several cleanups
2023-08-23 12:41:53 +09:00
Yu Watanabe 14c5c43985 Merge pull request #28496 from ssahani/ndisc-28426
network: ndisc - Also fill router preference
2023-08-23 12:36:45 +09:00
Yu Watanabe 51bf9b1ac3 core/namespace: do not return 1 unnecessarily
The caller of this function apply_mounts() -> apply_one_mount() only
checks if the return value is negative or not.
2023-08-22 23:22:34 +09:00
Yu Watanabe cc45ff17a4 core/namespace: add missing string table entries 2023-08-22 23:22:32 +09:00
Yu Watanabe 2b60ce545c mount-util: drop unused remount_and_move_sub_mounts() 2023-08-22 23:21:43 +09:00