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 - 2008 Novell, Inc.
19 * Copyright 2008 - 2014 Red Hat, Inc.
22 #include "nm-default.h"
26 #include "nm-setting-ip6-config.h"
27 #include "nm-ip6-config.h"
28 #include "NetworkManager.h"
29 #include "nm-types-private.h"
30 #include "nm-object-private.h"
33 G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_OBJECT)
35 #define NM_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP6_CONFIG, NMIP6ConfigPrivate))
62 * @connection: the #DBusGConnection
63 * @object_path: the DBus object path of the device
65 * Creates a new #NMIP6Config.
67 * Returns: (transfer full): a new IP6 configuration
70 nm_ip6_config_new (DBusGConnection *connection, const char *object_path)
72 return (GObject *) g_object_new (NM_TYPE_IP6_CONFIG,
73 NM_OBJECT_DBUS_CONNECTION, connection,
74 NM_OBJECT_DBUS_PATH, object_path,
79 demarshal_ip6_address_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
81 NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
83 g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref);
84 priv->addresses = NULL;
86 priv->addresses = nm_utils_ip6_addresses_from_gvalue (value);
87 _nm_object_queue_notify (object, NM_IP6_CONFIG_ADDRESSES);
93 demarshal_ip6_nameserver_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
95 if (!_nm_ip6_address_array_demarshal (value, (GSList **) field))
98 if (pspec && !strcmp (pspec->name, NM_IP6_CONFIG_NAMESERVERS))
99 _nm_object_queue_notify (object, NM_IP6_CONFIG_NAMESERVERS);
105 demarshal_domains (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
107 if (!_nm_string_array_demarshal (value, (GPtrArray **) field))
110 _nm_object_queue_notify (object, NM_IP6_CONFIG_DOMAINS);
115 demarshal_searches (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
117 if (!_nm_string_array_demarshal (value, (GPtrArray **) field))
120 _nm_object_queue_notify (object, NM_IP6_CONFIG_SEARCHES);
125 demarshal_ip6_routes_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
127 NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
129 g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
132 priv->routes = nm_utils_ip6_routes_from_gvalue (value);
133 _nm_object_queue_notify (object, NM_IP6_CONFIG_ROUTES);
139 register_properties (NMIP6Config *config)
141 NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
142 const NMPropertiesInfo property_info[] = {
143 { NM_IP6_CONFIG_GATEWAY, &priv->gateway, },
144 { NM_IP6_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip6_address_array },
145 { NM_IP6_CONFIG_ROUTES, &priv->routes, demarshal_ip6_routes_array },
146 { NM_IP6_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip6_nameserver_array },
147 { NM_IP6_CONFIG_DOMAINS, &priv->domains, demarshal_domains },
148 { NM_IP6_CONFIG_SEARCHES, &priv->searches, demarshal_searches },
152 _nm_object_register_properties (NM_OBJECT (config),
158 * nm_ip6_config_get_gateway:
159 * @config: a #NMIP6Config
161 * Gets the IP6 gateway.
163 * Returns: the IPv6 gateway of the configuration.
168 nm_ip6_config_get_gateway (NMIP6Config *config)
170 g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
172 _nm_object_ensure_inited (NM_OBJECT (config));
173 return NM_IP6_CONFIG_GET_PRIVATE (config)->gateway;
177 * nm_ip6_config_get_addresses:
178 * @config: a #NMIP6Config
180 * Gets the IP6 addresses (containing the address, prefix, and gateway).
182 * Returns: (element-type NMIP6Address): the #GSList containing
183 * #NMIP6Address<!-- -->es. This is the internal copy used by the configuration
184 * and must not be modified.
187 nm_ip6_config_get_addresses (NMIP6Config *config)
189 g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
191 _nm_object_ensure_inited (NM_OBJECT (config));
192 return NM_IP6_CONFIG_GET_PRIVATE (config)->addresses;
196 * nm_ip6_config_get_num_nameservers:
197 * @config: a #NMIP6Config
199 * Gets the number of the domain name servers in the configuration.
201 * Returns: the number of domain name servers
206 nm_ip6_config_get_num_nameservers (NMIP6Config *config)
208 g_return_val_if_fail (NM_IS_IP6_CONFIG (config), 0);
210 _nm_object_ensure_inited (NM_OBJECT (config));
211 return g_slist_length (NM_IP6_CONFIG_GET_PRIVATE (config)->nameservers);
215 * nm_ip6_config_get_nameserver:
216 * @config: a #NMIP6Config
217 * @idx: index of the nameserver to return
219 * Gets the domain name server at index @idx in the configuration.
221 * Returns: (array fixed-size=16) (element-type guint8) (transfer none):
222 * the IPv6 address of domain name server at index @iidx
226 const struct in6_addr *
227 nm_ip6_config_get_nameserver (NMIP6Config *config, guint32 idx)
229 NMIP6ConfigPrivate *priv;
233 g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
235 _nm_object_ensure_inited (NM_OBJECT (config));
236 priv = NM_IP6_CONFIG_GET_PRIVATE (config);
238 for (item = priv->nameservers; item && i < idx; i++)
241 g_return_val_if_fail (item, NULL);
242 return item ? (const struct in6_addr *) item->data : NULL;
245 /* FIXME: like in libnm_util, in6_addr is not introspectable, so skipping here */
247 * nm_ip6_config_get_nameservers: (skip)
248 * @config: a #NMIP6Config
250 * Gets the domain name servers (DNS).
252 * Returns: a #GSList containing elements of type 'struct in6_addr' which
253 * contain the addresses of nameservers of the configuration. This is the
254 * internal copy used by the configuration and must not be modified.
257 nm_ip6_config_get_nameservers (NMIP6Config *config)
259 g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
261 _nm_object_ensure_inited (NM_OBJECT (config));
262 return NM_IP6_CONFIG_GET_PRIVATE (config)->nameservers;
266 * nm_ip6_config_get_domains:
267 * @config: a #NMIP6Config
269 * Gets the domain names.
271 * Returns: (element-type utf8): the #GPtrArray containing domains as strings.
272 * This is the internal copy used by the configuration, and must not be modified.
275 nm_ip6_config_get_domains (NMIP6Config *config)
277 g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
279 _nm_object_ensure_inited (NM_OBJECT (config));
280 return handle_ptr_array_return (NM_IP6_CONFIG_GET_PRIVATE (config)->domains);
284 * nm_ip6_config_get_searches:
285 * @config: a #NMIP6Config
287 * Gets the dns searches.
289 * Returns: (element-type utf8): the #GPtrArray containing dns searches as strings.
290 * This is the internal copy used by the configuration, and must not be modified.
295 nm_ip6_config_get_searches (NMIP6Config *config)
297 g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
299 _nm_object_ensure_inited (NM_OBJECT (config));
300 return handle_ptr_array_return (NM_IP6_CONFIG_GET_PRIVATE (config)->searches);
304 * nm_ip6_config_get_routes:
305 * @config: a #NMIP6Config
309 * Returns: (element-type NMIP6Route): the #GSList containing
310 * #NMIP6Routes. This is the internal copy used by the configuration,
311 * and must not be modified.
314 nm_ip6_config_get_routes (NMIP6Config *config)
316 g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
318 _nm_object_ensure_inited (NM_OBJECT (config));
319 return NM_IP6_CONFIG_GET_PRIVATE (config)->routes;
323 constructed (GObject *object)
325 NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
327 G_OBJECT_CLASS (nm_ip6_config_parent_class)->constructed (object);
329 priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_IP6_CONFIG);
330 register_properties (NM_IP6_CONFIG (object));
334 finalize (GObject *object)
336 NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
338 g_free (priv->gateway);
340 g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref);
341 g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
342 g_slist_free_full (priv->nameservers, g_free);
345 g_ptr_array_set_free_func (priv->domains, g_free);
346 g_ptr_array_free (priv->domains, TRUE);
349 if (priv->searches) {
350 g_ptr_array_set_free_func (priv->searches, g_free);
351 g_ptr_array_free (priv->searches, TRUE);
354 g_object_unref (priv->proxy);
356 G_OBJECT_CLASS (nm_ip6_config_parent_class)->finalize (object);
360 get_property (GObject *object,
365 NMIP6Config *self = NM_IP6_CONFIG (object);
366 NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self);
368 _nm_object_ensure_inited (NM_OBJECT (object));
372 g_value_set_string (value, nm_ip6_config_get_gateway (self));
375 nm_utils_ip6_addresses_to_gvalue (priv->addresses, value);
378 nm_utils_ip6_routes_to_gvalue (priv->routes, value);
380 case PROP_NAMESERVERS:
381 g_value_set_boxed (value, nm_ip6_config_get_nameservers (self));
384 g_value_set_boxed (value, nm_ip6_config_get_domains (self));
387 g_value_set_boxed (value, nm_ip6_config_get_searches (self));
390 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
396 nm_ip6_config_init (NMIP6Config *config)
401 nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
403 GObjectClass *object_class = G_OBJECT_CLASS (config_class);
405 g_type_class_add_private (config_class, sizeof (NMIP6ConfigPrivate));
407 /* virtual methods */
408 object_class->constructed = constructed;
409 object_class->get_property = get_property;
410 object_class->finalize = finalize;
415 * NMIP6Config:gateway:
417 * The IPv6 gateway as string
421 g_object_class_install_property
422 (object_class, PROP_GATEWAY,
423 g_param_spec_string (NM_IP6_CONFIG_GATEWAY, "", "",
426 G_PARAM_STATIC_STRINGS));
429 * NMIP6Config:addresses:
431 * The #GPtrArray containing the IPv6 addresses; use
432 * nm_utils_ip6_addresses_from_gvalue() to return a #GSList of
433 * #NMSettingIP6Address objects that is more usable than the raw data.
435 g_object_class_install_property
436 (object_class, PROP_ADDRESSES,
437 g_param_spec_boxed (NM_IP6_CONFIG_ADDRESSES, "", "",
438 NM_TYPE_IP6_ADDRESS_OBJECT_ARRAY,
440 G_PARAM_STATIC_STRINGS));
443 * NMIP6Config:routes:
445 * The #GPtrArray containing the IPv6 routes; use
446 * nm_utils_ip6_routes_from_gvalue() to return a #GSList of
447 * #NMSettingIP6Address objects that is more usable than the raw data.
449 g_object_class_install_property
450 (object_class, PROP_ROUTES,
451 g_param_spec_boxed (NM_IP6_CONFIG_ROUTES, "", "",
452 NM_TYPE_IP6_ROUTE_OBJECT_ARRAY,
454 G_PARAM_STATIC_STRINGS));
457 * NMIP6Config:nameservers:
459 * The #GPtrArray containing elements of type 'struct ip6_addr' which
460 * contain the addresses of nameservers of the configuration.
462 g_object_class_install_property
463 (object_class, PROP_NAMESERVERS,
464 g_param_spec_boxed (NM_IP6_CONFIG_NAMESERVERS, "", "",
465 NM_TYPE_IP6_ADDRESS_ARRAY,
467 G_PARAM_STATIC_STRINGS));
470 * NMIP6Config:domains:
472 * The #GPtrArray containing domain strings of the configuration.
474 g_object_class_install_property
475 (object_class, PROP_DOMAINS,
476 g_param_spec_boxed (NM_IP6_CONFIG_DOMAINS, "", "",
477 NM_TYPE_STRING_ARRAY,
479 G_PARAM_STATIC_STRINGS));
482 * NMIP6Config:searches:
484 * The #GPtrArray containing dns search strings of the configuration.
488 g_object_class_install_property
489 (object_class, PROP_SEARCHES,
490 g_param_spec_boxed (NM_IP6_CONFIG_SEARCHES, "", "",
491 NM_TYPE_STRING_ARRAY,
493 G_PARAM_STATIC_STRINGS));