mirror of
https://github.com/systemd/systemd.git
synced 2024-10-28 11:55:44 +03:00
udev: link-config - less verbose logging
Also reinstate print to kmsg when renaming netif.
This commit is contained in:
parent
3e137a1b9a
commit
f61942250a
@ -44,6 +44,8 @@ struct link_config_ctx {
|
||||
|
||||
int ethtool_fd;
|
||||
|
||||
bool enable_name_policy;
|
||||
|
||||
sd_rtnl *rtnl;
|
||||
|
||||
char **link_dirs;
|
||||
@ -67,6 +69,8 @@ int link_config_ctx_new(link_config_ctx **ret) {
|
||||
|
||||
ctx->ethtool_fd = -1;
|
||||
|
||||
ctx->enable_name_policy = true;
|
||||
|
||||
ctx->link_dirs = strv_new("/etc/systemd/network",
|
||||
"/run/systemd/network",
|
||||
"/usr/lib/systemd/network",
|
||||
@ -181,12 +185,37 @@ failure:
|
||||
return r;
|
||||
}
|
||||
|
||||
static bool enable_name_policy(void) {
|
||||
_cleanup_free_ char *line;
|
||||
char *w, *state;
|
||||
int r;
|
||||
size_t l;
|
||||
|
||||
r = read_one_line_file("/proc/cmdline", &line);
|
||||
if (r < 0) {
|
||||
log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
|
||||
return true; /* something is very wrong, let's not make it worse */
|
||||
}
|
||||
|
||||
FOREACH_WORD_QUOTED(w, l, line, state)
|
||||
if (strneq(w, "net.ifnames=0", l))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int link_config_load(link_config_ctx *ctx) {
|
||||
int r;
|
||||
char **files, **f;
|
||||
|
||||
link_configs_free(ctx);
|
||||
|
||||
|
||||
if (!enable_name_policy()) {
|
||||
ctx->enable_name_policy = false;
|
||||
log_info("Network interface NamePolicy= disabled on kernel commandline, ignoring.");
|
||||
}
|
||||
|
||||
/* update timestamp */
|
||||
paths_check_timestamp(ctx->link_dirs, &ctx->link_dirs_ts_usec, true);
|
||||
|
||||
@ -255,10 +284,8 @@ int link_config_get(link_config_ctx *ctx, struct udev_device *device, link_confi
|
||||
link_config *link;
|
||||
|
||||
LIST_FOREACH(links, link, ctx->links) {
|
||||
if (!match_config(link, device)) {
|
||||
log_info("Config file %s does not apply to device %s", link->filename, udev_device_get_sysname(device));
|
||||
} else {
|
||||
log_info("Config file %s applies to device %s", link->filename, udev_device_get_sysname(device));
|
||||
if (match_config(link, device)) {
|
||||
log_debug("Config file %s applies to device %s", link->filename, udev_device_get_sysname(device));
|
||||
*ret = link;
|
||||
return 0;
|
||||
}
|
||||
@ -267,27 +294,6 @@ int link_config_get(link_config_ctx *ctx, struct udev_device *device, link_confi
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static bool enable_name_policy(void) {
|
||||
_cleanup_free_ char *line;
|
||||
char *w, *state;
|
||||
int r;
|
||||
size_t l;
|
||||
|
||||
r = read_one_line_file("/proc/cmdline", &line);
|
||||
if (r < 0) {
|
||||
log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
|
||||
return true; /* something is very wrong, let's not make it worse */
|
||||
}
|
||||
|
||||
FOREACH_WORD_QUOTED(w, l, line, state)
|
||||
if (strneq(w, "net.ifnames=0", l)) {
|
||||
log_info("Link name policy disabled on kernel commandline, ignoring.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool mac_is_random(struct udev_device *device) {
|
||||
const char *s;
|
||||
unsigned type;
|
||||
@ -387,8 +393,6 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev
|
||||
if (!old_name)
|
||||
return -EINVAL;
|
||||
|
||||
log_info("Configuring %s", old_name);
|
||||
|
||||
if (config->description) {
|
||||
r = udev_device_set_sysattr_value(device, "ifalias",
|
||||
config->description);
|
||||
@ -413,7 +417,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (config->name_policy && enable_name_policy()) {
|
||||
if (ctx->enable_name_policy && config->name_policy) {
|
||||
NamePolicy *policy;
|
||||
|
||||
for (policy = config->name_policy; !new_name && *policy != _NAMEPOLICY_INVALID; policy++) {
|
||||
|
@ -769,7 +769,7 @@ static int rename_netif(struct udev_event *event)
|
||||
log_error("error changing net interface name %s to %s: %s",
|
||||
oldname, name, strerror(-r));
|
||||
else
|
||||
log_info("renamed network interface %s to %s", oldname, name);
|
||||
print_kmsg("renamed network interface %s to %s", oldname, name);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user