Get a link-local IP when wired and DHCP fails
Heya, Here's a (small) patch I wrote after a discussion with Dan. The use-cases are: - Plug my laptop and desktop together, via a crossed-cable or some cheap hub, they both get a nice little IP address, and they can talk. - Create an ad-hoc non-encrypted network on my desktop, join in on my laptop, can't get a DHCP address (not running that kind of server on my desktop, too lazy), gets a nice little IP address, and they can talk. The only case left is when we have an ad-hoc encrypted network, as it's not really possible to know whether the DHCP request failure is due to no-DHCP server, or wrong WEP key. I remember Apple's solution to a similar problem (detecting whether a WEP key is accepted) being pretty ugly and Airport AP specific, but I don't quite remember the details. Any comments? --- Bastien Nocera [EMAIL PROTECTED] Index: NetworkManagerDevice.c === RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerDevice.c,v retrieving revision 1.145 diff -u -p -r1.145 NetworkManagerDevice.c --- NetworkManagerDevice.c 30 Jun 2005 14:28:52 - 1.145 +++ NetworkManagerDevice.c 30 Jun 2005 18:55:42 - @@ -2751,9 +2751,20 @@ static gboolean nm_device_activate_stage if (ap nm_ap_get_user_created (ap)) ip4_config = nm_device_new_ip4_autoip_config (dev); - else if (nm_device_get_use_dhcp (dev)) + else if (nm_device_get_use_dhcp (dev)) { ip4_config = nm_dhcp_manager_get_ip4_config (data-dhcp_manager, req); - else + + /* Couldn't get a DHCP address, so we'll try link-local + * for wired, and wireless non-encrypted networks, as if + * we have encryption on wireless, it could be a wrong + * WEP key causing the failure + */ + if (ip4_config == NULL nm_device_is_wired (dev)) { + ip4_config = nm_device_new_ip4_autoip_config (dev); + } else if (ip4_config == NULL nm_device_is_wireless (dev) == FALSE nm_ap_get_encrypted (ap) == FALSE) { + ip4_config = nm_device_new_ip4_autoip_config (dev); + } + } else ip4_config = nm_system_device_new_ip4_system_config (dev); if (nm_device_activation_should_cancel (dev)) ___ NetworkManager-list mailing list NetworkManager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Get a link-local IP when wired and DHCP fails
On Thu, 2005-06-30 at 16:19 -0400, Dan Williams wrote: On Thu, 2005-06-30 at 20:14 +0100, Bastien Nocera wrote: + } else if (ip4_config == NULL nm_device_is_wireless (dev) == FALSE nm_ap_get_encrypted (ap) == FALSE) { You probably want this to be nm_device_is_wireless (dev) == TRUE right? Damn, three lines and I manage to screw it up (that's a yes). --- Bastien Nocera [EMAIL PROTECTED] ___ NetworkManager-list mailing list NetworkManager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Get a link-local IP when wired and DHCP fails
On Thu, 2005-06-30 at 20:14 +0100, Bastien Nocera wrote: Any comments? When I don't have a DHCP server, I get failure on Stage 3 (start of DHCP transaction) and never make it to Stage 4. So, this isn't working for me. Debugging ... And, attached patch fixes the typo that Dan pointed out and adds an nm_info for verbosity. Robert Love Index: src/NetworkManagerDevice.c === RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerDevice.c,v retrieving revision 1.145 diff -u -u -r1.145 NetworkManagerDevice.c --- src/NetworkManagerDevice.c 30 Jun 2005 14:28:52 - 1.145 +++ src/NetworkManagerDevice.c 30 Jun 2005 21:02:38 - @@ -2752,7 +2752,23 @@ if (ap nm_ap_get_user_created (ap)) ip4_config = nm_device_new_ip4_autoip_config (dev); else if (nm_device_get_use_dhcp (dev)) + { + /* + * Could not get a DHCP address, so we'll try link-local for + * for wired, and wireless non-encrypted networks, because + * if we have encryption on wireless, it could be a wrong + * WEP key causing the failure. + */ ip4_config = nm_dhcp_manager_get_ip4_config (data-dhcp_manager, req); + if (ip4_config == NULL) + { + if (nm_device_is_wired (dev) || (nm_device_is_wireless (dev) == TRUE nm_ap_get_encrypted (ap) == FALSE)) + { +nm_info (No DHCP reply received. Automatically obtaining IP.); +ip4_config = nm_device_new_ip4_autoip_config (dev); + } + } + } else ip4_config = nm_system_device_new_ip4_system_config (dev); ___ NetworkManager-list mailing list NetworkManager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Get a link-local IP when wired and DHCP fails
On Thu, 2005-06-30 at 20:14 +0100, Bastien Nocera wrote: + } else if (ip4_config == NULL nm_device_is_wireless (dev) == FALSE nm_ap_get_encrypted (ap) == FALSE) { You probably want this to be nm_device_is_wireless (dev) == TRUE right? Dan ___ NetworkManager-list mailing list NetworkManager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list