From: Zbigniew Jędrzejewski-Szmek Date: Thu, 29 Oct 2020 18:27:29 +0000 (+0100) Subject: Merge pull request #17444 from BtbN/fix_ib_dhcp4 X-Git-Tag: v247-rc2~40 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fsystemd.git;a=commitdiff_plain;h=58f848148f0bbdbedd0243de289944804b772094;hp=f1f17144114a37680847f4f2cf6c8c5930b718a7 Merge pull request #17444 from BtbN/fix_ib_dhcp4 networkd: fix DHCP on InfiniBand interfaces --- diff --git a/hwdb.d/60-sensor.hwdb b/hwdb.d/60-sensor.hwdb index 7079736a8fa..16edca57aae 100644 --- a/hwdb.d/60-sensor.hwdb +++ b/hwdb.d/60-sensor.hwdb @@ -650,6 +650,14 @@ sensor:modalias:acpi:KIOX000A*:dmi:*:rvnPOV:rnI102A:* sensor:modalias:i2c:bmc150_accel:dmi:bvnINSYDECorp.:*:svnInsyde:pnBayTrail:*:rvn105B:rn0E57:* ACCEL_MOUNT_MATRIX=1, 0, 0; 0, -1, 0; 0, 0, 1 +######################################### +# Predia +######################################### + +# Predia Basic tablet, most DMI strings are generic, match on BIOS version +sensor:modalias:acpi:BOSC0200*:dmi:bvnINSYDECorp.:bvrMx.WT107.KUBNGEA*svnInsyde:pnCherryTrail:* + ACCEL_MOUNT_MATRIX=0, -1, 0; -1, 0, 0; 0, 0, 1 + ######################################### # Prowise ######################################### diff --git a/man/org.freedesktop.hostname1.xml b/man/org.freedesktop.hostname1.xml index 6b2341e48c0..ab49c0b3e21 100644 --- a/man/org.freedesktop.hostname1.xml +++ b/man/org.freedesktop.hostname1.xml @@ -260,7 +260,8 @@ node /org/freedesktop/hostname1 { org.freedesktop.hostname1.set-hostname. For SetStaticHostname() and SetPrettyHostname() it is org.freedesktop.hostname1.set-static-hostname. For - SetIconName() and SetChassis() it is + SetIconName(), SetChassis(), SetDeployment() + and SetLocation() it is org.freedesktop.hostname1.set-machine-info. diff --git a/man/systemd.special.xml b/man/systemd.special.xml index fe40da7fbe2..1434ead7d5e 100644 --- a/man/systemd.special.xml +++ b/man/systemd.special.xml @@ -41,7 +41,6 @@ hybrid-sleep.target, suspend-then-hibernate.target, initrd.target, - initrd-cryptsetup.target, initrd-fs.target, initrd-root-device.target, initrd-root-fs.target, @@ -183,10 +182,8 @@ cryptsetup.target - A target that pulls in setup services for local encrypted block devices. - See remote-cryptsetup.target below for the equivalent target for remote - volumes, and initrd-cryptsetup.target below for the equivalent target in the - initrd. + A target that pulls in setup services for all + encrypted block devices. @@ -355,20 +352,12 @@ initrd.target - This is the default target in the initrd, similar to default.target + This is the default target in the initramfs, similar to default.target in the main system. It is used to mount the real root and transition to it. See bootup7 for more discussion. - - initrd-cryptsetup.target - - A target that pulls in setup services for all encrypted block devices. See - cryptsetup.target and remote-cryptsetup.target for the - equivalent targets in the real root. - - initrd-fs.target @@ -560,9 +549,7 @@ Similar to cryptsetup.target, but for encrypted devices which are accessed over the network. It is used for crypttab8 - entries marked with . - See cryptsetup.target for the equivalent target for local volumes, and - initrd-cryptsetup.target for the equivalent target in the initrd. + entries marked with . diff --git a/meson.build b/meson.build index 1abcac27f49..5cfc24c2d6d 100644 --- a/meson.build +++ b/meson.build @@ -1561,21 +1561,11 @@ meson_apply_m4 = find_program('tools/meson-apply-m4.sh') includes = include_directories('src/basic', 'src/boot', + 'src/core', 'src/home', - 'src/shared', - 'src/systemd', 'src/journal', 'src/journal-remote', - 'src/nspawn', - 'src/resolve', - 'src/timesync', - 'src/time-wait-sync', - 'src/login', - 'src/udev', - 'src/libudev', - 'src/core', - 'src/shutdown', - 'src/xdg-autostart-generator', + 'src/libsystemd-network', 'src/libsystemd/sd-bus', 'src/libsystemd/sd-device', 'src/libsystemd/sd-event', @@ -1584,7 +1574,17 @@ includes = include_directories('src/basic', 'src/libsystemd/sd-netlink', 'src/libsystemd/sd-network', 'src/libsystemd/sd-resolve', - 'src/libsystemd-network', + 'src/libudev', + 'src/login', + 'src/nspawn', + 'src/resolve', + 'src/shared', + 'src/shutdown', + 'src/systemd', + 'src/time-wait-sync', + 'src/timesync', + 'src/udev', + 'src/xdg-autostart-generator', '.') add_project_arguments('-include', 'config.h', language : 'c') diff --git a/src/basic/MurmurHash2.c b/src/basic/MurmurHash2.c index 5859af0a81b..43a89a0820b 100644 --- a/src/basic/MurmurHash2.c +++ b/src/basic/MurmurHash2.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LicenseRef-murmurhash2-public-domain */ //----------------------------------------------------------------------------- // MurmurHash2 was written by Austin Appleby, and is placed in the public // domain. The author hereby disclaims copyright to this source code. diff --git a/src/basic/MurmurHash2.h b/src/basic/MurmurHash2.h index 1aef3afba06..5758b860398 100644 --- a/src/basic/MurmurHash2.h +++ b/src/basic/MurmurHash2.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LicenseRef-murmurhash2-public-domain */ //----------------------------------------------------------------------------- // MurmurHash2 was written by Austin Appleby, and is placed in the public // domain. The author hereby disclaims copyright to this source code. diff --git a/src/basic/gunicode.c b/src/basic/gunicode.c index c51b1a7a181..02637d74e91 100644 --- a/src/basic/gunicode.c +++ b/src/basic/gunicode.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /* gunicode.c - Unicode manipulation functions * * Copyright (C) 1999, 2000 Tom Tromey diff --git a/src/basic/gunicode.h b/src/basic/gunicode.h index a16b7b6ff1b..765077db832 100644 --- a/src/basic/gunicode.h +++ b/src/basic/gunicode.h @@ -1,10 +1,10 @@ -#pragma once - +/* SPDX-License-Identifier: LGPL-2.1+ */ /* gunicode.h - Unicode manipulation functions * * Copyright (C) 1999, 2000 Tom Tromey * Copyright © 2000, 2005 Red Hat, Inc. */ +#pragma once #include #include diff --git a/src/basic/memory-util.c b/src/basic/memory-util.c index 5f327ef0d7a..0a5cf2797d0 100644 --- a/src/basic/memory-util.c +++ b/src/basic/memory-util.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include #include "memory-util.h" diff --git a/src/basic/siphash24.c b/src/basic/siphash24.c index 61180819b1b..7c61eb145d9 100644 --- a/src/basic/siphash24.c +++ b/src/basic/siphash24.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: CC0-1.0 */ + /* SipHash reference C implementation @@ -10,7 +12,7 @@ worldwide. This software is distributed without any warranty. You should have received a copy of the CC0 Public Domain Dedication along with - this software. If not, see . + this software. If not, see . (Minimal changes made by Lennart Poettering, to make clean for inclusion in systemd) (Refactored by Tom Gundersen to split up in several functions and follow systemd diff --git a/src/basic/siphash24.h b/src/basic/siphash24.h index fe43256882e..90a6de00e4f 100644 --- a/src/basic/siphash24.h +++ b/src/basic/siphash24.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: CC0-1.0 */ + #pragma once #include diff --git a/src/basic/sort-util.c b/src/basic/sort-util.c index 5cf0d1d49b6..77342c4bdc6 100644 --- a/src/basic/sort-util.c +++ b/src/basic/sort-util.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include "sort-util.h" #include "alloc-util.h" diff --git a/src/basic/static-destruct.h b/src/basic/static-destruct.h index 8fbc07c5876..fbb8fa087b9 100644 --- a/src/basic/static-destruct.h +++ b/src/basic/static-destruct.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #pragma once #include "alloc-util.h" diff --git a/src/boot/efi/crc32.c b/src/boot/efi/crc32.c index 46b9aeea907..5dfd3db265f 100644 --- a/src/boot/efi/crc32.c +++ b/src/boot/efi/crc32.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LicenseRef-crc32-no-restriction */ /* This is copied from util-linux, which in turn copied in the version from Gary S. Brown */ /* diff --git a/src/boot/efi/crc32.h b/src/boot/efi/crc32.h index 64150ee948c..3af543b84e5 100644 --- a/src/boot/efi/crc32.h +++ b/src/boot/efi/crc32.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ +/* SPDX-License-Identifier: LicenseRef-crc32-no-restriction */ #pragma once #include diff --git a/src/boot/efi/random-seed.c b/src/boot/efi/random-seed.c index cc747993b8b..6e2a6f1d32f 100644 --- a/src/boot/efi/random-seed.c +++ b/src/boot/efi/random-seed.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include #include diff --git a/src/boot/efi/sha256.c b/src/boot/efi/sha256.c index 40da636dc71..005e1902d4b 100644 --- a/src/boot/efi/sha256.c +++ b/src/boot/efi/sha256.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + /* Stolen from glibc and converted to UEFI style. In glibc it comes with the following copyright blurb: */ /* Functions to compute SHA256 message digest of files or memory blocks. diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 13e9f3aedd0..df589ec3e4a 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -455,16 +455,10 @@ static int create_disk( } } - const char *target; - if (in_initrd()) - target = "initrd-cryptsetup.target"; - else if (netdev) - target = "remote-cryptsetup.target"; - else - target = "cryptsetup.target"; - if (!nofail) - fprintf(f, "Before=%s\n", target); + fprintf(f, + "Before=%s\n", + netdev ? "remote-cryptsetup.target" : "cryptsetup.target"); if (password && !keydev) { r = print_dependencies(f, password); @@ -527,7 +521,8 @@ static int create_disk( return log_error_errno(r, "Failed to write unit file %s: %m", n); if (!noauto) { - r = generator_add_symlink(arg_dest, target, + r = generator_add_symlink(arg_dest, + netdev ? "remote-cryptsetup.target" : "cryptsetup.target", nofail ? "wants" : "requires", n); if (r < 0) return r; diff --git a/src/home/homectl-recovery-key.c b/src/home/homectl-recovery-key.c index c63d3415f4b..3311205db50 100644 --- a/src/home/homectl-recovery-key.c +++ b/src/home/homectl-recovery-key.c @@ -1,17 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#if HAVE_QRENCODE -#include -#include "qrcode-util.h" -#endif - -#include "dlfcn-util.h" #include "errno-util.h" #include "homectl-recovery-key.h" #include "libcrypt-util.h" #include "locale-util.h" #include "memory-util.h" #include "modhex.h" +#include "qrcode-util.h" #include "random-util.h" #include "strv.h" #include "terminal-util.h" @@ -140,48 +135,6 @@ static int add_secret(JsonVariant **v, const char *password) { return 0; } -static int print_qr_code(const char *secret) { -#if HAVE_QRENCODE - QRcode* (*sym_QRcode_encodeString)(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive); - void (*sym_QRcode_free)(QRcode *qrcode); - _cleanup_(dlclosep) void *dl = NULL; - QRcode* qr; - int r; - - /* If this is not an UTF-8 system or ANSI colors aren't supported/disabled don't print any QR - * codes */ - if (!is_locale_utf8() || !colors_enabled()) - return -EOPNOTSUPP; - - dl = dlopen("libqrencode.so.4", RTLD_LAZY); - if (!dl) - return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), - "QRCODE support is not installed: %s", dlerror()); - - r = dlsym_many_and_warn( - dl, - LOG_DEBUG, - &sym_QRcode_encodeString, "QRcode_encodeString", - &sym_QRcode_free, "QRcode_free", - NULL); - if (r < 0) - return r; - - qr = sym_QRcode_encodeString(secret, 0, QR_ECLEVEL_L, QR_MODE_8, 0); - if (!qr) - return -ENOMEM; - - fprintf(stderr, "\nYou may optionally scan the recovery key off screen:\n\n"); - - write_qrcode(stderr, qr); - - fputc('\n', stderr); - - sym_QRcode_free(qr); -#endif - return 0; -} - int identity_add_recovery_key(JsonVariant **v) { _cleanup_(erase_and_freep) char *password = NULL, *hashed = NULL; int r; @@ -240,7 +193,7 @@ int identity_add_recovery_key(JsonVariant **v) { "whenever authentication is requested.\n", stderr); fflush(stderr); - print_qr_code(password); + (void) print_qrcode(stderr, "You may optionally scan the recovery key off screen", password); return 0; } diff --git a/src/home/user-record-sign.c b/src/home/user-record-sign.c index 91f86399976..6ef0c27c546 100644 --- a/src/home/user-record-sign.c +++ b/src/home/user-record-sign.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include #include "fd-util.h" diff --git a/src/journal-remote/journal-upload.h b/src/journal-remote/journal-upload.h index 4994cd8391d..95af35db054 100644 --- a/src/journal-remote/journal-upload.h +++ b/src/journal-remote/journal-upload.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #pragma once #include diff --git a/src/journal/journal-qrcode.c b/src/journal/journal-qrcode.c deleted file mode 100644 index e8a76553162..00000000000 --- a/src/journal/journal-qrcode.c +++ /dev/null @@ -1,97 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ - -#include -#include -#include -#include -#include - -#include "alloc-util.h" -#include "dlfcn-util.h" -#include "fd-util.h" -#include "fileio.h" -#include "journal-qrcode.h" -#include "locale-util.h" -#include "macro.h" -#include "qrcode-util.h" -#include "terminal-util.h" - -int print_qr_code( - FILE *output, - const char *prefix_text, - const void *seed, - size_t seed_size, - uint64_t start, - uint64_t interval, - const char *hn, - sd_id128_t machine) { - - QRcode* (*sym_QRcode_encodeString)(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive); - void (*sym_QRcode_free)(QRcode *qrcode); - _cleanup_(dlclosep) void *dl = NULL; - _cleanup_free_ char *url = NULL; - _cleanup_fclose_ FILE *f = NULL; - size_t url_size = 0; - QRcode* qr; - int r; - - assert(seed); - assert(seed_size > 0); - - /* If this is not an UTF-8 system or ANSI colors aren't supported/disabled don't print any QR - * codes */ - if (!is_locale_utf8() || !colors_enabled()) - return -EOPNOTSUPP; - - dl = dlopen("libqrencode.so.4", RTLD_LAZY); - if (!dl) - return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), - "QRCODE support is not installed: %s", dlerror()); - - r = dlsym_many_and_warn( - dl, - LOG_DEBUG, - &sym_QRcode_encodeString, "QRcode_encodeString", - &sym_QRcode_free, "QRcode_free", - NULL); - if (r < 0) - return r; - - f = open_memstream_unlocked(&url, &url_size); - if (!f) - return -ENOMEM; - - fputs("fss://", f); - - for (size_t i = 0; i < seed_size; i++) { - if (i > 0 && i % 3 == 0) - fputc('-', f); - fprintf(f, "%02x", ((uint8_t*) seed)[i]); - } - - fprintf(f, "/%"PRIx64"-%"PRIx64"?machine=" SD_ID128_FORMAT_STR, - start, - interval, - SD_ID128_FORMAT_VAL(machine)); - - if (hn) - fprintf(f, ";hostname=%s", hn); - - r = fflush_and_check(f); - if (r < 0) - return r; - - f = safe_fclose(f); - - qr = sym_QRcode_encodeString(url, 0, QR_ECLEVEL_L, QR_MODE_8, 1); - if (!qr) - return -ENOMEM; - - if (prefix_text) - fputs(prefix_text, output); - - write_qrcode(output, qr); - - sym_QRcode_free(qr); - return 0; -} diff --git a/src/journal/journal-qrcode.h b/src/journal/journal-qrcode.h deleted file mode 100644 index 24ae9d32eeb..00000000000 --- a/src/journal/journal-qrcode.h +++ /dev/null @@ -1,9 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ -#pragma once - -#include -#include - -#include "sd-id128.h" - -int print_qr_code(FILE *f, const char *prefix_text, const void *seed, size_t seed_size, uint64_t start, uint64_t interval, const char *hn, sd_id128_t machine); diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index e43e9d1afac..8bc0aa22dea 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -43,7 +43,6 @@ #include "io-util.h" #include "journal-def.h" #include "journal-internal.h" -#include "journal-qrcode.h" #include "journal-util.h" #include "journal-vacuum.h" #include "journal-verify.h" @@ -60,6 +59,7 @@ #include "path-util.h" #include "pcre2-dlopen.h" #include "pretty-print.h" +#include "qrcode-util.h" #include "random-util.h" #include "rlimit-util.h" #include "set.h" @@ -1779,6 +1779,55 @@ static int add_syslog_identifier(sd_journal *j) { return 0; } +#if HAVE_GCRYPT +static int format_journal_url( + const void *seed, + size_t seed_size, + uint64_t start, + uint64_t interval, + const char *hn, + sd_id128_t machine, + bool full, + char **ret_url) { + _cleanup_free_ char *url = NULL; + _cleanup_fclose_ FILE *f = NULL; + size_t url_size = 0; + int r; + + assert(seed); + assert(seed_size > 0); + + f = open_memstream_unlocked(&url, &url_size); + if (!f) + return -ENOMEM; + + if (full) + fputs("fss://", f); + + for (size_t i = 0; i < seed_size; i++) { + if (i > 0 && i % 3 == 0) + fputc('-', f); + fprintf(f, "%02x", ((uint8_t*) seed)[i]); + } + + fprintf(f, "/%"PRIx64"-%"PRIx64, start, interval); + + if (full) { + fprintf(f, "?machine=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(machine)); + if (hn) + fprintf(f, ";hostname=%s", hn); + } + + r = fflush_and_check(f); + if (r < 0) + return r; + + f = safe_fclose(f); + *ret_url = TAKE_PTR(url); + return 0; +} +#endif + static int setup_keys(void) { #if HAVE_GCRYPT size_t mpk_size, seed_size, state_size; @@ -1893,7 +1942,11 @@ static int setup_keys(void) { k = mfree(k); - _cleanup_free_ char *hn = NULL; + _cleanup_free_ char *hn = NULL, *key = NULL; + + r = format_journal_url(seed, seed_size, n, arg_interval, hn, machine, false, &key); + if (r < 0) + return r; if (on_tty()) { hn = gethostname_malloc(); @@ -1925,21 +1978,19 @@ static int setup_keys(void) { fflush(stderr); } - for (size_t i = 0; i < seed_size; i++) { - if (i > 0 && i % 3 == 0) - putchar('-'); - printf("%02x", ((uint8_t*) seed)[i]); - } - printf("/%llx-%llx\n", (unsigned long long) n, (unsigned long long) arg_interval); + puts(key); if (on_tty()) { fprintf(stderr, "%s", ansi_normal()); #if HAVE_QRENCODE - (void) print_qr_code(stderr, - "\nTo transfer the verification key to your phone scan the QR code below:\n", - seed, seed_size, - n, arg_interval, - hn, machine); + _cleanup_free_ char *url = NULL; + r = format_journal_url(seed, seed_size, n, arg_interval, hn, machine, true, &url); + if (r < 0) + return r; + + (void) print_qrcode(stderr, + "To transfer the verification key to your phone scan the QR code below", + url); #endif } diff --git a/src/journal/lookup3.c b/src/journal/lookup3.c index 74c80b724df..39967f21cdc 100644 --- a/src/journal/lookup3.c +++ b/src/journal/lookup3.c @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LicenseRef-lookup3-public-domain */ /* Slightly modified by Lennart Poettering, to avoid name clashes, and * unexport a few functions. */ diff --git a/src/journal/lookup3.h b/src/journal/lookup3.h index 0a01269e433..04e493e95ea 100644 --- a/src/journal/lookup3.h +++ b/src/journal/lookup3.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LicenseRef-lookup3-public-domain */ #pragma once #include diff --git a/src/journal/meson.build b/src/journal/meson.build index 3a590bdc6c5..215ba949e77 100644 --- a/src/journal/meson.build +++ b/src/journal/meson.build @@ -107,11 +107,6 @@ journalctl_sources = files(''' pcre2-dlopen.h '''.split()) -if conf.get('HAVE_QRENCODE') == 1 - journalctl_sources += files('journal-qrcode.c', - 'journal-qrcode.h') -endif - install_data('journald.conf', install_dir : pkgsysconfdir) diff --git a/src/libsystemd-network/test-sd-dhcp-lease.c b/src/libsystemd-network/test-sd-dhcp-lease.c index 534cc785640..91eaf814e40 100644 --- a/src/libsystemd-network/test-sd-dhcp-lease.c +++ b/src/libsystemd-network/test-sd-dhcp-lease.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include #include "dhcp-lease-internal.h" diff --git a/src/libsystemd/sd-bus/test-bus-address.c b/src/libsystemd/sd-bus/test-bus-address.c index 70a6df10f96..1316d376e13 100644 --- a/src/libsystemd/sd-bus/test-bus-address.c +++ b/src/libsystemd/sd-bus/test-bus-address.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include "sd-bus.h" #include "bus-internal.h" diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 5e770c83b7a..50ee29ae979 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -701,6 +701,33 @@ static void event_gc_signal_data(sd_event *e, const int64_t *priority, int sig) event_unmask_signal_data(e, d, sig); } +static void event_source_pp_prioq_reshuffle(sd_event_source *s) { + assert(s); + + /* Reshuffles the pending + prepare prioqs. Called whenever the dispatch order changes, i.e. when + * they are enabled/disabled or marked pending and such. */ + + if (s->pending) + prioq_reshuffle(s->event->pending, s, &s->pending_index); + + if (s->prepare) + prioq_reshuffle(s->event->prepare, s, &s->prepare_index); +} + +static void event_source_time_prioq_reshuffle(sd_event_source *s) { + struct clock_data *d; + + assert(s); + assert(EVENT_SOURCE_IS_TIME(s->type)); + + /* Called whenever the event source's timer ordering properties changed, i.e. time, accuracy, + * pending, enable state. Makes sure the two prioq's are ordered properly again. */ + assert_se(d = event_get_clock_data(s->event, s->type)); + prioq_reshuffle(d->earliest, s, &s->time.earliest_index); + prioq_reshuffle(d->latest, s, &s->time.latest_index); + d->needs_rearm = true; +} + static void source_disconnect(sd_event_source *s) { sd_event *event; @@ -907,16 +934,8 @@ static int source_set_pending(sd_event_source *s, bool b) { } else assert_se(prioq_remove(s->event->pending, s, &s->pending_index)); - if (EVENT_SOURCE_IS_TIME(s->type)) { - struct clock_data *d; - - d = event_get_clock_data(s->event, s->type); - assert(d); - - prioq_reshuffle(d->earliest, s, &s->time.earliest_index); - prioq_reshuffle(d->latest, s, &s->time.latest_index); - d->needs_rearm = true; - } + if (EVENT_SOURCE_IS_TIME(s->type)) + event_source_time_prioq_reshuffle(s); if (s->type == SOURCE_SIGNAL && !b) { struct signal_data *d; @@ -2207,11 +2226,7 @@ _public_ int sd_event_source_set_priority(sd_event_source *s, int64_t priority) } else s->priority = priority; - if (s->pending) - prioq_reshuffle(s->event->pending, s, &s->pending_index); - - if (s->prepare) - prioq_reshuffle(s->event->prepare, s, &s->prepare_index); + event_source_pp_prioq_reshuffle(s); if (s->type == SOURCE_EXIT) prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index); @@ -2237,189 +2252,182 @@ _public_ int sd_event_source_get_enabled(sd_event_source *s, int *m) { return s->enabled != SD_EVENT_OFF; } -_public_ int sd_event_source_set_enabled(sd_event_source *s, int m) { +static int event_source_disable(sd_event_source *s) { int r; - assert_return(s, -EINVAL); - assert_return(IN_SET(m, SD_EVENT_OFF, SD_EVENT_ON, SD_EVENT_ONESHOT), -EINVAL); - assert_return(!event_pid_changed(s->event), -ECHILD); - - /* If we are dead anyway, we are fine with turning off - * sources, but everything else needs to fail. */ - if (s->event->state == SD_EVENT_FINISHED) - return m == SD_EVENT_OFF ? 0 : -ESTALE; - - if (s->enabled == m) - return 0; + assert(s); + assert(s->enabled != SD_EVENT_OFF); - if (m == SD_EVENT_OFF) { + /* Unset the pending flag when this event source is disabled */ + if (!IN_SET(s->type, SOURCE_DEFER, SOURCE_EXIT)) { + r = source_set_pending(s, false); + if (r < 0) + return r; + } - /* Unset the pending flag when this event source is disabled */ - if (!IN_SET(s->type, SOURCE_DEFER, SOURCE_EXIT)) { - r = source_set_pending(s, false); - if (r < 0) - return r; - } + s->enabled = SD_EVENT_OFF; - switch (s->type) { + switch (s->type) { - case SOURCE_IO: - source_io_unregister(s); - s->enabled = m; - break; + case SOURCE_IO: + source_io_unregister(s); + break; - case SOURCE_TIME_REALTIME: - case SOURCE_TIME_BOOTTIME: - case SOURCE_TIME_MONOTONIC: - case SOURCE_TIME_REALTIME_ALARM: - case SOURCE_TIME_BOOTTIME_ALARM: { - struct clock_data *d; + case SOURCE_TIME_REALTIME: + case SOURCE_TIME_BOOTTIME: + case SOURCE_TIME_MONOTONIC: + case SOURCE_TIME_REALTIME_ALARM: + case SOURCE_TIME_BOOTTIME_ALARM: + event_source_time_prioq_reshuffle(s); + break; - s->enabled = m; - d = event_get_clock_data(s->event, s->type); - assert(d); + case SOURCE_SIGNAL: + event_gc_signal_data(s->event, &s->priority, s->signal.sig); + break; - prioq_reshuffle(d->earliest, s, &s->time.earliest_index); - prioq_reshuffle(d->latest, s, &s->time.latest_index); - d->needs_rearm = true; - break; - } + case SOURCE_CHILD: + assert(s->event->n_enabled_child_sources > 0); + s->event->n_enabled_child_sources--; - case SOURCE_SIGNAL: - s->enabled = m; + if (EVENT_SOURCE_WATCH_PIDFD(s)) + source_child_pidfd_unregister(s); + else + event_gc_signal_data(s->event, &s->priority, SIGCHLD); + break; - event_gc_signal_data(s->event, &s->priority, s->signal.sig); - break; + case SOURCE_EXIT: + prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index); + break; - case SOURCE_CHILD: - s->enabled = m; + case SOURCE_DEFER: + case SOURCE_POST: + case SOURCE_INOTIFY: + break; - assert(s->event->n_enabled_child_sources > 0); - s->event->n_enabled_child_sources--; + default: + assert_not_reached("Wut? I shouldn't exist."); + } - if (EVENT_SOURCE_WATCH_PIDFD(s)) - source_child_pidfd_unregister(s); - else - event_gc_signal_data(s->event, &s->priority, SIGCHLD); + return 0; +} - break; +static int event_source_enable(sd_event_source *s, int m) { + int r; - case SOURCE_EXIT: - s->enabled = m; - prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index); - break; + assert(s); + assert(IN_SET(m, SD_EVENT_ON, SD_EVENT_ONESHOT)); + assert(s->enabled == SD_EVENT_OFF); - case SOURCE_DEFER: - case SOURCE_POST: - case SOURCE_INOTIFY: - s->enabled = m; - break; + /* Unset the pending flag when this event source is enabled */ + if (!IN_SET(s->type, SOURCE_DEFER, SOURCE_EXIT)) { + r = source_set_pending(s, false); + if (r < 0) + return r; + } - default: - assert_not_reached("Wut? I shouldn't exist."); - } + s->enabled = m; - } else { + switch (s->type) { - /* Unset the pending flag when this event source is enabled */ - if (s->enabled == SD_EVENT_OFF && !IN_SET(s->type, SOURCE_DEFER, SOURCE_EXIT)) { - r = source_set_pending(s, false); - if (r < 0) - return r; + case SOURCE_IO: + r = source_io_register(s, m, s->io.events); + if (r < 0) { + s->enabled = SD_EVENT_OFF; + return r; } - switch (s->type) { - - case SOURCE_IO: - r = source_io_register(s, m, s->io.events); - if (r < 0) - return r; + break; - s->enabled = m; - break; + case SOURCE_TIME_REALTIME: + case SOURCE_TIME_BOOTTIME: + case SOURCE_TIME_MONOTONIC: + case SOURCE_TIME_REALTIME_ALARM: + case SOURCE_TIME_BOOTTIME_ALARM: + event_source_time_prioq_reshuffle(s); + break; - case SOURCE_TIME_REALTIME: - case SOURCE_TIME_BOOTTIME: - case SOURCE_TIME_MONOTONIC: - case SOURCE_TIME_REALTIME_ALARM: - case SOURCE_TIME_BOOTTIME_ALARM: { - struct clock_data *d; + case SOURCE_SIGNAL: + r = event_make_signal_data(s->event, s->signal.sig, NULL); + if (r < 0) { + s->enabled = SD_EVENT_OFF; + event_gc_signal_data(s->event, &s->priority, s->signal.sig); + return r; + } - s->enabled = m; - d = event_get_clock_data(s->event, s->type); - assert(d); + break; - prioq_reshuffle(d->earliest, s, &s->time.earliest_index); - prioq_reshuffle(d->latest, s, &s->time.latest_index); - d->needs_rearm = true; - break; - } + case SOURCE_CHILD: + s->event->n_enabled_child_sources++; - case SOURCE_SIGNAL: + if (EVENT_SOURCE_WATCH_PIDFD(s)) { + /* yes, we have pidfd */ - s->enabled = m; + r = source_child_pidfd_register(s, s->enabled); + if (r < 0) { + s->enabled = SD_EVENT_OFF; + s->event->n_enabled_child_sources--; + return r; + } + } else { + /* no pidfd, or something other to watch for than WEXITED */ - r = event_make_signal_data(s->event, s->signal.sig, NULL); + r = event_make_signal_data(s->event, SIGCHLD, NULL); if (r < 0) { s->enabled = SD_EVENT_OFF; - event_gc_signal_data(s->event, &s->priority, s->signal.sig); + s->event->n_enabled_child_sources--; + event_gc_signal_data(s->event, &s->priority, SIGCHLD); return r; } + } - break; + break; - case SOURCE_CHILD: + case SOURCE_EXIT: + prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index); + break; - if (s->enabled == SD_EVENT_OFF) - s->event->n_enabled_child_sources++; + case SOURCE_DEFER: + case SOURCE_POST: + case SOURCE_INOTIFY: + break; - s->enabled = m; + default: + assert_not_reached("Wut? I shouldn't exist."); + } - if (EVENT_SOURCE_WATCH_PIDFD(s)) { - /* yes, we have pidfd */ + return 0; +} - r = source_child_pidfd_register(s, s->enabled); - if (r < 0) { - s->enabled = SD_EVENT_OFF; - s->event->n_enabled_child_sources--; - return r; - } - } else { - /* no pidfd, or something other to watch for than WEXITED */ +_public_ int sd_event_source_set_enabled(sd_event_source *s, int m) { + int r; - r = event_make_signal_data(s->event, SIGCHLD, NULL); - if (r < 0) { - s->enabled = SD_EVENT_OFF; - s->event->n_enabled_child_sources--; - event_gc_signal_data(s->event, &s->priority, SIGCHLD); - return r; - } - } + assert_return(s, -EINVAL); + assert_return(IN_SET(m, SD_EVENT_OFF, SD_EVENT_ON, SD_EVENT_ONESHOT), -EINVAL); + assert_return(!event_pid_changed(s->event), -ECHILD); - break; + /* If we are dead anyway, we are fine with turning off sources, but everything else needs to fail. */ + if (s->event->state == SD_EVENT_FINISHED) + return m == SD_EVENT_OFF ? 0 : -ESTALE; - case SOURCE_EXIT: - s->enabled = m; - prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index); - break; + if (s->enabled == m) /* No change? */ + return 0; - case SOURCE_DEFER: - case SOURCE_POST: - case SOURCE_INOTIFY: + if (m == SD_EVENT_OFF) + r = event_source_disable(s); + else { + if (s->enabled != SD_EVENT_OFF) { + /* Switching from "on" to "oneshot" or back? If that's the case, we can take a shortcut, the + * event source is already enabled after all. */ s->enabled = m; - break; - - default: - assert_not_reached("Wut? I shouldn't exist."); + return 0; } - } - - if (s->pending) - prioq_reshuffle(s->event->pending, s, &s->pending_index); - if (s->prepare) - prioq_reshuffle(s->event->prepare, s, &s->prepare_index); + r = event_source_enable(s, m); + } + if (r < 0) + return r; + event_source_pp_prioq_reshuffle(s); return 0; } @@ -2434,7 +2442,6 @@ _public_ int sd_event_source_get_time(sd_event_source *s, uint64_t *usec) { } _public_ int sd_event_source_set_time(sd_event_source *s, uint64_t usec) { - struct clock_data *d; int r; assert_return(s, -EINVAL); @@ -2448,13 +2455,7 @@ _public_ int sd_event_source_set_time(sd_event_source *s, uint64_t usec) { s->time.next = usec; - d = event_get_clock_data(s->event, s->type); - assert(d); - - prioq_reshuffle(d->earliest, s, &s->time.earliest_index); - prioq_reshuffle(d->latest, s, &s->time.latest_index); - d->needs_rearm = true; - + event_source_time_prioq_reshuffle(s); return 0; } @@ -2486,7 +2487,6 @@ _public_ int sd_event_source_get_time_accuracy(sd_event_source *s, uint64_t *use } _public_ int sd_event_source_set_time_accuracy(sd_event_source *s, uint64_t usec) { - struct clock_data *d; int r; assert_return(s, -EINVAL); @@ -2504,12 +2504,7 @@ _public_ int sd_event_source_set_time_accuracy(sd_event_source *s, uint64_t usec s->time.accuracy = usec; - d = event_get_clock_data(s->event, s->type); - assert(d); - - prioq_reshuffle(d->latest, s, &s->time.latest_index); - d->needs_rearm = true; - + event_source_time_prioq_reshuffle(s); return 0; } @@ -2888,9 +2883,7 @@ static int process_timer( if (r < 0) return r; - prioq_reshuffle(d->earliest, s, &s->time.earliest_index); - prioq_reshuffle(d->latest, s, &s->time.latest_index); - d->needs_rearm = true; + event_source_time_prioq_reshuffle(s); } return 0; diff --git a/src/network/netdev/wireguard.h b/src/network/netdev/wireguard.h index 61113113e4b..e2c06f03776 100644 --- a/src/network/netdev/wireguard.h +++ b/src/network/netdev/wireguard.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #pragma once typedef struct Wireguard Wireguard; diff --git a/src/network/test-network-tables.c b/src/network/test-network-tables.c index 25b93963977..7743c63d4a7 100644 --- a/src/network/test-network-tables.c +++ b/src/network/test-network-tables.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include "bond.h" #include "dhcp6-internal.h" #include "dhcp6-protocol.h" diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index 683f1137515..2c243811718 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -436,20 +436,22 @@ static int dns_cache_put_positive( dns_cache_make_space(c, 1); - i = new0(DnsCacheItem, 1); + i = new(DnsCacheItem, 1); if (!i) return -ENOMEM; - i->type = DNS_CACHE_POSITIVE; - i->key = dns_resource_key_ref(rr->key); - i->rr = dns_resource_record_ref(rr); - i->until = calculate_until(rr, (uint32_t) -1, timestamp, false); - i->authenticated = authenticated; - i->shared_owner = shared_owner; - i->ifindex = ifindex; - i->owner_family = owner_family; - i->owner_address = *owner_address; - i->prioq_idx = PRIOQ_IDX_NULL; + *i = (DnsCacheItem) { + .type = DNS_CACHE_POSITIVE, + .key = dns_resource_key_ref(rr->key), + .rr = dns_resource_record_ref(rr), + .until = calculate_until(rr, (uint32_t) -1, timestamp, false), + .authenticated = authenticated, + .shared_owner = shared_owner, + .ifindex = ifindex, + .owner_family = owner_family, + .owner_address = *owner_address, + .prioq_idx = PRIOQ_IDX_NULL, + }; r = dns_cache_link_item(c, i); if (r < 0) @@ -521,21 +523,23 @@ static int dns_cache_put_negative( dns_cache_make_space(c, 1); - i = new0(DnsCacheItem, 1); + i = new(DnsCacheItem, 1); if (!i) return -ENOMEM; - i->type = - rcode == DNS_RCODE_SUCCESS ? DNS_CACHE_NODATA : - rcode == DNS_RCODE_NXDOMAIN ? DNS_CACHE_NXDOMAIN : DNS_CACHE_RCODE; - i->until = - i->type == DNS_CACHE_RCODE ? timestamp + CACHE_TTL_STRANGE_RCODE_USEC : - calculate_until(soa, nsec_ttl, timestamp, true); - i->authenticated = authenticated; - i->owner_family = owner_family; - i->owner_address = *owner_address; - i->prioq_idx = PRIOQ_IDX_NULL; - i->rcode = rcode; + *i = (DnsCacheItem) { + .type = + rcode == DNS_RCODE_SUCCESS ? DNS_CACHE_NODATA : + rcode == DNS_RCODE_NXDOMAIN ? DNS_CACHE_NXDOMAIN : DNS_CACHE_RCODE, + .until = + i->type == DNS_CACHE_RCODE ? timestamp + CACHE_TTL_STRANGE_RCODE_USEC : + calculate_until(soa, nsec_ttl, timestamp, true), + .authenticated = authenticated, + .owner_family = owner_family, + .owner_address = *owner_address, + .prioq_idx = PRIOQ_IDX_NULL, + .rcode = rcode, + }; if (i->type == DNS_CACHE_NXDOMAIN) { /* NXDOMAIN entries should apply equally to all types, so we use ANY as diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index 62240399925..05fa88ec892 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -75,12 +75,16 @@ int dns_packet_new( if (!p) return -ENOMEM; - p->size = p->rindex = DNS_PACKET_HEADER_SIZE; - p->allocated = a; - p->max_size = max_size; - p->protocol = protocol; - p->opt_start = p->opt_size = (size_t) -1; - p->n_ref = 1; + *p = (DnsPacket) { + .n_ref = 1, + .protocol = protocol, + .size = DNS_PACKET_HEADER_SIZE, + .rindex = DNS_PACKET_HEADER_SIZE, + .allocated = a, + .max_size = max_size, + .opt_start = (size_t) -1, + .opt_size = (size_t) -1, + }; *ret = p; diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c index 1eff893b21d..ef54c04ab0c 100644 --- a/src/resolve/resolved-dns-query.c +++ b/src/resolve/resolved-dns-query.c @@ -21,12 +21,14 @@ static int dns_query_candidate_new(DnsQueryCandidate **ret, DnsQuery *q, DnsScop assert(q); assert(s); - c = new0(DnsQueryCandidate, 1); + c = new(DnsQueryCandidate, 1); if (!c) return -ENOMEM; - c->query = q; - c->scope = s; + *c = (DnsQueryCandidate) { + .query = q, + .scope = s, + }; LIST_PREPEND(candidates_by_query, q->candidates, c); LIST_PREPEND(candidates_by_scope, s->query_candidates, c); @@ -413,17 +415,19 @@ int dns_query_new( if (m->n_dns_queries >= QUERIES_MAX) return -EBUSY; - q = new0(DnsQuery, 1); + q = new(DnsQuery, 1); if (!q) return -ENOMEM; - q->question_utf8 = dns_question_ref(question_utf8); - q->question_idna = dns_question_ref(question_idna); - q->ifindex = ifindex; - q->flags = flags; - q->answer_dnssec_result = _DNSSEC_RESULT_INVALID; - q->answer_protocol = _DNS_PROTOCOL_INVALID; - q->answer_family = AF_UNSPEC; + *q = (DnsQuery) { + .question_utf8 = dns_question_ref(question_utf8), + .question_idna = dns_question_ref(question_idna), + .ifindex = ifindex, + .flags = flags, + .answer_dnssec_result = _DNSSEC_RESULT_INVALID, + .answer_protocol = _DNS_PROTOCOL_INVALID, + .answer_family = AF_UNSPEC, + }; /* First dump UTF8 question */ DNS_QUESTION_FOREACH(key, question_utf8) diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c index 63ed9ebf10c..9ca7ad96fd2 100644 --- a/src/resolve/resolved-dns-rr.c +++ b/src/resolve/resolved-dns-rr.c @@ -97,14 +97,16 @@ DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char assert(name); - k = new0(DnsResourceKey, 1); + k = new(DnsResourceKey, 1); if (!k) return NULL; - k->n_ref = 1; - k->class = class; - k->type = type; - k->_name = name; + *k = (DnsResourceKey) { + .n_ref = 1, + .class = class, + .type = type, + ._name = name, + }; return k; } @@ -372,14 +374,17 @@ bool dns_resource_key_reduce(DnsResourceKey **a, DnsResourceKey **b) { DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) { DnsResourceRecord *rr; - rr = new0(DnsResourceRecord, 1); + rr = new(DnsResourceRecord, 1); if (!rr) return NULL; - rr->n_ref = 1; - rr->key = dns_resource_key_ref(key); - rr->expiry = USEC_INFINITY; - rr->n_skip_labels_signer = rr->n_skip_labels_source = (unsigned) -1; + *rr = (DnsResourceRecord) { + .n_ref = 1, + .key = dns_resource_key_ref(key), + .expiry = USEC_INFINITY, + .n_skip_labels_signer = (unsigned) -1, + .n_skip_labels_source = (unsigned) -1, + }; return rr; } diff --git a/src/resolve/resolved-dns-search-domain.c b/src/resolve/resolved-dns-search-domain.c index 425a4633494..420c9298144 100644 --- a/src/resolve/resolved-dns-search-domain.c +++ b/src/resolve/resolved-dns-search-domain.c @@ -33,14 +33,16 @@ int dns_search_domain_new( return -E2BIG; } - d = new0(DnsSearchDomain, 1); + d = new(DnsSearchDomain, 1); if (!d) return -ENOMEM; - d->n_ref = 1; - d->manager = m; - d->type = type; - d->name = TAKE_PTR(normalized); + *d = (DnsSearchDomain) { + .n_ref = 1, + .manager = m, + .type = type, + .name = TAKE_PTR(normalized), + }; switch (type) { diff --git a/src/resolve/resolved-dns-stub.c b/src/resolve/resolved-dns-stub.c index 445fa86dd1f..6fdd26399ee 100644 --- a/src/resolve/resolved-dns-stub.c +++ b/src/resolve/resolved-dns-stub.c @@ -15,6 +15,9 @@ * IP and UDP header sizes */ #define ADVERTISE_DATAGRAM_SIZE_MAX (65536U-14U-20U-8U) +/* On the extra stubs, use a more conservative choice */ +#define ADVERTISE_EXTRA_DATAGRAM_SIZE_MAX DNS_PACKET_UNICAST_SIZE_LARGE_MAX + static int manager_dns_stub_fd_extra(Manager *m, DnsStubListenerExtra *l, int type); static void dns_stub_listener_extra_hash_func(const DnsStubListenerExtra *a, struct siphash *state) { @@ -155,14 +158,15 @@ static int dns_stub_finish_reply_packet( bool tc, /* set the Truncated bit? */ bool add_opt, /* add an OPT RR to this packet? */ bool edns0_do, /* set the EDNS0 DNSSEC OK bit? */ - bool ad) { /* set the DNSSEC authenticated data bit? */ + bool ad, /* set the DNSSEC authenticated data bit? */ + uint16_t max_udp_size) { /* The maximum UDP datagram size to advertise to clients */ int r; assert(p); if (add_opt) { - r = dns_packet_append_opt(p, ADVERTISE_DATAGRAM_SIZE_MAX, edns0_do, /* include_rfc6975 = */ false, rcode, NULL); + r = dns_packet_append_opt(p, max_udp_size, edns0_do, /* include_rfc6975 = */ false, rcode, NULL); if (r == -EMSGSIZE) /* Hit the size limit? then indicate truncation */ tc = true; else if (r < 0) @@ -245,7 +249,15 @@ static int dns_stub_send_failure( if (r < 0) return log_debug_errno(r, "Failed to make failure packet: %m"); - r = dns_stub_finish_reply_packet(reply, DNS_PACKET_ID(p), rcode, false, !!p->opt, DNS_PACKET_DO(p), authenticated); + r = dns_stub_finish_reply_packet( + reply, + DNS_PACKET_ID(p), + rcode, + /* truncated = */ false, + !!p->opt, + DNS_PACKET_DO(p), + authenticated, + l ? ADVERTISE_EXTRA_DATAGRAM_SIZE_MAX : ADVERTISE_DATAGRAM_SIZE_MAX); if (r < 0) return log_debug_errno(r, "Failed to build failure packet: %m"); @@ -290,7 +302,8 @@ static void dns_stub_query_complete(DnsQuery *q) { truncated, !!q->request_dns_packet->opt, DNS_PACKET_DO(q->request_dns_packet), - dns_query_fully_authenticated(q)); + dns_query_fully_authenticated(q), + q->stub_listener_extra ? ADVERTISE_EXTRA_DATAGRAM_SIZE_MAX : ADVERTISE_DATAGRAM_SIZE_MAX); if (r < 0) { log_debug_errno(r, "Failed to finish reply packet: %m"); break; diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index 36f57eae629..15f349d623e 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -194,19 +194,20 @@ int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key) if (r < 0) return r; - t = new0(DnsTransaction, 1); + t = new(DnsTransaction, 1); if (!t) return -ENOMEM; - t->dns_udp_fd = -1; - t->answer_source = _DNS_TRANSACTION_SOURCE_INVALID; - t->answer_dnssec_result = _DNSSEC_RESULT_INVALID; - t->answer_nsec_ttl = (uint32_t) -1; - t->key = dns_resource_key_ref(key); - t->current_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID; - t->clamp_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID; - - t->id = pick_new_id(s->manager); + *t = (DnsTransaction) { + .dns_udp_fd = -1, + .answer_source = _DNS_TRANSACTION_SOURCE_INVALID, + .answer_dnssec_result = _DNSSEC_RESULT_INVALID, + .answer_nsec_ttl = (uint32_t) -1, + .key = dns_resource_key_ref(key), + .current_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID, + .clamp_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID, + .id = pick_new_id(s->manager), + }; r = hashmap_put(s->manager->dns_transactions, UINT_TO_PTR(t->id), t); if (r < 0) { @@ -1112,58 +1113,52 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p) { if (r > 0) /* Transaction got restarted... */ return; - if (IN_SET(t->scope->protocol, DNS_PROTOCOL_DNS, DNS_PROTOCOL_LLMNR, DNS_PROTOCOL_MDNS)) { - - /* When dealing with protocols other than mDNS only consider responses with - * equivalent query section to the request. For mDNS this check doesn't make - * sense, because the section 6 of RFC6762 states that "Multicast DNS responses MUST NOT - * contain any questions in the Question Section". */ - if (t->scope->protocol != DNS_PROTOCOL_MDNS) { - r = dns_packet_is_reply_for(p, t->key); - if (r < 0) - goto fail; - if (r == 0) { - dns_transaction_complete(t, DNS_TRANSACTION_INVALID_REPLY); - return; - } + /* When dealing with protocols other than mDNS only consider responses with equivalent query section + * to the request. For mDNS this check doesn't make sense, because the section 6 of RFC6762 states + * that "Multicast DNS responses MUST NOT contain any questions in the Question Section". */ + if (t->scope->protocol != DNS_PROTOCOL_MDNS) { + r = dns_packet_is_reply_for(p, t->key); + if (r < 0) + goto fail; + if (r == 0) { + dns_transaction_complete(t, DNS_TRANSACTION_INVALID_REPLY); + return; } + } - /* Install the answer as answer to the transaction */ - dns_answer_unref(t->answer); - t->answer = dns_answer_ref(p->answer); - t->answer_rcode = DNS_PACKET_RCODE(p); - t->answer_dnssec_result = _DNSSEC_RESULT_INVALID; - t->answer_authenticated = false; + /* Install the answer as answer to the transaction */ + dns_answer_unref(t->answer); + t->answer = dns_answer_ref(p->answer); + t->answer_rcode = DNS_PACKET_RCODE(p); + t->answer_dnssec_result = _DNSSEC_RESULT_INVALID; + t->answer_authenticated = false; - r = dns_transaction_fix_rcode(t); - if (r < 0) - goto fail; + r = dns_transaction_fix_rcode(t); + if (r < 0) + goto fail; - /* Block GC while starting requests for additional DNSSEC RRs */ - t->block_gc++; - r = dns_transaction_request_dnssec_keys(t); - t->block_gc--; + /* Block GC while starting requests for additional DNSSEC RRs */ + t->block_gc++; + r = dns_transaction_request_dnssec_keys(t); + t->block_gc--; - /* Maybe the transaction is ready for GC'ing now? If so, free it and return. */ - if (!dns_transaction_gc(t)) - return; + /* Maybe the transaction is ready for GC'ing now? If so, free it and return. */ + if (!dns_transaction_gc(t)) + return; - /* Requesting additional keys might have resulted in - * this transaction to fail, since the auxiliary - * request failed for some reason. If so, we are not - * in pending state anymore, and we should exit - * quickly. */ - if (t->state != DNS_TRANSACTION_PENDING) - return; - if (r < 0) - goto fail; - if (r > 0) { - /* There are DNSSEC transactions pending now. Update the state accordingly. */ - t->state = DNS_TRANSACTION_VALIDATING; - dns_transaction_close_connection(t); - dns_transaction_stop_timeout(t); - return; - } + /* Requesting additional keys might have resulted in this transaction to fail, since the auxiliary + * request failed for some reason. If so, we are not in pending state anymore, and we should exit + * quickly. */ + if (t->state != DNS_TRANSACTION_PENDING) + return; + if (r < 0) + goto fail; + if (r > 0) { + /* There are DNSSEC transactions pending now. Update the state accordingly. */ + t->state = DNS_TRANSACTION_VALIDATING; + dns_transaction_close_connection(t); + dns_transaction_stop_timeout(t); + return; } dns_transaction_process_dnssec(t); diff --git a/src/resolve/resolved-dns-zone.c b/src/resolve/resolved-dns-zone.c index f8e1491f8be..44554d8cdb6 100644 --- a/src/resolve/resolved-dns-zone.c +++ b/src/resolve/resolved-dns-zone.c @@ -231,13 +231,15 @@ int dns_zone_put(DnsZone *z, DnsScope *s, DnsResourceRecord *rr, bool probe) { if (r < 0) return r; - i = new0(DnsZoneItem, 1); + i = new(DnsZoneItem, 1); if (!i) return -ENOMEM; - i->scope = s; - i->rr = dns_resource_record_ref(rr); - i->probing_enabled = probe; + *i = (DnsZoneItem) { + .scope = s, + .rr = dns_resource_record_ref(rr), + .probing_enabled = probe, + }; r = dns_zone_link_item(z, i); if (r < 0) diff --git a/src/resolve/resolved-dnssd-bus.h b/src/resolve/resolved-dnssd-bus.h index 403455e89f4..e51c9ac1457 100644 --- a/src/resolve/resolved-dnssd-bus.h +++ b/src/resolve/resolved-dnssd-bus.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #pragma once #include "sd-bus.h" diff --git a/src/resolve/resolved-dnssd.h b/src/resolve/resolved-dnssd.h index 304bd890c95..faba11ca53c 100644 --- a/src/resolve/resolved-dnssd.h +++ b/src/resolve/resolved-dnssd.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #pragma once #include "list.h" diff --git a/src/resolve/resolved-etc-hosts.c b/src/resolve/resolved-etc-hosts.c index 6a7f7499572..4a748d4b64d 100644 --- a/src/resolve/resolved-etc-hosts.c +++ b/src/resolve/resolved-etc-hosts.c @@ -80,11 +80,13 @@ static int parse_line(EtcHosts *hosts, unsigned nr, const char *line) { if (r < 0) return log_oom(); - item = new0(EtcHostsItem, 1); + item = new(EtcHostsItem, 1); if (!item) return log_oom(); - item->address = address; + *item = (EtcHostsItem) { + .address = address, + }; r = hashmap_put(hosts->by_address, &item->address, item); if (r < 0) { diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c index 79d84dde1fa..6215d2bf464 100644 --- a/src/resolve/resolved-link.c +++ b/src/resolve/resolved-link.c @@ -818,14 +818,16 @@ int link_address_new(Link *l, LinkAddress **ret, int family, const union in_addr assert(l); assert(in_addr); - a = new0(LinkAddress, 1); + a = new(LinkAddress, 1); if (!a) return -ENOMEM; - a->family = family; - a->in_addr = *in_addr; + *a = (LinkAddress) { + .family = family, + .in_addr = *in_addr, + .link = l, + }; - a->link = l; LIST_PREPEND(addresses, l->addresses, a); l->n_addresses++; diff --git a/src/shared/binfmt-util.c b/src/shared/binfmt-util.c index 0229726b42d..c673c0435d8 100644 --- a/src/shared/binfmt-util.c +++ b/src/shared/binfmt-util.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include #include #include diff --git a/src/shared/dm-util.c b/src/shared/dm-util.c index 7efcb6b2aae..cfb13bad4c9 100644 --- a/src/shared/dm-util.c +++ b/src/shared/dm-util.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include #include #include diff --git a/src/shared/initreq.h b/src/shared/initreq.h index 1d7ff81df1f..1bf5b8edd7f 100644 --- a/src/shared/initreq.h +++ b/src/shared/initreq.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2+ */ /* * initreq.h Interface to talk to init through /dev/initctl. * diff --git a/src/shared/linux/nl80211.h b/src/shared/linux/nl80211.h index b065c1fe4df..65edfff1ca4 100644 --- a/src/shared/linux/nl80211.h +++ b/src/shared/linux/nl80211.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: MIT */ + #ifndef __LINUX_NL80211_H #define __LINUX_NL80211_H /* diff --git a/src/shared/meson.build b/src/shared/meson.build index 0ed216f1aaa..260ee5a8b63 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -195,6 +195,8 @@ shared_sources = files(''' ptyfwd.h pwquality-util.c pwquality-util.h + qrcode-util.c + qrcode-util.h reboot-util.c reboot-util.h resize-fs.c @@ -304,13 +306,6 @@ if conf.get('HAVE_PAM') == 1 '''.split()) endif -if conf.get('HAVE_QRENCODE') == 1 - shared_sources += files(''' - qrcode-util.c - qrcode-util.h -'''.split()) -endif - generate_ip_protocol_list = find_program('generate-ip-protocol-list.sh') ip_protocol_list_txt = custom_target( 'ip-protocol-list.txt', diff --git a/src/shared/pam-util.c b/src/shared/pam-util.c index f000798ce06..ff44df7762d 100644 --- a/src/shared/pam-util.c +++ b/src/shared/pam-util.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include #include #include diff --git a/src/shared/pe-header.h b/src/shared/pe-header.h index a3629175239..13cb1d8a15c 100644 --- a/src/shared/pe-header.h +++ b/src/shared/pe-header.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #pragma once #include diff --git a/src/shared/qrcode-util.c b/src/shared/qrcode-util.c index a545daaef3f..96d3df493ab 100644 --- a/src/shared/qrcode-util.c +++ b/src/shared/qrcode-util.c @@ -1,25 +1,29 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include "qrcode-util.h" + +#if HAVE_QRENCODE +#include + +#include "dlfcn-util.h" +#include "locale-util.h" #include "terminal-util.h" #define ANSI_WHITE_ON_BLACK "\033[40;37;1m" static void print_border(FILE *output, unsigned width) { - unsigned x, y; - /* Four rows of border */ - for (y = 0; y < 4; y += 2) { + for (unsigned y = 0; y < 4; y += 2) { fputs(ANSI_WHITE_ON_BLACK, output); - for (x = 0; x < 4 + width + 4; x++) + for (unsigned x = 0; x < 4 + width + 4; x++) fputs("\342\226\210", output); fputs(ANSI_NORMAL "\n", output); } } -void write_qrcode(FILE *output, QRcode *qr) { - unsigned x, y; - +static void write_qrcode(FILE *output, QRcode *qr) { assert(qr); if (!output) @@ -27,17 +31,15 @@ void write_qrcode(FILE *output, QRcode *qr) { print_border(output, qr->width); - for (y = 0; y < (unsigned) qr->width; y += 2) { - const uint8_t *row1, *row2; - - row1 = qr->data + qr->width * y; - row2 = row1 + qr->width; + for (unsigned y = 0; y < (unsigned) qr->width; y += 2) { + const uint8_t *row1 = qr->data + qr->width * y; + const uint8_t *row2 = row1 + qr->width; fputs(ANSI_WHITE_ON_BLACK, output); - for (x = 0; x < 4; x++) + for (unsigned x = 0; x < 4; x++) fputs("\342\226\210", output); - for (x = 0; x < (unsigned) qr->width; x ++) { + for (unsigned x = 0; x < (unsigned) qr->width; x++) { bool a, b; a = row1[x] & 1; @@ -53,7 +55,7 @@ void write_qrcode(FILE *output, QRcode *qr) { fputs("\342\226\210", output); } - for (x = 0; x < 4; x++) + for (unsigned x = 0; x < 4; x++) fputs("\342\226\210", output); fputs(ANSI_NORMAL "\n", output); } @@ -61,3 +63,45 @@ void write_qrcode(FILE *output, QRcode *qr) { print_border(output, qr->width); fflush(output); } + +int print_qrcode(FILE *out, const char *header, const char *string) { + QRcode* (*sym_QRcode_encodeString)(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive); + void (*sym_QRcode_free)(QRcode *qrcode); + _cleanup_(dlclosep) void *dl = NULL; + QRcode* qr; + int r; + + /* If this is not an UTF-8 system or ANSI colors aren't supported/disabled don't print any QR + * codes */ + if (!is_locale_utf8() || !colors_enabled()) + return -EOPNOTSUPP; + + dl = dlopen("libqrencode.so.4", RTLD_LAZY); + if (!dl) + return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), + "QRCODE support is not installed: %s", dlerror()); + + r = dlsym_many_and_warn( + dl, + LOG_DEBUG, + &sym_QRcode_encodeString, "QRcode_encodeString", + &sym_QRcode_free, "QRcode_free", + NULL); + if (r < 0) + return r; + + qr = sym_QRcode_encodeString(string, 0, QR_ECLEVEL_L, QR_MODE_8, 0); + if (!qr) + return -ENOMEM; + + if (header) + fprintf(out, "\n%s:\n\n", header); + + write_qrcode(out, qr); + + fputc('\n', out); + + sym_QRcode_free(qr); + return 0; +} +#endif diff --git a/src/shared/qrcode-util.h b/src/shared/qrcode-util.h index 9a21ffd7fe6..036c3f7f90d 100644 --- a/src/shared/qrcode-util.h +++ b/src/shared/qrcode-util.h @@ -1,9 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#pragma once -#if HAVE_QRENCODE -#include +#pragma once #include +#include -void write_qrcode(FILE *output, QRcode *qr); +#if HAVE_QRENCODE +int print_qrcode(FILE *out, const char *header, const char *string); +#else +static inline int print_qrcode(FILE *out, const char *header, const char *string) { + return -EOPNOTSUPP; +} #endif diff --git a/src/test/meson.build b/src/test/meson.build index daf62eb539a..e4ce8ac51ae 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -819,6 +819,10 @@ tests += [ [['src/test/test-psi-util.c'], [], []], + + [['src/test/test-qrcode-util.c'], + [libshared], + [libdl]], ] ############################################################ diff --git a/src/test/test-qrcode-util.c b/src/test/test-qrcode-util.c new file mode 100644 index 00000000000..c4e2894eb71 --- /dev/null +++ b/src/test/test-qrcode-util.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#include "locale-util.h" +#include "main-func.h" +#include "qrcode-util.h" +#include "tests.h" + +static int run(int argc, char **argv) { + int r; + + test_setup_logging(LOG_DEBUG); + + assert_se(setenv("SYSTEMD_COLORS", "1", 1) == 0); /* Force the qrcode to be printed */ + + r = print_qrcode(stdout, "This should say \"TEST\"", "TEST"); + if (r == -EOPNOTSUPP) + return log_tests_skipped("not supported"); + if (r < 0) + return log_error_errno(r, "Failed to print QR code: %m"); + return 0; +} + +DEFINE_MAIN_FUNCTION(run); diff --git a/src/test/test-sd-hwdb.c b/src/test/test-sd-hwdb.c index eb34d8eab2d..8746a841d43 100644 --- a/src/test/test-sd-hwdb.c +++ b/src/test/test-sd-hwdb.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + #include "sd-hwdb.h" #include "alloc-util.h" diff --git a/src/time-wait-sync/time-wait-sync.c b/src/time-wait-sync/time-wait-sync.c index 96072445f6e..02053e77087 100644 --- a/src/time-wait-sync/time-wait-sync.c +++ b/src/time-wait-sync/time-wait-sync.c @@ -1,11 +1,5 @@ -/* - * systemd service to wait until kernel realtime clock is synchronized - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* systemd service to wait until kernel realtime clock is synchronized */ #include #include diff --git a/units/initrd-cryptsetup.target b/units/initrd-cryptsetup.target deleted file mode 100644 index 2a2938c8955..00000000000 --- a/units/initrd-cryptsetup.target +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1+ -# -# This file is part of systemd. -# -# systemd is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation; either version 2.1 of the License, or -# (at your option) any later version. - -[Unit] -Description=Initrd Encrypted Volumes -Documentation=man:systemd.special(7) -OnFailure=emergency.target -OnFailureJobMode=replace-irreversibly -AssertPathExists=/etc/initrd-release -DefaultDependencies=no -Conflicts=shutdown.target diff --git a/units/meson.build b/units/meson.build index a55e7178688..2f09590736e 100644 --- a/units/meson.build +++ b/units/meson.build @@ -22,14 +22,12 @@ units = [ 'multi-user.target.wants/'], ['getty-pre.target', ''], ['graphical.target', '', - (with_runlevels ? 'runlevel5.target default.target' : 'default.target')], + 'default.target' + (with_runlevels ? ' runlevel5.target' : '')], ['halt.target', ''], ['hibernate.target', 'ENABLE_HIBERNATE'], ['hybrid-sleep.target', 'ENABLE_HIBERNATE'], ['suspend-then-hibernate.target', 'ENABLE_HIBERNATE'], ['initrd-cleanup.service', 'ENABLE_INITRD'], - ['initrd-cryptsetup.target', 'HAVE_LIBCRYPTSETUP ENABLE_INITRD', - 'sysinit.target.wants/'], ['initrd-fs.target', 'ENABLE_INITRD'], ['initrd-parse-etc.service', 'ENABLE_INITRD'], ['initrd-root-device.target', 'ENABLE_INITRD'], @@ -61,8 +59,9 @@ units = [ 'sysinit.target.wants/'], ['proc-sys-fs-binfmt_misc.mount', 'ENABLE_BINFMT'], ['reboot.target', '', - (with_runlevels ? 'runlevel6.target ctrl-alt-del.target' : 'ctrl-alt-del.target')], - ['remote-cryptsetup.target', 'HAVE_LIBCRYPTSETUP'], + 'ctrl-alt-del.target' + (with_runlevels ? ' runlevel6.target' : '')], + ['remote-cryptsetup.target', 'HAVE_LIBCRYPTSETUP', + 'initrd-root-device.target.wants/'], ['remote-fs-pre.target', ''], ['remote-fs.target', ''], ['rescue.target', '',