[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Switch to udhcpc in netcfg



Hi

Attached is a first try to support udhcpc in netcfg.

I opted for dropping support for pump and the ISC dhcp client, though
that could be reverted if really wanted.

I don't know how DHCP_OPTION_LEN for udhcpc can be found, so I did not
touch it for now.

Note that I did not test my patch yet except for compilation errors.
Please do test it and come back to me, any feedback appreciated!

Cheers

Luk
Index: dhcp.c
===================================================================
--- dhcp.c	(revision 58745)
+++ dhcp.c	(working copy)
@@ -23,10 +23,8 @@
 
 #define DHCP_OPTION_LEN 1236 /* pump 0.8.24 defines a max option size of 57,
                                 dhcp 2.0pl5 uses 1222, dhcp3 3.0.6 uses 1236 */
-#define DHCLIENT_REQUEST_DEFAULTS \
-  "subnet-mask, broadcast-address, time-offset, routers, domain-name, \
-   domain-name-servers, host-name"
-#define DHCLIENT_REQUEST_EXTRAS "ntp-servers"
+const char* dhclient_request_defaults[] = {"subnet-mask", "broadcast-address", "time-offset", "routers", "domain-name", "domain-name-servers", "host-name"};
+const char* dhclient_request_extras[] = {"ntp-servers"};
 
 static int dhcp_exit_status = 1;
 static pid_t dhcp_pid = -1;
@@ -60,12 +58,6 @@
         }
         fclose(fp);
     }
-    
-#if 0
-    if ((fp = file_open(RESOLV_FILE, "a"))) {
-        fclose(fp);
-    }
-#endif
 }
 
 /* Returns 1 if no default route is available */
@@ -107,74 +99,46 @@
 
 
 /* 
- * This function will start whichever DHCP client is available
+ * This function will start the default DHCP client
  * using the provided DHCP hostname, if supplied
  *
  * The client's PID is stored in dhcp_pid.
  */
 int start_dhcp_client (struct debconfclient *client, char* dhostname)
 {
-    FILE *dc = NULL;
-    enum { DHCLIENT, DHCLIENT3, PUMP } dhcp_client;
+    /* start filling after "udhcpc", "-i", interface, "--vendorclass=d-i" */
+    int j = 4;
+    int i;
+    /* 4 (see above) + 2*7 (defaults) + 2*1 (extras) + 2 (hostname) + 1 (NULL)*/
+    const char* arguments[23];
     
-    if (access("/var/lib/dhcp3", F_OK) == 0)
-        dhcp_client = DHCLIENT3;
-    else if (access("/sbin/dhclient", F_OK) == 0)
-        dhcp_client = DHCLIENT;
-    else if (access("/sbin/pump", F_OK) == 0)
-        dhcp_client = PUMP;
-    else {
-        debconf_input(client, "critical", "netcfg/no_dhcp_client");
-        debconf_go(client);
-        exit(1);
-    }
-    
     if ((dhcp_pid = fork()) == 0) { /* child */
         /* disassociate from debconf */
         fclose(client->out);
         
         /* get dhcp lease */
-        switch (dhcp_client) {
-        case PUMP:
-            if (dhostname)
-                execlp("pump", "pump", "-i", interface, "-h", dhostname, NULL);
-            else
-                execlp("pump", "pump", "-i", interface, NULL);
             
-            break;
-            
-        case DHCLIENT:
-            /* First, set up dhclient.conf */
-            
-            if ((dc = file_open(DHCLIENT_CONF, "w"))) {
-                fprintf(dc, "send dhcp-class-identifier \"d-i\";\n" );
-                fprintf(dc, "request " DHCLIENT_REQUEST_DEFAULTS", " \
-                                       DHCLIENT_REQUEST_EXTRAS";\n" );
-                if (dhostname) {
-                    fprintf(dc, "send host-name \"%s\";\n", dhostname);
-                }
-                fclose(dc);
-            }
-            
-            execlp("dhclient", "dhclient", "-e", interface, NULL);
-            break;
-            
-        case DHCLIENT3:
-            /* Different place.. */
-            
-            if ((dc = file_open(DHCLIENT3_CONF, "w"))) {
-                fprintf(dc, "send vendor-class-identifier \"d-i\";\n" );
-                fprintf(dc, "request " DHCLIENT_REQUEST_DEFAULTS", " \
-                                       DHCLIENT_REQUEST_EXTRAS";\n" );
-                if (dhostname) {
-                    fprintf(dc, "send host-name \"%s\";\n", dhostname);
-                }
-                fclose(dc);
-            }
-            
-            execlp("dhclient", "dhclient", "-1", interface, NULL);
-            break;
+        arguments[0] = "udhcpc";
+        arguments[1] = "-i";
+        arguments[2] = interface;
+        arguments[3] = "--vendorclass=d-i";
+        for(i=0; i < sizeof(dhclient_request_defaults)/sizeof(char*); i++) {
+            arguments[j++] = "-O";
+            arguments[j++] = dhclient_request_defaults[i];
         }
+        for(i=0; i < sizeof(dhclient_request_extras)/sizeof(char*); i++) {
+            arguments[j++] = "-O";
+            arguments[j++] = dhclient_request_extras[i];
+        }
+
+        if (dhostname) {
+            arguments[j++] = "-H";
+            arguments[j++] = dhostname;
+        }
+	while(j < sizeof(arguments)/sizeof(char*)) {
+            arguments[j++] = NULL;
+        }
+        execvp("udhcpc", arguments);
         if (errno != 0)
             di_error("Could not exec dhcp client: %s", strerror(errno));
         
Index: debian/control
===================================================================
--- debian/control	(revision 58745)
+++ debian/control	(working copy)
@@ -2,14 +2,14 @@
 Section: debian-installer
 Priority: optional
 Maintainer: Debian Install System Team <debian-boot@lists.debian.org>
-Uploaders: Joey Hess <joeyh@debian.org>, Colin Watson <cjwatson@debian.org>
+Uploaders: Joey Hess <joeyh@debian.org>, Colin Watson <cjwatson@debian.org>, Luk Claes <luk@debian.org>
 Build-Depends: debhelper (>= 5.0.22), dpkg-dev (>= 1.9.0), libdebconfclient0-dev (>= 0.46), libdebian-installer4-dev (>= 0.41), po-debconf (>= 0.5.0), libiw-dev (>= 27+28pre9-1)
 Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/netcfg
 
 Package: netcfg
 XC-Package-Type: udeb
 Architecture: i386 sparc alpha m68k arm armel armeb powerpc mips mipsel hppa ia64 amd64 lpia
-Depends: ${shlibs:Depends}, ${misc:Depends}, dhcp3-client-udeb (>= 3.1.0-2), ethernet-card-detection
+Depends: ${shlibs:Depends}, ${misc:Depends}, busybox-udeb (>= 1:1.13.3-1), ethernet-card-detection
 Provides: configured-network
 XB-Installer-Menu-Item: 1800
 Description: Configure the network

Reply to: