Commit Graph
1862 Commits
Author SHA1 Message Date
Yu Watanabe a925620f5f sd-ndisc: do not print "(null)" in the log message
If we received RA with no flags set, or with an invalid preference,
previously "(null)" was printed.

Follow-up for 238ed432c3.

Fixes https://github.com/systemd/systemd/pull/32308#discussion_r1600940289.
2024-05-22 22:07:58 +02:00
Yu Watanabe f8ef1df3d1 test: extend timeout for DHCP/NDisc tests
Fixes https://github.com/systemd/systemd/pull/32932#issuecomment-2120424121.
2024-05-20 22:55:07 +02:00
Luca Boccassi 5de20f5619 Merge pull request #32818 from keszybz/libsystemd-network-size-check
Check packet size in libsystemd-network
2024-05-15 17:33:22 +02:00
Zbigniew Jędrzejewski-Szmek 8e41e460e0 test: rename file with stub functions
icmp6-util-linux.c sounds like a specialized implementation of the functions in
icmp6-util.c. But it's just a set of stub versions used in tests. Rename the
file to make this more obvious.
2024-05-14 18:56:41 +02:00
Zbigniew Jędrzejewski-Szmek b17b91db80 libsystemd-network: use normal style for error checking
We generally use a flat list. The switch stmt was generating excessive
indentation.
2024-05-14 18:56:41 +02:00
Zbigniew Jędrzejewski-Szmek caa4bfd468 libsystemd-network: check size of icmpv6 packets
Coverity was complaining that we use the received packet size as a loop bound
without checking. This is indeed a bit iffy, because depending on how the host
is configured, the packet could be rather large. Let's refuse anything more
than the standard size early to prevent suspicious activity.

Resolves coverity CID#1534892, CID#1543949.
2024-05-14 18:56:35 +02:00
Zbigniew Jędrzejewski-Szmek f7a6418d47 libsystemd-network: remove double initialization 2024-05-14 18:55:34 +02:00
Radoslav Kolev 19614a08d1 libsystemd-network: skip dhcp server test in case of EAFNOSUPPORT
We want to eanble running tests as part of the build, but
our builds run in VMs with networking disabled.
2024-05-14 15:00:29 +02:00
Sebastian Pucilowski e6c4b5dc52 network: DHCP version logging typos
Some DHCP client log messages report "DHCP4" or "DHCP6" instead of
"DHCPv4" or "DHCPv6" as used within the rest of the codebase. Typos
fixed.
2024-04-28 11:47:55 +09:00
Luca Boccassi ffd8149bc0 sd-radv: remove unnecessary check
in6_addr_prefix_intersect() returns a bool, so the check < 0 is
dead code. Flagged by codeql.

Follow-up for c7c56724a5
2024-04-26 07:03:27 +09:00
Yu Watanabe c7c56724a5 sd-radv: use in6_addr_prefix_intersect() 2024-04-24 12:22:05 +09:00
Yu Watanabe 9dc2503539 sd-radv: allow to send multiple routes or prefix64 that have intersection with others
I cannot find any RFC that states we should not send multiple route
prefix or pref64 options that have intersection with others.
Moreover, each route prefix option has preference field, thus, user may
want to send e.g. a prefix with the normal preference, and another sub
prefix with the high preference. Previously, such configuration was
prohibited. Let's allow that now.
2024-04-24 12:22:05 +09:00
Yu Watanabe 96dd66eddf sd-radv: send RA on update in caller side
As the caller may want to update multiple prefixes and friends.
Let's not automatically announce on update in library side.

