device: deprecate "bridge.mac-address" for "ethernet.cloned-mac-address" setting

The settings "bridge.mac-address" and "ethernet.cloned-mac-address" have an
overlapping meaning. If the former is unset, fallback to the latter.

Effectively, "bridge.mac-address" is deprecated in favor of
"ethernet.cloned-mac-address", which is more powerful as it supports
various modes like "stable". However, if a connection specifies
"bridge.mac-address", it is used when creating the bridge interface,
while "ethernet.cloned-mac-address" is used shortly after, during
activation.
This commit is contained in:
Thomas Haller
2017-07-25 13:15:15 +02:00
parent 459e76bdfe
commit 51e1215c85
2 changed files with 22 additions and 5 deletions

View File

@@ -392,8 +392,13 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *setting_class)
* NMSettingBridge:mac-address: * NMSettingBridge:mac-address:
* *
* If specified, the MAC address of bridge. When creating a new bridge, this * If specified, the MAC address of bridge. When creating a new bridge, this
* MAC address will be set. When matching an existing (outside * MAC address will be set.
* NetworkManager created) bridge, this MAC address must match. *
* If this field is left unspecified, the "ethernet.cloned-mac-address" is
* referred instead to generate the initial MAC address. Note that setting
* "ethernet.cloned-mac-address" anyway overwrites the MAC address of
* the bridge later while activating the bridge. Hence, this property
* is deprecated.
**/ **/
/* ---keyfile--- /* ---keyfile---
* property: mac-address * property: mac-address

View File

@@ -433,20 +433,32 @@ create_and_realize (NMDevice *device,
NMSettingBridge *s_bridge; NMSettingBridge *s_bridge;
const char *iface = nm_device_get_iface (device); const char *iface = nm_device_get_iface (device);
const char *hwaddr; const char *hwaddr;
gs_free char *hwaddr_cloned = NULL;
guint8 mac_address[NM_UTILS_HWADDR_LEN_MAX]; guint8 mac_address[NM_UTILS_HWADDR_LEN_MAX];
NMPlatformError plerr; NMPlatformError plerr;
g_assert (iface); nm_assert (iface);
s_bridge = nm_connection_get_setting_bridge (connection); s_bridge = nm_connection_get_setting_bridge (connection);
g_assert (s_bridge); nm_assert (s_bridge);
hwaddr = nm_setting_bridge_get_mac_address (s_bridge); hwaddr = nm_setting_bridge_get_mac_address (s_bridge);
if ( !hwaddr
&& nm_device_hw_addr_get_cloned (device, connection, FALSE,
&hwaddr_cloned, NULL, NULL)) {
/* The cloned MAC address might by dynamic, for example with stable-id="${RANDOM}".
* It's a bit odd that we first create the device with one dynamic address,
* and later on may reset it to another. That is, because we don't cache
* the dynamic address in @device, like we do during nm_device_hw_addr_set_cloned(). */
hwaddr = hwaddr_cloned;
}
if (hwaddr) { if (hwaddr) {
if (!nm_utils_hwaddr_aton (hwaddr, mac_address, ETH_ALEN)) { if (!nm_utils_hwaddr_aton (hwaddr, mac_address, ETH_ALEN)) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
"Invalid hardware address '%s'", "Invalid hardware address '%s'",
hwaddr); hwaddr);
return FALSE; g_return_val_if_reached (FALSE);
} }
} }