summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-10-27 08:37:17 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-10-30 21:30:40 +0100
commit933d88f756fe69dd6b8ffe6e480d298edd7ba982 (patch)
treedb5496f35b4cd6c3e346801c51f7e1dd90c860ae /src/network
parentmkosi: Ensure we build with debuginfo (diff)
downloadsystemd-933d88f756fe69dd6b8ffe6e480d298edd7ba982.tar.xz
systemd-933d88f756fe69dd6b8ffe6e480d298edd7ba982.zip
network/netdev: move calls of netdev_attach() and netdev_request_to_create() to netdev_load()
No functional change, preparation for later commits.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/fuzz-netdev-parser.c3
-rw-r--r--src/network/netdev/netdev.c41
-rw-r--r--src/network/netdev/netdev.h2
3 files changed, 24 insertions, 22 deletions
diff --git a/src/network/fuzz-netdev-parser.c b/src/network/fuzz-netdev-parser.c
index f0988bd4cc..7e29ba9b8e 100644
--- a/src/network/fuzz-netdev-parser.c
+++ b/src/network/fuzz-netdev-parser.c
@@ -10,6 +10,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_(manager_freep) Manager *manager = NULL;
_cleanup_fclose_ FILE *f = NULL;
_cleanup_(unlink_tempfilep) char netdev_config[] = "/tmp/fuzz-networkd.XXXXXX";
+ _cleanup_(netdev_unrefp) NetDev *netdev = NULL;
if (outside_size_range(size, 0, 65536))
return 0;
@@ -22,6 +23,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
fflush(f);
assert_se(manager_new(&manager, /* test_mode = */ true) >= 0);
- (void) netdev_load_one(manager, netdev_config);
+ (void) netdev_load_one(manager, netdev_config, &netdev);
return 0;
}
diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c
index 80538a60ec..0cfe6ebb9e 100644
--- a/src/network/netdev/netdev.c
+++ b/src/network/netdev/netdev.c
@@ -940,21 +940,20 @@ static int netdev_request_to_create(NetDev *netdev) {
return 0;
}
-int netdev_load_one(Manager *manager, const char *filename) {
+int netdev_load_one(Manager *manager, const char *filename, NetDev **ret) {
_cleanup_(netdev_unrefp) NetDev *netdev_raw = NULL, *netdev = NULL;
const char *dropin_dirname;
int r;
assert(manager);
assert(filename);
+ assert(ret);
r = null_or_empty_path(filename);
if (r < 0)
return log_warning_errno(r, "Failed to check if \"%s\" is empty: %m", filename);
- if (r > 0) {
- log_debug("Skipping empty file: %s", filename);
- return 0;
- }
+ if (r > 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(ENOENT), "Skipping empty file: %s", filename);
netdev_raw = new(NetDev, 1);
if (!netdev_raw)
@@ -979,10 +978,8 @@ int netdev_load_one(Manager *manager, const char *filename) {
return r; /* config_parse_many() logs internally. */
/* skip out early if configuration does not match the environment */
- if (!condition_test_list(netdev_raw->conditions, environ, NULL, NULL, NULL)) {
- log_debug("%s: Conditions in the file do not match the system environment, skipping.", filename);
- return 0;
- }
+ if (!condition_test_list(netdev_raw->conditions, environ, NULL, NULL, NULL))
+ return log_debug_errno(SYNTHETIC_ERRNO(ESTALE), "%s: Conditions in the file do not match the system environment, skipping.", filename);
if (netdev_raw->kind == _NETDEV_KIND_INVALID)
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), "NetDev has no Kind= configured in \"%s\", ignoring.", filename);
@@ -1025,17 +1022,9 @@ int netdev_load_one(Manager *manager, const char *filename) {
if (!netdev->filename)
return log_oom();
- r = netdev_attach(netdev);
- if (r < 0)
- return r;
-
log_syntax(/* unit = */ NULL, LOG_DEBUG, filename, /* config_line = */ 0, /* error = */ 0, "Successfully loaded.");
- r = netdev_request_to_create(netdev);
- if (r < 0)
- return r; /* netdev_request_to_create() logs internally. */
-
- TAKE_PTR(netdev);
+ *ret = TAKE_PTR(netdev);
return 0;
}
@@ -1049,8 +1038,20 @@ int netdev_load(Manager *manager) {
if (r < 0)
return log_error_errno(r, "Failed to enumerate netdev files: %m");
- STRV_FOREACH(f, files)
- (void) netdev_load_one(manager, *f);
+ STRV_FOREACH(f, files) {
+ _cleanup_(netdev_unrefp) NetDev *netdev = NULL;
+
+ if (netdev_load_one(manager, *f, &netdev) < 0)
+ continue;
+
+ if (netdev_attach(netdev) < 0)
+ continue;
+
+ if (netdev_request_to_create(netdev) < 0)
+ continue;
+
+ TAKE_PTR(netdev);
+ }
return 0;
}
diff --git a/src/network/netdev/netdev.h b/src/network/netdev/netdev.h
index 786fe9e9f6..a91ef50654 100644
--- a/src/network/netdev/netdev.h
+++ b/src/network/netdev/netdev.h
@@ -218,7 +218,7 @@ void netdev_detach(NetDev *netdev);
int netdev_set_ifindex_internal(NetDev *netdev, int ifindex);
int netdev_load(Manager *manager);
-int netdev_load_one(Manager *manager, const char *filename);
+int netdev_load_one(Manager *manager, const char *filename, NetDev **ret);
void netdev_drop(NetDev *netdev);
void netdev_enter_failed(NetDev *netdev);
int netdev_enter_ready(NetDev *netdev);