Currently, only prefix is updated during running. Hence, this does not
change any effective behavior.
2024-04-24 12:22:05 +09:00
Yu Watanabe 59d475ba40 network/radv: introduce ReachableTimeSec= setting
To make the reachable time in the RA header sent by networkd
configurable.
2024-04-22 18:41:37 +09:00
Yu Watanabe bc50700c7e sd-radv: allow to configure reachable time in RA header 2024-04-22 18:40:10 +09:00
Yu Watanabe 1fea917a1b sd-radv: use sd_radv_is_running()
This also drops several unnecessary conditions for checking sd-radv is running
or not in setting options, e.g. home agent or mac address.
2024-04-20 14:59:27 +09:00
Yu Watanabe 89d7f069d3 sd-radv: shorten enumerated type definition 2024-04-20 14:59:27 +09:00
Luca Boccassi 0c8780babf Merge pull request #32346 from yuwata/sd-radv-handle-header-param-gracefully
sd-radv: handle header param gracefully
2024-04-19 21:14:21 +02:00
Yu Watanabe 2a1e890943 sd-radv: reset timer on sending unsolicited RA
Addresses https://github.com/systemd/systemd/pull/32267#discussion_r1567078807.
2024-04-19 12:05:41 +09:00
Yu Watanabe 16e4dce6e8 sd-radv: expose sd_radv_send()
To allow library users manually send RA.
Currently, this is not used, but will be used later.
2024-04-19 12:04:58 +09:00
Yu Watanabe ba5dc3afad sd-radv: set router preference gracefully
Rather than refusing to set non-zero preference, when lifetime is zero,
let's handle that gracefully on send.
2024-04-19 11:44:59 +09:00
Yu Watanabe 03401969d4 sd-radv: allow to modify RA header elements without stopping sd-radv
This also makes too large retransmit time handled gracefully,
as even if a too large value is specified, usec_to_be32_msec() in
radv_send_router() will handle it gracefully anyway.
Note, networkd still refuses such invalid values. Hence, this does not
change any effective behavior.
2024-04-19 11:44:59 +09:00
Luca Boccassi e54bf3fe0b Merge pull request #32299 from yuwata/network-radv-ignore-rs-from-the-same-interface
network/radv: ignore RS message from the same interface
2024-04-18 23:45:06 +02:00
Luca Boccassi 7f4f75593d Merge pull request #32292 from yuwata/sd-radv-send-on-stop
sd-radv: set only basic information in RA message on stop
2024-04-18 23:24:42 +02:00
Yu Watanabe 50ba4e401a sd-radv: refuse packet from the same interface
Prompted by https://github.com/systemd/systemd/pull/32267#discussion_r1566721306.
2024-04-18 09:40:23 +09:00
Yu Watanabe 258729a3b8 Merge pull request #32308 from yuwata/sd-ndisc-disable-timer-on-recv
sd-ndisc: disable one more timer event source
2024-04-18 09:28:16 +09:00
Yu Watanabe 54a4ffc077 fuzz-ndisc-rs: also test packets with sd-radv
Addresses https://github.com/systemd/systemd/pull/32267#discussion_r1566715787.

Suggested-by: Evgeny Vereshchagin <evvers@ya.ru>
2024-04-17 11:12:42 +03:00
Yu Watanabe 238ed432c3 sd-ndisc: improve debugging logs 2024-04-17 13:23:44 +09:00
Yu Watanabe 31db4c1bd5 sd-ndisc: disable one more timer event source
Otherwise, even if we have already received RA, timeout callback will be
called. Currently, networkd mostly does nothing on timeout, hence should
not change any effective behavior.

Follow-up for e7cb80474d.
2024-04-17 13:23:44 +09:00
Yu Watanabe 69628e3b3b sd-radv: drop unnecessary argument
The argument always has the same value.
2024-04-16 11:18:33 +09:00
Yu Watanabe 19f3cc86a0 sd-radv: set only basic information on stop
There are many possible reasons to stop the service;
tentative reboot of the service or the system, the router may be
revoked, and so on.
And, each situations, the availability of the previously announced
options e.g. prefixes, DNSSL and so on is not clear.
So, let's announce only the clear information, that is, the router
lifetime is zero. which indicates that the router will be invalidated
(regardless tentative or not).
2024-04-16 11:18:33 +09:00
Yu Watanabe cc2bcbf605 sd-radv: use ICMP6Packet and sd_ndisc_router_solicit
Then, sd-radv can reject invalid Router Solicit messages, e.g. that have
invalid options.

No effective functional change, just refactoring.
2024-04-16 09:59:52 +09:00
Yu Watanabe 8c1f24fb95 sd-radv: introduce sd_ndisc_router_solicit
It is not used in this stage, but will be used later in sd-radv.
2024-04-16 09:59:48 +09:00
Yu Watanabe 9506269d12 Merge pull request #32266 from yuwata/libsystemd-network-trivial-cleanups
libsystemd-network: trivial cleanups
2024-04-15 14:43:12 +09:00
Yu Watanabe 049bdac7b6 ndisc-option: add missing case
Follow-up for 9f3587ae44.
2024-04-15 14:41:45 +09:00
Yu Watanabe ac336e754e sd-ndisc: make ndisc_send() and icmp6_send() take struct in6_addr
No functional change, just refactoring.
2024-04-15 06:23:11 +09:00
Yu Watanabe 2c28eb0266 libsystemd-network: make constant addresses type-safe
No functional change, just refactoring.
2024-04-15 06:23:11 +09:00
Yu Watanabe dea17a0864 dhcp6-network: constify arguments
No functional change, just refactoring.
2024-04-15 06:23:11 +09:00
Mike Yuan d2198b3206 sd-dhcp-server: use close_and_replace (avoid fd leak)
Follow-up for 11b88419ae

Fixes #32252
2024-04-13 02:48:52 +08:00
Mike Yuan 3c321488bc sd-dhcp-server: check dir_fd with assert_return 2024-04-13 02:48:52 +08:00
Yu Watanabe 296afa8477 ndisc-option: also ignore Prefix Information option with multicast address
Fixes https://github.com/systemd/systemd/pull/32215#issuecomment-2049624693
2024-04-12 10:34:12 +01:00
Yu Watanabe bffa1c4889 sd-ndisc-redirect: fix verification of target address
See RFC 4861 section 8.1.
2024-04-12 04:59:42 +09:00
Yu Watanabe 8e91738fe9 libsystemd-network: do not trigger assertion by sd_*_is_running() with NULL
If systemd is built with developer mode, previously they trigger
hard assertions. Even built with release mode, we should not log about
that. Let's silently accept NULL and return false.

