|
Packit Service |
87a54e |
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
Packit |
5756e2 |
/*
|
|
Packit |
5756e2 |
* Copyright (C) 2011 - 2013 Red Hat, Inc.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-default.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-setting-bond.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include <stdlib.h>
|
|
Packit |
5756e2 |
#include <netinet/in.h>
|
|
Packit |
5756e2 |
#include <arpa/inet.h>
|
|
Packit Service |
d0b836 |
#include <linux/if_ether.h>
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-libnm-core-intern/nm-libnm-core-utils.h"
|
|
Packit |
5756e2 |
#include "nm-utils.h"
|
|
Packit |
5756e2 |
#include "nm-utils-private.h"
|
|
Packit |
5756e2 |
#include "nm-connection-private.h"
|
|
Packit |
5756e2 |
#include "nm-setting-infiniband.h"
|
|
Packit |
5756e2 |
#include "nm-core-internal.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* SECTION:nm-setting-bond
|
|
Packit |
5756e2 |
* @short_description: Describes connection properties for bonds
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* The #NMSettingBond object is a #NMSetting subclass that describes properties
|
|
Packit |
5756e2 |
* necessary for bond connections.
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NM_GOBJECT_PROPERTIES_DEFINE(NMSettingBond, PROP_OPTIONS, );
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct {
|
|
Packit Service |
a1bd4f |
GHashTable * options;
|
|
Packit Service |
a1bd4f |
NMUtilsNamedValue *options_idx_cache;
|
|
Packit |
5756e2 |
} NMSettingBondPrivate;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
G_DEFINE_TYPE(NMSettingBond, nm_setting_bond, NM_TYPE_SETTING)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NM_SETTING_BOND_GET_PRIVATE(o) \
|
|
Packit Service |
a1bd4f |
(G_TYPE_INSTANCE_GET_PRIVATE((o), NM_TYPE_SETTING_BOND, NMSettingBondPrivate))
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static const char *const valid_options_lst[] = {
|
|
Packit Service |
a1bd4f |
/* mode must be the first element. nm-device-bond.c relies on that. */
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_MODE,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_MIIMON,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_DOWNDELAY,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_UPDELAY,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ARP_INTERVAL,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ARP_IP_TARGET,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ARP_VALIDATE,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_PRIMARY,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_PRIMARY_RESELECT,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_FAIL_OVER_MAC,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_USE_CARRIER,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_AD_SELECT,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_XMIT_HASH_POLICY,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_RESEND_IGMP,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_LACP_RATE,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ACTIVE_SLAVE,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_AD_ACTOR_SYS_PRIO,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_AD_USER_PORT_KEY,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ALL_SLAVES_ACTIVE,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ARP_ALL_TARGETS,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_MIN_LINKS,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_NUM_GRAT_ARP,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_NUM_UNSOL_NA,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_PACKETS_PER_SLAVE,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_TLB_DYNAMIC_LB,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_LP_INTERVAL,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct {
|
|
Packit Service |
a1bd4f |
const char * val;
|
|
Packit Service |
a1bd4f |
NMBondOptionType opt_type;
|
|
Packit Service |
a1bd4f |
guint min;
|
|
Packit Service |
a1bd4f |
guint max;
|
|
Packit Service |
a1bd4f |
const char *const *list;
|
|
Packit |
5756e2 |
} OptionMeta;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
_nm_assert_bond_meta(const OptionMeta *option_meta)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (option_meta->opt_type) {
|
|
Packit Service |
a1bd4f |
case NM_BOND_OPTION_TYPE_BOTH:
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta->val);
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta->list);
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta->list[0]);
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta->min == 0);
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta->max == NM_PTRARRAY_LEN(option_meta->list) - 1);
|
|
Packit Service |
a1bd4f |
nm_assert(g_strv_contains(option_meta->list, option_meta->val));
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit Service |
a1bd4f |
case NM_BOND_OPTION_TYPE_INT:
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta->val);
|
|
Packit Service |
a1bd4f |
nm_assert(!option_meta->list);
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta->min < option_meta->max);
|
|
Packit Service |
a1bd4f |
nm_assert(NM_STRCHAR_ALL(option_meta->val, ch, g_ascii_isdigit(ch)));
|
|
Packit Service |
a1bd4f |
nm_assert(NM_STRCHAR_ALL(option_meta->val, ch, g_ascii_isdigit(ch)));
|
|
Packit Service |
a1bd4f |
nm_assert(({
|
|
Packit Service |
a1bd4f |
_nm_utils_ascii_str_to_uint64(option_meta->val,
|
|
Packit Service |
a1bd4f |
10,
|
|
Packit Service |
a1bd4f |
option_meta->min,
|
|
Packit Service |
a1bd4f |
option_meta->max,
|
|
Packit Service |
a1bd4f |
0);
|
|
Packit Service |
a1bd4f |
errno == 0;
|
|
Packit Service |
a1bd4f |
}));
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit Service |
a1bd4f |
case NM_BOND_OPTION_TYPE_IP:
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta->val);
|
|
Packit Service |
a1bd4f |
/* fall-through */
|
|
Packit Service |
a1bd4f |
case NM_BOND_OPTION_TYPE_IFNAME:
|
|
Packit Service |
a1bd4f |
case NM_BOND_OPTION_TYPE_MAC:
|
|
Packit Service |
a1bd4f |
nm_assert(!option_meta->list);
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta->min == 0);
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta->max == 0);
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nm_assert_not_reached();
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
static char const *const _option_default_strv_ad_select[] =
|
|
Packit Service |
a1bd4f |
NM_MAKE_STRV("stable", "bandwidth", "count");
|
|
Packit Service |
a1bd4f |
static char const *const _option_default_strv_arp_all_targets[] = NM_MAKE_STRV("any", "all");
|
|
Packit Service |
a1bd4f |
static char const *const _option_default_strv_arp_validate[] =
|
|
Packit Service |
a1bd4f |
NM_MAKE_STRV("none", "active", "backup", "all", "filter", "filter_active", "filter_backup");
|
|
Packit Service |
a1bd4f |
static char const *const _option_default_strv_fail_over_mac[] =
|
|
Packit Service |
a1bd4f |
NM_MAKE_STRV("none", "active", "follow");
|
|
Packit Service |
a1bd4f |
static char const *const _option_default_strv_lacp_rate[] = NM_MAKE_STRV("slow", "fast");
|
|
Packit Service |
a1bd4f |
static char const *const _option_default_strv_mode[] = NM_MAKE_STRV("balance-rr",
|
|
Packit Service |
a1bd4f |
"active-backup",
|
|
Packit Service |
a1bd4f |
"balance-xor",
|
|
Packit Service |
a1bd4f |
"broadcast",
|
|
Packit Service |
a1bd4f |
"802.3ad",
|
|
Packit Service |
a1bd4f |
"balance-tlb",
|
|
Packit Service |
a1bd4f |
"balance-alb");
|
|
Packit Service |
a1bd4f |
static char const *const _option_default_strv_primary_reselect[] =
|
|
Packit Service |
a1bd4f |
NM_MAKE_STRV("always", "better", "failure");
|
|
Packit Service |
a1bd4f |
static char const *const _option_default_strv_xmit_hash_policy[] =
|
|
Packit Service |
a1bd4f |
NM_MAKE_STRV("layer2", "layer3+4", "layer2+3", "encap2+3", "encap3+4");
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
static NM_UTILS_STRING_TABLE_LOOKUP_STRUCT_DEFINE(
|
|
Packit Service |
a1bd4f |
_get_option_meta,
|
|
Packit Service |
a1bd4f |
OptionMeta,
|
|
Packit Service |
a1bd4f |
{
|
|
Packit Service |
a1bd4f |
G_STATIC_ASSERT_EXPR(G_N_ELEMENTS(LIST) == G_N_ELEMENTS(valid_options_lst) - 1);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (NM_MORE_ASSERT_ONCE(5)) {
|
|
Packit Service |
a1bd4f |
int i;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nm_assert(G_N_ELEMENTS(LIST) == NM_PTRARRAY_LEN(valid_options_lst));
|
|
Packit Service |
a1bd4f |
for (i = 0; i < G_N_ELEMENTS(LIST); i++)
|
|
Packit Service |
a1bd4f |
_nm_assert_bond_meta(&LIST[i].value);
|
|
Packit Service |
a1bd4f |
nm_assert(nm_streq(valid_options_lst[0], NM_SETTING_BOND_OPTION_MODE));
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
},
|
|
Packit Service |
a1bd4f |
{ return NULL; },
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_ACTIVE_SLAVE, {NULL, NM_BOND_OPTION_TYPE_IFNAME}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_AD_ACTOR_SYS_PRIO, {"65535", NM_BOND_OPTION_TYPE_INT, 1, 65535}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM, {NULL, NM_BOND_OPTION_TYPE_MAC}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_AD_SELECT,
|
|
Packit Service |
a1bd4f |
{"stable", NM_BOND_OPTION_TYPE_BOTH, 0, 2, _option_default_strv_ad_select}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_AD_USER_PORT_KEY, {"0", NM_BOND_OPTION_TYPE_INT, 0, 1023}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_ALL_SLAVES_ACTIVE, {"0", NM_BOND_OPTION_TYPE_INT, 0, 1}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_ARP_ALL_TARGETS,
|
|
Packit Service |
a1bd4f |
{"any", NM_BOND_OPTION_TYPE_BOTH, 0, 1, _option_default_strv_arp_all_targets}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_ARP_INTERVAL, {"0", NM_BOND_OPTION_TYPE_INT, 0, G_MAXINT}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_ARP_IP_TARGET, {"", NM_BOND_OPTION_TYPE_IP}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_ARP_VALIDATE,
|
|
Packit Service |
a1bd4f |
{"none", NM_BOND_OPTION_TYPE_BOTH, 0, 6, _option_default_strv_arp_validate}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_DOWNDELAY, {"0", NM_BOND_OPTION_TYPE_INT, 0, G_MAXINT}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_FAIL_OVER_MAC,
|
|
Packit Service |
a1bd4f |
{"none", NM_BOND_OPTION_TYPE_BOTH, 0, 2, _option_default_strv_fail_over_mac}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_LACP_RATE,
|
|
Packit Service |
a1bd4f |
{"slow", NM_BOND_OPTION_TYPE_BOTH, 0, 1, _option_default_strv_lacp_rate}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_LP_INTERVAL, {"1", NM_BOND_OPTION_TYPE_INT, 1, G_MAXINT}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_MIIMON, {"100", NM_BOND_OPTION_TYPE_INT, 0, G_MAXINT}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_MIN_LINKS, {"0", NM_BOND_OPTION_TYPE_INT, 0, G_MAXINT}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_MODE,
|
|
Packit Service |
a1bd4f |
{"balance-rr", NM_BOND_OPTION_TYPE_BOTH, 0, 6, _option_default_strv_mode}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_NUM_GRAT_ARP, {"1", NM_BOND_OPTION_TYPE_INT, 0, 255}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_NUM_UNSOL_NA, {"1", NM_BOND_OPTION_TYPE_INT, 0, 255}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_PACKETS_PER_SLAVE, {"1", NM_BOND_OPTION_TYPE_INT, 0, 65535}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_PRIMARY, {"", NM_BOND_OPTION_TYPE_IFNAME}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_PRIMARY_RESELECT,
|
|
Packit Service |
a1bd4f |
{"always", NM_BOND_OPTION_TYPE_BOTH, 0, 2, _option_default_strv_primary_reselect}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_RESEND_IGMP, {"1", NM_BOND_OPTION_TYPE_INT, 0, 255}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_TLB_DYNAMIC_LB, {"1", NM_BOND_OPTION_TYPE_INT, 0, 1}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_UPDELAY, {"0", NM_BOND_OPTION_TYPE_INT, 0, G_MAXINT}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_USE_CARRIER, {"1", NM_BOND_OPTION_TYPE_INT, 0, 1}},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_XMIT_HASH_POLICY,
|
|
Packit Service |
a1bd4f |
{"layer2", NM_BOND_OPTION_TYPE_BOTH, 0, 4, _option_default_strv_xmit_hash_policy}}, );
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#define BIT(x) (((guint32) 1) << (x))
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
static NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(
|
|
Packit Service |
a1bd4f |
_bond_option_unsupp_mode,
|
|
Packit Service |
a1bd4f |
guint32,
|
|
Packit Service |
a1bd4f |
{ ; },
|
|
Packit Service |
a1bd4f |
{ return 0; },
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_ACTIVE_SLAVE,
|
|
Packit Service |
a1bd4f |
~(BIT(NM_BOND_MODE_ACTIVEBACKUP) | BIT(NM_BOND_MODE_TLB) | BIT(NM_BOND_MODE_ALB))},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_AD_ACTOR_SYS_PRIO, ~(BIT(NM_BOND_MODE_8023AD))},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM, ~(BIT(NM_BOND_MODE_8023AD))},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_AD_USER_PORT_KEY, ~(BIT(NM_BOND_MODE_8023AD))},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_ARP_INTERVAL,
|
|
Packit Service |
a1bd4f |
(BIT(NM_BOND_MODE_8023AD) | BIT(NM_BOND_MODE_TLB) | BIT(NM_BOND_MODE_ALB))},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_ARP_IP_TARGET,
|
|
Packit Service |
a1bd4f |
(BIT(NM_BOND_MODE_8023AD) | BIT(NM_BOND_MODE_TLB) | BIT(NM_BOND_MODE_ALB))},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_ARP_VALIDATE,
|
|
Packit Service |
a1bd4f |
(BIT(NM_BOND_MODE_8023AD) | BIT(NM_BOND_MODE_TLB) | BIT(NM_BOND_MODE_ALB))},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_LACP_RATE, ~(BIT(NM_BOND_MODE_8023AD))},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_PACKETS_PER_SLAVE, ~(BIT(NM_BOND_MODE_ROUNDROBIN))},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_PRIMARY,
|
|
Packit Service |
a1bd4f |
~(BIT(NM_BOND_MODE_ACTIVEBACKUP) | BIT(NM_BOND_MODE_TLB) | BIT(NM_BOND_MODE_ALB))},
|
|
Packit Service |
a1bd4f |
{NM_SETTING_BOND_OPTION_TLB_DYNAMIC_LB, ~(BIT(NM_BOND_MODE_TLB))}, );
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
gboolean
|
|
Packit Service |
a1bd4f |
_nm_setting_bond_option_supported(const char *option, NMBondMode mode)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(option);
|
|
Packit Service |
a1bd4f |
nm_assert(mode != NM_BOND_MODE_UNKNOWN);
|
|
Packit Service |
a1bd4f |
nm_assert(_NM_INT_NOT_NEGATIVE(mode) && mode < 32);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return !NM_FLAGS_ANY(_bond_option_unsupp_mode(option), BIT(mode));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
static const char *
|
|
Packit Service |
a1bd4f |
_bond_get_option(NMSettingBond *self, const char *option)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(self), NULL);
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(option, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return g_hash_table_lookup(NM_SETTING_BOND_GET_PRIVATE(self)->options, option);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
static const char *
|
|
Packit Service |
a1bd4f |
_bond_get_option_default(NMSettingBond *self, const char *option)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
const OptionMeta *option_meta;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(self), NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
option_meta = _get_option_meta(option);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(option_meta, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return option_meta->val;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
static const char *
|
|
Packit Service |
a1bd4f |
_bond_get_option_or_default(NMSettingBond *self, const char *option)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return _bond_get_option(self, option) ?: _bond_get_option_default(self, option);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
static const char *
|
|
Packit Service |
a1bd4f |
_bond_get_option_normalized(NMSettingBond *self, const char *option, gboolean get_default_only)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
const char *mode_str;
|
|
Packit Service |
a1bd4f |
NMBondMode mode;
|
|
Packit Service |
a1bd4f |
const char *value = NULL;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(self), NULL);
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(option, NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
mode_str = _bond_get_option_or_default(self, NM_SETTING_BOND_OPTION_MODE);
|
|
Packit Service |
a1bd4f |
mode = _nm_setting_bond_mode_from_string(mode_str);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (mode == NM_BOND_MODE_UNKNOWN) {
|
|
Packit Service |
a1bd4f |
/* the mode is unknown, consequently, there is no normalized/default
|
|
Packit Service |
a1bd4f |
* value either. */
|
|
Packit Service |
a1bd4f |
return NULL;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!_nm_setting_bond_option_supported(option, mode))
|
|
Packit Service |
a1bd4f |
return NULL;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Apply custom NetworkManager policies here */
|
|
Packit Service |
a1bd4f |
if (!get_default_only) {
|
|
Packit Service |
a1bd4f |
if (NM_IN_STRSET(option,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ARP_INTERVAL,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ARP_IP_TARGET)) {
|
|
Packit Service |
a1bd4f |
int miimon;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* if arp_interval is explicitly set and miimon is not, then disable miimon
|
|
Packit Service |
a1bd4f |
* (and related updelay and downdelay) as recommended by the kernel docs */
|
|
Packit Service |
a1bd4f |
miimon =
|
|
Packit Service |
a1bd4f |
_nm_utils_ascii_str_to_int64(_bond_get_option(self, NM_SETTING_BOND_OPTION_MIIMON),
|
|
Packit Service |
a1bd4f |
10,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
G_MAXINT,
|
|
Packit Service |
a1bd4f |
0);
|
|
Packit Service |
a1bd4f |
if (miimon != 0) {
|
|
Packit Service |
a1bd4f |
/* miimon is enabled. arp_interval values are unset. */
|
|
Packit Service |
a1bd4f |
if (nm_streq(option, NM_SETTING_BOND_OPTION_ARP_INTERVAL))
|
|
Packit Service |
a1bd4f |
return "0";
|
|
Packit Service |
a1bd4f |
return "";
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
value = _bond_get_option(self, option);
|
|
Packit Service |
a1bd4f |
} else if (NM_IN_STRSET(option,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_NUM_GRAT_ARP,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_NUM_UNSOL_NA)) {
|
|
Packit Service |
a1bd4f |
/* just get one of the 2, at kernel level they're the same bond option */
|
|
Packit Service |
a1bd4f |
value = _bond_get_option(self, NM_SETTING_BOND_OPTION_NUM_GRAT_ARP);
|
|
Packit Service |
a1bd4f |
if (!value)
|
|
Packit Service |
a1bd4f |
value = _bond_get_option(self, NM_SETTING_BOND_OPTION_NUM_UNSOL_NA);
|
|
Packit Service |
a1bd4f |
} else if (NM_IN_STRSET(option, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE)) {
|
|
Packit Service |
a1bd4f |
/* "active_slave" is deprecated, and an alias for "primary". The property
|
|
Packit Service |
a1bd4f |
* itself always normalizes to %NULL. */
|
|
Packit Service |
a1bd4f |
value = NULL;
|
|
Packit Service |
a1bd4f |
} else if (NM_IN_STRSET(option, NM_SETTING_BOND_OPTION_PRIMARY)) {
|
|
Packit Service |
a1bd4f |
/* "active_slave" is deprecated, and an alias for "primary". */
|
|
Packit Service |
a1bd4f |
value = _bond_get_option(self, NM_SETTING_BOND_OPTION_PRIMARY);
|
|
Packit Service |
a1bd4f |
if (!value)
|
|
Packit Service |
a1bd4f |
value = _bond_get_option(self, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE);
|
|
Packit Service |
a1bd4f |
} else
|
|
Packit Service |
a1bd4f |
value = _bond_get_option(self, option);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (value)
|
|
Packit Service |
a1bd4f |
return value;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Apply rules that change the default value of an option */
|
|
Packit Service |
a1bd4f |
if (nm_streq(option, NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM)) {
|
|
Packit Service |
a1bd4f |
/* The default value depends on the current mode */
|
|
Packit Service |
a1bd4f |
if (mode == NM_BOND_MODE_8023AD)
|
|
Packit Service |
a1bd4f |
return "00:00:00:00:00:00";
|
|
Packit Service |
a1bd4f |
return "";
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return _bond_get_option_or_default(self, option);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
const char *
|
|
Packit Service |
a1bd4f |
nm_setting_bond_get_option_or_default(NMSettingBond *self, const char *option)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(self), NULL);
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(option, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return _bond_get_option_normalized(self, option, FALSE);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static int
|
|
Packit Service |
a1bd4f |
_atoi(const char *value)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
int v;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
v = _nm_utils_ascii_str_to_int64(value, 10, 0, G_MAXINT, -1);
|
|
Packit Service |
a1bd4f |
nm_assert(v >= 0);
|
|
Packit Service |
a1bd4f |
return v;
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_setting_bond_get_num_options:
|
|
Packit |
5756e2 |
* @setting: the #NMSettingBond
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns the number of options that should be set for this bond when it
|
|
Packit |
5756e2 |
* is activated. This can be used to retrieve each option individually
|
|
Packit |
5756e2 |
* using nm_setting_bond_get_option().
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: the number of bonding options
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
guint32
|
|
Packit Service |
a1bd4f |
nm_setting_bond_get_num_options(NMSettingBond *setting)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(setting), 0);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return g_hash_table_size(NM_SETTING_BOND_GET_PRIVATE(setting)->options);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static int
|
|
Packit Service |
a1bd4f |
_get_option_sort(gconstpointer p_a, gconstpointer p_b, gpointer _unused)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
const char *a = *((const char *const *) p_a);
|
|
Packit Service |
a1bd4f |
const char *b = *((const char *const *) p_b);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
NM_CMP_DIRECT(nm_streq(b, NM_SETTING_BOND_OPTION_MODE),
|
|
Packit Service |
a1bd4f |
nm_streq(a, NM_SETTING_BOND_OPTION_MODE));
|
|
Packit Service |
a1bd4f |
NM_CMP_DIRECT_STRCMP(a, b);
|
|
Packit Service |
a1bd4f |
nm_assert_not_reached();
|
|
Packit Service |
a1bd4f |
return 0;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
_ensure_options_idx_cache(NMSettingBondPrivate *priv)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
if (!G_UNLIKELY(priv->options_idx_cache))
|
|
Packit Service |
a1bd4f |
priv->options_idx_cache = nm_utils_named_values_from_strdict_full(priv->options,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
_get_option_sort,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
NULL);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_setting_bond_get_option:
|
|
Packit |
5756e2 |
* @setting: the #NMSettingBond
|
|
Packit |
5756e2 |
* @idx: index of the desired option, from 0 to
|
|
Packit |
5756e2 |
* nm_setting_bond_get_num_options() - 1
|
|
Packit |
5756e2 |
* @out_name: (out) (transfer none): on return, the name of the bonding option;
|
|
Packit |
5756e2 |
* this value is owned by the setting and should not be modified
|
|
Packit |
5756e2 |
* @out_value: (out) (transfer none): on return, the value of the name of the
|
|
Packit |
5756e2 |
* bonding option; this value is owned by the setting and should not be
|
|
Packit |
5756e2 |
* modified
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Given an index, return the value of the bonding option at that index. Indexes
|
|
Packit |
5756e2 |
* are *not* guaranteed to be static across modifications to options done by
|
|
Packit |
5756e2 |
* nm_setting_bond_add_option() and nm_setting_bond_remove_option(),
|
|
Packit |
5756e2 |
* and should not be used to refer to options except for short periods of time
|
|
Packit |
5756e2 |
* such as during option iteration.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: %TRUE on success if the index was valid and an option was found,
|
|
Packit |
5756e2 |
* %FALSE if the index was invalid (ie, greater than the number of options
|
|
Packit |
5756e2 |
* currently held by the setting)
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
gboolean
|
|
Packit Service |
a1bd4f |
nm_setting_bond_get_option(NMSettingBond *setting,
|
|
Packit Service |
a1bd4f |
guint32 idx,
|
|
Packit Service |
a1bd4f |
const char ** out_name,
|
|
Packit Service |
a1bd4f |
const char ** out_value)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMSettingBondPrivate *priv;
|
|
Packit Service |
a1bd4f |
guint len;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(setting), FALSE);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
priv = NM_SETTING_BOND_GET_PRIVATE(setting);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
len = g_hash_table_size(priv->options);
|
|
Packit Service |
a1bd4f |
if (idx >= len)
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
_ensure_options_idx_cache(priv);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NM_SET_OUT(out_name, priv->options_idx_cache[idx].name);
|
|
Packit Service |
a1bd4f |
NM_SET_OUT(out_value, priv->options_idx_cache[idx].value_str);
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
validate_int(const char *name, const char *value, const OptionMeta *option_meta)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
guint64 num;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
if (!NM_STRCHAR_ALL(value, ch, g_ascii_isdigit(ch)))
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
num = _nm_utils_ascii_str_to_uint64(value, 10, option_meta->min, option_meta->max, G_MAXUINT64);
|
|
Packit Service |
a1bd4f |
if (num == G_MAXUINT64 && errno != 0)
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
validate_list(const char *name, const char *value, const OptionMeta *option_meta)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
int i;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_assert(option_meta->list);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
for (i = 0; option_meta->list[i]; i++) {
|
|
Packit Service |
a1bd4f |
if (nm_streq(option_meta->list[i], value))
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
validate_ip(const char *name, const char *value, GError **error)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
gs_free const char **addrs = NULL;
|
|
Packit Service |
a1bd4f |
gsize i;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
addrs = nm_utils_bond_option_arp_ip_targets_split(value);
|
|
Packit Service |
a1bd4f |
if (!addrs) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' option is empty"),
|
|
Packit Service |
a1bd4f |
name);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
for (i = 0; addrs[i]; i++) {
|
|
Packit Service |
a1bd4f |
if (!nm_utils_parse_inaddr_bin(AF_INET, addrs[i], NULL, NULL)) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' is not a valid IPv4 address for '%s' option"),
|
|
Packit Service |
a1bd4f |
addrs[i],
|
|
Packit Service |
a1bd4f |
name);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
validate_ifname(const char *name, const char *value)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return nm_utils_ifname_valid_kernel(value, NULL);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
gboolean
|
|
Packit Service |
a1bd4f |
_nm_setting_bond_validate_option(const char *name, const char *value, GError **error)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
const OptionMeta *option_meta;
|
|
Packit Service |
a1bd4f |
gboolean success;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
option_meta = _get_option_meta(name);
|
|
Packit Service |
a1bd4f |
if (!option_meta) {
|
|
Packit Service |
a1bd4f |
if (!name) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("missing option name"));
|
|
Packit Service |
a1bd4f |
} else {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("invalid option '%s'"),
|
|
Packit Service |
a1bd4f |
name);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!value)
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (option_meta->opt_type) {
|
|
Packit Service |
a1bd4f |
case NM_BOND_OPTION_TYPE_INT:
|
|
Packit Service |
a1bd4f |
success = validate_int(name, value, option_meta);
|
|
Packit Service |
a1bd4f |
goto handle_error;
|
|
Packit Service |
a1bd4f |
case NM_BOND_OPTION_TYPE_BOTH:
|
|
Packit Service |
a1bd4f |
success =
|
|
Packit Service |
a1bd4f |
(validate_int(name, value, option_meta) || validate_list(name, value, option_meta));
|
|
Packit Service |
a1bd4f |
goto handle_error;
|
|
Packit Service |
a1bd4f |
case NM_BOND_OPTION_TYPE_IP:
|
|
Packit Service |
a1bd4f |
nm_assert(nm_streq0(name, NM_SETTING_BOND_OPTION_ARP_IP_TARGET));
|
|
Packit Service |
a1bd4f |
return validate_ip(name, value, error);
|
|
Packit Service |
a1bd4f |
case NM_BOND_OPTION_TYPE_MAC:
|
|
Packit Service |
a1bd4f |
success = nm_utils_hwaddr_valid(value, ETH_ALEN);
|
|
Packit Service |
a1bd4f |
goto handle_error;
|
|
Packit Service |
a1bd4f |
case NM_BOND_OPTION_TYPE_IFNAME:
|
|
Packit Service |
a1bd4f |
success = validate_ifname(name, value);
|
|
Packit Service |
a1bd4f |
goto handle_error;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nm_assert_not_reached();
|
|
Packit Service |
a1bd4f |
success = FALSE;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
handle_error:
|
|
Packit Service |
a1bd4f |
if (!success) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("invalid value '%s' for option '%s'"),
|
|
Packit Service |
a1bd4f |
value,
|
|
Packit Service |
a1bd4f |
name);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
return success;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_setting_bond_validate_option:
|
|
Packit |
5756e2 |
* @name: the name of the option to validate
|
|
Packit |
5756e2 |
* @value: the value of the option to validate
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Checks whether @name is a valid bond option and @value is a valid value for
|
|
Packit |
5756e2 |
* the @name. If @value is %NULL, the function only validates the option name.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: %TRUE, if the @value is valid for the given name.
|
|
Packit |
5756e2 |
* If the @name is not a valid option, %FALSE will be returned.
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
gboolean
|
|
Packit Service |
a1bd4f |
nm_setting_bond_validate_option(const char *name, const char *value)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return _nm_setting_bond_validate_option(name, value, NULL);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_setting_bond_get_option_by_name:
|
|
Packit |
5756e2 |
* @setting: the #NMSettingBond
|
|
Packit |
5756e2 |
* @name: the option name for which to retrieve the value
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns the value associated with the bonding option specified by
|
|
Packit |
5756e2 |
* @name, if it exists.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: the value, or %NULL if the key/value pair was never added to the
|
|
Packit |
5756e2 |
* setting; the value is owned by the setting and must not be modified
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
const char *
|
|
Packit Service |
a1bd4f |
nm_setting_bond_get_option_by_name(NMSettingBond *setting, const char *name)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(setting), NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return _bond_get_option(setting, name);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_setting_bond_add_option:
|
|
Packit |
5756e2 |
* @setting: the #NMSettingBond
|
|
Packit |
5756e2 |
* @name: name for the option
|
|
Packit |
5756e2 |
* @value: value for the option
|
|
Packit |
5756e2 |
*
|
|
Packit Service |
a1bd4f |
* Add an option to the table. Adding a new name replaces any existing name/value pair
|
|
Packit |
5756e2 |
* that may already exist.
|
|
Packit |
5756e2 |
*
|
|
Packit Service |
a1bd4f |
* Returns: returns %FALSE if either @name or @value is %NULL, in that case
|
|
Packit Service |
a1bd4f |
* the option is not set. Otherwise, the function does not fail and does not validate
|
|
Packit Service |
a1bd4f |
* the arguments. All validation happens via nm_connection_verify() or do basic validation
|
|
Packit Service |
a1bd4f |
* yourself with nm_setting_bond_validate_option().
|
|
Packit |
5756e2 |
*
|
|
Packit Service |
a1bd4f |
* Note: Before 1.30, libnm would perform basic validation of the name and the value
|
|
Packit Service |
a1bd4f |
* via nm_setting_bond_validate_option() and reject the request by returning FALSE.
|
|
Packit Service |
a1bd4f |
* Since 1.30, libnm no longer rejects any values as the setter is not supposed
|
|
Packit Service |
a1bd4f |
* to perform validation.
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
gboolean
|
|
Packit Service |
a1bd4f |
nm_setting_bond_add_option(NMSettingBond *setting, const char *name, const char *value)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMSettingBondPrivate *priv;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(setting), FALSE);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
if (!name)
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
if (!value)
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
priv = NM_SETTING_BOND_GET_PRIVATE(setting);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_clear_g_free(&priv->options_idx_cache);
|
|
Packit Service |
a1bd4f |
g_hash_table_insert(priv->options, g_strdup(name), g_strdup(value));
|
|
Packit Service |
a1bd4f |
_notify(setting, PROP_OPTIONS);
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_setting_bond_remove_option:
|
|
Packit |
5756e2 |
* @setting: the #NMSettingBond
|
|
Packit |
5756e2 |
* @name: name of the option to remove
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Remove the bonding option referenced by @name from the internal option
|
|
Packit |
5756e2 |
* list.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: %TRUE if the option was found and removed from the internal option
|
|
Packit |
5756e2 |
* list, %FALSE if it was not.
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
gboolean
|
|
Packit Service |
a1bd4f |
nm_setting_bond_remove_option(NMSettingBond *setting, const char *name)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMSettingBondPrivate *priv;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(setting), FALSE);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
priv = NM_SETTING_BOND_GET_PRIVATE(setting);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
if (!g_hash_table_remove(priv->options, name))
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_clear_g_free(&priv->options_idx_cache);
|
|
Packit Service |
a1bd4f |
_notify(setting, PROP_OPTIONS);
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_setting_bond_get_valid_options:
|
|
Packit |
5756e2 |
* @setting: (allow-none): the #NMSettingBond
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns a list of valid bond options.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* The @setting argument is unused and may be passed as %NULL.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: (transfer none): a %NULL-terminated array of strings of valid bond options.
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
const char **
|
|
Packit Service |
a1bd4f |
nm_setting_bond_get_valid_options(NMSettingBond *setting)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return (const char **) valid_options_lst;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_setting_bond_get_option_default:
|
|
Packit |
5756e2 |
* @setting: the #NMSettingBond
|
|
Packit |
5756e2 |
* @name: the name of the option
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: the value of the bond option if not overridden by an entry in
|
|
Packit |
5756e2 |
* the #NMSettingBond:options property.
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
const char *
|
|
Packit Service |
a1bd4f |
nm_setting_bond_get_option_default(NMSettingBond *setting, const char *name)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(setting), NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
if (!name)
|
|
Packit Service |
a1bd4f |
return NULL;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return _bond_get_option_normalized(setting, name, TRUE);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_setting_bond_get_option_normalized:
|
|
Packit |
5756e2 |
* @setting: the #NMSettingBond
|
|
Packit |
5756e2 |
* @name: the name of the option
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Since: 1.24
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: the value of the bond option after normalization, which is what NetworkManager
|
|
Packit |
5756e2 |
* will actually apply when activating the connection. %NULL if the option won't be applied
|
|
Packit |
5756e2 |
* to the connection.
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
const char *
|
|
Packit Service |
a1bd4f |
nm_setting_bond_get_option_normalized(NMSettingBond *setting, const char *name)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(setting), NULL);
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(name, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return _bond_get_option_normalized(setting, name, FALSE);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_setting_bond_get_option_type:
|
|
Packit |
5756e2 |
* @setting: the #NMSettingBond
|
|
Packit |
5756e2 |
* @name: the name of the option
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: the type of the bond option.
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
NMBondOptionType
|
|
Packit Service |
a1bd4f |
_nm_setting_bond_get_option_type(NMSettingBond *setting, const char *name)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
const OptionMeta *option_meta;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_SETTING_BOND(setting), NM_BOND_OPTION_TYPE_INT);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
option_meta = _get_option_meta(name);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(option_meta, NM_BOND_OPTION_TYPE_INT);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return option_meta->opt_type;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
verify(NMSetting *setting, NMConnection *connection, GError **error)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMSettingBond * self = NM_SETTING_BOND(setting);
|
|
Packit Service |
a1bd4f |
NMSettingBondPrivate * priv = NM_SETTING_BOND_GET_PRIVATE(setting);
|
|
Packit Service |
a1bd4f |
int miimon;
|
|
Packit Service |
a1bd4f |
int arp_interval;
|
|
Packit Service |
a1bd4f |
int num_grat_arp;
|
|
Packit Service |
a1bd4f |
int num_unsol_na;
|
|
Packit Service |
a1bd4f |
const char * mode_str;
|
|
Packit Service |
a1bd4f |
const char * arp_ip_target = NULL;
|
|
Packit Service |
a1bd4f |
const char * lacp_rate;
|
|
Packit Service |
a1bd4f |
const char * primary;
|
|
Packit Service |
a1bd4f |
NMBondMode bond_mode;
|
|
Packit Service |
a1bd4f |
guint i;
|
|
Packit Service |
a1bd4f |
const NMUtilsNamedValue *n;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
_ensure_options_idx_cache(priv);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (priv->options_idx_cache) {
|
|
Packit Service |
a1bd4f |
for (i = 0; priv->options_idx_cache[i].name; i++) {
|
|
Packit Service |
a1bd4f |
n = &priv->options_idx_cache[i];
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!n->value_str || !_nm_setting_bond_validate_option(n->name, n->value_str, error)) {
|
|
Packit Service |
a1bd4f |
g_prefix_error(error,
|
|
Packit Service |
a1bd4f |
"%s.%s: ",
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_SETTING_NAME,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
miimon = _atoi(_bond_get_option_or_default(self, NM_SETTING_BOND_OPTION_MIIMON));
|
|
Packit Service |
a1bd4f |
arp_interval = _atoi(_bond_get_option_or_default(self, NM_SETTING_BOND_OPTION_ARP_INTERVAL));
|
|
Packit Service |
a1bd4f |
num_grat_arp = _atoi(_bond_get_option_or_default(self, NM_SETTING_BOND_OPTION_NUM_GRAT_ARP));
|
|
Packit Service |
a1bd4f |
num_unsol_na = _atoi(_bond_get_option_or_default(self, NM_SETTING_BOND_OPTION_NUM_UNSOL_NA));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Option restrictions:
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* arp_interval conflicts [ alb, tlb ]
|
|
Packit Service |
a1bd4f |
* arp_interval needs arp_ip_target
|
|
Packit Service |
a1bd4f |
* arp_validate does not work with [ BOND_MODE_8023AD, BOND_MODE_TLB, BOND_MODE_ALB ]
|
|
Packit Service |
a1bd4f |
* downdelay needs miimon
|
|
Packit Service |
a1bd4f |
* updelay needs miimon
|
|
Packit Service |
a1bd4f |
* primary needs [ active-backup, tlb, alb ]
|
|
Packit Service |
a1bd4f |
*/
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Verify bond mode */
|
|
Packit Service |
a1bd4f |
mode_str = _bond_get_option(self, NM_SETTING_BOND_OPTION_MODE);
|
|
Packit Service |
a1bd4f |
if (!mode_str) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("mandatory option '%s' is missing"),
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_MODE);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
bond_mode = _nm_setting_bond_mode_from_string(mode_str);
|
|
Packit Service |
a1bd4f |
if (bond_mode == NM_BOND_MODE_UNKNOWN) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' is not a valid value for '%s'"),
|
|
Packit Service |
a1bd4f |
mode_str,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_MODE);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Make sure mode is compatible with other settings */
|
|
Packit Service |
a1bd4f |
if (NM_IN_SET(bond_mode, NM_BOND_MODE_TLB, NM_BOND_MODE_ALB)) {
|
|
Packit Service |
a1bd4f |
if (arp_interval > 0) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s=%s' is incompatible with '%s > 0'"),
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_MODE,
|
|
Packit Service |
a1bd4f |
mode_str,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ARP_INTERVAL);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
primary = _bond_get_option(self, NM_SETTING_BOND_OPTION_PRIMARY);
|
|
Packit Service |
a1bd4f |
if (NM_IN_SET(bond_mode, NM_BOND_MODE_ACTIVEBACKUP, NM_BOND_MODE_TLB, NM_BOND_MODE_ALB)) {
|
|
Packit Service |
a1bd4f |
GError *tmp_error = NULL;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (primary && !nm_utils_ifname_valid_kernel(primary, &tmp_error)) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' is not valid for the '%s' option: %s"),
|
|
Packit Service |
a1bd4f |
primary,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_PRIMARY,
|
|
Packit Service |
a1bd4f |
tmp_error->message);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
g_error_free(tmp_error);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
} else if (primary) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' option is only valid for '%s=%s'"),
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_PRIMARY,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_MODE,
|
|
Packit Service |
a1bd4f |
"active-backup");
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (connection && nm_connection_get_setting_infiniband(connection)) {
|
|
Packit Service |
a1bd4f |
if (bond_mode != NM_BOND_MODE_ACTIVEBACKUP) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s=%s' is not a valid configuration for '%s'"),
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_MODE,
|
|
Packit Service |
a1bd4f |
mode_str,
|
|
Packit Service |
a1bd4f |
NM_SETTING_INFINIBAND_SETTING_NAME);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (miimon == 0) {
|
|
Packit Service |
a1bd4f |
/* updelay and downdelay need miimon to be enabled to be valid */
|
|
Packit Service |
a1bd4f |
if (_atoi(_bond_get_option_or_default(self, NM_SETTING_BOND_OPTION_UPDELAY))) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' option requires '%s' option to be enabled"),
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_UPDELAY,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_MIIMON);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (_atoi(_bond_get_option_or_default(self, NM_SETTING_BOND_OPTION_DOWNDELAY))) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' option requires '%s' option to be enabled"),
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_DOWNDELAY,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_MIIMON);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* arp_ip_target can only be used with arp_interval, and must
|
|
Packit Service |
a1bd4f |
* contain a comma-separated list of IPv4 addresses.
|
|
Packit Service |
a1bd4f |
*/
|
|
Packit Service |
a1bd4f |
arp_ip_target = _bond_get_option(self, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
|
|
Packit Service |
a1bd4f |
if (arp_interval > 0) {
|
|
Packit Service |
a1bd4f |
if (!arp_ip_target) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' option requires '%s' option to be set"),
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ARP_INTERVAL,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
} else {
|
|
Packit Service |
a1bd4f |
if (arp_ip_target) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' option requires '%s' option to be set"),
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ARP_IP_TARGET,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_ARP_INTERVAL);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
lacp_rate = _bond_get_option(self, NM_SETTING_BOND_OPTION_LACP_RATE);
|
|
Packit Service |
a1bd4f |
if (lacp_rate && bond_mode != NM_BOND_MODE_8023AD && !NM_IN_STRSET(lacp_rate, "0", "slow")) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' option is only valid with mode '%s'"),
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_LACP_RATE,
|
|
Packit Service |
a1bd4f |
"802.3ad");
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (_bond_get_option(self, NM_SETTING_BOND_OPTION_NUM_GRAT_ARP)
|
|
Packit Service |
a1bd4f |
&& _bond_get_option(self, NM_SETTING_BOND_OPTION_NUM_UNSOL_NA)
|
|
Packit Service |
a1bd4f |
&& num_grat_arp != num_unsol_na) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' and '%s' cannot have different values"),
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_NUM_GRAT_ARP,
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_NUM_UNSOL_NA);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!_nm_connection_verify_required_interface_name(connection, error))
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* *** errors above here should be always fatal, below NORMALIZABLE_ERROR *** */
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!NM_IN_STRSET(mode_str,
|
|
Packit Service |
a1bd4f |
"802.3ad",
|
|
Packit Service |
a1bd4f |
"active-backup",
|
|
Packit Service |
a1bd4f |
"balance-rr",
|
|
Packit Service |
a1bd4f |
"balance-alb",
|
|
Packit Service |
a1bd4f |
"balance-tlb",
|
|
Packit Service |
a1bd4f |
"balance-xor",
|
|
Packit Service |
a1bd4f |
"broadcast")) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' option should be string"),
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTION_MODE);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return NM_SETTING_VERIFY_NORMALIZABLE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* normalize unsupported options for the current mode */
|
|
Packit Service |
a1bd4f |
for (i = 0; priv->options_idx_cache[i].name; i++) {
|
|
Packit Service |
a1bd4f |
n = &priv->options_idx_cache[i];
|
|
Packit Service |
a1bd4f |
if (!_nm_setting_bond_option_supported(n->name, bond_mode)) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR,
|
|
Packit Service |
a1bd4f |
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
Packit Service |
a1bd4f |
_("'%s' option is not valid with mode '%s'"),
|
|
Packit Service |
a1bd4f |
n->name,
|
|
Packit Service |
a1bd4f |
mode_str);
|
|
Packit Service |
a1bd4f |
g_prefix_error(error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
|
|
Packit Service |
a1bd4f |
return NM_SETTING_VERIFY_NORMALIZABLE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
options_equal_asym(NMSettingBond *s_bond, NMSettingBond *s_bond2, NMSettingCompareFlags flags)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
GHashTableIter iter;
|
|
Packit Service |
a1bd4f |
const char * key, *value;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_hash_table_iter_init(&iter, NM_SETTING_BOND_GET_PRIVATE(s_bond)->options);
|
|
Packit Service |
a1bd4f |
while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &value)) {
|
|
Packit Service |
a1bd4f |
if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) {
|
|
Packit Service |
a1bd4f |
/* when doing an inferrable match, the active-slave should be ignored
|
|
Packit Service |
a1bd4f |
* as it might be differ from the setting in the connection.
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* Also, the fail_over_mac setting can change, see for example
|
|
Packit Service |
a1bd4f |
* https://bugzilla.redhat.com/show_bug.cgi?id=1375558#c8 */
|
|
Packit Service |
a1bd4f |
if (NM_IN_STRSET(key, "fail_over_mac", "active_slave"))
|
|
Packit Service |
a1bd4f |
continue;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!nm_streq0(value, _bond_get_option(s_bond2, key)))
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
options_equal(NMSettingBond *s_bond, NMSettingBond *s_bond2, NMSettingCompareFlags flags)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return options_equal_asym(s_bond, s_bond2, flags) && options_equal_asym(s_bond2, s_bond, flags);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static NMTernary
|
|
Packit Service |
a1bd4f |
compare_property(const NMSettInfoSetting *sett_info,
|
|
Packit Service |
a1bd4f |
guint property_idx,
|
|
Packit Service |
a1bd4f |
NMConnection * con_a,
|
|
Packit Service |
a1bd4f |
NMSetting * set_a,
|
|
Packit Service |
a1bd4f |
NMConnection * con_b,
|
|
Packit Service |
a1bd4f |
NMSetting * set_b,
|
|
Packit Service |
a1bd4f |
NMSettingCompareFlags flags)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_BOND_OPTIONS)) {
|
|
Packit Service |
a1bd4f |
return (!set_b || options_equal(NM_SETTING_BOND(set_a), NM_SETTING_BOND(set_b), flags));
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return NM_SETTING_CLASS(nm_setting_bond_parent_class)
|
|
Packit Service |
a1bd4f |
->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE(object);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (prop_id) {
|
|
Packit Service |
a1bd4f |
case PROP_OPTIONS:
|
|
Packit Service |
a1bd4f |
g_value_take_boxed(value, _nm_utils_copy_strdict(priv->options));
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
default:
|
|
Packit Service |
a1bd4f |
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE(object);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (prop_id) {
|
|
Packit Service |
a1bd4f |
case PROP_OPTIONS:
|
|
Packit Service |
a1bd4f |
nm_clear_g_free(&priv->options_idx_cache);
|
|
Packit Service |
a1bd4f |
g_hash_table_unref(priv->options);
|
|
Packit Service |
a1bd4f |
priv->options = _nm_utils_copy_strdict(g_value_get_boxed(value));
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
default:
|
|
Packit Service |
a1bd4f |
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nm_setting_bond_init(NMSettingBond *setting)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE(setting);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
priv->options = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_free);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Default values: */
|
|
Packit Service |
a1bd4f |
nm_setting_bond_add_option(setting, NM_SETTING_BOND_OPTION_MODE, "balance-rr");
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_setting_bond_new:
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Creates a new #NMSettingBond object with default values.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: (transfer full): the new empty #NMSettingBond object
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
NMSetting *
|
|
Packit Service |
a1bd4f |
nm_setting_bond_new(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return g_object_new(NM_TYPE_SETTING_BOND, NULL);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
finalize(GObject *object)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE(object);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_clear_g_free(&priv->options_idx_cache);
|
|
Packit Service |
a1bd4f |
g_hash_table_destroy(priv->options);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
G_OBJECT_CLASS(nm_setting_bond_parent_class)->finalize(object);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nm_setting_bond_class_init(NMSettingBondClass *klass)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
GObjectClass * object_class = G_OBJECT_CLASS(klass);
|
|
Packit Service |
a1bd4f |
NMSettingClass *setting_class = NM_SETTING_CLASS(klass);
|
|
Packit Service |
a1bd4f |
GArray * properties_override = _nm_sett_info_property_override_create_array();
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_type_class_add_private(klass, sizeof(NMSettingBondPrivate));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
object_class->get_property = get_property;
|
|
Packit Service |
a1bd4f |
object_class->set_property = set_property;
|
|
Packit Service |
a1bd4f |
object_class->finalize = finalize;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
setting_class->verify = verify;
|
|
Packit Service |
a1bd4f |
setting_class->compare_property = compare_property;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/**
|
|
Packit Service |
a1bd4f |
* NMSettingBond:options: (type GHashTable(utf8,utf8)):
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* Dictionary of key/value pairs of bonding options. Both keys and values
|
|
Packit Service |
a1bd4f |
* must be strings. Option names must contain only alphanumeric characters
|
|
Packit Service |
a1bd4f |
* (ie, [a-zA-Z0-9]).
|
|
Packit Service |
a1bd4f |
**/
|
|
Packit Service |
a1bd4f |
/* ---ifcfg-rh---
|
|
Packit Service |
a1bd4f |
* property: options
|
|
Packit Service |
a1bd4f |
* variable: BONDING_OPTS
|
|
Packit Service |
a1bd4f |
* description: Bonding options.
|
|
Packit Service |
a1bd4f |
* example: BONDING_OPTS="miimon=100 mode=broadcast"
|
|
Packit Service |
a1bd4f |
* ---end---
|
|
Packit Service |
a1bd4f |
*/
|
|
Packit Service |
a1bd4f |
obj_properties[PROP_OPTIONS] = g_param_spec_boxed(
|
|
Packit Service |
a1bd4f |
NM_SETTING_BOND_OPTIONS,
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
G_TYPE_HASH_TABLE,
|
|
Packit Service |
a1bd4f |
G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
|
|
Packit Service |
a1bd4f |
_nm_properties_override_gobj(properties_override,
|
|
Packit Service |
a1bd4f |
obj_properties[PROP_OPTIONS],
|
|
Packit Service |
a1bd4f |
&nm_sett_info_propert_type_strdict);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* ---dbus---
|
|
Packit Service |
a1bd4f |
* property: interface-name
|
|
Packit Service |
a1bd4f |
* format: string
|
|
Packit Service |
a1bd4f |
* description: Deprecated in favor of connection.interface-name, but can
|
|
Packit Service |
a1bd4f |
* be used for backward-compatibility with older daemons, to set the
|
|
Packit Service |
a1bd4f |
* bond's interface name.
|
|
Packit Service |
a1bd4f |
* ---end---
|
|
Packit Service |
a1bd4f |
*/
|
|
Packit Service |
a1bd4f |
_nm_properties_override_dbus(properties_override,
|
|
Packit Service |
a1bd4f |
"interface-name",
|
|
Packit Service |
a1bd4f |
&nm_sett_info_propert_type_deprecated_interface_name);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
_nm_setting_class_commit_full(setting_class,
|
|
Packit Service |
a1bd4f |
NM_META_SETTING_TYPE_BOND,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
properties_override);
|
|
Packit |
5756e2 |
}
|