mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
@@ -39,7 +39,6 @@
|
||||
struct LinkConfigContext {
|
||||
LIST_HEAD(LinkConfig, configs);
|
||||
int ethtool_fd;
|
||||
bool enable_name_policy;
|
||||
usec_t network_dirs_ts_usec;
|
||||
};
|
||||
|
||||
@@ -97,7 +96,6 @@ int link_config_ctx_new(LinkConfigContext **ret) {
|
||||
|
||||
*ctx = (LinkConfigContext) {
|
||||
.ethtool_fd = -1,
|
||||
.enable_name_policy = true,
|
||||
};
|
||||
|
||||
*ret = TAKE_PTR(ctx);
|
||||
@@ -298,12 +296,6 @@ int link_load_one(LinkConfigContext *ctx, const char *filename) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool enable_name_policy(void) {
|
||||
bool b;
|
||||
|
||||
return proc_cmdline_get_bool("net.ifnames", &b) <= 0 || b;
|
||||
}
|
||||
|
||||
static int device_unsigned_attribute(sd_device *device, const char *attr, unsigned *type) {
|
||||
const char *s;
|
||||
int r;
|
||||
@@ -326,11 +318,6 @@ int link_config_load(LinkConfigContext *ctx) {
|
||||
|
||||
link_configs_free(ctx);
|
||||
|
||||
if (!enable_name_policy()) {
|
||||
ctx->enable_name_policy = false;
|
||||
log_info("Network interface NamePolicy= disabled on kernel command line, ignoring.");
|
||||
}
|
||||
|
||||
/* update timestamp */
|
||||
paths_check_timestamp(NETWORK_DIRS, &ctx->network_dirs_ts_usec, true);
|
||||
|
||||
@@ -686,7 +673,27 @@ static int link_apply_rtnl_settings(Link *link, sd_netlink **rtnl) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int link_generate_new_name(Link *link, bool enable_name_policy) {
|
||||
static bool enable_name_policy(void) {
|
||||
static int cached = -1;
|
||||
bool b;
|
||||
int r;
|
||||
|
||||
if (cached >= 0)
|
||||
return cached;
|
||||
|
||||
r = proc_cmdline_get_bool("net.ifnames", &b);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to parse net.ifnames= kernel command line option, ignoring: %m");
|
||||
if (r <= 0)
|
||||
return (cached = true);
|
||||
|
||||
if (!b)
|
||||
log_info("Network interface NamePolicy= disabled on kernel command line.");
|
||||
|
||||
return (cached = b);
|
||||
}
|
||||
|
||||
static int link_generate_new_name(Link *link) {
|
||||
LinkConfig *config;
|
||||
sd_device *device;
|
||||
|
||||
@@ -709,7 +716,7 @@ static int link_generate_new_name(Link *link, bool enable_name_policy) {
|
||||
goto no_rename;
|
||||
}
|
||||
|
||||
if (enable_name_policy && config->name_policy)
|
||||
if (enable_name_policy() && config->name_policy)
|
||||
for (NamePolicy *policy = config->name_policy; *policy != _NAMEPOLICY_INVALID; policy++) {
|
||||
const char *new_name = NULL;
|
||||
|
||||
@@ -931,7 +938,7 @@ int link_apply_config(LinkConfigContext *ctx, sd_netlink **rtnl, Link *link) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = link_generate_new_name(link, ctx->enable_name_policy);
|
||||
r = link_generate_new_name(link);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -1138,8 +1138,15 @@ static int builtin_net_id(sd_device *dev, sd_netlink **rtnl, int argc, char *arg
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int builtin_net_id_init(void) {
|
||||
/* Load naming scheme here to suppress log messages in workers. */
|
||||
naming_scheme();
|
||||
return 0;
|
||||
}
|
||||
|
||||
const UdevBuiltin udev_builtin_net_id = {
|
||||
.name = "net_id",
|
||||
.cmd = builtin_net_id,
|
||||
.init = builtin_net_id_init,
|
||||
.help = "Network device properties",
|
||||
};
|
||||
|
||||
@@ -32,12 +32,10 @@ static const UdevBuiltin *const builtins[_UDEV_BUILTIN_MAX] = {
|
||||
};
|
||||
|
||||
void udev_builtin_init(void) {
|
||||
unsigned i;
|
||||
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
for (i = 0; i < _UDEV_BUILTIN_MAX; i++)
|
||||
for (UdevBuiltinCommand i = 0; i < _UDEV_BUILTIN_MAX; i++)
|
||||
if (builtins[i] && builtins[i]->init)
|
||||
builtins[i]->init();
|
||||
|
||||
@@ -45,12 +43,10 @@ void udev_builtin_init(void) {
|
||||
}
|
||||
|
||||
void udev_builtin_exit(void) {
|
||||
unsigned i;
|
||||
|
||||
if (!initialized)
|
||||
return;
|
||||
|
||||
for (i = 0; i < _UDEV_BUILTIN_MAX; i++)
|
||||
for (UdevBuiltinCommand i = 0; i < _UDEV_BUILTIN_MAX; i++)
|
||||
if (builtins[i] && builtins[i]->exit)
|
||||
builtins[i]->exit();
|
||||
|
||||
@@ -58,18 +54,14 @@ void udev_builtin_exit(void) {
|
||||
}
|
||||
|
||||
bool udev_builtin_validate(void) {
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < _UDEV_BUILTIN_MAX; i++)
|
||||
for (UdevBuiltinCommand i = 0; i < _UDEV_BUILTIN_MAX; i++)
|
||||
if (builtins[i] && builtins[i]->validate && builtins[i]->validate())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void udev_builtin_list(void) {
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < _UDEV_BUILTIN_MAX; i++)
|
||||
for (UdevBuiltinCommand i = 0; i < _UDEV_BUILTIN_MAX; i++)
|
||||
if (builtins[i])
|
||||
fprintf(stderr, " %-14s %s\n", builtins[i]->name, builtins[i]->help);
|
||||
}
|
||||
@@ -93,14 +85,13 @@ bool udev_builtin_run_once(UdevBuiltinCommand cmd) {
|
||||
}
|
||||
|
||||
UdevBuiltinCommand udev_builtin_lookup(const char *command) {
|
||||
UdevBuiltinCommand i;
|
||||
size_t n;
|
||||
|
||||
assert(command);
|
||||
|
||||
command += strspn(command, WHITESPACE);
|
||||
n = strcspn(command, WHITESPACE);
|
||||
for (i = 0; i < _UDEV_BUILTIN_MAX; i++)
|
||||
for (UdevBuiltinCommand i = 0; i < _UDEV_BUILTIN_MAX; i++)
|
||||
if (builtins[i] && strneq(builtins[i]->name, command, n))
|
||||
return i;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "sd-device.h"
|
||||
#include "sd-netlink.h"
|
||||
|
||||
typedef enum {
|
||||
typedef enum UdevBuiltinCommand {
|
||||
#if HAVE_BLKID
|
||||
UDEV_BUILTIN_BLKID,
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user