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 */
-       GPid    aipd_pid;
-       guint   aipd_watch;
-       guint   aipd_timeout;
+       GPid     aipd_pid;
+       guint    aipd_watch;
+       guint    aipd_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
[email protected]
https://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to