2008-03-12 Dan Williams <dcbw@redhat.com>

* libnm-util/nm-setting-ip4-config.c
	  libnm-util/nm-setting-ip4-config.h
		- Remove 'manual' and 'autoip' properties
		- Add 'method' property
		- (verify): fix verification with 'method'
		- (finalize): free 'method'
		- (set_property, get_property, nm_setting_ip4_config_class_init): fix
			up for 'method'

	* src/nm-device.c
		- (real_act_stage3_ip_config_start): check IP4Config method
		- (nm_device_new_ip4_autoip_config): add a note about not sucking in
			the future
		- (merge_ip4_config): IP settings are valid with DHCP too
		- (real_act_stage4_get_ip4_config): handle all IP4Config methods
		- (real_act_stage4_ip_config_timeout): don't do autoip on DHCP timeout

	* src/nm-device-802-11-wireless.c
		- (real_act_stage3_ip_config_start): remove; autoip only on demand
		- (real_act_stage4_get_ip4_config): just chain up to parent; autoip
			only on demand

	* system-settings/plugins/ifcfg-fedora/parser.c
	  system-settings/plugins/ifcfg-suse/parser.c
		- (make_ip4_setting): fix up for 'method'



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3443 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2008-03-13 03:11:02 +00:00
parent d5efb7be6d
commit 1cfb4db69f
7 changed files with 132 additions and 129 deletions

View File

@@ -1,3 +1,31 @@
2008-03-12 Dan Williams <dcbw@redhat.com>
* libnm-util/nm-setting-ip4-config.c
libnm-util/nm-setting-ip4-config.h
- Remove 'manual' and 'autoip' properties
- Add 'method' property
- (verify): fix verification with 'method'
- (finalize): free 'method'
- (set_property, get_property, nm_setting_ip4_config_class_init): fix
up for 'method'
* src/nm-device.c
- (real_act_stage3_ip_config_start): check IP4Config method
- (nm_device_new_ip4_autoip_config): add a note about not sucking in
the future
- (merge_ip4_config): IP settings are valid with DHCP too
- (real_act_stage4_get_ip4_config): handle all IP4Config methods
- (real_act_stage4_ip_config_timeout): don't do autoip on DHCP timeout
* src/nm-device-802-11-wireless.c
- (real_act_stage3_ip_config_start): remove; autoip only on demand
- (real_act_stage4_get_ip4_config): just chain up to parent; autoip
only on demand
* system-settings/plugins/ifcfg-fedora/parser.c
system-settings/plugins/ifcfg-suse/parser.c
- (make_ip4_setting): fix up for 'method'
2008-03-12 Dan Williams <dcbw@redhat.com> 2008-03-12 Dan Williams <dcbw@redhat.com>
* system-settings/plugins/ifcfg-fedora/parser.c * system-settings/plugins/ifcfg-fedora/parser.c

View File

