[ previous ] [ next ] [ threads ]
 
 From:  Pauline Middelink <middelink at polyware dot nl>
 To:  m0n0wall at lists dot m0n0 dot ch
 Subject:  [Patch]: hostname for dhcp on WAN
 Date:  Sun, 21 Dec 2003 23:58:27 +0100
LS,

Problem: some major dutch cable provider requires one to sent the given
hostname with each dhcp request, otherwise they will not supply you
with an IP adress. The problem is that the current monowall has no
provisions for this.

Attached you will find a smallish patch which will allow you to sent
the configured hostname with the dhcp request.

Description of the patch. It replaces the /etc/dhclient.conf file with
a link to /var/etc/dhclient.conf. Furthermore /etc/inc/interfaces.php
gained an extra function to create /etc/dhclient.conf which is called
when the dhcp mode is used on the WAN interface.

Hope this patch can make it in the next incarnation of monowall, so we
can stop patching them :)

PS. We use m0n0wall on the Lex Systems Light BookPC. Since monowall now
    automaticly detects on which drive the config stands, it now runs
    _unpatched_ in this little machine!
    (http://www.polyware.nl/hard-lex-light.html)

    Met vriendelijke groet,
        Pauline Middelink
-- 
GPG Key fingerprint = 2D5B 87A7 DDA6 0378 5DEA  BD3B 9A50 B416 E2D0 C3C2
For more details look at my website http://www.polyware.nl/~middelink
diff -ur image/etc/inc/interfaces.inc image.new/etc/inc/interfaces.inc
--- image/etc/inc/interfaces.inc	Sat Dec 13 15:36:58 2003
+++ image.new/etc/inc/interfaces.inc	Sun Dec 21 22:50:38 2003
@@ -248,6 +248,10 @@
         /* wait for processes to die */
         sleep(2);
         
+        /* remove dhclient.conf, if it exists */
+        if (file_exists("{$g['varetc_path']}/dhclient.conf")) {
+            unlink("{$g['varetc_path']}/dhclient.conf");
+        }
         /* remove mpd.conf, if it exists */
         if (file_exists("{$g['varetc_path']}/mpd.conf")) {
             unlink("{$g['varetc_path']}/mpd.conf");
@@ -273,8 +277,7 @@
     switch ($wancfg['ipaddr']) {
     
         case 'dhcp':            
-            /* fire up dhclient - don't wait for the lease (-nw) */
-            mwexec("/sbin/dhclient -nw " . escapeshellarg($wancfg['if']));
+	    interfaces_wan_dhcp_configure();
             break;
             
         case 'pppoe':
@@ -326,6 +329,46 @@
         echo "done\n";
     
     return 0;
+}
+
+function interfaces_wan_dhcp_configure() {
+    global $config, $g;
+    
+    /* determine the hostname */
+    $syscfg = $config['system'];
+    $hostname = $syscfg['hostname'];
+
+    /* determine the wan interface */
+    $wancfg = $config['interfaces']['wan'];
+    $intf = $wancfg['if'];
+
+    /* generate dhclient.conf */
+    $fd = fopen("{$g['varetc_path']}/dhclient.conf", "w");
+    if (!$fd) {
+        printf("Error: cannot open dhclient.conf in interfaces_wan_dhcp_configure().\n");
+        return 1;
+    }
+ 
+    $dhclientconf = <<<EOD
+# $FreeBSD: src/etc/dhclient.conf,v 1.2.2.1 2001/12/14 11:44:31 rwatson Exp $
+#
+#	This file is required by the ISC DHCP client.
+#	See ``man 5 dhclient.conf'' for details.
+#
+#	In most cases an empty file is sufficient for most people as the
+#	defaults are usually fine.
+#
+send dhcp-client-identifier "$hostname";
+interface "$intf" {
+	send host-name "$hostname";
+}
+EOD;
+
+    fwrite($fd, $dhclientconf);
+    fclose($fd);
+    
+    /* fire up dhclient - don't wait for the lease (-nw) */
+    mwexec("/sbin/dhclient -nw " . escapeshellarg($wancfg['if']));
 }
 
 function interfaces_wan_pppoe_configure() {