mirror of
https://github.com/systemd/systemd.git
synced 2024-10-31 16:21:26 +03:00
Merge pull request #12807 from keszybz/net-naming-scheme-yet-again
Extend naming scheme to mac address policy and introduce NAMING_STABLE_VIRTUAL_MACS
This commit is contained in:
commit
b337d89c68
@ -22,29 +22,30 @@
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
||||
<para>Network interfaces may be renamed to give them predictable names when there's enough information to
|
||||
generate appropriate names and the use of certain types of names is configured. This page describes the
|
||||
first part, i.e. what possible names may be generated. Those names are generated by the
|
||||
<para>Network interfaces names and MAC addresses may be generated based on certain stable interface
|
||||
attributes. This is possible when there is enough information about the device to generate those
|
||||
attributes and the use of this information is configured. This page describes interface naming, i.e. what
|
||||
possible names may be generated. Those names are generated by the
|
||||
<citerefentry><refentrytitle>systemd-udevd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
|
||||
builtin <command>net_id</command> and exported as udev properties
|
||||
(<varname>ID_NET_NAME_ONBOARD=</varname>, <varname>ID_NET_LABEL_ONBOARD=</varname>,
|
||||
<varname>ID_NET_NAME_PATH=</varname>, <varname>ID_NET_NAME_SLOT=</varname>).</para>
|
||||
|
||||
<para>Names are derived from various device metadata attributes. Newer versions of udev take more of
|
||||
these attributes into account, improving (and thus possibly changing) the names used for the same
|
||||
devices. Differents version of the naming rules are called "naming schemes". The default naming scheme is
|
||||
chosen at compilation time. Usually this will be the latest implemented version, but it is also possible
|
||||
to set one of the older versions to preserve compatibility. This may be useful for example for
|
||||
distributions, which may introduce new versions of systemd in stable releases without changing the naming
|
||||
scheme. The naming scheme may also be overriden using the <varname>net.naming-scheme=</varname> kernel
|
||||
command line switch, see
|
||||
<para>Names and MAC addresses are derived from various stable device metadata attributes. Newer versions
|
||||
of udev take more of these attributes into account, improving (and thus possibly changing) the names and
|
||||
addresses used for the same devices. Different versions of those generation rules are called "naming
|
||||
schemes". The default naming scheme is chosen at compilation time. Usually this will be the latest
|
||||
implemented version, but it is also possible to set one of the older versions to preserve
|
||||
compatibility. This may be useful for example for distributions, which may introduce new versions of
|
||||
systemd in stable releases without changing the naming scheme. The naming scheme may also be overriden
|
||||
using the <varname>net.naming-scheme=</varname> kernel command line switch, see
|
||||
<citerefentry><refentrytitle>systemd-udevd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
|
||||
Available naming schemes are described below.</para>
|
||||
|
||||
<para>After the udev proprties have been generated, appropriate udev rules may be used to actually rename
|
||||
devices based on those properties. See the description of <varname>NamePolicy=</varname> in
|
||||
<citerefentry><refentrytitle>systemd.link</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
|
||||
</para>
|
||||
devices based on those properties. See the description of <varname>NamePolicy=</varname> and
|
||||
<varname>MACAddressPolicy=</varname> in
|
||||
<citerefentry><refentrytitle>systemd.link</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
@ -288,7 +289,7 @@
|
||||
<varlistentry>
|
||||
<term><constant>v240</constant></term>
|
||||
|
||||
<para>The <literal>ib</literal> prefix and stable names for infiniband devices are
|
||||
<listitem><para>The <literal>ib</literal> prefix and stable names for infiniband devices are
|
||||
introduced. Previously those devices were not renamed.</para>
|
||||
|
||||
<para>The ACPI index field (used in <varname>ID_NET_NAME_ONBOARD=</varname>) is now also used when
|
||||
@ -301,22 +302,37 @@
|
||||
configuration, even if they have been renamed already, if <constant>keep</constant> is not
|
||||
specified as the naming policy in the <filename noindex='true'>.link</filename> file. See
|
||||
<citerefentry><refentrytitle>systemd.link</refentrytitle><manvolnum>5</manvolnum></citerefentry>
|
||||
for a description of <varname>NamePolicy=</varname>.</para>
|
||||
for a description of <varname>NamePolicy=</varname>.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><constant>v241</constant></term>
|
||||
|
||||
<listitem><para><option>MACAddressPolicy=persistent</option> was extended to set MAC addresses
|
||||
based on the device name. Previously addresses were only based on the
|
||||
<varname noindex='true'>ID_NET_NAME_*</varname> attributes, which meant that interface names would
|
||||
never be generated for virtual devices. Now a persistent address will be generated for most
|
||||
devices, including in particular bridges.</para>
|
||||
|
||||
<para>Note: when userspace does not set a MAC address for a bridge device, the kernel will
|
||||
initially assign a random address, and then change it when the first device is enslaved to the
|
||||
bridge. With this naming policy change, bridges get a persistent MAC address based on the bridge
|
||||
name instead of the first enslaved device.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><constant>v243</constant></term>
|
||||
|
||||
<para>Support for netdevsim (simulated networking devices) was added. Previously those devices were
|
||||
not renamed.</para>
|
||||
<listitem><para>Support for renaming netdevsim (simulated networking) devices was added. Previously
|
||||
those devices were not renamed.</para>
|
||||
|
||||
<para>Previously two-letter interface type prefix was prepended to
|
||||
<varname>ID_NET_LABEL_ONBOARD=</varname>. This is not done anymore.</para>
|
||||
<varname>ID_NET_LABEL_ONBOARD=</varname>. This is not done anymore.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<para>Note that <constant>latest</constant> may be used to denote the latest scheme known (to this
|
||||
particular version of systemd.</para>
|
||||
</variablelist>
|
||||
|
||||
<para>Note that <constant>latest</constant> may be used to denote the latest scheme known (to this
|
||||
particular version of systemd.</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
@ -190,7 +190,7 @@ int dhcp_identifier_set_iaid(
|
||||
/* device is under renaming */
|
||||
return -EBUSY;
|
||||
|
||||
name = net_get_name(device);
|
||||
name = net_get_name_persistent(device);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "utf8.h"
|
||||
#include "util.h"
|
||||
|
||||
const char *net_get_name(sd_device *device) {
|
||||
const char *net_get_name_persistent(sd_device *device) {
|
||||
const char *name, *field;
|
||||
|
||||
assert(device);
|
||||
@ -39,7 +39,7 @@ const char *net_get_name(sd_device *device) {
|
||||
|
||||
#define HASH_KEY SD_ID128_MAKE(d3,1e,48,fa,90,fe,4b,4c,9d,af,d5,d7,a1,b1,2e,8a)
|
||||
|
||||
int net_get_unique_predictable_data(sd_device *device, uint64_t *result) {
|
||||
int net_get_unique_predictable_data(sd_device *device, bool use_sysname, uint64_t *result) {
|
||||
size_t l, sz = 0;
|
||||
const char *name;
|
||||
int r;
|
||||
@ -47,10 +47,10 @@ int net_get_unique_predictable_data(sd_device *device, uint64_t *result) {
|
||||
|
||||
assert(device);
|
||||
|
||||
/* net_get_name() will return one of the device names based on stable information about the
|
||||
* device. If this is not available, we fall back to using the device name. */
|
||||
name = net_get_name(device);
|
||||
if (!name)
|
||||
/* net_get_name_persistent() will return one of the device names based on stable information about
|
||||
* the device. If this is not available, we fall back to using the actual device name. */
|
||||
name = net_get_name_persistent(device);
|
||||
if (!name && use_sysname)
|
||||
(void) sd_device_get_sysname(device, &name);
|
||||
if (!name)
|
||||
return log_device_debug_errno(device, SYNTHETIC_ERRNO(ENODATA),
|
||||
|
@ -32,8 +32,8 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ifnames);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ifalias);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_bridge_port_priority);
|
||||
|
||||
int net_get_unique_predictable_data(sd_device *device, uint64_t *result);
|
||||
const char *net_get_name(sd_device *device);
|
||||
int net_get_unique_predictable_data(sd_device *device, bool use_sysname, uint64_t *result);
|
||||
const char *net_get_name_persistent(sd_device *device);
|
||||
|
||||
size_t serialize_in_addrs(FILE *f,
|
||||
const struct in_addr *addresses,
|
||||
|
@ -210,7 +210,7 @@ int ipv4ll_configure(Link *link) {
|
||||
}
|
||||
|
||||
if (link->sd_device &&
|
||||
net_get_unique_predictable_data(link->sd_device, &seed) >= 0) {
|
||||
net_get_unique_predictable_data(link->sd_device, true, &seed) >= 0) {
|
||||
r = sd_ipv4ll_set_address_seed(link->ipv4ll, seed);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -318,10 +318,13 @@ static int get_mac(sd_device *device, MACAddressPolicy policy, struct ether_addr
|
||||
} else {
|
||||
uint64_t result;
|
||||
|
||||
r = net_get_unique_predictable_data(device, &result);
|
||||
r = net_get_unique_predictable_data(device,
|
||||
naming_scheme_has(NAMING_STABLE_VIRTUAL_MACS),
|
||||
&result);
|
||||
if (r < 0)
|
||||
return log_device_warning_errno(device, r, "Could not generate persistent MAC: %m");
|
||||
|
||||
log_device_debug(device, "Using generated persistent MAC address");
|
||||
assert_cc(ETH_ALEN <= sizeof(result));
|
||||
memcpy(mac->ether_addr_octet, &result, ETH_ALEN);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ static const NamingScheme naming_schemes[] = {
|
||||
{ "v238", NAMING_V238 },
|
||||
{ "v239", NAMING_V239 },
|
||||
{ "v240", NAMING_V240 },
|
||||
{ "v241", NAMING_V241 },
|
||||
{ "v243", NAMING_V243 },
|
||||
/* … add more schemes here, as the logic to name devices is updated … */
|
||||
};
|
||||
|
@ -22,19 +22,21 @@
|
||||
* OS versions, but not fully stabilize them. */
|
||||
typedef enum NamingSchemeFlags {
|
||||
/* First, the individual features */
|
||||
NAMING_SR_IOV_V = 1 << 0, /* Use "v" suffix for SR-IOV, see 609948c7043a40008b8299529c978ed8e11de8f6*/
|
||||
NAMING_NPAR_ARI = 1 << 1, /* Use NPAR "ARI", see 6bc04997b6eab35d1cb9fa73889892702c27be09 */
|
||||
NAMING_INFINIBAND = 1 << 2, /* Use "ib" prefix for infiniband, see 938d30aa98df887797c9e05074a562ddacdcdf5e */
|
||||
NAMING_ZERO_ACPI_INDEX = 1 << 3, /* Use zero acpi_index field, see d81186ef4f6a888a70f20a1e73a812d6acb9e22f */
|
||||
NAMING_ALLOW_RERENAMES = 1 << 4, /* Allow re-renaming of devices, see #9006 */
|
||||
NAMING_NETDEVSIM = 1 << 5, /* Generate names for netdevsim devices, see eaa9d507d85509c8bf727356e3884ec54b0fc646 */
|
||||
NAMING_LABEL_NOPREFIX = 1 << 6, /* Don't prepend ID_NET_LABEL_ONBOARD with interface type prefix */
|
||||
NAMING_SR_IOV_V = 1 << 0, /* Use "v" suffix for SR-IOV, see 609948c7043a */
|
||||
NAMING_NPAR_ARI = 1 << 1, /* Use NPAR "ARI", see 6bc04997b6ea */
|
||||
NAMING_INFINIBAND = 1 << 2, /* Use "ib" prefix for infiniband, see 938d30aa98df */
|
||||
NAMING_ZERO_ACPI_INDEX = 1 << 3, /* Use zero acpi_index field, see d81186ef4f6a */
|
||||
NAMING_ALLOW_RERENAMES = 1 << 4, /* Allow re-renaming of devices, see #9006 */
|
||||
NAMING_STABLE_VIRTUAL_MACS = 1 << 5, /* Use device name to generate MAC, see 6d3646406560 */
|
||||
NAMING_NETDEVSIM = 1 << 6, /* Generate names for netdevsim devices, see eaa9d507d855 */
|
||||
NAMING_LABEL_NOPREFIX = 1 << 7, /* Don't prepend ID_NET_LABEL_ONBOARD with interface type prefix */
|
||||
|
||||
/* And now the masks that combine the features above */
|
||||
NAMING_V238 = 0,
|
||||
NAMING_V239 = NAMING_V238 | NAMING_SR_IOV_V | NAMING_NPAR_ARI,
|
||||
NAMING_V240 = NAMING_V239 | NAMING_INFINIBAND | NAMING_ZERO_ACPI_INDEX | NAMING_ALLOW_RERENAMES,
|
||||
NAMING_V243 = NAMING_V240 | NAMING_NETDEVSIM | NAMING_LABEL_NOPREFIX,
|
||||
NAMING_V241 = NAMING_V240 | NAMING_STABLE_VIRTUAL_MACS,
|
||||
NAMING_V243 = NAMING_V241 | NAMING_NETDEVSIM | NAMING_LABEL_NOPREFIX,
|
||||
|
||||
_NAMING_SCHEME_FLAGS_INVALID = -1,
|
||||
} NamingSchemeFlags;
|
||||
|
Loading…
Reference in New Issue
Block a user