mirror of
https://github.com/systemd/systemd
synced 2024-10-04 15:21:01 +00:00
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 55b6530baa
, 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.
This commit is contained in:
parent
0b189e8fa7
commit
3907446f02
|
@ -250,17 +250,12 @@
|
|||
<varlistentry>
|
||||
<term><varname>NamePolicy=</varname></term>
|
||||
<listitem>
|
||||
<para>An ordered, space-separated list of policies by which
|
||||
the interface name should be set.
|
||||
<literal>NamePolicy</literal> may be disabled by specifying
|
||||
<literal>net.ifnames=0</literal> 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 <literal>ID_NET_NAME</literal>, which
|
||||
is, by default, used by a udev rule to set
|
||||
<literal>NAME</literal>. If the name has already been set by
|
||||
userspace, no renaming is performed. The available policies
|
||||
are:</para>
|
||||
<para>An ordered, space-separated list of policies by which the interface name should be set.
|
||||
<literal>NamePolicy</literal> may be disabled by specifying <literal>net.ifnames=0</literal> 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 <literal>ID_NET_NAME</literal>, which
|
||||
is, by default, used by a udev rule to set <literal>NAME</literal>. The available policies are:
|
||||
</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
|
@ -314,6 +309,13 @@
|
|||
<literal>ID_NET_NAME_MAC</literal>.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><literal>keep</literal></term>
|
||||
<listitem>
|
||||
<para>If the device already had a name given by userspace (as part of creation of the device
|
||||
or a rename), keep it.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -22,6 +22,7 @@ typedef enum MACPolicy {
|
|||
|
||||
typedef enum NamePolicy {
|
||||
NAMEPOLICY_KERNEL,
|
||||
NAMEPOLICY_KEEP,
|
||||
NAMEPOLICY_DATABASE,
|
||||
NAMEPOLICY_ONBOARD,
|
||||
NAMEPOLICY_SLOT,
|
||||
|
|
Loading…
Reference in a new issue