mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-14 20:18:39 +00:00
libnm-glib: add NMIP6Config object that proxies device's IP6 config
This commit is contained in:
parent
0fb5560b79
commit
0877323e8d
|
@ -49,7 +49,8 @@ IGNORE_HFILES= \
|
|||
nm-vpn-plugin-glue.h \
|
||||
nm-active-connection-bindings.h \
|
||||
nm-ip4-config-bindings.h \
|
||||
nm-dhcp4-config-bindings.h
|
||||
nm-dhcp4-config-bindings.h \
|
||||
nm-ip4-config-bindings.h
|
||||
|
||||
# Images to copy into HTML directory.
|
||||
HTML_IMAGES =
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
<xi:include href="xml/nm-gsm-device.xml"/>
|
||||
<xi:include href="xml/nm-device.xml"/>
|
||||
<xi:include href="xml/nm-ip4-config.xml"/>
|
||||
<xi:include href="xml/nm-ip6-config.xml"/>
|
||||
<xi:include href="xml/nm-object.xml"/>
|
||||
<xi:include href="xml/nm-settings.xml"/>
|
||||
<xi:include href="xml/nm-vpn-connection.xml"/>
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <nm-serial-device.h>
|
||||
#include <nm-access-point.h>
|
||||
#include <nm-ip4-config.h>
|
||||
#include <nm-ip6-config.h>
|
||||
#include <nm-active-connection.h>
|
||||
#include <nm-dhcp4-config.h>
|
||||
|
||||
|
@ -21,3 +22,4 @@ nm_access_point_get_type
|
|||
nm_ip4_config_get_type
|
||||
nm_active_connection_get_type
|
||||
nm_dhcp4_config_get_type
|
||||
nm_ip6_config_get_type
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#define NM_DBUS_INTERFACE_ACTIVE_CONNECTION NM_DBUS_INTERFACE ".Connection.Active"
|
||||
#define NM_DBUS_INTERFACE_IP4_CONFIG NM_DBUS_INTERFACE ".IP4Config"
|
||||
#define NM_DBUS_INTERFACE_DHCP4_CONFIG NM_DBUS_INTERFACE ".DHCP4Config"
|
||||
#define NM_DBUS_INTERFACE_IP6_CONFIG NM_DBUS_INTERFACE ".IP6Config"
|
||||
|
||||
|
||||
#define NM_DBUS_SERVICE_USER_SETTINGS "org.freedesktop.NetworkManagerUserSettings"
|
||||
|
|
|
@ -42,6 +42,11 @@
|
|||
Object path of the Dhcp4Config object describing the DHCP options returned by the DHCP server. Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state.
|
||||
</tp:docstring>
|
||||
</property>
|
||||
<property name="Ip6Config" type="o" access="read">
|
||||
<tp:docstring>
|
||||
Object path of the Ip6Config object describing the configuration of the device. Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state.
|
||||
</tp:docstring>
|
||||
</property>
|
||||
<property name="Managed" type="b" access="read">
|
||||
<tp:docstring>
|
||||
Whether or not this device is managed by NetworkManager.
|
||||
|
|
|
@ -19,7 +19,8 @@ BUILT_SOURCES = \
|
|||
nm-vpn-plugin-glue.h \
|
||||
nm-active-connection-bindings.h \
|
||||
nm-ip4-config-bindings.h \
|
||||
nm-dhcp4-config-bindings.h
|
||||
nm-dhcp4-config-bindings.h \
|
||||
nm-ip6-config-bindings.h
|
||||
|
||||
lib_LTLIBRARIES = libnm_glib.la libnm_glib_vpn.la
|
||||
|
||||
|
@ -53,7 +54,8 @@ libnminclude_HEADERS = \
|
|||
nm-dbus-connection.h \
|
||||
nm-dbus-settings.h \
|
||||
nm-dbus-settings-system.h \
|
||||
nm-dhcp4-config.h
|
||||
nm-dhcp4-config.h \
|
||||
nm-ip6-config.h
|
||||
|
||||
libnm_glib_la_SOURCES = \
|
||||
libnm_glib.c \
|
||||
|
@ -82,7 +84,8 @@ libnm_glib_la_SOURCES = \
|
|||
nm-dbus-connection.c \
|
||||
nm-dbus-settings.c \
|
||||
nm-dbus-settings-system.c \
|
||||
nm-dhcp4-config.c
|
||||
nm-dhcp4-config.c \
|
||||
nm-ip6-config.c
|
||||
|
||||
libnm_glib_la_LIBADD = \
|
||||
$(top_builddir)/libnm-util/libnm-util.la \
|
||||
|
@ -157,6 +160,9 @@ nm-ip4-config-bindings.h: $(top_srcdir)/introspection/nm-ip4-config.xml
|
|||
nm-dhcp4-config-bindings.h: $(top_srcdir)/introspection/nm-dhcp4-config.xml
|
||||
dbus-binding-tool --prefix=nm_dhcp4_config --mode=glib-client --output=$@ $<
|
||||
|
||||
nm-ip6-config-bindings.h: $(top_srcdir)/introspection/nm-ip6-config.xml
|
||||
dbus-binding-tool --prefix=nm_ip6_config --mode=glib-client --output=$@ $<
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libnm_glib.pc libnm_glib_vpn.pc
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ global:
|
|||
nm_device_get_driver;
|
||||
nm_device_get_iface;
|
||||
nm_device_get_ip4_config;
|
||||
nm_device_get_ip6_config;
|
||||
nm_device_get_managed;
|
||||
nm_device_get_product;
|
||||
nm_device_get_state;
|
||||
|
@ -103,6 +104,15 @@ global:
|
|||
nm_ip4_config_get_routes;
|
||||
nm_ip4_config_get_type;
|
||||
nm_ip4_config_new;
|
||||
nm_ip6_address_array_get_type;
|
||||
nm_ip6_address_object_array_get_type;
|
||||
nm_ip6_config_get_addresses;
|
||||
nm_ip6_config_get_domains;
|
||||
nm_ip6_config_get_nameservers;
|
||||
nm_ip6_config_get_routes;
|
||||
nm_ip6_config_get_type;
|
||||
nm_ip6_config_new;
|
||||
nm_ip6_route_object_array_get_type;
|
||||
nm_object_array_get_type;
|
||||
nm_object_get_connection;
|
||||
nm_object_get_path;
|
||||
|
|
|
@ -57,6 +57,8 @@ typedef struct {
|
|||
gboolean null_ip4_config;
|
||||
NMDHCP4Config *dhcp4_config;
|
||||
gboolean null_dhcp4_config;
|
||||
NMIP6Config *ip6_config;
|
||||
gboolean null_ip6_config;
|
||||
NMDeviceState state;
|
||||
|
||||
GUdevClient *client;
|
||||
|
@ -73,6 +75,7 @@ enum {
|
|||
PROP_MANAGED,
|
||||
PROP_IP4_CONFIG,
|
||||
PROP_DHCP4_CONFIG,
|
||||
PROP_IP6_CONFIG,
|
||||
PROP_STATE,
|
||||
PROP_PRODUCT,
|
||||
PROP_VENDOR,
|
||||
|
@ -177,6 +180,46 @@ demarshal_dhcp4_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoi
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
demarshal_ip6_config (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
|
||||
const char *path;
|
||||
NMIP6Config *config = NULL;
|
||||
DBusGConnection *connection;
|
||||
|
||||
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH))
|
||||
return FALSE;
|
||||
|
||||
priv->null_ip6_config = FALSE;
|
||||
|
||||
path = g_value_get_boxed (value);
|
||||
if (path) {
|
||||
if (!strcmp (path, "/"))
|
||||
priv->null_ip6_config = TRUE;
|
||||
else {
|
||||
config = NM_IP6_CONFIG (_nm_object_cache_get (path));
|
||||
if (config)
|
||||
config = g_object_ref (config);
|
||||
else {
|
||||
connection = nm_object_get_connection (object);
|
||||
config = NM_IP6_CONFIG (nm_ip6_config_new (connection, path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (priv->ip6_config) {
|
||||
g_object_unref (priv->ip6_config);
|
||||
priv->ip6_config = NULL;
|
||||
}
|
||||
|
||||
if (config)
|
||||
priv->ip6_config = config;
|
||||
|
||||
_nm_object_queue_notify (object, NM_DEVICE_IP6_CONFIG);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
register_for_property_changed (NMDevice *device)
|
||||
{
|
||||
|
@ -189,6 +232,7 @@ register_for_property_changed (NMDevice *device)
|
|||
{ NM_DEVICE_MANAGED, _nm_object_demarshal_generic, &priv->managed },
|
||||
{ NM_DEVICE_IP4_CONFIG, demarshal_ip4_config, &priv->ip4_config },
|
||||
{ NM_DEVICE_DHCP4_CONFIG, demarshal_dhcp4_config, &priv->dhcp4_config },
|
||||
{ NM_DEVICE_IP6_CONFIG, demarshal_ip6_config, &priv->ip6_config },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
|
@ -272,6 +316,8 @@ dispose (GObject *object)
|
|||
g_object_unref (priv->ip4_config);
|
||||
if (priv->dhcp4_config)
|
||||
g_object_unref (priv->dhcp4_config);
|
||||
if (priv->ip6_config)
|
||||
g_object_unref (priv->ip6_config);
|
||||
if (priv->client)
|
||||
g_object_unref (priv->client);
|
||||
|
||||
|
@ -322,6 +368,9 @@ get_property (GObject *object,
|
|||
case PROP_DHCP4_CONFIG:
|
||||
g_value_set_object (value, nm_device_get_dhcp4_config (device));
|
||||
break;
|
||||
case PROP_IP6_CONFIG:
|
||||
g_value_set_object (value, nm_device_get_ip6_config (device));
|
||||
break;
|
||||
case PROP_STATE:
|
||||
g_value_set_uint (value, nm_device_get_state (device));
|
||||
break;
|
||||
|
@ -443,6 +492,19 @@ nm_device_class_init (NMDeviceClass *device_class)
|
|||
NM_TYPE_DHCP4_CONFIG,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
/**
|
||||
* NMDevice:ip6-config:
|
||||
*
|
||||
* The #NMIP6Config of the device.
|
||||
**/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_IP6_CONFIG,
|
||||
g_param_spec_object (NM_DEVICE_IP6_CONFIG,
|
||||
"IP6 Config",
|
||||
"IP6 Config",
|
||||
NM_TYPE_IP6_CONFIG,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
/**
|
||||
* NMDevice:state:
|
||||
*
|
||||
|
@ -774,6 +836,40 @@ nm_device_get_dhcp4_config (NMDevice *device)
|
|||
return priv->dhcp4_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_device_get_ip6_config:
|
||||
* @device: a #NMDevice
|
||||
*
|
||||
* Gets the current #NMIP6Config associated with the #NMDevice.
|
||||
*
|
||||
* Returns: the #NMIP6Config or %NULL if the device is not activated.
|
||||
**/
|
||||
NMIP6Config *
|
||||
nm_device_get_ip6_config (NMDevice *device)
|
||||
{
|
||||
NMDevicePrivate *priv;
|
||||
char *path;
|
||||
GValue value = { 0, };
|
||||
|
||||
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
|
||||
|
||||
priv = NM_DEVICE_GET_PRIVATE (device);
|
||||
if (priv->ip6_config)
|
||||
return priv->ip6_config;
|
||||
if (priv->null_ip6_config)
|
||||
return NULL;
|
||||
|
||||
path = _nm_object_get_object_path_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Ip6Config");
|
||||
if (path) {
|
||||
g_value_init (&value, DBUS_TYPE_G_OBJECT_PATH);
|
||||
g_value_take_boxed (&value, path);
|
||||
demarshal_ip6_config (NM_OBJECT (device), NULL, &value, &priv->ip6_config);
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
return priv->ip6_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_device_get_state:
|
||||
* @device: a #NMDevice
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "NetworkManager.h"
|
||||
#include "nm-ip4-config.h"
|
||||
#include "nm-dhcp4-config.h"
|
||||
#include "nm-ip6-config.h"
|
||||
#include "nm-connection.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
@ -49,6 +50,7 @@ G_BEGIN_DECLS
|
|||
#define NM_DEVICE_MANAGED "managed"
|
||||
#define NM_DEVICE_IP4_CONFIG "ip4-config"
|
||||
#define NM_DEVICE_DHCP4_CONFIG "dhcp4-config"
|
||||
#define NM_DEVICE_IP6_CONFIG "ip6-config"
|
||||
#define NM_DEVICE_STATE "state"
|
||||
#define NM_DEVICE_VENDOR "vendor"
|
||||
#define NM_DEVICE_PRODUCT "product"
|
||||
|
@ -78,6 +80,7 @@ guint32 nm_device_get_capabilities (NMDevice *device);
|
|||
gboolean nm_device_get_managed (NMDevice *device);
|
||||
NMIP4Config * nm_device_get_ip4_config (NMDevice *device);
|
||||
NMDHCP4Config * nm_device_get_dhcp4_config (NMDevice *device);
|
||||
NMIP6Config * nm_device_get_ip6_config (NMDevice *device);
|
||||
NMDeviceState nm_device_get_state (NMDevice *device);
|
||||
const char * nm_device_get_product (NMDevice *device);
|
||||
const char * nm_device_get_vendor (NMDevice *device);
|
||||
|
|
|
@ -353,9 +353,9 @@ nm_ip4_config_get_addresses (NMIP4Config *config)
|
|||
return priv->addresses;
|
||||
|
||||
if (!_nm_object_get_property (NM_OBJECT (config),
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Addresses",
|
||||
&value)) {
|
||||
NM_DBUS_INTERFACE_IP4_CONFIG,
|
||||
"Addresses",
|
||||
&value)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -400,9 +400,9 @@ nm_ip4_config_get_nameservers (NMIP4Config *config)
|
|||
priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
||||
if (!priv->nameservers) {
|
||||
if (_nm_object_get_property (NM_OBJECT (config),
|
||||
NM_DBUS_INTERFACE_IP4_CONFIG,
|
||||
"Nameservers",
|
||||
&value)) {
|
||||
NM_DBUS_INTERFACE_IP4_CONFIG,
|
||||
"Nameservers",
|
||||
&value)) {
|
||||
array = (GArray *) g_value_get_boxed (&value);
|
||||
if (array && array->len) {
|
||||
priv->nameservers = g_array_sized_new (FALSE, TRUE, sizeof (guint32), array->len);
|
||||
|
@ -437,9 +437,9 @@ nm_ip4_config_get_domains (NMIP4Config *config)
|
|||
return handle_ptr_array_return (priv->domains);
|
||||
|
||||
if (_nm_object_get_property (NM_OBJECT (config),
|
||||
NM_DBUS_INTERFACE_IP4_CONFIG,
|
||||
"Domains",
|
||||
&value)) {
|
||||
NM_DBUS_INTERFACE_IP4_CONFIG,
|
||||
"Domains",
|
||||
&value)) {
|
||||
char **array = NULL, **p;
|
||||
|
||||
array = (char **) g_value_get_boxed (&value);
|
||||
|
@ -475,9 +475,9 @@ nm_ip4_config_get_wins_servers (NMIP4Config *config)
|
|||
priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
||||
if (!priv->nameservers) {
|
||||
if (_nm_object_get_property (NM_OBJECT (config),
|
||||
NM_DBUS_INTERFACE_IP4_CONFIG,
|
||||
"Nameservers",
|
||||
&value)) {
|
||||
NM_DBUS_INTERFACE_IP4_CONFIG,
|
||||
"Nameservers",
|
||||
&value)) {
|
||||
array = (GArray *) g_value_get_boxed (&value);
|
||||
if (array && array->len) {
|
||||
priv->nameservers = g_array_sized_new (FALSE, TRUE, sizeof (guint32), array->len);
|
||||
|
@ -512,9 +512,9 @@ nm_ip4_config_get_routes (NMIP4Config *config)
|
|||
return priv->routes;
|
||||
|
||||
if (!_nm_object_get_property (NM_OBJECT (config),
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Routes",
|
||||
&value)) {
|
||||
NM_DBUS_INTERFACE_IP4_CONFIG,
|
||||
"Routes",
|
||||
&value)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
436
libnm-glib/nm-ip6-config.c
Normal file
436
libnm-glib/nm-ip6-config.c
Normal file
|
@ -0,0 +1,436 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* libnm_glib -- Access network status & information from glib applications
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2007 - 2008 Novell, Inc.
|
||||
* Copyright (C) 2008 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <nm-setting-ip6-config.h>
|
||||
#include "nm-ip6-config.h"
|
||||
#include "NetworkManager.h"
|
||||
#include "nm-types-private.h"
|
||||
#include "nm-object-private.h"
|
||||
#include "nm-utils.h"
|
||||
|
||||
G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_OBJECT)
|
||||
|
||||
#define NM_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP6_CONFIG, NMIP6ConfigPrivate))
|
||||
|
||||
typedef struct {
|
||||
DBusGProxy *proxy;
|
||||
|
||||
GSList *addresses;
|
||||
GSList *nameservers;
|
||||
GPtrArray *domains;
|
||||
GSList *routes;
|
||||
} NMIP6ConfigPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_ADDRESSES,
|
||||
PROP_NAMESERVERS,
|
||||
PROP_DOMAINS,
|
||||
PROP_ROUTES,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
* nm_ip6_config_new:
|
||||
* @connection: the #DBusGConnection
|
||||
* @object_path: the DBus object path of the device
|
||||
*
|
||||
* Creates a new #NMIP6Config.
|
||||
*
|
||||
* Returns: a new IP6 configuration
|
||||
**/
|
||||
GObject *
|
||||
nm_ip6_config_new (DBusGConnection *connection, const char *object_path)
|
||||
{
|
||||
return (GObject *) g_object_new (NM_TYPE_IP6_CONFIG,
|
||||
NM_OBJECT_DBUS_CONNECTION, connection,
|
||||
NM_OBJECT_DBUS_PATH, object_path,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
demarshal_ip6_address_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
|
||||
|
||||
g_slist_foreach (priv->addresses, (GFunc) nm_ip6_address_unref, NULL);
|
||||
g_slist_free (priv->addresses);
|
||||
priv->addresses = NULL;
|
||||
|
||||
priv->addresses = nm_utils_ip6_addresses_from_gvalue (value);
|
||||
_nm_object_queue_notify (object, NM_IP6_CONFIG_ADDRESSES);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
demarshal_ip6_nameserver_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
|
||||
{
|
||||
if (!_nm_ip6_address_array_demarshal (value, (GSList **) field))
|
||||
return FALSE;
|
||||
|
||||
if (!strcmp (pspec->name, NM_IP6_CONFIG_NAMESERVERS))
|
||||
_nm_object_queue_notify (object, NM_IP6_CONFIG_NAMESERVERS);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
demarshal_domains (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
|
||||
{
|
||||
if (!_nm_string_array_demarshal (value, (GPtrArray **) field))
|
||||
return FALSE;
|
||||
|
||||
_nm_object_queue_notify (object, NM_IP6_CONFIG_DOMAINS);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
demarshal_ip6_routes_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
|
||||
|
||||
g_slist_foreach (priv->routes, (GFunc) nm_ip6_route_unref, NULL);
|
||||
g_slist_free (priv->routes);
|
||||
priv->routes = NULL;
|
||||
|
||||
priv->routes = nm_utils_ip6_routes_from_gvalue (value);
|
||||
_nm_object_queue_notify (object, NM_IP6_CONFIG_ROUTES);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
register_for_property_changed (NMIP6Config *config)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
|
||||
const NMPropertiesChangedInfo property_changed_info[] = {
|
||||
{ NM_IP6_CONFIG_ADDRESSES, demarshal_ip6_address_array, &priv->addresses },
|
||||
{ NM_IP6_CONFIG_NAMESERVERS, demarshal_ip6_nameserver_array, &priv->nameservers },
|
||||
{ NM_IP6_CONFIG_DOMAINS, demarshal_domains, &priv->domains },
|
||||
{ NM_IP6_CONFIG_ROUTES, demarshal_ip6_routes_array, &priv->routes },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
_nm_object_handle_properties_changed (NM_OBJECT (config),
|
||||
priv->proxy,
|
||||
property_changed_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_config_get_addresses:
|
||||
* @config: a #NMIP6Config
|
||||
*
|
||||
* Gets the IP6 addresses (containing the address, prefix, and gateway).
|
||||
*
|
||||
* Returns: the #GSList containing #NMSettingIP6Address<!-- -->es. This is the internal copy
|
||||
* used by the configuration and must not be modified.
|
||||
**/
|
||||
const GSList *
|
||||
nm_ip6_config_get_addresses (NMIP6Config *config)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv;
|
||||
GValue value = { 0, };
|
||||
|
||||
g_return_val_if_fail (NM_IS_IP6_CONFIG (config), 0);
|
||||
|
||||
priv = NM_IP6_CONFIG_GET_PRIVATE (config);
|
||||
if (priv->addresses)
|
||||
return priv->addresses;
|
||||
|
||||
if (!_nm_object_get_property (NM_OBJECT (config),
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"Addresses",
|
||||
&value)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
demarshal_ip6_address_array (NM_OBJECT (config), NULL, &value, &priv->addresses);
|
||||
g_value_unset (&value);
|
||||
|
||||
return priv->addresses;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_config_get_nameservers:
|
||||
* @config: a #NMIP6Config
|
||||
*
|
||||
* Gets the domain name servers (DNS).
|
||||
*
|
||||
* Returns: a #GSList containing elements of type 'struct in6_addr' which contain
|
||||
* the addresses of nameservers of the configuration. This is the internal copy
|
||||
* used by the configuration and must not be modified.
|
||||
**/
|
||||
const GSList *
|
||||
nm_ip6_config_get_nameservers (NMIP6Config *config)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv;
|
||||
GValue value = {0,};
|
||||
|
||||
g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
|
||||
|
||||
priv = NM_IP6_CONFIG_GET_PRIVATE (config);
|
||||
if (priv->nameservers)
|
||||
return priv->nameservers;
|
||||
|
||||
if (!_nm_object_get_property (NM_OBJECT (config),
|
||||
NM_DBUS_INTERFACE_IP6_CONFIG,
|
||||
"Nameservers",
|
||||
&value)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
demarshal_ip6_nameserver_array (NM_OBJECT (config), NULL, &value, &priv->nameservers);
|
||||
g_value_unset (&value);
|
||||
|
||||
return priv->nameservers;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_config_get_domains:
|
||||
* @config: a #NMIP6Config
|
||||
*
|
||||
* Gets the domain names.
|
||||
*
|
||||
* Returns: the #GPtrArray containing domains as strings. This is the
|
||||
* internal copy used by the configuration, and must not be modified.
|
||||
**/
|
||||
const GPtrArray *
|
||||
nm_ip6_config_get_domains (NMIP6Config *config)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv;
|
||||
GValue value = {0,};
|
||||
|
||||
g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
|
||||
|
||||
priv = NM_IP6_CONFIG_GET_PRIVATE (config);
|
||||
if (priv->domains)
|
||||
return handle_ptr_array_return (priv->domains);
|
||||
|
||||
if (!_nm_object_get_property (NM_OBJECT (config),
|
||||
NM_DBUS_INTERFACE_IP6_CONFIG,
|
||||
"Domains",
|
||||
&value)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
demarshal_domains (NM_OBJECT (config), NULL, &value, &priv->domains);
|
||||
g_value_unset (&value);
|
||||
|
||||
return handle_ptr_array_return (priv->domains);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_ip6_config_get_routes:
|
||||
* @config: a #NMIP6Config
|
||||
*
|
||||
* Gets the routes.
|
||||
*
|
||||
* Returns: the #GSList containing #NMSettingIP6Route<!-- -->s. This is the
|
||||
* internal copy used by the configuration, and must not be modified.
|
||||
**/
|
||||
const GSList *
|
||||
nm_ip6_config_get_routes (NMIP6Config *config)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv;
|
||||
GValue value = { 0, };
|
||||
|
||||
g_return_val_if_fail (NM_IS_IP6_CONFIG (config), 0);
|
||||
|
||||
priv = NM_IP6_CONFIG_GET_PRIVATE (config);
|
||||
if (priv->routes)
|
||||
return priv->routes;
|
||||
|
||||
if (!_nm_object_get_property (NM_OBJECT (config),
|
||||
NM_DBUS_INTERFACE_IP6_CONFIG,
|
||||
"Routes",
|
||||
&value)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
demarshal_ip6_routes_array (NM_OBJECT (config), NULL, &value, &priv->routes);
|
||||
g_value_unset (&value);
|
||||
|
||||
return priv->routes;
|
||||
}
|
||||
|
||||
static GObject*
|
||||
constructor (GType type,
|
||||
guint n_construct_params,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object;
|
||||
DBusGConnection *connection;
|
||||
NMIP6ConfigPrivate *priv;
|
||||
|
||||
object = G_OBJECT_CLASS (nm_ip6_config_parent_class)->constructor (type,
|
||||
n_construct_params,
|
||||
construct_params);
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
priv = NM_IP6_CONFIG_GET_PRIVATE (object);
|
||||
connection = nm_object_get_connection (NM_OBJECT (object));
|
||||
|
||||
priv->proxy = dbus_g_proxy_new_for_name (connection,
|
||||
NM_DBUS_SERVICE,
|
||||
nm_object_get_path (NM_OBJECT (object)),
|
||||
NM_DBUS_INTERFACE_IP6_CONFIG);
|
||||
|
||||
register_for_property_changed (NM_IP6_CONFIG (object));
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
|
||||
|
||||
g_slist_foreach (priv->addresses, (GFunc) nm_ip6_address_unref, NULL);
|
||||
g_slist_free (priv->addresses);
|
||||
|
||||
g_slist_foreach (priv->routes, (GFunc) nm_ip6_route_unref, NULL);
|
||||
g_slist_free (priv->routes);
|
||||
|
||||
g_slist_foreach (priv->nameservers, (GFunc) g_free, NULL);
|
||||
g_slist_free (priv->nameservers);
|
||||
|
||||
if (priv->domains) {
|
||||
g_ptr_array_foreach (priv->domains, (GFunc) g_free, NULL);
|
||||
g_ptr_array_free (priv->domains, TRUE);
|
||||
}
|
||||
|
||||
g_object_unref (priv->proxy);
|
||||
|
||||
G_OBJECT_CLASS (nm_ip6_config_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
NMIP6Config *self = NM_IP6_CONFIG (object);
|
||||
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ADDRESSES:
|
||||
nm_utils_ip6_addresses_to_gvalue (priv->addresses, value);
|
||||
break;
|
||||
case PROP_NAMESERVERS:
|
||||
g_value_set_boxed (value, nm_ip6_config_get_nameservers (self));
|
||||
break;
|
||||
case PROP_DOMAINS:
|
||||
g_value_set_boxed (value, nm_ip6_config_get_domains (self));
|
||||
break;
|
||||
case PROP_ROUTES:
|
||||
nm_utils_ip6_routes_to_gvalue (priv->routes, value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nm_ip6_config_init (NMIP6Config *config)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
|
||||
|
||||
g_type_class_add_private (config_class, sizeof (NMIP6ConfigPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->constructor = constructor;
|
||||
object_class->get_property = get_property;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
/* properties */
|
||||
|
||||
/**
|
||||
* NMIP6Config:addresses:
|
||||
*
|
||||
* The #GPtrArray containing the IPv6 addresses; use
|
||||
* nm_utils_ip6_addresses_from_gvalue() to return a #GSList of
|
||||
* #NMSettingIP6Address objects that is more usable than the raw data.
|
||||
**/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ADDRESSES,
|
||||
g_param_spec_boxed (NM_IP6_CONFIG_ADDRESSES,
|
||||
"Addresses",
|
||||
"Addresses",
|
||||
NM_TYPE_IP6_ADDRESS_OBJECT_ARRAY,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
/**
|
||||
* NMIP6Config:nameservers:
|
||||
*
|
||||
* The #GPtrArray containing elements of type 'struct ip6_addr' which
|
||||
* contain the addresses of nameservers of the configuration.
|
||||
**/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_NAMESERVERS,
|
||||
g_param_spec_boxed (NM_IP6_CONFIG_NAMESERVERS,
|
||||
"Nameservers",
|
||||
"Nameservers",
|
||||
NM_TYPE_IP6_ADDRESS_ARRAY,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
/**
|
||||
* NMIP6Config:domains:
|
||||
*
|
||||
* The #GPtrArray containing domain strings of the configuration.
|
||||
**/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_DOMAINS,
|
||||
g_param_spec_boxed (NM_IP6_CONFIG_DOMAINS,
|
||||
"Domains",
|
||||
"Domains",
|
||||
NM_TYPE_STRING_ARRAY,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
/**
|
||||
* NMIP6Config:routes:
|
||||
*
|
||||
* The #GPtrArray containing the IPv6 routes; use
|
||||
* nm_utils_ip6_routes_from_gvalue() to return a #GSList of
|
||||
* #NMSettingIP6Address objects that is more usable than the raw data.
|
||||
**/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ROUTES,
|
||||
g_param_spec_boxed (NM_IP6_CONFIG_ROUTES,
|
||||
"Routes",
|
||||
"Routes",
|
||||
NM_TYPE_IP6_ROUTE_OBJECT_ARRAY,
|
||||
G_PARAM_READABLE));
|
||||
}
|
||||
|
65
libnm-glib/nm-ip6-config.h
Normal file
65
libnm-glib/nm-ip6-config.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* libnm_glib -- Access network status & information from glib applications
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2007 - 2008 Novell, Inc.
|
||||
* Copyright (C) 2008 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NM_IP6_CONFIG_H
|
||||
#define NM_IP6_CONFIG_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include "nm-object.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NM_TYPE_IP6_CONFIG (nm_ip6_config_get_type ())
|
||||
#define NM_IP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IP6_CONFIG, NMIP6Config))
|
||||
#define NM_IP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_IP6_CONFIG, NMIP6ConfigClass))
|
||||
#define NM_IS_IP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_IP6_CONFIG))
|
||||
#define NM_IS_IP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_IP6_CONFIG))
|
||||
#define NM_IP6_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IP6_CONFIG, NMIP6ConfigClass))
|
||||
|
||||
typedef struct {
|
||||
NMObject parent;
|
||||
} NMIP6Config;
|
||||
|
||||
typedef struct {
|
||||
NMObjectClass parent;
|
||||
} NMIP6ConfigClass;
|
||||
|
||||
#define NM_IP6_CONFIG_ADDRESSES "addresses"
|
||||
#define NM_IP6_CONFIG_NAMESERVERS "nameservers"
|
||||
#define NM_IP6_CONFIG_DOMAINS "domains"
|
||||
#define NM_IP6_CONFIG_ROUTES "routes"
|
||||
|
||||
GType nm_ip6_config_get_type (void);
|
||||
|
||||
GObject *nm_ip6_config_new (DBusGConnection *connection, const char *object_path);
|
||||
|
||||
const GSList * nm_ip6_config_get_addresses (NMIP6Config *config);
|
||||
const GSList * nm_ip6_config_get_nameservers (NMIP6Config *config);
|
||||
const GPtrArray *nm_ip6_config_get_domains (NMIP6Config *config);
|
||||
const GSList * nm_ip6_config_get_routes (NMIP6Config *config);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_IP6_CONFIG_H */
|
|
@ -34,6 +34,6 @@ gboolean _nm_object_array_demarshal (GValue *value,
|
|||
GPtrArray **dest,
|
||||
DBusGConnection *connection,
|
||||
NMObjectCreatorFunc func);
|
||||
|
||||
gboolean _nm_ip6_address_array_demarshal (GValue *value, GSList **dest);
|
||||
|
||||
#endif /* NM_TYPES_PRIVATE_H */
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "nm-object-private.h"
|
||||
#include "nm-object-cache.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-setting-ip6-config.h"
|
||||
|
||||
static gpointer
|
||||
nm_ssid_copy (GByteArray *src)
|
||||
|
@ -275,3 +276,148 @@ _nm_object_array_demarshal (GValue *value,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************/
|
||||
|
||||
static gpointer
|
||||
nm_ip6_address_object_array_copy (GPtrArray *src)
|
||||
{
|
||||
GPtrArray *dest;
|
||||
int i;
|
||||
|
||||
dest = g_ptr_array_sized_new (src->len);
|
||||
for (i = 0; i < src->len; i++)
|
||||
g_ptr_array_add (dest, nm_ip6_address_dup (g_ptr_array_index (src, i)));
|
||||
return dest;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_ip6_address_object_array_free (GPtrArray *array)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < array->len; i++)
|
||||
nm_ip6_address_unref (g_ptr_array_index (array, i));
|
||||
g_ptr_array_free (array, TRUE);
|
||||
}
|
||||
|
||||
GType
|
||||
nm_ip6_address_object_array_get_type (void)
|
||||
{
|
||||
static GType our_type = 0;
|
||||
|
||||
if (our_type == 0)
|
||||
our_type = g_boxed_type_register_static (g_intern_static_string ("nm-ip6-address-object-array"),
|
||||
(GBoxedCopyFunc) nm_ip6_address_object_array_copy,
|
||||
(GBoxedFreeFunc) nm_ip6_address_object_array_free);
|
||||
return our_type;
|
||||
}
|
||||
|
||||
/*****************************/
|
||||
|
||||
static gpointer
|
||||
nm_ip6_address_array_copy (GPtrArray *src)
|
||||
{
|
||||
GPtrArray *dest;
|
||||
int i;
|
||||
|
||||
dest = g_ptr_array_sized_new (src->len);
|
||||
for (i = 0; i < src->len; i++) {
|
||||
struct in6_addr *addr = g_ptr_array_index (src, i);
|
||||
struct in6_addr *dup;
|
||||
|
||||
dup = g_malloc0 (sizeof (struct in6_addr));
|
||||
memcpy (dup, addr, sizeof (struct in6_addr));
|
||||
g_ptr_array_add (dest, dup);
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_ip6_address_array_free (GPtrArray *array)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < array->len; i++)
|
||||
g_free (g_ptr_array_index (array, i));
|
||||
g_ptr_array_free (array, TRUE);
|
||||
}
|
||||
|
||||
GType
|
||||
nm_ip6_address_array_get_type (void)
|
||||
{
|
||||
static GType our_type = 0;
|
||||
|
||||
if (our_type == 0)
|
||||
our_type = g_boxed_type_register_static (g_intern_static_string ("nm-ip6-address-array"),
|
||||
(GBoxedCopyFunc) nm_ip6_address_array_copy,
|
||||
(GBoxedFreeFunc) nm_ip6_address_array_free);
|
||||
return our_type;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_nm_ip6_address_array_demarshal (GValue *value, GSList **dest)
|
||||
{
|
||||
GPtrArray *array;
|
||||
|
||||
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY))
|
||||
return FALSE;
|
||||
|
||||
if (*dest) {
|
||||
g_slist_foreach (*dest, (GFunc) g_free, NULL);
|
||||
g_slist_free (*dest);
|
||||
*dest = NULL;
|
||||
}
|
||||
|
||||
array = (GPtrArray *) g_value_get_boxed (value);
|
||||
if (array && array->len) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < array->len; i++) {
|
||||
struct in6_addr *addr = g_ptr_array_index (array, i);
|
||||
struct in6_addr *dup;
|
||||
|
||||
dup = g_malloc0 (sizeof (struct in6_addr));
|
||||
memcpy (dup, addr, sizeof (struct in6_addr));
|
||||
*dest = g_slist_append (*dest, dup);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************/
|
||||
|
||||
static gpointer
|
||||
nm_ip6_route_object_array_copy (GPtrArray *src)
|
||||
{
|
||||
GPtrArray *dest;
|
||||
int i;
|
||||
|
||||
dest = g_ptr_array_sized_new (src->len);
|
||||
for (i = 0; i < src->len; i++)
|
||||
g_ptr_array_add (dest, nm_ip6_route_dup (g_ptr_array_index (src, i)));
|
||||
return dest;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_ip6_route_object_array_free (GPtrArray *array)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < array->len; i++)
|
||||
nm_ip6_route_unref (g_ptr_array_index (array, i));
|
||||
g_ptr_array_free (array, TRUE);
|
||||
}
|
||||
|
||||
GType
|
||||
nm_ip6_route_object_array_get_type (void)
|
||||
{
|
||||
static GType our_type = 0;
|
||||
|
||||
if (our_type == 0)
|
||||
our_type = g_boxed_type_register_static (g_intern_static_string ("nm-ip6-route-object-array"),
|
||||
(GBoxedCopyFunc) nm_ip6_route_object_array_copy,
|
||||
(GBoxedFreeFunc) nm_ip6_route_object_array_free);
|
||||
return our_type;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,4 +38,13 @@ GType nm_string_array_get_type (void) G_GNUC_CONST;
|
|||
#define NM_TYPE_OBJECT_ARRAY (nm_object_array_get_type ())
|
||||
GType nm_object_array_get_type (void) G_GNUC_CONST;
|
||||
|
||||
#define NM_TYPE_IP6_ADDRESS_OBJECT_ARRAY (nm_ip6_address_object_array_get_type ())
|
||||
GType nm_ip6_address_object_array_get_type (void) G_GNUC_CONST;
|
||||
|
||||
#define NM_TYPE_IP6_ADDRESS_ARRAY (nm_ip6_address_array_get_type ())
|
||||
GType nm_ip6_address_array_get_type (void) G_GNUC_CONST;
|
||||
|
||||
#define NM_TYPE_IP6_ROUTE_OBJECT_ARRAY (nm_ip6_route_object_array_get_type ())
|
||||
GType nm_ip6_route_object_array_get_type (void) G_GNUC_CONST;
|
||||
|
||||
#endif /* NM_TYPES_H */
|
||||
|
|
Loading…
Reference in a new issue