1
0
mirror of https://github.com/systemd/systemd synced 2026-04-13 10:35:08 +02:00

Compare commits

..

14 Commits

Author SHA1 Message Date
Evgeny Vereshchagin
007721e939 ci: turn meson warnings into errors 2022-01-14 01:53:37 +03:00
Luca Boccassi
e6d692ddfd
Merge pull request #22111 from medhefgo/boot-cleanup
boot: Cleanup
2022-01-13 22:50:52 +00:00
Yu Watanabe
902bbdc4b6 network: use scope link for direct unicast routes by default
Strictly speaking, this breaks the backward compatibility, but I guess
in most cases people already sets Scope=link for such routes.

This behavior matches with how 'ip route' command adds such route by
default.

Prompted by https://twitter.com/jplitza/status/1480500562391179270.
2022-01-13 22:46:52 +00:00
Luca Boccassi
fad7ad2b8b
Merge pull request #22106 from yuwata/dhcp6-broken-NTP
sd-dhcp6-client: handle broken NTP server option gracefully
2022-01-13 22:43:07 +00:00
Jan Janssen
2d1ac308c5 boot: Use FreePool from boot services directly
This should hopefully allow the compiler to optimize this a bit even
when gnu-efi is not compiled with LTO.
2022-01-13 14:30:51 +01:00
Jan Janssen
27c106bab8 boot: Add missing assert to file_read() 2022-01-13 14:30:51 +01:00
Jan Janssen
e1e086d1f7 boot: Use _cleanup_ in shim
Also, better be safe than sorry and check the return value.
2022-01-13 14:30:51 +01:00
Jan Janssen
acd28f3912 boot: Don't try to free loaded_image
EFI_LOADED_IMAGE is a protocol pointer and thus, we shouldn't try
to free it.
2022-01-13 14:29:46 +01:00
Jan Janssen
85eb489e23 boot: Use EFI_FILE* instead of EFI_FILE_HANDLE
They are both the same, but the former is shorter and also closer
to how file handles are represented in the UEFI spec.
2022-01-13 14:26:43 +01:00
Jan Janssen
41b74a18b2 boot: Fix invalid free
LocateDevicePath() advances the device path pointer, making it invalid
when freed.
2022-01-13 14:19:32 +01:00
Yu Watanabe
95c514e9a5 test: add testcase for broken NTP server option
For issue #22099.
2022-01-13 20:21:40 +09:00
Yu Watanabe
37408dd264 test: voidify test functions
This also drops unnecessary arguments, and unbreak several lines.
2022-01-13 20:20:48 +09:00
Yu Watanabe
16de849fd8 sd-dhcp6-client: expose client_parse_message()
To introduce tests for the function in later commits.
2022-01-13 20:20:19 +09:00
Yu Watanabe
0ac9daa4a1 sd-dhcp6-client: ignore broken non-critical options
The commit b89a3758e92894162e3c2dcb594a55acff3274d5 made the validity
check of the received message stricter. E.g. if the client received a
message with broken NTP server option, then the entire message is
dropped.

This relaxes the check. If some non-critical options are broken, then
ignore the options, but the message itself is still accepted.

Fixes #22099.
2022-01-13 20:20:19 +09:00
21 changed files with 160 additions and 134 deletions

View File

@ -117,12 +117,21 @@ ninja --version
for args in "${ARGS[@]}"; do for args in "${ARGS[@]}"; do
SECONDS=0 SECONDS=0
# meson fails with
# src/boot/efi/meson.build:52: WARNING: Not using lld as efi-ld, falling back to bfd
# src/boot/efi/meson.build:52:16: ERROR: Fatal warnings enabled, aborting
# when LINKER is set to lld so let's just not turn meson warnings into errors with lld
# to make sure that the build systemd can pick up the correct efi-ld linker automatically.
if [[ "$LINKER" != lld ]]; then
additional_meson_args="--fatal-meson-warnings"
fi
info "Checking build with $args" info "Checking build with $args"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
if ! AR="$AR" \ if ! AR="$AR" \
CC="$CC" CC_LD="$LINKER" CFLAGS="-Werror" \ CC="$CC" CC_LD="$LINKER" CFLAGS="-Werror" \
CXX="$CXX" CXX_LD="$LINKER" CXXFLAGS="-Werror" \ CXX="$CXX" CXX_LD="$LINKER" CXXFLAGS="-Werror" \
meson -Dtests=unsafe -Dslow-tests=true -Dfuzz-tests=true --werror \ meson -Dtests=unsafe -Dslow-tests=true -Dfuzz-tests=true --werror \
-Dnobody-group=nogroup $additional_meson_args \
-Dcryptolib="${CRYPTOLIB:?}" $args build; then -Dcryptolib="${CRYPTOLIB:?}" $args build; then
cat build/meson-logs/meson-log.txt cat build/meson-logs/meson-log.txt

View File

@ -56,7 +56,7 @@ for phase in "${PHASES[@]}"; do
# The docs build is slow and is not affected by compiler/flags, so do it just once # The docs build is slow and is not affected by compiler/flags, so do it just once
MESON_ARGS+=(-Dman=true) MESON_ARGS+=(-Dman=true)
fi fi
run_meson --werror -Dtests=unsafe -Dslow-tests=true -Dfuzz-tests=true "${MESON_ARGS[@]}" build run_meson --fatal-meson-warnings -Dnobody-group=nogroup --werror -Dtests=unsafe -Dslow-tests=true -Dfuzz-tests=true "${MESON_ARGS[@]}" build
ninja -C build -v ninja -C build -v
meson test -C build --print-errorlogs meson test -C build --print-errorlogs
;; ;;
@ -71,7 +71,7 @@ for phase in "${PHASES[@]}"; do
# -Db_lundef=false: See https://github.com/mesonbuild/meson/issues/764 # -Db_lundef=false: See https://github.com/mesonbuild/meson/issues/764
MESON_ARGS+=(-Db_lundef=false -Dfuzz-tests=true) MESON_ARGS+=(-Db_lundef=false -Dfuzz-tests=true)
fi fi
run_meson --werror -Dtests=unsafe -Db_sanitize=address,undefined "${MESON_ARGS[@]}" build run_meson --fatal-meson-warnings -Dnobody-group=nogroup --werror -Dtests=unsafe -Db_sanitize=address,undefined "${MESON_ARGS[@]}" build
ninja -C build -v ninja -C build -v
export ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 export ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1

