Commit Graph

1745 Commits

Author SHA1 Message Date
Matt Muggeridge
d4c8de21a0 IPv6 RA: Support the Retrans Timer field (IPv6 Conformance Test: v6LC.2.1.5)
The RA's Retransmission Timer field was being ignored. This resolves the IPv6
Core Conformance test, v6LC.2.1.5 [1].

Retransmission Timer is a 32-bit unsigned integer. The time, in milliseconds,
between retransmitted Neighbor Solicitation messages. Used by the Address
Resolution and Neighbor Unreachability Detection (NUD) algorithm.

Support setting a default value for the neighbour retransmission timer value with:

    [Network]
    IPv6RetransmissionTimeSec=<int>

By default, upon receiving a Router Advertisement with the Retransmission Timer
field set to a non-zero value, it will update the kernel's retransmit timer value.
To disable this behaviour, configure the UseIPv6RetransmissionTime= under the
[IPv6AcceptRA] section.

    [IPv6AcceptRA]
    UseIPv6RetransmissionTime=<bool>

RFC4861: Neighbor Discovery in IPv6
  * Section 4.2 RA Message Format.
  * Section 6.3.4 Processing Received Router Advertisements

A Router Advertisement field (e.g., Cur Hop Limit, Reachable Time,
and Retrans Timer) may contain a value denoting that it is
unspecified. In such cases, the parameter should be ignored and the
host should continue using whatever value it is already using. In
particular, a host MUST NOT interpret the unspecified value as
meaning change back to the default value that was in use before the
first Router Advertisement was received.

The RetransTimer variable SHOULD be copied from the Retrans Timer
field, if the received value is non-zero.

References
[1] IPv6 Core Conformance Spec (PDF)
2024-01-23 03:18:01 +09:00
Andres Beltran
6ff84614f5 Restart the DHCPv4 client when max REQUEST attempts is reached 2024-01-17 16:15:47 +00:00
Yu Watanabe
0705e05c3d sd-dhcp-client-id: introduce json_dispatch_client_id() 2024-01-11 17:03:25 +09:00
Yu Watanabe
cf9b425749 sd-dhcp-client-id/duid: do not trigger assertion when invalid size is passed
The data may be from user input or file. We usually use assertion for
programming error. Hence, using assert is not a good choise there.

Preparation for later commits.
2024-01-11 17:03:25 +09:00
Luca Boccassi
09263532b6 Merge pull request #30720 from yuwata/dhcp-server-address-verification
dhcp-server: several fixlets for address verification
2024-01-10 19:29:25 +00:00
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
ea7a35ed68 sd-dhcp-server: do not forget previously assigned addresses on pool change
Currently, networkd does not change pool size dynamically, so this
should not change behavior. But if networkd does that, then forgetting
leases causes that an address still used by a client may be assigned to
another host.
2024-01-04 05:10:47 +09:00
Yu Watanabe
0596f5939f sd-dhcp-server: check address conflict more carefully
- Even if we found a matching static lease, check if there is no
  conflicting lease.
- Accept an address request that is different from the previous one.
- Also return NAK if the server address is requested.
2024-01-04 05:10:47 +09:00
Yu Watanabe
cb0ba4b41b sd-dhcp-server: verify address of static lease before use 2024-01-04 05:10:47 +09: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