1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA.
19 * Copyright 2011 - 2013 Red Hat, Inc.
22 #include "nm-default.h"
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
30 #include "nm-setting-bond.h"
32 #include "nm-utils-private.h"
33 #include "nm-connection-private.h"
34 #include "nm-setting-infiniband.h"
35 #include "nm-core-internal.h"
38 * SECTION:nm-setting-bond
39 * @short_description: Describes connection properties for bonds
41 * The #NMSettingBond object is a #NMSetting subclass that describes properties
42 * necessary for bond connections.
45 G_DEFINE_TYPE_WITH_CODE (NMSettingBond, nm_setting_bond, NM_TYPE_SETTING,
46 _nm_register_setting (BOND, 1))
47 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BOND)
49 #define NM_SETTING_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BOND, NMSettingBondPrivate))
53 } NMSettingBondPrivate;
70 static const BondDefault defaults[] = {
71 { NM_SETTING_BOND_OPTION_MODE, "balance-rr", NM_BOND_OPTION_TYPE_BOTH, 0, 6,
72 { "balance-rr", "active-backup", "balance-xor", "broadcast", "802.3ad", "balance-tlb", "balance-alb", NULL } },
73 { NM_SETTING_BOND_OPTION_MIIMON, "100", NM_BOND_OPTION_TYPE_INT, 0, G_MAXINT },
74 { NM_SETTING_BOND_OPTION_DOWNDELAY, "0", NM_BOND_OPTION_TYPE_INT, 0, G_MAXINT },
75 { NM_SETTING_BOND_OPTION_UPDELAY, "0", NM_BOND_OPTION_TYPE_INT, 0, G_MAXINT },
76 { NM_SETTING_BOND_OPTION_ARP_INTERVAL, "0", NM_BOND_OPTION_TYPE_INT, 0, G_MAXINT },
77 { NM_SETTING_BOND_OPTION_ARP_IP_TARGET, "", NM_BOND_OPTION_TYPE_IP },
78 { NM_SETTING_BOND_OPTION_ARP_VALIDATE, "none", NM_BOND_OPTION_TYPE_BOTH, 0, 3,
79 { "none", "active", "backup", "all", NULL } },
80 { NM_SETTING_BOND_OPTION_PRIMARY, "", NM_BOND_OPTION_TYPE_IFNAME },
81 { NM_SETTING_BOND_OPTION_PRIMARY_RESELECT, "always", NM_BOND_OPTION_TYPE_BOTH, 0, 2,
82 { "always", "better", "failure", NULL } },
83 { NM_SETTING_BOND_OPTION_FAIL_OVER_MAC, "none", NM_BOND_OPTION_TYPE_BOTH, 0, 2,
84 { "none", "active", "follow", NULL } },
85 { NM_SETTING_BOND_OPTION_USE_CARRIER, "1", NM_BOND_OPTION_TYPE_INT, 0, 1 },
86 { NM_SETTING_BOND_OPTION_AD_SELECT, "stable", NM_BOND_OPTION_TYPE_BOTH, 0, 2,
87 { "stable", "bandwidth", "count", NULL } },
88 { NM_SETTING_BOND_OPTION_XMIT_HASH_POLICY, "layer2", NM_BOND_OPTION_TYPE_BOTH, 0, 2,
89 { "layer2", "layer3+4", "layer2+3", NULL } },
90 { NM_SETTING_BOND_OPTION_RESEND_IGMP, "1", NM_BOND_OPTION_TYPE_INT, 0, 255 },
91 { NM_SETTING_BOND_OPTION_LACP_RATE, "slow", NM_BOND_OPTION_TYPE_BOTH, 0, 1,
92 { "slow", "fast", NULL } },
93 { NM_SETTING_BOND_OPTION_ACTIVE_SLAVE, "", NM_BOND_OPTION_TYPE_IFNAME },
94 { NM_SETTING_BOND_OPTION_AD_ACTOR_SYS_PRIO,"65535", NM_BOND_OPTION_TYPE_INT, 1, 65535 },
95 { NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM, "", NM_BOND_OPTION_TYPE_MAC },
96 { NM_SETTING_BOND_OPTION_AD_USER_PORT_KEY, "0", NM_BOND_OPTION_TYPE_INT, 0, 1023},
97 { NM_SETTING_BOND_OPTION_ALL_SLAVES_ACTIVE,"0", NM_BOND_OPTION_TYPE_INT, 0, 1},
98 { NM_SETTING_BOND_OPTION_ARP_ALL_TARGETS, "any", NM_BOND_OPTION_TYPE_BOTH, 0, 1, {"any", "all"}},
99 { NM_SETTING_BOND_OPTION_MIN_LINKS, "0", NM_BOND_OPTION_TYPE_INT, 0, G_MAXINT },
100 { NM_SETTING_BOND_OPTION_NUM_GRAT_ARP, "1", NM_BOND_OPTION_TYPE_INT, 0, 255 },
101 { NM_SETTING_BOND_OPTION_NUM_UNSOL_NA, "1", NM_BOND_OPTION_TYPE_INT, 0, 255 },
102 { NM_SETTING_BOND_OPTION_PACKETS_PER_SLAVE,"1", NM_BOND_OPTION_TYPE_INT, 0, 65535 },
103 { NM_SETTING_BOND_OPTION_TLB_DYNAMIC_LB, "1", NM_BOND_OPTION_TYPE_INT, 0, 1 },
104 { NM_SETTING_BOND_OPTION_LP_INTERVAL, "1", NM_BOND_OPTION_TYPE_INT, 1, G_MAXINT },
108 * nm_setting_bond_new:
110 * Creates a new #NMSettingBond object with default values.
112 * Returns: (transfer full): the new empty #NMSettingBond object
115 nm_setting_bond_new (void)
117 return (NMSetting *) g_object_new (NM_TYPE_SETTING_BOND, NULL);
121 * nm_setting_bond_get_num_options:
122 * @setting: the #NMSettingBond
124 * Returns the number of options that should be set for this bond when it
125 * is activated. This can be used to retrieve each option individually
126 * using nm_setting_bond_get_option().
128 * Returns: the number of bonding options
131 nm_setting_bond_get_num_options (NMSettingBond *setting)
133 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);
135 return g_hash_table_size (NM_SETTING_BOND_GET_PRIVATE (setting)->options);
139 * nm_setting_bond_get_option:
140 * @setting: the #NMSettingBond
141 * @idx: index of the desired option, from 0 to
142 * nm_setting_bond_get_num_options() - 1
143 * @out_name: (out) (transfer none): on return, the name of the bonding option;
144 * this value is owned by the setting and should not be modified
145 * @out_value: (out) (transfer none): on return, the value of the name of the
146 * bonding option; this value is owned by the setting and should not be
149 * Given an index, return the value of the bonding option at that index. Indexes
150 * are *not* guaranteed to be static across modifications to options done by
151 * nm_setting_bond_add_option() and nm_setting_bond_remove_option(),
152 * and should not be used to refer to options except for short periods of time
153 * such as during option iteration.
155 * Returns: %TRUE on success if the index was valid and an option was found,
156 * %FALSE if the index was invalid (ie, greater than the number of options
157 * currently held by the setting)
160 nm_setting_bond_get_option (NMSettingBond *setting,
162 const char **out_name,
163 const char **out_value)
165 NMSettingBondPrivate *priv;
167 const char *_key = NULL, *_value = NULL;
169 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
171 priv = NM_SETTING_BOND_GET_PRIVATE (setting);
173 if (idx >= nm_setting_bond_get_num_options (setting))
176 keys = g_hash_table_get_keys (priv->options);
177 _key = g_list_nth_data (keys, idx);
178 _value = g_hash_table_lookup (priv->options, _key);
190 validate_int (const char *name, const char *value, const BondDefault *def)
195 for (i = 0; i < strlen (value); i++) {
196 if (!g_ascii_isdigit (value[i]) && value[i] != '-')
201 num = strtol (value, NULL, 10);
204 if (num < def->min || num > def->max)
211 validate_list (const char *name, const char *value, const BondDefault *def)
215 for (i = 0; i < G_N_ELEMENTS (def->list) && def->list[i]; i++) {
216 if (g_strcmp0 (def->list[i], value) == 0)
220 /* empty validation list means all values pass */
221 return def->list[0] == NULL ? TRUE : FALSE;
225 validate_ip (const char *name, const char *value)
228 gboolean success = TRUE;
231 if (!value || !value[0])
234 ips = g_strsplit_set (value, ",", 0);
235 for (iter = ips; iter && *iter && success; iter++)
236 success = !!inet_aton (*iter, &addr);
243 validate_ifname (const char *name, const char *value)
245 if (!value || !value[0])
248 return nm_utils_iface_valid_name (value);
252 * nm_setting_bond_validate_option:
253 * @name: the name of the option to validate
254 * @value: the value of the option to validate
256 * Checks whether @name is a valid bond option and @value is a valid value for
257 * the @name. If @value is %NULL, the function only validates the option name.
259 * Returns: %TRUE, if the @value is valid for the given name.
260 * If the @name is not a valid option, %FALSE will be returned.
263 nm_setting_bond_validate_option (const char *name,
268 if (!name || !name[0])
271 for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
272 if (g_strcmp0 (defaults[i].opt, name) == 0) {
275 switch (defaults[i].opt_type) {
276 case NM_BOND_OPTION_TYPE_INT:
277 return validate_int (name, value, &defaults[i]);
278 case NM_BOND_OPTION_TYPE_STRING:
279 return validate_list (name, value, &defaults[i]);
280 case NM_BOND_OPTION_TYPE_BOTH:
281 return ( validate_int (name, value, &defaults[i])
282 || validate_list (name, value, &defaults[i]));
283 case NM_BOND_OPTION_TYPE_IP:
284 return validate_ip (name, value);
285 case NM_BOND_OPTION_TYPE_MAC:
286 return nm_utils_hwaddr_valid (value, ETH_ALEN);
287 case NM_BOND_OPTION_TYPE_IFNAME:
288 return validate_ifname (name, value);
297 * nm_setting_bond_get_option_by_name:
298 * @setting: the #NMSettingBond
299 * @name: the option name for which to retrieve the value
301 * Returns the value associated with the bonding option specified by
302 * @name, if it exists.
304 * Returns: the value, or %NULL if the key/value pair was never added to the
305 * setting; the value is owned by the setting and must not be modified
308 nm_setting_bond_get_option_by_name (NMSettingBond *setting,
311 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
313 if (!nm_setting_bond_validate_option (name, NULL))
316 return g_hash_table_lookup (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name);
320 * nm_setting_bond_add_option:
321 * @setting: the #NMSettingBond
322 * @name: name for the option
323 * @value: value for the option
325 * Add an option to the table. The option is compared to an internal list
326 * of allowed options. Option names may contain only alphanumeric characters
327 * (ie [a-zA-Z0-9]). Adding a new name replaces any existing name/value pair
328 * that may already exist.
330 * The order of how to set several options is relevant because there are options
331 * that conflict with each other.
333 * Returns: %TRUE if the option was valid and was added to the internal option
334 * list, %FALSE if it was not.
337 nm_setting_bond_add_option (NMSettingBond *setting,
341 NMSettingBondPrivate *priv;
343 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
345 if (!value || !nm_setting_bond_validate_option (name, value))
348 priv = NM_SETTING_BOND_GET_PRIVATE (setting);
350 g_hash_table_insert (priv->options, g_strdup (name), g_strdup (value));
352 if ( !strcmp (name, NM_SETTING_BOND_OPTION_MIIMON)
353 && strcmp (value, "0") != 0) {
354 g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
355 g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
356 } else if ( !strcmp (name, NM_SETTING_BOND_OPTION_ARP_INTERVAL)
357 && strcmp (value, "0") != 0) {
358 g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_MIIMON);
359 g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_DOWNDELAY);
360 g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_UPDELAY);
363 g_object_notify (G_OBJECT (setting), NM_SETTING_BOND_OPTIONS);
369 * nm_setting_bond_remove_option:
370 * @setting: the #NMSettingBond
371 * @name: name of the option to remove
373 * Remove the bonding option referenced by @name from the internal option
376 * Returns: %TRUE if the option was found and removed from the internal option
377 * list, %FALSE if it was not.
380 nm_setting_bond_remove_option (NMSettingBond *setting,
385 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
387 if (!nm_setting_bond_validate_option (name, NULL))
390 found = g_hash_table_remove (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name);
392 g_object_notify (G_OBJECT (setting), NM_SETTING_BOND_OPTIONS);
397 * nm_setting_bond_get_valid_options:
398 * @setting: the #NMSettingBond
400 * Returns a list of valid bond options.
402 * Returns: (transfer none): a %NULL-terminated array of strings of valid bond options.
405 nm_setting_bond_get_valid_options (NMSettingBond *setting)
407 static const char *array[G_N_ELEMENTS (defaults) + 1] = { NULL };
410 /* initialize the array once */
411 if (G_UNLIKELY (array[0] == NULL)) {
412 for (i = 0; i < G_N_ELEMENTS (defaults); i++)
413 array[i] = defaults[i].opt;
420 * nm_setting_bond_get_option_default:
421 * @setting: the #NMSettingBond
422 * @name: the name of the option
424 * Returns: the value of the bond option if not overridden by an entry in
425 * the #NMSettingBond:options property.
428 nm_setting_bond_get_option_default (NMSettingBond *setting, const char *name)
432 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
433 g_return_val_if_fail (nm_setting_bond_validate_option (name, NULL), NULL);
435 for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
436 if (g_strcmp0 (defaults[i].opt, name) == 0)
437 return defaults[i].val;
439 /* Any option that passes nm_setting_bond_validate_option() should also be found in defaults */
440 g_assert_not_reached ();
444 * nm_setting_bond_get_option_type:
445 * @setting: the #NMSettingBond
446 * @name: the name of the option
448 * Returns: the type of the bond option.
451 _nm_setting_bond_get_option_type (NMSettingBond *setting, const char *name)
455 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NM_BOND_OPTION_TYPE_INT);
456 g_return_val_if_fail (nm_setting_bond_validate_option (name, NULL), NM_BOND_OPTION_TYPE_INT);
458 for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
459 if (nm_streq0 (defaults[i].opt, name))
460 return defaults[i].opt_type;
462 /* Any option that passes nm_setting_bond_validate_option() should also be found in defaults */
463 g_assert_not_reached ();
467 verify (NMSetting *setting, NMConnection *connection, GError **error)
469 NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting);
471 const char *key, *value;
472 int mode, miimon = 0, arp_interval = 0;
473 int num_grat_arp = -1, num_unsol_na = -1;
474 const char *mode_orig, *mode_new;
475 const char *arp_ip_target = NULL;
476 const char *lacp_rate;
479 g_hash_table_iter_init (&iter, priv->options);
480 while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
481 if (!value[0] || !nm_setting_bond_validate_option (key, value)) {
484 NM_CONNECTION_ERROR_INVALID_PROPERTY,
485 _("invalid option '%s' or its value '%s'"),
487 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
492 value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_MIIMON);
494 miimon = atoi (value);
495 value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
497 arp_interval = atoi (value);
498 value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_NUM_GRAT_ARP);
500 num_grat_arp = atoi (value);
501 value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_NUM_UNSOL_NA);
503 num_unsol_na = atoi (value);
505 /* Can only set one of miimon and arp_interval */
506 if (miimon > 0 && arp_interval > 0) {
509 NM_CONNECTION_ERROR_INVALID_PROPERTY,
510 _("only one of '%s' and '%s' can be set"),
511 NM_SETTING_BOND_OPTION_MIIMON,
512 NM_SETTING_BOND_OPTION_ARP_INTERVAL);
513 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
517 /* Verify bond mode */
518 mode_orig = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_MODE);
522 NM_CONNECTION_ERROR_INVALID_PROPERTY,
523 _("mandatory option '%s' is missing"),
524 NM_SETTING_BOND_OPTION_MODE);
525 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
528 mode = nm_utils_bond_mode_string_to_int (mode_orig);
532 NM_CONNECTION_ERROR_INVALID_PROPERTY,
533 _("'%s' is not a valid value for '%s'"),
534 value, NM_SETTING_BOND_OPTION_MODE);
535 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
538 mode_new = nm_utils_bond_mode_int_to_string (mode);
540 /* Make sure mode is compatible with other settings */
541 if ( strcmp (mode_new, "balance-alb") == 0
542 || strcmp (mode_new, "balance-tlb") == 0) {
543 if (arp_interval > 0) {
546 NM_CONNECTION_ERROR_INVALID_PROPERTY,
547 _("'%s=%s' is incompatible with '%s > 0'"),
548 NM_SETTING_BOND_OPTION_MODE, mode_new, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
549 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
554 primary = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_PRIMARY);
555 if (strcmp (mode_new, "active-backup") == 0) {
556 if (primary && !nm_utils_iface_valid_name (primary)) {
559 NM_CONNECTION_ERROR_INVALID_PROPERTY,
560 _("'%s' is not a valid interface name for '%s' option"),
561 primary, NM_SETTING_BOND_OPTION_PRIMARY);
562 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
569 NM_CONNECTION_ERROR_INVALID_PROPERTY,
570 _("'%s' option is only valid for '%s=%s'"),
571 NM_SETTING_BOND_OPTION_PRIMARY,
572 NM_SETTING_BOND_OPTION_MODE, "active-backup");
573 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
578 if (nm_connection_get_setting_infiniband (connection)) {
579 if (strcmp (mode_new, "active-backup") != 0) {
582 NM_CONNECTION_ERROR_INVALID_PROPERTY,
583 _("'%s=%s' is not a valid configuration for '%s'"),
584 NM_SETTING_BOND_OPTION_MODE, mode_new, NM_SETTING_INFINIBAND_SETTING_NAME);
585 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
591 /* updelay and downdelay can only be used with miimon */
592 if (g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_UPDELAY)) {
595 NM_CONNECTION_ERROR_INVALID_PROPERTY,
596 _("'%s' option requires '%s' option to be set"),
597 NM_SETTING_BOND_OPTION_UPDELAY, NM_SETTING_BOND_OPTION_MIIMON);
598 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
601 if (g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_DOWNDELAY)) {
604 NM_CONNECTION_ERROR_INVALID_PROPERTY,
605 _("'%s' option requires '%s' option to be set"),
606 NM_SETTING_BOND_OPTION_DOWNDELAY, NM_SETTING_BOND_OPTION_MIIMON);
607 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
612 /* arp_ip_target can only be used with arp_interval, and must
613 * contain a comma-separated list of IPv4 addresses.
615 arp_ip_target = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
616 if (arp_interval > 0) {
621 if (!arp_ip_target) {
624 NM_CONNECTION_ERROR_INVALID_PROPERTY,
625 _("'%s' option requires '%s' option to be set"),
626 NM_SETTING_BOND_OPTION_ARP_INTERVAL, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
627 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
631 addrs = g_strsplit (arp_ip_target, ",", -1);
635 NM_CONNECTION_ERROR_INVALID_PROPERTY,
636 _("'%s' option is empty"),
637 NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
638 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
643 for (i = 0; addrs[i]; i++) {
644 if (!inet_pton (AF_INET, addrs[i], &addr)) {
647 NM_CONNECTION_ERROR_INVALID_PROPERTY,
648 _("'%s' is not a valid IPv4 address for '%s' option"),
649 NM_SETTING_BOND_OPTION_ARP_IP_TARGET, addrs[i]);
650 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
660 NM_CONNECTION_ERROR_INVALID_PROPERTY,
661 _("'%s' option requires '%s' option to be set"),
662 NM_SETTING_BOND_OPTION_ARP_IP_TARGET, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
663 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
668 lacp_rate = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_LACP_RATE);
670 && g_strcmp0 (mode_new, "802.3ad")
671 && strcmp (lacp_rate, "slow") != 0
672 && strcmp (lacp_rate, "0") != 0) {
675 NM_CONNECTION_ERROR_INVALID_PROPERTY,
676 _("'%s' option is only valid with mode '%s'"),
677 NM_SETTING_BOND_OPTION_LACP_RATE, "802.3ad");
678 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
682 if ( (num_grat_arp != -1 && num_unsol_na != -1)
683 && (num_grat_arp != num_unsol_na)) {
686 NM_CONNECTION_ERROR_INVALID_PROPERTY,
687 _("'%s' and '%s' cannot have different values"),
688 NM_SETTING_BOND_OPTION_NUM_GRAT_ARP,
689 NM_SETTING_BOND_OPTION_NUM_UNSOL_NA);
690 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
694 if (!_nm_connection_verify_required_interface_name (connection, error))
697 /* *** errors above here should be always fatal, below NORMALIZABLE_ERROR *** */
699 if (g_strcmp0 (mode_orig, mode_new) != 0) {
702 NM_CONNECTION_ERROR_INVALID_PROPERTY,
703 _("'%s' option should be string"),
704 NM_SETTING_BOND_OPTION_MODE);
705 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
706 return NM_SETTING_VERIFY_NORMALIZABLE;
713 nm_setting_bond_init (NMSettingBond *setting)
715 NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting);
717 priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
719 /* Default values: */
720 nm_setting_bond_add_option (setting, NM_SETTING_BOND_OPTION_MODE, "balance-rr");
724 finalize (GObject *object)
726 NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
728 g_hash_table_destroy (priv->options);
730 G_OBJECT_CLASS (nm_setting_bond_parent_class)->finalize (object);
734 set_property (GObject *object, guint prop_id,
735 const GValue *value, GParamSpec *pspec)
737 NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
741 g_hash_table_unref (priv->options);
742 priv->options = _nm_utils_copy_strdict (g_value_get_boxed (value));
745 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
751 get_property (GObject *object, guint prop_id,
752 GValue *value, GParamSpec *pspec)
754 NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
758 g_value_take_boxed (value, _nm_utils_copy_strdict (priv->options));
761 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
767 nm_setting_bond_class_init (NMSettingBondClass *setting_class)
769 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
770 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
772 g_type_class_add_private (setting_class, sizeof (NMSettingBondPrivate));
774 /* virtual methods */
775 object_class->set_property = set_property;
776 object_class->get_property = get_property;
777 object_class->finalize = finalize;
778 parent_class->verify = verify;
782 * NMSettingBond:options:
784 * Dictionary of key/value pairs of bonding options. Both keys and values
785 * must be strings. Option names must contain only alphanumeric characters
788 * Type: GHashTable(utf8,utf8)
792 * variable: BONDING_OPTS
793 * description: Bonding options.
794 * example: BONDING_OPTS="miimon=100 mode=broadcast"
797 g_object_class_install_property
798 (object_class, PROP_OPTIONS,
799 g_param_spec_boxed (NM_SETTING_BOND_OPTIONS, "", "",
802 NM_SETTING_PARAM_INFERRABLE |
803 G_PARAM_STATIC_STRINGS));
804 _nm_setting_class_transform_property (parent_class, NM_SETTING_BOND_OPTIONS,
805 G_VARIANT_TYPE ("a{ss}"),
806 _nm_utils_strdict_to_dbus,
807 _nm_utils_strdict_from_dbus);
810 * property: interface-name
812 * description: Deprecated in favor of connection.interface-name, but can
813 * be used for backward-compatibility with older daemons, to set the
814 * bond's interface name.
817 _nm_setting_class_add_dbus_only_property (parent_class, "interface-name",
818 G_VARIANT_TYPE_STRING,
819 _nm_setting_get_deprecated_virtual_interface_name,