bug-hurd
[Top][All Lists]
Advanced

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

dhcp client (pfinet patch)


From: Marco Gerards
Subject: dhcp client (pfinet patch)
Date: 21 Jun 2003 04:36:24 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Hi,

Here is some quick and fast hack for pfinet to make dhcp work. I've
added an option "-d" or "--dhcp" to pfinet to make it prepare for
dhcp.

When using this it sets the ip to 1.1.1.1, netmask to 255.0.0.0 and
adds a route like is done for GNU/Linux to be able to send broadcasts
for dhcp.

Perhaps a better option would be adding a ioctl for editing the router
table like linux has. For this the interfaces must be updated, etc.

If some Hurd hacker wants me to rewrite the code to ioctl support,
please ask and I'll do that. Any other hints are also usefull.

Please notice while reading the code that I haven't cleaned it up
totally and there is just one device supported when using DHCP. I will
work on this if the maintainer(s) agree about the right solution (the
current one or ioctls).

Thanks,
Marco

(ps. a seperate dhcpclient is still required, this code is just to
make it possible for the dhcpclient to work).

diff -upr pfinet_old/Makefile pfinet/Makefile
--- pfinet_old/Makefile 2002-09-17 22:42:06.000000000 +0200
+++ pfinet/Makefile     2003-06-21 02:18:32.000000000 +0200
@@ -37,6 +37,7 @@ ipv4-srcs     := af_inet.c                                    
              \
                   fib_frontend.c                                             \
                   fib_hash.c                                                 \
                   fib_semantics.c                                            \
+                  rtnetlink.c                                                \
                   icmp.c                                                     \
                   igmp.c                                                     \
                   ip_forward.c                                               \
@@ -79,7 +80,7 @@ FROBBEDLINUXHEADERS = autoconf.h config.
        ip.h ip_fw.h ipx.h kernel.h major.h malloc.h mm.h net.h netdevice.h \
        notifier.h param.h route.h sched.h skbuff.h socket.h sockios.h stat.h \
        string.h tcp.h termios.h time.h timer.h types.h udp.h un.h wait.h
-ASMHEADERS=bitops.h segment.h system.h
+ASMHEADERS=bitops.h segment.h system.h string.h
 
 HURDLIBS=trivfs fshelp threads ports ihash shouldbeinlibc iohelp
 
diff -upr pfinet_old/config.h pfinet/config.h
--- pfinet_old/config.h 2000-02-04 07:32:38.000000000 +0100
+++ pfinet/config.h     2003-06-21 01:22:31.000000000 +0200
@@ -34,3 +34,5 @@
 #define CONFIG_SKB_LARGE 1
 
 #define CONFIG_IP_NOSIOCRT 1   /* How convenient.  */
+#undef CONFIG_IP_NOSIOCRT
+
diff -upr pfinet_old/linux-src/net/core/rtnetlink.c 
pfinet/linux-src/net/core/rtnetlink.c
--- pfinet_old/linux-src/net/core/rtnetlink.c   2000-02-04 04:21:18.000000000 
+0100
+++ pfinet/linux-src/net/core/rtnetlink.c       2003-06-21 02:43:19.000000000 
+0200
@@ -38,7 +38,7 @@
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
-#include <asm/string.h>
+//#include <asm/string.h>
 
 #include <linux/inet.h>
 #include <linux/netdevice.h>
diff -upr pfinet_old/linux-src/net/ipv4/fib_frontend.c 
pfinet/linux-src/net/ipv4/fib_frontend.c
--- pfinet_old/linux-src/net/ipv4/fib_frontend.c        2000-02-04 
04:21:18.000000000 +0100
+++ pfinet/linux-src/net/ipv4/fib_frontend.c    2003-06-21 02:01:34.000000000 
+0200
@@ -45,6 +45,13 @@
 #include <net/arp.h>
 #include <net/ip_fib.h>
 
+#undef SIOCDELRT
+#undef SIOCADDRT
+
+/* WARNING: SIODELRT is never used but should be defined.  */
+#define        SIOCDELRT       0x890C
+#define        SIOCADDRT       0x890B
+
 #define FFprint(a...) printk(KERN_DEBUG a)
 
 #ifndef CONFIG_IP_MULTIPLE_TABLES
diff -upr pfinet_old/linux-src/net/ipv4/fib_semantics.c 
pfinet/linux-src/net/ipv4/fib_semantics.c
--- pfinet_old/linux-src/net/ipv4/fib_semantics.c       2000-02-04 
04:21:18.000000000 +0100
+++ pfinet/linux-src/net/ipv4/fib_semantics.c   2003-06-21 02:01:43.000000000 
+0200
@@ -43,6 +43,13 @@
 #include <net/sock.h>
 #include <net/ip_fib.h>
 
