Source-Changes-HG archive

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

[src/trunk]: src/distrib/utils/sysinst dhclient support added



details:   https://anonhg.NetBSD.org/src/rev/1444462ef884
branches:  trunk
changeset: 488124:1444462ef884
user:      cyber <cyber%NetBSD.org@localhost>
date:      Sun Jun 18 23:50:02 2000 +0000

description:
dhclient support added
only invoked if dhclient is present on install image

diffstat:

 distrib/utils/sysinst/defs.h      |    4 +-
 distrib/utils/sysinst/menus.mi.en |    7 +-
 distrib/utils/sysinst/menus.mi.fr |    6 +-
 distrib/utils/sysinst/msg.mi.en   |    6 +-
 distrib/utils/sysinst/msg.mi.fr   |    5 +-
 distrib/utils/sysinst/net.c       |  163 ++++++++++++++++++++++++++++++++++++-
 6 files changed, 179 insertions(+), 12 deletions(-)

diffs (truncated from 327 to 300 lines):

diff -r 86a243c4bbf1 -r 1444462ef884 distrib/utils/sysinst/defs.h
--- a/distrib/utils/sysinst/defs.h      Sun Jun 18 23:03:45 2000 +0000
+++ b/distrib/utils/sysinst/defs.h      Sun Jun 18 23:50:02 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.52 2000/03/24 21:56:04 thorpej Exp $        */
+/*     $NetBSD: defs.h,v 1.53 2000/06/18 23:50:02 cyber Exp $  */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -91,6 +91,8 @@
 
 /* variables */
 
+EXTERN char m_continue[STRSIZE] INIT("");
+
 EXTERN char rel[SSTRSIZE] INIT(REL);
 EXTERN char machine[SSTRSIZE] INIT(MACH);
 
diff -r 86a243c4bbf1 -r 1444462ef884 distrib/utils/sysinst/menus.mi.en
--- a/distrib/utils/sysinst/menus.mi.en Sun Jun 18 23:03:45 2000 +0000
+++ b/distrib/utils/sysinst/menus.mi.en Sun Jun 18 23:50:02 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: menus.mi.en,v 1.39 2000/03/14 22:42:49 fvdl Exp $      */
+/*     $NetBSD: menus.mi.en,v 1.40 2000/06/18 23:50:03 cyber Exp $     */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -390,3 +390,8 @@
 menu ip6autoconf, title "Perform IPv6 autoconfiguration?";
        option "Yes", exit, action  {yesno = 1;};
        option "No",  exit, action  {yesno = 0;};
+
+menu dhcpautoconf, title "Perform DHCP autoconfiguration?";
+       option "Yes", exit, action  {yesno = 1;};
+       option "No",  exit, action  {yesno = 0;};
+
diff -r 86a243c4bbf1 -r 1444462ef884 distrib/utils/sysinst/menus.mi.fr
--- a/distrib/utils/sysinst/menus.mi.fr Sun Jun 18 23:03:45 2000 +0000
+++ b/distrib/utils/sysinst/menus.mi.fr Sun Jun 18 23:50:02 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: menus.mi.fr,v 1.27 2000/03/14 22:42:49 fvdl Exp $      */
+/*     $NetBSD: menus.mi.fr,v 1.28 2000/06/18 23:50:03 cyber Exp $     */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -390,3 +390,7 @@
 menu ip6autoconf, title "Faire la configuration automatique IPv6 ?";
        option "Yes", exit, action  {yesno = 1;};
        option "No",  exit, action  {yesno = 0;};
+
+menu dhcpautoconf, title "Exécutez la configuration automatique de DHCP?";
+        option "Yes", exit, action  {yesno = 1;};
+        option "No",  exit, action  {yesno = 0;};
diff -r 86a243c4bbf1 -r 1444462ef884 distrib/utils/sysinst/msg.mi.en
--- a/distrib/utils/sysinst/msg.mi.en   Sun Jun 18 23:03:45 2000 +0000
+++ b/distrib/utils/sysinst/msg.mi.en   Sun Jun 18 23:50:02 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg.mi.en,v 1.61 2000/06/17 17:40:32 hubertf Exp $     */
+/*     $NetBSD: msg.mi.en,v 1.62 2000/06/18 23:50:03 cyber Exp $       */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -744,3 +744,7 @@
 {The only suitable partition that was found for NetBSD installation is of
 the old NetBSD/386BSD/FreeBSD partition type. Do you want to change the type
 of this partition to the new NetBSD-only partition type?}
