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 2012 - 2013 Red Hat, Inc.
22 #include "nm-default.h"
27 #include <dbus/dbus-glib.h>
29 #include "nm-setting-bridge-port.h"
31 #include "nm-utils-private.h"
32 #include "nm-setting-private.h"
35 * SECTION:nm-setting-bridge-port
36 * @short_description: Describes connection properties for bridge ports
37 * @include: nm-setting-bridge-port.h
39 * The #NMSettingBridgePort object is a #NMSetting subclass that describes
40 * optional properties that apply to bridge ports.
46 * nm_setting_bridge_port_error_quark:
48 * Registers an error quark for #NMSettingBridgePort if necessary.
50 * Returns: the error quark used for #NMSettingBridgePort errors.
55 nm_setting_bridge_port_error_quark (void)
59 if (G_UNLIKELY (!quark))
60 quark = g_quark_from_static_string ("nm-setting-bridge-port-error-quark");
64 G_DEFINE_TYPE_WITH_CODE (NMSettingBridgePort, nm_setting_bridge_port, NM_TYPE_SETTING,
65 _nm_register_setting (NM_SETTING_BRIDGE_PORT_SETTING_NAME,
68 NM_SETTING_BRIDGE_PORT_ERROR))
69 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BRIDGE_PORT)
71 #define NM_SETTING_BRIDGE_PORT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BRIDGE_PORT, NMSettingBridgePortPrivate))
76 gboolean hairpin_mode;
77 } NMSettingBridgePortPrivate;
87 /**************************************************************************/
90 * nm_setting_bridge_port_get_priority:
91 * @setting: the #NMSettingBridgePort
93 * Returns: the #NMSettingBridgePort:priority property of the setting
98 nm_setting_bridge_port_get_priority (NMSettingBridgePort *setting)
100 g_return_val_if_fail (NM_IS_SETTING_BRIDGE_PORT (setting), 0);
102 return NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting)->priority;
106 * nm_setting_bridge_port_get_path_cost:
107 * @setting: the #NMSettingBridgePort
109 * Returns: the #NMSettingBridgePort:path-cost property of the setting
114 nm_setting_bridge_port_get_path_cost (NMSettingBridgePort *setting)
116 g_return_val_if_fail (NM_IS_SETTING_BRIDGE_PORT (setting), 0);
118 return NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting)->path_cost;
122 * nm_setting_bridge_port_get_hairpin_mode:
123 * @setting: the #NMSettingBridgePort
125 * Returns: the #NMSettingBridgePort:hairpin-mode property of the setting
130 nm_setting_bridge_port_get_hairpin_mode (NMSettingBridgePort *setting)
132 g_return_val_if_fail (NM_IS_SETTING_BRIDGE_PORT (setting), FALSE);
134 return NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting)->hairpin_mode;
137 /**************************************************************************/
139 #define BR_MAX_PORT_PRIORITY 63
140 #define BR_DEF_PRIORITY 32
142 #define BR_MIN_PATH_COST 1
143 #define BR_MAX_PATH_COST 65535
146 verify (NMSetting *setting, GSList *all_settings, GError **error)
148 NMSettingBridgePortPrivate *priv = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting);
150 if (priv->priority > BR_MAX_PORT_PRIORITY) {
152 NM_SETTING_BRIDGE_PORT_ERROR,
153 NM_SETTING_BRIDGE_PORT_ERROR_INVALID_PROPERTY,
154 _("'%d' is not a valid value for the property (should be <= %d)"),
155 priv->priority, BR_MAX_PORT_PRIORITY);
156 g_prefix_error (error, "%s.%s: ",
157 NM_SETTING_BRIDGE_PORT_SETTING_NAME,
158 NM_SETTING_BRIDGE_PORT_PRIORITY);
162 if (priv->path_cost > BR_MAX_PATH_COST) {
164 NM_SETTING_BRIDGE_PORT_ERROR,
165 NM_SETTING_BRIDGE_PORT_ERROR_INVALID_PROPERTY,
166 _("'%d' is not a valid value for the property (should be <= %d)"),
167 priv->path_cost, BR_MAX_PATH_COST);
168 g_prefix_error (error, "%s.%s: ",
169 NM_SETTING_BRIDGE_PORT_SETTING_NAME,
170 NM_SETTING_BRIDGE_PORT_PATH_COST);
177 /**************************************************************************/
180 * nm_setting_bridge_port_new:
182 * Creates a new #NMSettingBridgePort object with default values.
184 * Returns: (transfer full): the new empty #NMSettingBridgePort object
189 nm_setting_bridge_port_new (void)
191 return (NMSetting *) g_object_new (NM_TYPE_SETTING_BRIDGE_PORT, NULL);
195 nm_setting_bridge_port_init (NMSettingBridgePort *setting)
200 set_property (GObject *object, guint prop_id,
201 const GValue *value, GParamSpec *pspec)
203 NMSettingBridgePortPrivate *priv = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (object);
207 priv->priority = (guint16) (g_value_get_uint (value) & 0xFFFF);
210 priv->path_cost = (guint16) (g_value_get_uint (value) & 0xFFFF);
212 case PROP_HAIRPIN_MODE:
213 priv->hairpin_mode = g_value_get_boolean (value);
216 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
222 get_property (GObject *object, guint prop_id,
223 GValue *value, GParamSpec *pspec)
225 NMSettingBridgePortPrivate *priv = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (object);
229 g_value_set_uint (value, priv->priority);
232 g_value_set_uint (value, priv->path_cost);
234 case PROP_HAIRPIN_MODE:
235 g_value_set_boolean (value, priv->hairpin_mode);
238 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
244 nm_setting_bridge_port_class_init (NMSettingBridgePortClass *setting_class)
246 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
247 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
249 g_type_class_add_private (setting_class, sizeof (NMSettingBridgePortPrivate));
251 /* virtual methods */
252 object_class->set_property = set_property;
253 object_class->get_property = get_property;
254 parent_class->verify = verify;
258 * NMSettingBridgePort:priority:
260 * The Spanning Tree Protocol (STP) priority of this bridge port.
264 g_object_class_install_property
265 (object_class, PROP_PRIORITY,
266 g_param_spec_uint (NM_SETTING_BRIDGE_PORT_PRIORITY, "", "",
267 0, BR_MAX_PORT_PRIORITY, BR_DEF_PRIORITY,
270 NM_SETTING_PARAM_INFERRABLE |
271 G_PARAM_STATIC_STRINGS));
274 * NMSettingBridgePort:path-cost:
276 * The Spanning Tree Protocol (STP) port cost for destinations via this
281 g_object_class_install_property
282 (object_class, PROP_PATH_COST,
283 g_param_spec_uint (NM_SETTING_BRIDGE_PORT_PATH_COST, "", "",
284 0, BR_MAX_PATH_COST, 100,
287 NM_SETTING_PARAM_INFERRABLE |
288 G_PARAM_STATIC_STRINGS));
291 * NMSettingBridgePort:hairpin-mode:
293 * Enables or disabled "hairpin mode" for the port, which allows frames to
294 * be sent back out through the port the frame was received on.
298 g_object_class_install_property
299 (object_class, PROP_HAIRPIN_MODE,
300 g_param_spec_boolean (NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, "", "",
303 NM_SETTING_PARAM_INFERRABLE |
304 G_PARAM_STATIC_STRINGS));