[PATCH]: wait_for_interface poll on driver interface initialization

Kel Modderman kel at otaku42.de
Sun Jan 13 17:47:35 EST 2008


On Monday 14 January 2008 02:57:40 Jouni Malinen wrote:
> On Sun, Jan 13, 2008 at 07:41:21PM +1000, Kel Modderman wrote:
> > The attached patch attempts to fix the wait_for_interface option by
> > reorganizing wpa_supplicant_driver_init() and
> > wpa_supplicant_init_iface2() so that polling is done before the driver
> > interface is prepared for work.
> >
> > Currently, the driver interface is prepared before wait_for_interface is
> > considered, resulting in broken -w command line option, and ignoring any
> > driver parameters.
>
> Hmm.. I must have broken this at some point when moving initialization
> calls around to fetch MAC address early enough for other code modules..
>
> > I'd be just as happy to see the wait_for_interface stuff completely
> > removed, as any distro should have some hotplug agent or similar support
> > in their networking toolset. Therefore, I see no need for this option to
> > exist at all, but while it does exist and does not work, I'll have a go
> > at fixing it ;-)
>
> I think I would prefer to just get rid of it completely.. It's
> unnecessary extra complexity that is obviously easy to break (as seen
> here..). I've never used it myself (apart from the minimal testing I've
> done) and I would agree that there are better ways of handling this.
> Anyway, similar functionality can be added by using a separate program
> to do the waiting if someone really needs it and does not have hotplug
> (etc.)..

Here is preliminary patch to remove wait_for_interface. It should apply to
hostap git with a bit of fuzz, it was based on the 0.6.2 release.

Signed-off-by: Kel Modderman <Kel at otaku42.de>
---
--- a/wpa_supplicant/main.c
+++ b/wpa_supplicant/main.c
@@ -147,7 +147,7 @@
 	wpa_supplicant_fd_workaround();
 
 	for (;;) {
-		c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNp:P:qtuvwW");
+		c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNp:P:qtuvW");
 		if (c < 0)
 			break;
 		switch (c) {
@@ -220,9 +220,6 @@
 			printf("%s\n", wpa_supplicant_version);
 			exitcode = 0;
 			goto out;
-		case 'w':
-			params.wait_for_interface++;
-			break;
 		case 'W':
 			params.wait_for_monitor++;
 			break;
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -1471,36 +1471,26 @@
 /**
  * wpa_supplicant_driver_init - Initialize driver interface parameters
  * @wpa_s: Pointer to wpa_supplicant data
- * @wait_for_interface: 0 = do not wait for the interface (reports a failure if
- * the interface is not present), 1 = wait until the interface is available
- * Returns: 0 on success, -1 on failure
  *
  * This function is called to initialize driver interface parameters.
  * wpa_drv_init() must have been called before this function to initialize the
  * driver interface.
  */
-int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s,
-			       int wait_for_interface)
+int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s)
 {
 	static int interface_count = 0;
 
-	for (;;) {
-		if (wpa_s->driver->send_eapol) {
-			const u8 *addr = wpa_drv_get_mac_addr(wpa_s);
-			if (addr)
-				os_memcpy(wpa_s->own_addr, addr, ETH_ALEN);
-			break;
-		}
+	if (wpa_s->driver->send_eapol) {
+		const u8 *addr = wpa_drv_get_mac_addr(wpa_s);
+		if (addr)
+			os_memcpy(wpa_s->own_addr, addr, ETH_ALEN);
+	} else {
 		wpa_s->l2 = l2_packet_init(wpa_s->ifname,
 					   wpa_drv_get_mac_addr(wpa_s),
 					   ETH_P_EAPOL,
 					   wpa_supplicant_rx_eapol, wpa_s, 0);
-		if (wpa_s->l2)
-			break;
-		else if (!wait_for_interface)
+		if (wpa_s->l2 == NULL)
 			return -1;
-		wpa_printf(MSG_DEBUG, "Waiting for interface..");
-		os_sleep(5, 0);
 	}
 
 	if (wpa_s->l2 && l2_packet_get_own_addr(wpa_s->l2, wpa_s->own_addr)) {
@@ -1668,8 +1658,7 @@
 }
 
 
-static int wpa_supplicant_init_iface2(struct wpa_supplicant *wpa_s,
-				      int wait_for_interface)
+static int wpa_supplicant_init_iface2(struct wpa_supplicant *wpa_s)
 {
 	const char *ifname;
 	struct wpa_driver_capa capa;
@@ -1739,9 +1728,9 @@
 		return -1;
 	}
 
-	if (wpa_supplicant_driver_init(wpa_s, wait_for_interface) < 0) {
+	if (wpa_supplicant_driver_init(wpa_s) < 0)
 		return -1;
-	}
+
 	wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr);
 
 	wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
@@ -1825,8 +1814,7 @@
 		return NULL;
 
 	if (wpa_supplicant_init_iface(wpa_s, iface) ||
-	    wpa_supplicant_init_iface2(wpa_s,
-				       global->params.wait_for_interface)) {
+	    wpa_supplicant_init_iface2(wpa_s)) {
 		wpa_printf(MSG_DEBUG, "Failed to add interface %s",
 			   iface->ifname);
 		wpa_supplicant_deinit_iface(wpa_s);
@@ -1940,7 +1928,6 @@
 	if (global == NULL)
 		return NULL;
 	global->params.daemonize = params->daemonize;
-	global->params.wait_for_interface = params->wait_for_interface;
 	global->params.wait_for_monitor = params->wait_for_monitor;
 	global->params.dbus_ctrl_interface = params->dbus_ctrl_interface;
 	if (params->pid_file)
@@ -1976,8 +1963,8 @@
 		}
 	}
 