View File

@ -1547,9 +1547,9 @@ Table=1234</programlisting></para>
<para>For IPv4 route, defaults to <literal>host</literal> if <varname>Type=</varname> is <para>For IPv4 route, defaults to <literal>host</literal> if <varname>Type=</varname> is
<literal>local</literal> or <literal>nat</literal>, and <literal>link</literal> if <literal>local</literal> or <literal>nat</literal>, and <literal>link</literal> if
<varname>Type=</varname> is <literal>broadcast</literal>, <literal>multicast</literal>, or <varname>Type=</varname> is <literal>broadcast</literal>, <literal>multicast</literal>,
<literal>anycast</literal>. In other cases, defaults to <literal>global</literal>. The value <literal>anycast</literal>, or direct <literal>unicast</literal> routes. In other cases,
is not used for IPv6.</para> defaults to <literal>global</literal>. The value is not used for IPv6.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@ -1309,12 +1309,9 @@ good:
entry->next_name = xpool_print(L"%s+%u-%u%s", prefix, next_left, next_done, suffix ?: L""); entry->next_name = xpool_print(L"%s+%u-%u%s", prefix, next_left, next_done, suffix ?: L"");
} }
static void config_entry_bump_counters( static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) {
ConfigEntry *entry,
EFI_FILE_HANDLE root_dir) {
_cleanup_freepool_ CHAR16* old_path = NULL, *new_path = NULL; _cleanup_freepool_ CHAR16* old_path = NULL, *new_path = NULL;
_cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL; _cleanup_(file_closep) EFI_FILE *handle = NULL;
_cleanup_freepool_ EFI_FILE_INFO *file_info = NULL; _cleanup_freepool_ EFI_FILE_INFO *file_info = NULL;
UINTN file_info_size; UINTN file_info_size;
EFI_STATUS err; EFI_STATUS err;
@ -1375,7 +1372,6 @@ static void config_entry_add_from_file(
UINTN pos = 0; UINTN pos = 0;
CHAR8 *key, *value; CHAR8 *key, *value;
EFI_STATUS err; EFI_STATUS err;
EFI_FILE_HANDLE handle;
_cleanup_freepool_ CHAR16 *initrd = NULL; _cleanup_freepool_ CHAR16 *initrd = NULL;
assert(config); assert(config);
@ -1483,10 +1479,10 @@ static void config_entry_add_from_file(
return; return;
/* check existence */ /* check existence */
_cleanup_(file_closep) EFI_FILE *handle = NULL;
err = root_dir->Open(root_dir, &handle, entry->loader, EFI_FILE_MODE_READ, 0ULL); err = root_dir->Open(root_dir, &handle, entry->loader, EFI_FILE_MODE_READ, 0ULL);
if (EFI_ERROR(err)) if (EFI_ERROR(err))
return; return;
handle->Close(handle);
/* add initrd= to options */ /* add initrd= to options */
if (entry->type == LOADER_LINUX && initrd) { if (entry->type == LOADER_LINUX && initrd) {
@ -1571,7 +1567,7 @@ static void config_load_entries(
EFI_FILE *root_dir, EFI_FILE *root_dir,
const CHAR16 *loaded_image_path) { const CHAR16 *loaded_image_path) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE entries_dir = NULL; _cleanup_(file_closep) EFI_FILE *entries_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *f = NULL; _cleanup_freepool_ EFI_FILE_INFO *f = NULL;
UINTN f_size = 0; UINTN f_size = 0;
EFI_STATUS err; EFI_STATUS err;
@ -1888,9 +1884,6 @@ static ConfigEntry *config_entry_add_loader_auto(
const CHAR16 *title, const CHAR16 *title,
const CHAR16 *loader) { const CHAR16 *loader) {
EFI_FILE_HANDLE handle;
EFI_STATUS err;
assert(config); assert(config);
assert(device); assert(device);
assert(root_dir); assert(root_dir);
@ -1916,10 +1909,10 @@ static ConfigEntry *config_entry_add_loader_auto(
} }
/* check existence */ /* check existence */
err = root_dir->Open(root_dir, &handle, (CHAR16*) loader, EFI_FILE_MODE_READ, 0ULL); _cleanup_(file_closep) EFI_FILE *handle = NULL;
EFI_STATUS err = root_dir->Open(root_dir, &handle, (CHAR16*) loader, EFI_FILE_MODE_READ, 0ULL);
if (EFI_ERROR(err)) if (EFI_ERROR(err))
return NULL; return NULL;
handle->Close(handle);
return config_entry_add_loader(config, device, LOADER_AUTO, id, key, title, loader, NULL); return config_entry_add_loader(config, device, LOADER_AUTO, id, key, title, loader, NULL);
} }
@ -1939,7 +1932,7 @@ static void config_entry_add_osx(Config *config) {
return; return;
for (UINTN i = 0; i < n_handles; i++) { for (UINTN i = 0; i < n_handles; i++) {
_cleanup_(file_handle_closep) EFI_FILE *root = LibOpenRoot(handles[i]); _cleanup_(file_closep) EFI_FILE *root = LibOpenRoot(handles[i]);
if (!root) if (!root)
continue; continue;
@ -2066,7 +2059,7 @@ static void config_entry_add_linux(
EFI_HANDLE *device, EFI_HANDLE *device,
EFI_FILE *root_dir) { EFI_FILE *root_dir) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE linux_dir = NULL; _cleanup_(file_closep) EFI_FILE *linux_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *f = NULL; _cleanup_freepool_ EFI_FILE_INFO *f = NULL;
ConfigEntry *entry; ConfigEntry *entry;
UINTN f_size = 0; UINTN f_size = 0;
@ -2224,7 +2217,7 @@ static void config_load_xbootldr(
Config *config, Config *config,
EFI_HANDLE *device) { EFI_HANDLE *device) {
_cleanup_(file_handle_closep) EFI_FILE *root_dir = NULL; _cleanup_(file_closep) EFI_FILE *root_dir = NULL;
EFI_HANDLE new_device; EFI_HANDLE new_device;
EFI_STATUS err; EFI_STATUS err;
@ -2240,7 +2233,7 @@ static void config_load_xbootldr(
} }
static EFI_STATUS image_start( static EFI_STATUS image_start(
EFI_FILE_HANDLE root_dir, EFI_FILE *root_dir,
EFI_HANDLE parent_image, EFI_HANDLE parent_image,
const Config *config, const Config *config,
const ConfigEntry *entry) { const ConfigEntry *entry) {
@ -2455,8 +2448,8 @@ static void config_load_all_entries(
} }
EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
_cleanup_freepool_ EFI_LOADED_IMAGE *loaded_image = NULL; EFI_LOADED_IMAGE *loaded_image;
_cleanup_(file_handle_closep) EFI_FILE *root_dir = NULL; _cleanup_(file_closep) EFI_FILE *root_dir = NULL;
_cleanup_(config_free) Config config = {}; _cleanup_(config_free) Config config = {};
CHAR16 *loaded_image_path; CHAR16 *loaded_image_path;
EFI_STATUS err; EFI_STATUS err;

View File

@ -316,7 +316,7 @@ EFI_STATUS pack_cpio(
void **ret_buffer, void **ret_buffer,
UINTN *ret_buffer_size) { UINTN *ret_buffer_size) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE root = NULL, extra_dir = NULL; _cleanup_(file_closep) EFI_FILE *root = NULL, *extra_dir = NULL;
UINTN dirent_size = 0, buffer_size = 0, n_items = 0, n_allocated = 0; UINTN dirent_size = 0, buffer_size = 0, n_items = 0, n_allocated = 0;
_cleanup_freepool_ CHAR16 *rel_dropin_dir = NULL; _cleanup_freepool_ CHAR16 *rel_dropin_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *dirent = NULL; _cleanup_freepool_ EFI_FILE_INFO *dirent = NULL;

View File

@ -64,9 +64,8 @@ static EFI_STATUS devicetree_fixup(struct devicetree_state *state, UINTN len) {
return err; return err;
} }
EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, CHAR16 *name) {
EFI_FILE_HANDLE root_dir, CHAR16 *name) { _cleanup_(file_closep) EFI_FILE *handle = NULL;
_cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
_cleanup_freepool_ EFI_FILE_INFO *info = NULL; _cleanup_freepool_ EFI_FILE_INFO *info = NULL;
UINTN len; UINTN len;
EFI_STATUS err; EFI_STATUS err;

View File

@ -7,7 +7,7 @@ struct devicetree_state {
void *orig; void *orig;
}; };
EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE_HANDLE root_dir, CHAR16 *name); EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, CHAR16 *name);
EFI_STATUS devicetree_install_from_memory( EFI_STATUS devicetree_install_from_memory(
struct devicetree_state *state, const VOID *dtb_buffer, UINTN dtb_length); struct devicetree_state *state, const VOID *dtb_buffer, UINTN dtb_length);
void devicetree_cleanup(struct devicetree_state *state); void devicetree_cleanup(struct devicetree_state *state);

View File

@ -80,9 +80,9 @@ static EFI_STATUS reconnect(void) {
EFI_STATUS load_drivers( EFI_STATUS load_drivers(
EFI_HANDLE parent_image, EFI_HANDLE parent_image,
EFI_LOADED_IMAGE *loaded_image, EFI_LOADED_IMAGE *loaded_image,
EFI_FILE_HANDLE root_dir) { EFI_FILE *root_dir) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE drivers_dir = NULL; _cleanup_(file_closep) EFI_FILE *drivers_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *dirent = NULL; _cleanup_freepool_ EFI_FILE_INFO *dirent = NULL;
UINTN dirent_size = 0, n_succeeded = 0; UINTN dirent_size = 0, n_succeeded = 0;
EFI_STATUS err; EFI_STATUS err;

View File

@ -6,4 +6,4 @@
EFI_STATUS load_drivers( EFI_STATUS load_drivers(
EFI_HANDLE parent_image, EFI_HANDLE parent_image,
EFI_LOADED_IMAGE *loaded_image, EFI_LOADED_IMAGE *loaded_image,
EFI_FILE_HANDLE root_dir); EFI_FILE *root_dir);

View File

@ -224,7 +224,7 @@ EFI_STATUS pe_file_locate_sections(
UINTN *offsets, UINTN *offsets,
UINTN *sizes) { UINTN *sizes) {
_cleanup_freepool_ struct PeSectionHeader *section_table = NULL; _cleanup_freepool_ struct PeSectionHeader *section_table = NULL;
_cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL; _cleanup_(file_closep) EFI_FILE *handle = NULL;
struct DosFileHeader dos; struct DosFileHeader dos;
struct PeFileHeader pe; struct PeFileHeader pe;
UINTN len, section_table_len; UINTN len, section_table_len;

View File

@ -225,7 +225,7 @@ static void validate_sha256(void) {
EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) { EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
_cleanup_freepool_ void *seed = NULL, *new_seed = NULL, *rng = NULL, *for_kernel = NULL, *system_token = NULL; _cleanup_freepool_ void *seed = NULL, *new_seed = NULL, *rng = NULL, *for_kernel = NULL, *system_token = NULL;
_cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL; _cleanup_(file_closep) EFI_FILE *handle = NULL;
UINTN size, rsize, wsize, system_token_size = 0; UINTN size, rsize, wsize, system_token_size = 0;
_cleanup_freepool_ EFI_FILE_INFO *info = NULL; _cleanup_freepool_ EFI_FILE_INFO *info = NULL;
EFI_STATUS err; EFI_STATUS err;

View File

@ -105,7 +105,6 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT
_cleanup_freepool_ EFI_DEVICE_PATH *dev_path = NULL; _cleanup_freepool_ EFI_DEVICE_PATH *dev_path = NULL;
_cleanup_freepool_ CHAR16 *dev_path_str = NULL; _cleanup_freepool_ CHAR16 *dev_path_str = NULL;
EFI_HANDLE h; EFI_HANDLE h;
EFI_FILE *root;
_cleanup_freepool_ CHAR8 *file_buffer = NULL; _cleanup_freepool_ CHAR8 *file_buffer = NULL;
UINTN file_size; UINTN file_size;
@ -118,20 +117,22 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT
if (!dev_path) if (!dev_path)
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
status = BS->LocateDevicePath(&FileSystemProtocol, &dev_path, &h); EFI_DEVICE_PATH *dp = dev_path;
status = BS->LocateDevicePath(&FileSystemProtocol, &dp, &h);
if (EFI_ERROR(status)) if (EFI_ERROR(status))
return status; return status;
/* No need to check return value, this already happened in efi_main() */ _cleanup_(file_closep) EFI_FILE *root = LibOpenRoot(h);
root = LibOpenRoot(h); if (!root)
dev_path_str = DevicePathToStr(dev_path); return EFI_NOT_FOUND;
dev_path_str = DevicePathToStr(dp);
if (!dev_path_str) if (!dev_path_str)
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
status = file_read(root, dev_path_str, 0, 0, &file_buffer, &file_size); status = file_read(root, dev_path_str, 0, 0, &file_buffer, &file_size);
if (EFI_ERROR(status)) if (EFI_ERROR(status))
return status; return status;
root->Close(root);
if (shim_validate(file_buffer, file_size)) if (shim_validate(file_buffer, file_size))
return EFI_SUCCESS; return EFI_SUCCESS;

View File

@ -435,11 +435,12 @@ CHAR8 *strchra(const CHAR8 *s, CHAR8 c) {
return NULL; return NULL;
} }
EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) { EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL; _cleanup_(file_closep) EFI_FILE *handle = NULL;
_cleanup_freepool_ CHAR8 *buf = NULL; _cleanup_freepool_ CHAR8 *buf = NULL;
EFI_STATUS err; EFI_STATUS err;
assert(dir);
assert(name); assert(name);
assert(ret); assert(ret);
@ -544,7 +545,7 @@ void sort_pointer_array(
} }
EFI_STATUS get_file_info_harder( EFI_STATUS get_file_info_harder(
EFI_FILE_HANDLE handle, EFI_FILE *handle,
EFI_FILE_INFO **ret, EFI_FILE_INFO **ret,
UINTN *ret_size) { UINTN *ret_size) {
@ -577,7 +578,7 @@ EFI_STATUS get_file_info_harder(
} }
EFI_STATUS readdir_harder( EFI_STATUS readdir_harder(
EFI_FILE_HANDLE handle, EFI_FILE *handle,
EFI_FILE_INFO **buffer, EFI_FILE_INFO **buffer,
UINTN *buffer_size) { UINTN *buffer_size) {
@ -700,11 +701,11 @@ CHAR16 **strv_free(CHAR16 **v) {
} }
EFI_STATUS open_directory( EFI_STATUS open_directory(
EFI_FILE_HANDLE root, EFI_FILE *root,
const CHAR16 *path, const CHAR16 *path,
EFI_FILE_HANDLE *ret) { EFI_FILE **ret) {
_cleanup_(file_handle_closep) EFI_FILE_HANDLE dir = NULL; _cleanup_(file_closep) EFI_FILE *dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *file_info = NULL; _cleanup_freepool_ EFI_FILE_INFO *file_info = NULL;
EFI_STATUS err; EFI_STATUS err;

View File

@ -71,7 +71,7 @@ CHAR8 *strchra(const CHAR8 *s, CHAR8 c);
CHAR16 *xstra_to_path(const CHAR8 *stra); CHAR16 *xstra_to_path(const CHAR8 *stra);
CHAR16 *xstra_to_str(const CHAR8 *stra); CHAR16 *xstra_to_str(const CHAR8 *stra);
EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size); EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size);
static inline void free_poolp(void *p) { static inline void free_poolp(void *p) {
void *q = *(void**) p; void *q = *(void**) p;
@ -79,12 +79,12 @@ static inline void free_poolp(void *p) {
if (!q) if (!q)
return; return;
FreePool(q); (void) BS->FreePool(q);
} }
#define _cleanup_freepool_ _cleanup_(free_poolp) #define _cleanup_freepool_ _cleanup_(free_poolp)
static inline void file_handle_closep(EFI_FILE_HANDLE *handle) { static inline void file_closep(EFI_FILE **handle) {
if (!*handle) if (!*handle)
return; return;
@ -117,9 +117,9 @@ void clear_screen(UINTN attr);
typedef INTN (*compare_pointer_func_t)(const void *a, const void *b); typedef INTN (*compare_pointer_func_t)(const void *a, const void *b);
void sort_pointer_array(void **array, UINTN n_members, compare_pointer_func_t compare); void sort_pointer_array(void **array, UINTN n_members, compare_pointer_func_t compare);
EFI_STATUS get_file_info_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **ret, UINTN *ret_size); EFI_STATUS get_file_info_harder(EFI_FILE *handle, EFI_FILE_INFO **ret, UINTN *ret_size);
EFI_STATUS readdir_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **buffer, UINTN *buffer_size); EFI_STATUS readdir_harder(EFI_FILE *handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
UINTN strnlena(const CHAR8 *p, UINTN maxlen); UINTN strnlena(const CHAR8 *p, UINTN maxlen);
CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz); CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz);
@ -136,7 +136,7 @@ static inline void strv_freep(CHAR16 ***p) {
strv_free(*p); strv_free(*p);
} }
EFI_STATUS open_directory(EFI_FILE_HANDLE root_dir, const CHAR16 *path, EFI_FILE_HANDLE *ret); EFI_STATUS open_directory(EFI_FILE *root_dir, const CHAR16 *path, EFI_FILE **ret);
/* Conversion between EFI_PHYSICAL_ADDRESS and pointers is not obvious. The former is always 64bit, even on /* Conversion between EFI_PHYSICAL_ADDRESS and pointers is not obvious. The former is always 64bit, even on
* 32bit archs. And gcc complains if we cast a pointer to an integer of a different size. Hence let's do the * 32bit archs. And gcc complains if we cast a pointer to an integer of a different size. Hence let's do the

View File

@ -286,7 +286,8 @@ EFI_STATUS xbootldr_open(EFI_HANDLE *device, EFI_HANDLE *ret_device, EFI_FILE **
hd->SignatureType = SIGNATURE_TYPE_GUID; hd->SignatureType = SIGNATURE_TYPE_GUID;
} }
err = BS->LocateDevicePath(&BlockIoProtocol, &partition_path, &new_device); EFI_DEVICE_PATH *dp = partition_path;
err = BS->LocateDevicePath(&BlockIoProtocol, &dp, &new_device);
if (EFI_ERROR(err)) if (EFI_ERROR(err))
return err; return err;

View File

@ -11,6 +11,7 @@
#include "sd-event.h" #include "sd-event.h"
#include "sd-dhcp6-client.h" #include "sd-dhcp6-client.h"
#include "dhcp6-protocol.h"
#include "hashmap.h" #include "hashmap.h"
#include "list.h" #include "list.h"
#include "macro.h" #include "macro.h"
@ -130,6 +131,12 @@ int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *address);
int dhcp6_network_send_udp_socket(int s, struct in6_addr *address, int dhcp6_network_send_udp_socket(int s, struct in6_addr *address,
const void *packet, size_t len); const void *packet, size_t len);
int client_parse_message(
sd_dhcp6_client *client,
DHCP6Message *message,
size_t len,
sd_dhcp6_lease *lease);
const char *dhcp6_message_type_to_string(int s) _const_; const char *dhcp6_message_type_to_string(int s) _const_;
int dhcp6_message_type_from_string(const char *s) _pure_; int dhcp6_message_type_from_string(const char *s) _pure_;
const char *dhcp6_message_status_to_string(int s) _const_; const char *dhcp6_message_status_to_string(int s) _const_;

View File

@ -1124,7 +1124,7 @@ static int client_ensure_iaid(sd_dhcp6_client *client) {
return 0; return 0;
} }
static int client_parse_message( int client_parse_message(
sd_dhcp6_client *client, sd_dhcp6_client *client,
DHCP6Message *message, DHCP6Message *message,
size_t len, size_t len,
@ -1261,35 +1261,35 @@ static int client_parse_message(
case SD_DHCP6_OPTION_DNS_SERVERS: case SD_DHCP6_OPTION_DNS_SERVERS:
r = dhcp6_lease_add_dns(lease, optval, optlen); r = dhcp6_lease_add_dns(lease, optval, optlen);
if (r < 0) if (r < 0)
return r; log_dhcp6_client_errno(client, r, "Failed to parse DNS server option, ignoring: %m");
break; break;
case SD_DHCP6_OPTION_DOMAIN_LIST: case SD_DHCP6_OPTION_DOMAIN_LIST:
r = dhcp6_lease_add_domains(lease, optval, optlen); r = dhcp6_lease_add_domains(lease, optval, optlen);
if (r < 0) if (r < 0)
return r; log_dhcp6_client_errno(client, r, "Failed to parse domain list option, ignoring: %m");
break; break;
case SD_DHCP6_OPTION_NTP_SERVER: case SD_DHCP6_OPTION_NTP_SERVER:
r = dhcp6_lease_add_ntp(lease, optval, optlen); r = dhcp6_lease_add_ntp(lease, optval, optlen);
if (r < 0) if (r < 0)
return r; log_dhcp6_client_errno(client, r, "Failed to parse NTP server option, ignoring: %m");
break; break;
case SD_DHCP6_OPTION_SNTP_SERVERS: case SD_DHCP6_OPTION_SNTP_SERVERS:
r = dhcp6_lease_add_sntp(lease, optval, optlen); r = dhcp6_lease_add_sntp(lease, optval, optlen);
if (r < 0) if (r < 0)
return r; log_dhcp6_client_errno(client, r, "Failed to parse SNTP server option, ignoring: %m");
break; break;
case SD_DHCP6_OPTION_CLIENT_FQDN: case SD_DHCP6_OPTION_CLIENT_FQDN:
r = dhcp6_lease_set_fqdn(lease, optval, optlen); r = dhcp6_lease_set_fqdn(lease, optval, optlen);
if (r < 0) if (r < 0)
return r; log_dhcp6_client_errno(client, r, "Failed to parse FQDN option, ignoring: %m");
break; break;

View File

@ -37,7 +37,7 @@ static int test_client_message_num;
static be32_t test_iaid = 0; static be32_t test_iaid = 0;
static uint8_t test_duid[14] = { }; static uint8_t test_duid[14] = { };
static int test_client_basic(sd_event *e) { static void test_client_basic(sd_event *e) {
sd_dhcp6_client *client; sd_dhcp6_client *client;
int v; int v;
@ -108,11 +108,9 @@ static int test_client_basic(sd_event *e) {
assert_se(sd_dhcp6_client_detach_event(client) >= 0); assert_se(sd_dhcp6_client_detach_event(client) >= 0);
assert_se(!sd_dhcp6_client_unref(client)); assert_se(!sd_dhcp6_client_unref(client));
return 0;
} }
static int test_parse_domain(sd_event *e) { static void test_parse_domain(void) {
uint8_t *data; uint8_t *data;
char *domain; char *domain;
char **list; char **list;
@ -154,11 +152,9 @@ static int test_parse_domain(sd_event *e) {
data = (uint8_t []) { 0 , 0 }; data = (uint8_t []) { 0 , 0 };
r = dhcp6_option_parse_domainname_list(data, 2, &list); r = dhcp6_option_parse_domainname_list(data, 2, &list);
assert_se(r < 0); assert_se(r < 0);
return 0;
} }
static int test_option(sd_event *e) { static void test_option(void) {
uint8_t packet[] = { uint8_t packet[] = {
'F', 'O', 'O', 'H', 'O', 'G', 'E', 'F', 'O', 'O', 'H', 'O', 'G', 'E',
0x00, SD_DHCP6_OPTION_ORO, 0x00, 0x07, 0x00, SD_DHCP6_OPTION_ORO, 0x00, 0x07,
@ -232,11 +228,9 @@ static int test_option(sd_event *e) {
assert_se(*out == 'B'); assert_se(*out == 'B');
assert_se(memcmp(packet, result, sizeof(packet)) == 0); assert_se(memcmp(packet, result, sizeof(packet)) == 0);
return 0;
} }
static int test_option_status(sd_event *e) { static void test_option_status(void) {
uint8_t option1[] = { uint8_t option1[] = {
/* IA NA */ /* IA NA */
0x00, 0x03, 0x00, 0x12, 0x1a, 0x1d, 0x1a, 0x1d, 0x00, 0x03, 0x00, 0x12, 0x1a, 0x1d, 0x1a, 0x1d,
@ -370,8 +364,56 @@ static int test_option_status(sd_event *e) {
assert_se(r >= 0); assert_se(r >= 0);
assert_se(pd.addresses); assert_se(pd.addresses);
dhcp6_lease_free_ia(&pd); dhcp6_lease_free_ia(&pd);
}
return 0; static void test_client_parse_message_issue_22099(void) {
static const uint8_t msg[] = {
/* xid */
0x07, 0x7c, 0x4c, 0x16,
/* status code (zero length) */
0x00, 0x0e, 0x00, 0x00,
/* NTP servers (broken sub option and sub option length) */
0x00, 0x38, 0x00, 0x14, 0x01, 0x00, 0x10, 0x00, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xde, 0x15, 0xc8, 0xff, 0xfe, 0xef, 0x1e, 0x4e,
/* client ID */
0x00, 0x01, 0x00, 0x0e, 0x00, 0x02, 0x00, 0x00, 0xab, 0x11, 0x5c, 0x6b, 0x90, 0xec, 0xda, 0x95,
0x15, 0x45,
/* server ID */
0x00, 0x02, 0x00, 0x0a, 0x00, 0x03, 0x00, 0x01, 0xdc, 0x15, 0xc8, 0xef, 0x1e, 0x4e,
/* preference */
0x00, 0x07, 0x00, 0x01, 0x00,
/* DNS servers */
0x00, 0x17, 0x00, 0x10, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0x15, 0xc8, 0xff,
0xfe, 0xef, 0x1e, 0x4e,
/* v6 pcp server */
0x00, 0x56, 0x00, 0x10, 0x2a, 0x02, 0x81, 0x0d, 0x98, 0x80, 0x37, 0x00, 0xde, 0x15, 0xc8, 0xff,
0xfe, 0xef, 0x1e, 0x4e,
/* IA_NA */
0x00, 0x03, 0x00, 0x28, 0xcc, 0x59, 0x11, 0x7b, 0x00, 0x00, 0x07, 0x08, 0x00, 0x00, 0x0b, 0x40,
/* IA_NA (iaaddr) */
0x00, 0x05, 0x00, 0x18, 0x2a, 0x02, 0x81, 0x0d, 0x98, 0x80, 0x37, 0x00, 0x6a, 0x05, 0xca, 0xff,
0xfe, 0xf1, 0x51, 0x53, 0x00, 0x00, 0x0e, 0x10, 0x00, 0x00, 0x1c, 0x20,
/* IA_PD */
0x00, 0x19, 0x00, 0x29, 0xcc, 0x59, 0x11, 0x7b, 0x00, 0x00, 0x07, 0x08, 0x00, 0x00, 0x0b, 0x40,
/* IA_PD (iaprefix) */
0x00, 0x1a, 0x00, 0x19, 0x00, 0x00, 0x0e, 0x10, 0x00, 0x00, 0x1c, 0x20, 0x3a, 0x2a, 0x02, 0x81,
0x0d, 0x98, 0x80, 0x37, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint8_t duid[] = {
0x00, 0x00, 0xab, 0x11, 0x5c, 0x6b, 0x90, 0xec, 0xda, 0x95, 0x15, 0x45,
};
_cleanup_(sd_dhcp6_client_unrefp) sd_dhcp6_client *client = NULL;
_cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL;
log_debug("/* %s */", __func__);
assert_se(sd_dhcp6_client_new(&client) >= 0);
assert_se(sd_dhcp6_client_set_iaid(client, 0xcc59117b) >= 0);
assert_se(sd_dhcp6_client_set_duid(client, 2, duid, sizeof(duid)) >= 0);
assert_se(dhcp6_lease_new(&lease) >= 0);
assert_se(client_parse_message(client, (DHCP6Message*) msg, sizeof(msg), lease) >= 0);
} }
static uint8_t msg_advertise[198] = { static uint8_t msg_advertise[198] = {
@ -434,7 +476,7 @@ static uint8_t fqdn_wire[16] = {
0x05, 'i', 'n', 't', 'r', 'a', 0x00 0x05, 'i', 'n', 't', 'r', 'a', 0x00
}; };
static int test_advertise_option(sd_event *e) { static void test_advertise_option(sd_event *e) {
_cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL; _cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL;
DHCP6Message *advertise = (DHCP6Message *)msg_advertise; DHCP6Message *advertise = (DHCP6Message *)msg_advertise;
size_t len = sizeof(msg_advertise) - sizeof(DHCP6Message), pos = 0; size_t len = sizeof(msg_advertise) - sizeof(DHCP6Message), pos = 0;
@ -455,8 +497,7 @@ static int test_advertise_option(sd_event *e) {
assert_se(dhcp6_lease_new(&lease) >= 0); assert_se(dhcp6_lease_new(&lease) >= 0);
assert_se(advertise->type == DHCP6_MESSAGE_ADVERTISE); assert_se(advertise->type == DHCP6_MESSAGE_ADVERTISE);
assert_se((be32toh(advertise->transaction_id) & 0x00ffffff) == assert_se((be32toh(advertise->transaction_id) & 0x00ffffff) == 0x0fb4e5);
0x0fb4e5);
while (pos < len) { while (pos < len) {
DHCP6Option *option = (DHCP6Option *)&advertise->options[pos]; DHCP6Option *option = (DHCP6Option *)&advertise->options[pos];
@ -495,16 +536,14 @@ static int test_advertise_option(sd_event *e) {
assert_se(optval == &msg_advertise[179]); assert_se(optval == &msg_advertise[179]);
assert_se(!memcmp(optval, &msg_advertise[179], optlen)); assert_se(!memcmp(optval, &msg_advertise[179], optlen));
assert_se(dhcp6_lease_set_serverid(lease, optval, assert_se(dhcp6_lease_set_serverid(lease, optval, optlen) >= 0);
optlen) >= 0);
break; break;
case SD_DHCP6_OPTION_PREFERENCE: case SD_DHCP6_OPTION_PREFERENCE:
assert_se(optlen == 1); assert_se(optlen == 1);
assert_se(!*optval); assert_se(!*optval);
assert_se(dhcp6_lease_set_preference(lease, assert_se(dhcp6_lease_set_preference(lease, *optval) >= 0);
*optval) >= 0);
break; break;
case SD_DHCP6_OPTION_ELAPSED_TIME: case SD_DHCP6_OPTION_ELAPSED_TIME:
@ -538,26 +577,20 @@ static int test_advertise_option(sd_event *e) {
assert_se(opt_clientid); assert_se(opt_clientid);
sd_dhcp6_lease_reset_address_iter(lease); sd_dhcp6_lease_reset_address_iter(lease);
assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, &lt_valid) >= 0);
&lt_valid) >= 0);
assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr))); assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr)));
assert_se(lt_pref == 150); assert_se(lt_pref == 150);
assert_se(lt_valid == 180); assert_se(lt_valid == 180);
assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, &lt_valid) == -ENOMSG);
&lt_valid) == -ENOMSG);
sd_dhcp6_lease_reset_address_iter(lease); sd_dhcp6_lease_reset_address_iter(lease);
assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, &lt_valid) >= 0);
&lt_valid) >= 0);
assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr))); assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr)));
assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, &lt_valid) == -ENOMSG);
&lt_valid) == -ENOMSG);
sd_dhcp6_lease_reset_address_iter(lease); sd_dhcp6_lease_reset_address_iter(lease);
assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, &lt_valid) >= 0);
&lt_valid) >= 0);
assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr))); assert_se(!memcmp(&addr, &msg_advertise[42], sizeof(addr)));
assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, &lt_valid) == -ENOMSG);
&lt_valid) == -ENOMSG);
assert_se(dhcp6_lease_get_serverid(lease, &opt, &len) >= 0); assert_se(dhcp6_lease_get_serverid(lease, &opt, &len) >= 0);
assert_se(len == 14); assert_se(len == 14);
@ -578,8 +611,6 @@ static int test_advertise_option(sd_event *e) {
r = sd_dhcp6_lease_get_ntp_addrs(lease, &addrs); r = sd_dhcp6_lease_get_ntp_addrs(lease, &addrs);
assert_se(r == 1); assert_se(r == 1);
assert_se(!memcmp(addrs, &msg_advertise[159], r * 16)); assert_se(!memcmp(addrs, &msg_advertise[159], r * 16));
return 0;
} }
static int test_check_completed_in_2_seconds(sd_event_source *s, uint64_t usec, void *userdata) { static int test_check_completed_in_2_seconds(sd_event_source *s, uint64_t usec, void *userdata) {
@ -615,7 +646,7 @@ static void test_client_solicit_cb(sd_dhcp6_client *client, int event,
sd_event_exit(e, 0); sd_event_exit(e, 0);
} }
static int test_client_send_reply(DHCP6Message *request) { static void test_client_send_reply(DHCP6Message *request) {
DHCP6Message reply; DHCP6Message reply;
log_debug("/* %s */", __func__); log_debug("/* %s */", __func__);
@ -629,13 +660,10 @@ static int test_client_send_reply(DHCP6Message *request) {
memcpy(&msg_reply[44], &test_iaid, sizeof(test_iaid)); memcpy(&msg_reply[44], &test_iaid, sizeof(test_iaid));
assert_se(write(test_dhcp_fd[1], msg_reply, sizeof(msg_reply)) assert_se(write(test_dhcp_fd[1], msg_reply, sizeof(msg_reply)) == sizeof(msg_reply));
== sizeof(msg_reply));
return 0;
} }
static int test_client_verify_request(DHCP6Message *request, size_t len) { static void test_client_verify_request(DHCP6Message *request, size_t len) {
_cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL; _cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL;
bool found_clientid = false, found_iana = false, found_serverid = false, bool found_clientid = false, found_iana = false, found_serverid = false,
found_elapsed_time = false, found_fqdn = false; found_elapsed_time = false, found_fqdn = false;
@ -714,16 +742,13 @@ static int test_client_verify_request(DHCP6Message *request, size_t len) {
pos += sizeof(*option) + optlen; pos += sizeof(*option) + optlen;
} }
assert_se(found_clientid && found_iana && found_serverid && assert_se(found_clientid && found_iana && found_serverid && found_elapsed_time);
found_elapsed_time);
sd_dhcp6_lease_reset_address_iter(lease); sd_dhcp6_lease_reset_address_iter(lease);
assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, &lt_valid) == -ENOMSG); assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, &lt_valid) == -ENOMSG);
return 0;
} }
static int test_client_send_advertise(DHCP6Message *solicit) { static void test_client_send_advertise(DHCP6Message *solicit) {
DHCP6Message advertise; DHCP6Message advertise;
log_debug("/* %s */", __func__); log_debug("/* %s */", __func__);
@ -737,13 +762,10 @@ static int test_client_send_advertise(DHCP6Message *solicit) {
memcpy(&msg_advertise[26], &test_iaid, sizeof(test_iaid)); memcpy(&msg_advertise[26], &test_iaid, sizeof(test_iaid));
assert_se(write(test_dhcp_fd[1], msg_advertise, sizeof(msg_advertise)) assert_se(write(test_dhcp_fd[1], msg_advertise, sizeof(msg_advertise)) == sizeof(msg_advertise));
== sizeof(msg_advertise));
return 0;
} }
static int test_client_verify_solicit(DHCP6Message *solicit, size_t len) { static void test_client_verify_solicit(DHCP6Message *solicit, size_t len) {
bool found_clientid = false, found_iana = false, bool found_clientid = false, found_iana = false,
found_elapsed_time = false, found_fqdn = false; found_elapsed_time = false, found_fqdn = false;
size_t pos = 0; size_t pos = 0;
@ -805,12 +827,9 @@ static int test_client_verify_solicit(DHCP6Message *solicit, size_t len) {
assert_se(pos == len); assert_se(pos == len);
assert_se(found_clientid && found_iana && found_elapsed_time); assert_se(found_clientid && found_iana && found_elapsed_time);
return 0;
} }
static void test_client_information_cb(sd_dhcp6_client *client, int event, static void test_client_information_cb(sd_dhcp6_client *client, int event, void *userdata) {
void *userdata) {
sd_event *e = userdata; sd_event *e = userdata;
sd_dhcp6_lease *lease; sd_dhcp6_lease *lease;
const struct in6_addr *addrs; const struct in6_addr *addrs;
@ -843,18 +862,14 @@ static void test_client_information_cb(sd_dhcp6_client *client, int event,
assert_se(sd_dhcp6_client_stop(client) >= 0); assert_se(sd_dhcp6_client_stop(client) >= 0);
assert_se(sd_dhcp6_client_set_information_request(client, false) >= 0); assert_se(sd_dhcp6_client_set_information_request(client, false) >= 0);
assert_se(sd_dhcp6_client_set_callback(client, assert_se(sd_dhcp6_client_set_callback(client, test_client_solicit_cb, e) >= 0);
test_client_solicit_cb, e) >= 0);
assert_se(sd_dhcp6_client_set_local_address(client, &address) >= 0); assert_se(sd_dhcp6_client_set_local_address(client, &address) >= 0);
assert_se(sd_dhcp6_client_start(client) >= 0); assert_se(sd_dhcp6_client_start(client) >= 0);
} }
static int test_client_verify_information_request(DHCP6Message *information_request, static void test_client_verify_information_request(DHCP6Message *information_request, size_t len) {
size_t len) {
_cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL; _cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease = NULL;
size_t pos = 0; size_t pos = 0;
bool found_clientid = false, found_elapsed_time = false; bool found_clientid = false, found_elapsed_time = false;
@ -905,16 +920,12 @@ static int test_client_verify_information_request(DHCP6Message *information_requ
sd_dhcp6_lease_reset_address_iter(lease); sd_dhcp6_lease_reset_address_iter(lease);
assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, &lt_valid) == -ENOMSG);
&lt_valid) == -ENOMSG);
return 0;
} }
int dhcp6_network_send_udp_socket(int s, struct in6_addr *server_address, int dhcp6_network_send_udp_socket(int s, struct in6_addr *server_address,
const void *packet, size_t len) { const void *packet, size_t len) {
struct in6_addr mcast = struct in6_addr mcast = IN6ADDR_ALL_DHCP6_RELAY_AGENTS_AND_SERVERS_INIT;
IN6ADDR_ALL_DHCP6_RELAY_AGENTS_AND_SERVERS_INIT;
DHCP6Message *message; DHCP6Message *message;
log_debug("/* %s */", __func__); log_debug("/* %s */", __func__);
@ -955,7 +966,7 @@ int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *local_address) {
return test_dhcp_fd[0]; return test_dhcp_fd[0];
} }
static int test_client_solicit(sd_event *e) { static void test_client_solicit(sd_event *e) {
sd_dhcp6_client *client; sd_dhcp6_client *client;
struct in6_addr address = { { { 0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01 } } }; struct in6_addr address = { { { 0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01 } } };
int val; int val;
@ -998,8 +1009,6 @@ static int test_client_solicit(sd_event *e) {
assert_se(!sd_dhcp6_client_unref(client)); assert_se(!sd_dhcp6_client_unref(client));
test_dhcp_fd[1] = safe_close(test_dhcp_fd[1]); test_dhcp_fd[1] = safe_close(test_dhcp_fd[1]);
return 0;
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -1010,11 +1019,12 @@ int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG); test_setup_logging(LOG_DEBUG);
test_client_basic(e); test_client_basic(e);
test_option(e); test_parse_domain();
test_option_status(e); test_option();
test_option_status();
test_client_parse_message_issue_22099();
test_advertise_option(e); test_advertise_option(e);
test_client_solicit(e); test_client_solicit(e);
test_parse_domain(e);
return 0; return 0;
} }

