Merge pull request #34392 from poettering/format-util-split

tweaks to networkd sysctl logging
This commit is contained in:
Daan De Meyer 2024-09-13 09:18:56 +02:00 committed by GitHub
commit 76c774828f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 95 additions and 78 deletions

View file

@ -788,18 +788,22 @@ Defined-By: systemd
Support: %SUPPORT_URL% Support: %SUPPORT_URL%
Documentation: man:systemd-tpm2-setup.service(8) Documentation: man:systemd-tpm2-setup.service(8)
An authorization failure occurred while attempting to enroll a Storage Root Key (SRK) on the Trusted Platform An authorization failure occurred while attempting to enroll a Storage Root Key
Module (TPM). Most likely this means that a PIN/Password (authValue) has been set on the Owner hierarchy of (SRK) on the Trusted Platform Module (TPM). Most likely this means that a
the TPM. PIN/Password (authValue) has been set on the Owner hierarchy of the TPM.
Automatic SRK enrollment on TPMs in such scenarios is not supported. In order to unset the PIN/password Automatic SRK enrollment on TPMs in such scenarios is not supported. In order
protection on the owner hierarchy issue a command like the following: 'tpm2_changeauth -c o -p <OLDPW> ""'. to unset the PIN/password protection on the owner hierarchy issue a command
like the following: 'tpm2_changeauth -c o -p <OLDPW> ""'.
-- 9cf56b8baf9546cf9478783a8de42113 -- 9cf56b8baf9546cf9478783a8de42113
Subject: A foreign process changed a sysctl we manage Subject: A foreign process changed a sysctl systemd-networkd manages
Defined-By: systemd Defined-By: systemd
Support: %SUPPORT_URL% Support: %SUPPORT_URL%
A sysctl handle under /proc/sys/net, which is managed by systemd-networkd, has been changed by another process. The sysctl configuration setting @SYSCTL@, which is managed by
The event is raised only if the written value differs from the current one. systemd-networkd, has been changed by another, unrelated process
The program name, the written value, the previous value, and the value initially set by networkd have been logged. ("@OBJECT_COMM@", PID @OBJECT_PID@). This represents a conflict of ownership
and will likely result in problems later on.
Value changed to "@NEWVALUE@", which should be "@OURVALUE@".

37
src/basic/format-ifname.c Normal file
View file

@ -0,0 +1,37 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "format-ifname.h"
#include "string-util.h"
assert_cc(STRLEN("%") + DECIMAL_STR_MAX(int) <= IF_NAMESIZE);
int format_ifname_full(int ifindex, FormatIfnameFlag flag, char buf[static IF_NAMESIZE]) {
if (ifindex <= 0)
return -EINVAL;
if (if_indextoname(ifindex, buf))
return 0;
if (!FLAGS_SET(flag, FORMAT_IFNAME_IFINDEX))
return -errno;
if (FLAGS_SET(flag, FORMAT_IFNAME_IFINDEX_WITH_PERCENT))
assert_se(snprintf_ok(buf, IF_NAMESIZE, "%%%d", ifindex));
else
assert_se(snprintf_ok(buf, IF_NAMESIZE, "%d", ifindex));
return 0;
}
int format_ifname_full_alloc(int ifindex, FormatIfnameFlag flag, char **ret) {
char buf[IF_NAMESIZE];
int r;
assert(ret);
r = format_ifname_full(ifindex, flag, buf);
if (r < 0)
return r;
return strdup_to(ret, buf);
}

27
src/basic/format-ifname.h Normal file
View file

@ -0,0 +1,27 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <net/if.h>
typedef enum {
FORMAT_IFNAME_IFINDEX = 1 << 0,
FORMAT_IFNAME_IFINDEX_WITH_PERCENT = (1 << 1) | FORMAT_IFNAME_IFINDEX,
} FormatIfnameFlag;
int format_ifname_full(int ifindex, FormatIfnameFlag flag, char buf[static IF_NAMESIZE]);
int format_ifname_full_alloc(int ifindex, FormatIfnameFlag flag, char **ret);
static inline int format_ifname(int ifindex, char buf[static IF_NAMESIZE]) {
return format_ifname_full(ifindex, 0, buf);
}
static inline int format_ifname_alloc(int ifindex, char **ret) {
return format_ifname_full_alloc(ifindex, 0, ret);
}
static inline char* _format_ifname_full(int ifindex, FormatIfnameFlag flag, char buf[static IF_NAMESIZE]) {
(void) format_ifname_full(ifindex, flag, buf);
return buf;
}
#define FORMAT_IFNAME_FULL(index, flag) _format_ifname_full(index, flag, (char[IF_NAMESIZE]){})
#define FORMAT_IFNAME(index) _format_ifname_full(index, 0, (char[IF_NAMESIZE]){})

View file

