Commit Graph
2037 Commits
Author SHA1 Message Date
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
Yu Watanabe ff944339f3 ndisc-option: allow to set valid time of options
When an option is delegated from an upstream server, its lifetime
may be limited by a time. Such functionality will be used later by
sd-radv.

This also remove 'offset' argument from the option setter
ndisc_option_set_xyz(), and make it update existing option.
See comments in ndisc_option_add_link_layer_address() for more details.
2024-03-28 12:34:09 +00:00
Yu Watanabe 95d3570b47 sd-ndisc-router: introduce sd_ndisc_router_set_sender_address()
Currently this is not used, but will be used later to modify the sender
address.
2024-03-27 13:13:12 +00:00
Yu Watanabe 9f3587ae44 ndisc-option: add HomeAgent option support
Currently, these are not used, but will be used later in sd-radv.
2024-03-27 13:12:30 +00:00
Yu Watanabe 073f438365 ndisc-option: sort options in sent message
To make the sent message reproducible.
2024-03-26 13:58:36 +00:00
Yu Watanabe 24578ce63a ndisc-option: introduce ndisc_option_remove() 2024-03-26 03:30:41 +09:00
Yu Watanabe 697c3693b3 ndisc-option: rename ndisc_option_get() -> ndisc_option_get_by_type()
Then, introduce more generic ndisc_option_get().
2024-03-26 03:30:41 +09:00
Yu WatanabeandEvgeny Vereshchagin cdb88ae4e5 fuzz: test NDisc packet with more low level functions
Also, test send back the test packet.

Co-authored-by: Evgeny Vereshchagin <evvers@ya.ru>
2024-03-18 23:19:44 +09:00
Yu Watanabe fcfb691fc1 icmp6-packet: expose icmp6_packet_get_header() 2024-03-18 23:18:43 +09:00
Yu Watanabe d112b4454c icmp6-util: drop unused icmp6_send_router_solicitation() 2024-03-18 22:52:29 +09:00
Yu Watanabe 349d51e7a1 sd-ndisc: use sd_ndisc_option and ndisc_send() 2024-03-18 22:52:29 +09:00
Yu Watanabe ca11446217 ndisc-option: introduce ndisc_send()
This will be used when sending Router Solicitation and Advertisement.
2024-03-18 22:52:29 +09:00
Yu Watanabe af0d593b32 ndisc-option: add a way to specify invalid or unsupported options
Mostly for testing.
2024-03-18 22:52:29 +09:00
Yu Watanabe 8430c4d91d test-ndisc-rs: send Router Solicit message before sending test packet 2024-03-18 22:52:29 +09:00
Yu Watanabe 5ed4c2b944 sd-dhcp-server: also save the server address and netmask to the leases file
And introduce a tiny helper to retrieve these information.
The function is not used at this time, but will be used later.
2024-03-15 04:15:10 +09:00
Yu Watanabe d47f83302e sd-dhcp-server: rearrange the parser of the leases file
No functional changes, just refactoring and preparation for later
commits.
2024-03-15 04:15:10 +09:00
Yu Watanabe 11b88419ae sd-dhcp-server: make sd_dhcp_server_set_lease_file() optionally take directory fd
Currently, though, no valid directory fd is passed to the function call.
Preparation for later commits.
2024-03-15 04:15:10 +09:00
Luca Boccassi 8e35076101 Merge pull request #31584 from yuwata/sd-ndisc-option-parser-cleanups
sd-ndisc: rewrite option parser
2024-03-13 23:06:50 +00:00
Evgeny Vereshchagin a96b4557cb fuzz: make sure DHCP client leases are loaded successfully
Now that fa3357b9e8 is merged the fuzz
target should no longer crash there.
2024-03-14 00:10:08 +09:00
Yu Watanabe 9ca04752cb sd-ndisc-router: adjust function names and type of returned value
- prefix length and preference should be fit in uint8_t, and actually
  the kernel and networkd uses uint8_t to store them.
- captive portal is now stored as a NUL-terminated string. Hence, it
  is not necessary to also provide its length.
2024-03-13 12:32:52 +09:00
Yu Watanabe b43c2221f6 sd-ndisc-router: introduce sd_ndisc_router_get_sender_mac()
The Router Advertisement option can take the MAC address of the sender.
Let's introduce a function to get it from the parsed options.
2024-03-13 12:32:52 +09:00
Yu Watanabe 0216c67269 ndisc-option: drop unused function 2024-03-13 12:32:52 +09:00
Yu Watanabe c0edd6b3b3 sd-ndisc-router: use ndisc_parse_options() and friends to parse Router Advertisement 2024-03-13 12:32:52 +09:00
Yu Watanabe a163404cc8 ndisc-option: introduce generic NDisc option parser
It is not used in this commit, but will be used for parsing NDisc
options in Router Advertisement message and friends.

The parser does mostly equivalent to what currently we do in
sd-ndisc-router.c. Several notable differences are:
- also perse source and target link-layer address,
- refuse multiple captive portals,
- check if the captive portal is in safe characters, as previously we
  checked that in networkd-ndisc.c,
- dedup prefixes, routes, and pref64,
- limit the total number of options, for safety.
2024-03-13 12:32:37 +09:00
Yu Watanabe dd6bbb3027 sd-ndisc: rename ndisc-protocol.[ch] -> ndisc-option.[ch] 2024-03-13 10:55:48 +09:00
Yu Watanabe 3fbade30a8 Merge pull request #31716 from evverx/fuzz-lease-save-load
fuzz: save/load DHCP client leases
2024-03-12 19:05:17 +09:00