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>
29 #include <dbus/dbus-glib.h>
31 #include "nm-setting-bond.h"
32 #include "nm-param-spec-specialized.h"
34 #include "nm-utils-private.h"
35 #include "nm-dbus-glib-types.h"
36 #include "nm-setting-private.h"
39 * SECTION:nm-setting-bond
40 * @short_description: Describes connection properties for bonds
41 * @include: nm-setting-bond.h
43 * The #NMSettingBond object is a #NMSetting subclass that describes properties
44 * necessary for bond connections.
48 * nm_setting_bond_error_quark:
50 * Registers an error quark for #NMSettingBond if necessary.
52 * Returns: the error quark used for #NMSettingBond errors.
55 nm_setting_bond_error_quark (void)
59 if (G_UNLIKELY (!quark))
60 quark = g_quark_from_static_string ("nm-setting-bond-error-quark");
65 G_DEFINE_TYPE_WITH_CODE (NMSettingBond, nm_setting_bond, NM_TYPE_SETTING,
66 _nm_register_setting (NM_SETTING_BOND_SETTING_NAME,
69 NM_SETTING_BOND_ERROR))
70 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BOND)
72 #define NM_SETTING_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BOND, NMSettingBondPrivate))
77 } NMSettingBondPrivate;
103 static const BondDefault defaults[] = {
104 { NM_SETTING_BOND_OPTION_MODE, "balance-rr", TYPE_BOTH, 0, 6,
105 { "balance-rr", "active-backup", "balance-xor", "broadcast", "802.3ad", "balance-tlb", "balance-alb", NULL } },
106 { NM_SETTING_BOND_OPTION_MIIMON, "100", TYPE_INT, 0, G_MAXINT },
107 { NM_SETTING_BOND_OPTION_DOWNDELAY, "0", TYPE_INT, 0, G_MAXINT },
108 { NM_SETTING_BOND_OPTION_UPDELAY, "0", TYPE_INT, 0, G_MAXINT },
109 { NM_SETTING_BOND_OPTION_ARP_INTERVAL, "0", TYPE_INT, 0, G_MAXINT },
110 { NM_SETTING_BOND_OPTION_ARP_IP_TARGET, "", TYPE_IP },
111 { NM_SETTING_BOND_OPTION_ARP_VALIDATE, "0", TYPE_BOTH, 0, 3,
112 { "none", "active", "backup", "all", NULL } },
113 { NM_SETTING_BOND_OPTION_PRIMARY, "", TYPE_IFNAME },
114 { NM_SETTING_BOND_OPTION_PRIMARY_RESELECT, "0", TYPE_BOTH, 0, 2,
115 { "always", "better", "failure", NULL } },
116 { NM_SETTING_BOND_OPTION_FAIL_OVER_MAC, "0", TYPE_BOTH, 0, 2,
117 { "none", "active", "follow", NULL } },
118 { NM_SETTING_BOND_OPTION_USE_CARRIER, "1", TYPE_INT, 0, 1 },
119 { NM_SETTING_BOND_OPTION_AD_SELECT, "0", TYPE_BOTH, 0, 2,
120 { "stable", "bandwidth", "count", NULL } },
121 { NM_SETTING_BOND_OPTION_XMIT_HASH_POLICY, "0", TYPE_BOTH, 0, 2,
122 { "layer2", "layer3+4", "layer2+3", NULL } },
123 { NM_SETTING_BOND_OPTION_RESEND_IGMP, "1", TYPE_INT, 0, 255 },
124 { NM_SETTING_BOND_OPTION_LACP_RATE, "0", TYPE_BOTH, 0, 1,
125 { "slow", "fast", NULL } },
129 * nm_setting_bond_new:
131 * Creates a new #NMSettingBond object with default values.
133 * Returns: (transfer full): the new empty #NMSettingBond object
136 nm_setting_bond_new (void)
138 return (NMSetting *) g_object_new (NM_TYPE_SETTING_BOND, NULL);
142 * nm_setting_bond_get_interface_name:
143 * @setting: the #NMSettingBond
145 * Returns: the #NMSettingBond:interface-name property of the setting
148 nm_setting_bond_get_interface_name (NMSettingBond *setting)
150 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
152 return NM_SETTING_BOND_GET_PRIVATE (setting)->interface_name;
156 * nm_setting_bond_get_num_options:
157 * @setting: the #NMSettingBond
159 * Returns the number of options that should be set for this bond when it
160 * is activated. This can be used to retrieve each option individually
161 * using nm_setting_bond_get_option().
163 * Returns: the number of bonding options
166 nm_setting_bond_get_num_options (NMSettingBond *setting)
168 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);
170 return g_hash_table_size (NM_SETTING_BOND_GET_PRIVATE (setting)->options);
174 * nm_setting_bond_get_option:
175 * @setting: the #NMSettingBond
176 * @idx: index of the desired option, from 0 to
177 * nm_setting_bond_get_num_options() - 1
178 * @out_name: (out): on return, the name of the bonding option; this
179 * value is owned by the setting and should not be modified
180 * @out_value: (out): on return, the value of the name of the bonding
181 * option; this value is owned by the setting and should not be modified
183 * Given an index, return the value of the bonding option at that index. Indexes
184 * are *not* guaranteed to be static across modifications to options done by
185 * nm_setting_bond_add_option() and nm_setting_bond_remove_option(),
186 * and should not be used to refer to options except for short periods of time
187 * such as during option iteration.
189 * Returns: %TRUE on success if the index was valid and an option was found,
190 * %FALSE if the index was invalid (ie, greater than the number of options
191 * currently held by the setting)
194 nm_setting_bond_get_option (NMSettingBond *setting,
196 const char **out_name,
197 const char **out_value)
199 NMSettingBondPrivate *priv;
201 const char *_key = NULL, *_value = NULL;
203 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
205 priv = NM_SETTING_BOND_GET_PRIVATE (setting);
207 if (idx >= nm_setting_bond_get_num_options (setting))
210 keys = g_hash_table_get_keys (priv->options);
211 _key = g_list_nth_data (keys, idx);
212 _value = g_hash_table_lookup (priv->options, _key);
224 validate_int (const char *name, const char *value, const BondDefault *def)
229 for (i = 0; i < strlen (value); i++) {
230 if (!g_ascii_isdigit (value[i]) && value[i] != '-')
235 num = strtol (value, NULL, 10);
238 if (num < def->min || num > def->max)
245 validate_list (const char *name, const char *value, const BondDefault *def)
249 for (i = 0; i < G_N_ELEMENTS (def->list) && def->list[i]; i++) {
250 if (g_strcmp0 (def->list[i], value) == 0)
254 /* empty validation list means all values pass */
255 return def->list[0] == NULL ? TRUE : FALSE;
259 validate_ip (const char *name, const char *value)
262 gboolean success = TRUE;
265 if (!value || !value[0])
268 ips = g_strsplit_set (value, ",", 0);
269 for (iter = ips; iter && *iter && success; iter++)
270 success = !!inet_aton (*iter, &addr);
277 validate_ifname (const char *name, const char *value)
279 if (!value || !value[0])
282 return nm_utils_iface_valid_name (value);
286 * nm_setting_bond_validate_option:
287 * @name: the name of the option to validate
288 * @value: the value of the option to validate
290 * Checks whether @name is a valid bond option and @value is a valid value for
291 * the @name. If @value is %NULL, the function only validates the option name.
293 * Returns: %TRUE, if the @value is valid for the given name.
294 * If the @name is not a valid option, %FALSE will be returned.
299 nm_setting_bond_validate_option (const char *name,
304 if (!name || !name[0])
307 for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
308 if (g_strcmp0 (defaults[i].opt, name) == 0) {
311 switch (defaults[i].opt_type) {
313 return validate_int (name, value, &defaults[i]);
315 return validate_list (name, value, &defaults[i]);
317 return ( validate_int (name, value, &defaults[i])
318 || validate_list (name, value, &defaults[i]));
320 return validate_ip (name, value);
322 return validate_ifname (name, value);
331 * nm_setting_bond_get_option_by_name:
332 * @setting: the #NMSettingBond
333 * @name: the option name for which to retrieve the value
335 * Returns the value associated with the bonding option specified by
336 * @name, if it exists.
338 * Returns: the value, or %NULL if the key/value pair was never added to the
339 * setting; the value is owned by the setting and must not be modified
342 nm_setting_bond_get_option_by_name (NMSettingBond *setting,
345 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
347 if (!nm_setting_bond_validate_option (name, NULL))
350 return g_hash_table_lookup (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name);
354 * nm_setting_bond_add_option:
355 * @setting: the #NMSettingBond
356 * @name: name for the option
357 * @value: value for the option
359 * Add an option to the table. The option is compared to an internal list
360 * of allowed options. Option names may contain only alphanumeric characters
361 * (ie [a-zA-Z0-9]). Adding a new name replaces any existing name/value pair
362 * that may already exist.
364 * The order of how to set several options is relevant because there are options
365 * that conflict with each other.
367 * Returns: %TRUE if the option was valid and was added to the internal option
368 * list, %FALSE if it was not.
371 nm_setting_bond_add_option (NMSettingBond *setting,
375 NMSettingBondPrivate *priv;
377 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
379 if (!value || !nm_setting_bond_validate_option (name, value))
382 priv = NM_SETTING_BOND_GET_PRIVATE (setting);
384 g_hash_table_insert (priv->options, g_strdup (name), g_strdup (value));
386 if ( !strcmp (name, NM_SETTING_BOND_OPTION_MIIMON)
387 && strcmp (value, "0") != 0) {
388 g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
389 g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
390 } else if ( !strcmp (name, NM_SETTING_BOND_OPTION_ARP_INTERVAL)
391 && strcmp (value, "0") != 0) {
392 g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_MIIMON);
393 g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_DOWNDELAY);
394 g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_UPDELAY);
397 g_object_notify (G_OBJECT (setting), NM_SETTING_BOND_OPTIONS);
403 * nm_setting_bond_remove_option:
404 * @setting: the #NMSettingBond
405 * @name: name of the option to remove
407 * Remove the bonding option referenced by @name from the internal option
410 * Returns: %TRUE if the option was found and removed from the internal option
411 * list, %FALSE if it was not.
414 nm_setting_bond_remove_option (NMSettingBond *setting,
419 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
421 if (!nm_setting_bond_validate_option (name, NULL))
424 found = g_hash_table_remove (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name);
426 g_object_notify (G_OBJECT (setting), NM_SETTING_BOND_OPTIONS);
431 * nm_setting_bond_get_valid_options:
432 * @setting: the #NMSettingBond
434 * Returns a list of valid bond options.
436 * Returns: (transfer none): a %NULL-terminated array of strings of valid bond options.
439 nm_setting_bond_get_valid_options (NMSettingBond *setting)
441 static const char *array[G_N_ELEMENTS (defaults) + 1] = { NULL };
444 /* initialize the array once */
445 if (G_UNLIKELY (array[0] == NULL)) {
446 for (i = 0; i < G_N_ELEMENTS (defaults); i++)
447 array[i] = defaults[i].opt;
454 * nm_setting_bond_get_option_default:
455 * @setting: the #NMSettingBond
456 * @name: the name of the option
458 * Returns: the value of the bond option if not overridden by an entry in
459 * the #NMSettingBond:options property.
462 nm_setting_bond_get_option_default (NMSettingBond *setting, const char *name)
466 g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
467 g_return_val_if_fail (nm_setting_bond_validate_option (name, NULL), NULL);
469 for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
470 if (g_strcmp0 (defaults[i].opt, name) == 0)
471 return defaults[i].val;
473 /* Any option that passes nm_setting_bond_validate_option() should also be found in defaults */
474 g_assert_not_reached ();
478 verify (NMSetting *setting, GSList *all_settings, GError **error)
480 NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting);
482 const char *key, *value;
483 const char *valid_modes[] = { "balance-rr",
491 int miimon = 0, arp_interval = 0;
492 const char *arp_ip_target = NULL;
493 const char *lacp_rate;
496 g_hash_table_iter_init (&iter, priv->options);
497 while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
498 if (!value[0] || !nm_setting_bond_validate_option (key, value)) {
500 NM_SETTING_BOND_ERROR,
501 NM_SETTING_BOND_ERROR_INVALID_OPTION,
502 _("invalid option '%s' or its value '%s'"),
504 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
509 value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_MIIMON);
511 miimon = atoi (value);
512 value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
514 arp_interval = atoi (value);
516 /* Can only set one of miimon and arp_interval */
517 if (miimon > 0 && arp_interval > 0) {
519 NM_SETTING_BOND_ERROR,
520 NM_SETTING_BOND_ERROR_INVALID_OPTION,
521 _("only one of '%s' and '%s' can be set"),
522 NM_SETTING_BOND_OPTION_MIIMON,
523 NM_SETTING_BOND_OPTION_ARP_INTERVAL);
524 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
527 value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_MODE);
530 NM_SETTING_BOND_ERROR,
531 NM_SETTING_BOND_ERROR_MISSING_OPTION,
532 _("mandatory option '%s' is missing"),
533 NM_SETTING_BOND_OPTION_MODE);
534 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
537 if (!_nm_utils_string_in_list (value, valid_modes)) {
539 NM_SETTING_BOND_ERROR,
540 NM_SETTING_BOND_ERROR_INVALID_OPTION,
541 _("'%s' is not a valid value for '%s'"),
542 value, NM_SETTING_BOND_OPTION_MODE);
543 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
547 /* Make sure mode is compatible with other settings */
548 if ( strcmp (value, "balance-alb") == 0
549 || strcmp (value, "balance-tlb") == 0) {
550 if (arp_interval > 0) {
552 NM_SETTING_BOND_ERROR,
553 NM_SETTING_BOND_ERROR_INVALID_OPTION,
554 _("'%s=%s' is incompatible with '%s > 0'"),
555 NM_SETTING_BOND_OPTION_MODE, value, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
556 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
561 primary = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_PRIMARY);
562 if (strcmp (value, "active-backup") == 0) {
563 if (primary && !nm_utils_iface_valid_name (primary)) {
565 NM_SETTING_BOND_ERROR,
566 NM_SETTING_BOND_ERROR_INVALID_OPTION,
567 _("'%s' is not a valid interface name for '%s' option"),
568 primary, NM_SETTING_BOND_OPTION_PRIMARY);
569 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
575 NM_SETTING_BOND_ERROR,
576 NM_SETTING_BOND_ERROR_INVALID_OPTION,
577 _("'%s' option is only valid for '%s=%s'"),
578 NM_SETTING_BOND_OPTION_PRIMARY,
579 NM_SETTING_BOND_OPTION_MODE, "active-backup");
580 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
585 if (nm_setting_find_in_list (all_settings, NM_SETTING_INFINIBAND_SETTING_NAME)) {
586 if (strcmp (value, "active-backup") != 0) {
588 NM_SETTING_BOND_ERROR,
589 NM_SETTING_BOND_ERROR_INVALID_OPTION,
590 _("'%s=%s' is not a valid configuration for '%s'"),
591 NM_SETTING_BOND_OPTION_MODE, value, NM_SETTING_INFINIBAND_SETTING_NAME);
592 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
598 /* updelay and downdelay can only be used with miimon */
599 if (g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_UPDELAY)) {
601 NM_SETTING_BOND_ERROR,
602 NM_SETTING_BOND_ERROR_INVALID_OPTION,
603 _("'%s' option requires '%s' option to be set"),
604 NM_SETTING_BOND_OPTION_UPDELAY, NM_SETTING_BOND_OPTION_MIIMON);
605 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
608 if (g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_DOWNDELAY)) {
610 NM_SETTING_BOND_ERROR,
611 NM_SETTING_BOND_ERROR_INVALID_OPTION,
612 _("'%s' option requires '%s' option to be set"),
613 NM_SETTING_BOND_OPTION_DOWNDELAY, NM_SETTING_BOND_OPTION_MIIMON);
614 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
619 /* arp_ip_target can only be used with arp_interval, and must
620 * contain a comma-separated list of IPv4 addresses.
622 arp_ip_target = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
623 if (arp_interval > 0) {
628 if (!arp_ip_target) {
630 NM_SETTING_BOND_ERROR,
631 NM_SETTING_BOND_ERROR_MISSING_OPTION,
632 _("'%s' option requires '%s' option to be set"),
633 NM_SETTING_BOND_OPTION_ARP_INTERVAL, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
634 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
638 addrs = g_strsplit (arp_ip_target, ",", -1);
641 NM_SETTING_BOND_ERROR,
642 NM_SETTING_BOND_ERROR_INVALID_OPTION,
643 _("'%s' option is empty"),
644 NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
645 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
650 for (i = 0; addrs[i]; i++) {
651 if (!inet_pton (AF_INET, addrs[i], &addr)) {
653 NM_SETTING_BOND_ERROR,
654 NM_SETTING_BOND_ERROR_INVALID_OPTION,
655 _("'%s' is not a valid IPv4 address for '%s' option"),
656 NM_SETTING_BOND_OPTION_ARP_IP_TARGET, addrs[i]);
657 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
666 NM_SETTING_BOND_ERROR,
667 NM_SETTING_BOND_ERROR_INVALID_OPTION,
668 _("'%s' option requires '%s' option to be set"),
669 NM_SETTING_BOND_OPTION_ARP_IP_TARGET, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
670 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
675 lacp_rate = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_LACP_RATE);
677 && (g_strcmp0 (value, "802.3ad") != 0 && g_strcmp0 (value, "4") != 0)
678 && (strcmp (lacp_rate, "slow") != 0 && strcmp (lacp_rate, "0") != 0)) {
680 NM_SETTING_BOND_ERROR,
681 NM_SETTING_BOND_ERROR_INVALID_OPTION,
682 _("'%s' option is only valid with mode '%s'"),
683 NM_SETTING_BOND_OPTION_LACP_RATE, "802.3ad");
684 g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
688 return _nm_setting_verify_deprecated_virtual_iface_name (
689 priv->interface_name, FALSE,
690 NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_INTERFACE_NAME,
691 NM_SETTING_BOND_ERROR,
692 NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
693 NM_SETTING_BOND_ERROR_MISSING_PROPERTY,
694 all_settings, error);
698 get_virtual_iface_name (NMSetting *setting)
700 NMSettingBond *self = NM_SETTING_BOND (setting);
702 return nm_setting_bond_get_interface_name (self);
706 nm_setting_bond_init (NMSettingBond *setting)
708 NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting);
710 priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
712 /* Default values: */
713 nm_setting_bond_add_option (setting, NM_SETTING_BOND_OPTION_MODE, "balance-rr");
717 finalize (GObject *object)
719 NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
721 g_free (priv->interface_name);
722 g_hash_table_destroy (priv->options);
724 G_OBJECT_CLASS (nm_setting_bond_parent_class)->finalize (object);
728 copy_hash (gpointer key, gpointer value, gpointer user_data)
730 g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), g_strdup (value));
734 set_property (GObject *object, guint prop_id,
735 const GValue *value, GParamSpec *pspec)
737 NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
738 GHashTable *new_hash;
741 case PROP_INTERFACE_NAME:
742 g_free (priv->interface_name);
743 priv->interface_name = g_value_dup_string (value);
746 /* Must make a deep copy of the hash table here... */
747 g_hash_table_remove_all (priv->options);
748 new_hash = g_value_get_boxed (value);
750 g_hash_table_foreach (new_hash, copy_hash, priv->options);
753 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
759 get_property (GObject *object, guint prop_id,
760 GValue *value, GParamSpec *pspec)
762 NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
763 NMSettingBond *setting = NM_SETTING_BOND (object);
766 case PROP_INTERFACE_NAME:
767 g_value_set_string (value, nm_setting_bond_get_interface_name (setting));
770 g_value_set_boxed (value, priv->options);
773 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
779 nm_setting_bond_class_init (NMSettingBondClass *setting_class)
781 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
782 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
784 g_type_class_add_private (setting_class, sizeof (NMSettingBondPrivate));
786 /* virtual methods */
787 object_class->set_property = set_property;
788 object_class->get_property = get_property;
789 object_class->finalize = finalize;
790 parent_class->verify = verify;
791 parent_class->get_virtual_iface_name = get_virtual_iface_name;
795 * NMSettingBond:interface-name:
797 * The name of the virtual in-kernel bonding network interface
799 g_object_class_install_property
800 (object_class, PROP_INTERFACE_NAME,
801 g_param_spec_string (NM_SETTING_BOND_INTERFACE_NAME, "", "",
804 NM_SETTING_PARAM_INFERRABLE |
805 G_PARAM_STATIC_STRINGS));
808 * NMSettingBond:options:
810 * Dictionary of key/value pairs of bonding options. Both keys and values
811 * must be strings. Option names must contain only alphanumeric characters
814 g_object_class_install_property
815 (object_class, PROP_OPTIONS,
816 _nm_param_spec_specialized (NM_SETTING_BOND_OPTIONS, "", "",
817 DBUS_TYPE_G_MAP_OF_STRING,
819 NM_SETTING_PARAM_INFERRABLE |
820 G_PARAM_STATIC_STRINGS));