+
+message continue
+{Continue?}
+
diff -r 86a243c4bbf1 -r 1444462ef884 distrib/utils/sysinst/msg.mi.fr
--- a/distrib/utils/sysinst/msg.mi.fr   Sun Jun 18 23:03:45 2000 +0000
+++ b/distrib/utils/sysinst/msg.mi.fr   Sun Jun 18 23:50:02 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg.mi.fr,v 1.33 2000/03/14 22:42:49 fvdl Exp $        */
+/*     $NetBSD: msg.mi.fr,v 1.34 2000/06/18 23:50:04 cyber Exp $       */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -770,3 +770,6 @@
 {La seule partition disponible pour installer NetBSD est de l'ancien type
 NetBSD/386BSD/FreeBSD. Voulez-vous le changer pour le nouveau type
 dédié à NetBSD ?}
+
+message continue
+{Continuez?}
diff -r 86a243c4bbf1 -r 1444462ef884 distrib/utils/sysinst/net.c
--- a/distrib/utils/sysinst/net.c       Sun Jun 18 23:03:45 2000 +0000
+++ b/distrib/utils/sysinst/net.c       Sun Jun 18 23:50:02 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.c,v 1.57 2000/01/05 01:50:45 itojun Exp $  */
+/*     $NetBSD: net.c,v 1.58 2000/06/18 23:50:04 cyber Exp $   */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -71,6 +71,12 @@
 
 static void write_etc_hosts(FILE *f);
 
+#define DHCLIENT_EX "/sbin/dhclient"
+#include <signal.h>
+static int config_dhcp __P((char *));
+static void get_command_out __P((char *, char *, char *));
+static void get_dhcp_value __P(( char *, char *));
+
 #ifdef INET6
 static int is_v6kernel __P((void));
 static void init_v6kernel __P((int));
@@ -245,6 +251,8 @@
        int textsize;
        char *t;
        char hostname[MAXHOSTNAMELEN + 1];
+       int max_len;
+       char *dot;
 
        /* First look to see if the selected interface is already configured. */
        textsize = collect(T_OUTPUT, &textbuf,
@@ -300,7 +308,22 @@
        /* Check host (and domain?) name */
        if (gethostname(hostname, sizeof(hostname)) == 0) {
                hostname[sizeof(hostname) - 1] = '\0';
-               strncpy(net_host, hostname, sizeof(net_host));
+               /* check for a . */
+               dot = strchr(hostname, '.');
+               if ( dot == NULL ) {
+                       /* if not found its just a host, punt on domain */
+                       strncpy(net_host, hostname, sizeof(net_host));
+               } else {
+                       /* split hostname into host/domain parts */
+                       max_len = dot - hostname;
+                       max_len = (sizeof(net_host)<max_len)?sizeof(net_host):max_len;
+                       *dot = '\0';
+                       dot++;
+                       strncpy(net_host, hostname, max_len);
+                       max_len = strlen(dot);
+                       max_len = (sizeof(net_host)<max_len)?sizeof(net_host):max_len;
+                       strncpy(net_domain, dot, max_len);
+               }
        }
 }
 
@@ -367,7 +390,7 @@
 {      char *tp;
        char defname[255];
        int  octet0;
-       int  pass, needmedia, v6config;
+       int  pass, needmedia, v6config, dhcp_config;
 
        FILE *f;
        time_t now;
@@ -404,17 +427,34 @@
        /* Remove that space we added. */
        net_dev[strlen(net_dev) - 1] = 0;
 
+again:
+
 #ifdef INET6
        v6config = 1;
 #else
        v6config = 0;
 #endif
 
-again:
        /* Preload any defaults we can find */
+       dhcp_config = config_dhcp(net_dev);
        get_ifinterface_info();
        pass = strlen(net_mask) == 0 ? 0 : 1;
        needmedia = strlen(net_media) == 0 ? 0 : 1;
+       if(dhcp_config) {
+               /* disable ipv6 */
+               v6config=0;
+               /* run route show and extract data */
+               get_command_out(net_defroute,"/sbin/route show 2>/dev/null","default");
+               /* pull nameserver info out of /etc/resolv.conf */
+               get_command_out(net_namesvr,"cat /etc/resolv.conf 2> /dev/null","nameserver");
+
+               /* pull domainname out of leases file */
+               get_dhcp_value(net_domain,"domain-name");
+               /* pull hostname out of leases file */
+               get_dhcp_value(net_host,"hostname");
+
+               goto confirm;  /* CEBXXX goto's suck */
+       }
 
        /* domain and host */
        msg_display(MSG_netinfo);
@@ -427,7 +467,6 @@
                               STRSIZE);
 
        /* Manually configure IPv4 */
