From 1cfb4db69fb0913bc30e79e3b83aa76279db1e18 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 13 Mar 2008 03:11:02 +0000 Subject: [PATCH] 2008-03-12 Dan Williams * 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 --- ChangeLog | 28 ++++++++ libnm-util/nm-setting-ip4-config.c | 67 +++++++++++-------- libnm-util/nm-setting-ip4-config.h | 10 +-- src/nm-device-802-11-wireless.c | 59 ++-------------- src/nm-device.c | 58 ++++++++-------- system-settings/plugins/ifcfg-fedora/parser.c | 33 +++++---- system-settings/plugins/ifcfg-suse/parser.c | 6 +- 7 files changed, 132 insertions(+), 129 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3c80de655..47543bdf6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2008-03-12 Dan Williams + + * 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 * system-settings/plugins/ifcfg-fedora/parser.c diff --git a/libnm-util/nm-setting-ip4-config.c b/libnm-util/nm-setting-ip4-config.c index 30eb465da..80d030a50 100644 --- a/libnm-util/nm-setting-ip4-config.c +++ b/libnm-util/nm-setting-ip4-config.c @@ -1,5 +1,7 @@ /* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +#include + #include #include "nm-setting-ip4-config.h" #include "nm-param-spec-specialized.h" @@ -9,8 +11,7 @@ G_DEFINE_TYPE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING) enum { PROP_0, - PROP_MANUAL, - PROP_AUTOIP, + PROP_METHOD, PROP_DNS, PROP_DNS_SEARCH, PROP_ADDRESSES, @@ -29,11 +30,34 @@ verify (NMSetting *setting, GSList *all_settings) { 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) { g_warning ("address is not provided"); 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; @@ -51,6 +75,8 @@ finalize (GObject *object) { NMSettingIP4Config *self = NM_SETTING_IP4_CONFIG (object); + g_free (self->method); + if (self->dns) g_array_free (self->dns, TRUE); @@ -125,11 +151,9 @@ set_property (GObject *object, guint prop_id, NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object); switch (prop_id) { - case PROP_MANUAL: - setting->manual = g_value_get_boolean (value); - break; - case PROP_AUTOIP: - setting->autoip = g_value_get_boolean (value); + case PROP_METHOD: + g_free (setting->method); + setting->method = g_value_dup_string (value); break; case PROP_DNS: if (setting->dns) @@ -157,11 +181,8 @@ get_property (GObject *object, guint prop_id, NMSettingIP4Config *setting = NM_SETTING_IP4_CONFIG (object); switch (prop_id) { - case PROP_MANUAL: - g_value_set_boolean (value, setting->manual); - break; - case PROP_AUTOIP: - g_value_set_boolean (value, setting->autoip); + case PROP_METHOD: + g_value_set_string (value, setting->method); break; case PROP_DNS: g_value_set_boxed (value, setting->dns); @@ -192,20 +213,12 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class) /* Properties */ g_object_class_install_property - (object_class, PROP_MANUAL, - g_param_spec_boolean (NM_SETTING_IP4_CONFIG_MANUAL, - "Manual", - "Do not use DHCP", - FALSE, - 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)); + (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)); g_object_class_install_property (object_class, PROP_DNS, diff --git a/libnm-util/nm-setting-ip4-config.h b/libnm-util/nm-setting-ip4-config.h index d1d5b027c..c7e00a00d 100644 --- a/libnm-util/nm-setting-ip4-config.h +++ b/libnm-util/nm-setting-ip4-config.h @@ -16,12 +16,15 @@ G_BEGIN_DECLS #define NM_SETTING_IP4_CONFIG_SETTING_NAME "ipv4" -#define NM_SETTING_IP4_CONFIG_MANUAL "manual" -#define NM_SETTING_IP4_CONFIG_AUTOIP "autoip" +#define NM_SETTING_IP4_CONFIG_METHOD "method" #define NM_SETTING_IP4_CONFIG_DNS "dns" #define NM_SETTING_IP4_CONFIG_DNS_SEARCH "dns-search" #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 { guint32 address; guint32 netmask; @@ -31,8 +34,7 @@ typedef struct { typedef struct { NMSetting parent; - gboolean manual; - gboolean autoip; + char *method; GArray *dns; /* array of guint32 */ GSList *dns_search; /* list of strings */ GSList *addresses; /* array of NMSettingIP4Address */ diff --git a/src/nm-device-802-11-wireless.c b/src/nm-device-802-11-wireless.c index 7d0b35d8d..148f200b5 100644 --- a/src/nm-device-802-11-wireless.c +++ b/src/nm-device-802-11-wireless.c @@ -2685,69 +2685,19 @@ out: 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 real_act_stage4_get_ip4_config (NMDevice *dev, 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; + 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_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 */ - klass = NM_DEVICE_802_11_WIRELESS_GET_CLASS (self); - parent_class = NM_DEVICE_CLASS (g_type_class_peek_parent (klass)); - ret = parent_class->act_stage4_get_ip4_config (dev, config); - } + /* Chain up to parent */ + parent_class = NM_DEVICE_CLASS (nm_device_802_11_wireless_parent_class); + ret = parent_class->act_stage4_get_ip4_config (dev, config); if ((ret == NM_ACT_STAGE_RETURN_SUCCESS) && *config) { 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_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_ip_config_timeout = real_act_stage4_ip_config_timeout; parent_class->deactivate = real_deactivate; diff --git a/src/nm-device.c b/src/nm-device.c index a1b2a5464..adfa103a1 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -531,11 +531,11 @@ real_act_stage3_ip_config_start (NMDevice *self) NM_TYPE_SETTING_IP4_CONFIG); /* If we did not receive IP4 configuration information, default to DHCP */ - if (!setting || setting->manual == FALSE) { - /* Begin a DHCP transaction on the interface */ + if (!setting || !strcmp (setting->method, NM_SETTING_IP4_CONFIG_METHOD_DHCP)) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); gboolean success; + /* Begin a DHCP transaction on the interface */ nm_device_set_use_dhcp (self, TRUE); /* 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); - if (get_autoip (self, &ip)) - { + // FIXME: make our autoip implementation not suck; use avahi-autoip + if (get_autoip (self, &ip)) { #define LINKLOCAL_BCAST 0xa9feffff config = nm_ip4_config_new (); @@ -673,15 +673,13 @@ merge_ip4_config (NMIP4Config *ip4_config, NMSettingIP4Config *setting) if (setting->addresses) { /* 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_netmask (ip4_config, addr->netmask); + nm_ip4_config_set_address (ip4_config, addr->address); + nm_ip4_config_set_netmask (ip4_config, addr->netmask); - if (addr->gateway) - nm_ip4_config_set_gateway (ip4_config, addr->gateway); - } + if (addr->gateway) + nm_ip4_config_set_gateway (ip4_config, addr->gateway); } } @@ -691,30 +689,37 @@ real_act_stage4_get_ip4_config (NMDevice *self, { NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; 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); 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, 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); - ret = NM_ACT_STAGE_RETURN_SUCCESS; } else { - /* Make sure device is up even if config fails */ - if (!nm_device_bring_up (self, FALSE)) - ret = NM_ACT_STAGE_RETURN_FAILURE; + g_assert (s_ip4); + + 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; } @@ -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); - /* Wired network, no DHCP reply. Let's get an IP via Zeroconf. */ - nm_info ("No DHCP reply received. Automatically obtaining IP via Zeroconf."); - *config = nm_device_new_ip4_autoip_config (self); - - return NM_ACT_STAGE_RETURN_SUCCESS; + /* DHCP failed; connection must fail */ + return NM_ACT_STAGE_RETURN_FAILURE; } diff --git a/system-settings/plugins/ifcfg-fedora/parser.c b/system-settings/plugins/ifcfg-fedora/parser.c index 7bfd7174e..44a89417d 100644 --- a/system-settings/plugins/ifcfg-fedora/parser.c +++ b/system-settings/plugins/ifcfg-fedora/parser.c @@ -302,12 +302,17 @@ make_ip4_setting (shvarFile *ifcfg, GError **error) NMSettingIP4Config *s_ip4 = NULL; char *value = NULL; NMSettingIP4Address tmp = { 0, 0, 0 }; - gboolean manual = TRUE; + char *method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; char *dir; value = svGetValue (ifcfg, "BOOTPROTO"); - if (value && (!strcmp (value, "bootp") || !strcmp (value, "dhcp"))) - manual = FALSE; + if (value && (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp"))) + 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"); if (value) { @@ -348,8 +353,9 @@ make_ip4_setting (shvarFile *ifcfg, GError **error) g_free (value); } +done: 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) { NMSettingIP4Address *addr; addr = g_new0 (NMSettingIP4Address, 1); @@ -357,14 +363,17 @@ make_ip4_setting (shvarFile *ifcfg, GError **error) s_ip4->addresses = g_slist_append (s_ip4->addresses, addr); } - dir = g_path_get_dirname (ifcfg->fileName); - if (dir) { - read_profile_resolv_conf (dir, s_ip4); - g_free (dir); - } else { - g_set_error (error, ifcfg_plugin_error_quark (), 0, - "Not enough memory to parse resolv.conf"); - goto error; + /* No DNS for autoip */ + if (g_ascii_strcasecmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTOIP)) { + dir = g_path_get_dirname (ifcfg->fileName); + if (dir) { + read_profile_resolv_conf (dir, s_ip4); + g_free (dir); + } else { + g_set_error (error, ifcfg_plugin_error_quark (), 0, + "Not enough memory to parse resolv.conf"); + goto error; + } } return NM_SETTING (s_ip4); diff --git a/system-settings/plugins/ifcfg-suse/parser.c b/system-settings/plugins/ifcfg-suse/parser.c index cefb73fb3..bca60305f 100644 --- a/system-settings/plugins/ifcfg-suse/parser.c +++ b/system-settings/plugins/ifcfg-suse/parser.c @@ -155,14 +155,14 @@ make_ip4_setting (shvarFile *ifcfg, GError **error) NMSettingIP4Config *s_ip4 = NULL; char *value = NULL; NMSettingIP4Address tmp = { 0, 0, 0 }; - gboolean manual = TRUE; + char *method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; value = svGetValue (ifcfg, "BOOTPROTO"); if (!value) return NULL; if (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp")) { - manual = FALSE; + method = NM_SETTING_IP4_CONFIG_METHOD_DHCP; return NULL; } @@ -212,7 +212,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error) } 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) { NMSettingIP4Address *addr; addr = g_new0 (NMSettingIP4Address, 1);