From d16905df633ceea08c93b6e982f660627d06ff34 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 21 Oct 2014 08:33:18 -0400 Subject: libnm-core, libnm, core: add AddressData and RouteData properties Add AddressData and RouteData properties to NMSettingIPConfig and NMIP[46]Config. These are like the existing "addresses" and "routes" properties, but using strings and containing additional attributes, like NMIPAddress and NMIPRoute. This only affects the D-Bus representations; there are no API changes to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the additional information is just added to the existing 'addresses' and 'routes' properties. NMSettingIP4Config and NMSettingIP6Config now always generate both old-style data ('addresses', 'address-labels', 'routes') and new-style data ('address-data', 'gateway', 'route-data') when serializing to D-Bus, for backward compatibility. When deserializing, they will fill in the 'addresses' and 'routes' properties from the new-style data if it is present (ignoring the old-style data), or from the old-style data if the new-style isn't present. The daemon-side NMIP4Config and NMIP6Config always emit changes for both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The libnm-side classes initially listen for changes on both properties, but start ignoring the 'Addresses' and 'Routes' properties once they know the daemon is also providing 'AddressData' and 'RouteData'. --- libnm/nm-ip4-config.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'libnm/nm-ip4-config.c') diff --git a/libnm/nm-ip4-config.c b/libnm/nm-ip4-config.c index a37f835774..d242fe55db 100644 --- a/libnm/nm-ip4-config.c +++ b/libnm/nm-ip4-config.c @@ -40,6 +40,8 @@ typedef struct { char **domains; char **searches; char **wins; + + gboolean new_style_data; } NMIP4ConfigPrivate; enum { @@ -69,10 +71,13 @@ nm_ip4_config_init (NMIP4Config *config) } static gboolean -demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) +demarshal_ip4_addresses (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object); + if (priv->new_style_data) + return TRUE; + g_ptr_array_unref (priv->addresses); priv->addresses = nm_utils_ip4_addresses_from_variant (value, NULL); _nm_object_queue_notify (object, NM_IP4_CONFIG_ADDRESSES); @@ -80,6 +85,20 @@ demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GVariant *valu return TRUE; } +static gboolean +demarshal_ip4_address_data (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) +{ + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object); + + priv->new_style_data = TRUE; + + g_ptr_array_unref (priv->addresses); + priv->addresses = nm_utils_ip_addresses_from_variant (value, AF_INET); + _nm_object_queue_notify (object, NM_IP4_CONFIG_ADDRESSES); + + return TRUE; +} + static gboolean demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { @@ -96,10 +115,13 @@ demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpoin } static gboolean -demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) +demarshal_ip4_routes (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object); + if (priv->new_style_data) + return TRUE; + g_ptr_array_unref (priv->routes); priv->routes = nm_utils_ip4_routes_from_variant (value); _nm_object_queue_notify (object, NM_IP4_CONFIG_ROUTES); @@ -107,14 +129,30 @@ demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GVariant *value return TRUE; } +static gboolean +demarshal_ip4_route_data (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) +{ + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object); + + priv->new_style_data = TRUE; + + g_ptr_array_unref (priv->routes); + priv->routes = nm_utils_ip_routes_from_variant (value, AF_INET); + _nm_object_queue_notify (object, NM_IP4_CONFIG_ROUTES); + + return TRUE; +} + static void init_dbus (NMObject *object) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object); const NMPropertiesInfo property_info[] = { { NM_IP4_CONFIG_GATEWAY, &priv->gateway, }, - { NM_IP4_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip4_address_array }, - { NM_IP4_CONFIG_ROUTES, &priv->routes, demarshal_ip4_routes_array }, + { NM_IP4_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip4_addresses }, + { "address-data", &priv->addresses, demarshal_ip4_address_data }, + { NM_IP4_CONFIG_ROUTES, &priv->routes, demarshal_ip4_routes }, + { "route-data", &priv->routes, demarshal_ip4_route_data }, { NM_IP4_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip4_array }, { NM_IP4_CONFIG_DOMAINS, &priv->domains, }, { NM_IP4_CONFIG_SEARCHES, &priv->searches, }, -- cgit v1.2.1