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 2015 Red Hat, Inc.
22 #include "nm-default.h"
27 #include "nm-setting-macvlan.h"
29 #include "nm-setting-connection.h"
30 #include "nm-setting-private.h"
31 #include "nm-setting-wired.h"
32 #include "nm-connection-private.h"
35 * SECTION:nm-setting-macvlan
36 * @short_description: Describes connection properties for macvlan interfaces
38 * The #NMSettingMacvlan object is a #NMSetting subclass that describes properties
39 * necessary for connection to macvlan interfaces.
42 G_DEFINE_TYPE_WITH_CODE (NMSettingMacvlan, nm_setting_macvlan, NM_TYPE_SETTING,
43 _nm_register_setting (MACVLAN, 1))
44 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_MACVLAN)
46 #define NM_SETTING_MACVLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_MACVLAN, NMSettingMacvlanPrivate))
50 NMSettingMacvlanMode mode;
53 } NMSettingMacvlanPrivate;
65 * nm_setting_macvlan_new:
67 * Creates a new #NMSettingMacvlan object with default values.
69 * Returns: (transfer full): the new empty #NMSettingMacvlan object
74 nm_setting_macvlan_new (void)
76 return (NMSetting *) g_object_new (NM_TYPE_SETTING_MACVLAN, NULL);
80 * nm_setting_macvlan_get_parent:
81 * @setting: the #NMSettingMacvlan
83 * Returns: the #NMSettingMacvlan:parent property of the setting
88 nm_setting_macvlan_get_parent (NMSettingMacvlan *setting)
90 g_return_val_if_fail (NM_IS_SETTING_MACVLAN (setting), NULL);
91 return NM_SETTING_MACVLAN_GET_PRIVATE (setting)->parent;
95 * nm_setting_macvlan_get_mode:
96 * @setting: the #NMSettingMacvlan
98 * Returns: the #NMSettingMacvlan:mode property of the setting
103 nm_setting_macvlan_get_mode (NMSettingMacvlan *setting)
105 g_return_val_if_fail (NM_IS_SETTING_MACVLAN (setting), NM_SETTING_MACVLAN_MODE_UNKNOWN);
106 return NM_SETTING_MACVLAN_GET_PRIVATE (setting)->mode;
110 * nm_setting_macvlan_get_promiscuous:
111 * @setting: the #NMSettingMacvlan
113 * Returns: the #NMSettingMacvlan:promiscuous property of the setting
118 nm_setting_macvlan_get_promiscuous (NMSettingMacvlan *setting)
120 g_return_val_if_fail (NM_IS_SETTING_MACVLAN (setting), FALSE);
121 return NM_SETTING_MACVLAN_GET_PRIVATE (setting)->promiscuous;
125 * nm_setting_macvlan_get_tap:
126 * @setting: the #NMSettingMacvlan
128 * Returns: the #NMSettingMacvlan:tap property of the setting
133 nm_setting_macvlan_get_tap (NMSettingMacvlan *setting)
135 g_return_val_if_fail (NM_IS_SETTING_MACVLAN (setting), FALSE);
136 return NM_SETTING_MACVLAN_GET_PRIVATE (setting)->tap;
139 /*********************************************************************/
142 nm_setting_macvlan_init (NMSettingMacvlan *setting)
147 verify (NMSetting *setting, NMConnection *connection, GError **error)
149 NMSettingMacvlanPrivate *priv = NM_SETTING_MACVLAN_GET_PRIVATE (setting);
150 NMSettingConnection *s_con;
151 NMSettingWired *s_wired;
154 s_con = nm_connection_get_setting_connection (connection);
155 s_wired = nm_connection_get_setting_wired (connection);
162 if ( !nm_utils_is_uuid (priv->parent)
163 && !nm_utils_iface_valid_name (priv->parent)) {
166 NM_CONNECTION_ERROR_INVALID_PROPERTY,
167 _("'%s' is neither an UUID nor an interface name"),
169 g_prefix_error (error, "%s.%s: ", NM_SETTING_MACVLAN_SETTING_NAME, NM_SETTING_MACVLAN_PARENT);
173 /* If parent is NULL, the parent must be specified via
174 * NMSettingWired:mac-address.
177 && (!s_wired || !nm_setting_wired_get_mac_address (s_wired))) {
180 NM_CONNECTION_ERROR_MISSING_PROPERTY,
181 _("property is not specified and neither is '%s:%s'"),
182 NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS);
183 g_prefix_error (error, "%s.%s: ", NM_SETTING_MACVLAN_SETTING_NAME, NM_SETTING_MACVLAN_PARENT);
188 if (!priv->promiscuous && priv->mode != NM_SETTING_MACVLAN_MODE_PASSTHRU) {
189 g_set_error_literal (error,
191 NM_CONNECTION_ERROR_INVALID_PROPERTY,
192 _("non promiscuous operation is allowed only in passthru mode"));
193 g_prefix_error (error, "%s.%s: ",
194 NM_SETTING_MACVLAN_SETTING_NAME,
195 NM_SETTING_MACVLAN_PROMISCUOUS);
203 set_property (GObject *object, guint prop_id,
204 const GValue *value, GParamSpec *pspec)
206 NMSettingMacvlan *setting = NM_SETTING_MACVLAN (object);
207 NMSettingMacvlanPrivate *priv = NM_SETTING_MACVLAN_GET_PRIVATE (setting);
211 g_free (priv->parent);
212 priv->parent = g_value_dup_string (value);
215 priv->mode = g_value_get_uint (value);
217 case PROP_PROMISCUOUS:
218 priv->promiscuous = g_value_get_boolean (value);
221 priv->tap = g_value_get_boolean (value);
224 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
230 get_property (GObject *object, guint prop_id,
231 GValue *value, GParamSpec *pspec)
233 NMSettingMacvlan *setting = NM_SETTING_MACVLAN (object);
234 NMSettingMacvlanPrivate *priv = NM_SETTING_MACVLAN_GET_PRIVATE (setting);
238 g_value_set_string (value, priv->parent);
241 g_value_set_uint (value, priv->mode);
243 case PROP_PROMISCUOUS:
244 g_value_set_boolean (value, priv->promiscuous);
247 g_value_set_boolean (value, priv->tap);
250 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
256 finalize (GObject *object)
258 NMSettingMacvlan *setting = NM_SETTING_MACVLAN (object);
259 NMSettingMacvlanPrivate *priv = NM_SETTING_MACVLAN_GET_PRIVATE (setting);
261 g_free (priv->parent);
263 G_OBJECT_CLASS (nm_setting_macvlan_parent_class)->finalize (object);
267 nm_setting_macvlan_class_init (NMSettingMacvlanClass *setting_class)
269 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
270 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
272 g_type_class_add_private (setting_class, sizeof (NMSettingMacvlanPrivate));
274 /* virtual methods */
275 object_class->set_property = set_property;
276 object_class->get_property = get_property;
277 object_class->finalize = finalize;
278 parent_class->verify = verify;
283 * NMSettingMacvlan:parent:
285 * If given, specifies the parent interface name or parent connection UUID
286 * from which this MAC-VLAN interface should be created. If this property is
287 * not specified, the connection must contain an #NMSettingWired setting
288 * with a #NMSettingWired:mac-address property.
292 g_object_class_install_property
293 (object_class, PROP_PARENT,
294 g_param_spec_string (NM_SETTING_MACVLAN_PARENT, "", "",
298 NM_SETTING_PARAM_INFERRABLE |
299 G_PARAM_STATIC_STRINGS));
302 * NMSettingMacvlan:mode:
304 * The macvlan mode, which specifies the communication mechanism between multiple
305 * macvlans on the same lower device.
309 g_object_class_install_property
310 (object_class, PROP_MODE,
311 g_param_spec_uint (NM_SETTING_MACVLAN_MODE, "", "",
315 NM_SETTING_PARAM_INFERRABLE |
316 G_PARAM_STATIC_STRINGS));
319 * NMSettingMacvlan:promiscuous:
321 * Whether the interface should be put in promiscuous mode.
325 g_object_class_install_property
326 (object_class, PROP_PROMISCUOUS,
327 g_param_spec_boolean (NM_SETTING_MACVLAN_PROMISCUOUS, "", "",
331 NM_SETTING_PARAM_INFERRABLE |
332 G_PARAM_STATIC_STRINGS));
335 * NMSettingMacvlan:tap:
337 * Whether the interface should be a MACVTAP.
341 g_object_class_install_property
342 (object_class, PROP_TAP,
343 g_param_spec_boolean (NM_SETTING_MACVLAN_TAP, "", "",
347 NM_SETTING_PARAM_INFERRABLE |
348 G_PARAM_STATIC_STRINGS));