1
0
mirror of https://github.com/systemd/systemd synced 2026-03-29 11:14:50 +02:00

Compare commits

..

No commits in common. "41a978fdb16fa39411dbc3411d267797af1e453a" and "5b81fa7ae18c746dc02abf9e82ec9bd23e683f2e" have entirely different histories.

53 changed files with 224 additions and 448 deletions

View File

@ -707,30 +707,8 @@ else
conf.set('DEFAULT_HIERARCHY', 'CGROUP_UNIFIED_ALL')
endif
extra_net_naming_schemes = []
extra_net_naming_map = []
foreach scheme: get_option('extra-net-naming-schemes').split(',')
if scheme != ''
name = scheme.split('=')[0]
value = scheme.split('=')[1]
NAME = name.underscorify().to_upper()
VALUE = []
foreach field: value.split('+')
VALUE += 'NAMING_' + field.underscorify().to_upper()
endforeach
extra_net_naming_schemes += 'NAMING_@0@ = @1@,'.format(NAME, '|'.join(VALUE))
extra_net_naming_map += '{ "@0@", NAMING_@1@ },'.format(name, NAME)
endif
endforeach
conf.set('EXTRA_NET_NAMING_SCHEMES', ' '.join(extra_net_naming_schemes))
conf.set('EXTRA_NET_NAMING_MAP', ' '.join(extra_net_naming_map))
default_net_naming_scheme = get_option('default-net-naming-scheme')
conf.set_quoted('DEFAULT_NET_NAMING_SCHEME', default_net_naming_scheme)
if default_net_naming_scheme != 'latest'
conf.set('_DEFAULT_NET_NAMING_SCHEME_TEST',
'NAMING_' + default_net_naming_scheme.underscorify().to_upper())
endif
time_epoch = get_option('time-epoch')
if time_epoch == -1

View File

