Commit Graph

1150 Commits

Author SHA1 Message Date
Thomas Haller 1835a8a105 sd-dhcp-client: avoid "maybe-uninitialized" warning in client_timeout_resend()
When compiling with CFLAGS='-Werror=maybe-uninitialized -Og' we get a
warning about uninitialized "next_timeout" variable.

Avoid the warning by adding an (unreachable) "default" label.

Fixes: c24288d21e ("sd-dhcp-client: correct dhcpv4 renew/rebind retransmit timeouts")
2020-12-26 09:01:01 +09:00
Yu Watanabe 0afa4d569d sd-ndisc: fix indentation 2020-12-24 17:15:44 +09:00
Dan Streetman 8bc63a0b13 sd-dhcp-client: fix renew/rebind timeout calculation to avoid infinite loop
unfortunately I missed adding the timeout to 'now' which results in
an endless loop of renewal timeouts.

Fixes: 3a23834d6b
2020-12-16 19:49:31 +09:00
Lennart Poettering 94b78105c6
Merge pull request #17967 from poettering/connect-user-bus
add support for "systemctl --user --machine=foobar@.host" for connecting to user bus of user "foobar"
2020-12-15 21:14:01 +01:00
Lennart Poettering 52ef5dd798 hostname-util: flagsify hostname_is_valid(), drop machine_name_is_valid()
Let's clean up hostname_is_valid() a bit: let's turn the second boolean
argument into a more explanatory flags field, and add a flag that
accepts the special name ".host" as valid. This is useful for the
container logic, where the special hostname ".host" refers to the "root
container", i.e. the host system itself, and can be specified at various
places.

let's also get rid of machine_name_is_valid(). It was just an alias,
which is confusing and even more so now that we have the flags param.
2020-12-15 17:59:48 +01:00
Dan Streetman f3808b872f sd-dhcp-client: correct retransmission timeout to match RFC
This changes the retransmission timeout algorithm for requests
other than RENEW and REBIND. Previously, the retransmission timeout
started at 2 seconds, then doubling each retransmission up to a max
of 64 seconds. This is changed to match what RFC2131 section 4.1 describes,
which skips the initial 2 second timeout and starts with a 4 second timeout
instead. Note that -1 to +1 seconds of random 'fuzz' is added to each
timeout, in previous and current behavior.

This change is therefore slightly slower than the previous behavior in
attempting retransmissions when no server response is received, since the
first transmission times out in 4 seconds instead of 2.

Since TRANSIENT_FAILURE_ATTEMPTS is set to 3, the previous length of time
before a transient failure was reported back to systemd-networkd was
2 + 4 + 8 = 14 seconds, plus, on average, 3 seconds of random 'fuzz' for
a transient failure timeout between 11 and 17 seconds. Now, since the
first timeout starts at 4, the transient failure will be reported at
4 + 8 + 16 = 28 seconds, again plus 3 random seconds for a transient
failure timeout between 25 and 31 seconds.

Additionally, if MaxAttempts= is set, it will take slightly longer to
reach than with previous behavior.
2020-12-14 18:19:29 -05:00
Dan Streetman c24288d21e sd-dhcp-client: correct dhcpv4 renew/rebind retransmit timeouts
Use the request timeout algorithm specified in RFC2131 section 4.4.5 for
handling timed out RENEW and REBIND requests.

This changes behavior, as previously only 2 RENEW and 2 REBIND requests
were sent, no matter how long the lease lifetime. Now, requests are
send according to the RFC, which results in starting with a timeout
of 1/2 the t1 or t2 period, and halving the timeout for each retry
down to a minimum of 60 seconds.

Fixes: #17909
2020-12-14 18:19:22 -05:00
Dan Streetman b0d7d8063c sd-dhcp-client: simplify dhcp4 t1/t2 parsing
The parsing of the dhcpv4 lease lifetime, as well as the t1/t2
times, is simplified by this commit.

