diff options
Diffstat (limited to 'src/nm-ip6-config.c')
| -rw-r--r-- | src/nm-ip6-config.c | 143 |
1 files changed, 85 insertions, 58 deletions
diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index fd63dcb4..6d83bd53 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -19,20 +19,18 @@ * Copyright (C) 2006 - 2008 Novell, Inc. */ -#include "config.h" +#include "nm-default.h" + +#include "nm-ip6-config.h" #include <string.h> #include <arpa/inet.h> -#include "nm-default.h" -#include "nm-ip6-config.h" - #include "nm-utils.h" #include "nm-platform.h" #include "nm-route-manager.h" #include "nm-core-internal.h" #include "NetworkManagerUtils.h" -#include "nm-macros-internal.h" #include "nmdbus-ip6-config.h" @@ -55,8 +53,7 @@ typedef struct _NMIP6ConfigPrivate { } NMIP6ConfigPrivate; -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE (NMIP6Config, PROP_IFINDEX, PROP_ADDRESS_DATA, PROP_ADDRESSES, @@ -67,12 +64,7 @@ enum { PROP_DOMAINS, PROP_SEARCHES, PROP_DNS_OPTIONS, - - LAST_PROP -}; -static GParamSpec *obj_properties[LAST_PROP] = { NULL, }; -#define _NOTIFY(config, prop) G_STMT_START { g_object_notify_by_pspec (G_OBJECT (config), obj_properties[prop]); } G_STMT_END - +); NMIP6Config * nm_ip6_config_new (int ifindex) @@ -83,6 +75,18 @@ nm_ip6_config_new (int ifindex) NULL); } +NMIP6Config * +nm_ip6_config_new_cloned (const NMIP6Config *src) +{ + NMIP6Config *new; + + g_return_val_if_fail (NM_IS_IP6_CONFIG (src), NULL); + + new = nm_ip6_config_new (nm_ip6_config_get_ifindex (src)); + nm_ip6_config_replace (new, src, NULL); + return new; +} + int nm_ip6_config_get_ifindex (const NMIP6Config *config) { @@ -218,8 +222,8 @@ _addresses_sort_cmp (gconstpointer a, gconstpointer b, gpointer user_data) /* tentative addresses are always sorted back... */ /* sort tentative addresses after non-tentative. */ - tent1 = (a1->flags & IFA_F_TENTATIVE); - tent2 = (a2->flags & IFA_F_TENTATIVE); + tent1 = (a1->n_ifa_flags & IFA_F_TENTATIVE); + tent2 = (a2->n_ifa_flags & IFA_F_TENTATIVE); if (tent1 != tent2) return tent1 ? 1 : -1; @@ -230,20 +234,20 @@ _addresses_sort_cmp (gconstpointer a, gconstpointer b, gpointer user_data) if (p1 != p2) return p1 > p2 ? -1 : 1; - ipv6_privacy1 = !!(a1->flags & (IFA_F_MANAGETEMPADDR | IFA_F_TEMPORARY)); - ipv6_privacy2 = !!(a2->flags & (IFA_F_MANAGETEMPADDR | IFA_F_TEMPORARY)); + ipv6_privacy1 = !!(a1->n_ifa_flags & (IFA_F_MANAGETEMPADDR | IFA_F_TEMPORARY)); + ipv6_privacy2 = !!(a2->n_ifa_flags & (IFA_F_MANAGETEMPADDR | IFA_F_TEMPORARY)); if (ipv6_privacy1 || ipv6_privacy2) { gboolean prefer_temp = ((NMSettingIP6ConfigPrivacy) GPOINTER_TO_INT (user_data)) == NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR; gboolean public1 = TRUE, public2 = TRUE; if (ipv6_privacy1) { - if (a1->flags & IFA_F_TEMPORARY) + if (a1->n_ifa_flags & IFA_F_TEMPORARY) public1 = prefer_temp; else public1 = !prefer_temp; } if (ipv6_privacy2) { - if (a2->flags & IFA_F_TEMPORARY) + if (a2->n_ifa_flags & IFA_F_TEMPORARY) public2 = prefer_temp; else public2 = !prefer_temp; @@ -258,8 +262,8 @@ _addresses_sort_cmp (gconstpointer a, gconstpointer b, gpointer user_data) return a1->source > a2->source ? -1 : 1; /* sort permanent addresses before non-permanent. */ - perm1 = (a1->flags & IFA_F_PERMANENT); - perm2 = (a2->flags & IFA_F_PERMANENT); + perm1 = (a1->n_ifa_flags & IFA_F_PERMANENT); + perm2 = (a2->n_ifa_flags & IFA_F_PERMANENT); if (perm1 != perm2) return perm1 ? -1 : 1; @@ -290,8 +294,8 @@ nm_ip6_config_addresses_sort (NMIP6Config *self, NMSettingIP6ConfigPrivacy use_t g_free (data_pre); if (changed) { - _NOTIFY (self, PROP_ADDRESS_DATA); - _NOTIFY (self, PROP_ADDRESSES); + _notify (self, PROP_ADDRESS_DATA); + _notify (self, PROP_ADDRESSES); return TRUE; } } @@ -372,13 +376,13 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co /* actually, nobody should be connected to the signal, just to be sure, notify */ if (notify_nameservers) - _NOTIFY (config, PROP_NAMESERVERS); - _NOTIFY (config, PROP_ADDRESS_DATA); - _NOTIFY (config, PROP_ADDRESSES); - _NOTIFY (config, PROP_ROUTE_DATA); - _NOTIFY (config, PROP_ROUTES); + _notify (config, PROP_NAMESERVERS); + _notify (config, PROP_ADDRESS_DATA); + _notify (config, PROP_ADDRESSES); + _notify (config, PROP_ROUTE_DATA); + _notify (config, PROP_ROUTES); if (!IN6_ARE_ADDR_EQUAL (&priv->gateway, &old_gateway)) - _NOTIFY (config, PROP_GATEWAY); + _notify (config, PROP_GATEWAY); return config; } @@ -713,7 +717,7 @@ nm_ip6_config_destination_is_direct (const NMIP6Config *config, const struct in6 const NMPlatformIP6Address *item = nm_ip6_config_get_address (config, i); if (item->plen <= plen && same_prefix (&item->address, network, item->plen) && - !(item->flags & IFA_F_NOPREFIXROUTE)) + !(item->n_ifa_flags & IFA_F_NOPREFIXROUTE)) return TRUE; } @@ -968,8 +972,8 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev const NMPlatformIP6Address *dst_addr, *src_addr; const NMPlatformIP6Route *dst_route, *src_route; - g_return_val_if_fail (src != NULL, FALSE); - g_return_val_if_fail (dst != NULL, FALSE); + g_return_val_if_fail (NM_IS_IP6_CONFIG (src), FALSE); + g_return_val_if_fail (NM_IS_IP6_CONFIG (dst), FALSE); g_return_val_if_fail (src != dst, FALSE); #if NM_MORE_ASSERTS @@ -1231,7 +1235,7 @@ nm_ip6_config_set_gateway (NMIP6Config *config, const struct in6_addr *gateway) return; memset (&priv->gateway, 0, sizeof (priv->gateway)); } - _NOTIFY (config, PROP_GATEWAY); + _notify (config, PROP_GATEWAY); } const struct in6_addr * @@ -1259,8 +1263,8 @@ nm_ip6_config_reset_addresses (NMIP6Config *config) if (priv->addresses->len != 0) { g_array_set_size (priv->addresses, 0); - _NOTIFY (config, PROP_ADDRESS_DATA); - _NOTIFY (config, PROP_ADDRESSES); + _notify (config, PROP_ADDRESS_DATA); + _notify (config, PROP_ADDRESSES); } } @@ -1317,8 +1321,8 @@ nm_ip6_config_add_address (NMIP6Config *config, const NMPlatformIP6Address *new) g_array_append_val (priv->addresses, *new); NOTIFY: - _NOTIFY (config, PROP_ADDRESS_DATA); - _NOTIFY (config, PROP_ADDRESSES); + _notify (config, PROP_ADDRESS_DATA); + _notify (config, PROP_ADDRESSES); } void @@ -1329,8 +1333,8 @@ nm_ip6_config_del_address (NMIP6Config *config, guint i) g_return_if_fail (i < priv->addresses->len); g_array_remove_index (priv->addresses, i); - _NOTIFY (config, PROP_ADDRESS_DATA); - _NOTIFY (config, PROP_ADDRESSES); + _notify (config, PROP_ADDRESS_DATA); + _notify (config, PROP_ADDRESSES); } guint @@ -1356,6 +1360,29 @@ nm_ip6_config_address_exists (const NMIP6Config *config, return _addresses_get_index (config, needle) >= 0; } +const NMPlatformIP6Address * +nm_ip6_config_get_address_first_nontentative (const NMIP6Config *config, gboolean linklocal) +{ + NMIP6ConfigPrivate *priv; + guint i; + + g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); + + priv = NM_IP6_CONFIG_GET_PRIVATE (config); + + linklocal = !!linklocal; + + for (i = 0; i < priv->addresses->len; i++) { + const NMPlatformIP6Address *addr = &g_array_index (priv->addresses, NMPlatformIP6Address, i); + + if ( ((!!IN6_IS_ADDR_LINKLOCAL (&addr->address)) == linklocal) + && !(addr->n_ifa_flags & IFA_F_TENTATIVE)) + return addr; + } + + return NULL; +} + /******************************************************************/ void @@ -1365,8 +1392,8 @@ nm_ip6_config_reset_routes (NMIP6Config *config) if (priv->routes->len != 0) { g_array_set_size (priv->routes, 0); - _NOTIFY (config, PROP_ROUTE_DATA); - _NOTIFY (config, PROP_ROUTES); + _notify (config, PROP_ROUTE_DATA); + _notify (config, PROP_ROUTES); } } @@ -1409,8 +1436,8 @@ nm_ip6_config_add_route (NMIP6Config *config, const NMPlatformIP6Route *new) g_array_append_val (priv->routes, *new); g_array_index (priv->routes, NMPlatformIP6Route, priv->routes->len - 1).ifindex = priv->ifindex; NOTIFY: - _NOTIFY (config, PROP_ROUTE_DATA); - _NOTIFY (config, PROP_ROUTES); + _notify (config, PROP_ROUTE_DATA); + _notify (config, PROP_ROUTES); } void @@ -1421,8 +1448,8 @@ nm_ip6_config_del_route (NMIP6Config *config, guint i) g_return_if_fail (i < priv->routes->len); g_array_remove_index (priv->routes, i); - _NOTIFY (config, PROP_ROUTE_DATA); - _NOTIFY (config, PROP_ROUTES); + _notify (config, PROP_ROUTE_DATA); + _notify (config, PROP_ROUTES); } guint @@ -1512,7 +1539,7 @@ nm_ip6_config_reset_nameservers (NMIP6Config *config) if (priv->nameservers->len != 0) { g_array_set_size (priv->nameservers, 0); - _NOTIFY (config, PROP_NAMESERVERS); + _notify (config, PROP_NAMESERVERS); } } @@ -1529,7 +1556,7 @@ nm_ip6_config_add_nameserver (NMIP6Config *config, const struct in6_addr *new) return; g_array_append_val (priv->nameservers, *new); - _NOTIFY (config, PROP_NAMESERVERS); + _notify (config, PROP_NAMESERVERS); } void @@ -1540,7 +1567,7 @@ nm_ip6_config_del_nameserver (NMIP6Config *config, guint i) g_return_if_fail (i < priv->nameservers->len); g_array_remove_index (priv->nameservers, i); - _NOTIFY (config, PROP_NAMESERVERS); + _notify (config, PROP_NAMESERVERS); } guint32 @@ -1568,7 +1595,7 @@ nm_ip6_config_reset_domains (NMIP6Config *config) if (priv->domains->len != 0) { g_ptr_array_set_size (priv->domains, 0); - _NOTIFY (config, PROP_DOMAINS); + _notify (config, PROP_DOMAINS); } } @@ -1586,7 +1613,7 @@ nm_ip6_config_add_domain (NMIP6Config *config, const char *domain) return; g_ptr_array_add (priv->domains, g_strdup (domain)); - _NOTIFY (config, PROP_DOMAINS); + _notify (config, PROP_DOMAINS); } void @@ -1597,7 +1624,7 @@ nm_ip6_config_del_domain (NMIP6Config *config, guint i) g_return_if_fail (i < priv->domains->len); g_ptr_array_remove_index (priv->domains, i); - _NOTIFY (config, PROP_DOMAINS); + _notify (config, PROP_DOMAINS); } guint32 @@ -1625,7 +1652,7 @@ nm_ip6_config_reset_searches (NMIP6Config *config) if (priv->searches->len != 0) { g_ptr_array_set_size (priv->searches, 0); - _NOTIFY (config, PROP_SEARCHES); + _notify (config, PROP_SEARCHES); } } @@ -1658,7 +1685,7 @@ nm_ip6_config_add_search (NMIP6Config *config, const char *new) } g_ptr_array_add (priv->searches, search); - _NOTIFY (config, PROP_SEARCHES); + _notify (config, PROP_SEARCHES); } void @@ -1669,7 +1696,7 @@ nm_ip6_config_del_search (NMIP6Config *config, guint i) g_return_if_fail (i < priv->searches->len); g_ptr_array_remove_index (priv->searches, i); - _NOTIFY (config, PROP_SEARCHES); + _notify (config, PROP_SEARCHES); } guint32 @@ -1697,7 +1724,7 @@ nm_ip6_config_reset_dns_options (NMIP6Config *config) if (priv->dns_options->len != 0) { g_ptr_array_set_size (priv->dns_options, 0); - _NOTIFY (config, PROP_DNS_OPTIONS); + _notify (config, PROP_DNS_OPTIONS); } } @@ -1715,7 +1742,7 @@ nm_ip6_config_add_dns_option (NMIP6Config *config, const char *new) return; g_ptr_array_add (priv->dns_options, g_strdup (new)); - _NOTIFY (config, PROP_DNS_OPTIONS); + _notify (config, PROP_DNS_OPTIONS); } void @@ -1726,7 +1753,7 @@ nm_ip6_config_del_dns_option (NMIP6Config *config, guint i) g_return_if_fail (i < priv->dns_options->len); g_ptr_array_remove_index (priv->dns_options, i); - _NOTIFY (config, PROP_DNS_OPTIONS); + _notify (config, PROP_DNS_OPTIONS); } guint32 @@ -2164,7 +2191,7 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_properties (object_class, LAST_PROP, obj_properties); + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class), NMDBUS_TYPE_IP6_CONFIG_SKELETON, |