dhcp: use the attached sd_device object when generating IAID
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 Oct 2022 21:56:25 +0000 (06:56 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 27 Oct 2022 00:12:47 +0000 (09:12 +0900)
commit14805b1468dc73bc10d90b69975a5c8914609bb7
tree2a25704e5d27f1db1aa397f0ec6685e6ccdb6fb2
parent3b1dbdf0c260cafaf83bfa6ddabaa163c017f5cf
dhcp: use the attached sd_device object when generating IAID

Note, previously `use_mac` set with `test_mode`. As `dev`, which is set with
`client->dev`, is not set when running test or fuzzer. Hence, the condition
```
if (udev_available() && !use_mac)
```
is effectively equivalent to
```
if (dev)
```
So, this commit mostly does not change behavior. Except for the following
corner case.

The sd_device object assigned from networkd (that is, Link.dev) never
has ID_RENAMING udev property, as sd_device objects which has the property
are filtered out at `link_check_initialized()` or `manager_udev_process_link()`
in networkd-link.c.

However, sd_device object created in `dhcp_identifier_set_iaid()` in the
previous code may have it. Such situation may (at least, theoretically)
happen when the network interface is renamed after initialized, e.g. by
creating the following spurious .link file:
```
[Match]
OriginalName=eno1
[Link]
Name=lan
```
and then trigger uevent for the network interface while systemd-networkd
calling `dhcp_identifier_set_iaid()`.
src/libsystemd-network/dhcp-identifier.c
src/libsystemd-network/dhcp-identifier.h
src/libsystemd-network/dhcp6-internal.h
src/libsystemd-network/sd-dhcp-client.c
src/libsystemd-network/sd-dhcp6-client.c
src/libsystemd-network/test-dhcp-client.c