Commit Graph
1737 Commits
Author SHA1 Message Date
Mike Yuan bdd2036e81 hexdecoct: make unbase64mem and unhexmem always use SIZE_MAX 2024-01-09 03:59:15 +09:00
Luca Boccassi 1323a222d2 sd-dhcp-client: add assert_not_reached in switch case
Tell static analysis that r is always initialised

Follow-up for 1809132064

CID#1533109
2024-01-04 14:30:20 +01:00
Yu Watanabe dd8ab4a206 sd-dhcp-server: rename DHCPLease -> sd_dhcp_server_lease
Then, move basic functions for the object to sd-dhcp-server-lease.[ch].

No effective funcional changes.
2024-01-03 15:20:31 +09:00
Yu Watanabe 95c48613f4 sd-dhcp-server: use sd_dhcp_client_id 2024-01-03 15:20:31 +09:00
Yu Watanabe d59a2b3bf5 sd-dhcp-lease: use sd_dhcp_client_id 2024-01-03 06:06:39 +09:00
Yu Watanabe 1809132064 dhcp: move sd_dhcp_client_id_to_string() to sd-dhcp-client-id.[ch]
Then, this makes it take sd_dhcp_client_id object, and introduce
sd_dhcp_client_id_to_string_from_raw().
2024-01-03 06:06:36 +09:00
Yu Watanabe 6efa51f862 dhcp: introduce sd_dhcp_client_id and relevant functions
This splits out client ID handling from sd-dhcp-client.c to
sd-dhcp-client-id.[ch]. This will be used later in other places.
2024-01-03 06:06:34 +09:00
Luca Boccassi 9d75598bc4 Merge pull request #30593 from yuwata/sd-dhcp-duid
dhcp: introduce sd_dhcp_duid and relevant functions
2024-01-01 19:24:31 +01:00
Mike Yuan 0a0f49556f Merge pull request #30622 from yuwata/space
tree-wide: drop unnecessary space or insert missing space
2023-12-25 17:52:48 +08:00
Yu Watanabe c01a5c0527 siphash24: introduce siphash24_compress_typesafe() macro
To prevent copy-and-paste mistake.

This also introduce in_addr_hash_func().

No functional change, just refactoring.
2023-12-25 15:38:59 +09:00
Yu Watanabe b3a9d980f3 tree-wide: drop space between variable and an increment/decrement 2023-12-25 01:56:40 +09:00
Yu Watanabe 8161f6086e test: make assert_return() critical by default on fuzzer and unit tests
Several test cases intentionally trigger assert_return(). So, to avoid
the entire test fails, this introduces several macros that tentatively
make assert_return() not critical.
2023-12-24 02:02:18 +09:00
Yu Watanabe 3a6c22274c dhcp: introduce sd_dhcp_duid_to_string()
This also renames sd_dhcp6_client_duid_as_string() ->
sd_dhcp6_client_get_duid_as_string(), and make it use
sd_dhcp_duid_to_string().
2023-12-23 04:15:09 +09:00
Yu Watanabe ce9bd20616 sd-dhcp6-client: introduce direct getter and setter of DUID 2023-12-23 04:15:09 +09:00
Yu Watanabe 97c3506dcd dhcp: introduce sd_dhcp_duid and move relevant functions to sd_dhcp_duid.[ch] 2023-12-23 04:15:09 +09:00
Yu Watanabe c74d18e4ad dhcp: cleanup headers included by dhcp-identifier.h 2023-12-23 04:15:09 +09:00
Yu Watanabe f67208a172 network/ipv4ll: do not start sd-ipv4ll on exit
When assert_return() is critical, the following assertion is triggered
on exit:
---
 #0  0x00007f8b1f6b0884 in __pthread_kill_implementation () from target:/lib64/libc.so.6
 #1  0x00007f8b1f65fafe in raise () from target:/lib64/libc.so.6
 #2  0x00007f8b1f64887f in abort () from target:/lib64/libc.so.6
 #3  0x00007f8b208d02d6 in log_assert_failed (text=0x7f8b210009e0 "e->state != SD_EVENT_FINISHED", file=0x7f8b20fff403 "src/libsystemd/sd-event/sd-event.c",
     line=1252, func=0x7f8b21004400 <__func__.154> "sd_event_add_io") at ../src/basic/log.c:948
 #4  0x00007f8b208d0457 in log_assert_failed_return (text=0x7f8b210009e0 "e->state != SD_EVENT_FINISHED",
     file=0x7f8b20fff403 "src/libsystemd/sd-event/sd-event.c", line=1252, func=0x7f8b21004400 <__func__.154> "sd_event_add_io") at ../src/basic/log.c:967
 #5  0x00007f8b20c7d102 in sd_event_add_io (e=0x617000000080, ret=0x60c000000a20, fd=11, events=1, callback=0x7dfd85 <ipv4acd_on_packet>,
     userdata=0x60c000000a00) at ../src/libsystemd/sd-event/sd-event.c:1252
 #6  0x00000000007e3934 in sd_ipv4acd_start (acd=0x60c000000a00, reset_conflicts=true) at ../src/libsystemd-network/sd-ipv4acd.c:597
 #7  0x00000000007e72b9 in ipv4ll_start_internal (ll=0x6080000006a0, reset_generation=true) at ../src/libsystemd-network/sd-ipv4ll.c:278
 #8  0x00000000007e7462 in sd_ipv4ll_start (ll=0x6080000006a0) at ../src/libsystemd-network/sd-ipv4ll.c:298
 #9  0x00000000006047a1 in dhcp4_handler (client=0x617000000400, event=0, userdata=0x61a000000680) at ../src/network/networkd-dhcp4.c:1183
 #10 0x000000000075b1ed in client_notify (client=0x617000000400, event=0) at ../src/libsystemd-network/sd-dhcp-client.c:783
 #11 0x000000000075bf8d in client_stop (client=0x617000000400, error=0) at ../src/libsystemd-network/sd-dhcp-client.c:821
 #12 0x000000000077710f in sd_dhcp_client_stop (client=0x617000000400) at ../src/libsystemd-network/sd-dhcp-client.c:2388
 #13 0x000000000065cdd1 in link_stop_engines (link=0x61a000000680, may_keep_dhcp=true) at ../src/network/networkd-link.c:336
 #14 0x000000000041f214 in manager_free (m=0x618000000080) at ../src/network/networkd-manager.c:613
 #15 0x00000000004124e3 in manager_freep (p=0x7f8b1c800040) at ../src/network/networkd-manager.h:128
 #16 0x00000000004139f6 in run (argc=1, argv=0x7ffffe4522e8) at ../src/network/networkd.c:24
 #17 0x0000000000413b20 in main (argc=1, argv=0x7ffffe4522e8) at ../src/network/networkd.c:119