View File

@ -2846,6 +2846,12 @@ static int route_section_verify(Route *route, Network *network) {
route->scope = RT_SCOPE_HOST; route->scope = RT_SCOPE_HOST;
else if (IN_SET(route->type, RTN_BROADCAST, RTN_ANYCAST, RTN_MULTICAST)) else if (IN_SET(route->type, RTN_BROADCAST, RTN_ANYCAST, RTN_MULTICAST))
route->scope = RT_SCOPE_LINK; route->scope = RT_SCOPE_LINK;
else if (IN_SET(route->type, RTN_UNICAST, RTN_UNSPEC) &&
!route->gateway_from_dhcp_or_ra &&
!in_addr_is_set(route->gw_family, &route->gw) &&
ordered_set_isempty(route->multipath_routes) &&
route->nexthop_id == 0)
route->scope = RT_SCOPE_LINK;
} }
if (route->scope != RT_SCOPE_UNIVERSE && route->family == AF_INET6) { if (route->scope != RT_SCOPE_UNIVERSE && route->family == AF_INET6) {

View File

@ -24,7 +24,6 @@ Gateway=fe80::222:4dff:ff:ff:ff:ff
[Route] [Route]
Destination=149.10.124.64 Destination=149.10.124.64
Scope=link
[Route] [Route]
Gateway=149.10.124.64 Gateway=149.10.124.64

View File

@ -2542,9 +2542,9 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
self.assertIn('149.10.124.48/28 proto kernel scope link src 149.10.124.58', output) self.assertIn('149.10.124.48/28 proto kernel scope link src 149.10.124.58', output)
self.assertIn('149.10.124.64 proto static scope link', output) self.assertIn('149.10.124.64 proto static scope link', output)
self.assertIn('169.254.0.0/16 proto static scope link metric 2048', output) self.assertIn('169.254.0.0/16 proto static scope link metric 2048', output)
self.assertIn('192.168.1.1 proto static initcwnd 20', output) self.assertIn('192.168.1.1 proto static scope link initcwnd 20', output)
self.assertIn('192.168.1.2 proto static initrwnd 30', output) self.assertIn('192.168.1.2 proto static scope link initrwnd 30', output)
self.assertIn('192.168.1.3 proto static advmss 30', output) self.assertIn('192.168.1.3 proto static scope link advmss 30', output)
self.assertIn('multicast 149.10.123.4 proto static', output) self.assertIn('multicast 149.10.123.4 proto static', output)
print('### ip -4 route show dev dummy98 default') print('### ip -4 route show dev dummy98 default')