mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-08 21:17:47 +03:00
udev: introduce AlternativeNamesPolicy= setting
This commit is contained in:
parent
bb181dd4a6
commit
ef1d2c07f9
@ -356,6 +356,17 @@
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><varname>AlternativeNamesPolicy=</varname></term>
|
||||
<listitem>
|
||||
<para>A space-separated list of policies by which the interface's alternative names
|
||||
should be set. Each of the policies may fail, and all successful policies are used. The
|
||||
available policies are <literal>database</literal>, <literal>onboard</literal>,
|
||||
<literal>slot</literal>, <literal>path</literal>, and <literal>mac</literal>. If the
|
||||
kernel does not support the alternative names, then this setting will be ignored.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><varname>AlternativeName=</varname></term>
|
||||
<listitem>
|
||||
|
@ -19,40 +19,41 @@ struct ConfigPerfItem;
|
||||
%struct-type
|
||||
%includes
|
||||
%%
|
||||
Match.MACAddress, config_parse_hwaddrs, 0, offsetof(link_config, match_mac)
|
||||
Match.OriginalName, config_parse_match_ifnames, 0, offsetof(link_config, match_name)
|
||||
Match.Path, config_parse_match_strv, 0, offsetof(link_config, match_path)
|
||||
Match.Driver, config_parse_match_strv, 0, offsetof(link_config, match_driver)
|
||||
Match.Type, config_parse_match_strv, 0, offsetof(link_config, match_type)
|
||||
Match.Property, config_parse_match_property, 0, offsetof(link_config, match_property)
|
||||
Match.Host, config_parse_net_condition, CONDITION_HOST, offsetof(link_config, conditions)
|
||||
Match.Virtualization, config_parse_net_condition, CONDITION_VIRTUALIZATION, offsetof(link_config, conditions)
|
||||
Match.KernelCommandLine, config_parse_net_condition, CONDITION_KERNEL_COMMAND_LINE, offsetof(link_config, conditions)
|
||||
Match.KernelVersion, config_parse_net_condition, CONDITION_KERNEL_VERSION, offsetof(link_config, conditions)
|
||||
Match.Architecture, config_parse_net_condition, CONDITION_ARCHITECTURE, offsetof(link_config, conditions)
|
||||
Link.Description, config_parse_string, 0, offsetof(link_config, description)
|
||||
Link.MACAddressPolicy, config_parse_mac_address_policy, 0, offsetof(link_config, mac_address_policy)
|
||||
Link.MACAddress, config_parse_hwaddr, 0, offsetof(link_config, mac)
|
||||
Link.NamePolicy, config_parse_name_policy, 0, offsetof(link_config, name_policy)
|
||||
Link.Name, config_parse_ifname, 0, offsetof(link_config, name)
|
||||
Link.AlternativeName, config_parse_ifnames, 1, offsetof(link_config, alternative_names)
|
||||
Link.Alias, config_parse_ifalias, 0, offsetof(link_config, alias)
|
||||
Link.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(link_config, mtu)
|
||||
Link.BitsPerSecond, config_parse_si_size, 0, offsetof(link_config, speed)
|
||||
Link.Duplex, config_parse_duplex, 0, offsetof(link_config, duplex)
|
||||
Link.AutoNegotiation, config_parse_tristate, 0, offsetof(link_config, autonegotiation)
|
||||
Link.WakeOnLan, config_parse_wol, 0, offsetof(link_config, wol)
|
||||
Link.Port, config_parse_port, 0, offsetof(link_config, port)
|
||||
Link.GenericSegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_GSO])
|
||||
Link.TCPSegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_TSO])
|
||||
Link.TCP6SegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_TSO6])
|
||||
Link.UDPSegmentationOffload, config_parse_warn_compat, DISABLED_LEGACY, 0
|
||||
Link.GenericReceiveOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_GRO])
|
||||
Link.LargeReceiveOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_LRO])
|
||||
Link.RxChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
||||
Link.TxChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
||||
Link.OtherChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
||||
Link.CombinedChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
||||
Link.Advertise, config_parse_advertise, 0, offsetof(link_config, advertise)
|
||||
Link.RxBufferSize, config_parse_nic_buffer_size, 0, offsetof(link_config, ring)
|
||||
Link.TxBufferSize, config_parse_nic_buffer_size, 0, offsetof(link_config, ring)
|
||||
Match.MACAddress, config_parse_hwaddrs, 0, offsetof(link_config, match_mac)
|
||||
Match.OriginalName, config_parse_match_ifnames, 0, offsetof(link_config, match_name)
|
||||
Match.Path, config_parse_match_strv, 0, offsetof(link_config, match_path)
|
||||
Match.Driver, config_parse_match_strv, 0, offsetof(link_config, match_driver)
|
||||
Match.Type, config_parse_match_strv, 0, offsetof(link_config, match_type)
|
||||
Match.Property, config_parse_match_property, 0, offsetof(link_config, match_property)
|
||||
Match.Host, config_parse_net_condition, CONDITION_HOST, offsetof(link_config, conditions)
|
||||
Match.Virtualization, config_parse_net_condition, CONDITION_VIRTUALIZATION, offsetof(link_config, conditions)
|
||||
Match.KernelCommandLine, config_parse_net_condition, CONDITION_KERNEL_COMMAND_LINE, offsetof(link_config, conditions)
|
||||
Match.KernelVersion, config_parse_net_condition, CONDITION_KERNEL_VERSION, offsetof(link_config, conditions)
|
||||
Match.Architecture, config_parse_net_condition, CONDITION_ARCHITECTURE, offsetof(link_config, conditions)
|
||||
Link.Description, config_parse_string, 0, offsetof(link_config, description)
|
||||
Link.MACAddressPolicy, config_parse_mac_address_policy, 0, offsetof(link_config, mac_address_policy)
|
||||
Link.MACAddress, config_parse_hwaddr, 0, offsetof(link_config, mac)
|
||||
Link.NamePolicy, config_parse_name_policy, 0, offsetof(link_config, name_policy)
|
||||
Link.Name, config_parse_ifname, 0, offsetof(link_config, name)
|
||||
Link.AlternativeName, config_parse_ifnames, 1, offsetof(link_config, alternative_names)
|
||||
Link.AlternativeNamesPolicy, config_parse_alternative_names_policy, 0, offsetof(link_config, alternative_names_policy)
|
||||
Link.Alias, config_parse_ifalias, 0, offsetof(link_config, alias)
|
||||
Link.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(link_config, mtu)
|
||||
Link.BitsPerSecond, config_parse_si_size, 0, offsetof(link_config, speed)
|
||||
Link.Duplex, config_parse_duplex, 0, offsetof(link_config, duplex)
|
||||
Link.AutoNegotiation, config_parse_tristate, 0, offsetof(link_config, autonegotiation)
|
||||
Link.WakeOnLan, config_parse_wol, 0, offsetof(link_config, wol)
|
||||
Link.Port, config_parse_port, 0, offsetof(link_config, port)
|
||||
Link.GenericSegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_GSO])
|
||||
Link.TCPSegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_TSO])
|
||||
Link.TCP6SegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_TSO6])
|
||||
Link.UDPSegmentationOffload, config_parse_warn_compat, DISABLED_LEGACY, 0
|
||||
Link.GenericReceiveOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_GRO])
|
||||
Link.LargeReceiveOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_LRO])
|
||||
Link.RxChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
||||
Link.TxChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
||||
Link.OtherChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
||||
Link.CombinedChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
||||
Link.Advertise, config_parse_advertise, 0, offsetof(link_config, advertise)
|
||||
Link.RxBufferSize, config_parse_nic_buffer_size, 0, offsetof(link_config, ring)
|
||||
Link.TxBufferSize, config_parse_nic_buffer_size, 0, offsetof(link_config, ring)
|
||||
|
@ -59,6 +59,7 @@ static void link_config_free(link_config *link) {
|
||||
free(link->name_policy);
|
||||
free(link->name);
|
||||
strv_free(link->alternative_names);
|
||||
free(link->alternative_names_policy);
|
||||
free(link->alias);
|
||||
|
||||
free(link);
|
||||
@ -326,6 +327,7 @@ static int get_mac(sd_device *device, MACAddressPolicy policy, struct ether_addr
|
||||
|
||||
int link_config_apply(link_config_ctx *ctx, link_config *config,
|
||||
sd_device *device, const char **name) {
|
||||
_cleanup_strv_free_ char **altnames = NULL;
|
||||
struct ether_addr generated_mac;
|
||||
struct ether_addr *mac = NULL;
|
||||
const char *new_name = NULL;
|
||||
@ -461,11 +463,52 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
|
||||
if (r < 0)
|
||||
return log_warning_errno(r, "Could not set Alias=, MACAddress= or MTU= on %s: %m", old_name);
|
||||
|
||||
r = rtnl_set_link_alternative_names(&ctx->rtnl, ifindex, config->alternative_names);
|
||||
if (config->alternative_names) {
|
||||
altnames = strv_copy(config->alternative_names);
|
||||
if (!altnames)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
if (config->alternative_names_policy)
|
||||
for (NamePolicy *p = config->alternative_names_policy; *p != _NAMEPOLICY_INVALID; p++) {
|
||||
const char *n;
|
||||
|
||||
switch (*p) {
|
||||
case NAMEPOLICY_DATABASE:
|
||||
(void) sd_device_get_property_value(device, "ID_NET_NAME_FROM_DATABASE", &n);
|
||||
break;
|
||||
case NAMEPOLICY_ONBOARD:
|
||||
(void) sd_device_get_property_value(device, "ID_NET_NAME_ONBOARD", &n);
|
||||
break;
|
||||
case NAMEPOLICY_SLOT:
|
||||
(void) sd_device_get_property_value(device, "ID_NET_NAME_SLOT", &n);
|
||||
break;
|
||||
case NAMEPOLICY_PATH:
|
||||
(void) sd_device_get_property_value(device, "ID_NET_NAME_PATH", &n);
|
||||
break;
|
||||
case NAMEPOLICY_MAC:
|
||||
(void) sd_device_get_property_value(device, "ID_NET_NAME_MAC", &n);
|
||||
break;
|
||||
default:
|
||||
assert_not_reached("invalid policy");
|
||||
}
|
||||
if (!isempty(n)) {
|
||||
r = strv_extend(&altnames, n);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
}
|
||||
|
||||
if (new_name)
|
||||
strv_remove(altnames, new_name);
|
||||
strv_remove(altnames, old_name);
|
||||
strv_uniq(altnames);
|
||||
|
||||
r = rtnl_set_link_alternative_names(&ctx->rtnl, ifindex, altnames);
|
||||
if (r == -EOPNOTSUPP)
|
||||
log_debug_errno(r, "Could not set AlternativeName= on %s, ignoring: %m", old_name);
|
||||
log_debug_errno(r, "Could not set AlternativeName= or apply AlternativeNamesPolicy= on %s, ignoring: %m", old_name);
|
||||
else if (r < 0)
|
||||
return log_warning_errno(r, "Could not set AlternativeName= on %s: %m", old_name);
|
||||
return log_warning_errno(r, "Could not set AlternativeName= or apply AlternativeNamesPolicy= on %s: %m", old_name);
|
||||
|
||||
*name = new_name;
|
||||
|
||||
@ -513,3 +556,16 @@ DEFINE_STRING_TABLE_LOOKUP(name_policy, NamePolicy);
|
||||
DEFINE_CONFIG_PARSE_ENUMV(config_parse_name_policy, name_policy, NamePolicy,
|
||||
_NAMEPOLICY_INVALID,
|
||||
"Failed to parse interface name policy");
|
||||
|
||||
static const char* const alternative_names_policy_table[_NAMEPOLICY_MAX] = {
|
||||
[NAMEPOLICY_DATABASE] = "database",
|
||||
[NAMEPOLICY_ONBOARD] = "onboard",
|
||||
[NAMEPOLICY_SLOT] = "slot",
|
||||
[NAMEPOLICY_PATH] = "path",
|
||||
[NAMEPOLICY_MAC] = "mac",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(alternative_names_policy, NamePolicy);
|
||||
DEFINE_CONFIG_PARSE_ENUMV(config_parse_alternative_names_policy, alternative_names_policy, NamePolicy,
|
||||
_NAMEPOLICY_INVALID,
|
||||
"Failed to parse alternative names policy");
|
||||
|
@ -47,6 +47,7 @@ struct link_config {
|
||||
struct ether_addr *mac;
|
||||
MACAddressPolicy mac_address_policy;
|
||||
NamePolicy *name_policy;
|
||||
NamePolicy *alternative_names_policy;
|
||||
char *name;
|
||||
char **alternative_names;
|
||||
char *alias;
|
||||
@ -79,6 +80,9 @@ int link_get_driver(link_config_ctx *ctx, sd_device *device, char **ret);
|
||||
const char *name_policy_to_string(NamePolicy p) _const_;
|
||||
NamePolicy name_policy_from_string(const char *p) _pure_;
|
||||
|
||||
const char *alternative_names_policy_to_string(NamePolicy p) _const_;
|
||||
NamePolicy alternative_names_policy_from_string(const char *p) _pure_;
|
||||
|
||||
const char *mac_address_policy_to_string(MACAddressPolicy p) _const_;
|
||||
MACAddressPolicy mac_address_policy_from_string(const char *p) _pure_;
|
||||
|
||||
@ -87,3 +91,4 @@ const struct ConfigPerfItem* link_config_gperf_lookup(const char *key, GPERF_LEN
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_mac_address_policy);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_name_policy);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_alternative_names_policy);
|
||||
|
@ -16,6 +16,7 @@ MACAddressPolicy=
|
||||
MACAddress=
|
||||
NamePolicy=
|
||||
Name=
|
||||
AlternativeNamesPolicy=
|
||||
AlternativeName=
|
||||
Alias=
|
||||
MTUBytes=
|
||||
|
Loading…
Reference in New Issue
Block a user