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"
28 #include "nm-setting-bridge.h"
29 #include "nm-connection-private.h"
31 #include "nm-utils-private.h"
34 * SECTION:nm-setting-bridge
35 * @short_description: Describes connection properties for bridges
37 * The #NMSettingBridge object is a #NMSetting subclass that describes properties
38 * necessary for bridging connections.
41 G_DEFINE_TYPE_WITH_CODE (NMSettingBridge, nm_setting_bridge, NM_TYPE_SETTING,
42 _nm_register_setting (BRIDGE, 1))
43 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BRIDGE)
45 #define NM_SETTING_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BRIDGE, NMSettingBridgePrivate))
51 guint16 forward_delay;
55 gboolean multicast_snooping;
56 } NMSettingBridgePrivate;
67 PROP_MULTICAST_SNOOPING,
72 * nm_setting_bridge_new:
74 * Creates a new #NMSettingBridge object with default values.
76 * Returns: (transfer full): the new empty #NMSettingBridge object
79 nm_setting_bridge_new (void)
81 return (NMSetting *) g_object_new (NM_TYPE_SETTING_BRIDGE, NULL);
85 * nm_setting_bridge_get_mac_address:
86 * @setting: the #NMSettingBridge
88 * Returns: the #NMSettingBridge:mac-address property of the setting
91 nm_setting_bridge_get_mac_address (NMSettingBridge *setting)
93 g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), NULL);
95 return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->mac_address;
99 * nm_setting_bridge_get_stp:
100 * @setting: the #NMSettingBridge
102 * Returns: the #NMSettingBridge:stp property of the setting
105 nm_setting_bridge_get_stp (NMSettingBridge *setting)
107 g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), FALSE);
109 return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->stp;
113 * nm_setting_bridge_get_priority:
114 * @setting: the #NMSettingBridge
116 * Returns: the #NMSettingBridge:priority property of the setting
119 nm_setting_bridge_get_priority (NMSettingBridge *setting)
121 g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
123 return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->priority;
127 * nm_setting_bridge_get_forward_delay:
128 * @setting: the #NMSettingBridge
130 * Returns: the #NMSettingBridge:forward-delay property of the setting
133 nm_setting_bridge_get_forward_delay (NMSettingBridge *setting)
135 g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
137 return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->forward_delay;
141 * nm_setting_bridge_get_hello_time:
142 * @setting: the #NMSettingBridge
144 * Returns: the #NMSettingBridge:hello-time property of the setting
147 nm_setting_bridge_get_hello_time (NMSettingBridge *setting)
149 g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
151 return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->hello_time;
155 * nm_setting_bridge_get_max_age:
156 * @setting: the #NMSettingBridge
158 * Returns: the #NMSettingBridge:max-age property of the setting
161 nm_setting_bridge_get_max_age (NMSettingBridge *setting)
163 g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
165 return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->max_age;
169 * nm_setting_bridge_get_ageing_time:
170 * @setting: the #NMSettingBridge
172 * Returns: the #NMSettingBridge:ageing-time property of the setting
175 nm_setting_bridge_get_ageing_time (NMSettingBridge *setting)
177 g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
179 return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->ageing_time;
183 * nm_setting_bridge_get_multicast_snooping:
184 * @setting: the #NMSettingBridge
186 * Returns: the #NMSettingBridge:multicast-snooping property of the setting
191 nm_setting_bridge_get_multicast_snooping (NMSettingBridge *setting)
193 g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), FALSE);
195 return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->multicast_snooping;
198 /* IEEE 802.1D-1998 timer values */
199 #define BR_MIN_HELLO_TIME 1
200 #define BR_MAX_HELLO_TIME 10
202 #define BR_MIN_FORWARD_DELAY 2
203 #define BR_MAX_FORWARD_DELAY 30
205 #define BR_MIN_MAX_AGE 6
206 #define BR_MAX_MAX_AGE 40
208 /* IEEE 802.1D-1998 Table 7.4 */
209 #define BR_MIN_AGEING_TIME 0
210 #define BR_MAX_AGEING_TIME 1000000
212 static inline gboolean
213 check_range (guint32 val,
220 if (zero && val == 0)
223 if (val < min || val > max) {
226 NM_CONNECTION_ERROR_INVALID_PROPERTY,
227 _("value '%d' is out of range <%d-%d>"),
229 g_prefix_error (error, "%s.%s: ", NM_SETTING_BRIDGE_SETTING_NAME, prop);
236 verify (NMSetting *setting, NMConnection *connection, GError **error)
238 NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (setting);
240 if (priv->mac_address && !nm_utils_hwaddr_valid (priv->mac_address, ETH_ALEN)) {
241 g_set_error_literal (error,
243 NM_CONNECTION_ERROR_INVALID_PROPERTY,
244 _("is not a valid MAC address"));
245 g_prefix_error (error, "%s.%s: ", NM_SETTING_BRIDGE_SETTING_NAME, NM_SETTING_BRIDGE_MAC_ADDRESS);
249 if (!check_range (priv->forward_delay,
250 BR_MIN_FORWARD_DELAY,
251 BR_MAX_FORWARD_DELAY,
253 NM_SETTING_BRIDGE_FORWARD_DELAY,
257 if (!check_range (priv->hello_time,
261 NM_SETTING_BRIDGE_HELLO_TIME,
265 if (!check_range (priv->max_age,
269 NM_SETTING_BRIDGE_MAX_AGE,
273 if (!check_range (priv->ageing_time,
277 NM_SETTING_BRIDGE_AGEING_TIME,
281 return _nm_connection_verify_required_interface_name (connection, error);
285 nm_setting_bridge_init (NMSettingBridge *setting)
290 finalize (GObject *object)
292 NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
294 g_free (priv->mac_address);
296 G_OBJECT_CLASS (nm_setting_bridge_parent_class)->finalize (object);
300 set_property (GObject *object, guint prop_id,
301 const GValue *value, GParamSpec *pspec)
303 NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
306 case PROP_MAC_ADDRESS:
307 g_free (priv->mac_address);
308 priv->mac_address = _nm_utils_hwaddr_canonical_or_invalid (g_value_get_string (value),
312 priv->stp = g_value_get_boolean (value);
315 priv->priority = (guint16) g_value_get_uint (value);
317 case PROP_FORWARD_DELAY:
318 priv->forward_delay = (guint16) g_value_get_uint (value);
320 case PROP_HELLO_TIME:
321 priv->hello_time = (guint16) g_value_get_uint (value);
324 priv->max_age = (guint16) g_value_get_uint (value);
326 case PROP_AGEING_TIME:
327 priv->ageing_time = g_value_get_uint (value);
329 case PROP_MULTICAST_SNOOPING:
330 priv->multicast_snooping = g_value_get_boolean (value);
333 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
339 get_property (GObject *object, guint prop_id,
340 GValue *value, GParamSpec *pspec)
342 NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
343 NMSettingBridge *setting = NM_SETTING_BRIDGE (object);
346 case PROP_MAC_ADDRESS:
347 g_value_set_string (value, nm_setting_bridge_get_mac_address (setting));
350 g_value_set_boolean (value, priv->stp);
353 g_value_set_uint (value, priv->priority);
355 case PROP_FORWARD_DELAY:
356 g_value_set_uint (value, priv->forward_delay);
358 case PROP_HELLO_TIME:
359 g_value_set_uint (value, priv->hello_time);
362 g_value_set_uint (value, priv->max_age);
364 case PROP_AGEING_TIME:
365 g_value_set_uint (value, priv->ageing_time);
367 case PROP_MULTICAST_SNOOPING:
368 g_value_set_boolean (value, priv->multicast_snooping);
371 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
377 nm_setting_bridge_class_init (NMSettingBridgeClass *setting_class)
379 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
380 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
382 g_type_class_add_private (setting_class, sizeof (NMSettingBridgePrivate));
384 /* virtual methods */
385 object_class->set_property = set_property;
386 object_class->get_property = get_property;
387 object_class->finalize = finalize;
388 parent_class->verify = verify;
392 * NMSettingBridge:mac-address:
394 * If specified, the MAC address of bridge. When creating a new bridge, this
395 * MAC address will be set. When matching an existing (outside
396 * NetworkManager created) bridge, this MAC address must match.
399 * property: mac-address
400 * format: usual hex-digits-and-colons notation
401 * description: MAC address in traditional hex-digits-and-colons notation,
402 * or semicolon separated list of 6 decimal bytes (obsolete)
403 * example: mac-address=00:22:68:12:79:A2
404 * mac-address=0;34;104;18;121;162;
407 * property: mac-address
408 * variable: MACADDR(+)
409 * description: MAC address of the bridge. Note that this requires a recent
410 * kernel support, originally introduced in 3.15 upstream kernel)
411 * MACADDR for bridges is an NM extension.
414 g_object_class_install_property
415 (object_class, PROP_MAC_ADDRESS,
416 g_param_spec_string (NM_SETTING_BRIDGE_MAC_ADDRESS, "", "",
419 NM_SETTING_PARAM_INFERRABLE |
420 G_PARAM_STATIC_STRINGS));
421 _nm_setting_class_transform_property (parent_class, NM_SETTING_BRIDGE_MAC_ADDRESS,
422 G_VARIANT_TYPE_BYTESTRING,
423 _nm_utils_hwaddr_to_dbus,
424 _nm_utils_hwaddr_from_dbus);
427 * NMSettingBridge:stp:
429 * Controls whether Spanning Tree Protocol (STP) is enabled for this bridge.
435 * description: Span tree protocol participation.
438 g_object_class_install_property
439 (object_class, PROP_STP,
440 g_param_spec_boolean (NM_SETTING_BRIDGE_STP, "", "",
444 NM_SETTING_PARAM_INFERRABLE |
445 G_PARAM_STATIC_STRINGS));
448 * NMSettingBridge:priority:
450 * Sets the Spanning Tree Protocol (STP) priority for this bridge. Lower
451 * values are "better"; the lowest priority bridge will be elected the root
456 * variable: BRIDGING_OPTS: priority=
459 * description: STP priority.
462 g_object_class_install_property
463 (object_class, PROP_PRIORITY,
464 g_param_spec_uint (NM_SETTING_BRIDGE_PRIORITY, "", "",
465 0, G_MAXUINT16, 0x8000,
468 NM_SETTING_PARAM_INFERRABLE |
469 G_PARAM_STATIC_STRINGS));
472 * NMSettingBridge:forward-delay:
474 * The Spanning Tree Protocol (STP) forwarding delay, in seconds.
477 * property: forward-delay
481 * description: STP forwarding delay.
484 g_object_class_install_property
485 (object_class, PROP_FORWARD_DELAY,
486 g_param_spec_uint (NM_SETTING_BRIDGE_FORWARD_DELAY, "", "",
487 0, BR_MAX_FORWARD_DELAY, 15,
490 NM_SETTING_PARAM_INFERRABLE |
491 G_PARAM_STATIC_STRINGS));
494 * NMSettingBridge:hello-time:
496 * The Spanning Tree Protocol (STP) hello time, in seconds.
499 * property: hello-time
500 * variable: BRIDGING_OPTS: hello_time=
503 * description: STP hello time.
506 g_object_class_install_property
507 (object_class, PROP_HELLO_TIME,
508 g_param_spec_uint (NM_SETTING_BRIDGE_HELLO_TIME, "", "",
509 0, BR_MAX_HELLO_TIME, 2,
512 NM_SETTING_PARAM_INFERRABLE |
513 G_PARAM_STATIC_STRINGS));
516 * NMSettingBridge:max-age:
518 * The Spanning Tree Protocol (STP) maximum message age, in seconds.
522 * variable: BRIDGING_OPTS: max_age=
525 * description: STP maximum message age.
528 g_object_class_install_property
529 (object_class, PROP_MAX_AGE,
530 g_param_spec_uint (NM_SETTING_BRIDGE_MAX_AGE, "", "",
531 0, BR_MAX_MAX_AGE, 20,
534 NM_SETTING_PARAM_INFERRABLE |
535 G_PARAM_STATIC_STRINGS));
538 * NMSettingBridge:ageing-time:
540 * The Ethernet MAC address aging time, in seconds.
543 * property: ageing-time
544 * variable: BRIDGING_OPTS: ageing_time=
545 * values: 0 - 1000000
547 * description: Ethernet MAC ageing time.
550 g_object_class_install_property
551 (object_class, PROP_AGEING_TIME,
552 g_param_spec_uint (NM_SETTING_BRIDGE_AGEING_TIME, "", "",
553 0, BR_MAX_AGEING_TIME, 300,
556 NM_SETTING_PARAM_INFERRABLE |
557 G_PARAM_STATIC_STRINGS));
560 * NMSettingBridge:multicast-snooping:
562 * Controls whether IGMP snooping is enabled for this bridge.
563 * Note that if snooping was automatically disabled due to hash collisions,
564 * the system may refuse to enable the feature until the collisions are
570 * property: multicast-snooping
571 * variable: BRIDGING_OPTS: multicast_snooping=
574 * description: IGMP snooping support.
577 g_object_class_install_property
578 (object_class, PROP_MULTICAST_SNOOPING,
579 g_param_spec_boolean (NM_SETTING_BRIDGE_MULTICAST_SNOOPING, "", "",
583 NM_SETTING_PARAM_INFERRABLE |
584 G_PARAM_STATIC_STRINGS));
587 * property: interface-name
589 * description: Deprecated in favor of connection.interface-name, but can
590 * be used for backward-compatibility with older daemons, to set the
591 * bridge's interface name.
594 _nm_setting_class_add_dbus_only_property (parent_class, "interface-name",
595 G_VARIANT_TYPE_STRING,
596 _nm_setting_get_deprecated_virtual_interface_name,