From b172519045e5ea4825f85fca81de8395e92600c1 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 23 Apr 2010 15:52:09 -0700 Subject: core: fail connections if IP configuration expires Need to mark these connections invalid too, otherwise they'll just be retried over and over and over. Ran into a problem with DHCPv6 where lease expiration (cached lease really) was *negative*, which caused the lease to expire immediately after being bound. Previously the policy wouldn't mark connections like this as invalid because they hadn't failed during activation. NetworkManager: (eth0): carrier now ON (device state 2) NetworkManager: (eth0): device state change: 2 -> 3 (reason 40) NetworkManager: Activation (eth0) starting connection 'dhcp6 test' NetworkManager: (eth0): device state change: 3 -> 4 (reason 0) NetworkManager: Activation (eth0) Stage 1 of 5 (Device Prepare) scheduled... NetworkManager: Activation (eth0) Stage 1 of 5 (Device Prepare) started... NetworkManager: Activation (eth0) Stage 2 of 5 (Device Configure) scheduled... NetworkManager: Activation (eth0) Stage 1 of 5 (Device Prepare) complete. NetworkManager: Activation (eth0) Stage 2 of 5 (Device Configure) starting... NetworkManager: (eth0): device state change: 4 -> 5 (reason 0) NetworkManager: Activation (eth0) Stage 2 of 5 (Device Configure) successful. NetworkManager: Activation (eth0) Stage 3 of 5 (IP Configure Start) scheduled. NetworkManager: Activation (eth0) Stage 2 of 5 (Device Configure) complete. NetworkManager: Activation (eth0) Stage 3 of 5 (IP Configure Start) started... NetworkManager: (eth0): device state change: 5 -> 7 (reason 0) NetworkManager: Activation (eth0) Beginning DHCPv6 transaction (timeout in 45 seconds) NetworkManager: dhclient started with pid 6639 NetworkManager: Activation (eth0) Stage 3 of 5 (IP Configure Start) complete. Internet Systems Consortium DHCP Client 4.1.1 Copyright 2004-2010 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ NetworkManager: (eth0): DHCPv6 state changed nbi -> preinit6 Bound to *:546 Listening on Socket/eth0 Sending on Socket/eth0 PRC: Confirming active lease (INIT-REBOOT). XMT: Forming Confirm, 0 ms elapsed. XMT: X-- IA_NA 5a:47:1f:71 XMT: | X-- Confirm Address 3ffe:501:ffff::4 XMT: V IA_NA appended. XMT: Confirm on eth0, interval 1090ms. send_packet6: Cannot assign requested address dhc6: sendpacket6() sent -1 of 80 bytes XMT: Forming Confirm, 1090 ms elapsed. XMT: X-- IA_NA 5a:47:1f:71 XMT: | X-- Confirm Address 3ffe:501:ffff::4 XMT: V IA_NA appended. XMT: Confirm on eth0, interval 2120ms. send_packet6: Cannot assign requested address dhc6: sendpacket6() sent -1 of 80 bytes XMT: Forming Confirm, 3210 ms elapsed. XMT: X-- IA_NA 5a:47:1f:71 XMT: | X-- Confirm Address 3ffe:501:ffff::4 XMT: V IA_NA appended. XMT: Confirm on eth0, interval 4320ms. XMT: Forming Confirm, 7530 ms elapsed. XMT: X-- IA_NA 5a:47:1f:71 XMT: | X-- Confirm Address 3ffe:501:ffff::4 XMT: V IA_NA appended. XMT: Confirm on eth0, interval 2470ms. Max retransmission duration exceeded. PRC: Bound to lease 00:01:00:01:12:e1:92:d9:00:14:22:fd:06:e7. PRC: Rebind event scheduled in -8604281 seconds, to run for 110 seconds. PRC: Depreference scheduled in -8604241 seconds. PRC: Expiration scheduled in -8604171 seconds. PRC: Rebinding lease on eth0. PRC: Depreference scheduled in -8604241 seconds. PRC: Expiration scheduled in -8604171 seconds. NetworkManager: (eth0): DHCPv6 state changed preinit6 -> bound6 NetworkManager: Activation (eth0) Stage 4 of 5 (IP6 Configure Get) scheduled... NetworkManager: Activation (eth0) Stage 4 of 5 (IP6 Configure Get) started... NetworkManager: address 3ffe:501:ffff::4 NetworkManager: prefix 64 NetworkManager: nameserver '2000::2' NetworkManager: domain search 'ibm.com.' NetworkManager: Activation (eth0) Stage 5 of 5 (IP Configure Commit) scheduled... NetworkManager: Activation (eth0) Stage 4 of 5 (IP6 Configure Get) complete. NetworkManager: Activation (eth0) Stage 5 of 5 (IP Configure Commit) started... PRC: Address 3ffe:501:ffff::4 depreferred. PRC: Expiration scheduled in -8604171 seconds. PRC: Address 3ffe:501:ffff::4 expired. PRC: Bound lease is devoid of active addresses. Re-initializing. PRC: Soliciting for leases (INIT). XMT: Forming Solicit, 0 ms elapsed. XMT: X-- IA_NA 5a:47:1f:71 XMT: | X-- Request renew in +3600 XMT: | X-- Request rebind in +5400 XMT: Solicit on eth0, interval 1040ms. Stopping nscd: [ OK ] Starting nscd: [ OK ] NetworkManager: (eth0): device state change: 7 -> 8 (reason 0) NetworkManager: Activation (eth0) successful, device activated. NetworkManager: Activation (eth0) Stage 5 of 5 (IP Configure Commit) complete. NetworkManager: (eth0): DHCPv6 state changed bound6 -> depref6 NetworkManager: (eth0): DHCPv6 state changed depref6 -> expire6 --- src/nm-device.c | 16 ++++++++++++++++ src/nm-policy.c | 21 +++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/nm-device.c b/src/nm-device.c index ba88c6b0e3..26b00474dc 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -1312,6 +1312,22 @@ dhcp_state_changed (NMDHCPClient *client, else if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED); break; + case DHC_STOP: + case DHC_STOP6: + case DHC_EXPIRE: + case DHC_EXPIRE6: + if (dev_state == NM_DEVICE_STATE_ACTIVATED) { + if (ipv6) + nm_dhcp6_config_reset (priv->dhcp6_config); + else + nm_dhcp4_config_reset (priv->dhcp4_config); + + /* dhclient quit and can't get/renew a lease; so kill the connection */ + nm_device_state_changed (device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED); + } + break; default: break; } diff --git a/src/nm-policy.c b/src/nm-policy.c index 4fccaf4d11..2591de27b6 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -585,10 +585,23 @@ device_state_changed (NMDevice *device, /* Mark the connection invalid if it failed during activation so that * it doesn't get automatically chosen over and over and over again. */ - if (connection && IS_ACTIVATING_STATE (old_state)) { - g_object_set_data (G_OBJECT (connection), INVALID_TAG, GUINT_TO_POINTER (TRUE)); - nm_log_info (LOGD_DEVICE, "Marking connection '%s' invalid.", get_connection_id (connection)); - nm_connection_clear_secrets (connection); + if (connection) { + gboolean fail = FALSE; + + if (IS_ACTIVATING_STATE (old_state)) { + nm_log_info (LOGD_DEVICE, "Marking connection '%s' invalid.", get_connection_id (connection)); + fail = TRUE; + } else if ( (old_state == NM_DEVICE_STATE_ACTIVATED) + && (reason == NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED)) { + nm_log_info (LOGD_DEVICE, "Marking connection '%s' invalid because IP configuration expired.", + get_connection_id (connection)); + fail = TRUE; + } + + if (fail) { + g_object_set_data (G_OBJECT (connection), INVALID_TAG, GUINT_TO_POINTER (TRUE)); + nm_connection_clear_secrets (connection); + } } schedule_activate_check (policy, device, 3); break; -- cgit v1.2.3