Commit Graph
1602 Commits
Author SHA1 Message Date
Rene Hollander 930133d5df networkd/dhcpserver: Save and expose the client hostname sent when requesting a DHCP lease.
DHCP clients often send their own hostname in option 12. It can be useful
to store it with the lease so it can be shown to a human to easily identify
which lease belongs to which device.

RFC: https://www.rfc-editor.org/rfc/rfc2132#section-3.14
2023-06-01 06:51:45 +09:00
Frantisek Sumsal f018fad483 sd-network: use structured initialization
And squash one unnecessary assignment.
2023-05-30 21:35:33 +02:00
Frantisek Sumsal aca607d18d sd-network: avoid leaking DHCPLease
If we fail any allocation prior adding the lease to the server lease
hashmap.

==2103==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 128 byte(s) in 2 object(s) allocated from:
    #0 0x4a203e in __interceptor_calloc /src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:77:3
    #1 0x4f6341 in calloc (/build/fuzz-dhcp-server+0x4f6341)
    #2 0x4ec818 in add_lease /work/build/../../src/systemd/src/libsystemd-network/fuzz-dhcp-server.c:26:9
    #3 0x4ec2bf in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/libsystemd-network/fuzz-dhcp-server.c:75:9
    #4 0x4f68a8 in NaloFuzzerTestOneInput (/build/fuzz-dhcp-server+0x4f68a8)
    #5 0x5158b3 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:611:15
    #6 0x51509a in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool, bool*) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:514:3
    #7 0x516769 in fuzzer::Fuzzer::MutateAndTestOne() /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:757:19
    #8 0x517435 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, std::__Fuzzer::allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:895:5
    #9 0x50679f in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:912:6
    #10 0x507068 in LLVMFuzzerRunDriver /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:925:10
    #11 0x4f6b25 in main (/build/fuzz-dhcp-server+0x4f6b25)
    #12 0x7f16084e3082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)

DEDUP_TOKEN: __interceptor_calloc--calloc--add_lease
SUMMARY: AddressSanitizer: 128 byte(s) leaked in 2 allocation(s).

