2007-11-07 16:06:43 +00:00
|
|
|
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
|
|
|
|
2008-03-13 03:11:02 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2007-11-07 16:06:43 +00:00
|
|
|
#include <dbus/dbus-glib.h>
|
|
|
|
#include "nm-setting-ip4-config.h"
|
|
|
|
#include "nm-param-spec-specialized.h"
|
|
|
|
#include "nm-utils.h"
|
2008-03-29 21:35:41 +00:00
|
|
|
#include "nm-dbus-glib-types.h"
|
2007-11-07 16:06:43 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2008-03-13 03:11:02 +00:00
|
|
|
PROP_METHOD,
|
2007-11-07 16:06:43 +00:00
|
|
|
PROP_DNS,
|
|
|
|
PROP_DNS_SEARCH,
|
|
|
|
PROP_ADDRESSES,
|
2008-06-02 08:44:48 +00:00
|
|
|
PROP_ROUTES,
|
2008-05-23 07:35:43 +00:00
|
|
|
PROP_IGNORE_DHCP_DNS,
|
2007-11-07 16:06:43 +00:00
|
|
|
|
|
|
|
LAST_PROP
|
|
|
|
};
|
|
|
|
|
|
|
|
NMSetting *
|
|
|
|
nm_setting_ip4_config_new (void)
|
|
|
|
{
|
|
|
|
return (NMSetting *) g_object_new (NM_TYPE_SETTING_IP4_CONFIG, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
verify (NMSetting *setting, GSList *all_settings)
|
|
|
|
{
|
|
|
|
NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (setting);
|
|
|
|
|
2008-03-13 03:11:02 +00:00
|
|
|
if (!self->method)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!strcmp (self->method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
|
2007-11-07 16:06:43 +00:00
|
|
|
if (!self->addresses) {
|
|
|
|
g_warning ("address is not provided");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-05-29 20:53:01 +00:00
|
|
|
} else if ( !strcmp (self->method, NM_SETTING_IP4_CONFIG_METHOD_AUTOIP)
|
|
|
|
|| !strcmp (self->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) {
|
2008-03-13 03:11:02 +00:00
|
|
|
if (self->dns && self->dns->len) {
|
2008-05-29 20:53:01 +00:00
|
|
|
g_warning ("may not specify DNS when using autoip/shared");
|
2008-03-13 03:11:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_slist_length (self->dns_search)) {
|
2008-05-29 20:53:01 +00:00
|
|
|
g_warning ("may not specify DNS searches when using autoip/shared");
|
2008-03-13 03:11:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_slist_length (self->addresses)) {
|
2008-05-29 20:53:01 +00:00
|
|
|
g_warning ("may not specify IP addresses when using autoip/shared");
|
2008-03-13 03:11:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else if (!strcmp (self->method, NM_SETTING_IP4_CONFIG_METHOD_DHCP)) {
|
|
|
|
/* nothing to do */
|
|
|
|
} else {
|
|
|
|
g_warning ("invalid IP4 config method '%s'", self->method);
|
|
|
|
return FALSE;
|
2007-11-07 16:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
nm_setting_ip4_config_init (NMSettingIP4Config *setting)
|
|
|
|
{
|
|
|
|
((NMSetting *) setting)->name = g_strdup (NM_SETTING_IP4_CONFIG_SETTING_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
finalize (GObject *object)
|
|
|
|
{
|
|
|
|
NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (object);
|
|
|
|
|
2008-03-13 03:11:02 +00:00
|
|
|
g_free (self->method);
|
|
|
|
|
2007-11-07 16:06:43 +00:00
|
|
|
if (self->dns)
|
|
|
|
g_array_free (self->dns, TRUE);
|
|
|
|
|
|
|
|
nm_utils_slist_free (self->dns_search, g_free);
|
|
|
|
nm_utils_slist_free (self->addresses, g_free);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (nm_setting_ip4_config_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2008-03-13 03:11:02 +00:00
|
|
|
case PROP_METHOD:
|
|
|
|
g_free (setting->method);
|
|
|
|
setting->method = g_value_dup_string (value);
|
2008-03-12 12:45:20 +00:00
|
|
|
break;
|
2007-11-07 16:06:43 +00:00
|
|
|
case PROP_DNS:
|
|
|
|
if (setting->dns)
|
|
|
|
g_array_free (setting->dns, TRUE);
|
|
|
|
setting->dns = g_value_dup_boxed (value);
|
|
|
|
break;
|
|
|
|
case PROP_DNS_SEARCH:
|
|
|
|
nm_utils_slist_free (setting->dns_search, g_free);
|
|
|
|
setting->dns_search = g_value_dup_boxed (value);
|
|
|
|
break;
|
|
|
|
case PROP_ADDRESSES:
|
|
|
|
nm_utils_slist_free (setting->addresses, g_free);
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
setting->addresses = nm_utils_ip4_addresses_from_gvalue (value);
|
2008-06-02 08:44:48 +00:00
|
|
|
case PROP_ROUTES:
|
|
|
|
nm_utils_slist_free (setting->routes, g_free);
|
|
|
|
setting->routes = nm_utils_ip4_addresses_from_gvalue (value);
|
2007-11-07 16:06:43 +00:00
|
|
|
break;
|
2008-05-23 07:35:43 +00:00
|
|
|
case PROP_IGNORE_DHCP_DNS:
|
|
|
|
setting->ignore_dhcp_dns = g_value_get_boolean (value);
|
|
|
|
break;
|
2007-11-07 16:06:43 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2008-03-13 03:11:02 +00:00
|
|
|
case PROP_METHOD:
|
|
|
|
g_value_set_string (value, setting->method);
|
2008-03-12 12:45:20 +00:00
|
|
|
break;
|
2007-11-07 16:06:43 +00:00
|
|
|
case PROP_DNS:
|
|
|
|
g_value_set_boxed (value, setting->dns);
|
|
|
|
break;
|
|
|
|
case PROP_DNS_SEARCH:
|
|
|
|
g_value_set_boxed (value, setting->dns_search);
|
|
|
|
break;
|
|
|
|
case PROP_ADDRESSES:
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
nm_utils_ip4_addresses_to_gvalue (setting->addresses, value);
|
2007-11-07 16:06:43 +00:00
|
|
|
break;
|
2008-06-02 08:44:48 +00:00
|
|
|
case PROP_ROUTES:
|
|
|
|
nm_utils_ip4_addresses_to_gvalue (setting->routes, value);
|
|
|
|
break;
|
2008-05-23 07:35:43 +00:00
|
|
|
case PROP_IGNORE_DHCP_DNS:
|
|
|
|
g_value_set_boolean (value, setting->ignore_dhcp_dns);
|
|
|
|
break;
|
2007-11-07 16:06:43 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
|
|
|
|
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
|
|
|
|
|
|
|
|
/* virtual methods */
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
object_class->get_property = get_property;
|
|
|
|
object_class->finalize = finalize;
|
|
|
|
parent_class->verify = verify;
|
|
|
|
|
|
|
|
/* Properties */
|
|
|
|
g_object_class_install_property
|
2008-03-13 03:11:02 +00:00
|
|
|
(object_class, PROP_METHOD,
|
|
|
|
g_param_spec_string (NM_SETTING_IP4_CONFIG_METHOD,
|
|
|
|
"Method",
|
|
|
|
"IP configuration method",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
2008-03-12 12:45:20 +00:00
|
|
|
|
2007-11-07 16:06:43 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_DNS,
|
|
|
|
nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_DNS,
|
|
|
|
"DNS",
|
|
|
|
"List of DNS servers",
|
|
|
|
DBUS_TYPE_G_UINT_ARRAY,
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_DNS_SEARCH,
|
|
|
|
nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_DNS_SEARCH,
|
|
|
|
"DNS search",
|
|
|
|
"List of DNS search domains",
|
2008-03-29 21:35:41 +00:00
|
|
|
DBUS_TYPE_G_LIST_OF_STRING,
|
2007-11-07 16:06:43 +00:00
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_ADDRESSES,
|
|
|
|
nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_ADDRESSES,
|
|
|
|
"Addresses",
|
|
|
|
"List of NMSettingIP4Addresses",
|
2008-03-29 21:35:41 +00:00
|
|
|
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
|
2007-11-07 16:06:43 +00:00
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
2008-05-23 07:35:43 +00:00
|
|
|
|
2008-06-02 08:44:48 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_ROUTES,
|
|
|
|
nm_param_spec_specialized (NM_SETTING_IP4_CONFIG_ROUTES,
|
|
|
|
"Routes",
|
|
|
|
"List of NMSettingIP4Addresses",
|
|
|
|
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
|
|
|
|
2008-05-23 07:35:43 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class, PROP_IGNORE_DHCP_DNS,
|
|
|
|
g_param_spec_boolean (NM_SETTING_IP4_CONFIG_IGNORE_DHCP_DNS,
|
|
|
|
"Ignore DHCP DNS",
|
|
|
|
"Ignore DHCP DNS",
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
|
2007-11-07 16:06:43 +00:00
|
|
|
}
|