network/netdev: move calls of netdev_attach() and netdev_request_to_create() to netdev_load()

No functional change, preparation for later commits.
This commit is contained in:
Yu Watanabe
2024-10-31 05:30:40 +09:00
parent 954dd5242b
commit 933d88f756
3 changed files with 24 additions and 22 deletions
+2 -1
View File
@@ -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;
}
+21 -20
View File
@@ -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;
}
+1 -1
View File
@@ -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);