[PATCH] RFC: fall back to IPv4-LL in case of DHCP failure

2012-07-18 Thread Jan Luebbe
In some cases, it is useful to have a static configuration which succeeds
to configure a network interface regardless of whether a DHCP server
is available or not. One such use-case is an embedded system with
factory default settings, which would fall back to IPv4-LL when
connected directly to the notebook of a field engineer.

With this patch, when DHCP reports a timeout, the connection attempt
is restart with phase 3 of autoipd-based IPv4 Link-Local configuration.
For now this behaviour is hard-coded, but I'd make it configurable
if this approach is acceptable.

For configuration, a new IPv4 method could be added (either a new
'Automatic with fall back' or 'DHCP only', making enabled fall back
the default in 'Automatic'). Alternatively an option could be added
to the IPv4 configuration (i.e. 'll-fall-back=true').

Best regards,
Jan Luebbe

---
 src/nm-device.c |   28 
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/nm-device.c b/src/nm-device.c
index 6eaa94d..886d5bc 100644
--- a/src/nm-device.c
+++ b/src/nm-device.c
@@ -204,9 +204,10 @@ typedef struct {
DBusGProxyCall*fw_call;
 
/* avahi-autoipd stuff */
-   GPidaipd_pid;
-   guint   aipd_watch;
-   guint   aipd_timeout;
+   GPid aipd_pid;
+   guintaipd_watch;
+   guintaipd_timeout;
+   gboolean aipd_failed;
 
/* IP6 configuration info */
NMIP6Config *  ip6_config;
@@ -1262,6 +1263,8 @@ aipd_cleanup (NMDevice *self)
}
 
aipd_timeout_remove (self);
+
+   priv-aipd_failed = FALSE;
 }
 
 static NMIP4Config *
@@ -1331,7 +1334,8 @@ nm_device_handle_autoip4_event (NMDevice *self,
if (s_ip4)
method = nm_setting_ip4_config_get_method (s_ip4);
 
-   if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) != 0)
+   if (   g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) != 0
+g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) != 0)
return;
 
iface = nm_device_get_iface (self);
@@ -1423,6 +1427,7 @@ aipd_timeout_cb (gpointer user_data)
nm_log_info (LOGD_AUTOIP4, (%s): avahi-autoipd timed out., 
nm_device_get_iface (self));
priv-aipd_timeout = 0;
aipd_cleanup (self);
+   priv-aipd_failed = TRUE;
 
