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"
25 #include "nm-setting-wired.h"
28 #include <net/ethernet.h>
31 #include "nm-utils-private.h"
32 #include "nm-setting-private.h"
35 * SECTION:nm-setting-wired
36 * @short_description: Describes connection properties for Ethernet-based networks
38 * The #NMSettingWired object is a #NMSetting subclass that describes properties
39 * necessary for connection to Ethernet networks.
42 G_DEFINE_TYPE_WITH_CODE (NMSettingWired, nm_setting_wired, NM_TYPE_SETTING,
43 _nm_register_setting (WIRED, 1))
44 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRED)
46 #define NM_SETTING_WIRED_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRED, NMSettingWiredPrivate))
52 gboolean auto_negotiate;
53 char *device_mac_address;
54 char *cloned_mac_address;
55 GArray *mac_address_blacklist;
57 char **s390_subchannels;
59 GHashTable *s390_options;
60 NMSettingWiredWakeOnLan wol;
62 } NMSettingWiredPrivate;
71 PROP_CLONED_MAC_ADDRESS,
72 PROP_MAC_ADDRESS_BLACKLIST,
74 PROP_S390_SUBCHANNELS,
78 PROP_WAKE_ON_LAN_PASSWORD,
83 static const char *valid_s390_opts[] = {
84 "portno", "layer2", "portname", "protocol", "priority_queueing",
85 "buffer_count", "isolation", "total", "inter", "inter_jumbo", "route4",
86 "route6", "fake_broadcast", "broadcast_mode", "canonical_macaddr",
87 "checksumming", "sniffer", "large_send", "ipato_enable", "ipato_invert4",
88 "ipato_add4", "ipato_invert6", "ipato_add6", "vipa_add4", "vipa_add6",
89 "rxip_add4", "rxip_add6", "lancmd_timeout", "ctcprot",
94 * nm_setting_wired_new:
96 * Creates a new #NMSettingWired object with default values.
98 * Returns: (transfer full): the new empty #NMSettingWired object
101 nm_setting_wired_new (void)
103 return (NMSetting *) g_object_new (NM_TYPE_SETTING_WIRED, NULL);
107 * nm_setting_wired_get_port:
108 * @setting: the #NMSettingWired
110 * Returns: the #NMSettingWired:port property of the setting
113 nm_setting_wired_get_port (NMSettingWired *setting)
115 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
117 return NM_SETTING_WIRED_GET_PRIVATE (setting)->port;
121 * nm_setting_wired_get_speed:
122 * @setting: the #NMSettingWired
124 * Returns: the #NMSettingWired:speed property of the setting
127 nm_setting_wired_get_speed (NMSettingWired *setting)
129 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), 0);
131 return NM_SETTING_WIRED_GET_PRIVATE (setting)->speed;
135 * nm_setting_wired_get_duplex:
136 * @setting: the #NMSettingWired
138 * Returns: the #NMSettingWired:duplex property of the setting
141 nm_setting_wired_get_duplex (NMSettingWired *setting)
143 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
145 return NM_SETTING_WIRED_GET_PRIVATE (setting)->duplex;
149 * nm_setting_wired_get_auto_negotiate:
150 * @setting: the #NMSettingWired
152 * Returns: the #NMSettingWired:auto-negotiate property of the setting
155 nm_setting_wired_get_auto_negotiate (NMSettingWired *setting)
157 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
159 return NM_SETTING_WIRED_GET_PRIVATE (setting)->auto_negotiate;
163 * nm_setting_wired_get_mac_address:
164 * @setting: the #NMSettingWired
166 * Returns: the #NMSettingWired:mac-address property of the setting
169 nm_setting_wired_get_mac_address (NMSettingWired *setting)
171 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
173 return NM_SETTING_WIRED_GET_PRIVATE (setting)->device_mac_address;
177 * nm_setting_wired_get_cloned_mac_address:
178 * @setting: the #NMSettingWired
180 * Returns: the #NMSettingWired:cloned-mac-address property of the setting
183 nm_setting_wired_get_cloned_mac_address (NMSettingWired *setting)
185 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
187 return NM_SETTING_WIRED_GET_PRIVATE (setting)->cloned_mac_address;
191 * nm_setting_wired_get_mac_address_blacklist:
192 * @setting: the #NMSettingWired
194 * Returns: the #NMSettingWired:mac-address-blacklist property of the setting
197 nm_setting_wired_get_mac_address_blacklist (NMSettingWired *setting)
199 NMSettingWiredPrivate *priv;
201 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
203 priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
204 return (const char * const *) priv->mac_address_blacklist->data;
208 * nm_setting_wired_get_num_mac_blacklist_items:
209 * @setting: the #NMSettingWired
211 * Returns: the number of blacklisted MAC addresses
214 nm_setting_wired_get_num_mac_blacklist_items (NMSettingWired *setting)
216 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), 0);
218 return NM_SETTING_WIRED_GET_PRIVATE (setting)->mac_address_blacklist->len;
222 * nm_setting_wired_get_mac_blacklist_item:
223 * @setting: the #NMSettingWired
224 * @idx: the zero-based index of the MAC address entry
226 * Returns: the blacklisted MAC address string (hex-digits-and-colons notation)
230 nm_setting_wired_get_mac_blacklist_item (NMSettingWired *setting, guint32 idx)
232 NMSettingWiredPrivate *priv;
234 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
236 priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
237 g_return_val_if_fail (idx <= priv->mac_address_blacklist->len, NULL);
239 return g_array_index (priv->mac_address_blacklist, const char *, idx);
243 * nm_setting_wired_add_mac_blacklist_item:
244 * @setting: the #NMSettingWired
245 * @mac: the MAC address string (hex-digits-and-colons notation) to blacklist
247 * Adds a new MAC address to the #NMSettingWired:mac-address-blacklist property.
249 * Returns: %TRUE if the MAC address was added; %FALSE if the MAC address
250 * is invalid or was already present
253 nm_setting_wired_add_mac_blacklist_item (NMSettingWired *setting, const char *mac)
255 NMSettingWiredPrivate *priv;
256 const char *candidate;
259 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
260 g_return_val_if_fail (mac != NULL, FALSE);
262 if (!nm_utils_hwaddr_valid (mac, ETH_ALEN))
265 priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
266 for (i = 0; i < priv->mac_address_blacklist->len; i++) {
267 candidate = g_array_index (priv->mac_address_blacklist, char *, i);
268 if (nm_utils_hwaddr_matches (mac, -1, candidate, -1))
272 mac = nm_utils_hwaddr_canonical (mac, ETH_ALEN);
273 g_array_append_val (priv->mac_address_blacklist, mac);
274 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST);
279 * nm_setting_wired_remove_mac_blacklist_item:
280 * @setting: the #NMSettingWired
281 * @idx: index number of the MAC address
283 * Removes the MAC address at index @idx from the blacklist.
286 nm_setting_wired_remove_mac_blacklist_item (NMSettingWired *setting, guint32 idx)
288 NMSettingWiredPrivate *priv;
290 g_return_if_fail (NM_IS_SETTING_WIRED (setting));
292 priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
293 g_return_if_fail (idx < priv->mac_address_blacklist->len);
295 g_array_remove_index (priv->mac_address_blacklist, idx);
296 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST);
300 * nm_setting_wired_remove_mac_blacklist_item_by_value:
301 * @setting: the #NMSettingWired
302 * @mac: the MAC address string (hex-digits-and-colons notation) to remove from
305 * Removes the MAC address @mac from the blacklist.
307 * Returns: %TRUE if the MAC address was found and removed; %FALSE if it was not.
310 nm_setting_wired_remove_mac_blacklist_item_by_value (NMSettingWired *setting, const char *mac)
312 NMSettingWiredPrivate *priv;
313 const char *candidate;
316 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
317 g_return_val_if_fail (mac != NULL, FALSE);
319 priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
320 for (i = 0; i < priv->mac_address_blacklist->len; i++) {
321 candidate = g_array_index (priv->mac_address_blacklist, char *, i);
322 if (!nm_utils_hwaddr_matches (mac, -1, candidate, -1)) {
323 g_array_remove_index (priv->mac_address_blacklist, i);
324 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST);
332 * nm_setting_wired_clear_mac_blacklist_items:
333 * @setting: the #NMSettingWired
335 * Removes all blacklisted MAC addresses.
338 nm_setting_wired_clear_mac_blacklist_items (NMSettingWired *setting)
340 g_return_if_fail (NM_IS_SETTING_WIRED (setting));
342 g_array_set_size (NM_SETTING_WIRED_GET_PRIVATE (setting)->mac_address_blacklist, 0);
343 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST);
347 * nm_setting_wired_get_mtu:
348 * @setting: the #NMSettingWired
350 * Returns: the #NMSettingWired:mtu property of the setting
353 nm_setting_wired_get_mtu (NMSettingWired *setting)
355 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), 0);
357 return NM_SETTING_WIRED_GET_PRIVATE (setting)->mtu;
361 * nm_setting_wired_get_s390_subchannels:
362 * @setting: the #NMSettingWired
364 * Return the list of s390 subchannels that identify the device that this
365 * connection is applicable to. The connection should only be used in
366 * conjunction with that device.
368 * Returns: (transfer none) (element-type utf8): array of strings, each specifying
369 * one subchannel the s390 device uses to communicate to the host.
372 nm_setting_wired_get_s390_subchannels (NMSettingWired *setting)
374 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
376 return (const char * const *) NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_subchannels;
380 * nm_setting_wired_get_s390_nettype:
381 * @setting: the #NMSettingWired
383 * Returns the s390 device type this connection should apply to. Will be one
384 * of 'qeth', 'lcs', or 'ctc'.
386 * Returns: the s390 device type
389 nm_setting_wired_get_s390_nettype (NMSettingWired *setting)
391 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
393 return NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_nettype;
397 * nm_setting_wired_get_num_s390_options:
398 * @setting: the #NMSettingWired
400 * Returns the number of s390-specific options that should be set for this
401 * device when it is activated. This can be used to retrieve each s390
402 * option individually using nm_setting_wired_get_s390_option().
404 * Returns: the number of s390-specific device options
407 nm_setting_wired_get_num_s390_options (NMSettingWired *setting)
409 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), 0);
411 return g_hash_table_size (NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options);
415 * nm_setting_wired_get_s390_option:
416 * @setting: the #NMSettingWired
417 * @idx: index of the desired option, from 0 to
418 * nm_setting_wired_get_num_s390_options() - 1
419 * @out_key: (out) (transfer none): on return, the key name of the s390 specific
420 * option; this value is owned by the setting and should not be modified
421 * @out_value: (out) (transfer none): on return, the value of the key of the
422 * s390 specific option; this value is owned by the setting and should not be
425 * Given an index, return the value of the s390 option at that index. indexes
426 * are *not* guaranteed to be static across modifications to options done by
427 * nm_setting_wired_add_s390_option() and nm_setting_wired_remove_s390_option(),
428 * and should not be used to refer to options except for short periods of time
429 * such as during option iteration.
431 * Returns: %TRUE on success if the index was valid and an option was found,
432 * %FALSE if the index was invalid (ie, greater than the number of options
433 * currently held by the setting)
436 nm_setting_wired_get_s390_option (NMSettingWired *setting,
438 const char **out_key,
439 const char **out_value)
441 const char *_key, *_value;
445 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
447 g_hash_table_iter_init (&iter, NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options);
448 while (g_hash_table_iter_next (&iter, (gpointer) &_key, (gpointer) &_value)) {
458 g_return_val_if_reached (FALSE);
462 * nm_setting_wired_get_s390_option_by_key:
463 * @setting: the #NMSettingWired
464 * @key: the key for which to retrieve the value
466 * Returns the value associated with the s390-specific option specified by
467 * @key, if it exists.
469 * Returns: the value, or %NULL if the key/value pair was never added to the
470 * setting; the value is owned by the setting and must not be modified
473 nm_setting_wired_get_s390_option_by_key (NMSettingWired *setting,
476 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
477 g_return_val_if_fail (key != NULL, NULL);
478 g_return_val_if_fail (strlen (key), NULL);
480 return g_hash_table_lookup (NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options, key);
484 * nm_setting_wired_add_s390_option:
485 * @setting: the #NMSettingWired
486 * @key: key name for the option
487 * @value: value for the option
489 * Add an option to the table. The option is compared to an internal list
490 * of allowed options. Key names may contain only alphanumeric characters
491 * (ie [a-zA-Z0-9]). Adding a new key replaces any existing key/value pair that
494 * Returns: %TRUE if the option was valid and was added to the internal option
495 * list, %FALSE if it was not.
498 nm_setting_wired_add_s390_option (NMSettingWired *setting,
504 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
505 g_return_val_if_fail (key != NULL, FALSE);
506 g_return_val_if_fail (strlen (key), FALSE);
507 g_return_val_if_fail (_nm_utils_string_in_list (key, valid_s390_opts), FALSE);
508 g_return_val_if_fail (value != NULL, FALSE);
510 value_len = strlen (value);
511 g_return_val_if_fail (value_len > 0 && value_len < 200, FALSE);
513 g_hash_table_insert (NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options,
516 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_S390_OPTIONS);
521 * nm_setting_wired_remove_s390_option:
522 * @setting: the #NMSettingWired
523 * @key: key name for the option to remove
525 * Remove the s390-specific option referenced by @key from the internal option
528 * Returns: %TRUE if the option was found and removed from the internal option
529 * list, %FALSE if it was not.
532 nm_setting_wired_remove_s390_option (NMSettingWired *setting,
537 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
538 g_return_val_if_fail (key != NULL, FALSE);
539 g_return_val_if_fail (strlen (key), FALSE);
541 found = g_hash_table_remove (NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options, key);
543 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRED_S390_OPTIONS);
548 * nm_setting_wired_get_valid_s390_options:
549 * @setting: the #NMSettingWired
551 * Returns a list of valid s390 options.
553 * Returns: (transfer none): a %NULL-terminated array of strings of valid s390 options.
556 nm_setting_wired_get_valid_s390_options (NMSettingWired *setting)
558 return valid_s390_opts;
562 * nm_setting_wired_get_wake_on_lan:
563 * @setting: the #NMSettingWired
565 * Returns the Wake-on-LAN options enabled for the connection
567 * Returns: the Wake-on-LAN options
571 NMSettingWiredWakeOnLan
572 nm_setting_wired_get_wake_on_lan (NMSettingWired *setting)
574 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NM_SETTING_WIRED_WAKE_ON_LAN_NONE);
576 return NM_SETTING_WIRED_GET_PRIVATE (setting)->wol;
578 NM_BACKPORT_SYMBOL (libnm_1_0_6, NMSettingWiredWakeOnLan, nm_setting_wired_get_wake_on_lan,
579 (NMSettingWired *setting), (setting));
582 * nm_setting_wired_get_wake_on_lan_password:
583 * @setting: the #NMSettingWired
585 * Returns the Wake-on-LAN password. This only applies to
586 * %NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC.
588 * Returns: the Wake-on-LAN setting password, or %NULL if there is no password.
593 nm_setting_wired_get_wake_on_lan_password (NMSettingWired *setting)
595 g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), NULL);
597 return NM_SETTING_WIRED_GET_PRIVATE (setting)->wol_password;
599 NM_BACKPORT_SYMBOL (libnm_1_0_6, const char *, nm_setting_wired_get_wake_on_lan_password,
600 (NMSettingWired *setting), (setting));
602 NM_BACKPORT_SYMBOL (libnm_1_0_6, GType, nm_setting_wired_wake_on_lan_get_type, (void), ());
605 verify (NMSetting *setting, NMConnection *connection, GError **error)
607 NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
608 const char *valid_ports[] = { "tp", "aui", "bnc", "mii", NULL };
609 const char *valid_duplex[] = { "half", "full", NULL };
610 const char *valid_nettype[] = { "qeth", "lcs", "ctc", NULL };
612 const char *key, *value;
615 if (priv->port && !_nm_utils_string_in_list (priv->port, valid_ports)) {
618 NM_CONNECTION_ERROR_INVALID_PROPERTY,
619 _("'%s' is not a valid Ethernet port value"),
621 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_PORT);
625 if (priv->duplex && !_nm_utils_string_in_list (priv->duplex, valid_duplex)) {
628 NM_CONNECTION_ERROR_INVALID_PROPERTY,
629 _("'%s' is not a valid duplex value"),
631 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_DUPLEX);
635 if (priv->device_mac_address && !nm_utils_hwaddr_valid (priv->device_mac_address, ETH_ALEN)) {
636 g_set_error_literal (error,
638 NM_CONNECTION_ERROR_INVALID_PROPERTY,
639 _("is not a valid MAC address"));
640 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS);
644 for (i = 0; i < priv->mac_address_blacklist->len; i++) {
645 const char *mac = g_array_index (priv->mac_address_blacklist, const char *, i);
647 if (!nm_utils_hwaddr_valid (mac, ETH_ALEN)) {
650 NM_CONNECTION_ERROR_INVALID_PROPERTY,
651 _("'%s' is not a valid MAC address"),
653 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST);
658 if (priv->s390_subchannels) {
659 int len = g_strv_length (priv->s390_subchannels);
661 if (len != 2 && len != 3) {
662 g_set_error_literal (error,
664 NM_CONNECTION_ERROR_INVALID_PROPERTY,
665 _("property is invalid"));
666 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_SUBCHANNELS);
671 if (priv->s390_nettype && !_nm_utils_string_in_list (priv->s390_nettype, valid_nettype)) {
672 g_set_error_literal (error,
674 NM_CONNECTION_ERROR_INVALID_PROPERTY,
675 _("property is invalid"));
676 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_NETTYPE);
680 g_hash_table_iter_init (&iter, priv->s390_options);
681 while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
682 if ( !_nm_utils_string_in_list (key, valid_s390_opts)
684 || (strlen (value) > 200)) {
687 NM_CONNECTION_ERROR_INVALID_PROPERTY,
688 _("invalid '%s' or its value '%s'"),
690 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_OPTIONS);
695 if (priv->cloned_mac_address && !nm_utils_hwaddr_valid (priv->cloned_mac_address, ETH_ALEN)) {
696 g_set_error_literal (error,
698 NM_CONNECTION_ERROR_INVALID_PROPERTY,
699 _("is not a valid MAC address"));
700 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_CLONED_MAC_ADDRESS);
704 if ( NM_FLAGS_ANY (priv->wol, NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS)
705 && !nm_utils_is_power_of_two (priv->wol)) {
706 g_set_error_literal (error,
708 NM_CONNECTION_ERROR_INVALID_PROPERTY,
709 _("Wake-on-LAN mode 'default' and 'ignore' are exclusive flags"));
710 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_WAKE_ON_LAN);
714 if (priv->wol_password && !NM_FLAGS_HAS (priv->wol, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) {
715 g_set_error_literal (error,
717 NM_CONNECTION_ERROR_INVALID_PROPERTY,
718 _("Wake-on-LAN password can only be used with magic packet mode"));
719 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD);
723 if (priv->wol_password && !nm_utils_hwaddr_valid (priv->wol_password, ETH_ALEN)) {
724 g_set_error_literal (error,
726 NM_CONNECTION_ERROR_INVALID_PROPERTY,
727 _("is not a valid MAC address"));
728 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD);
736 clear_blacklist_item (char **item_p)
742 nm_setting_wired_init (NMSettingWired *setting)
744 NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
746 priv->s390_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
748 /* We use GArray rather than GPtrArray so it will automatically be NULL-terminated */
749 priv->mac_address_blacklist = g_array_new (TRUE, FALSE, sizeof (char *));
750 g_array_set_clear_func (priv->mac_address_blacklist, (GDestroyNotify) clear_blacklist_item);
754 finalize (GObject *object)
756 NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (object);
759 g_free (priv->duplex);
760 g_free (priv->s390_nettype);
762 g_hash_table_destroy (priv->s390_options);
764 g_free (priv->device_mac_address);
765 g_free (priv->cloned_mac_address);
766 g_array_unref (priv->mac_address_blacklist);
768 if (priv->s390_subchannels)
769 g_strfreev (priv->s390_subchannels);
771 g_free (priv->wol_password);
773 G_OBJECT_CLASS (nm_setting_wired_parent_class)->finalize (object);
777 set_property (GObject *object, guint prop_id,
778 const GValue *value, GParamSpec *pspec)
780 NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (object);
781 const char * const *blacklist;
788 priv->port = g_value_dup_string (value);
791 priv->speed = g_value_get_uint (value);
794 g_free (priv->duplex);
795 priv->duplex = g_value_dup_string (value);
797 case PROP_AUTO_NEGOTIATE:
798 priv->auto_negotiate = g_value_get_boolean (value);
800 case PROP_MAC_ADDRESS:
801 g_free (priv->device_mac_address);
802 priv->device_mac_address = _nm_utils_hwaddr_canonical_or_invalid (g_value_get_string (value),
805 case PROP_CLONED_MAC_ADDRESS:
806 g_free (priv->cloned_mac_address);
807 priv->cloned_mac_address = _nm_utils_hwaddr_canonical_or_invalid (g_value_get_string (value),
810 case PROP_MAC_ADDRESS_BLACKLIST:
811 blacklist = g_value_get_boxed (value);
812 g_array_set_size (priv->mac_address_blacklist, 0);
813 if (blacklist && *blacklist) {
814 for (i = 0; blacklist[i]; i++) {
815 mac = _nm_utils_hwaddr_canonical_or_invalid (blacklist[i], ETH_ALEN);
816 g_array_append_val (priv->mac_address_blacklist, mac);
821 priv->mtu = g_value_get_uint (value);
823 case PROP_S390_SUBCHANNELS:
824 if (priv->s390_subchannels)
825 g_strfreev (priv->s390_subchannels);
826 priv->s390_subchannels = g_value_dup_boxed (value);
828 case PROP_S390_NETTYPE:
829 g_free (priv->s390_nettype);
830 priv->s390_nettype = g_value_dup_string (value);
832 case PROP_S390_OPTIONS:
833 g_hash_table_unref (priv->s390_options);
834 priv->s390_options = _nm_utils_copy_strdict (g_value_get_boxed (value));
836 case PROP_WAKE_ON_LAN:
837 priv->wol = g_value_get_uint (value);
839 case PROP_WAKE_ON_LAN_PASSWORD:
840 g_free (priv->wol_password);
841 priv->wol_password = g_value_dup_string (value);
844 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
850 get_property (GObject *object, guint prop_id,
851 GValue *value, GParamSpec *pspec)
853 NMSettingWired *setting = NM_SETTING_WIRED (object);
854 NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
858 g_value_set_string (value, nm_setting_wired_get_port (setting));
861 g_value_set_uint (value, nm_setting_wired_get_speed (setting));
864 g_value_set_string (value, nm_setting_wired_get_duplex (setting));
866 case PROP_AUTO_NEGOTIATE:
867 g_value_set_boolean (value, nm_setting_wired_get_auto_negotiate (setting));
869 case PROP_MAC_ADDRESS:
870 g_value_set_string (value, nm_setting_wired_get_mac_address (setting));
872 case PROP_CLONED_MAC_ADDRESS:
873 g_value_set_string (value, nm_setting_wired_get_cloned_mac_address (setting));
875 case PROP_MAC_ADDRESS_BLACKLIST:
876 g_value_set_boxed (value, (char **) priv->mac_address_blacklist->data);
879 g_value_set_uint (value, nm_setting_wired_get_mtu (setting));
881 case PROP_S390_SUBCHANNELS:
882 g_value_set_boxed (value, priv->s390_subchannels);
884 case PROP_S390_NETTYPE:
885 g_value_set_string (value, nm_setting_wired_get_s390_nettype (setting));
887 case PROP_S390_OPTIONS:
888 g_value_take_boxed (value, _nm_utils_copy_strdict (priv->s390_options));
890 case PROP_WAKE_ON_LAN:
891 g_value_set_uint (value, priv->wol);
893 case PROP_WAKE_ON_LAN_PASSWORD:
894 g_value_set_string (value, priv->wol_password);
897 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
903 nm_setting_wired_class_init (NMSettingWiredClass *setting_class)
905 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
906 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
908 g_type_class_add_private (setting_class, sizeof (NMSettingWiredPrivate));
910 /* virtual methods */
911 object_class->set_property = set_property;
912 object_class->get_property = get_property;
913 object_class->finalize = finalize;
914 parent_class->verify = verify;
918 * NMSettingWired:port:
920 * Specific port type to use if multiple the device supports multiple
921 * attachment methods. One of "tp" (Twisted Pair), "aui" (Attachment Unit
922 * Interface), "bnc" (Thin Ethernet) or "mii" (Media Independent Interface.
923 * If the device supports only one port type, this setting is ignored.
928 * description: The property is not saved by the plugin.
931 g_object_class_install_property
932 (object_class, PROP_PORT,
933 g_param_spec_string (NM_SETTING_WIRED_PORT, "", "",
936 G_PARAM_STATIC_STRINGS));
939 * NMSettingWired:speed:
941 * If non-zero, request that the device use only the specified speed. In
942 * Mbit/s, ie 100 == 100Mbit/s.
947 * description: The property is not saved by the plugin.
950 g_object_class_install_property
951 (object_class, PROP_SPEED,
952 g_param_spec_uint (NM_SETTING_WIRED_SPEED, "", "",
956 G_PARAM_STATIC_STRINGS));
959 * NMSettingWired:duplex:
961 * If specified, request that the device only use the specified duplex mode.
962 * Either "half" or "full".
967 * description: The property is not saved by the plugin.
970 g_object_class_install_property
971 (object_class, PROP_DUPLEX,
972 g_param_spec_string (NM_SETTING_WIRED_DUPLEX, "", "",
975 G_PARAM_STATIC_STRINGS));
978 * NMSettingWired:auto-negotiate:
980 * If %TRUE, allow auto-negotiation of port speed and duplex mode. If
981 * %FALSE, do not allow auto-negotiation, in which case the "speed" and
982 * "duplex" properties should be set.
985 * property: auto-negotiate
987 * description: The property is not saved by the plugin.
990 g_object_class_install_property
991 (object_class, PROP_AUTO_NEGOTIATE,
992 g_param_spec_boolean (NM_SETTING_WIRED_AUTO_NEGOTIATE, "", "",
996 G_PARAM_STATIC_STRINGS));
999 * NMSettingWired:mac-address:
1001 * If specified, this connection will only apply to the Ethernet device
1002 * whose permanent MAC address matches. This property does not change the
1003 * MAC address of the device (i.e. MAC spoofing).
1006 * property: mac-address
1007 * format: usual hex-digits-and-colons notation
1008 * description: MAC address in traditional hex-digits-and-colons notation
1009 * (e.g. 00:22:68:12:79:A2), or semicolon separated list of 6 bytes (obsolete)
1010 * (e.g. 0;34;104;18;121;162)
1013 * property: mac-address
1015 * description: Hardware address of the device in traditional hex-digits-and-colons
1016 * notation (e.g. 00:22:68:14:5A:05).
1019 g_object_class_install_property
1020 (object_class, PROP_MAC_ADDRESS,
1021 g_param_spec_string (NM_SETTING_WIRED_MAC_ADDRESS, "", "",
1024 NM_SETTING_PARAM_INFERRABLE |
1025 G_PARAM_STATIC_STRINGS));
1026 _nm_setting_class_transform_property (parent_class, NM_SETTING_WIRED_MAC_ADDRESS,
1027 G_VARIANT_TYPE_BYTESTRING,
1028 _nm_utils_hwaddr_to_dbus,
1029 _nm_utils_hwaddr_from_dbus);
1032 * NMSettingWired:cloned-mac-address:
1034 * If specified, request that the device use this MAC address instead of its
1035 * permanent MAC address. This is known as MAC cloning or spoofing.
1038 * property: cloned-mac-address
1039 * format: usual hex-digits-and-colons notation
1040 * description: Cloned MAC address in traditional hex-digits-and-colons notation
1041 * (e.g. 00:22:68:12:79:B2), or semicolon separated list of 6 bytes (obsolete)
1042 * (e.g. 0;34;104;18;121;178).
1045 * property: cloned-mac-address
1047 * description: Cloned (spoofed) MAC address in traditional hex-digits-and-colons
1048 * notation (e.g. 00:22:68:14:5A:99).
1051 g_object_class_install_property
1052 (object_class, PROP_CLONED_MAC_ADDRESS,
1053 g_param_spec_string (NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "", "",
1056 NM_SETTING_PARAM_INFERRABLE |
1057 G_PARAM_STATIC_STRINGS));
1058 _nm_setting_class_transform_property (parent_class, NM_SETTING_WIRED_CLONED_MAC_ADDRESS,
1059 G_VARIANT_TYPE_BYTESTRING,
1060 _nm_utils_hwaddr_to_dbus,
1061 _nm_utils_hwaddr_from_dbus);
1064 * NMSettingWired:mac-address-blacklist:
1066 * If specified, this connection will never apply to the Ethernet device
1067 * whose permanent MAC address matches an address in the list. Each MAC
1068 * address is in the standard hex-digits-and-colons notation
1069 * (00:11:22:33:44:55).
1072 * property: mac-address-blacklist
1073 * format: list of MACs (separated with semicolons)
1074 * description: MAC address blacklist.
1075 * example: mac-address-blacklist= 00:22:68:12:79:A6;00:22:68:12:79:78
1078 * property: mac-address-blacklist
1079 * variable: HWADDR_BLACKLIST(+)
1080 * description: It denies usage of the connection for any device whose address
1082 * example: HWADDR_BLACKLIST="00:22:68:11:69:08 00:11:22:11:44:55"
1085 g_object_class_install_property
1086 (object_class, PROP_MAC_ADDRESS_BLACKLIST,
1087 g_param_spec_boxed (NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST, "", "",
1090 NM_SETTING_PARAM_FUZZY_IGNORE |
1091 G_PARAM_STATIC_STRINGS));
1094 * NMSettingWired:mtu:
1096 * If non-zero, only transmit packets of the specified size or smaller,
1097 * breaking larger packets up into multiple Ethernet frames.
1102 * description: MTU of the interface.
1105 g_object_class_install_property
1106 (object_class, PROP_MTU,
1107 g_param_spec_uint (NM_SETTING_WIRED_MTU, "", "",
1111 NM_SETTING_PARAM_FUZZY_IGNORE |
1112 G_PARAM_STATIC_STRINGS));
1115 * NMSettingWired:s390-subchannels:
1117 * Identifies specific subchannels that this network device uses for
1118 * communication with z/VM or s390 host. Like the
1119 * #NMSettingWired:mac-address property for non-z/VM devices, this property
1120 * can be used to ensure this connection only applies to the network device
1121 * that uses these subchannels. The list should contain exactly 3 strings,
1122 * and each string may only be composed of hexadecimal characters and the
1123 * period (.) character.
1126 * property: s390-subchannels
1127 * variable: SUBCHANNELS
1128 * description: Subchannels for IBM S390 hosts.
1129 * example: SUBCHANNELS=0.0.b00a,0.0.b00b,0.0.b00c
1132 g_object_class_install_property
1133 (object_class, PROP_S390_SUBCHANNELS,
1134 g_param_spec_boxed (NM_SETTING_WIRED_S390_SUBCHANNELS, "", "",
1137 NM_SETTING_PARAM_INFERRABLE |
1138 G_PARAM_STATIC_STRINGS));
1141 * NMSettingWired:s390-nettype:
1143 * s390 network device type; one of "qeth", "lcs", or "ctc", representing
1144 * the different types of virtual network devices available on s390 systems.
1147 * property: s390-nettype
1149 * values: "qeth", "lcs" or "ctc"
1150 * description: Network type of the S390 host.
1151 * example: NETTYPE=qeth
1154 g_object_class_install_property
1155 (object_class, PROP_S390_NETTYPE,
1156 g_param_spec_string (NM_SETTING_WIRED_S390_NETTYPE, "", "",
1159 NM_SETTING_PARAM_INFERRABLE |
1160 G_PARAM_STATIC_STRINGS));
1163 * NMSettingWired:s390-options:
1165 * Dictionary of key/value pairs of s390-specific device options. Both keys
1166 * and values must be strings. Allowed keys include "portno", "layer2",
1167 * "portname", "protocol", among others. Key names must contain only
1168 * alphanumeric characters (ie, [a-zA-Z0-9]).
1170 * Type: GHashTable(utf8,utf8)
1173 * property: s390-options
1174 * variable: OPTIONS and PORTNAME, CTCPROTO,
1175 * description: S390 device options. All options go to OPTIONS, except for
1176 * "portname" and "ctcprot" that have their own variables.
1179 g_object_class_install_property
1180 (object_class, PROP_S390_OPTIONS,
1181 g_param_spec_boxed (NM_SETTING_WIRED_S390_OPTIONS, "", "",
1184 NM_SETTING_PARAM_INFERRABLE |
1185 G_PARAM_STATIC_STRINGS));
1186 _nm_setting_class_transform_property (parent_class, NM_SETTING_WIRED_S390_OPTIONS,
1187 G_VARIANT_TYPE ("a{ss}"),
1188 _nm_utils_strdict_to_dbus,
1189 _nm_utils_strdict_from_dbus);
1192 * NMSettingWired:wake-on-lan:
1194 * The #NMSettingWiredWakeOnLan options to enable. Not all devices support all options.
1195 * May be any combination of %NM_SETTING_WIRED_WAKE_ON_LAN_PHY,
1196 * %NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST, %NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST,
1197 * %NM_SETTING_WIRED_WAKE_ON_LAN_BROADCAST, %NM_SETTING_WIRED_WAKE_ON_LAN_ARP,
1198 * %NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC or the special values
1199 * %NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT (to use global settings) and
1200 * %NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE (to disable management of Wake-on-LAN in
1205 g_object_class_install_property
1206 (object_class, PROP_WAKE_ON_LAN,
1207 g_param_spec_uint (NM_SETTING_WIRED_WAKE_ON_LAN, "", "",
1208 0, G_MAXUINT32, NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT,
1211 G_PARAM_STATIC_STRINGS));
1214 * NMSettingWired:wake-on-lan-password:
1216 * If specified, the password used with magic-packet-based
1217 * Wake-on-LAN, represented as an Ethernet MAC address. If %NULL,
1218 * no password will be required.
1222 g_object_class_install_property
1223 (object_class, PROP_WAKE_ON_LAN_PASSWORD,
1224 g_param_spec_string (NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, "", "",
1227 G_PARAM_STATIC_STRINGS));