-	if (global->params.wait_for_interface && global->params.daemonize &&
-	    wpa_supplicant_daemon(global->params.pid_file)) {
+	if (global->params.daemonize &&
+	    wpa_supplicant_daemon(global->params.pid_file) < 0) {
 		wpa_supplicant_deinit(global);
 		return NULL;
 	}
@@ -1999,8 +1986,8 @@
 {
 	struct wpa_supplicant *wpa_s;
 
-	if (!global->params.wait_for_interface && global->params.daemonize &&
-	    wpa_supplicant_daemon(global->params.pid_file))
+	if (global->params.daemonize &&
+	    wpa_supplicant_daemon(global->params.pid_file) < 0)
 		return -1;
 
 	if (global->params.wait_for_monitor) {
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -96,17 +96,6 @@
 	int daemonize;
 
 	/**
-	 * wait_for_interface - Wait for the network interface to appear
-	 *
-	 * If set, %wpa_supplicant will wait until all the configured network
-	 * interfaces are available before starting processing. Please note
-	 * that in many cases, a better alternative would be to start
-	 * %wpa_supplicant without network interfaces and add the interfaces
-	 * dynamically whenever they become available.
-	 */
-	int wait_for_interface;
-
-	/**
 	 * wait_for_monitor - Wait for a monitor program before starting
 	 */
 	int wait_for_monitor;
@@ -349,8 +338,7 @@
 int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s);
 
 const char * wpa_supplicant_state_txt(int state);
-int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s,
-			       int wait_for_interface);
+int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s);
 int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
 			      struct wpa_scan_res *bss,
 			      struct wpa_ssid *ssid,
--- a/wpa_supplicant/doc/docbook/wpa_supplicant.sgml
+++ b/wpa_supplicant/doc/docbook/wpa_supplicant.sgml
@@ -12,7 +12,7 @@
   <refsynopsisdiv>
     <cmdsynopsis>
       <command>wpa_supplicant</command>
-      <arg>-BddfhKLqqtuvwW</arg>
+      <arg>-BddfhKLqqtuvW</arg>
       <arg>-i<replaceable>ifname</replaceable></arg>
       <arg>-c<replaceable>config file</replaceable></arg>
       <arg>-D<replaceable>driver</replaceable></arg>
@@ -67,10 +67,7 @@
     <para>Before wpa_supplicant can do its work, the network interface
     must be available.  That means that the physical device must be
     present and enabled, and the driver for the device must have be
-    loaded.  Note, however, that the '-w' option of the wpa_supplicant
-    daemon instructs the daemon to continue running and to wait for
-    the interface to become available.  Without the '-w' option, the
-    daemon will exit immediately if the device is not already
+    loaded. The daemon will exit immediately if the device is not already
     available.</para>
 
     <para>After <command>wpa_supplicant</command> has configured the
@@ -454,15 +451,6 @@
       </varlistentry>
 
       <varlistentry>
-	<term>-w</term>
-	<listitem>
-	  <para>Wait for interface to be added, if needed.  Normally,
-	  <command>wpa_supplicant</command> will exit if the interface
-	  is not there yet.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
 	<term>-W</term>
 	<listitem>
 	  <para>Wait for a control interface monitor before starting.</para>
@@ -485,11 +473,10 @@
     started with:</para>
 
 <blockquote><programlisting>
-wpa_supplicant -Bw -c/etc/wpa_supplicant.conf -iwlan0
+wpa_supplicant -B -c/etc/wpa_supplicant.conf -iwlan0
 </programlisting></blockquote>
 
-    <para>This makes the process fork into background and wait for the wlan0
-    interface if it is not available at startup time.</para>
+    <para>This makes the process fork into background.</para>
 
     <para>The easiest way to debug problems, and to get debug log for
     bug reports, is to start <command>wpa_supplicant</command> on
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -862,7 +862,7 @@
 			break;
 		wpa_s->interface_removed = 0;
 		wpa_printf(MSG_DEBUG, "Configured interface was added.");
-		if (wpa_supplicant_driver_init(wpa_s, 1) < 0) {
+		if (wpa_supplicant_driver_init(wpa_s) < 0) {
 			wpa_printf(MSG_INFO, "Failed to initialize the driver "
 				   "after interface was added.");
 		}
---


More information about the HostAP mailing list