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 2007 - 2014 Red Hat, Inc.
20 * Copyright 2007 - 2008 Novell, Inc.
23 #include "nm-default.h"
26 #include <net/ethernet.h>
27 #include <netinet/ether.h>
28 #include <dbus/dbus-glib.h>
30 #include "nm-setting-wired.h"
31 #include "nm-param-spec-specialized.h"
33 #include "nm-utils-private.h"
34 #include "nm-dbus-glib-types.h"
35 #include "nm-setting-private.h"
38 * SECTION:nm-setting-wired
39 * @short_description: Describes connection properties for Ethernet-based networks
40 * @include: nm-setting-wired.h
42 * The #NMSettingWired object is a #NMSetting subclass that describes properties
43 * necessary for connection to Ethernet networks.
47 * nm_setting_wired_error_quark:
49 * Registers an error quark for #NMSettingWired if necessary.
51 * Returns: the error quark used for #NMSettingWired errors.
54 nm_setting_wired_error_quark (void)
58 if (G_UNLIKELY (!quark))
59 quark = g_quark_from_static_string ("nm-setting-wired-error-quark");
64 G_DEFINE_TYPE_WITH_CODE (NMSettingWired, nm_setting_wired, NM_TYPE_SETTING,
65 _nm_register_setting (NM_SETTING_WIRED_SETTING_NAME,
68 NM_SETTING_WIRED_ERROR))
69 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRED)
71 #define NM_SETTING_WIRED_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRED, NMSettingWiredPrivate))
77 gboolean auto_negotiate;
78 GByteArray *device_mac_address;
79 GByteArray *cloned_mac_address;
80 GSList *mac_address_blacklist;
82 GPtrArray *s390_subchannels;
84 GHashTable *s390_options;
85 } NMSettingWiredPrivate;
94 PROP_CLONED_MAC_ADDRESS,
95 PROP_MAC_ADDRESS_BLACKLIST,
97 PROP_S390_SUBCHANNELS,
104 static const char *valid_s390_opts[] = {
105 "portno", "layer2", "portname", "protocol", "priority_queueing",
106 "buffer_count", "isolation", "total", "inter", "inter_jumbo", "route4",
107 "route6", "fake_broadcast", "broadcast_mode", "canonical_macaddr",
108 "checksumming", "sniffer", "large_send", "ipato_enable", "ipato_invert4",
109 "ipato_add4", "ipato_invert6", "ipato_add6", "vipa_add4", "vipa_add6",
110 "rxip_add4", "rxip_add6", "lancmd_timeout", "ctcprot",
115 * nm_setting_wired_new:
117 * Creates a new #NMSettingWired object with default values.
119 * Returns: (transfer full): the new empty #NMSettingWired object
122 nm_setting_wired_new (void)
124 return (NMSetting *) g_object_new (NM_TYPE_SETTING_WIRED, NULL);
128 * nm_setting_wired_get_port:
129 * @setting: the #NMSettingWired
131 * Returns: the #NMSettingWired:port property of the setting
134 nm_setting_wired_get_port (NMSettingWired *setting)
136 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
138 return NM_SETTING_WIRED_GET_PRIVATE (setting)->port;
142 * nm_setting_wired_get_speed:
143 * @setting: the #NMSettingWired
145 * Returns: the #NMSettingWired:speed property of the setting
148 nm_setting_wired_get_speed (NMSettingWired *setting)
150 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), 0);
152 return NM_SETTING_WIRED_GET_PRIVATE (setting)->speed;
156 * nm_setting_wired_get_duplex:
157 * @setting: the #NMSettingWired
159 * Returns: the #NMSettingWired:duplex property of the setting
162 nm_setting_wired_get_duplex (NMSettingWired *setting)
164 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
166 return NM_SETTING_WIRED_GET_PRIVATE (setting)->duplex;
170 * nm_setting_wired_get_auto_negotiate:
171 * @setting: the #NMSettingWired
173 * Returns: the #NMSettingWired:auto-negotiate property of the setting
176 nm_setting_wired_get_auto_negotiate (NMSettingWired *setting)
178 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
180 return NM_SETTING_WIRED_GET_PRIVATE (setting)->auto_negotiate;
184 * nm_setting_wired_get_mac_address:
185 * @setting: the #NMSettingWired
187 * Returns: the #NMSettingWired:mac-address property of the setting
190 nm_setting_wired_get_mac_address (NMSettingWired *setting)
192 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
194 return NM_SETTING_WIRED_GET_PRIVATE (setting)->device_mac_address;
198 * nm_setting_wired_get_cloned_mac_address:
199 * @setting: the #NMSettingWired
201 * Returns: the #NMSettingWired:cloned-mac-address property of the setting
204 nm_setting_wired_get_cloned_mac_address (NMSettingWired *setting)
206 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
208 return NM_SETTING_WIRED_GET_PRIVATE (setting)->cloned_mac_address;
212 * nm_setting_wired_get_mac_address_blacklist:
213 * @setting: the #NMSettingWired
215 * Returns: (element-type GLib.ByteArray): the #NMSettingWired:mac-address-blacklist
216 * property of the setting
219 nm_setting_wired_get_mac_address_blacklist (NMSettingWired *setting)
221 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
223 return NM_SETTING_WIRED_GET_PRIVATE (setting)->mac_address_blacklist;
227 * nm_setting_wired_get_num_mac_blacklist_items:
228 * @setting: the #NMSettingWired
230 * Returns: the number of blacklisted MAC addresses
235 nm_setting_wired_get_num_mac_blacklist_items (NMSettingWired *setting)
237 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), 0);
239 return g_slist_length (NM_SETTING_WIRED_GET_PRIVATE (setting)->mac_address_blacklist);
243 * nm_setting_wired_get_mac_blacklist_item:
244 * @setting: the #NMSettingWired
245 * @idx: the zero-based index of the MAC address entry
247 * Returns: the blacklisted MAC address string (hex-digits-and-colons notation)
253 nm_setting_wired_get_mac_blacklist_item (NMSettingWired *setting, guint32 idx)
255 NMSettingWiredPrivate *priv;
257 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
259 priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
260 g_return_val_if_fail (idx <= g_slist_length (priv->mac_address_blacklist), NULL);
262 return (const char *) g_slist_nth_data (priv->mac_address_blacklist, idx);
266 * nm_setting_wired_add_mac_blacklist_item:
267 * @setting: the #NMSettingWired
268 * @mac: the MAC address string (hex-digits-and-colons notation) to blacklist
270 * Adds a new MAC address to the #NMSettingWired:mac-address-blacklist property.
272 * Returns: %TRUE if the MAC address was added; %FALSE if the MAC address
273 * is invalid or was already present
278 nm_setting_wired_add_mac_blacklist_item (NMSettingWired *setting, const char *mac)
280 NMSettingWiredPrivate *priv;
284 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
285 g_return_val_if_fail (mac != NULL, FALSE);
287 if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf))
290 priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
291 for (iter = priv->mac_address_blacklist; iter; iter = g_slist_next (iter)) {
292 if (!strcasecmp (mac, (char *) iter->data))
296 priv->mac_address_blacklist = g_slist_append (priv->mac_address_blacklist,
297 g_ascii_strup (mac, -1));
298 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST);
303 * nm_setting_wired_remove_mac_blacklist_item:
304 * @setting: the #NMSettingWired
305 * @idx: index number of the MAC address
307 * Removes the MAC address at index @idx from the blacklist.
312 nm_setting_wired_remove_mac_blacklist_item (NMSettingWired *setting, guint32 idx)
314 NMSettingWiredPrivate *priv;
317 g_return_if_fail (NM_IS_SETTING_WIRED (setting));
319 priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
320 elt = g_slist_nth (priv->mac_address_blacklist, idx);
321 g_return_if_fail (elt != NULL);
324 priv->mac_address_blacklist = g_slist_delete_link (priv->mac_address_blacklist, elt);
325 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST);
329 * nm_setting_wired_remove_mac_blacklist_item_by_value:
330 * @setting: the #NMSettingWired
331 * @mac: the MAC address string (hex-digits-and-colons notation) to remove from
334 * Removes the MAC address @mac from the blacklist.
336 * Returns: %TRUE if the MAC address was found and removed; %FALSE if it was not.
341 nm_setting_wired_remove_mac_blacklist_item_by_value (NMSettingWired *setting, const char *mac)
343 NMSettingWiredPrivate *priv;
347 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
348 g_return_val_if_fail (mac != NULL, FALSE);
350 if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf))
353 priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
354 for (iter = priv->mac_address_blacklist; iter; iter = g_slist_next (iter)) {
355 if (!strcasecmp (mac, (char *) iter->data)) {
356 priv->mac_address_blacklist = g_slist_delete_link (priv->mac_address_blacklist, iter);
357 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST);
365 * nm_setting_wired_clear_mac_blacklist_items:
366 * @setting: the #NMSettingWired
368 * Removes all blacklisted MAC addresses.
373 nm_setting_wired_clear_mac_blacklist_items (NMSettingWired *setting)
375 g_return_if_fail (NM_IS_SETTING_WIRED (setting));
377 g_slist_free_full (NM_SETTING_WIRED_GET_PRIVATE (setting)->mac_address_blacklist, g_free);
378 NM_SETTING_WIRED_GET_PRIVATE (setting)->mac_address_blacklist = NULL;
379 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST);
383 * nm_setting_wired_get_mtu:
384 * @setting: the #NMSettingWired
386 * Returns: the #NMSettingWired:mtu property of the setting
389 nm_setting_wired_get_mtu (NMSettingWired *setting)
391 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), 0);
393 return NM_SETTING_WIRED_GET_PRIVATE (setting)->mtu;
397 * nm_setting_wired_get_s390_subchannels:
398 * @setting: the #NMSettingWired
400 * Return the list of s390 subchannels that identify the device that this
401 * connection is applicable to. The connection should only be used in
402 * conjunction with that device.
404 * Returns: (element-type utf8): #GPtrArray of strings, each specifying one
405 * subchannel the s390 device uses to communicate to the host.
408 nm_setting_wired_get_s390_subchannels (NMSettingWired *setting)
410 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
412 return NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_subchannels;
416 * nm_setting_wired_get_s390_nettype:
417 * @setting: the #NMSettingWired
419 * Returns the s390 device type this connection should apply to. Will be one
420 * of 'qeth', 'lcs', or 'ctc'.
422 * Returns: the s390 device type
425 nm_setting_wired_get_s390_nettype (NMSettingWired *setting)
427 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
429 return NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_nettype;
433 * nm_setting_wired_get_num_s390_options:
434 * @setting: the #NMSettingWired
436 * Returns the number of s390-specific options that should be set for this
437 * device when it is activated. This can be used to retrieve each s390
438 * option individually using nm_setting_wired_get_s390_option().
440 * Returns: the number of s390-specific device options
443 nm_setting_wired_get_num_s390_options (NMSettingWired *setting)
445 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), 0);
447 return g_hash_table_size (NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options);
451 * nm_setting_wired_get_s390_option:
452 * @setting: the #NMSettingWired
453 * @idx: index of the desired option, from 0 to
454 * nm_setting_wired_get_num_s390_options() - 1
455 * @out_key: (out): on return, the key name of the s390 specific option; this
456 * value is owned by the setting and should not be modified
457 * @out_value: (out): on return, the value of the key of the s390 specific
458 * option; this value is owned by the setting and should not be modified
460 * Given an index, return the value of the s390 option at that index. indexes
461 * are *not* guaranteed to be static across modifications to options done by
462 * nm_setting_wired_add_s390_option() and nm_setting_wired_remove_s390_option(),
463 * and should not be used to refer to options except for short periods of time
464 * such as during option iteration.
466 * Returns: %TRUE on success if the index was valid and an option was found,
467 * %FALSE if the index was invalid (ie, greater than the number of options
468 * currently held by the setting)
471 nm_setting_wired_get_s390_option (NMSettingWired *setting,
473 const char **out_key,
474 const char **out_value)
476 const char *_key, *_value;
480 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
482 g_hash_table_iter_init (&iter, NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options);
483 while (g_hash_table_iter_next (&iter, (gpointer) &_key, (gpointer) &_value)) {
493 g_return_val_if_reached (FALSE);
497 * nm_setting_wired_get_s390_option_by_key:
498 * @setting: the #NMSettingWired
499 * @key: the key for which to retrieve the value
501 * Returns the value associated with the s390-specific option specified by
502 * @key, if it exists.
504 * Returns: the value, or %NULL if the key/value pair was never added to the
505 * setting; the value is owned by the setting and must not be modified
508 nm_setting_wired_get_s390_option_by_key (NMSettingWired *setting,
511 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
512 g_return_val_if_fail (key != NULL, NULL);
513 g_return_val_if_fail (strlen (key), NULL);
515 return g_hash_table_lookup (NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options, key);
519 * nm_setting_wired_add_s390_option:
520 * @setting: the #NMSettingWired
521 * @key: key name for the option
522 * @value: value for the option
524 * Add an option to the table. The option is compared to an internal list
525 * of allowed options. Key names may contain only alphanumeric characters
526 * (ie [a-zA-Z0-9]). Adding a new key replaces any existing key/value pair that
529 * Returns: %TRUE if the option was valid and was added to the internal option
530 * list, %FALSE if it was not.
533 nm_setting_wired_add_s390_option (NMSettingWired *setting,
539 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
540 g_return_val_if_fail (key != NULL, FALSE);
541 g_return_val_if_fail (strlen (key), FALSE);
542 g_return_val_if_fail (_nm_utils_string_in_list (key, valid_s390_opts), FALSE);
543 g_return_val_if_fail (value != NULL, FALSE);
545 value_len = strlen (value);
546 g_return_val_if_fail (value_len > 0 && value_len < 200, FALSE);
548 g_hash_table_insert (NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options,
551 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_S390_OPTIONS);
556 * nm_setting_wired_remove_s390_option:
557 * @setting: the #NMSettingWired
558 * @key: key name for the option to remove
560 * Remove the s390-specific option referenced by @key from the internal option
563 * Returns: %TRUE if the option was found and removed from the internal option
564 * list, %FALSE if it was not.
567 nm_setting_wired_remove_s390_option (NMSettingWired *setting,
572 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
573 g_return_val_if_fail (key != NULL, FALSE);
574 g_return_val_if_fail (strlen (key), FALSE);
576 found = g_hash_table_remove (NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options, key);
578 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_S390_OPTIONS);
583 * nm_setting_wired_get_valid_s390_options:
584 * @setting: the #NMSettingWired
586 * Returns a list of valid s390 options.
588 * Returns: (transfer none): a %NULL-terminated array of strings of valid s390 options.
593 nm_setting_wired_get_valid_s390_options (NMSettingWired *setting)
595 return valid_s390_opts;
599 verify (NMSetting *setting, GSList *all_settings, GError **error)
601 NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
602 const char *valid_ports[] = { "tp", "aui", "bnc", "mii", NULL };
603 const char *valid_duplex[] = { "half", "full", NULL };
604 const char *valid_nettype[] = { "qeth", "lcs", "ctc", NULL };
606 GSList* mac_blacklist_iter;
607 const char *key, *value;
609 if (priv->port && !_nm_utils_string_in_list (priv->port, valid_ports)) {
611 NM_SETTING_WIRED_ERROR,
612 NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
613 _("'%s' is not a valid Ethernet port value"),
615 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_PORT);
619 if (priv->duplex && !_nm_utils_string_in_list (priv->duplex, valid_duplex)) {
621 NM_SETTING_WIRED_ERROR,
622 NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
623 _("'%s' is not a valid duplex value"),
625 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_DUPLEX);
629 if (priv->device_mac_address && priv->device_mac_address->len != ETH_ALEN) {
630 g_set_error_literal (error,
631 NM_SETTING_WIRED_ERROR,
632 NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
633 _("is not a valid MAC address"));
634 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS);
638 for (mac_blacklist_iter = priv->mac_address_blacklist; mac_blacklist_iter;
639 mac_blacklist_iter = mac_blacklist_iter->next) {
640 struct ether_addr addr;
642 if (!ether_aton_r (mac_blacklist_iter->data, &addr)) {
644 NM_SETTING_WIRED_ERROR,
645 NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
646 _("'%s' is not a valid MAC address"),
647 (const char *) mac_blacklist_iter->data);
648 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST);
653 if ( priv->s390_subchannels
654 && !(priv->s390_subchannels->len == 3 || priv->s390_subchannels->len == 2)) {
655 g_set_error_literal (error,
656 NM_SETTING_WIRED_ERROR,
657 NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
658 _("property is invalid"));
659 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_SUBCHANNELS);
663 if (priv->s390_nettype && !_nm_utils_string_in_list (priv->s390_nettype, valid_nettype)) {
664 g_set_error_literal (error,
665 NM_SETTING_WIRED_ERROR,
666 NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
667 _("property is invalid"));
668 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_NETTYPE);
672 g_hash_table_iter_init (&iter, priv->s390_options);
673 while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
674 if ( !_nm_utils_string_in_list (key, valid_s390_opts)
676 || (strlen (value) > 200)) {
678 NM_SETTING_WIRED_ERROR,
679 NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
680 _("invalid '%s' or its value '%s'"),
682 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_OPTIONS);
687 if (priv->cloned_mac_address && priv->cloned_mac_address->len != ETH_ALEN) {
688 g_set_error_literal (error,
689 NM_SETTING_WIRED_ERROR,
690 NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
691 _("is not a valid MAC address"));
692 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_CLONED_MAC_ADDRESS);
700 nm_setting_wired_init (NMSettingWired *setting)
702 NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
704 priv->s390_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
708 finalize (GObject *object)
710 NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (object);
713 g_free (priv->duplex);
714 g_free (priv->s390_nettype);
716 g_hash_table_destroy (priv->s390_options);
718 if (priv->device_mac_address)
719 g_byte_array_free (priv->device_mac_address, TRUE);
721 if (priv->cloned_mac_address)
722 g_byte_array_free (priv->cloned_mac_address, TRUE);
724 g_slist_free_full (priv->mac_address_blacklist, g_free);
726 if (priv->s390_subchannels) {
727 g_ptr_array_set_free_func (priv->s390_subchannels, g_free);
728 g_ptr_array_free (priv->s390_subchannels, TRUE);
731 G_OBJECT_CLASS (nm_setting_wired_parent_class)->finalize (object);
735 copy_hash (gpointer key, gpointer value, gpointer user_data)
737 g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), g_strdup (value));
741 set_property (GObject *object, guint prop_id,
742 const GValue *value, GParamSpec *pspec)
744 NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (object);
745 GHashTable *new_hash;
750 priv->port = g_value_dup_string (value);
753 priv->speed = g_value_get_uint (value);
756 g_free (priv->duplex);
757 priv->duplex = g_value_dup_string (value);
759 case PROP_AUTO_NEGOTIATE:
760 priv->auto_negotiate = g_value_get_boolean (value);
762 case PROP_MAC_ADDRESS:
763 if (priv->device_mac_address)
764 g_byte_array_free (priv->device_mac_address, TRUE);
765 priv->device_mac_address = g_value_dup_boxed (value);
767 case PROP_CLONED_MAC_ADDRESS:
768 if (priv->cloned_mac_address)
769 g_byte_array_free (priv->cloned_mac_address, TRUE);
770 priv->cloned_mac_address = g_value_dup_boxed (value);
772 case PROP_MAC_ADDRESS_BLACKLIST:
773 g_slist_free_full (priv->mac_address_blacklist, g_free);
774 priv->mac_address_blacklist = g_value_dup_boxed (value);
777 priv->mtu = g_value_get_uint (value);
779 case PROP_S390_SUBCHANNELS:
780 if (priv->s390_subchannels) {
781 g_ptr_array_set_free_func (priv->s390_subchannels, g_free);
782 g_ptr_array_free (priv->s390_subchannels, TRUE);
784 priv->s390_subchannels = g_value_dup_boxed (value);
786 case PROP_S390_NETTYPE:
787 g_free (priv->s390_nettype);
788 priv->s390_nettype = g_value_dup_string (value);
790 case PROP_S390_OPTIONS:
791 /* Must make a deep copy of the hash table here... */
792 g_hash_table_remove_all (priv->s390_options);
793 new_hash = g_value_get_boxed (value);
795 g_hash_table_foreach (new_hash, copy_hash, priv->s390_options);
798 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
804 get_property (GObject *object, guint prop_id,
805 GValue *value, GParamSpec *pspec)
807 NMSettingWired *setting = NM_SETTING_WIRED (object);
808 NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
812 g_value_set_string (value, nm_setting_wired_get_port (setting));
815 g_value_set_uint (value, nm_setting_wired_get_speed (setting));
818 g_value_set_string (value, nm_setting_wired_get_duplex (setting));
820 case PROP_AUTO_NEGOTIATE:
821 g_value_set_boolean (value, nm_setting_wired_get_auto_negotiate (setting));
823 case PROP_MAC_ADDRESS:
824 g_value_set_boxed (value, nm_setting_wired_get_mac_address (setting));
826 case PROP_CLONED_MAC_ADDRESS:
827 g_value_set_boxed (value, nm_setting_wired_get_cloned_mac_address (setting));
829 case PROP_MAC_ADDRESS_BLACKLIST:
830 g_value_set_boxed (value, nm_setting_wired_get_mac_address_blacklist (setting));
833 g_value_set_uint (value, nm_setting_wired_get_mtu (setting));
835 case PROP_S390_SUBCHANNELS:
836 g_value_set_boxed (value, nm_setting_wired_get_s390_subchannels (setting));
838 case PROP_S390_NETTYPE:
839 g_value_set_string (value, nm_setting_wired_get_s390_nettype (setting));
841 case PROP_S390_OPTIONS:
842 g_value_set_boxed (value, priv->s390_options);
845 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
851 nm_setting_wired_class_init (NMSettingWiredClass *setting_class)
853 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
854 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
856 g_type_class_add_private (setting_class, sizeof (NMSettingWiredPrivate));
858 /* virtual methods */
859 object_class->set_property = set_property;
860 object_class->get_property = get_property;
861 object_class->finalize = finalize;
862 parent_class->verify = verify;
866 * NMSettingWired:port:
868 * Specific port type to use if multiple the device supports multiple
869 * attachment methods. One of "tp" (Twisted Pair), "aui" (Attachment Unit
870 * Interface), "bnc" (Thin Ethernet) or "mii" (Media Independent Interface.
871 * If the device supports only one port type, this setting is ignored.
873 g_object_class_install_property
874 (object_class, PROP_PORT,
875 g_param_spec_string (NM_SETTING_WIRED_PORT, "", "",
878 G_PARAM_STATIC_STRINGS));
881 * NMSettingWired:speed:
883 * If non-zero, request that the device use only the specified speed. In
884 * Mbit/s, ie 100 == 100Mbit/s.
886 g_object_class_install_property
887 (object_class, PROP_SPEED,
888 g_param_spec_uint (NM_SETTING_WIRED_SPEED, "", "",
892 G_PARAM_STATIC_STRINGS));
895 * NMSettingWired:duplex:
897 * If specified, request that the device only use the specified duplex mode.
898 * Either "half" or "full".
900 g_object_class_install_property
901 (object_class, PROP_DUPLEX,
902 g_param_spec_string (NM_SETTING_WIRED_DUPLEX, "", "",
905 G_PARAM_STATIC_STRINGS));
908 * NMSettingWired:auto-negotiate:
910 * If %TRUE, allow auto-negotiation of port speed and duplex mode. If
911 * %FALSE, do not allow auto-negotiation, in which case the "speed" and
912 * "duplex" properties should be set.
914 g_object_class_install_property
915 (object_class, PROP_AUTO_NEGOTIATE,
916 g_param_spec_boolean (NM_SETTING_WIRED_AUTO_NEGOTIATE, "", "",
920 G_PARAM_STATIC_STRINGS));
923 * NMSettingWired:mac-address:
925 * If specified, this connection will only apply to the Ethernet device
926 * whose permanent MAC address matches. This property does not change the
927 * MAC address of the device (i.e. MAC spoofing).
929 g_object_class_install_property
930 (object_class, PROP_MAC_ADDRESS,
931 _nm_param_spec_specialized (NM_SETTING_WIRED_MAC_ADDRESS, "", "",
932 DBUS_TYPE_G_UCHAR_ARRAY,
934 NM_SETTING_PARAM_INFERRABLE |
935 G_PARAM_STATIC_STRINGS));
938 * NMSettingWired:cloned-mac-address:
940 * If specified, request that the device use this MAC address instead of its
941 * permanent MAC address. This is known as MAC cloning or spoofing.
943 g_object_class_install_property
944 (object_class, PROP_CLONED_MAC_ADDRESS,
945 _nm_param_spec_specialized (NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "", "",
946 DBUS_TYPE_G_UCHAR_ARRAY,
948 NM_SETTING_PARAM_INFERRABLE |
949 G_PARAM_STATIC_STRINGS));
952 * NMSettingWired:mac-address-blacklist:
954 * If specified, this connection will never apply to the Ethernet device
955 * whose permanent MAC address matches an address in the list. Each MAC
956 * address is in the standard hex-digits-and-colons notation
957 * (00:11:22:33:44:55).
959 g_object_class_install_property
960 (object_class, PROP_MAC_ADDRESS_BLACKLIST,
961 _nm_param_spec_specialized (NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST, "", "",
962 DBUS_TYPE_G_LIST_OF_STRING,
964 NM_SETTING_PARAM_FUZZY_IGNORE |
965 G_PARAM_STATIC_STRINGS));
968 * NMSettingWired:mtu:
970 * If non-zero, only transmit packets of the specified size or smaller,
971 * breaking larger packets up into multiple Ethernet frames.
973 g_object_class_install_property
974 (object_class, PROP_MTU,
975 g_param_spec_uint (NM_SETTING_WIRED_MTU, "", "",
979 NM_SETTING_PARAM_FUZZY_IGNORE |
980 G_PARAM_STATIC_STRINGS));
983 * NMSettingWired:s390-subchannels:
985 * Identifies specific subchannels that this network device uses for
986 * communication with z/VM or s390 host. Like the
987 * #NMSettingWired:mac-address property for non-z/VM devices, this property
988 * can be used to ensure this connection only applies to the network device
989 * that uses these subchannels. The list should contain exactly 3 strings,
990 * and each string may only be composed of hexadecimal characters and the
991 * period (.) character.
993 g_object_class_install_property
994 (object_class, PROP_S390_SUBCHANNELS,
995 _nm_param_spec_specialized (NM_SETTING_WIRED_S390_SUBCHANNELS, "", "",
996 DBUS_TYPE_G_ARRAY_OF_STRING,
998 NM_SETTING_PARAM_INFERRABLE |
999 G_PARAM_STATIC_STRINGS));
1002 * NMSettingWired:s390-nettype:
1004 * s390 network device type; one of "qeth", "lcs", or "ctc", representing
1005 * the different types of virtual network devices available on s390 systems.
1007 g_object_class_install_property
1008 (object_class, PROP_S390_NETTYPE,
1009 g_param_spec_string (NM_SETTING_WIRED_S390_NETTYPE, "", "",
1012 NM_SETTING_PARAM_INFERRABLE |
1013 G_PARAM_STATIC_STRINGS));
1016 * NMSettingWired:s390-options:
1018 * Dictionary of key/value pairs of s390-specific device options. Both keys
1019 * and values must be strings. Allowed keys include "portno", "layer2",
1020 * "portname", "protocol", among others. Key names must contain only
1021 * alphanumeric characters (ie, [a-zA-Z0-9]).
1023 g_object_class_install_property
1024 (object_class, PROP_S390_OPTIONS,
1025 _nm_param_spec_specialized (NM_SETTING_WIRED_S390_OPTIONS, "", "",
1026 DBUS_TYPE_G_MAP_OF_STRING,
1028 NM_SETTING_PARAM_INFERRABLE |
1029 G_PARAM_STATIC_STRINGS));