+#undef SIOCDELRT
+#undef SIOCADDRT
+
+/* WARNING: SIODELRT is never used but should be defined.  */
+#define        SIOCDELRT       0x890C
+#define        SIOCADDRT       0x890B
+
 #define FSprintk(a...)
 
 static struct fib_info         *fib_info_list;
diff -upr pfinet_old/options.c pfinet/options.c
--- pfinet_old/options.c        2001-07-18 18:56:57.000000000 +0200
+++ pfinet/options.c    2003-06-21 05:48:21.000000000 +0200
@@ -31,6 +31,8 @@
 
 #include "pfinet.h"
 
+
+
 #include <linux/netdevice.h>
 #include <linux/inetdevice.h>
 #include <linux/ip.h>
@@ -60,6 +62,7 @@ static const struct argp_option options[
   {"netmask",   'm', "MASK",    0, "Set the netmask"},
   {"peer",      'p', "ADDRESS", 0, "Set the peer address"},
   {"gateway",   'g', "ADDRESS", 0, "Set the default gateway"},
+  {"dhcp",     'd', 0        , 0, "Prepare pfinet for dhcp"},
   {"shutdown",  's', 0,         0, "Shut it down"},
   {0}
 };
@@ -108,9 +111,12 @@ parse_hook_add_interface (struct parse_h
   h->curint->netmask = INADDR_NONE;
   h->curint->peer = INADDR_NONE;
   h->curint->gateway = INADDR_NONE;
+
   return 0;
 }
 
+static int dhcp_option;
+
 static error_t
 parse_opt (int opt, char *arg, struct argp_state *state)
 {
@@ -189,6 +195,8 @@ parse_opt (int opt, char *arg, struct ar
                  "%s: Illegal or undefined network address", arg);
        }
       break;
+    case 'd':
+      dhcp_option = 1; break;
     case 'm':
       h->curint->netmask = ADDR (arg, "netmask"); break;
     case 'p':
@@ -213,6 +221,16 @@ parse_opt (int opt, char *arg, struct ar
 
     case ARGP_KEY_SUCCESS:
       in = h->curint;
+
+      /* Configure the interface to default values.  */
+      if (dhcp_option)
+       {
+         h->curint->netmask = ADDR ("255.0.0.0", "netmask");
+         h->curint->address = ADDR ("1.1.1.1", "address");
+         h->curint->gateway = INADDR_NONE;
+         h->curint->peer = INADDR_NONE;
+       }
+
       if (! in->device)
        /* No specific interface specified; is that ok?  */
        if (in->address != INADDR_NONE || in->netmask != INADDR_NONE
@@ -315,6 +333,56 @@ parse_opt (int opt, char *arg, struct ar
          }
       }
 
+      /*  Setup the routing required for DHCP. */
+      if (dhcp_option)
+       {
+         struct kern_rta rta;
+         struct
+         {
+           struct nlmsghdr nlh;
+           struct rtmsg rtm;
+         } req;
+         struct fib_table *tb;
+         struct rtentry route;
+         struct sockaddr_in *genmask;
+         struct sockaddr_in *dst;
+
+         bzero (&req.rtm, sizeof (req.rtm));
+         bzero (&rta, sizeof (rta));
+         bzero (&route, sizeof (struct rtentry));
+
+         genmask = (struct sockaddr_in *) &route.rt_genmask;
+         dst = (struct sockaddr_in *) &route.rt_dst;
+
+         genmask->sin_family = AF_INET;
+         dst->sin_family = AF_INET;
+         route.rt_flags = RTF_UP;
+         route.rt_dev = "eth0";
+
+         err = fib_convert_rtentry (0x890B/*SIOCADDRT*/, &req.nlh, &req.rtm,
+                                    &rta, &route);
+
+         if (err)
+           {
+             __mutex_unlock (&global_lock);
+             FAIL (err, 17, 0, "cannot convert route");
+           }
+         
+         tb = fib_new_table (req.rtm.rtm_table);
+         /* XXX: err = - ENOBUFS ??? */
+
+         if (tb)
+           err = tb->tb_insert (tb, &req.rtm, &rta, &req.nlh, NULL);
+         else
+           err = ENOBUFS;
+         
+         if (err)
+           {
+             __mutex_unlock (&global_lock);
+             FAIL (err, 17, 0, "cannot add route");
+           }
+       }
+
       __mutex_unlock (&global_lock);
 
       /* Fall through to free hook.  */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]