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 2007 - 2014 Red Hat, Inc.
22 #include "nm-default.h"
25 #include <dbus/dbus-glib.h>
27 #include "nm-setting-ip6-config.h"
28 #include "nm-param-spec-specialized.h"
30 #include "nm-dbus-glib-types.h"
31 #include "nm-setting-private.h"
34 * SECTION:nm-setting-ip6-config
35 * @short_description: Describes IPv6 addressing, routing, and name service properties
36 * @include: nm-setting-ip6-config.h
38 * The #NMSettingIP6Config object is a #NMSetting subclass that describes
39 * properties related to IPv6 addressing, routing, and Domain Name Service
43 * nm_setting_ip6_config_error_quark:
45 * Registers an error quark for #NMSettingIP6Config if necessary.
47 * Returns: the error quark used for #NMSettingIP6Config errors.
50 nm_setting_ip6_config_error_quark (void)
54 if (G_UNLIKELY (!quark))
55 quark = g_quark_from_static_string ("nm-setting-ip6-config-error-quark");
59 G_DEFINE_BOXED_TYPE (NMIP6Address, nm_ip6_address, nm_ip6_address_dup, nm_ip6_address_unref)
60 G_DEFINE_BOXED_TYPE (NMIP6Route, nm_ip6_route, nm_ip6_route_dup, nm_ip6_route_unref)
62 G_DEFINE_TYPE_WITH_CODE (NMSettingIP6Config, nm_setting_ip6_config, NM_TYPE_SETTING,
63 _nm_register_setting (NM_SETTING_IP6_CONFIG_SETTING_NAME,
66 NM_SETTING_IP6_CONFIG_ERROR))
67 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP6_CONFIG)
69 #define NM_SETTING_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP6_CONFIG, NMSettingIP6ConfigPrivate))
74 GSList *dns; /* array of struct in6_addr */
75 GSList *dns_search; /* list of strings */
76 GSList *addresses; /* array of NMIP6Address */
77 GSList *routes; /* array of NMIP6Route */
79 gboolean ignore_auto_routes;
80 gboolean ignore_auto_dns;
81 gboolean never_default;
83 NMSettingIP6ConfigPrivacy ip6_privacy;
84 } NMSettingIP6ConfigPrivate;
96 PROP_IGNORE_AUTO_ROUTES,
106 * nm_setting_ip6_config_new:
108 * Creates a new #NMSettingIP6Config object with default values.
110 * Returns: (transfer full): the new empty #NMSettingIP6Config object
113 nm_setting_ip6_config_new (void)
115 return (NMSetting *) g_object_new (NM_TYPE_SETTING_IP6_CONFIG, NULL);
119 * nm_setting_ip6_config_get_method:
120 * @setting: the #NMSettingIP6Config
122 * Returns: the #NMSettingIP6Config:method property of the setting
125 nm_setting_ip6_config_get_method (NMSettingIP6Config *setting)
127 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
129 return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->method;
133 * nm_setting_ip6_config_get_dhcp_hostname:
134 * @setting: the #NMSettingIP6Config
136 * Returns the value contained in the #NMSettingIP6Config:dhcp-hostname
139 * Returns: the configured hostname to send to the DHCP server
144 nm_setting_ip6_config_get_dhcp_hostname (NMSettingIP6Config *setting)
146 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
148 return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dhcp_hostname;
152 * nm_setting_ip6_config_get_num_dns:
153 * @setting: the #NMSettingIP6Config
155 * Returns: the number of configured DNS servers
158 nm_setting_ip6_config_get_num_dns (NMSettingIP6Config *setting)
160 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), 0);
162 return g_slist_length (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns);
166 * nm_setting_ip6_config_get_dns:
167 * @setting: the #NMSettingIP6Config
168 * @i: index number of the DNS server to return
170 * Returns: (transfer none): the IPv6 address of the DNS server at index @i
172 const struct in6_addr *
173 nm_setting_ip6_config_get_dns (NMSettingIP6Config *setting, guint32 i)
175 NMSettingIP6ConfigPrivate *priv;
178 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
180 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
181 g_return_val_if_fail (i <= g_slist_length (priv->dns), NULL);
183 return (const struct in6_addr *) g_slist_nth_data (priv->dns, i);
187 * nm_setting_ip6_config_add_dns:
188 * @setting: the #NMSettingIP6Config
189 * @dns: the IPv6 address of the DNS server to add
191 * Adds a new DNS server to the setting.
193 * Returns: %TRUE if the DNS server was added; %FALSE if the server was already
197 nm_setting_ip6_config_add_dns (NMSettingIP6Config *setting, const struct in6_addr *addr)
199 NMSettingIP6ConfigPrivate *priv;
200 struct in6_addr *copy;
203 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
205 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
206 for (iter = priv->dns; iter; iter = g_slist_next (iter)) {
207 if (!memcmp (addr, (struct in6_addr *) iter->data, sizeof (struct in6_addr)))
211 copy = g_malloc0 (sizeof (struct in6_addr));
212 memcpy (copy, addr, sizeof (struct in6_addr));
213 priv->dns = g_slist_append (priv->dns, copy);
214 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS);
220 * nm_setting_ip6_config_remove_dns:
221 * @setting: the #NMSettingIP6Config
222 * @i: index number of the DNS server to remove
224 * Removes the DNS server at index @i.
227 nm_setting_ip6_config_remove_dns (NMSettingIP6Config *setting, guint32 i)
229 NMSettingIP6ConfigPrivate *priv;
232 g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
234 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
235 elt = g_slist_nth (priv->dns, i);
236 g_return_if_fail (elt != NULL);
239 priv->dns = g_slist_delete_link (priv->dns, elt);
240 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS);
244 * nm_setting_ip6_config_remove_dns_by_value:
245 * @setting: the #NMSettingIP6Config
246 * @dns: the IPv6 address of the DNS server to remove
248 * Removes the DNS server at index @i.
250 * Returns: %TRUE if the DNS server was found and removed; %FALSE if it was not.
255 nm_setting_ip6_config_remove_dns_by_value (NMSettingIP6Config *setting,
256 const struct in6_addr *addr)
258 NMSettingIP6ConfigPrivate *priv;
261 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
263 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
264 for (iter = priv->dns; iter; iter = g_slist_next (iter)) {
265 if (!memcmp (addr, (struct in6_addr *) iter->data, sizeof (struct in6_addr))) {
266 priv->dns = g_slist_delete_link (priv->dns, iter);
267 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS);
275 * nm_setting_ip6_config_clear_dns:
276 * @setting: the #NMSettingIP6Config
278 * Removes all configured DNS servers.
281 nm_setting_ip6_config_clear_dns (NMSettingIP6Config *setting)
283 g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
285 g_slist_free_full (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns, g_free);
286 NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns = NULL;
287 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS);
291 * nm_setting_ip6_config_get_num_dns_searches:
292 * @setting: the #NMSettingIP6Config
294 * Returns: the number of configured DNS search domains
297 nm_setting_ip6_config_get_num_dns_searches (NMSettingIP6Config *setting)
299 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), 0);
301 return g_slist_length (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns_search);
305 * nm_setting_ip6_config_get_dns_search:
306 * @setting: the #NMSettingIP6Config
307 * @i: index number of the DNS search domain to return
309 * Returns: the DNS search domain at index @i
312 nm_setting_ip6_config_get_dns_search (NMSettingIP6Config *setting, guint32 i)
314 NMSettingIP6ConfigPrivate *priv;
316 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
318 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
319 g_return_val_if_fail (i <= g_slist_length (priv->dns_search), NULL);
321 return (const char *) g_slist_nth_data (priv->dns_search, i);
325 * nm_setting_ip6_config_add_dns_search:
326 * @setting: the #NMSettingIP6Config
327 * @dns_search: the search domain to add
329 * Adds a new DNS search domain to the setting.
331 * Returns: %TRUE if the DNS search domain was added; %FALSE if the search
332 * domain was already known
335 nm_setting_ip6_config_add_dns_search (NMSettingIP6Config *setting,
336 const char *dns_search)
338 NMSettingIP6ConfigPrivate *priv;
341 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
342 g_return_val_if_fail (dns_search != NULL, FALSE);
343 g_return_val_if_fail (dns_search[0] != '\0', FALSE);
345 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
346 for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) {
347 if (!strcmp (dns_search, (char *) iter->data))
351 priv->dns_search = g_slist_append (priv->dns_search, g_strdup (dns_search));
352 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS_SEARCH);
357 * nm_setting_ip6_config_remove_dns_search:
358 * @setting: the #NMSettingIP6Config
359 * @i: index number of the DNS search domain
361 * Removes the DNS search domain at index @i.
364 nm_setting_ip6_config_remove_dns_search (NMSettingIP6Config *setting, guint32 i)
366 NMSettingIP6ConfigPrivate *priv;
369 g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
371 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
372 elt = g_slist_nth (priv->dns_search, i);
373 g_return_if_fail (elt != NULL);
376 priv->dns_search = g_slist_delete_link (priv->dns_search, elt);
377 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS_SEARCH);
381 * nm_setting_ip6_config_remove_dns_search_by_value:
382 * @setting: the #NMSettingIP6Config
383 * @dns_search: the search domain to remove
385 * Removes the DNS search domain @dns_search.
387 * Returns: %TRUE if the DNS search domain was found and removed; %FALSE if it was not.
392 nm_setting_ip6_config_remove_dns_search_by_value (NMSettingIP6Config *setting,
393 const char *dns_search)
395 NMSettingIP6ConfigPrivate *priv;
398 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
399 g_return_val_if_fail (dns_search != NULL, FALSE);
400 g_return_val_if_fail (dns_search[0] != '\0', FALSE);
402 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
403 for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) {
404 if (!strcmp (dns_search, (char *) iter->data)) {
405 priv->dns_search = g_slist_delete_link (priv->dns_search, iter);
406 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS_SEARCH);
414 * nm_setting_ip6_config_clear_dns_searches:
415 * @setting: the #NMSettingIP6Config
417 * Removes all configured DNS search domains.
420 nm_setting_ip6_config_clear_dns_searches (NMSettingIP6Config *setting)
422 g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
424 g_slist_free_full (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns_search, g_free);
425 NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->dns_search = NULL;
426 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS_SEARCH);
430 * nm_setting_ip6_config_get_num_addresses:
431 * @setting: the #NMSettingIP6Config
433 * Returns: the number of configured addresses
436 nm_setting_ip6_config_get_num_addresses (NMSettingIP6Config *setting)
438 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), 0);
440 return g_slist_length (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->addresses);
444 * nm_setting_ip6_config_get_address:
445 * @setting: the #NMSettingIP6Config
446 * @i: index number of the address to return
448 * Returns: the address at index @i
451 nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i)
453 NMSettingIP6ConfigPrivate *priv;
455 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
457 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
458 g_return_val_if_fail (i <= g_slist_length (priv->addresses), NULL);
460 return (NMIP6Address *) g_slist_nth_data (priv->addresses, i);
464 * nm_setting_ip6_config_add_address:
465 * @setting: the #NMSettingIP6Config
466 * @address: the new address to add
468 * Adds a new IPv6 address and associated information to the setting. The
469 * given address is duplicated internally and is not changed by this function.
471 * Returns: %TRUE if the address was added; %FALSE if the address was already
475 nm_setting_ip6_config_add_address (NMSettingIP6Config *setting,
476 NMIP6Address *address)
478 NMSettingIP6ConfigPrivate *priv;
482 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
483 g_return_val_if_fail (address != NULL, FALSE);
485 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
486 for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
487 if (nm_ip6_address_compare ((NMIP6Address *) iter->data, address))
491 copy = nm_ip6_address_dup (address);
492 priv->addresses = g_slist_append (priv->addresses, copy);
493 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
498 * nm_setting_ip6_config_remove_address:
499 * @setting: the #NMSettingIP6Config
500 * @i: index number of the address to remove
502 * Removes the address at index @i.
505 nm_setting_ip6_config_remove_address (NMSettingIP6Config *setting, guint32 i)
507 NMSettingIP6ConfigPrivate *priv;
510 g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
512 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
513 elt = g_slist_nth (priv->addresses, i);
514 g_return_if_fail (elt != NULL);
516 nm_ip6_address_unref ((NMIP6Address *) elt->data);
517 priv->addresses = g_slist_delete_link (priv->addresses, elt);
518 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
522 * nm_setting_ip6_config_remove_address_by_value:
523 * @setting: the #NMSettingIP6Config
524 * @address: the address to remove
526 * Removes the address @address.
528 * Returns: %TRUE if the address was found and removed; %FALSE if it was not.
533 nm_setting_ip6_config_remove_address_by_value (NMSettingIP6Config *setting,
534 NMIP6Address *address)
536 NMSettingIP6ConfigPrivate *priv;
539 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
540 g_return_val_if_fail (address != NULL, FALSE);
542 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
543 for (iter = priv->addresses; iter; iter = g_slist_next (iter)) {
544 if (nm_ip6_address_compare ((NMIP6Address *) iter->data, address)) {
545 priv->addresses = g_slist_delete_link (priv->addresses, iter);
546 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
554 * nm_setting_ip6_config_clear_addresses:
555 * @setting: the #NMSettingIP6Config
557 * Removes all configured addresses.
560 nm_setting_ip6_config_clear_addresses (NMSettingIP6Config *setting)
562 NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
564 g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
566 g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref);
567 priv->addresses = NULL;
568 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES);
572 * nm_setting_ip6_config_get_num_routes:
573 * @setting: the #NMSettingIP6Config
575 * Returns: the number of configured routes
578 nm_setting_ip6_config_get_num_routes (NMSettingIP6Config *setting)
580 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), 0);
582 return g_slist_length (NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->routes);
586 * nm_setting_ip6_config_get_route:
587 * @setting: the #NMSettingIP6Config
588 * @i: index number of the route to return
590 * Returns: the route at index @i
593 nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i)
595 NMSettingIP6ConfigPrivate *priv;
597 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NULL);
599 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
600 g_return_val_if_fail (i <= g_slist_length (priv->routes), NULL);
602 return (NMIP6Route *) g_slist_nth_data (priv->routes, i);
606 * nm_setting_ip6_config_add_route:
607 * @setting: the #NMSettingIP6Config
608 * @route: the route to add
610 * Adds a new IPv6 route and associated information to the setting. The
611 * given route is duplicated internally and is not changed by this function.
613 * Returns: %TRUE if the route was added; %FALSE if the route was already known.
616 nm_setting_ip6_config_add_route (NMSettingIP6Config *setting,
619 NMSettingIP6ConfigPrivate *priv;
623 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
624 g_return_val_if_fail (route != NULL, FALSE);
626 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
627 for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
628 if (nm_ip6_route_compare ((NMIP6Route *) iter->data, route))
632 copy = nm_ip6_route_dup (route);
633 priv->routes = g_slist_append (priv->routes, copy);
634 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
639 * nm_setting_ip6_config_remove_route:
640 * @setting: the #NMSettingIP6Config
641 * @i: index number of the route
643 * Removes the route at index @i.
646 nm_setting_ip6_config_remove_route (NMSettingIP6Config *setting, guint32 i)
648 NMSettingIP6ConfigPrivate *priv;
651 g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
653 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
654 elt = g_slist_nth (priv->routes, i);
655 g_return_if_fail (elt != NULL);
657 nm_ip6_route_unref ((NMIP6Route *) elt->data);
658 priv->routes = g_slist_delete_link (priv->routes, elt);
659 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
663 * nm_setting_ip6_config_remove_route_by_value:
664 * @setting: the #NMSettingIP6Config
665 * @route: the route to remove
667 * Removes the route @route.
669 * Returns: %TRUE if the route was found and removed; %FALSE if it was not.
674 nm_setting_ip6_config_remove_route_by_value (NMSettingIP6Config *setting,
677 NMSettingIP6ConfigPrivate *priv;
680 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
681 g_return_val_if_fail (route != NULL, FALSE);
683 priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
684 for (iter = priv->routes; iter; iter = g_slist_next (iter)) {
685 if (nm_ip6_route_compare ((NMIP6Route *) iter->data, route)) {
686 nm_ip6_route_unref ((NMIP6Route *) iter->data);
687 priv->routes = g_slist_delete_link (priv->routes, iter);
688 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
696 * nm_setting_ip6_config_clear_routes:
697 * @setting: the #NMSettingIP6Config
699 * Removes all configured routes.
702 nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting)
704 NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
706 g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting));
708 g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
710 g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES);
714 * nm_setting_ip6_config_get_route_metric:
715 * @setting: the #NMSettingIP6Config
717 * Returns the value contained in the #NMSettingIP6Config:route-metric
720 * Returns: the route metric that is used for IPv6 routes that don't explicitly
721 * specify a metric. See #NMSettingIP6Config:route-metric for more details.
726 nm_setting_ip6_config_get_route_metric (NMSettingIP6Config *setting)
728 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), -1);
730 return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->route_metric;
734 * nm_setting_ip6_config_get_ignore_auto_routes:
735 * @setting: the #NMSettingIP6Config
737 * Returns the value contained in the #NMSettingIP6Config:ignore-auto-routes
740 * Returns: %TRUE if automatically configured (ie via DHCP) routes should be
744 nm_setting_ip6_config_get_ignore_auto_routes (NMSettingIP6Config *setting)
746 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
748 return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->ignore_auto_routes;
752 * nm_setting_ip6_config_get_ignore_auto_dns:
753 * @setting: the #NMSettingIP6Config
755 * Returns the value contained in the #NMSettingIP6Config:ignore-auto-dns
758 * Returns: %TRUE if automatically configured (ie via DHCP or router
759 * advertisements) DNS information should be ignored.
762 nm_setting_ip6_config_get_ignore_auto_dns (NMSettingIP6Config *setting)
764 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
766 return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->ignore_auto_dns;
770 * nm_setting_ip6_config_get_never_default:
771 * @setting: the #NMSettingIP6Config
773 * Returns the value contained in the #NMSettingIP6Config:never-default
776 * Returns: %TRUE if this connection should never be the default connection
777 * for IPv6 addressing
780 nm_setting_ip6_config_get_never_default (NMSettingIP6Config *setting)
782 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
784 return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->never_default;
788 * nm_setting_ip6_config_get_may_fail:
789 * @setting: the #NMSettingIP6Config
791 * Returns the value contained in the #NMSettingIP6Config:may-fail
794 * Returns: %TRUE if this connection doesn't require IPv6 addressing to complete
795 * for the connection to succeed.
798 nm_setting_ip6_config_get_may_fail (NMSettingIP6Config *setting)
800 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE);
802 return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->may_fail;
806 * nm_setting_ip6_config_get_ip6_privacy:
807 * @setting: the #NMSettingIP6Config
809 * Returns the value contained in the #NMSettingIP6Config:ip6-privacy
812 * Returns: IPv6 Privacy Extensions configuration value (#NMSettingIP6ConfigPrivacy).
814 NMSettingIP6ConfigPrivacy
815 nm_setting_ip6_config_get_ip6_privacy (NMSettingIP6Config *setting)
817 g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN);
819 return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->ip6_privacy;
823 verify (NMSetting *setting, GSList *all_settings, GError **error)
825 NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
830 g_set_error_literal (error,
831 NM_SETTING_IP6_CONFIG_ERROR,
832 NM_SETTING_IP6_CONFIG_ERROR_MISSING_PROPERTY,
833 _("property is missing"));
834 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_METHOD);
838 if (!strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
839 if (!priv->addresses) {
841 NM_SETTING_IP6_CONFIG_ERROR,
842 NM_SETTING_IP6_CONFIG_ERROR_MISSING_PROPERTY,
843 _("this property cannot be empty for '%s=%s'"),
844 NM_SETTING_IP6_CONFIG_METHOD, priv->method);
845 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_ADDRESSES);
848 } else if ( !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)
849 || !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)
850 || !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) {
851 if (g_slist_length (priv->dns)) {
853 NM_SETTING_IP6_CONFIG_ERROR,
854 NM_SETTING_IP6_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
855 _("this property is not allowed for '%s=%s'"),
856 NM_SETTING_IP6_CONFIG_METHOD, priv->method);
857 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_DNS);
861 if (g_slist_length (priv->dns_search)) {
863 NM_SETTING_IP6_CONFIG_ERROR,
864 NM_SETTING_IP6_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
865 _("this property is not allowed for '%s=%s'"),
866 NM_SETTING_IP6_CONFIG_METHOD, priv->method);
867 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_DNS_SEARCH);
871 if (g_slist_length (priv->addresses)) {
873 NM_SETTING_IP6_CONFIG_ERROR,
874 NM_SETTING_IP6_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD,
875 _("this property is not allowed for '%s=%s'"),
876 NM_SETTING_IP6_CONFIG_METHOD, priv->method);
877 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_ADDRESSES);
880 } else if ( !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)
881 || !strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) {
884 g_set_error_literal (error,
885 NM_SETTING_IP6_CONFIG_ERROR,
886 NM_SETTING_IP6_CONFIG_ERROR_INVALID_PROPERTY,
887 _("property is invalid"));
888 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_METHOD);
892 if (priv->dhcp_hostname && !strlen (priv->dhcp_hostname)) {
893 g_set_error_literal (error,
894 NM_SETTING_IP6_CONFIG_ERROR,
895 NM_SETTING_IP6_CONFIG_ERROR_INVALID_PROPERTY,
896 _("property is missing"));
897 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME);
901 /* Validate addresses */
902 for (iter = priv->addresses, i = 0; iter; iter = g_slist_next (iter), i++) {
903 NMIP6Address *addr = (NMIP6Address *) iter->data;
904 guint32 prefix = nm_ip6_address_get_prefix (addr);
906 if (IN6_IS_ADDR_UNSPECIFIED (nm_ip6_address_get_address (addr))) {
908 NM_SETTING_IP6_CONFIG_ERROR,
909 NM_SETTING_IP6_CONFIG_ERROR_INVALID_PROPERTY,
910 _("%d. IPv6 address is invalid"),
912 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_ADDRESSES);
916 if (!prefix || prefix > 128) {
918 NM_SETTING_IP6_CONFIG_ERROR,
919 NM_SETTING_IP6_CONFIG_ERROR_INVALID_PROPERTY,
920 _("%d. IPv6 address has invalid prefix"),
922 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_ADDRESSES);
927 /* Validate routes */
928 for (iter = priv->routes, i = 0; iter; iter = g_slist_next (iter), i++) {
929 NMIP6Route *route = (NMIP6Route *) iter->data;
930 guint32 prefix = nm_ip6_route_get_prefix (route);
932 if (!prefix || prefix > 128) {
934 NM_SETTING_IP6_CONFIG_ERROR,
935 NM_SETTING_IP6_CONFIG_ERROR_INVALID_PROPERTY,
936 _("%d. route has invalid prefix"),
938 g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_ROUTES);
948 nm_setting_ip6_config_init (NMSettingIP6Config *setting)
953 finalize (GObject *object)
955 NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (object);
957 g_free (priv->method);
958 g_free (priv->dhcp_hostname);
960 g_slist_free_full (priv->dns, g_free);
961 g_slist_free_full (priv->dns_search, g_free);
962 g_slist_free_full (priv->addresses, g_free);
963 g_slist_free_full (priv->routes, g_free);
965 G_OBJECT_CLASS (nm_setting_ip6_config_parent_class)->finalize (object);
969 set_property (GObject *object, guint prop_id,
970 const GValue *value, GParamSpec *pspec)
972 NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (object);
976 g_free (priv->method);
977 priv->method = g_value_dup_string (value);
980 g_slist_free_full (priv->dns, g_free);
981 priv->dns = nm_utils_ip6_dns_from_gvalue (value);
983 case PROP_DNS_SEARCH:
984 g_slist_free_full (priv->dns_search, g_free);
985 priv->dns_search = g_value_dup_boxed (value);
988 g_slist_free_full (priv->addresses, g_free);
989 priv->addresses = nm_utils_ip6_addresses_from_gvalue (value);
992 g_slist_free_full (priv->routes, g_free);
993 priv->routes = nm_utils_ip6_routes_from_gvalue (value);
995 case PROP_ROUTE_METRIC:
996 priv->route_metric = g_value_get_int64 (value);
998 case PROP_IGNORE_AUTO_ROUTES:
999 priv->ignore_auto_routes = g_value_get_boolean (value);
1001 case PROP_IGNORE_AUTO_DNS:
1002 priv->ignore_auto_dns = g_value_get_boolean (value);
1004 case PROP_DHCP_HOSTNAME:
1005 g_free (priv->dhcp_hostname);
1006 priv->dhcp_hostname = g_value_dup_string (value);
1008 case PROP_NEVER_DEFAULT:
1009 priv->never_default = g_value_get_boolean (value);
1012 priv->may_fail = g_value_get_boolean (value);
1014 case PROP_IP6_PRIVACY:
1015 priv->ip6_privacy = g_value_get_int (value);
1018 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1024 get_property (GObject *object, guint prop_id,
1025 GValue *value, GParamSpec *pspec)
1027 NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (object);
1031 g_value_set_string (value, priv->method);
1034 nm_utils_ip6_dns_to_gvalue (priv->dns, value);
1036 case PROP_DNS_SEARCH:
1037 g_value_set_boxed (value, priv->dns_search);
1039 case PROP_ADDRESSES:
1040 nm_utils_ip6_addresses_to_gvalue (priv->addresses, value);
1043 nm_utils_ip6_routes_to_gvalue (priv->routes, value);
1045 case PROP_ROUTE_METRIC:
1046 g_value_set_int64 (value, priv->route_metric);
1048 case PROP_IGNORE_AUTO_ROUTES:
1049 g_value_set_boolean (value, priv->ignore_auto_routes);
1051 case PROP_IGNORE_AUTO_DNS:
1052 g_value_set_boolean (value, priv->ignore_auto_dns);
1054 case PROP_DHCP_HOSTNAME:
1055 g_value_set_string (value, priv->dhcp_hostname);
1057 case PROP_NEVER_DEFAULT:
1058 g_value_set_boolean (value, priv->never_default);
1061 g_value_set_boolean (value, priv->may_fail);
1063 case PROP_IP6_PRIVACY:
1064 g_value_set_int (value, priv->ip6_privacy);
1067 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1073 nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class)
1075 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
1076 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
1078 g_type_class_add_private (setting_class, sizeof (NMSettingIP6ConfigPrivate));
1080 /* virtual methods */
1081 object_class->set_property = set_property;
1082 object_class->get_property = get_property;
1083 object_class->finalize = finalize;
1084 parent_class->verify = verify;
1088 * NMSettingIP6Config:method:
1090 * IPv6 configuration method. If "auto" is specified then the appropriate
1091 * automatic method (PPP, router advertisement, etc) is used for the device
1092 * and most other properties can be left unset. To force the use of DHCP
1093 * only, specify "dhcp"; this method is only valid for Ethernet- based
1094 * hardware. If "link-local" is specified, then an IPv6 link-local address
1095 * will be assigned to the interface. If "manual" is specified, static IP
1096 * addressing is used and at least one IP address must be given in the
1097 * "addresses" property. If "ignore" is specified, IPv6 configuration is
1098 * not done. This property must be set. Note: the "shared" method is not
1101 g_object_class_install_property
1102 (object_class, PROP_METHOD,
1103 g_param_spec_string (NM_SETTING_IP6_CONFIG_METHOD, "", "",
1106 NM_SETTING_PARAM_INFERRABLE |
1107 G_PARAM_STATIC_STRINGS));
1110 * NMSettingIP6Config:dhcp-hostname:
1112 * The specified name will be sent to the DHCP server when acquiring a
1117 g_object_class_install_property
1118 (object_class, PROP_DHCP_HOSTNAME,
1119 g_param_spec_string (NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME, "", "",
1122 G_PARAM_STATIC_STRINGS));
1125 * NMSettingIP6Config:dns:
1127 * Array of DNS servers, where each member of the array is a byte array
1128 * containing the IPv6 address of the DNS server (in network byte order).
1129 * For the "auto" method, these DNS servers are appended to those (if any)
1130 * returned by automatic configuration. DNS servers cannot be used with the
1131 * "shared" or "link-local" methods as there is no usptream network. In all
1132 * other methods, these DNS servers are used as the only DNS servers for
1135 g_object_class_install_property
1136 (object_class, PROP_DNS,
1137 _nm_param_spec_specialized (NM_SETTING_IP6_CONFIG_DNS, "", "",
1138 DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR,
1140 G_PARAM_STATIC_STRINGS));
1143 * NMSettingIP6Config:dns-search:
1145 * List of DNS search domains. For the "auto" method, these search domains
1146 * are appended to those returned by automatic configuration. Search domains
1147 * cannot be used with the "shared" or "link-local" methods as there is no
1148 * upstream network. In all other methods, these search domains are used as
1149 * the only search domains for this connection.
1151 g_object_class_install_property
1152 (object_class, PROP_DNS_SEARCH,
1153 _nm_param_spec_specialized (NM_SETTING_IP6_CONFIG_DNS_SEARCH, "", "",
1154 DBUS_TYPE_G_LIST_OF_STRING,
1156 G_PARAM_STATIC_STRINGS));
1159 * NMSettingIP6Config:addresses:
1161 * Array of IPv6 address structures. Each IPv6 address structure is
1162 * composed of 3 members, the first being a byte array containing the IPv6
1163 * address (network byte order), the second a 32-bit integer containing the
1164 * IPv6 address prefix, and the third a byte array containing the IPv6
1165 * address (network byte order) of the gateway associated with this address,
1166 * if any. If no gateway is given, the third element should be given as all
1167 * zeros. For the "auto" method, given IP addresses are appended to those
1168 * returned by automatic configuration. Addresses cannot be used with the
1169 * "shared" or "link-local" methods as the interface is automatically
1170 * assigned an address with these methods.
1172 g_object_class_install_property
1173 (object_class, PROP_ADDRESSES,
1174 _nm_param_spec_specialized (NM_SETTING_IP6_CONFIG_ADDRESSES, "", "",
1175 DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS,
1177 NM_SETTING_PARAM_INFERRABLE |
1178 G_PARAM_STATIC_STRINGS));
1181 * NMSettingIP6Config:routes:
1183 * Array of IPv6 route structures. Each IPv6 route structure is composed of
1184 * 4 members; the first being the destination IPv6 network or address
1185 * (network byte order) as a byte array, the second the destination network
1186 * or address IPv6 prefix, the third being the next-hop IPv6 address
1187 * (network byte order) if any, and the fourth being the route metric. For
1188 * the "auto" method, given IP routes are appended to those returned by
1189 * automatic configuration. Routes cannot be used with the "shared" or
1190 * "link-local" methods because there is no upstream network.
1192 g_object_class_install_property
1193 (object_class, PROP_ROUTES,
1194 _nm_param_spec_specialized (NM_SETTING_IP6_CONFIG_ROUTES, "", "",
1195 DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE,
1197 NM_SETTING_PARAM_INFERRABLE |
1198 G_PARAM_STATIC_STRINGS));
1201 * NMSettingIP6Config:route-metric:
1203 * The default metric for routes that don't explicitly specify a metric.
1204 * The default value -1 means that the metric is choosen automatically
1205 * based on the device type.
1206 * The metric applies to dynamic routes, manual (static) routes that
1207 * don't have an explicit metric setting, address prefix routes, and
1208 * the default route.
1209 * As the linux kernel replaces zero (0) by 1024 (user-default), setting
1210 * this property to 0 means effectively setting it to 1024.
1214 g_object_class_install_property
1215 (object_class, PROP_ROUTE_METRIC,
1216 g_param_spec_int64 (NM_SETTING_IP6_CONFIG_ROUTE_METRIC, "", "",
1217 -1, G_MAXUINT32, -1,
1220 G_PARAM_STATIC_STRINGS));
1223 * NMSettingIP6Config:ignore-auto-routes:
1225 * When the method is set to "auto" or "dhcp" and this property is set to
1226 * %TRUE, automatically configured routes are ignored and only routes
1227 * specified in the #NMSettingIP6Config:routes property, if any, are used.
1229 g_object_class_install_property
1230 (object_class, PROP_IGNORE_AUTO_ROUTES,
1231 g_param_spec_boolean (NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, "", "",
1235 G_PARAM_STATIC_STRINGS));
1238 * NMSettingIP6Config:ignore-auto-dns:
1240 * When the method is set to "auto" or "dhcp" and this property is set to
1241 * %TRUE, automatically configured nameservers and search domains are
1242 * ignored and only nameservers and search domains specified in the
1243 * #NMSettingIP6Config:dns and #NMSettingIP6Config:dns-search properties, if
1246 g_object_class_install_property
1247 (object_class, PROP_IGNORE_AUTO_DNS,
1248 g_param_spec_boolean (NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, "", "",
1252 G_PARAM_STATIC_STRINGS));
1255 * NMSettingIP6Config:never-default:
1257 * If %TRUE, this connection will never be the default IPv6 connection,
1258 * meaning it will never be assigned the default IPv6 route by
1261 g_object_class_install_property
1262 (object_class, PROP_NEVER_DEFAULT,
1263 g_param_spec_boolean (NM_SETTING_IP6_CONFIG_NEVER_DEFAULT, "", "",
1267 G_PARAM_STATIC_STRINGS));
1270 * NMSettingIP6Config:may-fail:
1272 * If %TRUE, allow overall network configuration to proceed even if IPv6
1273 * configuration times out. Note that at least one IP configuration must
1274 * succeed or overall network configuration will still fail. For example,
1275 * in IPv4-only networks, setting this property to %TRUE allows the overall
1276 * network configuration to succeed if IPv6 configuration fails but IPv4
1277 * configuration completes successfully.
1279 g_object_class_install_property
1280 (object_class, PROP_MAY_FAIL,
1281 g_param_spec_boolean (NM_SETTING_IP6_CONFIG_MAY_FAIL, "", "",
1285 G_PARAM_STATIC_STRINGS));
1288 * NMSettingIP6Config:ip6-privacy:
1290 * Configure IPv6 Privacy Extensions for SLAAC, described in RFC4941. If
1291 * enabled, it makes the kernel generate a temporary IPv6 address in
1292 * addition to the public one generated from MAC address via modified
1293 * EUI-64. This enhances privacy, but could cause problems in some
1294 * applications, on the other hand. The permitted values are: 0: disabled,
1295 * 1: enabled (prefer public address), 2: enabled (prefer temporary
1298 g_object_class_install_property
1299 (object_class, PROP_IP6_PRIVACY,
1300 g_param_spec_int (NM_SETTING_IP6_CONFIG_IP6_PRIVACY, "", "",
1301 NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN,
1302 NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR,
1303 NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN,
1306 G_PARAM_STATIC_STRINGS));
1309 /********************************************************************/
1311 struct NMIP6Address {
1313 struct in6_addr address;
1315 struct in6_addr gateway;
1319 * nm_ip6_address_new:
1321 * Creates and returns a new #NMIP6Address object.
1323 * Returns: (transfer full): the new empty #NMIP6Address object
1326 nm_ip6_address_new (void)
1328 NMIP6Address *address;
1330 address = g_malloc0 (sizeof (NMIP6Address));
1331 address->refcount = 1;
1336 * nm_ip6_address_dup:
1337 * @source: the #NMIP6Address object to copy
1339 * Copies a given #NMIP6Address object and returns the copy.
1341 * Returns: (transfer full): the copy of the given #NMIP6Address copy
1344 nm_ip6_address_dup (NMIP6Address *source)
1346 NMIP6Address *address;
1348 g_return_val_if_fail (source != NULL, NULL);
1349 g_return_val_if_fail (source->refcount > 0, NULL);
1351 address = nm_ip6_address_new ();
1352 address->prefix = source->prefix;
1353 memcpy (&address->address, &source->address, sizeof (struct in6_addr));
1354 memcpy (&address->gateway, &source->gateway, sizeof (struct in6_addr));
1360 * nm_ip6_address_ref:
1361 * @address: the #NMIP6Address
1363 * Increases the reference count of the object.
1366 nm_ip6_address_ref (NMIP6Address *address)
1368 g_return_if_fail (address != NULL);
1369 g_return_if_fail (address->refcount > 0);
1371 address->refcount++;
1375 * nm_ip6_address_unref:
1376 * @address: the #NMIP6Address
1378 * Decreases the reference count of the object. If the reference count
1379 * reaches zero, the object will be destroyed.
1382 nm_ip6_address_unref (NMIP6Address *address)
1384 g_return_if_fail (address != NULL);
1385 g_return_if_fail (address->refcount > 0);
1387 address->refcount--;
1388 if (address->refcount == 0) {
1389 memset (address, 0, sizeof (NMIP6Address));
1395 * nm_ip6_address_compare:
1396 * @address: the #NMIP6Address
1397 * @other: the #NMIP6Address to compare @address to.
1399 * Determines if two #NMIP6Address objects contain the same values.
1401 * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
1404 nm_ip6_address_compare (NMIP6Address *address, NMIP6Address *other)
1406 g_return_val_if_fail (address != NULL, FALSE);
1407 g_return_val_if_fail (address->refcount > 0, FALSE);
1409 g_return_val_if_fail (other != NULL, FALSE);
1410 g_return_val_if_fail (other->refcount > 0, FALSE);
1412 if ( memcmp (&address->address, &other->address, sizeof (struct in6_addr))
1413 || address->prefix != other->prefix
1414 || memcmp (&address->gateway, &other->gateway, sizeof (struct in6_addr)))
1420 * nm_ip6_address_get_address:
1421 * @address: the #NMIP6Address
1423 * Gets the IPv6 address property of this address object.
1425 * Returns: (array fixed-size=16) (element-type guint8) (transfer none):
1428 const struct in6_addr *
1429 nm_ip6_address_get_address (NMIP6Address *address)
1431 g_return_val_if_fail (address != NULL, NULL);
1432 g_return_val_if_fail (address->refcount > 0, NULL);
1434 return &address->address;
1438 * nm_ip6_address_set_address:
1439 * @address: the #NMIP6Address
1440 * @addr: the IPv6 address
1442 * Sets the IPv6 address property of this object.
1445 nm_ip6_address_set_address (NMIP6Address *address, const struct in6_addr *addr)
1447 g_return_if_fail (address != NULL);
1448 g_return_if_fail (address->refcount > 0);
1449 g_return_if_fail (addr != NULL);
1451 memcpy (&address->address, addr, sizeof (struct in6_addr));
1455 * nm_ip6_address_get_prefix:
1456 * @address: the #NMIP6Address
1458 * Gets the IPv6 address prefix property of this address object.
1460 * Returns: the IPv6 address prefix
1463 nm_ip6_address_get_prefix (NMIP6Address *address)
1465 g_return_val_if_fail (address != NULL, 0);
1466 g_return_val_if_fail (address->refcount > 0, 0);
1468 return address->prefix;
1472 * nm_ip6_address_set_prefix:
1473 * @address: the #NMIP6Address
1474 * @prefix: the address prefix, a number between 0 and 128 inclusive
1476 * Sets the IPv6 address prefix.
1479 nm_ip6_address_set_prefix (NMIP6Address *address, guint32 prefix)
1481 g_return_if_fail (address != NULL);
1482 g_return_if_fail (address->refcount > 0);
1483 g_return_if_fail (prefix <= 128);
1484 g_return_if_fail (prefix > 0);
1486 address->prefix = prefix;
1490 * nm_ip6_address_get_gateway:
1491 * @address: the #NMIP6Address
1493 * Gets the IPv6 default gateway property of this address object.
1495 * Returns: (array fixed-size=16) (element-type guint8) (transfer none):
1496 * the IPv6 gateway address
1498 const struct in6_addr *
1499 nm_ip6_address_get_gateway (NMIP6Address *address)
1501 g_return_val_if_fail (address != NULL, NULL);
1502 g_return_val_if_fail (address->refcount > 0, NULL);
1504 return &address->gateway;
1508 * nm_ip6_address_set_gateway:
1509 * @address: the #NMIP6Address
1510 * @gateway: the IPv6 default gateway
1512 * Sets the IPv6 default gateway property of this address object.
1515 nm_ip6_address_set_gateway (NMIP6Address *address, const struct in6_addr *gateway)
1517 g_return_if_fail (address != NULL);
1518 g_return_if_fail (address->refcount > 0);
1519 g_return_if_fail (gateway != NULL);
1521 memcpy (&address->gateway, gateway, sizeof (struct in6_addr));
1524 /********************************************************************/
1529 struct in6_addr dest;
1531 struct in6_addr next_hop;
1532 guint32 metric; /* lower metric == more preferred */
1538 * Creates and returns a new #NMIP6Route object.
1540 * Returns: (transfer full): the new empty #NMIP6Route object
1543 nm_ip6_route_new (void)
1547 route = g_malloc0 (sizeof (NMIP6Route));
1548 route->refcount = 1;
1554 * @source: the #NMIP6Route object to copy
1556 * Copies a given #NMIP6Route object and returns the copy.
1558 * Returns: (transfer full): the copy of the given #NMIP6Route copy
1561 nm_ip6_route_dup (NMIP6Route *source)
1565 g_return_val_if_fail (source != NULL, NULL);
1566 g_return_val_if_fail (source->refcount > 0, NULL);
1568 route = nm_ip6_route_new ();
1569 route->prefix = source->prefix;
1570 route->metric = source->metric;
1571 memcpy (&route->dest, &source->dest, sizeof (struct in6_addr));
1572 memcpy (&route->next_hop, &source->next_hop, sizeof (struct in6_addr));
1579 * @route: the #NMIP6Route
1581 * Increases the reference count of the object.
1584 nm_ip6_route_ref (NMIP6Route *route)
1586 g_return_if_fail (route != NULL);
1587 g_return_if_fail (route->refcount > 0);
1593 * nm_ip6_route_unref:
1594 * @route: the #NMIP6Route
1596 * Decreases the reference count of the object. If the reference count
1597 * reaches zero, the object will be destroyed.
1600 nm_ip6_route_unref (NMIP6Route *route)
1602 g_return_if_fail (route != NULL);
1603 g_return_if_fail (route->refcount > 0);
1606 if (route->refcount == 0) {
1607 memset (route, 0, sizeof (NMIP6Route));
1613 * nm_ip6_route_compare:
1614 * @route: the #NMIP6Route
1615 * @other: the #NMIP6Route to compare @route to.
1617 * Determines if two #NMIP6Route objects contain the same values.
1619 * Returns: %TRUE if the objects contain the same values, %FALSE if they do not.
1622 nm_ip6_route_compare (NMIP6Route *route, NMIP6Route *other)
1624 g_return_val_if_fail (route != NULL, FALSE);
1625 g_return_val_if_fail (route->refcount > 0, FALSE);
1627 g_return_val_if_fail (other != NULL, FALSE);
1628 g_return_val_if_fail (other->refcount > 0, FALSE);
1630 if ( memcmp (&route->dest, &other->dest, sizeof (struct in6_addr))
1631 || route->prefix != other->prefix
1632 || memcmp (&route->next_hop, &other->next_hop, sizeof (struct in6_addr))
1633 || route->metric != other->metric)
1639 * nm_ip6_route_get_dest:
1640 * @route: the #NMIP6Route
1642 * Gets the IPv6 destination address property of this route object.
1644 * Returns: (array fixed-size=16) (element-type guint8) (transfer none):
1645 * the IPv6 address of destination
1647 const struct in6_addr *
1648 nm_ip6_route_get_dest (NMIP6Route *route)
1650 g_return_val_if_fail (route != NULL, NULL);
1651 g_return_val_if_fail (route->refcount > 0, NULL);
1653 return &route->dest;
1657 * nm_ip6_route_set_dest:
1658 * @route: the #NMIP6Route
1659 * @dest: the destination address
1661 * Sets the IPv6 destination address property of this route object.
1664 nm_ip6_route_set_dest (NMIP6Route *route, const struct in6_addr *dest)
1666 g_return_if_fail (route != NULL);
1667 g_return_if_fail (route->refcount > 0);
1668 g_return_if_fail (dest != NULL);
1670 memcpy (&route->dest, dest, sizeof (struct in6_addr));
1674 * nm_ip6_route_get_prefix:
1675 * @route: the #NMIP6Route
1677 * Gets the IPv6 prefix (ie "32" or "64" etc) of this route.
1679 * Returns: the IPv6 prefix
1682 nm_ip6_route_get_prefix (NMIP6Route *route)
1684 g_return_val_if_fail (route != NULL, 0);
1685 g_return_val_if_fail (route->refcount > 0, 0);
1687 return route->prefix;
1691 * nm_ip6_route_set_prefix:
1692 * @route: the #NMIP6Route
1693 * @prefix: the prefix, a number between 1 and 128 inclusive
1695 * Sets the IPv6 prefix of this route.
1698 nm_ip6_route_set_prefix (NMIP6Route *route, guint32 prefix)
1700 g_return_if_fail (route != NULL);
1701 g_return_if_fail (route->refcount > 0);
1702 g_return_if_fail (prefix <= 128);
1703 g_return_if_fail (prefix > 0);
1705 route->prefix = prefix;
1709 * nm_ip6_route_get_next_hop:
1710 * @route: the #NMIP6Route
1712 * Gets the IPv6 address of the next hop of this route.
1714 * Returns: (array fixed-size=16) (element-type guint8) (transfer none):
1715 * the IPv6 address of next hop
1717 const struct in6_addr *
1718 nm_ip6_route_get_next_hop (NMIP6Route *route)
1720 g_return_val_if_fail (route != NULL, NULL);
1721 g_return_val_if_fail (route->refcount > 0, NULL);
1723 return &route->next_hop;
1727 * nm_ip6_route_set_next_hop:
1728 * @route: the #NMIP6Route
1729 * @next_hop: the IPv6 address of the next hop
1731 * Sets the IPv6 address of the next hop of this route.
1734 nm_ip6_route_set_next_hop (NMIP6Route *route, const struct in6_addr *next_hop)
1736 g_return_if_fail (route != NULL);
1737 g_return_if_fail (route->refcount > 0);
1738 g_return_if_fail (next_hop != NULL);
1740 memcpy (&route->next_hop, next_hop, sizeof (struct in6_addr));
1744 * nm_ip6_route_get_metric:
1745 * @route: the #NMIP6Route
1747 * Gets the route metric property of this route object; lower values indicate
1748 * "better" or more preferred routes.
1750 * Returns: the route metric
1753 nm_ip6_route_get_metric (NMIP6Route *route)
1755 g_return_val_if_fail (route != NULL, 0);
1756 g_return_val_if_fail (route->refcount > 0, 0);
1758 return route->metric;
1762 * nm_ip6_route_set_metric:
1763 * @route: the #NMIP6Route
1764 * @metric: the route metric
1766 * Sets the route metric property of this route object; lower values indicate
1767 * "better" or more preferred routes.
1770 nm_ip6_route_set_metric (NMIP6Route *route, guint32 metric)
1772 g_return_if_fail (route != NULL);
1773 g_return_if_fail (route->refcount > 0);
1775 route->metric = metric;