This differs from previous behavior; previously, the lease lifetime and
t1/t2 values were modified by random 'fuzz' by subtracting 3, then adding
a random number between 0 and (slightly over) 2 seconds. The resulting
values were therefore always between 1-3 seconds shorter than the value
provided by the server (or the default, in case of t1/t2). Now, as
described in RFC2131, the random 'fuzz' is between -1 and +1 seconds,
meaning the actual t1 and t2 value will be up to 1 second earlier or
later than the server-provided (or default) t1/t2 value.

This also differs in handling the lease lifetime, as described above it
previously was adjusted by the random 'fuzz', but the RFC does not state
that the lease expiration time should be adjusted, so now the code uses
exactly the lease lifetime as provided by the server with no adjustment.
2020-12-14 18:19:07 -05:00
Dan Streetman 3d75a443ee sd-dhcp-client: add RFC2131 retransmission details
RFC2131, providing the details for dhcpv4, has specific retransmission
intervals that it outlines. This adds functions to compute the timeouts
as the RFC describes.
2020-12-14 18:19:01 -05:00
Dan Streetman 0c3c59783b sd-dhcp-client: track dhcp4 t1, t2, expire times
Add fields to dhcp4 client to track t1, t2, and lease expiry times
2020-12-14 17:39:26 -05:00
Dan Streetman f3bd46c657 sd-dhcp-client: don't log timeouts if already expired 2020-12-14 17:39:26 -05:00
Yu Watanabe 878c035a48 sd-ipv4acd: logs current state 2020-12-02 18:42:17 +09:00
Yu Watanabe 3f2c0d8520 sd-ipv4acd,sd-ipv4ll: include interface name in the debug logs 2020-12-02 18:42:13 +09:00
Yu Watanabe 99b06a2f5c sd-ipv4acd,sd-ipv4ll: introduce _get_ifindex() and _get_ifname()
They will be used in later commits.

This also makes sd_ipv4acd_set_ifindex() check the existence of the interface.
2020-12-02 18:40:24 +09:00
Zbigniew Jędrzejewski-Szmek fb536bc5da sd-dhcp-client: report transient DHCP failure to the caller
So far we only reported major state transitions like failure to acquire
the message. Let's report the initial failure after a few timeouts in
a new event type.

The number of timeouts is hardcoded as 3, since Windows seems to be using
that. I don't think we need to make this configurable out of the box. A
reasonable default may be enough.
2020-11-30 12:37:36 +09:00
Zbigniew Jędrzejewski-Szmek e4dc0845bc sd-dhcp-client: minor simplification 2020-11-30 12:37:36 +09:00
Yu Watanabe 0d5eb02134
Merge pull request #17478 from yuwata/split-network-internal
libsystemd-network: split network-internal.c
2020-11-27 09:04:19 +09:00
Jörg Thalheim 1d370b2c18 networkd/dhcp6: allow layer3 devices without MAC
Devices with multicast but without mac addresses i.e. tun devices
are not getting setuped correctly:

$ ip tuntap add mode tun dev tun0
$ ip addr show tun0
16: tun0: <NO-CARRIER,POINTOPOINT,MULTICAST,NOARP,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 500
    link/none
$ cat /etc/systemd/network/tun0.network
[Match]
Name = tun0