-       /* XXX todo: dhcp */
        msg_prompt_add(MSG_net_ip, net_ip, net_ip, STRSIZE);
        octet0 = atoi(net_ip);
        if (!pass) {
@@ -444,9 +483,9 @@
 
 #ifdef INET6
        /* IPv6 autoconfiguration */
-       if (!is_v6kernel())
+       if (!is_v6kernel() )
                v6config = 0;
-       else {
+       else if(v6config) {  /* dhcp config will disable this */
                process_menu(MENU_ip6autoconf);
                v6config = yesno ? 1 : 0;
        }
@@ -459,6 +498,7 @@
        }
 #endif
 
+confirm:
        /* confirm the setting */
        msg_display(MSG_netok, net_domain, net_host,
                     *net_ip == '\0' ? "<none>" : net_ip,
@@ -866,3 +906,112 @@
                }
        }
 }
+
+
+int
+config_dhcp (inter)
+char * inter;
+{
+       int dhcpautoconf;
+       int result;
+       char *textbuf;
+       int pid;
+
+       /* check if dhclient is running, if so, kill it */
+       result = collect(T_FILE, &textbuf, "/tmp/dhclient.pid");
+       if (result >=0) {
+               pid = atoi(textbuf);
+               if (pid > 0) {
+                       kill(pid,15);
+                       sleep(1);
+                       kill(pid,9);
+               }
+       }
+
+       result = run_prog(0, 0, NULL, "test %s %s", "-f", DHCLIENT_EX);
+       if (result!=0) {
+               return 0;
+       }
+       process_menu(MENU_dhcpautoconf);
+       if (yesno) {
+               /* spawn off dhclient and wait for parent to exit */
+               dhcpautoconf = run_prog(0, 1, NULL, "%s -pf /tmp/dhclient.pid -lf /tmp/dhclient.leases %s", DHCLIENT_EX,inter);
+               return dhcpautoconf?0:1;
+       }
+       return 0;
+}
+
+void
+get_command_out (targ, command, search)
+char *targ;
+char *command;
+char *search;
+{
+       int textsize;
+       char *textbuf;
+       char *t;
+
+       textsize = collect(T_OUTPUT, &textbuf, command);
+       if (textsize < 0) {
+               if (logging)
+                       (void)fprintf(log, "Aborting: Could not run %s.\n", command);
+               (void)fprintf(stderr, "Could not run ifconfig.");
+               exit(1);
+       }
+       if (textsize >= 0) {
+               (void)strtok(textbuf, " \t\n"); /* ignore interface name */
+               while ((t = strtok(NULL, " \t\n")) != NULL) {
+                       if (strcmp(t, search) == 0) {
+                               t = strtok(NULL, " \t\n");
+                               if (strcmp(t, "0.0.0.0") != 0) {
+                                       strcpy(targ, t);
+                               }
+                       } 
+               }
+       }
+       return;
+}
+
+
+void
+get_dhcp_value(targ, line)
+char *targ;
+char *line;
+{
+       int textsize;
+       char *textbuf;
+       char *t;
+       char *walk;
+
+       textsize = collect(T_FILE, &textbuf, "/tmp/dhclient.leases");
+       if (textsize < 0) {
+               if (logging)
+                       (void)fprintf(log, "Could not open file /tmp/dhclient.leases.\n");
+               (void)fprintf(stderr, "Could not open /tmp/dhclient.leases\n");



Home | Main Index | Thread Index | Old Index