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 2007 - 2011 Novell, Inc.
19 * Copyright 2008 Red Hat, Inc.
22 #include "nm-default.h"
26 #include "nm-setting-ip4-config.h"
27 #include "nm-ip4-config.h"
28 #include "NetworkManager.h"
29 #include "nm-types-private.h"
30 #include "nm-object-private.h"
33 G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_OBJECT)
35 #define NM_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP4_CONFIG, NMIP4ConfigPrivate))
63 nm_ip4_config_init (NMIP4Config *config)
68 demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
70 NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
72 g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
73 priv->addresses = NULL;
75 priv->addresses = nm_utils_ip4_addresses_from_gvalue (value);
76 _nm_object_queue_notify (object, NM_IP4_CONFIG_ADDRESSES);
82 demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
84 if (!_nm_uint_array_demarshal (value, (GArray **) field))
87 if (!strcmp (pspec->name, NM_IP4_CONFIG_NAMESERVERS))
88 _nm_object_queue_notify (object, NM_IP4_CONFIG_NAMESERVERS);
89 else if (!strcmp (pspec->name, NM_IP4_CONFIG_WINS_SERVERS))
90 _nm_object_queue_notify (object, NM_IP4_CONFIG_WINS_SERVERS);
96 demarshal_string_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
98 if (!_nm_string_array_demarshal (value, (GPtrArray **) field))
101 _nm_object_queue_notify (object, pspec->name);
106 demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
108 NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
110 g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
113 priv->routes = nm_utils_ip4_routes_from_gvalue (value);
114 _nm_object_queue_notify (object, NM_IP4_CONFIG_ROUTES);
120 register_properties (NMIP4Config *config)
122 NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
123 const NMPropertiesInfo property_info[] = {
124 { NM_IP4_CONFIG_GATEWAY, &priv->gateway, },
125 { NM_IP4_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip4_address_array },
126 { NM_IP4_CONFIG_ROUTES, &priv->routes, demarshal_ip4_routes_array },
127 { NM_IP4_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip4_array },
128 { NM_IP4_CONFIG_DOMAINS, &priv->domains, demarshal_string_array },
129 { NM_IP4_CONFIG_SEARCHES, &priv->searches, demarshal_string_array },
130 { NM_IP4_CONFIG_WINS_SERVERS, &priv->wins, demarshal_ip4_array },
134 _nm_object_register_properties (NM_OBJECT (config),
140 constructed (GObject *object)
142 NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
144 G_OBJECT_CLASS (nm_ip4_config_parent_class)->constructed (object);
146 priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_IP4_CONFIG);
147 register_properties (NM_IP4_CONFIG (object));
151 finalize (GObject *object)
153 NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
155 g_free (priv->gateway);
157 g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
158 g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
160 if (priv->nameservers)
161 g_array_free (priv->nameservers, TRUE);
164 g_array_free (priv->wins, TRUE);
167 g_ptr_array_set_free_func (priv->domains, g_free);
168 g_ptr_array_free (priv->domains, TRUE);
171 if (priv->searches) {
172 g_ptr_array_set_free_func (priv->searches, g_free);
173 g_ptr_array_free (priv->searches, TRUE);
176 g_object_unref (priv->proxy);
178 G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object);
182 get_property (GObject *object,
187 NMIP4Config *self = NM_IP4_CONFIG (object);
188 NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
190 _nm_object_ensure_inited (NM_OBJECT (object));
194 g_value_set_string (value, nm_ip4_config_get_gateway (self));
197 nm_utils_ip4_addresses_to_gvalue (priv->addresses, value);
200 nm_utils_ip4_routes_to_gvalue (priv->routes, value);
202 case PROP_NAMESERVERS:
203 g_value_set_boxed (value, nm_ip4_config_get_nameservers (self));
206 g_value_set_boxed (value, nm_ip4_config_get_domains (self));
209 g_value_set_boxed (value, nm_ip4_config_get_searches (self));
211 case PROP_WINS_SERVERS:
212 g_value_set_boxed (value, nm_ip4_config_get_wins_servers (self));
215 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
221 nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
223 GObjectClass *object_class = G_OBJECT_CLASS (config_class);
225 g_type_class_add_private (config_class, sizeof (NMIP4ConfigPrivate));
227 /* virtual methods */
228 object_class->constructed = constructed;
229 object_class->get_property = get_property;
230 object_class->finalize = finalize;
235 * NMIP4Config:gateway:
237 * The IP4 gateway address of the configuration as string.
241 g_object_class_install_property
242 (object_class, PROP_GATEWAY,
243 g_param_spec_string (NM_IP4_CONFIG_GATEWAY, "", "",
246 G_PARAM_STATIC_STRINGS));
249 * NMIP4Config:addresses:
251 * The #GPtrArray containing #NMIP4Address<!-- -->es of the configuration.
253 g_object_class_install_property
254 (object_class, PROP_ADDRESSES,
255 g_param_spec_pointer (NM_IP4_CONFIG_ADDRESSES, "", "",
257 G_PARAM_STATIC_STRINGS));
260 * NMIP4Config:routes:
262 * The #GPtrArray containing #NMSettingIP4Routes of the configuration.
264 g_object_class_install_property
265 (object_class, PROP_ROUTES,
266 g_param_spec_pointer (NM_IP4_CONFIG_ROUTES, "", "",
268 G_PARAM_STATIC_STRINGS));
271 * NMIP4Config:nameservers:
273 * The #GArray containing name servers (#guint32s) of the configuration.
275 g_object_class_install_property
276 (object_class, PROP_NAMESERVERS,
277 g_param_spec_boxed (NM_IP4_CONFIG_NAMESERVERS, "", "",
280 G_PARAM_STATIC_STRINGS));
283 * NMIP4Config:domains:
285 * The #GPtrArray containing domain strings of the configuration.
287 g_object_class_install_property
288 (object_class, PROP_DOMAINS,
289 g_param_spec_boxed (NM_IP4_CONFIG_DOMAINS, "", "",
290 NM_TYPE_STRING_ARRAY,
292 G_PARAM_STATIC_STRINGS));
295 * NMIP4Config:searches:
297 * The #GPtrArray containing dns search strings of the configuration.
301 g_object_class_install_property
302 (object_class, PROP_SEARCHES,
303 g_param_spec_boxed (NM_IP4_CONFIG_SEARCHES, "", "",
304 NM_TYPE_STRING_ARRAY,
306 G_PARAM_STATIC_STRINGS));
309 * NMIP4Config:wins-servers:
311 * The #GArray containing WINS servers (#guint32s) of the configuration.
313 g_object_class_install_property
314 (object_class, PROP_WINS_SERVERS,
315 g_param_spec_boxed (NM_IP4_CONFIG_WINS_SERVERS, "", "",
318 G_PARAM_STATIC_STRINGS));
323 * @connection: the #DBusGConnection
324 * @object_path: the DBus object path of the device
326 * Creates a new #NMIP4Config.
328 * Returns: (transfer full): a new IP4 configuration
331 nm_ip4_config_new (DBusGConnection *connection, const char *object_path)
333 return (GObject *) g_object_new (NM_TYPE_IP4_CONFIG,
334 NM_OBJECT_DBUS_CONNECTION, connection,
335 NM_OBJECT_DBUS_PATH, object_path,
340 * nm_ip4_config_get_gateway:
341 * @config: a #NMIP4Config
343 * Gets the IP4 gateway address.
345 * Returns: the IP4 address of the gateway.
350 nm_ip4_config_get_gateway (NMIP4Config *config)
352 g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
354 _nm_object_ensure_inited (NM_OBJECT (config));
355 return NM_IP4_CONFIG_GET_PRIVATE (config)->gateway;
359 * nm_ip4_config_get_addresses:
360 * @config: a #NMIP4Config
362 * Gets the IP4 addresses (containing the address, prefix, and gateway).
364 * Returns: (element-type NMIP4Address): the #GSList containing #NMIP4Address<!-- -->es.
365 * This is the internal copy used by the configuration and must not be modified.
368 nm_ip4_config_get_addresses (NMIP4Config *config)
370 g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
372 _nm_object_ensure_inited (NM_OBJECT (config));
373 return NM_IP4_CONFIG_GET_PRIVATE (config)->addresses;
377 * nm_ip4_config_get_nameservers:
378 * @config: a #NMIP4Config
380 * Gets the domain name servers (DNS).
382 * Returns: (element-type guint32): the #GArray containing #guint32s.
383 * This is the internal copy used by the configuration and must not be
387 nm_ip4_config_get_nameservers (NMIP4Config *config)
389 g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
391 _nm_object_ensure_inited (NM_OBJECT (config));
392 return NM_IP4_CONFIG_GET_PRIVATE (config)->nameservers;
396 * nm_ip4_config_get_domains:
397 * @config: a #NMIP4Config
399 * Gets the domain names.
401 * Returns: (element-type utf8): the #GPtrArray containing domains as strings. This is the
402 * internal copy used by the configuration, and must not be modified.
405 nm_ip4_config_get_domains (NMIP4Config *config)
407 g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
409 _nm_object_ensure_inited (NM_OBJECT (config));
410 return handle_ptr_array_return (NM_IP4_CONFIG_GET_PRIVATE (config)->domains);
414 * nm_ip4_config_get_searches:
415 * @config: a #NMIP4Config
417 * Gets the dns searches.
419 * Returns: (element-type utf8): the #GPtrArray containing dns searches as strings. This is the
420 * internal copy used by the configuration, and must not be modified.
425 nm_ip4_config_get_searches (NMIP4Config *config)
427 g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
429 _nm_object_ensure_inited (NM_OBJECT (config));
430 return handle_ptr_array_return (NM_IP4_CONFIG_GET_PRIVATE (config)->searches);
434 * nm_ip4_config_get_wins_servers:
435 * @config: a #NMIP4Config
437 * Gets the Windows Internet Name Service servers (WINS).
439 * Returns: (element-type guint32): the #GArray containing #guint32s.
440 * This is the internal copy used by the configuration and must not be
444 nm_ip4_config_get_wins_servers (NMIP4Config *config)
446 g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
448 _nm_object_ensure_inited (NM_OBJECT (config));
449 return NM_IP4_CONFIG_GET_PRIVATE (config)->wins;
453 * nm_ip4_config_get_routes:
454 * @config: a #NMIP4Config
458 * Returns: (element-type NMIP4Route): the #GSList containing
459 * #NMIP4Routes. This is the internal copy used by the configuration,
460 * and must not be modified.
463 nm_ip4_config_get_routes (NMIP4Config *config)
465 g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
467 _nm_object_ensure_inited (NM_OBJECT (config));
468 return NM_IP4_CONFIG_GET_PRIVATE (config)->routes;