1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2015 Red Hat, Inc.
21 #include "nm-default.h"
25 #include "nm-setting-connection.h"
26 #include "nm-setting-macvlan.h"
27 #include "nm-setting-wired.h"
30 #include "nm-device-macvlan.h"
31 #include "nm-device-private.h"
32 #include "nm-object-private.h"
34 G_DEFINE_TYPE (NMDeviceMacvlan, nm_device_macvlan, NM_TYPE_DEVICE)
36 #define NM_DEVICE_MACVLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MACVLAN, NMDeviceMacvlanPrivate))
44 } NMDeviceMacvlanPrivate;
58 * nm_device_macvlan_get_parent:
59 * @device: a #NMDeviceMacvlan
61 * Returns: (transfer none): the device's parent device
66 nm_device_macvlan_get_parent (NMDeviceMacvlan *device)
68 g_return_val_if_fail (NM_IS_DEVICE_MACVLAN (device), FALSE);
70 return NM_DEVICE_MACVLAN_GET_PRIVATE (device)->parent;
74 * nm_device_macvlan_get_mode:
75 * @device: a #NMDeviceMacvlan
77 * Gets the MACVLAN mode of the device.
79 * Returns: the MACVLAN mode. This is the internal string used by the
80 * device, and must not be modified.
85 nm_device_macvlan_get_mode (NMDeviceMacvlan *device)
87 g_return_val_if_fail (NM_IS_DEVICE_MACVLAN (device), NULL);
89 return NM_DEVICE_MACVLAN_GET_PRIVATE (device)->mode;
93 * nm_device_macvlan_get_no_promisc
94 * @device: a #NMDeviceMacvlan
96 * Gets the no-promiscuous flag of the device.
98 * Returns: the no-promiscuous flag of the device.
103 nm_device_macvlan_get_no_promisc (NMDeviceMacvlan *device)
105 g_return_val_if_fail (NM_IS_DEVICE_MACVLAN (device), FALSE);
107 return NM_DEVICE_MACVLAN_GET_PRIVATE (device)->no_promisc;
111 * nm_device_macvlan_get_tap:
112 * @device: a #NMDeviceMacvlan
114 * Gets the device type (MACVLAN or MACVTAP).
116 * Returns: %TRUE if the device is a MACVTAP, %FALSE if it is a MACVLAN.
121 nm_device_macvlan_get_tap (NMDeviceMacvlan *device)
123 g_return_val_if_fail (NM_IS_DEVICE_MACVLAN (device), FALSE);
125 return NM_DEVICE_MACVLAN_GET_PRIVATE (device)->tap;
129 * nm_device_macvlan_get_hw_address:
130 * @device: a #NMDeviceMacvlan
132 * Gets the hardware (MAC) address of the #NMDeviceMacvlan
134 * Returns: the hardware address. This is the internal string used by the
135 * device, and must not be modified.
140 nm_device_macvlan_get_hw_address (NMDeviceMacvlan *device)
142 g_return_val_if_fail (NM_IS_DEVICE_MACVLAN (device), NULL);
144 return NM_DEVICE_MACVLAN_GET_PRIVATE (device)->hw_address;
149 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
151 NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (device);
152 NMSettingMacvlan *s_macvlan;
154 if (!NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->connection_compatible (device, connection, error))
157 if (!nm_connection_is_type (connection, NM_SETTING_MACVLAN_SETTING_NAME)) {
158 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
159 _("The connection was not a MAC-VLAN connection."));
163 s_macvlan = nm_connection_get_setting_macvlan (connection);
165 if (nm_setting_macvlan_get_tap (s_macvlan) != priv->tap)
173 get_hw_address (NMDevice *device)
175 return nm_device_macvlan_get_hw_address (NM_DEVICE_MACVLAN (device));
179 get_setting_type (NMDevice *device)
181 return NM_TYPE_SETTING_MACVLAN;
184 /***********************************************************/
187 nm_device_macvlan_init (NMDeviceMacvlan *device)
189 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_MACVLAN);
193 init_dbus (NMObject *object)
195 NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (object);
196 const NMPropertiesInfo property_info[] = {
197 { NM_DEVICE_MACVLAN_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE },
198 { NM_DEVICE_MACVLAN_MODE, &priv->mode },
199 { NM_DEVICE_MACVLAN_NO_PROMISC, &priv->no_promisc },
200 { NM_DEVICE_MACVLAN_TAP, &priv->tap },
201 { NM_DEVICE_MACVLAN_HW_ADDRESS, &priv->hw_address },
205 NM_OBJECT_CLASS (nm_device_macvlan_parent_class)->init_dbus (object);
207 _nm_object_register_properties (object,
208 NM_DBUS_INTERFACE_DEVICE_MACVLAN,
213 finalize (GObject *object)
215 NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (object);
218 g_free (priv->hw_address);
219 g_clear_object (&priv->parent);
221 G_OBJECT_CLASS (nm_device_macvlan_parent_class)->finalize (object);
225 get_property (GObject *object,
230 NMDeviceMacvlan *device = NM_DEVICE_MACVLAN (object);
234 g_value_set_object (value, nm_device_macvlan_get_parent (device));
237 g_value_set_string (value, nm_device_macvlan_get_mode (device));
239 case PROP_NO_PROMISC:
240 g_value_set_boolean (value, nm_device_macvlan_get_no_promisc (device));
243 g_value_set_boolean (value, nm_device_macvlan_get_tap (device));
245 case PROP_HW_ADDRESS:
246 g_value_set_string (value, nm_device_macvlan_get_hw_address (device));
249 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
255 nm_device_macvlan_class_init (NMDeviceMacvlanClass *gre_class)
257 GObjectClass *object_class = G_OBJECT_CLASS (gre_class);
258 NMObjectClass *nm_object_class = NM_OBJECT_CLASS (gre_class);
259 NMDeviceClass *device_class = NM_DEVICE_CLASS (gre_class);
261 g_type_class_add_private (gre_class, sizeof (NMDeviceMacvlanPrivate));
263 _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_MACVLAN);
265 /* virtual methods */
266 object_class->finalize = finalize;
267 object_class->get_property = get_property;
269 nm_object_class->init_dbus = init_dbus;
271 device_class->connection_compatible = connection_compatible;
272 device_class->get_setting_type = get_setting_type;
273 device_class->get_hw_address = get_hw_address;
278 * NMDeviceMacvlan:parent:
280 * The devices's parent device.
284 g_object_class_install_property
285 (object_class, PROP_PARENT,
286 g_param_spec_object (NM_DEVICE_MACVLAN_PARENT, "", "",
289 G_PARAM_STATIC_STRINGS));
292 * NMDeviceMacvlan:mode:
298 g_object_class_install_property
299 (object_class, PROP_MODE,
300 g_param_spec_string (NM_DEVICE_MACVLAN_MODE, "", "",
303 G_PARAM_STATIC_STRINGS));
306 * NMDeviceMacvlan:no-promisc:
308 * Whether the device has the no-promiscuos flag.
312 g_object_class_install_property
313 (object_class, PROP_NO_PROMISC,
314 g_param_spec_boolean (NM_DEVICE_MACVLAN_NO_PROMISC, "", "",
317 G_PARAM_STATIC_STRINGS));
320 * NMDeviceMacvlan:tap:
322 * Whether the device is a MACVTAP.
326 g_object_class_install_property
327 (object_class, PROP_TAP,
328 g_param_spec_boolean (NM_DEVICE_MACVLAN_TAP, "", "",
331 G_PARAM_STATIC_STRINGS));
334 * NMDeviceMacvlan:hw-address:
336 * The hardware (MAC) address of the device.
340 g_object_class_install_property
341 (object_class, PROP_HW_ADDRESS,
342 g_param_spec_string (NM_DEVICE_MACVLAN_HW_ADDRESS, "", "",
345 G_PARAM_STATIC_STRINGS));