@ -5,38 +5,6 @@
#include "stdio-util.h" #include "stdio-util.h"
#include "strxcpyx.h" #include "strxcpyx.h"
assert_cc(STRLEN("%") + DECIMAL_STR_MAX(int) <= IF_NAMESIZE);
int format_ifname_full(int ifindex, FormatIfnameFlag flag, char buf[static IF_NAMESIZE]) {
if (ifindex <= 0)
return -EINVAL;
if (if_indextoname(ifindex, buf))
return 0;
if (!FLAGS_SET(flag, FORMAT_IFNAME_IFINDEX))
return -errno;
if (FLAGS_SET(flag, FORMAT_IFNAME_IFINDEX_WITH_PERCENT))
assert(snprintf_ok(buf, IF_NAMESIZE, "%%%d", ifindex));
else
assert(snprintf_ok(buf, IF_NAMESIZE, "%d", ifindex));
return 0;
}
int format_ifname_full_alloc(int ifindex, FormatIfnameFlag flag, char **ret) {
char buf[IF_NAMESIZE];
int r;
assert(ret);
r = format_ifname_full(ifindex, flag, buf);
if (r < 0)
return r;
return strdup_to(ret, buf);
}
char* format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag) { char* format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag) {
typedef struct { typedef struct {
const char *suffix; const char *suffix;

View file

@ -2,7 +2,6 @@
#pragma once #pragma once
#include <inttypes.h> #include <inttypes.h>
#include <net/if.h>
#include <stdbool.h> #include <stdbool.h>
#include "cgroup-util.h" #include "cgroup-util.h"
@ -66,29 +65,6 @@ assert_cc(sizeof(gid_t) == sizeof(uint32_t));
# error Unknown ino_t size # error Unknown ino_t size
#endif #endif
typedef enum {
FORMAT_IFNAME_IFINDEX = 1 << 0,
FORMAT_IFNAME_IFINDEX_WITH_PERCENT = (1 << 1) | FORMAT_IFNAME_IFINDEX,
} FormatIfnameFlag;
int format_ifname_full(int ifindex, FormatIfnameFlag flag, char buf[static IF_NAMESIZE]);
int format_ifname_full_alloc(int ifindex, FormatIfnameFlag flag, char **ret);
static inline int format_ifname(int ifindex, char buf[static IF_NAMESIZE]) {
return format_ifname_full(ifindex, 0, buf);
}
static inline int format_ifname_alloc(int ifindex, char **ret) {
return format_ifname_full_alloc(ifindex, 0, ret);
}
static inline char* _format_ifname_full(int ifindex, FormatIfnameFlag flag, char buf[static IF_NAMESIZE]) {
(void) format_ifname_full(ifindex, flag, buf);
return buf;
}
#define FORMAT_IFNAME_FULL(index, flag) _format_ifname_full(index, flag, (char[IF_NAMESIZE]){})
#define FORMAT_IFNAME(index) _format_ifname_full(index, 0, (char[IF_NAMESIZE]){})
typedef enum { typedef enum {
FORMAT_BYTES_USE_IEC = 1 << 0, FORMAT_BYTES_USE_IEC = 1 << 0,
FORMAT_BYTES_BELOW_POINT = 1 << 1, FORMAT_BYTES_BELOW_POINT = 1 << 1,

View file

@ -33,6 +33,7 @@ basic_sources = files(
'fd-util.c', 'fd-util.c',
'fileio.c', 'fileio.c',
'filesystems.c', 'filesystems.c',
'format-ifname.c',
'format-util.c', 'format-util.c',
'fs-util.c', 'fs-util.c',
'gcrypt-util.c', 'gcrypt-util.c',

View file

@ -21,7 +21,7 @@
#include "escape.h" #include "escape.h"
#include "fd-util.h" #include "fd-util.h"
#include "fileio.h" #include "fileio.h"
#include "format-util.h" #include "format-ifname.h"
#include "io-util.h" #include "io-util.h"
#include "log.h" #include "log.h"
#include "memory-util.h" #include "memory-util.h"

View file

@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "env-util.h" #include "env-util.h"
#include "format-util.h" #include "format-ifname.h"
#include "network-common.h" #include "network-common.h"
#include "socket-util.h" #include "socket-util.h"
#include "unaligned.h" #include "unaligned.h"

View file

@ -32,6 +32,7 @@
#include "edit-util.h" #include "edit-util.h"
#include "env-util.h" #include "env-util.h"
#include "fd-util.h" #include "fd-util.h"
#include "format-ifname.h"
#include "format-table.h" #include "format-table.h"
#include "hostname-util.h" #include "hostname-util.h"
#include "import-util.h" #include "import-util.h"

View file

@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "format-util.h" #include "format-ifname.h"
#include "in-addr-util.h" #include "in-addr-util.h"
#include "local-addresses.h" #include "local-addresses.h"
#include "networkctl-dump-util.h" #include "networkctl-dump-util.h"

View file

@ -5,7 +5,7 @@
#include "bus-error.h" #include "bus-error.h"
#include "bus-locator.h" #include "bus-locator.h"
#include "fd-util.h" #include "fd-util.h"
#include "format-util.h" #include "format-ifname.h"
#include "netlink-util.h" #include "netlink-util.h"
#include "networkctl.h" #include "networkctl.h"
#include "networkctl-misc.h" #include "networkctl-misc.h"

View file

@ -24,7 +24,7 @@
#include "event-util.h" #include "event-util.h"
#include "fd-util.h" #include "fd-util.h"
#include "fileio.h" #include "fileio.h"
#include "format-util.h" #include "format-ifname.h"
#include "fs-util.h" #include "fs-util.h"
#include "glyph-util.h" #include "glyph-util.h"
#include "logarithm.h" #include "logarithm.h"

View file

@ -9,6 +9,7 @@
#include "af-list.h" #include "af-list.h"
#include "cgroup-util.h" #include "cgroup-util.h"
#include "fd-util.h" #include "fd-util.h"
#include "format-util.h"
#include "missing_network.h" #include "missing_network.h"
#include "networkd-link.h" #include "networkd-link.h"
#include "networkd-lldp-tx.h" #include "networkd-lldp-tx.h"
@ -72,14 +73,14 @@ static int sysctl_event_handler(void *ctx, void *data, size_t data_sz) {
if (!strneq(value, we->newvalue, sizeof(we->newvalue))) if (!strneq(value, we->newvalue, sizeof(we->newvalue)))
log_struct(LOG_WARNING, log_struct(LOG_WARNING,
"MESSAGE_ID=" SD_MESSAGE_SYSCTL_CHANGED_STR, "MESSAGE_ID=" SD_MESSAGE_SYSCTL_CHANGED_STR,
"OBJECT_PID=%d", we->pid, "OBJECT_PID=" PID_FMT, we->pid,
"OBJECT_COMM=%s", we->comm, "OBJECT_COMM=%s", we->comm,
"SYSCTL=/proc/sys/%s", we->path, "SYSCTL=%s", path,
"OLDVALUE=%s", we->current, "OLDVALUE=%s", we->current,
"NEWVALUE=%s", we->newvalue, "NEWVALUE=%s", we->newvalue,
"OURVALUE=%s", value, "OURVALUE=%s", value,
LOG_MESSAGE("Foreign process '%s[%d]' changed sysctl '/proc/sys/%s' from '%s' to '%s', conflicting with our setting to '%s'", LOG_MESSAGE("Foreign process '%s[" PID_FMT "]' changed sysctl '%s' from '%s' to '%s', conflicting with our setting to '%s'.",
we->comm, we->pid, we->path, we->current, we->newvalue, value)); we->comm, we->pid, path, we->current, we->newvalue, value));
return 0; return 0;
} }

View file

@ -3,7 +3,7 @@
#include "sd-network.h" #include "sd-network.h"
#include "alloc-util.h" #include "alloc-util.h"
#include "format-util.h" #include "format-ifname.h"
#include "hashmap.h" #include "hashmap.h"
#include "link.h" #include "link.h"
#include "manager.h" #include "manager.h"

View file

@ -3,6 +3,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <linux/nsfs.h> #include <linux/nsfs.h>
#include <linux/veth.h> #include <linux/veth.h>
#include <net/if.h>
#include <sys/eventfd.h> #include <sys/eventfd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>

View file

@ -20,8 +20,8 @@
#include "dns-domain.h" #include "dns-domain.h"
#include "errno-list.h" #include "errno-list.h"
#include "escape.h" #include "escape.h"
#include "format-ifname.h"
#include "format-table.h" #include "format-table.h"
#include "format-util.h"
#include "gcrypt-util.h" #include "gcrypt-util.h"
#include "hostname-util.h" #include "hostname-util.h"
#include "json-util.h" #include "json-util.h"

View file

@ -5,7 +5,7 @@
#include "af-list.h" #include "af-list.h"
#include "alloc-util.h" #include "alloc-util.h"
#include "dns-domain.h" #include "dns-domain.h"
#include "format-util.h" #include "format-ifname.h"
#include "resolved-dns-answer.h" #include "resolved-dns-answer.h"
#include "resolved-dns-cache.h" #include "resolved-dns-cache.h"
#include "resolved-dns-packet.h" #include "resolved-dns-packet.h"

View file

@ -10,6 +10,7 @@
#include "devnum-util.h" #include "devnum-util.h"
#include "fd-util.h" #include "fd-util.h"
#include "fileio.h" #include "fileio.h"
#include "format-ifname.h"
#include "format-table.h" #include "format-table.h"
#include "format-util.h" #include "format-util.h"
#include "fs-util.h" #include "fs-util.h"

View file

@ -9,7 +9,7 @@
#include "dlfcn-util.h" #include "dlfcn-util.h"
#include "env-util.h" #include "env-util.h"
#include "errno-list.h" #include "errno-list.h"
#include "format-util.h" #include "format-ifname.h"
#include "hexdecoct.h" #include "hexdecoct.h"
#include "hostname-util.h" #include "hostname-util.h"
#include "in-addr-util.h" #include "in-addr-util.h"