---
Prompted by https://github.com/systemd/systemd/pull/30049#issuecomment-1844087965.
2023-12-10 14:40:09 +09:00
Yu Watanabe dd59d5e57c libsystemd-network: introduce triple_timestamp_from_cmsg()
Follow-up for 461ef3981f.

This should fix compile error on x32 and riscv32.
2023-11-20 15:44:23 +00:00
Yu Watanabe 965040d811 test: always call test_setup_logging() 2023-11-18 03:04:27 +09:00
Luca Boccassi 461ef3981f sd-dhcp: use CMSG_FIND_AND_COPY_DATA to avoid build failures on x32 architectures
On architectures where timeval is 64bit but size_t is 32bit
we have to use CMSG_FIND_AND_COPY_DATA. This affects x32 and riscv32.

Follow-up for 905d0ea7b0
2023-11-16 11:26:57 +09:00
Yu Watanabe c0b927eb3a dhcp: do not trigger assertion by malformed messages
This also changes error code from -ENODATA -> -EBADMSG,
as we received bad message in that case.

Prompted by #30029.
2023-11-16 02:32:12 +09:00
Yu Watanabe fdf759e3ae sd-dhcp6-client: fix DUID data length passed to hexmem()
Fixes a bug introduced by 6b7d5b6eaf.
2023-11-15 14:41:02 +09:00
Yu Watanabe 1ae9a98292 dhcp: fix maximum DUID size
This effectively reverts 9291496011.

This fixes the maximum length of DUID.
See RFC 8415 section 11.1.
2023-11-15 14:38:55 +09:00
Yu Watanabe b3884498a9 dhcp: drop unused prototype
Follow-up for 53488ea352.
2023-11-15 10:17:34 +09:00
Zbigniew Jędrzejewski-Szmek fa5a025167 Rename {dual,triple}_timestamp_get to {dual,triple}_timestamp_now
Those functions take a pointer to a timestamp and return a timestamp pointer,
so the reader would be justified to think that those are just getters. Rename
them to avoid confusion.
2023-11-13 13:27:07 +01:00
Yu Watanabe 905d0ea7b0 sd-dhcp-client,-server: set timestamp based on the time when received a packet
It seems that RFC does not say anything about the timestamp of lease
we should use: time that the client sent a request or received a reply.
In DHCPv6 client and NDisc, we use a timestamp that we receive a packet,
rather than we sent something. So, let's consistently use the same
logic for DHCPv4 client.

By using the logic, we will hopefully not forget to set timestamp again,
which is fixed by 089362976c.
2023-11-08 17:58:51 +09:00
Yu Watanabe a57dd1d13f sd-dhcp-client: move packet size check to dhcp_packet_verify_headers()
No functional change.
2023-11-08 17:54:52 +09:00
Yu Watanabe 7f42c66015 sd-dhcp-client: split out client_verify_message_header()
This is not necessary to be called when a packet is received through the
RAW socket, but should not hurt anything.
2023-11-08 17:54:30 +09:00
Yu Watanabe 69f50bf35e sd-dhcp-client: make client_handle_message() propagate critical error
Then, stop client in the caller side.

This also makes
- ignore all errors except for resource errors like OOM when FORCERENEW
  is received,