if (priv-ip4_state == IP_CONF)
nm_device_activate_schedule_ip4_config_timeout (self);
@@ -2499,6 +2504,21 @@ nm_device_activate_schedule_stage3_ip_config_start 
(NMDevice *self)
 static NMActStageReturn
 real_act_stage4_ip4_config_timeout (NMDevice *self, NMDeviceStateReason 
*reason)
 {
+   NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
+   NMConnection *connection;
+   NMSettingIP4Config *s_ip4;
+   const char *method;
+
+   connection = nm_device_get_connection (self);
+   g_assert (connection);
+
+   s_ip4 = nm_connection_get_setting_ip4_config (connection);
+   g_assert (s_ip4);
+
+   method = nm_setting_ip4_config_get_method (s_ip4);
+   if (   strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0
+!priv-aipd_failed)
+   return aipd_start (self, reason);
if (nm_device_ip_config_should_fail (self, FALSE)) {
*reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE;
return NM_ACT_STAGE_RETURN_FAILURE;
-- 
1.7.10

___
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list


[RFC PATCH] WIP: support ap-mode with wpa_supplicant

2012-05-31 Thread Jan Luebbe
A new value for NM80211Mode is introduced (NM_802_11_MODE_AP) and the
new mode is passed to wpa_supplicant analogous to adhoc-mode.

Signed-off-by: Jan Luebbe j...@pengutronix.de
---
Hi!

Would something like the patch below be acceptable?

Currently the frequency is still hard-coded, which I would change if
the general approach is fine.

Regards,
Jan

 include/NetworkManager.h   |3 +-
 libnm-util/nm-setting-wireless.c   |6 ++--
 libnm-util/nm-setting-wireless.h   |7 +
 src/nm-device-wifi.c   |5 
 src/nm-wifi-ap.c   |4 ++-
 src/supplicant-manager/nm-supplicant-config.c  |   30 +---
 .../nm-supplicant-settings-verify.c|2 +-
 7 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/include/NetworkManager.h b/include/NetworkManager.h
index 0aa31ae..f1b484f 100644
--- a/include/NetworkManager.h
+++ b/include/NetworkManager.h
@@ -233,7 +233,8 @@ typedef enum {
 typedef enum {
NM_802_11_MODE_UNKNOWN = 0,
NM_802_11_MODE_ADHOC,
-   NM_802_11_MODE_INFRA
+   NM_802_11_MODE_INFRA,
+   NM_802_11_MODE_AP
 } NM80211Mode;
 
 /**
diff --git a/libnm-util/nm-setting-wireless.c b/libnm-util/nm-setting-wireless.c
index 3188251..ff8584b 100644
--- a/libnm-util/nm-setting-wireless.c
+++ b/libnm-util/nm-setting-wireless.c
@@ -568,7 +568,7 @@ static gboolean
 verify (NMSetting *setting, GSList *all_settings, GError **error)
 {
NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE 
(setting);
-   const char *valid_modes[] = { NM_SETTING_WIRELESS_MODE_INFRA, 
NM_SETTING_WIRELESS_MODE_ADHOC, NULL };
+   const char *valid_modes[] = { NM_SETTING_WIRELESS_MODE_INFRA, 
NM_SETTING_WIRELESS_MODE_ADHOC, NM_SETTING_WIRELESS_MODE_AP, NULL };
const char *valid_bands[] = { a, bg, NULL };
GSList *iter;
 
@@ -866,8 +866,8 @@ nm_setting_wireless_class_init (NMSettingWirelessClass 
*setting_class)
(object_class, PROP_MODE,
 g_param_spec_string (NM_SETTING_WIRELESS_MODE,
  Mode,
- WiFi network mode; one of 
'infrastructure' or 
- 'adhoc'.  If blank, 
infrastructure is assumed.,
+ WiFi network mode; one of 
'infrastructure', 
+ 'adhoc' or 'ap'.  If blank, 
infrastructure is assumed.,
  NULL,
  G_PARAM_READWRITE | 
NM_SETTING_PARAM_SERIALIZE));
 
diff --git a/libnm-util/nm-setting-wireless.h b/libnm-util/nm-setting-wireless.h
index 3182f41..99cbe41 100644
--- a/libnm-util/nm-setting-wireless.h
+++ b/libnm-util/nm-setting-wireless.h
@@ -85,6 +85,13 @@ GQuark nm_setting_wireless_error_quark (void);
 #define NM_SETTING_WIRELESS_MODE_ADHOC  adhoc
 
 /**
+ * NM_SETTING_WIRELESS_MODE_ADHOC:
+ *
+ * Indicates AP/master mode where this device is the access point.
+ */
+#define NM_SETTING_WIRELESS_MODE_AP ap
+
+/**
  * NM_SETTING_WIRELESS_MODE_INFRA
  *
  * Indicates infrastructure mode where an access point is expected to be 
present
diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c
index ed964a5..a52d895 100644
--- a/src/nm-device-wifi.c
+++ b/src/nm-device-wifi.c
@@ -696,6 +696,11 @@ periodic_update (NMDeviceWifi *self)
NMAccessPoint *new_ap;
guint32 new_rate, percent;
 
+   /* In AP mode we currently have nothing to do. */
+   if (priv-current_ap  (nm_ap_get_mode (priv-current_ap) == 
NM_802_11_MODE_AP)) {
+   return;
+   }
+
/* In IBSS mode, most newer firmware/drivers do BSS coalescing where
 * multiple IBSS stations using the same SSID will eventually switch to
 * using the same BSSID to avoid network segmentation.  When this 
happens,
diff --git a/src/nm-wifi-ap.c b/src/nm-wifi-ap.c
index 92a99b6..009ca5c 100644
--- a/src/nm-wifi-ap.c
+++ b/src/nm-wifi-ap.c
@@ -652,6 +652,8 @@ nm_ap_new_fake_from_connection (NMConnection *connection)
nm_ap_set_mode (ap, NM_802_11_MODE_INFRA);
else if (!strcmp (mode, adhoc))
nm_ap_set_mode (ap, NM_802_11_MODE_ADHOC);
+   else if (!strcmp (mode, ap))
+   nm_ap_set_mode (ap, NM_802_11_MODE_AP);
else
goto error;
} else {
@@ -967,7 +969,7 @@ void nm_ap_set_mode (NMAccessPoint *ap, const NM80211Mode 
mode)
 
g_return_if_fail (NM_IS_AP (ap));
 
-   if (mode == NM_802_11_MODE_ADHOC || mode == NM_802_11_MODE_INFRA) {
+   if (mode == NM_802_11_MODE_ADHOC || mode == NM_802_11_MODE_INFRA || 
mode == NM_802_11_MODE_AP) {
priv = NM_AP_GET_PRIVATE (ap