Found by Nallocufzz.
2023-05-26 16:16:25 +02:00
David Tardon d6f2cd671c tree-wide: use free_and_replace() more 2023-05-24 14:59:07 +02:00
Daan De Meyer 3d41b6b8e8 tree-wide: Fix false positives on newer gcc
Recent gcc versions have started to trigger false positive
maybe-uninitialized warnings. Let's make sure we initialize
variables annotated with _cleanup_ to avoid these.
2023-05-23 19:45:27 +01:00
Yu Watanabe 0c3ea0c222 sd-dhcp-server: also send DNS servers or friends on DHCPOFFER
From RFC 2131 section 4.3.1 (https://www.rfc-editor.org/rfc/rfc2131#section-4.3.1):
----
The server MUST return to the client:
- Parameters requested by the client, according to the following rules:
  -- IF the server has been explicitly configured with a default
     value for the parameter, the server MUST include that value
     in an appropriate option in the 'option' field,
----
The sentence is not only for ACK, but for all (positive) responses, that
is DHCPOFFER and DHCPACK.

Fixes #27471.
2023-05-13 12:37:17 +01:00
Yu Watanabe 251ca88230 sd-dhcp-client: client ID always has non-zero data
Follow-up for f04c991a2f.
Fixes CID#1510978.
2023-05-09 14:41:55 +01:00
Yu Watanabe e69c281ad2 sd-dhcp-client: do not use implicit cast to boolean 2023-05-09 00:37:29 +09:00
Yu Watanabe f04c991a2f sd-dhcp-client: make return arguments for sd_dhcp_client_get_client_id() optional 2023-05-09 00:34:06 +09:00
Yu Watanabe 22e299fc5e sd-dhcp-client: drop redundant condition
Closes #27561.
2023-05-09 00:27:24 +09:00
Robert Meijers 4646cdaa37 networkd: fallback to chaddr for static lease lookup when not found
DHCP static leases are looked up by the client identifier as send by
the client, while configured based on MAC. As RFC 2131 states the client
identifier is an opaque key and must not be interpreted by the server
this means that DHCP clients can (/will) also use a client identifier
which is not a MAC address. One of these clients actually is
systemd-networkd which uses an RFC 4361 by default to generate the
client identifier. For these kind of DHCP clients static leases thus
don't work because of this mismatch between configuring a MAC address
but the server matching based on client identifier. This adds a fallback
to try to look up a configured static lease based on the "chaddr" of the
DHCP message as this will always contain the MAC address of the client.

Fixes #21368
2023-04-20 19:18:50 +09:00
Yu Watanabe b5d39bb3ca tree-wide: also use CMSG_TYPED_DATA() on writing message header 2023-04-16 13:26:58 +09:00
Yu Watanabe 1ebb0953f0 sd-dhcp-server: use CMSG_FIND_DATA() at one more place 2023-04-16 13:26:58 +09:00
Yu Watanabe 789f5c6f70 tree-wide: copy timestamp data from cmsg
On RISCV32, time_t is 64bit and size_t is 32bit, hence the timestamp
data in message header may not be aligned.

Fixes #27241.
2023-04-16 13:26:58 +09:00
Lennart Poettering b1d0219136 tree-wide: port more code over to CMSG_TYPED_DATA() 2023-04-13 10:49:23 +02:00
Frantisek Sumsal 1da3cb8141 tree-wide: simplify x ? x : y to x ?: y where applicable 2023-03-18 14:23:11 +01:00
Jan Janssen 9214828313 meson: Introduce userspace dep
This will help in a later commit to separate userspace from EFI builds.
2023-03-10 11:40:14 +01:00
Yu Watanabe 58fbf167d7 Merge pull request #26528 from keszybz/valgrind-simplification
Drop the -Dvalgrind configuration option
2023-02-22 23:04:12 +09:00
Zbigniew Jędrzejewski-Szmek 50b35193ec meson: merge our two valgrind configuration conditions into one
Most of the support for valgrind was under HAVE_VALGRIND_VALGRIND_H, i.e. we
would enable if the valgrind headers were found. The operations then we be
conditionalized on RUNNING_UNDER_VALGRIND.

But in a few places we had code which was conditionalized on VALGRIND, i.e. the
config option. I noticed because I compiled with -Dvalgrind=true on a machine
that didn't have valgrind.h, and the build failed because
RUNNING_UNDER_VALGRIND was not defined. My first idea was to add a check that
the header is present if the option is set, but it seems better to just remove
the option. The code to support valgrind is trivial, and if we're
!RUNNING_UNDER_VALGRIND, it has negligible cost. And the case of running under
valgrind is always some special testing/debugging mode, so we should just do
those extra steps to make valgrind output cleaner. Removing the option makes
things simpler and we don't have to think if something should be covered by the
one or the other configuration bit.

I had a vague recollection that in some places we used -Dvalgrind=true not
for valgrind support, but to enable additional cleanup under other sanitizers.
But that code would fail to build without the valgrind headers anyway, so
I'm not sure if that was still used. If there are uses like that, we can
extend the condition for cleanup_pools().
2023-02-22 11:39:44 +01:00
Jan Janssen 2ed35b2f3e meson: Use dicts for fuzzer definitions 2023-02-21 15:10:26 +01:00
Jan Janssen 822cd3ff25 meson: Use dicts for test definitions
Although this slightly more verbose it makes it much easier to reason
about. The code that produces the tests heavily benefits from this.

Test lists are also now sorted by test name.
2023-02-21 15:10:26 +01:00
Yu Watanabe 0b75493da0 tree-wide: fix typo and comment style update 2023-02-15 10:08:16 +09:00
Zbigniew Jędrzejewski-Szmek d42add3c17 sd-network: stop using fake flexible array 2023-02-06 10:19:52 +01:00
Yu Watanabe b52031dbbc sd-dhcp-server: allow to send header only message
If we receive a header only message, and the server is running in relay
mode, then the assertion was triggered.

Fixes #26151.
2023-01-28 10:44:30 +00:00
Jan Janssen 4a7ee0a521 meson: Do not include headers in source lists
Meson+ninja+compiler do this for us and are better at it.

https://mesonbuild.com/FAQ.html#do-i-need-to-add-my-headers-to-the-sources-list-like-in-autotools
2023-01-24 22:04:03 +01:00
Lennart Poettering 7153213e40 string-util: add common implementation of function that converts sized character buffers to NUL terminated C strings 2023-01-21 10:45:25 +01:00
Luca Boccassi a6a9ee4b36 Merge pull request #26115 from yuwata/test-fix-memleak-fdleak
test: fix memleak and fd leak
2023-01-20 11:00:53 +00:00
Yu Watanabe d09df6b94e tree-wide: fix typo 2023-01-20 15:32:16 +09:00
Yu Watanabe 86d82cb888 test-ndisc: fix memleak and fd leak
Fixes issues reported at #22576.
2023-01-20 14:54:53 +09:00
chris b895aa5ff5 send dhcpv6 release when stopping 2023-01-17 21:26:18 +09:00
Yu Watanabe 841dfd3dc0 sd-dhcp-client: gracefully handle invalid ether type client ID
Currently, sd-dhcp-server accepts spurious client IDs, then the leases
exposed by networkd may be invalid. Let's make networkctl gracefully
show such leases.

Fixes #25984.
2023-01-16 20:00:08 +00:00
Yu Watanabe ea9dbf51c6 sd-dhcp6: always append the default status message generated from status code
Fixes #25988.
2023-01-16 19:46:05 +00:00
chris ea57796854 optionally set socket priority on DHCPv4 raw socket 2023-01-12 13:26:47 +09:00
Cristian Rodríguez 2cc697d740 libsystemd-network: FTBS in c2x mode
cannot pass false as argument because function wants a pointer to bool
instead, use NULL instead
2023-01-03 15:58:55 +01:00
Yu Watanabe 5bb1d7fbab tree-wide: use -EBADF more 2022-12-21 01:50:33 +09:00
Yu Watanabe 19ee48a6c2 tree-wide: introduce PIPE_EBADF macro 2022-12-20 11:12:58 +09:00
Yu Watanabe f26c38edfa fuzz: sort headers 2022-12-20 11:12:58 +09:00
Zbigniew Jędrzejewski-Szmek 3401477982 tree-wide: use -EBADF also in pipe initializers
In some places, initialization is dropped when unnecesary.
2022-12-19 15:00:59 +01:00
Zbigniew Jędrzejewski-Szmek 254d1313ae tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various
places. Let's make things consistent in the new style.

Note that there are two candidates:
EBADF 9 Bad file descriptor
EBADFD 77 File descriptor in bad state

Since we're initializating the fd, we're just assigning a value that means
"no fd yet", so it's just a bad file descriptor, and the first errno fits
better. If instead we had a valid file descriptor that became invalid because
of some operation or state change, the other errno would fit better.

In some places, initialization is dropped if unnecessary.
2022-12-19 15:00:57 +01:00
Thomas Haller 6759b62720 all: avoid various "-Wcast-align=strict" warnings 2022-12-09 08:58:07 +01:00
Zbigniew Jędrzejewski-Szmek 3ae6b3bf72 basic: rename util.h to logarithm.h
util.h is now about logarithms only, so we can rename it. Many files included
util.h for no apparent reason… Those includes are dropped.
2022-11-08 18:21:10 +01:00
Yu Watanabe 14805b1468 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()`.
2022-10-27 09:12:47 +09:00
Yu Watanabe 793178b987 sd-dhcp6-client: introduce sd_dhcp6_client_attach_device()
It will be used later.
2022-10-26 08:08:35 +09:00
Yu Watanabe be615f7c14 sd-dhcp-client: introduce sd_dhcp_client_attach_device()
It will be used later.
2022-10-26 08:08:35 +09:00
Zbigniew Jędrzejewski-Szmek 0923b4253c tree-wide: replace "plural(s)" by "plurals"
(s) is just ugly with a vibe of DOS. In most cases just using the normal plural
form is more natural and gramatically correct.

There are some log_debug() statements left, and texts in foreign licenses or
headers. Those are not touched on purpose.
2022-10-17 15:10:53 +02:00
Yu Watanabe 6c65a9e1d6 Merge pull request #24973 from keszybz/simplify-variable-declarations
Simplify variable declarations
2022-10-12 19:36:47 +09:00
Zbigniew Jędrzejewski-Szmek 59818f4381 libsystemd-network: trivial simplification 2022-10-12 09:18:24 +02:00
Zbigniew Jędrzejewski-Szmek 1d3fae91f7 Merge pull request #24867 from yuwata/sd-dhcp6-client-large-packet
sd-dhcp6-client: allow to build large packet
2022-10-12 09:18:07 +02:00
Luca Boccassi dd4212105e Merge pull request #24957 from yuwata/network-ignore-failure-in-sending-solicitation
network: ignore failure in sending solicitation
2022-10-11 21:58:26 +02:00
Zbigniew Jędrzejewski-Szmek 0b6a47957b tree-wide: drop () around the first argument of a ternary op
https://github.com/systemd/systemd/pull/24933#discussion_r991242789
2022-10-11 16:59:00 +02:00