Prompted by https://github.com/systemd/systemd/pull/32166#issuecomment-2044710151.
2024-04-10 22:53:55 +01:00
Lennart Poettering 475107f014 ndisc: use memzero() where appropriate 2024-04-10 16:54:20 +09:00
Frantisek Sumsal edda10f2ae tree-wide: make sure net/if.h is included before any linux/ header
The linux/ headers include linux/libc-compat.h that makes sure the
linux/ headers won't redeclare symbols already declared by net/if.h, but
glibc's net/if.h doesn't do that, so if the include order is reversed
we'll end up with a bunch of errors about redeclared stuff:

[3/519] Compiling C object test-network-tables.p/src_network_test-network-tables.c.o
FAILED: test-network-tables.p/src_network_test-network-tables.c.o
cc -Itest-network-tables.p -I. -I.. -Isrc/basic -I../src/basic -Isrc/fundamental -I../src/fundamental -Isrc/systemd -I../src/systemd -I../src/libsystemd/sd-bus -I../src/libsystemd/sd-device -I../src/libsystemd/sd-event -I../src/libsystemd/sd-hwdb -I../src/libsystemd/sd-id128 -I../src/libsystemd/sd-journal -I../src/libsystemd/sd-netlink -I../src/libsystemd/sd-network -I../src/libsystemd/sd-resolve -Isrc/shared -I../src/shared -Isrc/libsystemd-network -I../src/libsystemd-network -Isrc/network -I../src/network -I../src/network/netdev -I../src/network/tc -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O0 -g -Wno-missing-field-initializers -Wno-unused-parameter -Wno-nonnull-compare -Warray-bounds -Warray-bounds=2 -Wdate-time -Wendif-labels -Werror=format=2 -Werror=format-signedness -Werror=implicit-function-declaration -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Werror=missing-declarations -Werror=missing-prototypes -Werror=overflow -Werror=override-init -Werror=return-type -Werror=shift-count-overflow -Werror=shift-overflow=2 -Werror=strict-flex-arrays -Werror=undef -Wfloat-equal -Wimplicit-fallthrough=5 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-aliasing=2 -Wstrict-prototypes -Wsuggest-attribute=noreturn -Wunused-function -Wwrite-strings -Wzero-length-bounds -fdiagnostics-show-option -fno-common -fstack-protector -fstack-protector-strong -fstrict-flex-arrays --param=ssp-buffer-size=4 -Wno-unused-result -Werror=shadow -fno-strict-aliasing -fstrict-flex-arrays=1 -fvisibility=hidden -fno-omit-frame-pointer -include config.h -pthread -DTEST_CODE=1 -MD -MQ test-network-tables.p/src_network_test-network-tables.c.o -MF test-network-tables.p/src_network_test-network-tables.c.o.d -o test-network-tables.p/src_network_test-network-tables.c.o -c ../src/network/test-network-tables.c
In file included from ../src/basic/linux/if_bonding.h:47,
                 from ../src/network/netdev/bond.h:5,
                 from ../src/network/test-network-tables.c:3:
../src/basic/linux/if.h:111:41: error: redeclaration of enumerator ‘IFF_UP’
  111 | #define IFF_UP                          IFF_UP
      |                                         ^~~~~~
../src/basic/linux/if.h:84:9: note: previous definition of ‘IFF_UP’ with type ‘enum net_device_flags’
   84 |         IFF_UP                          = 1<<0,  /* sysfs */
      |         ^~~~~~
../src/basic/linux/if.h:112:41: error: redeclaration of enumerator ‘IFF_BROADCAST’
  112 | #define IFF_BROADCAST                   IFF_BROADCAST
      |                                         ^~~~~~~~~~~~~
...

This also drops remaining workarounds from the last time this issue was
brought up (6f270e6bd8) since they shouldn't be needed anymore if the
order of the includes is the "correct" one. I also added a comment to
each affected include when this is inevitably encountered again in the
future.

Resolves: #32160
2024-04-09 21:19:15 +02:00
Yu Watanabe 447fe37ee3 test: introduce a test executable to send NDisc message 2024-04-05 06:22:19 +09:00
Yu Watanabe 44e8cf303b sd-ndisc: add basic support of Redirect message
This makes sd-ndisc support Redirect message defined in RFC 4861.
2024-04-05 05:57:14 +09:00
Yu Watanabe ecab9b6040 test-ndisc: add basic tests for Neighbor Advertisement handling 2024-04-05 02:16:03 +09:00
Yu Watanabe 696eb2b8de sd-ndisc: add basic support of Neighbor Advertisement message
This adds basic support of receiving and parsing Neighbor Advertisement
message defined in RFC 4861.
2024-04-05 02:16:03 +09:00
Evgeny Vereshchagin a33a636b48 fuzz: check that ND options are parsed sucessfully
At that point the options have been parsed, sent and received again so
`ndisc_parse_options` should never fail there (unless ndisc_send corrupts
them somehow).

It's a follow-up to https://github.com/systemd/systemd/pull/31807
2024-04-04 02:42:21 +09:00