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 2012 Red Hat, Inc.
21 #include "nm-default.h"
25 #include "nm-setting-connection.h"
26 #include "nm-setting-vlan.h"
27 #include "nm-setting-wired.h"
30 #include "nm-device-vlan.h"
31 #include "nm-device-private.h"
32 #include "nm-object-private.h"
34 G_DEFINE_TYPE (NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE)
36 #define NM_DEVICE_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_VLAN, NMDeviceVlanPrivate))
43 } NMDeviceVlanPrivate;
56 * nm_device_vlan_get_hw_address:
57 * @device: a #NMDeviceVlan
59 * Gets the hardware (MAC) address of the #NMDeviceVlan
61 * Returns: the hardware address. This is the internal string used by the
62 * device, and must not be modified.
65 nm_device_vlan_get_hw_address (NMDeviceVlan *device)
67 g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), NULL);
69 return NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address;
73 * nm_device_vlan_get_carrier:
74 * @device: a #NMDeviceVlan
76 * Whether the device has carrier.
78 * Returns: %TRUE if the device has carrier
81 nm_device_vlan_get_carrier (NMDeviceVlan *device)
83 g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), FALSE);
85 return NM_DEVICE_VLAN_GET_PRIVATE (device)->carrier;
89 * nm_device_vlan_get_parent:
90 * @device: a #NMDeviceVlan
92 * Returns: (transfer none): the device's parent device
95 nm_device_vlan_get_parent (NMDeviceVlan *device)
97 g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), FALSE);
99 return NM_DEVICE_VLAN_GET_PRIVATE (device)->parent;
103 * nm_device_vlan_get_vlan_id:
104 * @device: a #NMDeviceVlan
106 * Returns: the device's VLAN ID
109 nm_device_vlan_get_vlan_id (NMDeviceVlan *device)
111 g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), FALSE);
113 return NM_DEVICE_VLAN_GET_PRIVATE (device)->vlan_id;
117 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
119 NMSettingVlan *s_vlan;
120 NMSettingWired *s_wired;
121 const char *setting_hwaddr;
123 if (!NM_DEVICE_CLASS (nm_device_vlan_parent_class)->connection_compatible (device, connection, error))
126 if (!nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
127 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
128 _("The connection was not a VLAN connection."));
132 s_vlan = nm_connection_get_setting_vlan (connection);
133 if (nm_setting_vlan_get_id (s_vlan) != nm_device_vlan_get_vlan_id (NM_DEVICE_VLAN (device))) {
134 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
135 _("The VLAN identifiers of the device and the connection didn't match."));
139 s_wired = nm_connection_get_setting_wired (connection);
141 setting_hwaddr = nm_setting_wired_get_mac_address (s_wired);
143 setting_hwaddr = NULL;
144 if (setting_hwaddr) {
145 if (!nm_utils_hwaddr_matches (setting_hwaddr, -1,
146 NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address, -1)) {
147 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
148 _("The hardware address of the device and the connection didn't match."));
156 get_setting_type (NMDevice *device)
158 return NM_TYPE_SETTING_VLAN;
162 get_hw_address (NMDevice *device)
164 return nm_device_vlan_get_hw_address (NM_DEVICE_VLAN (device));
167 /***********************************************************/
170 nm_device_vlan_init (NMDeviceVlan *device)
172 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_VLAN);
176 init_dbus (NMObject *object)
178 NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object);
179 const NMPropertiesInfo property_info[] = {
180 { NM_DEVICE_VLAN_HW_ADDRESS, &priv->hw_address },
181 { NM_DEVICE_VLAN_CARRIER, &priv->carrier },
182 { NM_DEVICE_VLAN_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE },
183 { NM_DEVICE_VLAN_VLAN_ID, &priv->vlan_id },
187 NM_OBJECT_CLASS (nm_device_vlan_parent_class)->init_dbus (object);
189 _nm_object_register_properties (object,
190 NM_DBUS_INTERFACE_DEVICE_VLAN,
195 finalize (GObject *object)
197 NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object);
199 g_free (priv->hw_address);
200 g_clear_object (&priv->parent);
202 G_OBJECT_CLASS (nm_device_vlan_parent_class)->finalize (object);
206 get_property (GObject *object,
211 NMDeviceVlan *device = NM_DEVICE_VLAN (object);
214 case PROP_HW_ADDRESS:
215 g_value_set_string (value, nm_device_vlan_get_hw_address (device));
218 g_value_set_boolean (value, nm_device_vlan_get_carrier (device));
221 g_value_set_object (value, nm_device_vlan_get_parent (device));
224 g_value_set_uint (value, nm_device_vlan_get_vlan_id (device));
227 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
233 nm_device_vlan_class_init (NMDeviceVlanClass *vlan_class)
235 GObjectClass *object_class = G_OBJECT_CLASS (vlan_class);
236 NMObjectClass *nm_object_class = NM_OBJECT_CLASS (vlan_class);
237 NMDeviceClass *device_class = NM_DEVICE_CLASS (vlan_class);
239 g_type_class_add_private (vlan_class, sizeof (NMDeviceVlanPrivate));
241 _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_VLAN);
243 /* virtual methods */
244 object_class->finalize = finalize;
245 object_class->get_property = get_property;
247 nm_object_class->init_dbus = init_dbus;
249 device_class->connection_compatible = connection_compatible;
250 device_class->get_setting_type = get_setting_type;
251 device_class->get_hw_address = get_hw_address;
256 * NMDeviceVlan:hw-address:
258 * The hardware (MAC) address of the device.
260 g_object_class_install_property
261 (object_class, PROP_HW_ADDRESS,
262 g_param_spec_string (NM_DEVICE_VLAN_HW_ADDRESS, "", "",
265 G_PARAM_STATIC_STRINGS));
268 * NMDeviceVlan:carrier:
270 * Whether the device has carrier.
272 g_object_class_install_property
273 (object_class, PROP_CARRIER,
274 g_param_spec_boolean (NM_DEVICE_VLAN_CARRIER, "", "",
277 G_PARAM_STATIC_STRINGS));
280 * NMDeviceVlan:parent:
282 * The devices's parent device.
284 g_object_class_install_property
285 (object_class, PROP_PARENT,
286 g_param_spec_object (NM_DEVICE_VLAN_PARENT, "", "",
289 G_PARAM_STATIC_STRINGS));
292 * NMDeviceVlan:vlan-id:
294 * The device's VLAN ID.
296 g_object_class_install_property
297 (object_class, PROP_VLAN_ID,
298 g_param_spec_uint (NM_DEVICE_VLAN_VLAN_ID, "", "",
301 G_PARAM_STATIC_STRINGS));