@ -200,9 +200,8 @@ option('fallback-hostname', type : 'string', value : 'localhost',
option('default-hierarchy', type : 'combo',
choices : ['legacy', 'hybrid', 'unified'], value : 'unified',
description : 'default cgroup hierarchy')
option('extra-net-naming-schemes', type : 'string',
description : 'comma-separated list of extra net.naming-scheme= definitions')
option('default-net-naming-scheme', type : 'string', value : 'latest',
option('default-net-naming-scheme', type : 'combo',
choices : ['latest', 'v238', 'v239', 'v240', 'v241', 'v243', 'v245', 'v247', 'v249'],
description : 'default net.naming-scheme= value')
option('status-unit-format-default', type : 'combo',
choices : ['description', 'name', 'combined'],

View File

@ -148,30 +148,6 @@ int write_string_stream_ts(
return -EBADF;
}
if (flags & WRITE_STRING_FILE_SUPPRESS_REDUNDANT_VIRTUAL) {
_cleanup_free_ char *t = NULL;
/* If value to be written is same as that of the existing value, then suppress the write. */
if (fd < 0) {
fd = fileno(f);
if (fd < 0)
return -EBADF;
}
/* Read an additional byte to detect cases where the prefix matches but the rest
* doesn't. Also, 0 returned by read_virtual_file_fd() means the read was truncated and
* it won't be equal to the new value. */
if (read_virtual_file_fd(fd, strlen(line)+1, &t, NULL) > 0 &&
streq_skip_trailing_chars(line, t, NEWLINE)) {
log_debug("No change in value '%s', supressing write", line);
return 0;
}
if (lseek(fd, 0, SEEK_SET) < 0)
return -errno;
}
needs_nl = !(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n");
if (needs_nl && (flags & WRITE_STRING_FILE_DISABLE_BUFFER)) {
@ -287,11 +263,10 @@ int write_string_file_ts(
assert(!ts);
/* We manually build our own version of fopen(..., "we") that works without O_CREAT and with O_NOFOLLOW if needed. */
fd = open(fn, O_CLOEXEC|O_NOCTTY |
fd = open(fn, O_WRONLY|O_CLOEXEC|O_NOCTTY |
(FLAGS_SET(flags, WRITE_STRING_FILE_NOFOLLOW) ? O_NOFOLLOW : 0) |
(FLAGS_SET(flags, WRITE_STRING_FILE_CREATE) ? O_CREAT : 0) |
(FLAGS_SET(flags, WRITE_STRING_FILE_TRUNCATE) ? O_TRUNC : 0) |
(FLAGS_SET(flags, WRITE_STRING_FILE_SUPPRESS_REDUNDANT_VIRTUAL) ? O_RDWR : O_WRONLY),
(FLAGS_SET(flags, WRITE_STRING_FILE_TRUNCATE) ? O_TRUNC : 0),
(FLAGS_SET(flags, WRITE_STRING_FILE_MODE_0600) ? 0600 : 0666));
if (fd < 0) {
r = -errno;
@ -400,8 +375,9 @@ int verify_file(const char *fn, const char *blob, bool accept_extra_nl) {
return 1;
}
int read_virtual_file_fd(int fd, size_t max_size, char **ret_contents, size_t *ret_size) {
int read_virtual_file(const char *filename, size_t max_size, char **ret_contents, size_t *ret_size) {
_cleanup_free_ char *buf = NULL;
_cleanup_close_ int fd = -1;
size_t n, size;
int n_retries;
bool truncated = false;
@ -419,7 +395,10 @@ int read_virtual_file_fd(int fd, size_t max_size, char **ret_contents, size_t *r
* contents* may be returned. (Though the read is still done using one syscall.) Returns 0 on
* partial success, 1 if untruncated contents were read. */
assert(fd >= 0);
fd = open(filename, O_RDONLY|O_NOCTTY|O_CLOEXEC);
if (fd < 0)
return -errno;
assert(max_size <= READ_VIRTUAL_BYTES_MAX || max_size == SIZE_MAX);
/* Limit the number of attempts to read the number of bytes returned by fstat(). */
@ -455,8 +434,8 @@ int read_virtual_file_fd(int fd, size_t max_size, char **ret_contents, size_t *r
n_retries--;
} else if (n_retries > 1) {
/* Files in /proc are generally smaller than the page size so let's start with
* a page size buffer from malloc and only use the max buffer on the final try. */
/* Files in /proc are generally smaller than the page size so let's start with a page size
* buffer from malloc and only use the max buffer on the final try. */
size = MIN3(page_size() - 1, READ_VIRTUAL_BYTES_MAX, max_size);
n_retries = 1;
} else {
@ -545,18 +524,6 @@ int read_virtual_file_fd(int fd, size_t max_size, char **ret_contents, size_t *r
return !truncated;
}
int read_virtual_file(const char *filename, size_t max_size, char **ret_contents, size_t *ret_size) {
_cleanup_close_ int fd = -1;
assert(filename);
fd = open(filename, O_RDONLY | O_NOCTTY | O_CLOEXEC);
if (fd < 0)
return -errno;
return read_virtual_file_fd(fd, max_size, ret_contents, ret_size);
}
int read_full_stream_full(
FILE *f,
const char *filename,

View File

@ -15,18 +15,17 @@
#define LONG_LINE_MAX (1U*1024U*1024U)
typedef enum {
WRITE_STRING_FILE_CREATE = 1 << 0,
WRITE_STRING_FILE_TRUNCATE = 1 << 1,
WRITE_STRING_FILE_ATOMIC = 1 << 2,
WRITE_STRING_FILE_AVOID_NEWLINE = 1 << 3,
WRITE_STRING_FILE_VERIFY_ON_FAILURE = 1 << 4,
WRITE_STRING_FILE_VERIFY_IGNORE_NEWLINE = 1 << 5,
WRITE_STRING_FILE_SYNC = 1 << 6,
WRITE_STRING_FILE_DISABLE_BUFFER = 1 << 7,
WRITE_STRING_FILE_NOFOLLOW = 1 << 8,
WRITE_STRING_FILE_MKDIR_0755 = 1 << 9,
WRITE_STRING_FILE_MODE_0600 = 1 << 10,
WRITE_STRING_FILE_SUPPRESS_REDUNDANT_VIRTUAL = 1 << 11,
WRITE_STRING_FILE_CREATE = 1 << 0,
WRITE_STRING_FILE_TRUNCATE = 1 << 1,
WRITE_STRING_FILE_ATOMIC = 1 << 2,
WRITE_STRING_FILE_AVOID_NEWLINE = 1 << 3,
WRITE_STRING_FILE_VERIFY_ON_FAILURE = 1 << 4,
WRITE_STRING_FILE_VERIFY_IGNORE_NEWLINE = 1 << 5,
WRITE_STRING_FILE_SYNC = 1 << 6,
WRITE_STRING_FILE_DISABLE_BUFFER = 1 << 7,
WRITE_STRING_FILE_NOFOLLOW = 1 << 8,
WRITE_STRING_FILE_MKDIR_0755 = 1 << 9,
WRITE_STRING_FILE_MODE_0600 = 1 << 10,
/* And before you wonder, why write_string_file_atomic_label_ts() is a separate function instead of just one
more flag here: it's about linking: we don't want to pull -lselinux into all users of write_string_file()
@ -68,7 +67,6 @@ static inline int read_full_file(const char *filename, char **ret_contents, size
return read_full_file_full(AT_FDCWD, filename, UINT64_MAX, SIZE_MAX, 0, NULL, ret_contents, ret_size);
}
int read_virtual_file_fd(int fd, size_t max_size, char **ret_contents, size_t *ret_size);
int read_virtual_file(const char *filename, size_t max_size, char **ret_contents, size_t *ret_size);
static inline int read_full_virtual_file(const char *filename, char **ret_contents, size_t *ret_size) {
return read_virtual_file(filename, SIZE_MAX, ret_contents, ret_size);

View File

@ -3,43 +3,23 @@
#include "format-util.h"
#include "memory-util.h"
#include "stdio-util.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;
assert_cc(DECIMAL_STR_MAX(int) + 1 <= IF_NAMESIZE + 1);
char *format_ifname_full(int ifindex, char buf[static IF_NAMESIZE + 1], FormatIfnameFlag flag) {
/* Buffer is always cleared */
memzero(buf, IF_NAMESIZE + 1);
if (if_indextoname(ifindex, buf))
return 0;
return buf;
if (!FLAGS_SET(flag, FORMAT_IFNAME_IFINDEX))
return -errno;
return NULL;
if (FLAGS_SET(flag, FORMAT_IFNAME_IFINDEX_WITH_PERCENT))
assert(snprintf_ok(buf, IF_NAMESIZE, "%%%d", ifindex));
assert(snprintf_ok(buf, IF_NAMESIZE + 1, "%%%d", ifindex));
else
assert(snprintf_ok(buf, IF_NAMESIZE, "%d", ifindex));
assert(snprintf_ok(buf, IF_NAMESIZE + 1, "%d", ifindex));
return 0;
}
int format_ifname_full_alloc(int ifindex, FormatIfnameFlag flag, char **ret) {
char buf[IF_NAMESIZE], *copy;
int r;
assert(ret);
r = format_ifname_full(ifindex, flag, buf);
if (r < 0)
return r;
copy = strdup(buf);
if (!copy)
return -ENOMEM;
*ret = copy;
return 0;
return buf;
}
char *format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag) {

View File

@ -61,23 +61,10 @@ typedef enum {
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);
char *format_ifname_full(int ifindex, char buf[static IF_NAMESIZE + 1], FormatIfnameFlag flag);
static inline char *format_ifname(int ifindex, char buf[static IF_NAMESIZE + 1]) {
return format_ifname_full(ifindex, buf, 0);
}
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 {
FORMAT_BYTES_USE_IEC = 1 << 0,

View File

@ -455,23 +455,23 @@ int sockaddr_pretty(
if (r < 0)
return -ENOMEM;
} else {
char a[INET6_ADDRSTRLEN];
char a[INET6_ADDRSTRLEN], ifname[IF_NAMESIZE + 1];
inet_ntop(AF_INET6, &sa->in6.sin6_addr, a, sizeof(a));
if (sa->in6.sin6_scope_id != 0)
format_ifname_full(sa->in6.sin6_scope_id, ifname, FORMAT_IFNAME_IFINDEX);
if (include_port) {
if (asprintf(&p,
r = asprintf(&p,
"[%s]:%u%s%s",
a,
be16toh(sa->in6.sin6_port),
sa->in6.sin6_scope_id != 0 ? "%" : "",
FORMAT_IFNAME_FULL(sa->in6.sin6_scope_id, FORMAT_IFNAME_IFINDEX)) < 0)
sa->in6.sin6_scope_id != 0 ? ifname : "");
if (r < 0)
return -ENOMEM;
} else {
if (sa->in6.sin6_scope_id != 0)
p = strjoin(a, "%", FORMAT_IFNAME_FULL(sa->in6.sin6_scope_id, FORMAT_IFNAME_IFINDEX));
else
p = strdup(a);
p = sa->in6.sin6_scope_id != 0 ? strjoin(a, "%", ifname) : strdup(a);
if (!p)
return -ENOMEM;
}
@ -1233,7 +1233,7 @@ int socket_bind_to_ifname(int fd, const char *ifname) {
}
int socket_bind_to_ifindex(int fd, int ifindex) {
char ifname[IF_NAMESIZE];
char ifname[IF_NAMESIZE + 1];
int r;
assert(fd >= 0);
@ -1251,9 +1251,8 @@ int socket_bind_to_ifindex(int fd, int ifindex) {
return r;
/* Fall back to SO_BINDTODEVICE on kernels < 5.0 which didn't have SO_BINDTOIFINDEX */
r = format_ifname(ifindex, ifname);
if (r < 0)
return r;
if (!format_ifname(ifindex, ifname))
return -errno;
return socket_bind_to_ifname(fd, ifname);
}

View File

@ -1146,19 +1146,3 @@ int string_contains_word_strv(const char *string, const char *separators, char *
*ret_word = found;
return !!found;
}
bool streq_skip_trailing_chars(const char *s1, const char *s2, const char *ok) {
if (!s1 && !s2)
return true;
if (!s1 || !s2)
return false;
if (!ok)
ok = WHITESPACE;
for (; *s1 && *s2; s1++, s2++)
if (*s1 != *s2)
break;
return in_charset(s1, ok) && in_charset(s2, ok);
}

View File

@ -226,5 +226,3 @@ int string_contains_word_strv(const char *string, const char *separators, char *
static inline int string_contains_word(const char *string, const char *separators, const char *word) {
return string_contains_word_strv(string, separators, STRV_MAKE(word), NULL);
}
bool streq_skip_trailing_chars(const char *s1, const char *s2, const char *ok);

View File

@ -58,7 +58,7 @@ int sysctl_write(const char *property, const char *value) {
log_debug("Setting '%s' to '%s'", p, value);
return write_string_file(p, value, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER | WRITE_STRING_FILE_SUPPRESS_REDUNDANT_VIRTUAL);
return write_string_file(p, value, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
}
int sysctl_writef(const char *property, const char *format, ...) {

View File

@ -52,7 +52,7 @@ static void scope_done(Unit *u) {
s->timer_event_source = sd_event_source_disable_unref(s->timer_event_source);
}
static usec_t scope_running_timeout(Scope *s) {
static int scope_running_timeout(Scope *s) {
usec_t delta = 0;
assert(s);

View File

@ -515,7 +515,7 @@ static void service_remove_fd_store(Service *s, const char *name) {
}
}
static usec_t service_running_timeout(Service *s) {
static int service_running_timeout(Service *s) {
usec_t delta = 0;
assert(s);

View File

@ -12,7 +12,7 @@
#include "sd-dhcp-client.h"
#include "dhcp-protocol.h"
#include "network-common.h"
#include "log-link.h"
#include "socket-util.h"
typedef struct sd_dhcp_option {
@ -75,10 +75,10 @@ void dhcp_client_set_test_mode(sd_dhcp_client *client, bool test_mode);
#define log_dhcp_client_errno(client, error, fmt, ...) \
log_interface_prefix_full_errno( \
"DHCPv4 client: ", \
sd_dhcp_client, client, \
sd_dhcp_client_get_ifname(client), \
error, fmt, ##__VA_ARGS__)
#define log_dhcp_client(client, fmt, ...) \
log_interface_prefix_full_errno_zerook( \
"DHCPv4 client: ", \
sd_dhcp_client, client, \
sd_dhcp_client_get_ifname(client), \
0, fmt, ##__VA_ARGS__)

View File

@ -9,8 +9,8 @@
#include "sd-event.h"
#include "dhcp-internal.h"
#include "network-common.h"
#include "ordered-set.h"
#include "log-link.h"
#include "time-util.h"
typedef enum DHCPRawOption {
@ -112,10 +112,10 @@ int client_id_compare_func(const DHCPClientId *a, const DHCPClientId *b);
#define log_dhcp_server_errno(server, error, fmt, ...) \
log_interface_prefix_full_errno( \
"DHCPv4 server: ", \
sd_dhcp_server, server, \
sd_dhcp_server_get_ifname(server), \
error, fmt, ##__VA_ARGS__)
#define log_dhcp_server(server, fmt, ...) \
log_interface_prefix_full_errno_zerook( \
"DHCPv4 server: ", \
sd_dhcp_server, server, \
sd_dhcp_server_get_ifname(server), \
0, fmt, ##__VA_ARGS__)

View File

@ -13,8 +13,8 @@
#include "hashmap.h"
#include "list.h"
#include "log-link.h"
#include "macro.h"
#include "network-common.h"
#include "sparse-endian.h"
typedef struct sd_dhcp6_option {
@ -125,10 +125,10 @@ void dhcp6_client_set_test_mode(sd_dhcp6_client *client, bool test_mode);
#define log_dhcp6_client_errno(client, error, fmt, ...) \
log_interface_prefix_full_errno( \
"DHCPv6 client: ", \
sd_dhcp6_client, client, \
sd_dhcp6_client_get_ifname(client), \
error, fmt, ##__VA_ARGS__)
#define log_dhcp6_client(client, fmt, ...) \
log_interface_prefix_full_errno_zerook( \
"DHCPv6 client: ", \
sd_dhcp6_client, client, \
sd_dhcp6_client_get_ifname(client), \
0, fmt, ##__VA_ARGS__)

View File

@ -5,7 +5,7 @@
#include "sd-lldp-rx.h"
#include "hashmap.h"
#include "network-common.h"
#include "log-link.h"
#include "prioq.h"
struct sd_lldp_rx {
@ -39,10 +39,10 @@ sd_lldp_rx_event_t lldp_rx_event_from_string(const char *s) _pure_;
#define log_lldp_rx_errno(lldp_rx, error, fmt, ...) \
log_interface_prefix_full_errno( \
"LLDP Rx: ", \
sd_lldp_rx, lldp_rx, \
sd_lldp_rx_get_ifname(lldp_rx), \
error, fmt, ##__VA_ARGS__)
#define log_lldp_rx(lldp_rx, fmt, ...) \
log_interface_prefix_full_errno_zerook( \
"LLDP Rx: ", \
sd_lldp_rx, lldp_rx, \
sd_lldp_rx_get_ifname(lldp_rx), \
0, fmt, ##__VA_ARGS__)

View File

@ -7,7 +7,7 @@
#include "sd-ndisc.h"
#include "network-common.h"
#include "log-link.h"
#include "time-util.h"
#define NDISC_ROUTER_SOLICITATION_INTERVAL (4U * USEC_PER_SEC)
@ -44,10 +44,10 @@ sd_ndisc_event_t ndisc_event_from_string(const char *s) _pure_;
#define log_ndisc_errno(ndisc, error, fmt, ...) \
log_interface_prefix_full_errno( \
"NDISC: ", \
sd_ndisc, ndisc, \
sd_ndisc_get_ifname(ndisc), \
error, fmt, ##__VA_ARGS__)
#define log_ndisc(ndisc, fmt, ...) \
log_interface_prefix_full_errno_zerook( \
"NDISC: ", \
sd_ndisc, ndisc, \
sd_ndisc_get_ifname(ndisc), \
0, fmt, ##__VA_ARGS__)

View File

@ -2,14 +2,23 @@
#include "format-util.h"
#include "network-common.h"
#include "string-util.h"
const char *get_ifname(int ifindex, char **ifname) {
char buf[IF_NAMESIZE + 1];
int get_ifname(int ifindex, char **ifname) {
assert(ifname);
/* This sets ifname only when it is not set yet. */
if (*ifname)
return 0;
return *ifname;
return format_ifname_alloc(ifindex, ifname);
if (ifindex <= 0)
return NULL;
if (!format_ifname(ifindex, buf))
return NULL;
return *ifname = strdup(buf);
}

View File

@ -1,28 +1,4 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "log-link.h"
#define log_interface_prefix_full_errno_zerook(prefix, type, val, error, fmt, ...) \
({ \
int _e = (error); \
if (DEBUG_LOGGING) { \
const char *_n = NULL; \
\
(void) type##_get_ifname(val, &_n); \
log_interface_full_errno_zerook( \
_n, LOG_DEBUG, _e, prefix fmt, \
##__VA_ARGS__); \
} \
-ERRNO_VALUE(_e); \
})
#define log_interface_prefix_full_errno(prefix, type, val, error, fmt, ...) \
({ \
int _error = (error); \
ASSERT_NON_ZERO(_error); \
log_interface_prefix_full_errno_zerook( \
prefix, type, val, _error, fmt, ##__VA_ARGS__); \
})
int get_ifname(int ifindex, char **ifname);
const char *get_ifname(int ifindex, char **ifname);

View File

@ -7,8 +7,8 @@
#include "sd-radv.h"
#include "log-link.h"
#include "list.h"
#include "network-common.h"
#include "sparse-endian.h"
assert_cc(SD_RADV_DEFAULT_MIN_TIMEOUT_USEC <= SD_RADV_DEFAULT_MAX_TIMEOUT_USEC);
@ -128,10 +128,10 @@ struct sd_radv_route_prefix {
#define log_radv_errno(radv, error, fmt, ...) \
log_interface_prefix_full_errno( \
"RADV: ", \
sd_radv, radv, \
sd_radv_get_ifname(radv), \
error, fmt, ##__VA_ARGS__)
#define log_radv(radv, fmt, ...) \
log_interface_prefix_full_errno_zerook( \
"RADV: ", \
sd_radv, radv, \
sd_radv_get_ifname(radv), \
0, fmt, ##__VA_ARGS__)

View File

@ -297,19 +297,11 @@ int sd_dhcp_client_set_ifname(sd_dhcp_client *client, const char *ifname) {
return free_and_strdup(&client->ifname, ifname);
}
int sd_dhcp_client_get_ifname(sd_dhcp_client *client, const char **ret) {
int r;
const char *sd_dhcp_client_get_ifname(sd_dhcp_client *client) {
if (!client)
return NULL;
assert_return(client, -EINVAL);
r = get_ifname(client->ifindex, &client->ifname);
if (r < 0)
return r;
if (ret)
*ret = client->ifname;
return 0;
return get_ifname(client->ifindex, &client->ifname);
}
int sd_dhcp_client_set_mac(

View File

@ -230,19 +230,11 @@ int sd_dhcp_server_set_ifname(sd_dhcp_server *server, const char *ifname) {
return free_and_strdup(&server->ifname, ifname);
}
int sd_dhcp_server_get_ifname(sd_dhcp_server *server, const char **ret) {
int r;
const char *sd_dhcp_server_get_ifname(sd_dhcp_server *server) {
if (!server)
return NULL;
assert_return(server, -EINVAL);
r = get_ifname(server->ifindex, &server->ifname);
if (r < 0)
return r;
if (ret)
*ret = server->ifname;
return 0;
return get_ifname(server->ifindex, &server->ifname);
}
int sd_dhcp_server_attach_event(sd_dhcp_server *server, sd_event *event, int64_t priority) {

View File

@ -179,19 +179,11 @@ int sd_dhcp6_client_set_ifname(sd_dhcp6_client *client, const char *ifname) {
return free_and_strdup(&client->ifname, ifname);
}
int sd_dhcp6_client_get_ifname(sd_dhcp6_client *client, const char **ret) {
int r;
const char *sd_dhcp6_client_get_ifname(sd_dhcp6_client *client) {
if (!client)
return NULL;
assert_return(client, -EINVAL);
r = get_ifname(client->ifindex, &client->ifname);
if (r < 0)
return r;
if (ret)
*ret = client->ifname;
return 0;
return get_ifname(client->ifindex, &client->ifname);
}
int sd_dhcp6_client_set_local_address(

View File

@ -17,6 +17,7 @@
#include "event-util.h"
#include "fd-util.h"
#include "in-addr-util.h"
#include "log-link.h"
#include "memory-util.h"
#include "network-common.h"
#include "random-util.h"
@ -80,12 +81,12 @@ struct sd_ipv4acd {
#define log_ipv4acd_errno(acd, error, fmt, ...) \
log_interface_prefix_full_errno( \
"IPv4ACD: ", \
sd_ipv4acd, acd, \
sd_ipv4acd_get_ifname(acd), \
error, fmt, ##__VA_ARGS__)
#define log_ipv4acd(acd, fmt, ...) \
log_interface_prefix_full_errno_zerook( \
"IPv4ACD: ", \
sd_ipv4acd, acd, \
sd_ipv4acd_get_ifname(acd), \
0, fmt, ##__VA_ARGS__)
static const char * const ipv4acd_state_table[_IPV4ACD_STATE_MAX] = {
@ -444,19 +445,11 @@ int sd_ipv4acd_set_ifname(sd_ipv4acd *acd, const char *ifname) {
return free_and_strdup(&acd->ifname, ifname);
}
int sd_ipv4acd_get_ifname(sd_ipv4acd *acd, const char **ret) {
int r;
const char *sd_ipv4acd_get_ifname(sd_ipv4acd *acd) {
if (!acd)
return NULL;
assert_return(acd, -EINVAL);
r = get_ifname(acd->ifindex, &acd->ifname);
if (r < 0)
return r;
if (ret)
*ret = acd->ifname;
return 0;
return get_ifname(acd->ifindex, &acd->ifname);
}
int sd_ipv4acd_set_mac(sd_ipv4acd *acd, const struct ether_addr *addr) {

View File

@ -15,7 +15,7 @@
#include "alloc-util.h"
#include "ether-addr-util.h"
#include "in-addr-util.h"
#include "network-common.h"
#include "log-link.h"
#include "random-util.h"
#include "siphash24.h"
#include "sparse-endian.h"
@ -55,12 +55,12 @@ struct sd_ipv4ll {
#define log_ipv4ll_errno(ll, error, fmt, ...) \
log_interface_prefix_full_errno( \
"IPv4LL: ", \
sd_ipv4ll, ll, \
sd_ipv4ll_get_ifname(ll), \
error, fmt, ##__VA_ARGS__)
#define log_ipv4ll(ll, fmt, ...) \
log_interface_prefix_full_errno_zerook( \
"IPv4LL: ", \
sd_ipv4ll, ll, \
sd_ipv4ll_get_ifname(ll), \
0, fmt, ##__VA_ARGS__)
static void ipv4ll_on_acd(sd_ipv4acd *acd, int event, void *userdata);
@ -133,10 +133,11 @@ int sd_ipv4ll_set_ifname(sd_ipv4ll *ll, const char *ifname) {
return sd_ipv4acd_set_ifname(ll->acd, ifname);
}
int sd_ipv4ll_get_ifname(sd_ipv4ll *ll, const char **ret) {
assert_return(ll, -EINVAL);
const char *sd_ipv4ll_get_ifname(sd_ipv4ll *ll) {
if (!ll)
return NULL;
return sd_ipv4acd_get_ifname(ll->acd, ret);
return sd_ipv4acd_get_ifname(ll->acd);
}
int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr) {

View File

@ -359,19 +359,11 @@ int sd_lldp_rx_set_ifname(sd_lldp_rx *lldp_rx, const char *ifname) {
return free_and_strdup(&lldp_rx->ifname, ifname);
}
int sd_lldp_rx_get_ifname(sd_lldp_rx *lldp_rx, const char **ret) {
int r;
const char *sd_lldp_rx_get_ifname(sd_lldp_rx *lldp_rx) {
if (!lldp_rx)
return NULL;
assert_return(lldp_rx, -EINVAL);
r = get_ifname(lldp_rx->ifindex, &lldp_rx->ifname);
if (r < 0)
return r;
if (ret)
*ret = lldp_rx->ifname;
return 0;
return get_ifname(lldp_rx->ifindex, &lldp_rx->ifname);
}
static sd_lldp_rx *lldp_rx_free(sd_lldp_rx *lldp_rx) {

View File

@ -12,6 +12,7 @@
#include "ether-addr-util.h"
#include "fd-util.h"
#include "hostname-util.h"
#include "log-link.h"
#include "network-common.h"
#include "random-util.h"
#include "socket-util.h"
@ -69,12 +70,12 @@ struct sd_lldp_tx {
#define log_lldp_tx_errno(lldp_tx, error, fmt, ...) \
log_interface_prefix_full_errno( \
"LLDP Tx: ", \
sd_lldp_tx, lldp_tx, \
sd_lldp_tx_get_ifname(lldp_tx), \
error, fmt, ##__VA_ARGS__)
#define log_lldp_tx(lldp_tx, fmt, ...) \
log_interface_prefix_full_errno_zerook( \
"LLDP Tx: ", \
sd_lldp_tx, lldp_tx, \
sd_lldp_tx_get_ifname(lldp_tx), \
0, fmt, ##__VA_ARGS__)
static sd_lldp_tx *lldp_tx_free(sd_lldp_tx *lldp_tx) {
@ -130,19 +131,11 @@ int sd_lldp_tx_set_ifname(sd_lldp_tx *lldp_tx, const char *ifname) {
return free_and_strdup(&lldp_tx->ifname, ifname);
}
int sd_lldp_tx_get_ifname(sd_lldp_tx *lldp_tx, const char **ret) {
int r;
const char *sd_lldp_tx_get_ifname(sd_lldp_tx *lldp_tx) {
if (!lldp_tx)
return NULL;
assert_return(lldp_tx, -EINVAL);
r = get_ifname(lldp_tx->ifindex, &lldp_tx->ifname);
if (r < 0)
return r;
if (ret)
*ret = lldp_tx->ifname;
return 0;
return get_ifname(lldp_tx->ifindex, &lldp_tx->ifname);
}
int sd_lldp_tx_set_multicast_mode(sd_lldp_tx *lldp_tx, sd_lldp_multicast_mode_t mode) {
@ -229,7 +222,7 @@ static size_t lldp_tx_calculate_maximum_packet_size(sd_lldp_tx *lldp_tx, const c
/* Chassis ID */
2 + 1 + (SD_ID128_STRING_MAX - 1) +
/* Port ID */
2 + 1 + strlen_ptr(lldp_tx->ifname) +
2 + 1 + strlen_ptr(sd_lldp_tx_get_ifname(lldp_tx)) +
/* Port description */
2 + strlen_ptr(lldp_tx->port_description) +
/* System name */
@ -341,11 +334,6 @@ static int lldp_tx_create_packet(sd_lldp_tx *lldp_tx, size_t *ret_packet_size, u
assert(ret_packet_size);
assert(ret_packet);
/* If ifname is not set yet, set ifname from ifindex. */
r = sd_lldp_tx_get_ifname(lldp_tx, NULL);
if (r < 0)
return r;
r = sd_id128_get_machine(&machine_id);
if (r < 0)
return r;
@ -377,7 +365,7 @@ static int lldp_tx_create_packet(sd_lldp_tx *lldp_tx, size_t *ret_packet_size, u
r = packet_append_prefixed_string(packet, packet_size, &offset, SD_LLDP_TYPE_PORT_ID,
1, (const uint8_t[]) { SD_LLDP_PORT_SUBTYPE_INTERFACE_NAME },
lldp_tx->ifname);
sd_lldp_tx_get_ifname(lldp_tx));
if (r < 0)
return r;

View File

@ -74,19 +74,11 @@ int sd_ndisc_set_ifname(sd_ndisc *nd, const char *ifname) {
return free_and_strdup(&nd->ifname, ifname);
}
int sd_ndisc_get_ifname(sd_ndisc *nd, const char **ret) {
int r;
const char *sd_ndisc_get_ifname(sd_ndisc *nd) {
if (!nd)
return NULL;
assert_return(nd, -EINVAL);
r = get_ifname(nd->ifindex, &nd->ifname);
if (r < 0)
return r;
if (ret)
*ret = nd->ifname;
return 0;
return get_ifname(nd->ifindex, &nd->ifname);
}
_public_ int sd_ndisc_set_mac(sd_ndisc *nd, const struct ether_addr *mac_addr) {

View File

@ -438,19 +438,11 @@ int sd_radv_set_ifname(sd_radv *ra, const char *ifname) {
return free_and_strdup(&ra->ifname, ifname);
}
int sd_radv_get_ifname(sd_radv *ra, const char **ret) {
int r;
const char *sd_radv_get_ifname(sd_radv *ra) {
if (!ra)
return NULL;
assert_return(ra, -EINVAL);
r = get_ifname(ra->ifindex, &ra->ifname);
if (r < 0)
return r;
if (ret)
*ret = ra->ifname;
return 0;
return get_ifname(ra->ifindex, &ra->ifname);
}
_public_ int sd_radv_set_mac(sd_radv *ra, const struct ether_addr *mac_addr) {

View File

@ -284,12 +284,12 @@ _public_ int sd_device_new_from_ifname(sd_device **ret, const char *ifname) {
}
_public_ int sd_device_new_from_ifindex(sd_device **ret, int ifindex) {
char ifname[IF_NAMESIZE];
char ifname[IF_NAMESIZE + 1];
assert_return(ret, -EINVAL);
assert_return(ifindex > 0, -EINVAL);
if (format_ifname(ifindex, ifname) < 0)
if (!format_ifname(ifindex, ifname))
return -ENODEV;
return device_new_from_main_ifname(ret, ifname);

View File

@ -12,7 +12,7 @@
int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
_cleanup_strv_free_ char **alternative_names = NULL;
char old_name[IF_NAMESIZE] = {};
char old_name[IF_NAMESIZE + 1] = {};
int r;
assert(rtnl);
@ -33,9 +33,7 @@ int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name) {
return log_debug_errno(r, "Failed to remove '%s' from alternative names on network interface %i: %m",
name, ifindex);
r = format_ifname(ifindex, old_name);
if (r < 0)
return log_debug_errno(r, "Failed to get current name of network interface %i: %m", ifindex);
format_ifname(ifindex, old_name);
}
r = sd_rtnl_message_new_link(*rtnl, &message, RTM_SETLINK, ifindex);

View File

@ -557,9 +557,9 @@ static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) {
fputs("\t Iface:", stdout);
for (size_t c = 0; c < i->n_netif; c++) {
char name[IF_NAMESIZE];
char name[IF_NAMESIZE+1];
if (format_ifname(i->netif[c], name) >= 0) {
if (format_ifname(i->netif[c], name)) {
fputc(' ', stdout);
fputs(name, stdout);

View File

@ -1044,6 +1044,7 @@ static int dump_gateways(
for (int i = 0; i < n; i++) {
_cleanup_free_ char *gateway = NULL, *description = NULL;
char name[IF_NAMESIZE+1];
r = in_addr_to_string(local[i].family, &local[i].address, &gateway);
if (r < 0)
@ -1062,7 +1063,7 @@ static int dump_gateways(
r = strv_extendf(&buf, "%s%s%s",
gateway,
ifindex <= 0 ? " on " : "",
ifindex <= 0 ? FORMAT_IFNAME_FULL(local[i].ifindex, FORMAT_IFNAME_IFINDEX_WITH_PERCENT) : "");
ifindex <= 0 ? format_ifname_full(local[i].ifindex, name, FORMAT_IFNAME_IFINDEX_WITH_PERCENT) : "");
if (r < 0)
return log_oom();
}
@ -1093,6 +1094,7 @@ static int dump_addresses(
for (int i = 0; i < n; i++) {
_cleanup_free_ char *pretty = NULL;
char name[IF_NAMESIZE+1];
r = in_addr_to_string(local[i].family, &local[i].address, &pretty);
if (r < 0)
@ -1116,7 +1118,7 @@ static int dump_addresses(
r = strv_extendf(&buf, "%s%s%s",
pretty,
ifindex <= 0 ? " on " : "",
ifindex <= 0 ? FORMAT_IFNAME_FULL(local[i].ifindex, FORMAT_IFNAME_IFINDEX_WITH_PERCENT) : "");
ifindex <= 0 ? format_ifname_full(local[i].ifindex, name, FORMAT_IFNAME_IFINDEX_WITH_PERCENT) : "");
if (r < 0)
return log_oom();
}
@ -2680,9 +2682,12 @@ static int link_up_down(int argc, char *argv[], void *userdata) {
SET_FOREACH(p, indexes) {
index = PTR_TO_INT(p);
r = link_up_down_send_message(rtnl, argv[0], index);
if (r < 0)
if (r < 0) {
char ifname[IF_NAMESIZE + 1];
return log_error_errno(r, "Failed to bring %s interface %s: %m",
argv[0], FORMAT_IFNAME_FULL(index, FORMAT_IFNAME_IFINDEX));
argv[0], format_ifname_full(index, ifname, FORMAT_IFNAME_IFINDEX));
}
}
return r;
@ -2715,9 +2720,12 @@ static int link_delete(int argc, char *argv[], void *userdata) {
SET_FOREACH(p, indexes) {
index = PTR_TO_INT(p);
r = link_delete_send_message(rtnl, index);
if (r < 0)
if (r < 0) {
char ifname[IF_NAMESIZE + 1];
return log_error_errno(r, "Failed to delete interface %s: %m",
FORMAT_IFNAME_FULL(index, FORMAT_IFNAME_IFINDEX));
format_ifname_full(index, ifname, FORMAT_IFNAME_IFINDEX));
}
}
return r;
@ -2836,9 +2844,12 @@ static int verb_reconfigure(int argc, char *argv[], void *userdata) {
SET_FOREACH(p, indexes) {
index = PTR_TO_INT(p);
r = bus_call_method(bus, bus_network_mgr, "ReconfigureLink", &error, NULL, "i", index);
if (r < 0)
if (r < 0) {
char ifname[IF_NAMESIZE + 1];
return log_error_errno(r, "Failed to reconfigure network interface %s: %m",
FORMAT_IFNAME_FULL(index, FORMAT_IFNAME_IFINDEX));
format_ifname_full(index, ifname, FORMAT_IFNAME_IFINDEX));
}
}
return 0;

View File

@ -2212,7 +2212,7 @@ static int link_update_alternative_names(Link *link, sd_netlink_message *message
}
static int link_update_name(Link *link, sd_netlink_message *message) {
char ifname_from_index[IF_NAMESIZE];
char ifname_from_index[IF_NAMESIZE + 1];
const char *ifname;
int r;
@ -2229,9 +2229,8 @@ static int link_update_name(Link *link, sd_netlink_message *message) {
if (streq(ifname, link->ifname))
return 0;
r = format_ifname(link->ifindex, ifname_from_index);
if (r < 0)
return log_link_debug_errno(link, r, "Could not get interface name for index %i.", link->ifindex);
if (!format_ifname(link->ifindex, ifname_from_index))
return log_link_debug_errno(link, SYNTHETIC_ERRNO(ENXIO), "Could not get interface name for index %i.", link->ifindex);
if (!streq(ifname, ifname_from_index)) {
log_link_debug(link, "New interface name '%s' received from the kernel does not correspond "

View File

@ -187,19 +187,17 @@ static void print_source(uint64_t flags, usec_t rtt) {
}
static void print_ifindex_comment(int printed_so_far, int ifindex) {
char ifname[IF_NAMESIZE];
int r;
char ifname[IF_NAMESIZE + 1];
if (ifindex <= 0)
return;
r = format_ifname(ifindex, ifname);
if (r < 0)
return (void) log_warning_errno(r, "Failed to resolve interface name for index %i, ignoring: %m", ifindex);
printf("%*s%s-- link: %s%s",
60 > printed_so_far ? 60 - printed_so_far : 0, " ", /* Align comment to the 60th column */
ansi_grey(), ifname, ansi_normal());
if (!format_ifname(ifindex, ifname))
log_warning_errno(errno, "Failed to resolve interface name for index %i, ignoring: %m", ifindex);
else
printf("%*s%s-- link: %s%s",
60 > printed_so_far ? 60 - printed_so_far : 0, " ", /* Align comment to the 60th column */
ansi_grey(), ifname, ansi_normal());
}
static int resolve_host(sd_bus *bus, const char *name) {
@ -1557,16 +1555,15 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode
_cleanup_(link_info_clear) LinkInfo link_info = {};
_cleanup_(table_unrefp) Table *table = NULL;
_cleanup_free_ char *p = NULL;
char ifi[DECIMAL_STR_MAX(int)], ifname[IF_NAMESIZE];
char ifi[DECIMAL_STR_MAX(int)], ifname[IF_NAMESIZE + 1] = "";
int r;
assert(bus);
assert(ifindex > 0);
if (!name) {
r = format_ifname(ifindex, ifname);
if (r < 0)
return log_error_errno(r, "Failed to resolve interface name for %i: %m", ifindex);
if (!format_ifname(ifindex, ifname))
return log_error_errno(errno, "Failed to resolve interface name for %i: %m", ifindex);
name = ifname;
}

View File

@ -504,6 +504,7 @@ static int dns_cache_put_positive(
if (DEBUG_LOGGING) {
_cleanup_free_ char *t = NULL;
char ifname[IF_NAMESIZE + 1];
(void) in_addr_to_string(i->owner_family, &i->owner_address, &t);
@ -513,7 +514,7 @@ static int dns_cache_put_positive(
i->shared_owner ? " shared" : "",
dns_resource_key_to_string(i->key, key_str, sizeof key_str),
(i->until - timestamp) / USEC_PER_SEC,
i->ifindex == 0 ? "*" : FORMAT_IFNAME(i->ifindex),
i->ifindex == 0 ? "*" : strna(format_ifname(i->ifindex, ifname)),
af_to_name_short(i->owner_family),
strna(t));
}

View File

@ -1665,9 +1665,16 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
case TABLE_IFINDEX: {
_cleanup_free_ char *p = NULL;
char name[IF_NAMESIZE + 1];
if (format_ifname_full_alloc(d->ifindex, FORMAT_IFNAME_IFINDEX, &p) < 0)
return NULL;
if (format_ifname(d->ifindex, name)) {
p = strdup(name);
if (!p)
return NULL;
} else {
if (asprintf(&p, "%i" , d->ifindex) < 0)
return NULL;
}
d->formatted = TAKE_PTR(p);
break;

View File

@ -17,6 +17,24 @@
log_interface_full_errno_zerook(ifname, level, _error, __VA_ARGS__); \
})
#define log_interface_prefix_full_errno_zerook(prefix, ifname_expr, error, fmt, ...) \
({ \
int _e = (error); \
if (DEBUG_LOGGING) \
log_interface_full_errno_zerook( \
ifname_expr, \
LOG_DEBUG, _e, prefix fmt, \
##__VA_ARGS__); \
-ERRNO_VALUE(_e); \
})
#define log_interface_prefix_full_errno(prefix, ifname_expr, error, fmt, ...) \
({ \
int _error = (error); \
ASSERT_NON_ZERO(_error); \
log_interface_prefix_full_errno_zerook(prefix, ifname_expr, _error, fmt, ##__VA_ARGS__); \
})
/*
* The following macros append INTERFACE= to the message.
* The macros require a struct named 'Link' which contains 'char *ifname':

View File

@ -5,13 +5,6 @@
#include "proc-cmdline.h"
#include "string-util.h"
#ifdef _DEFAULT_NET_NAMING_SCHEME_TEST
/* The primary purpose of this check is to verify that _DEFAULT_NET_NAMING_SCHEME_TEST
* is a valid identifier. If an invalid name is given during configuration, this will
* fail with a name error. */
assert_cc(_DEFAULT_NET_NAMING_SCHEME_TEST >= 0);
#endif
static const NamingScheme naming_schemes[] = {
{ "v238", NAMING_V238 },
{ "v239", NAMING_V239 },
@ -22,22 +15,19 @@ static const NamingScheme naming_schemes[] = {
{ "v247", NAMING_V247 },
{ "v249", NAMING_V249 },
/* … add more schemes here, as the logic to name devices is updated … */
EXTRA_NET_NAMING_MAP
/* also remember to update the list of options in meson_options.txt */
};
const NamingScheme* naming_scheme_from_name(const char *name) {
/* "latest" may either be defined explicitly by the extra map, in which case we we will find it in
* the table like any other name. After iterating through the table, we check for "latest" again,
* which means that if not mapped explicitly, it maps to the last defined entry, whatever that is. */
for (size_t i = 0; i < ELEMENTSOF(naming_schemes); i++)
if (streq(naming_schemes[i].name, name))
return naming_schemes + i;
static const NamingScheme* naming_scheme_from_name(const char *name) {
size_t i;
if (streq(name, "latest"))
return naming_schemes + ELEMENTSOF(naming_schemes) - 1;
for (i = 0; i < ELEMENTSOF(naming_schemes); i++)
if (streq(naming_schemes[i].name, name))
return naming_schemes + i;
return NULL;
}

View File

@ -46,8 +46,6 @@ typedef enum NamingSchemeFlags {
NAMING_V247 = NAMING_V245 | NAMING_BRIDGE_NO_SLOT,
NAMING_V249 = NAMING_V247 | NAMING_SLOT_FUNCTION_ID | NAMING_16BIT_INDEX | NAMING_REPLACE_STRICTLY,
EXTRA_NET_NAMING_SCHEMES
_NAMING_SCHEME_FLAGS_INVALID = -EINVAL,
} NamingSchemeFlags;
@ -56,7 +54,6 @@ typedef struct NamingScheme {
NamingSchemeFlags flags;
} NamingScheme;
const NamingScheme* naming_scheme_from_name(const char *name);
const NamingScheme* naming_scheme(void);
static inline bool naming_scheme_has(NamingSchemeFlags flags) {

View File

@ -135,7 +135,7 @@ int sd_dhcp_client_set_ifindex(
int sd_dhcp_client_set_ifname(
sd_dhcp_client *client,
const char *interface_name);
int sd_dhcp_client_get_ifname(sd_dhcp_client *client, const char **ret);
const char *sd_dhcp_client_get_ifname(sd_dhcp_client *client);
int sd_dhcp_client_set_mac(
sd_dhcp_client *client,
const uint8_t *addr,

View File

@ -38,7 +38,7 @@ enum {
int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex);
int sd_dhcp_server_set_ifname(sd_dhcp_server *server, const char *ifname);
int sd_dhcp_server_get_ifname(sd_dhcp_server *server, const char **ret);
const char *sd_dhcp_server_get_ifname(sd_dhcp_server *server);
sd_dhcp_server *sd_dhcp_server_ref(sd_dhcp_server *server);
sd_dhcp_server *sd_dhcp_server_unref(sd_dhcp_server *server);

View File

@ -94,7 +94,7 @@ int sd_dhcp6_client_set_ifindex(
int sd_dhcp6_client_set_ifname(
sd_dhcp6_client *client,
const char *interface_name);
int sd_dhcp6_client_get_ifname(sd_dhcp6_client *client, const char **ret);
const char * sd_dhcp6_client_get_ifname(sd_dhcp6_client *client);
int sd_dhcp6_client_set_local_address(
sd_dhcp6_client *client,
const struct in6_addr *local_address);

View File

@ -47,7 +47,7 @@ int sd_ipv4acd_set_mac(sd_ipv4acd *acd, const struct ether_addr *addr);
int sd_ipv4acd_set_ifindex(sd_ipv4acd *acd, int interface_index);
int sd_ipv4acd_get_ifindex(sd_ipv4acd *acd);
int sd_ipv4acd_set_ifname(sd_ipv4acd *acd, const char *interface_name);
int sd_ipv4acd_get_ifname(sd_ipv4acd *acd, const char **ret);
const char *sd_ipv4acd_get_ifname(sd_ipv4acd *acd);
int sd_ipv4acd_set_address(sd_ipv4acd *acd, const struct in_addr *address);
int sd_ipv4acd_is_running(sd_ipv4acd *acd);
int sd_ipv4acd_start(sd_ipv4acd *acd, bool reset_conflicts);

View File

@ -47,7 +47,7 @@ int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr);
int sd_ipv4ll_set_ifindex(sd_ipv4ll *ll, int interface_index);
int sd_ipv4ll_get_ifindex(sd_ipv4ll *ll);
int sd_ipv4ll_set_ifname(sd_ipv4ll *ll, const char *interface_name);
int sd_ipv4ll_get_ifname(sd_ipv4ll *ll, const char **ret);
const char *sd_ipv4ll_get_ifname(sd_ipv4ll *ll);
int sd_ipv4ll_set_address(sd_ipv4ll *ll, const struct in_addr *address);
int sd_ipv4ll_set_address_seed(sd_ipv4ll *ll, uint64_t seed);
int sd_ipv4ll_is_running(sd_ipv4ll *ll);

View File

@ -59,7 +59,7 @@ sd_event *sd_lldp_rx_get_event(sd_lldp_rx *lldp_rx);
int sd_lldp_rx_set_callback(sd_lldp_rx *lldp_rx, sd_lldp_rx_callback_t cb, void *userdata);
int sd_lldp_rx_set_ifindex(sd_lldp_rx *lldp_rx, int ifindex);
int sd_lldp_rx_set_ifname(sd_lldp_rx *lldp_rx, const char *ifname);
int sd_lldp_rx_get_ifname(sd_lldp_rx *lldp_rx, const char **ret);
const char *sd_lldp_rx_get_ifname(sd_lldp_rx *lldp_rx);
/* Controls how much and what to store in the neighbors database */
int sd_lldp_rx_set_neighbors_max(sd_lldp_rx *lldp_rx, uint64_t n);

View File

@ -54,7 +54,7 @@ sd_event *sd_lldp_tx_get_event(sd_lldp_tx *lldp_tx);
int sd_lldp_tx_set_ifindex(sd_lldp_tx *lldp_tx, int ifindex);
int sd_lldp_tx_set_ifname(sd_lldp_tx *lldp_tx, const char *ifname);
int sd_lldp_tx_get_ifname(sd_lldp_tx *lldp_tx, const char **ret);
const char *sd_lldp_tx_get_ifname(sd_lldp_tx *lldp_tx);
int sd_lldp_tx_set_multicast_mode(sd_lldp_tx *lldp_tx, sd_lldp_multicast_mode_t mode);
int sd_lldp_tx_set_hwaddr(sd_lldp_tx *lldp_tx, const struct ether_addr *hwaddr);

View File

@ -79,7 +79,7 @@ sd_event *sd_ndisc_get_event(sd_ndisc *nd);
int sd_ndisc_set_callback(sd_ndisc *nd, sd_ndisc_callback_t cb, void *userdata);
int sd_ndisc_set_ifindex(sd_ndisc *nd, int interface_index);
int sd_ndisc_set_ifname(sd_ndisc *nd, const char *interface_name);
int sd_ndisc_get_ifname(sd_ndisc *nd, const char **ret);
const char *sd_ndisc_get_ifname(sd_ndisc *nd);
int sd_ndisc_set_mac(sd_ndisc *nd, const struct ether_addr *mac_addr);
int sd_ndisc_get_mtu(sd_ndisc *nd, uint32_t *ret);

View File

@ -54,7 +54,7 @@ int sd_radv_is_running(sd_radv *ra);
int sd_radv_set_ifindex(sd_radv *ra, int interface_index);
int sd_radv_set_ifname(sd_radv *ra, const char *interface_name);
int sd_radv_get_ifname(sd_radv *ra, const char **ret);
const char *sd_radv_get_ifname(sd_radv *ra);
int sd_radv_set_mac(sd_radv *ra, const struct ether_addr *mac_addr);
int sd_radv_set_mtu(sd_radv *ra, uint32_t mtu);
int sd_radv_set_hop_limit(sd_radv *ra, uint8_t hop_limit);

View File

@ -429,8 +429,6 @@ tests += [
[['src/test/test-firewall-util.c']],
[['src/test/test-net-naming-scheme.c']],
[['src/test/test-netlink-manual.c'],
[],
[libkmod],

View File

@ -1,31 +0,0 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "netif-naming-scheme.h"
#include "string-util.h"
#include "tests.h"
static void test_default_net_naming_scheme(void) {
log_info("/* %s */", __func__);
const NamingScheme *n;
assert_se(n = naming_scheme_from_name(DEFAULT_NET_NAMING_SCHEME));
log_info("default → %s", n->name);
}
static void test_naming_scheme_conversions(void) {
log_info("/* %s */", __func__);
const NamingScheme *n;
assert_se(n = naming_scheme_from_name("latest"));
log_info("latest → %s", n->name);
assert_se(n = naming_scheme_from_name("v238"));
assert_se(streq(n->name, "v238"));
}
int main(int argc, char **argv) {
test_setup_logging(LOG_INFO);
test_default_net_naming_scheme();
test_naming_scheme_conversions();
}

View File

@ -41,12 +41,14 @@ static const char* af_to_string(int family, char *buf, size_t buf_len) {
}
static int print_gaih_addrtuples(const struct gaih_addrtuple *tuples) {
int r, n = 0;
int n = 0;
for (const struct gaih_addrtuple *it = tuples; it; it = it->next) {
_cleanup_free_ char *a = NULL;
union in_addr_union u;
int r;
char family_name[DECIMAL_STR_MAX(int)];
char ifname[IF_NAMESIZE + 1];
memcpy(&u, it->addr, 16);
r = in_addr_to_string(it->family, &u, &a);
@ -54,13 +56,21 @@ static int print_gaih_addrtuples(const struct gaih_addrtuple *tuples) {
if (r == -EAFNOSUPPORT)
assert_se(a = hexmem(it->addr, 16));
log_info(" \"%s\" %s %s %s",
if (it->scopeid == 0)
goto numerical_index;
if (!format_ifname(it->scopeid, ifname)) {
log_warning_errno(errno, "if_indextoname(%d) failed: %m", it->scopeid);
numerical_index:
xsprintf(ifname, "%i", it->scopeid);
};
log_info(" \"%s\" %s %s %%%s",
it->name,
af_to_string(it->family, family_name, sizeof family_name),
a,
FORMAT_IFNAME_FULL(it->scopeid, FORMAT_IFNAME_IFINDEX_WITH_PERCENT));
n++;
ifname);
n ++;
}
return n;
}

View File

@ -1000,33 +1000,6 @@ static void test_strextendf(void) {
assert_se(streq(p, "<77>,<99>,< 88>,<00001234>"));
}
static void test_streq_skip_trailing_chars(void) {
log_info("/* %s */", __func__);
/* NULL is WHITESPACE by default*/
assert_se(streq_skip_trailing_chars("foo bar", "foo bar", NULL));
assert_se(streq_skip_trailing_chars("foo", "foo", NULL));
assert_se(streq_skip_trailing_chars("foo bar ", "foo bar", NULL));
assert_se(streq_skip_trailing_chars("foo bar", "foo bar\t\t", NULL));
assert_se(streq_skip_trailing_chars("foo bar ", "foo bar\t\t", NULL));
assert_se(streq_skip_trailing_chars("foo\nbar", "foo\nbar", NULL));
assert_se(streq_skip_trailing_chars("\t\tfoo bar", "\t\tfoo bar", NULL));
assert_se(streq_skip_trailing_chars(" foo bar\t", " foo bar\n", NULL));
assert_se(!streq_skip_trailing_chars("foobar", "foo bar", NULL));
assert_se(!streq_skip_trailing_chars("foo\nbar", "foo\tbar", NULL));
assert_se(!streq_skip_trailing_chars("\t\nfoo bar", "\t foo bar", NULL));
assert_se(streq_skip_trailing_chars("foo bar ", "foo bar", WHITESPACE));
assert_se(!streq_skip_trailing_chars("foo bar ", "foo bar", NEWLINE));
assert_se(streq_skip_trailing_chars(NULL, NULL, NULL));
assert_se(streq_skip_trailing_chars("", "", NULL));
assert_se(!streq_skip_trailing_chars(NULL, "foo bar", NULL));
assert_se(!streq_skip_trailing_chars("foo", NULL, NULL));
assert_se(!streq_skip_trailing_chars("", "f", NULL));
}
int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG);
@ -1066,7 +1039,6 @@ int main(int argc, char *argv[]) {
test_string_contains_word();
test_strverscmp_improved();
test_strextendf();
test_streq_skip_trailing_chars();
return 0;
}