- trigger assertion when an message received even if the client is
  stopped.

This should not change any functionality. Just refactoring.
2023-11-08 13:03:40 +09:00
Yu Watanabe 538ff0a60a sd-dhcp-server: support rapid commit (RFC4039)
https://datatracker.ietf.org/doc/html/rfc4039
2023-11-08 02:39:59 +09:00
Yu Watanabe 089362976c sd-dhcp-client: unconditionally set sd_dhcp_client.request_sent when a packet is sent
If a server replies an ACK for the initial DISCOVER, previously
request_sent was not set, so networkd handle the lease timed out.

Follow-up for 808b65a087.
2023-11-08 02:18:15 +09:00
Yu Watanabe c4efe0e51e sd-dhcp-client: gracefully ignore OFFER with Rapid Commit option
Fixes #29904.
2023-11-07 16:13:54 +01:00
Yu Watanabe 498a6de596 dhcp6: enterprise ID is 32bit
Follow-up for 6b44099b3b.

Fixes #29800.
2023-11-01 13:19:59 +00:00
Yu Watanabe 78101ca9cc Merge pull request #29247 from naraghavan/naraghavan/dhcpv6-vendor-options
networkd: Add DHCP vendor specific sub options to dbus API
2023-10-31 17:14:20 +09:00
Yu Watanabe d19434fbf8 tree-wide: fix typo 2023-10-31 14:35:33 +09:00
Nandakumar Raghavan 6b44099b3b networkd: Add DHCP vendor specific options to dbus API
Add DHCP vendor specific options to expose in dbus API.
This will be added to the JSON output when we query
org.freedesktop.network1.Manager object.
2023-10-27 12:11:09 +00:00
Ronan Pigott 808b65a087 network: implement RFC4039 DHCP Rapid Commit
This implements the DHCPv4 equivalent of the DHCPv6 Rapid Commit option,
enabling a lease to be selected in an accelerated 2-message exchange
instead of the typical 4-message exchange.
2023-10-26 15:26:50 -07:00
Ronan Pigott 5516b0dd20 network: cleanup unreachable condition in dhcp client path
The client state is unconditionally set just above, making this
conditional unreachable.
2023-10-26 15:26:50 -07:00
Lennart Poettering 7113640493 fd-uitl: rename PIPE_EBADF → EBADF_PAIR, and add EBADF_TRIPLET
We use it for more than just pipe() arrays. For example also for
socketpair(). Hence let's give it a generic name.

Also add EBADF_TRIPLET to mirror this for things like
stdin/stdout/stderr arrays, which we use a bunch of times.
2023-10-26 22:30:42 +02:00
Frantisek Sumsal 25f7271c42 network: ENOTSUP → EOPNOTSUPP 2023-10-25 11:26:19 +02:00
Yu Watanabe 0bc30a2038 network,dhcp: restart client with 'networkctl renew' when delayed by IPv6 only mode
This is convenient when the server supports IPv6 only mode.
Otherwise, we cannot request a new address during the client is waiting an
IPv6 connectivity. Note, the minimal timespan is 5min, and a server may
send a quite large value.
2023-10-21 01:54:08 +09:00
Yu Watanabe 95bd6816d7 sd-dhcp-client: always use sd_dhcp_client.timeout_ipv6_only_mode for delaying subsequent task
Otherwise, sd_dhcp_client_set_ipv6_connectivity() may not work, as it
checks if the timer event source is enabled or not.
2023-10-21 01:54:08 +09:00
Yu Watanabe 74c102d7e9 sd-dhcp-client: add a short comment about IPv6 only mode 2023-10-21 01:54:08 +09:00
Yu Watanabe dab96fed0c sd-dhcp-client: only send RENEW message when the client is in bound state
Fixes an issue reported at
https://github.com/systemd/systemd/pull/29544#issuecomment-1762742561.
2023-10-21 01:54:08 +09:00
Yu Watanabe a43f922526 sd-dhcp-client: simplify the condition in sd_dhcp_client_get_lease()
The condition was outdated, e.g. SELECTING state does not have a lease.
See client_handle_offer() and client_enter_requesting().

The condition based on the state may become much complex in the future.
Let's use simpler condition.
2023-10-21 01:54:08 +09:00
Yu Watanabe 8664ded716 dhcp: split dhcp-internal.h into two 2023-10-21 01:54:08 +09:00
Yu Watanabe 40e4be7e8e dhcp: move DHCP client specific definitions to dhcp-client-internal.h 2023-10-21 01:54:08 +09:00
Yu Watanabe 9bcbb61458 dhcp: split out dhcp-network.h from dhcp-internal.h 2023-10-21 01:54:07 +09:00
Yu Watanabe 8320db407c dhcp: move DHCPState to dhcp-client-internal.h
All other definitions in dhcp-protocol.h are common for client and
server. Let's move DHCP client specific definitions.
2023-10-21 01:54:07 +09:00
Yu Watanabe f3d84e20c9 fuzz: include library headers first 2023-10-21 01:54:07 +09:00