From 3907446f02d5966e795a7361860f7189c8b3ccc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 16 Jan 2019 14:26:29 +0100 Subject: link-config: add "keep" policy and use it by default If "keep" policy is specified, and the interface has a name that is NET_NAME_USER or NET_NAME_RENAMED, we stop processing rules. "keep" should probably be specified either first or last depending on the preference. This partially reimplements 55b6530baacf4658a183b15b010a8cf3483fde08, in the sense that if the "keep" policy is not specified, and if the interface has a NamingPolicy, it will be renamed, even if it had a name previously. So this breaks backwards compatibility in this case, but that's more in line with what users expect. Closes #9006. --- man/systemd.link.xml | 24 +++++++++++++----------- network/99-default.link | 2 +- src/udev/net/link-config.c | 17 ++++++++++------- src/udev/net/link-config.h | 1 + 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/man/systemd.link.xml b/man/systemd.link.xml index f74edd0186..22713e0316 100644 --- a/man/systemd.link.xml +++ b/man/systemd.link.xml @@ -250,17 +250,12 @@ NamePolicy= - An ordered, space-separated list of policies by which - the interface name should be set. - NamePolicy may be disabled by specifying - net.ifnames=0 on the kernel command line. - Each of the policies may fail, and the first successful one - is used. The name is not set directly, but is exported to - udev as the property ID_NET_NAME, which - is, by default, used by a udev rule to set - NAME. If the name has already been set by - userspace, no renaming is performed. The available policies - are: + An ordered, space-separated list of policies by which the interface name should be set. + NamePolicy may be disabled by specifying net.ifnames=0 on the + kernel command line. Each of the policies may fail, and the first successful one is used. The name + is not set directly, but is exported to udev as the property ID_NET_NAME, which + is, by default, used by a udev rule to set NAME. The available policies are: + @@ -314,6 +309,13 @@ ID_NET_NAME_MAC. + + keep + + If the device already had a name given by userspace (as part of creation of the device + or a rename), keep it. + + diff --git a/network/99-default.link b/network/99-default.link index 561bf329e4..92fcbe83ea 100644 --- a/network/99-default.link +++ b/network/99-default.link @@ -8,5 +8,5 @@ # (at your option) any later version. [Link] -NamePolicy=kernel database onboard slot path +NamePolicy=keep kernel database onboard slot path MACAddressPolicy=persistent diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index dc0f02bde9..dfb00485d1 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -399,11 +399,6 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, (void) link_name_type(device, &name_type); - if (IN_SET(name_type, NET_NAME_USER, NET_NAME_RENAMED)) { - log_device_info(device, "Device already has a name given by userspace, not renaming."); - goto no_rename; - } - if (ctx->enable_name_policy && config->name_policy) for (NamePolicy *p = config->name_policy; !new_name && *p != _NAMEPOLICY_INVALID; p++) { policy = *p; @@ -417,6 +412,13 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, log_device_debug(device, "Policy *%s*: keeping predictable kernel name", name_policy_to_string(policy)); goto no_rename; + case NAMEPOLICY_KEEP: + if (!IN_SET(name_type, NET_NAME_USER, NET_NAME_RENAMED)) + continue; + + log_device_debug(device, "Policy *%s*: keeping existing userspace name", + name_policy_to_string(policy)); + goto no_rename; case NAMEPOLICY_DATABASE: (void) sd_device_get_property_value(device, "ID_NET_NAME_FROM_DATABASE", &new_name); break; @@ -503,7 +505,7 @@ int link_get_driver(link_config_ctx *ctx, sd_device *device, char **ret) { static const char* const mac_policy_table[_MACPOLICY_MAX] = { [MACPOLICY_PERSISTENT] = "persistent", [MACPOLICY_RANDOM] = "random", - [MACPOLICY_NONE] = "none" + [MACPOLICY_NONE] = "none", }; DEFINE_STRING_TABLE_LOOKUP(mac_policy, MACPolicy); @@ -512,11 +514,12 @@ DEFINE_CONFIG_PARSE_ENUM(config_parse_mac_policy, mac_policy, MACPolicy, static const char* const name_policy_table[_NAMEPOLICY_MAX] = { [NAMEPOLICY_KERNEL] = "kernel", + [NAMEPOLICY_KEEP] = "keep", [NAMEPOLICY_DATABASE] = "database", [NAMEPOLICY_ONBOARD] = "onboard", [NAMEPOLICY_SLOT] = "slot", [NAMEPOLICY_PATH] = "path", - [NAMEPOLICY_MAC] = "mac" + [NAMEPOLICY_MAC] = "mac", }; DEFINE_STRING_TABLE_LOOKUP(name_policy, NamePolicy); diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h index 8204959034..1113b1052e 100644 --- a/src/udev/net/link-config.h +++ b/src/udev/net/link-config.h @@ -22,6 +22,7 @@ typedef enum MACPolicy { typedef enum NamePolicy { NAMEPOLICY_KERNEL, + NAMEPOLICY_KEEP, NAMEPOLICY_DATABASE, NAMEPOLICY_ONBOARD, NAMEPOLICY_SLOT, -- cgit v1.2.1