@@ -1,5 +1,7 @@
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ /* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
#include <string.h>
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>
#include "nm-setting-ip4-config.h" #include "nm-setting-ip4-config.h"
#include "nm-param-spec-specialized.h" #include "nm-param-spec-specialized.h"
@@ -9,8 +11,7 @@ G_DEFINE_TYPE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING)
enum { enum {
PROP_0, PROP_0,
PROP_MANUAL, PROP_METHOD,
PROP_AUTOIP,
PROP_DNS, PROP_DNS,
PROP_DNS_SEARCH, PROP_DNS_SEARCH,
PROP_ADDRESSES, PROP_ADDRESSES,
@@ -29,11 +30,34 @@ verify (NMSetting *setting, GSList *all_settings)
{ {
NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (setting); NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (setting);
if (self->manual) { if (!self->method)
return FALSE;
if (!strcmp (self->method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
if (!self->addresses) { if (!self->addresses) {
g_warning ("address is not provided"); g_warning ("address is not provided");
return FALSE; return FALSE;
} }
} else if (!strcmp (self->method, NM_SETTING_IP4_CONFIG_METHOD_AUTOIP)) {
if (self->dns && self->dns->len) {
g_warning ("may not specify DNS when using autoip");
return FALSE;
}
if (g_slist_length (self->dns_search)) {
g_warning ("may not specify DNS searches when using autoip");
return FALSE;
}
if (g_slist_length (self->addresses)) {
g_warning ("may not specify IP addresses when using autoip");
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;
} }
return TRUE; return TRUE;
@@ -51,6 +75,8 @@ finalize (GObject *object)
{ {
NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (object); NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (object);
g_free (self->method);
if (self->dns) if (self->dns)
g_array_free (self->dns, TRUE); g_array_free (self->dns, TRUE);
@@ -125,11 +151,9 @@ set_property (GObject *object, guint prop_id,
NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object); NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
switch (prop_id) { switch (prop_id) {
case PROP_MANUAL: case PROP_METHOD:
setting->manual = g_value_get_boolean (value); g_free (setting->method);
break; setting->method = g_value_dup_string (value);
case PROP_AUTOIP:
setting->autoip = g_value_get_boolean (value);
break; break;
case PROP_DNS: case PROP_DNS:
if (setting->dns) if (setting->dns)
@@ -157,11 +181,8 @@ get_property (GObject *object, guint prop_id,
NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object); NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object);
switch (prop_id) { switch (prop_id) {
case PROP_MANUAL: case PROP_METHOD:
g_value_set_boolean (value, setting->manual); g_value_set_string (value, setting->method);
break;
case PROP_AUTOIP:
g_value_set_boolean (value, setting->autoip);
break; break;
case PROP_DNS: case PROP_DNS:
g_value_set_boxed (value, setting->dns); g_value_set_boxed (value, setting->dns);
@@ -192,19 +213,11 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class)
/* Properties */ /* Properties */
g_object_class_install_property g_object_class_install_property
(object_class, PROP_MANUAL, (object_class, PROP_METHOD,
g_param_spec_boolean (NM_SETTING_IP4_CONFIG_MANUAL, g_param_spec_string (NM_SETTING_IP4_CONFIG_METHOD,
"Manual", "Method",
"Do not use DHCP", "IP configuration method",
FALSE, NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
g_object_class_install_property
(object_class, PROP_AUTOIP,
g_param_spec_boolean (NM_SETTING_IP4_CONFIG_AUTOIP,
"Auto IP",
"Use Auto IP",
FALSE,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
g_object_class_install_property g_object_class_install_property

View File

@@ -16,12 +16,15 @@ G_BEGIN_DECLS
#define NM_SETTING_IP4_CONFIG_SETTING_NAME "ipv4" #define NM_SETTING_IP4_CONFIG_SETTING_NAME "ipv4"
#define NM_SETTING_IP4_CONFIG_MANUAL "manual" #define NM_SETTING_IP4_CONFIG_METHOD "method"
#define NM_SETTING_IP4_CONFIG_AUTOIP "autoip"
#define NM_SETTING_IP4_CONFIG_DNS "dns" #define NM_SETTING_IP4_CONFIG_DNS "dns"
#define NM_SETTING_IP4_CONFIG_DNS_SEARCH "dns-search" #define NM_SETTING_IP4_CONFIG_DNS_SEARCH "dns-search"
#define NM_SETTING_IP4_CONFIG_ADDRESSES "addresses" #define NM_SETTING_IP4_CONFIG_ADDRESSES "addresses"
#define NM_SETTING_IP4_CONFIG_METHOD_DHCP "dhcp"
#define NM_SETTING_IP4_CONFIG_METHOD_AUTOIP "autoip"
#define NM_SETTING_IP4_CONFIG_METHOD_MANUAL "manual"
typedef struct { typedef struct {
guint32 address; guint32 address;
guint32 netmask; guint32 netmask;
@@ -31,8 +34,7 @@ typedef struct {
typedef struct { typedef struct {
NMSetting parent; NMSetting parent;
gboolean manual; char *method;
gboolean autoip;
GArray *dns; /* array of guint32 */ GArray *dns; /* array of guint32 */
GSList *dns_search; /* list of strings */ GSList *dns_search; /* list of strings */
GSList *addresses; /* array of NMSettingIP4Address */ GSList *addresses; /* array of NMSettingIP4Address */

View File

@@ -2685,69 +2685,19 @@ out:
return ret; return ret;
} }
static NMActStageReturn
real_act_stage3_ip_config_start (NMDevice *dev)
{
NMDevice80211Wireless * self = NM_DEVICE_802_11_WIRELESS (dev);
NMAccessPoint * ap;
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
NMActRequest * req;
NMConnection * connection;
ap = nm_device_802_11_wireless_get_activation_ap (self);
g_assert (ap);
req = nm_device_get_act_request (dev);
g_assert (req);
connection = nm_act_request_get_connection (req);
g_assert (connection);
/* User-created access points (ie, Ad-Hoc networks) don't do DHCP,
* everything else does.
*/
if (!nm_ap_get_user_created (ap))
{
NMDevice80211WirelessClass * klass;
NMDeviceClass * parent_class;
/* Chain up to parent */
klass = NM_DEVICE_802_11_WIRELESS_GET_CLASS (self);
parent_class = NM_DEVICE_CLASS (g_type_class_peek_parent (klass));
ret = parent_class->act_stage3_ip_config_start (dev);
}
else
ret = NM_ACT_STAGE_RETURN_SUCCESS;
return ret;
}
static NMActStageReturn static NMActStageReturn
real_act_stage4_get_ip4_config (NMDevice *dev, real_act_stage4_get_ip4_config (NMDevice *dev,
NMIP4Config **config) NMIP4Config **config)
{ {
NMDevice80211Wireless *self = NM_DEVICE_802_11_WIRELESS (dev);
NMAccessPoint *ap = nm_device_802_11_wireless_get_activation_ap (self);
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
NMDeviceClass *parent_class;
g_return_val_if_fail (config != NULL, NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (config != NULL, NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (*config == NULL, NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (*config == NULL, NM_ACT_STAGE_RETURN_FAILURE);
g_assert (ap);
if (nm_ap_get_user_created (ap)) {
*config = nm_device_new_ip4_autoip_config (NM_DEVICE (self));
ret = NM_ACT_STAGE_RETURN_SUCCESS;
} else {
NMDevice80211WirelessClass * klass;
NMDeviceClass * parent_class;
/* Chain up to parent */ /* Chain up to parent */
klass = NM_DEVICE_802_11_WIRELESS_GET_CLASS (self); parent_class = NM_DEVICE_CLASS (nm_device_802_11_wireless_parent_class);
parent_class = NM_DEVICE_CLASS (g_type_class_peek_parent (klass));
ret = parent_class->act_stage4_get_ip4_config (dev, config); ret = parent_class->act_stage4_get_ip4_config (dev, config);
}
if ((ret == NM_ACT_STAGE_RETURN_SUCCESS) && *config) { if ((ret == NM_ACT_STAGE_RETURN_SUCCESS) && *config) {
NMConnection *connection; NMConnection *connection;
@@ -3052,7 +3002,6 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass)
parent_class->act_stage1_prepare = real_act_stage1_prepare; parent_class->act_stage1_prepare = real_act_stage1_prepare;
parent_class->act_stage2_config = real_act_stage2_config; parent_class->act_stage2_config = real_act_stage2_config;
parent_class->act_stage3_ip_config_start = real_act_stage3_ip_config_start;
parent_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config; parent_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
parent_class->act_stage4_ip_config_timeout = real_act_stage4_ip_config_timeout; parent_class->act_stage4_ip_config_timeout = real_act_stage4_ip_config_timeout;
parent_class->deactivate = real_deactivate; parent_class->deactivate = real_deactivate;

View File

@@ -531,11 +531,11 @@ real_act_stage3_ip_config_start (NMDevice *self)
NM_TYPE_SETTING_IP4_CONFIG); NM_TYPE_SETTING_IP4_CONFIG);
/* If we did not receive IP4 configuration information, default to DHCP */ /* If we did not receive IP4 configuration information, default to DHCP */
if (!setting || setting->manual == FALSE) { if (!setting || !strcmp (setting->method, NM_SETTING_IP4_CONFIG_METHOD_DHCP)) {
/* Begin a DHCP transaction on the interface */
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
gboolean success; gboolean success;
/* Begin a DHCP transaction on the interface */
nm_device_set_use_dhcp (self, TRUE); nm_device_set_use_dhcp (self, TRUE);
/* DHCP manager will cancel any transaction already in progress and we do not /* DHCP manager will cancel any transaction already in progress and we do not
@@ -636,8 +636,8 @@ nm_device_new_ip4_autoip_config (NMDevice *self)
g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self != NULL, NULL);
if (get_autoip (self, &ip)) // FIXME: make our autoip implementation not suck; use avahi-autoip
{ if (get_autoip (self, &ip)) {
#define LINKLOCAL_BCAST 0xa9feffff #define LINKLOCAL_BCAST 0xa9feffff
config = nm_ip4_config_new (); config = nm_ip4_config_new ();
@@ -673,7 +673,6 @@ merge_ip4_config (NMIP4Config *ip4_config, NMSettingIP4Config *setting)
if (setting->addresses) { if (setting->addresses) {
/* FIXME; add support for more than one set of address/netmask/gateway for NMIP4Config */ /* FIXME; add support for more than one set of address/netmask/gateway for NMIP4Config */
if (setting->manual) {
NMSettingIP4Address *addr = (NMSettingIP4Address *) setting->addresses->data; NMSettingIP4Address *addr = (NMSettingIP4Address *) setting->addresses->data;
nm_ip4_config_set_address (ip4_config, addr->address); nm_ip4_config_set_address (ip4_config, addr->address);
@@ -682,7 +681,6 @@ merge_ip4_config (NMIP4Config *ip4_config, NMSettingIP4Config *setting)
if (addr->gateway) if (addr->gateway)
nm_ip4_config_set_gateway (ip4_config, addr->gateway); nm_ip4_config_set_gateway (ip4_config, addr->gateway);
} }
}
} }
static NMActStageReturn static NMActStageReturn
@@ -691,29 +689,36 @@ real_act_stage4_get_ip4_config (NMDevice *self,
{ {
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
NMConnection *connection; NMConnection *connection;
NMSettingIP4Config *s_ip4;
g_return_val_if_fail (config != NULL, NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (config != NULL, NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (*config == NULL, NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (*config == NULL, NM_ACT_STAGE_RETURN_FAILURE);
connection = nm_act_request_get_connection (nm_device_get_act_request (self)); connection = nm_act_request_get_connection (nm_device_get_act_request (self));
g_assert (connection);
if (nm_device_get_use_dhcp (self)) s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
if (nm_device_get_use_dhcp (self)) {
*config = nm_dhcp_manager_get_ip4_config (NM_DEVICE_GET_PRIVATE (self)->dhcp_manager, *config = nm_dhcp_manager_get_ip4_config (NM_DEVICE_GET_PRIVATE (self)->dhcp_manager,
nm_device_get_iface (self)); nm_device_get_iface (self));
else
*config = nm_ip4_config_new ();
if (*config) {
NMSettingIP4Config *s_ip4;
s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG));
merge_ip4_config (*config, s_ip4); merge_ip4_config (*config, s_ip4);
ret = NM_ACT_STAGE_RETURN_SUCCESS;
} else { } else {
/* Make sure device is up even if config fails */ g_assert (s_ip4);
if (!nm_device_bring_up (self, FALSE))
ret = NM_ACT_STAGE_RETURN_FAILURE; if (!strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_AUTOIP)) {
nm_device_new_ip4_autoip_config (self);
} else if (!strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
*config = nm_ip4_config_new ();
merge_ip4_config (*config, s_ip4);
} }
}
if (!*config) {
/* Make sure device is up even if config fails */
nm_device_bring_up (self, FALSE);
} else
ret = NM_ACT_STAGE_RETURN_SUCCESS;
return ret; return ret;
} }
@@ -791,11 +796,8 @@ real_act_stage4_ip_config_timeout (NMDevice *self,
g_return_val_if_fail (config != NULL, NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (config != NULL, NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (*config == NULL, NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (*config == NULL, NM_ACT_STAGE_RETURN_FAILURE);
/* Wired network, no DHCP reply. Let's get an IP via Zeroconf. */ /* DHCP failed; connection must fail */
nm_info ("No DHCP reply received. Automatically obtaining IP via Zeroconf."); return NM_ACT_STAGE_RETURN_FAILURE;
*config = nm_device_new_ip4_autoip_config (self);
return NM_ACT_STAGE_RETURN_SUCCESS;
} }

View File

@@ -302,12 +302,17 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
NMSettingIP4Config *s_ip4 = NULL; NMSettingIP4Config *s_ip4 = NULL;
char *value = NULL; char *value = NULL;
NMSettingIP4Address tmp = { 0, 0, 0 }; NMSettingIP4Address tmp = { 0, 0, 0 };
gboolean manual = TRUE; char *method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
char *dir; char *dir;
value = svGetValue (ifcfg, "BOOTPROTO"); value = svGetValue (ifcfg, "BOOTPROTO");
if (value && (!strcmp (value, "bootp") || !strcmp (value, "dhcp"))) if (value && (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp")))
manual = FALSE; method = NM_SETTING_IP4_CONFIG_METHOD_DHCP;
if (value && !g_ascii_strcasecmp (value, "autoip")) {
method = NM_SETTING_IP4_CONFIG_METHOD_AUTOIP;
goto done;
}
value = svGetValue (ifcfg, "IPADDR"); value = svGetValue (ifcfg, "IPADDR");
if (value) { if (value) {
@@ -348,8 +353,9 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
g_free (value); g_free (value);
} }
done:
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
s_ip4->manual = manual; s_ip4->method = g_strdup (method);
if (tmp.address || tmp.netmask || tmp.gateway) { if (tmp.address || tmp.netmask || tmp.gateway) {
NMSettingIP4Address *addr; NMSettingIP4Address *addr;
addr = g_new0 (NMSettingIP4Address, 1); addr = g_new0 (NMSettingIP4Address, 1);
@@ -357,6 +363,8 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
s_ip4->addresses = g_slist_append (s_ip4->addresses, addr); s_ip4->addresses = g_slist_append (s_ip4->addresses, addr);
} }
/* No DNS for autoip */
if (g_ascii_strcasecmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTOIP)) {
dir = g_path_get_dirname (ifcfg->fileName); dir = g_path_get_dirname (ifcfg->fileName);
if (dir) { if (dir) {
read_profile_resolv_conf (dir, s_ip4); read_profile_resolv_conf (dir, s_ip4);
@@ -366,6 +374,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
"Not enough memory to parse resolv.conf"); "Not enough memory to parse resolv.conf");
goto error; goto error;
} }
}
return NM_SETTING (s_ip4); return NM_SETTING (s_ip4);

View File

@@ -155,14 +155,14 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
NMSettingIP4Config *s_ip4 = NULL; NMSettingIP4Config *s_ip4 = NULL;
char *value = NULL; char *value = NULL;
NMSettingIP4Address tmp = { 0, 0, 0 }; NMSettingIP4Address tmp = { 0, 0, 0 };
gboolean manual = TRUE; char *method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
value = svGetValue (ifcfg, "BOOTPROTO"); value = svGetValue (ifcfg, "BOOTPROTO");
if (!value) if (!value)
return NULL; return NULL;
if (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp")) { if (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp")) {
manual = FALSE; method = NM_SETTING_IP4_CONFIG_METHOD_DHCP;
return NULL; return NULL;
} }
@@ -212,7 +212,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
} }
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
s_ip4->manual = manual; s_ip4->method = g_strdup (method);
if (tmp.address || tmp.netmask || tmp.gateway) { if (tmp.address || tmp.netmask || tmp.gateway) {
NMSettingIP4Address *addr; NMSettingIP4Address *addr;
addr = g_new0 (NMSettingIP4Address, 1); addr = g_new0 (NMSettingIP4Address, 1);