mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 22:10:14 +01:00
bonding: add support to prio property in bond ports
Add per port priority support for bond active port re-selection during failover. A higher number means a higher priority in selection. The primary port still has the highest priority. This option is only compatible with active-backup, balance-tlb and balance-alb modes. (cherry picked from commit2f0571f193) (cherry picked from commit748f6388aa)
This commit is contained in:
parent
4fd186bbf6
commit
d36620e654
14 changed files with 146 additions and 15 deletions
|
|
@ -234,7 +234,12 @@ controller_update_port_connection(NMDevice *self,
|
|||
pllink = nm_platform_link_get(nm_device_get_platform(port), ifindex_port);
|
||||
|
||||
if (pllink && pllink->port_kind == NM_PORT_KIND_BOND)
|
||||
g_object_set(s_port, NM_SETTING_BOND_PORT_QUEUE_ID, pllink->port_data.bond.queue_id, NULL);
|
||||
g_object_set(s_port,
|
||||
NM_SETTING_BOND_PORT_QUEUE_ID,
|
||||
pllink->port_data.bond.queue_id,
|
||||
NM_SETTING_BOND_PORT_PRIO,
|
||||
pllink->port_data.bond.prio,
|
||||
NULL);
|
||||
|
||||
g_object_set(nm_connection_get_setting_connection(connection),
|
||||
NM_SETTING_CONNECTION_MASTER,
|
||||
|
|
@ -495,11 +500,52 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason)
|
|||
static void
|
||||
commit_port_options(NMDevice *bond_device, NMDevice *port, NMSettingBondPort *s_port)
|
||||
{
|
||||
nm_platform_link_change(
|
||||
nm_device_get_platform(port),
|
||||
nm_device_get_ifindex(port),
|
||||
&((NMPlatformLinkBondPort){.queue_id = s_port ? nm_setting_bond_port_get_queue_id(s_port)
|
||||
: NM_BOND_PORT_QUEUE_ID_DEF}));
|
||||
NMBondMode mode = NM_BOND_MODE_UNKNOWN;
|
||||
const char *value;
|
||||
NMSettingBond *s_bond;
|
||||
gint32 prio;
|
||||
gboolean prio_has;
|
||||
|
||||
s_bond = nm_device_get_applied_setting(bond_device, NM_TYPE_SETTING_BOND);
|
||||
if (s_bond) {
|
||||
value = nm_setting_bond_get_option_normalized(s_bond, NM_SETTING_BOND_OPTION_MODE);
|
||||
mode = _nm_setting_bond_mode_from_string(value);
|
||||
}
|
||||
|
||||
prio = s_port ? nm_setting_bond_port_get_prio(s_port) : NM_BOND_PORT_PRIO_DEF;
|
||||
|
||||
if (prio != 0) {
|
||||
/* The profile explicitly sets the priority. No matter what, we try to set it
|
||||
* in netlink. */
|
||||
prio_has = TRUE;
|
||||
} else if (!NM_IN_SET(mode, NM_BOND_MODE_ACTIVEBACKUP, NM_BOND_MODE_TLB, NM_BOND_MODE_ALB)) {
|
||||
/* The priority only is configurable with certain modes. If we don't have
|
||||
* one of those modes, don't try to set the priority explicitly to zero. */
|
||||
prio_has = FALSE;
|
||||
} else if (nm_platform_kernel_support_get_full(
|
||||
NM_PLATFORM_KERNEL_SUPPORT_TYPE_IFLA_BOND_SLAVE_PRIO,
|
||||
FALSE)
|
||||
== NM_OPTION_BOOL_TRUE) {
|
||||
/* We can only detect support if we have it. We cannot detect lack of support if
|
||||
* we don't have it.
|
||||
*
|
||||
* But we did explicitly detect support, so explicitly set the prio to zero. */
|
||||
prio_has = TRUE;
|
||||
} else {
|
||||
/* We either have an unsuitable mode or didn't detect kernel support for the
|
||||
* priority. Don't explicitly set priority to zero. It is already the default,
|
||||
* so it shouldn't be necessary. */
|
||||
prio_has = FALSE;
|
||||
}
|
||||
|
||||
nm_platform_link_change(nm_device_get_platform(port),
|
||||
nm_device_get_ifindex(port),
|
||||
&((NMPlatformLinkBondPort){
|
||||
.queue_id = s_port ? nm_setting_bond_port_get_queue_id(s_port)
|
||||
: NM_BOND_PORT_QUEUE_ID_DEF,
|
||||
.prio = prio_has ? prio : 0,
|
||||
.prio_has = prio_has,
|
||||
}));
|
||||
}
|
||||
|
||||
static NMTernary
|
||||
|
|
|
|||
|
|
@ -5557,6 +5557,7 @@ make_bond_port_setting(shvarFile *ifcfg)
|
|||
gs_free char *value_to_free = NULL;
|
||||
const char *value;
|
||||
guint queue_id;
|
||||
gint32 prio;
|
||||
|
||||
g_return_val_if_fail(ifcfg != NULL, FALSE);
|
||||
|
||||
|
|
@ -5565,11 +5566,23 @@ make_bond_port_setting(shvarFile *ifcfg)
|
|||
s_port = nm_setting_bond_port_new();
|
||||
queue_id =
|
||||
_nm_utils_ascii_str_to_uint64(value, 10, 0, G_MAXUINT16, NM_BOND_PORT_QUEUE_ID_DEF);
|
||||
if (errno != 0) {
|
||||
PARSE_WARNING("Invalid bond port queue_id value '%s'", value);
|
||||
return s_port;
|
||||
}
|
||||
g_object_set(G_OBJECT(s_port), NM_SETTING_BOND_PORT_QUEUE_ID, queue_id, NULL);
|
||||
if (errno != 0)
|
||||
PARSE_WARNING("Invalid bond port queue_id value BOND_PORT_QUEUE_ID '%s'", value);
|
||||
else
|
||||
g_object_set(G_OBJECT(s_port), NM_SETTING_BOND_PORT_QUEUE_ID, queue_id, NULL);
|
||||
}
|
||||
|
||||
nm_clear_g_free(&value_to_free);
|
||||
value = svGetValue(ifcfg, "BOND_PORT_PRIO", &value_to_free);
|
||||
if (value) {
|
||||
if (!s_port)
|
||||
s_port = nm_setting_bond_port_new();
|
||||
prio =
|
||||
_nm_utils_ascii_str_to_int64(value, 10, G_MININT32, G_MAXINT32, NM_BOND_PORT_PRIO_DEF);
|
||||
if (errno != 0)
|
||||
PARSE_WARNING("Invalid bond port prio value BOND_PORT_PRIO '%s'", value);
|
||||
else
|
||||
g_object_set(G_OBJECT(s_port), NM_SETTING_BOND_PORT_PRIO, prio, NULL);
|
||||
}
|
||||
|
||||
return s_port;
|
||||
|
|
|
|||
|
|
@ -827,6 +827,7 @@ const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[] = {
|
|||
_KEY_TYPE("BAND", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
|
||||
_KEY_TYPE("BONDING_MASTER", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
|
||||
_KEY_TYPE("BONDING_OPTS", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
|
||||
_KEY_TYPE("BOND_PORT_PRIO", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
|
||||
_KEY_TYPE("BOND_PORT_QUEUE_ID", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
|
||||
_KEY_TYPE("BOOTPROTO", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
|
||||
_KEY_TYPE("BRIDGE", NMS_IFCFG_KEY_TYPE_IS_PLAIN),
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ typedef struct {
|
|||
NMSIfcfgKeyTypeFlags key_flags;
|
||||
} NMSIfcfgKeyTypeInfo;
|
||||
|
||||
extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[256];
|
||||
extern const NMSIfcfgKeyTypeInfo nms_ifcfg_well_known_keys[257];
|
||||
|
||||
const NMSIfcfgKeyTypeInfo *nms_ifcfg_well_known_key_find_info(const char *key, gssize *out_idx);
|
||||
|
||||
|
|
|
|||
|
|
@ -1910,8 +1910,10 @@ write_bond_port_setting(NMConnection *connection, shvarFile *ifcfg)
|
|||
NMSettingBondPort *s_port;
|
||||
|
||||
s_port = _nm_connection_get_setting(connection, NM_TYPE_SETTING_BOND_PORT);
|
||||
if (s_port)
|
||||
if (s_port) {
|
||||
svSetValueInt64(ifcfg, "BOND_PORT_QUEUE_ID", nm_setting_bond_port_get_queue_id(s_port));
|
||||
svSetValueInt64(ifcfg, "BOND_PORT_PRIO", nm_setting_bond_port_get_prio(s_port));
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
|
|
@ -8325,6 +8325,7 @@ test_write_bond_port(void)
|
|||
|
||||
s_bond_port = _nm_connection_new_setting(connection, NM_TYPE_SETTING_BOND_PORT);
|
||||
g_object_set(s_bond_port, NM_SETTING_BOND_PORT_QUEUE_ID, 1, NULL);
|
||||
g_object_set(s_bond_port, NM_SETTING_BOND_PORT_PRIO, 10, NULL);
|
||||
|
||||
nmtst_assert_connection_verifies(connection);
|
||||
|
||||
|
|
|
|||
|
|
@ -392,6 +392,7 @@ typedef struct {
|
|||
/****************************************************************************/
|
||||
|
||||
#define NM_BOND_PORT_QUEUE_ID_DEF 0
|
||||
#define NM_BOND_PORT_PRIO_DEF 0
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -1878,3 +1878,8 @@ global:
|
|||
nm_utils_ip_routes_to_variant;
|
||||
nm_vpn_plugin_info_supports_multiple;
|
||||
} libnm_1_40_0;
|
||||
|
||||
libnm_1_40_20_bondp {
|
||||
global:
|
||||
nm_setting_bond_port_get_prio;
|
||||
} libnm_1_40_0;
|
||||
|
|
|
|||
|
|
@ -97,8 +97,10 @@ def syms_from_ver(verfile):
|
|||
):
|
||||
c_syms[str_removesuffix(line, ";")] = version
|
||||
|
||||
# This one is... messy.
|
||||
# These are exceptions and we cannot know the version for the symbol so we
|
||||
# harcode it.
|
||||
c_syms["nm_ethtool_optname_is_feature"] = "1.20"
|
||||
c_syms["nm_setting_bond_port_get_prio"] = "1.44"
|
||||
|
||||
return c_syms
|
||||
|
||||
|
|
|
|||
|
|
@ -22,9 +22,10 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
NM_GOBJECT_PROPERTIES_DEFINE(NMSettingBondPort, PROP_QUEUE_ID, );
|
||||
NM_GOBJECT_PROPERTIES_DEFINE(NMSettingBondPort, PROP_QUEUE_ID, PROP_PRIO, );
|
||||
|
||||
typedef struct {
|
||||
gint32 prio;
|
||||
guint32 queue_id;
|
||||
} NMSettingBondPortPrivate;
|
||||
|
||||
|
|
@ -65,6 +66,22 @@ nm_setting_bond_port_get_queue_id(NMSettingBondPort *setting)
|
|||
return NM_SETTING_BOND_PORT_GET_PRIVATE(setting)->queue_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_bond_port_get_prio:
|
||||
* @setting: the #NMSettingBondPort
|
||||
*
|
||||
* Returns: the #NMSettingBondPort:prio property of the setting
|
||||
*
|
||||
* Since: 1.44, 1.42.8, 1.40.20
|
||||
**/
|
||||
gint32
|
||||
nm_setting_bond_port_get_prio(NMSettingBondPort *setting)
|
||||
{
|
||||
g_return_val_if_fail(NM_IS_SETTING_BOND_PORT(setting), 0);
|
||||
|
||||
return NM_SETTING_BOND_PORT_GET_PRIVATE(setting)->prio;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
|
|
@ -165,6 +182,35 @@ nm_setting_bond_port_class_init(NMSettingBondPortClass *klass)
|
|||
NMSettingBondPort,
|
||||
_priv.queue_id);
|
||||
|
||||
/**
|
||||
* NMSettingBondPort:prio:
|
||||
*
|
||||
* The port priority for bond active port re-selection during failover. A
|
||||
* higher number means a higher priority in selection. The primary port has
|
||||
* the highest priority. This option is only compatible with active-backup,
|
||||
* balance-tlb and balance-alb modes.
|
||||
*
|
||||
* Since: 1.44, 1.42.8, 1.40.20
|
||||
**/
|
||||
/* ---ifcfg-rh---
|
||||
* property: prio
|
||||
* variable: BOND_PORT_PRIO(+)
|
||||
* values: -2147483648 - 2147483647
|
||||
* default: 0
|
||||
* description: Port priority.
|
||||
* ---end---
|
||||
*/
|
||||
_nm_setting_property_define_direct_int32(properties_override,
|
||||
obj_properties,
|
||||
NM_SETTING_BOND_PORT_PRIO,
|
||||
PROP_PRIO,
|
||||
G_MININT32,
|
||||
G_MAXINT32,
|
||||
NM_BOND_PORT_PRIO_DEF,
|
||||
NM_SETTING_PARAM_INFERRABLE,
|
||||
NMSettingBondPort,
|
||||
_priv.prio);
|
||||
|
||||
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
||||
|
||||
_nm_setting_class_commit(setting_class,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ G_BEGIN_DECLS
|
|||
#define NM_SETTING_BOND_PORT_SETTING_NAME "bond-port"
|
||||
|
||||
#define NM_SETTING_BOND_PORT_QUEUE_ID "queue-id"
|
||||
#define NM_SETTING_BOND_PORT_PRIO "prio"
|
||||
|
||||
typedef struct _NMSettingBondPortClass NMSettingBondPortClass;
|
||||
|
||||
|
|
@ -41,6 +42,9 @@ NMSetting *nm_setting_bond_port_new(void);
|
|||
NM_AVAILABLE_IN_1_34
|
||||
guint32 nm_setting_bond_port_get_queue_id(NMSettingBondPort *setting);
|
||||
|
||||
NM_AVAILABLE_IN_1_40_20
|
||||
gint32 nm_setting_bond_port_get_prio(NMSettingBondPort *setting);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __NM_SETTING_BOND_PORT_H__ */
|
||||
|
|
|
|||
|
|
@ -5154,6 +5154,12 @@ static const NMMetaPropertyInfo *const property_infos_BOND_PORT[] = {
|
|||
.prompt = N_("Queue ID"),
|
||||
.property_type = &_pt_gobject_int,
|
||||
),
|
||||
PROPERTY_INFO_WITH_DESC (NM_SETTING_BOND_PORT_PRIO,
|
||||
.is_cli_option = TRUE,
|
||||
.property_alias = "prio",
|
||||
.prompt = N_("Port Priority"),
|
||||
.property_type= &_pt_gobject_int,
|
||||
),
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -426,6 +426,7 @@
|
|||
#define DESCRIBE_DOC_NM_SETTING_WPAN_PAGE N_("IEEE 802.15.4 channel page. A positive integer or -1, meaning \"do not set, use whatever the device is already set to\".")
|
||||
#define DESCRIBE_DOC_NM_SETTING_WPAN_PAN_ID N_("IEEE 802.15.4 Personal Area Network (PAN) identifier.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_WPAN_SHORT_ADDRESS N_("Short IEEE 802.15.4 address to be used within a restricted environment.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_BOND_PORT_PRIO N_("The port priority for bond active port re-selection during failover. A higher number means a higher priority in selection. The primary port has the highest priority. This option is only compatible with active-backup, balance-tlb and balance-alb modes.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_BOND_PORT_QUEUE_ID N_("The queue ID of this bond port. The maximum value of queue ID is the number of TX queues currently active in device.")
|
||||
#define DESCRIBE_DOC_NM_SETTING_HOSTNAME_FROM_DHCP N_("Whether the system hostname can be determined from DHCP on this connection. When set to NM_TERNARY_DEFAULT (-1), the value from global configuration is used. If the property doesn't have a value in the global configuration, NetworkManager assumes the value to be NM_TERNARY_TRUE (1).")
|
||||
#define DESCRIBE_DOC_NM_SETTING_HOSTNAME_FROM_DNS_LOOKUP N_("Whether the system hostname can be determined from reverse DNS lookup of addresses on this device. When set to NM_TERNARY_DEFAULT (-1), the value from global configuration is used. If the property doesn't have a value in the global configuration, NetworkManager assumes the value to be NM_TERNARY_TRUE (1).")
|
||||
|
|
|
|||
|
|
@ -271,6 +271,9 @@
|
|||
<property name="queue-id"
|
||||
alias="queue-id"
|
||||
description="The queue ID of this bond port. The maximum value of queue ID is the number of TX queues currently active in device." />
|
||||
<property name="prio"
|
||||
alias="prio"
|
||||
description="The port priority for bond active port re-selection during failover. A higher number means a higher priority in selection. The primary port has the highest priority. This option is only compatible with active-backup, balance-tlb and balance-alb modes." />
|
||||
</setting>
|
||||
<setting name="bridge" >
|
||||
<property name="mac-address"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue