Skip to content

Commit

Permalink
link-config: add "keep" policy and use it by default
Browse files Browse the repository at this point in the history
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 55b6530, 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 systemd#9006.
  • Loading branch information
keszybz committed Jan 16, 2019
1 parent 0b189e8 commit dfbec57
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
7 changes: 7 additions & 0 deletions man/systemd.link.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,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>
Expand Down
2 changes: 1 addition & 1 deletion network/99-default.link
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 10 additions & 7 deletions src/udev/net/link-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_info(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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/udev/net/link-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef enum MACPolicy {

typedef enum NamePolicy {
NAMEPOLICY_KERNEL,
NAMEPOLICY_KEEP,
NAMEPOLICY_DATABASE,
NAMEPOLICY_ONBOARD,
NAMEPOLICY_SLOT,
Expand Down

0 comments on commit dfbec57

Please sign in to comment.