[Network]
Address=192.168.1.1/32
$ ./systemd-networkd
tun0: DHCP6 CLIENT: Failed to set identifier: Invalid argument
tun0: Failed
2020-11-23 13:56:48 +01:00
Yu Watanabe 787dd704e1 sd-dhcp6-client: insert spaces around ternary operator 2020-11-16 18:59:28 +09:00
Zbigniew Jędrzejewski-Szmek b5c474f69b libsystemd-network: add comment explaining unusual memory access
Inspired by coverity CID#1435984. I'm confused by the union definion every time I look at it...
Let's at least add a comment to help future readers.
2020-11-10 15:52:32 +01:00
Yu Watanabe dd1b187075 sd-radv: refuse to set preference except medium when router lifetime is zero 2020-11-10 00:04:52 +09:00
Yu Watanabe ac138551ce sd-radv: router lifetime is uint16_t 2020-11-10 00:04:52 +09:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Zbigniew Jędrzejewski-Szmek 58f848148f
Merge pull request #17444 from BtbN/fix_ib_dhcp4
networkd: fix DHCP on InfiniBand interfaces
2020-10-29 19:27:29 +01:00
Zbigniew Jędrzejewski-Szmek 4368277c74 tree-wide: use the usual SPDX header for our own files 2020-10-29 10:47:20 +01:00
Yu Watanabe 26f4d32365 meson: drop libsystemd_network from several binaries
This reduces the size of udevadm:

Before:
```
$ ll udevadm
-rwxrwxr-x 1 watanabe watanabe 1203800 Oct 29 01:36 udevadm
```

After:
```
$ ll udevadm
-rwxrwxr-x 1 watanabe watanabe 1094384 Oct 29 01:38 udevadm
```
2020-10-29 14:23:49 +09:00
Yu Watanabe 01ab92af71 tree-wide: drop unnecessary inclusion of network-internal.h 2020-10-29 14:23:49 +09:00
Yu Watanabe dc7f6c9b94 sd-network: move net_get_unique_predictable_data() and net_get_name_persisten() 2020-10-29 14:23:49 +09:00
Yu Watanabe 7e19cc5462 net-condition: move net_match_config() and related conf parsers 2020-10-29 14:23:49 +09:00
Yu Watanabe 1929ed0e58 sd-network: move link_get_type_string() 2020-10-29 14:23:49 +09:00
Yu Watanabe 0ec2a7a125 libsystemd-network: move config_parse_hwaddr() and config_parse_hwaddrs() 2020-10-29 14:23:49 +09:00
Yu Watanabe fc27088ae7 udev: move config_parse_ifalias() 2020-10-29 14:23:49 +09:00
Yu Watanabe 796aa313b3 network: move config_parse_bridge_port_priority() 2020-10-29 14:23:49 +09:00
Yu Watanabe 6a74900002 libsystemd-network: make conf parsers accept an empty string 2020-10-29 14:23:49 +09:00
Yu Watanabe 7e7aa4e811 libsystemd-network: downgrade log level in conf parsers 2020-10-29 14:23:49 +09:00
Timo Rothenpieler 14b66dbc92 dhcp4: fix DHCP on InfiniBand interfaces
With these patches applied, networkd is successfully able to get an
address from a DHCP server on an IPoIB interface.

1)
Makes networkd pass the actual interface type to the dhcp client,
instead of hardcoding it to Ethernet.

2)
Fixes some issues in handling the larger (20 Byte) IB MAC addresses in
the dhcp code.

3)
Add a new field to networkds Link struct, which holds the interface
broadcast address.

3.1)
Modify the DHCP code to also expect the broadcast address as parameter.
On an Ethernet-Interface the Broadcast address never changes and is always
all 6 bytes set to 0xFF.
On an IB one however it is not neccesarily always the same, thus
fetching the actual address from the interface is neccesary.

4)
Only the last 8 bytes of an IB MAC are stable, so when using an IB MAC to
generate a client ID, only pass those 8 bytes.
2020-10-28 14:44:43 +01:00
Yu Watanabe 5a8775bb39 Revert "sd-dhcp-client: use asynchronous_close()"
This effectively reverts the commit 22fc2420b2.

The function `asynchronous_close()` confuses valgrind. Before this commit,
valgrind may report the following:

```
HEAP SUMMARY:
    in use at exit: 384 bytes in 1 blocks
  total heap usage: 4,787 allocs, 4,786 frees, 1,379,191 bytes allocated

384 bytes in 1 blocks are possibly lost in loss record 1 of 1
   at 0x483CAE9: calloc (vg_replace_malloc.c:760)
   by 0x401456A: _dl_allocate_tls (in /usr/lib64/ld-2.31.so)
   by 0x4BD212E: pthread_create@@GLIBC_2.2.5 (in /usr/lib64/libpthread-2.31.so)
   by 0x499B662: asynchronous_job (async.c:47)
   by 0x499B7DC: asynchronous_close (async.c:102)
   by 0x4CFA8B: client_initialize (sd-dhcp-client.c:696)
   by 0x4CFC5E: client_stop (sd-dhcp-client.c:725)
   by 0x4D4589: sd_dhcp_client_stop (sd-dhcp-client.c:2134)
   by 0x493C2F: link_stop_clients (networkd-link.c:620)
   by 0x4126DB: manager_free (networkd-manager.c:867)
   by 0x40D193: manager_freep (networkd-manager.h:97)
   by 0x40DAFC: run (networkd.c:20)

LEAK SUMMARY:
   definitely lost: 0 bytes in 0 blocks
   indirectly lost: 0 bytes in 0 blocks
     possibly lost: 384 bytes in 1 blocks
   still reachable: 0 bytes in 0 blocks
        suppressed: 0 bytes in 0 blocks

For lists of detected and suppressed errors, rerun with: -s
ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
```
2020-10-24 13:27:37 +02:00
Lennart Poettering 69f30d4321
Merge pull request #17356 from yuwata/sd-xxx-stop
network: about sd_xxx_stop()
2020-10-21 18:07:38 +02:00
Lennart Poettering 141261f127 dhcp-server: make parameter const 2020-10-21 15:02:16 +09:00
Yu Watanabe c8bae36372 libsystemd-network: do not request each daemon exist in sd_xxx_stop() 2020-10-15 07:24:17 +09:00
Yu Watanabe 4081756a63 sd-dhcp-client: make sd_dhcp_client_set_request_option() not return -EEXIST
Fixes #16964.
2020-10-14 12:54:55 +09:00
Frantisek Sumsal d46b79bbe0 tree-wide: drop if braces around single line expressions as well 2020-10-09 15:11:55 +02:00
Frantisek Sumsal d7a0f1f4f9 tree-wide: assorted coccinelle fixes 2020-10-09 15:02:23 +02:00
Frantisek Sumsal 1d6cc5d0e5 tree-wide: coccinelle fixes 2020-10-04 12:32:21 +02:00
mog422 26a63b8132
sd-dhcp6-client: Fix sending prefix delegation request (#17136)
SD_DHCP6_OPTION_IA_NA does not exist in DHCP6_ADVERTISE packet if DHCP server only provides prefix delegation. So the attempt to send the DHCP6_REQUEST packet fails on r = dhcp6_option_append_ia(&opt, &optlen, &client->lease->ia); forever.
2020-09-24 17:04:52 +02:00
Lennart Poettering bcaf20dc38
Merge pull request #17143 from keszybz/late-exec-resolution-alt
Late exec resolution (subset)
2020-09-24 09:38:36 +02:00
Lennart Poettering 6333aa9d46 sd-radv: fix indentation
Fix-up for 97efde65d8
2020-09-23 13:44:26 +02:00
Zbigniew Jędrzejewski-Szmek afa8ffae99 various: remove assignments of unread variables 2020-09-22 17:58:11 +02:00
Zbigniew Jędrzejewski-Szmek 0706c01259 Add CLOSE_AND_REPLACE helper
Similar to free_and_replace. I think this should be uppercase to make it
clear that this is a macro. free_and_replace should probably be uppercased
too.
2020-09-18 15:28:48 +02:00
Lennart Poettering 40eb1b0ae8 tree-wide: prefer AF_xyz over PF_xyz
This really doesn't matter given that AF_xyz and PF_xyz are equivalent
in all ways, but we almost always use AF_xyz, hence stick to it
universally and convert the remaining PF_ to AF_
2020-09-09 23:42:55 +02:00