Source-Changes-HG archive

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

[src/trunk]: src/distrib/utils/sysinst do not skip IPv6 configuration menu on...



details:   https://anonhg.NetBSD.org/src/rev/c9d43dd7acef
branches:  trunk
changeset: 495214:c9d43dd7acef
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon Jul 24 10:52:28 2000 +0000

description:
do not skip IPv6 configuration menu on dhcp configuration.

do not save address/netmask/default router, if we got them from dhcp.
(we shouldn't do that).  if we keep any of dhcp config into /etc, we shoul
update rc.conf to run dhcp again.

diffstat:

 distrib/utils/sysinst/defs.h |    9 +-
 distrib/utils/sysinst/net.c  |  246 +++++++++++++++++++++++++-----------------
 2 files changed, 151 insertions(+), 104 deletions(-)

diffs (truncated from 388 to 300 lines):

diff -r 40a42357f86e -r c9d43dd7acef distrib/utils/sysinst/defs.h
--- a/distrib/utils/sysinst/defs.h      Mon Jul 24 10:10:05 2000 +0000
+++ b/distrib/utils/sysinst/defs.h      Mon Jul 24 10:52:28 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.53 2000/06/18 23:50:02 cyber Exp $  */
+/*     $NetBSD: defs.h,v 1.54 2000/07/24 10:52:28 itojun Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -219,7 +219,7 @@
 EXTERN char command[STRSIZE];
 
 /* Access to network information */
-EXTERN char net_devices [STRSIZE] INIT("");
+EXTERN char net_devices[STRSIZE] INIT("");
 EXTERN char net_dev[STRSIZE] INIT("");
 EXTERN char net_domain[STRSIZE] INIT("");
 EXTERN char net_host[STRSIZE] INIT("");
@@ -228,6 +228,11 @@
 EXTERN char net_namesvr[STRSIZE] INIT("");
 EXTERN char net_defroute[STRSIZE] INIT("");
 EXTERN char net_media[STRSIZE] INIT("");
+EXTERN int net_dhcpconf INIT(0);
+#define DHCPCONF_IPADDR                0x01
+#define DHCPCONF_NAMESVR       0x02
+#define DHCPCONF_HOST          0x04
+#define DHCPCONF_DOMAIN                0x08
 #ifdef INET6
 EXTERN char net_ip6[STRSIZE] INIT("");
 EXTERN char net_namesvr6[STRSIZE] INIT("");
diff -r 40a42357f86e -r c9d43dd7acef distrib/utils/sysinst/net.c
--- a/distrib/utils/sysinst/net.c       Mon Jul 24 10:10:05 2000 +0000
+++ b/distrib/utils/sysinst/net.c       Mon Jul 24 10:52:28 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.c,v 1.60 2000/07/24 06:05:51 itojun Exp $  */
+/*     $NetBSD: net.c,v 1.61 2000/07/24 10:52:28 itojun Exp $  */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -47,9 +47,10 @@
 #include <sys/param.h>
 #ifdef INET6
 #include <sys/sysctl.h>
+#endif
 #include <sys/socket.h>
 #include <netinet/in.h>
-#endif
+#include <arpa/inet.h>
 #include "defs.h"
 #include "md.h"
 #include "msg_defs.h"
@@ -74,7 +75,7 @@
 #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_command_out __P((char *, int, char *, char *));
 static void get_dhcp_value __P(( char *, char *));
 
 #ifdef INET6
@@ -390,7 +391,7 @@
 {      char *tp;
        char defname[255];
        int  octet0;
-       int  pass, needmedia, v6config, dhcp_config;
+       int  pass, v6config, dhcp_config;
 
        FILE *f;
        time_t now;
@@ -436,48 +437,63 @@
 #endif
 
        /* 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) {
-               /* 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);
+
+       /* ethernet medium */
+       if (strlen(net_media) == 0)
+               msg_prompt_add(MSG_net_media, net_media, net_media, STRSIZE);
+
+       /* try a dhcp configuration */
+       dhcp_config = config_dhcp(net_dev);
+       if (dhcp_config) {
+               net_dhcpconf |= DHCPCONF_IPADDR;
+
+               /* run route show and extract data */
+               get_command_out(net_defroute, AF_INET,
+                   "/sbin/route -n show -inet 2>/dev/null", "default");
+
+               /* pull nameserver info out of /etc/resolv.conf */
+               get_command_out(net_namesvr, AF_INET,
+                   "cat /etc/resolv.conf 2> /dev/null", "nameserver");
+               if (strlen(net_namesvr) != 0)
+                       net_dhcpconf |= DHCPCONF_NAMESVR;
+
+               /* pull domainname out of leases file */
+               get_dhcp_value(net_domain, "domain-name");
+               if (strlen(net_domain) != 0)
+                       net_dhcpconf |= DHCPCONF_DOMAIN;
+
+               /* pull hostname out of leases file */
+               get_dhcp_value(net_host, "hostname");
+               if (strlen(net_host) != 0)
+                       net_dhcpconf |= DHCPCONF_HOST;
+       }
+
        msg_prompt_add(MSG_net_domain, net_domain, net_domain, STRSIZE);
        msg_prompt_add(MSG_net_host, net_host, net_host, STRSIZE);
 
-       /* ethernet medium */
-       if (needmedia)
-               msg_prompt_add(MSG_net_media, net_media, net_media,
-                              STRSIZE);
-
-       /* Manually configure IPv4 */
-       msg_prompt_add(MSG_net_ip, net_ip, net_ip, STRSIZE);
-       octet0 = atoi(net_ip);
-       if (!pass) {
-               if (0 <= octet0 && octet0 <= 127)
-                       strcpy(net_mask, "0xff000000");
-               else if (128 <= octet0 && octet0 <= 191)
-                       strcpy(net_mask, "0xffff0000");
-               else if (192 <= octet0 && octet0 <= 223)
-                       strcpy(net_mask, "0xffffff00");
+       if (!dhcp_config) {
+               /* Manually configure IPv4 */
+               msg_prompt_add(MSG_net_ip, net_ip, net_ip, STRSIZE);
+               octet0 = atoi(net_ip);
+               if (!pass) {
+                       if (0 <= octet0 && octet0 <= 127)
+                               strcpy(net_mask, "0xff000000");
+                       else if (128 <= octet0 && octet0 <= 191)
+                               strcpy(net_mask, "0xffff0000");
+                       else if (192 <= octet0 && octet0 <= 223)
+                               strcpy(net_mask, "0xffffff00");
+               }
+               msg_prompt_add(MSG_net_mask, net_mask, net_mask, STRSIZE);
+               msg_prompt_add(MSG_net_defroute, net_defroute, net_defroute,
+                   STRSIZE);
+               msg_prompt_add(MSG_net_namesrv, net_namesvr, net_namesvr,
+                   STRSIZE);
        }
-       msg_prompt_add(MSG_net_mask, net_mask, net_mask, STRSIZE);
-       msg_prompt_add(MSG_net_defroute, net_defroute, net_defroute, STRSIZE);
-       msg_prompt_add(MSG_net_namesrv, net_namesvr, net_namesvr, STRSIZE);
 
 #ifdef INET6
        /* IPv6 autoconfiguration */
@@ -496,7 +512,6 @@
        }
 #endif
 
-confirm:
        /* confirm the setting */
        msg_display(MSG_netok, net_domain, net_host,
                     *net_ip == '\0' ? "<none>" : net_ip,
@@ -840,75 +855,96 @@
        char ifconfig_fn [STRSIZE];
        FILE *f;
 
-       if (network_up) {
-               msg_prompt(MSG_mntnetconfig, ans, ans, 5);
-               if (*ans == 'y') {
+       if (!network_up)
+               return;
+       msg_prompt(MSG_mntnetconfig, ans, ans, 5);
+       if (*ans != 'y')
+               return;
 
-                       /* Write hostname to /etc/myname */
-                       f = target_fopen("/etc/myname", "w");
-                       if (f != 0) {
-                               (void)fprintf(f, "%s\n", net_host);
-                               if (scripting)
-                                       (void)fprintf(script, "echo \"%s\" >%s/etc/myname\n", net_host, target_prefix());
-                               (void)fclose(f);
+       /* Write hostname to /etc/myname */
+       if ((net_dhcpconf & DHCPCONF_HOST) == 0) {
+               f = target_fopen("/etc/myname", "w");
+               if (f != 0) {
+                       (void)fprintf(f, "%s\n", net_host);
+                       if (scripting) {
+                               (void)fprintf(script,
+                                   "echo \"%s\" >%s/etc/myname\n",
+                                   net_host, target_prefix());
                        }
+                       (void)fclose(f);
+               }
+       }
+
+       /* If not running in target, copy resolv.conf there. */
+       if ((net_dhcpconf & DHCPCONF_NAMESVR) == 0) {
+               if (strcmp(net_namesvr, "") != 0)
+                       dup_file_into_target("/etc/resolv.conf");
+       }
 
-                       /* If not running in target, copy resolv.conf there. */
-                       if (strcmp(net_namesvr, "") != 0)
-                               dup_file_into_target("/etc/resolv.conf");
-                       /* 
-                        * Add IPaddr/hostname to  /etc/hosts.
-                        * Be careful not to clobber any existing contents.
-                        * Relies on ordered seach of /etc/hosts. XXX YP?
-                        */
-                       f = target_fopen("/etc/hosts", "a");
-                       if (f != 0) {
-                               write_etc_hosts(f);
-                               (void)fclose(f);
+       if ((net_dhcpconf & DHCPCONF_IPADDR) == 0) {
+               /* 
+                * Add IPaddr/hostname to  /etc/hosts.
+                * Be careful not to clobber any existing contents.
+                * Relies on ordered seach of /etc/hosts. XXX YP?
+                */
+               f = target_fopen("/etc/hosts", "a");
+               if (f != 0) {
+                       write_etc_hosts(f);
+                       (void)fclose(f);
+                       if (scripting) {
+                               (void)fprintf(script,
+                                   "cat <<EOF >>%s/etc/hosts\n",
+                                   target_prefix());
+                               write_etc_hosts(script);
+                               (void)fprintf(script, "EOF\n");
+                       }
+               }
+
+               /* Write IPaddr and netmask to /etc/ifconfig.if[0-9] */
+               snprintf(ifconfig_fn, STRSIZE, "/etc/ifconfig.%s",
+                   net_dev);
+               f = target_fopen(ifconfig_fn, "w");
+               if (f != 0) {
+                       if (*net_media != '\0') {
+                               fprintf(f, "%s netmask %s media %s\n",
+                                       net_ip, net_mask, net_media);
                                if (scripting) {
-                                       (void)fprintf(script, "cat <<EOF >>%s/etc/hosts\n", target_prefix());
-                                       write_etc_hosts(script);
-                                       (void)fprintf(script, "EOF\n");
+                                       fprintf(script,
+                                           "echo \"%s netmask %s media %s\">%s%s\n",
+                                           net_ip, net_mask, net_media,
+                                           target_prefix(), ifconfig_fn);
+                               }
+                       } else {
+                               fprintf(f, "%s netmask %s\n",
+                                       net_ip, net_mask);
+                               if (scripting) {
+                                       fprintf(script,
+                                           "echo \"%s netmask %s\">%s%s\n",
+                                           net_ip, net_mask, target_prefix(),
+                                           ifconfig_fn);
                                }
                        }
+                       fclose(f);
+               }
 
-                       /* Write IPaddr and netmask to /etc/ifconfig.if[0-9] */
-                       snprintf(ifconfig_fn, STRSIZE, "/etc/ifconfig.%s",
-                           net_dev);
-                       f = target_fopen(ifconfig_fn, "w");
-                       if (f != 0) {
-                               if (*net_media != '\0') {
-                                       fprintf(f, "%s netmask %s media %s\n",
-                                               net_ip, net_mask, net_media);
-                                       if (scripting)
-                                               fprintf(script, "echo \"%s netmask %s media %s\">%s%s\n",
-                                                       net_ip, net_mask, net_media, target_prefix(), ifconfig_fn);
-                               } else {
-                                       fprintf(f, "%s netmask %s\n",
-                                               net_ip, net_mask);
-                                       if (scripting)
-                                               fprintf(script, "echo \"%s netmask %s\">%s%s\n",
-                                                       net_ip, net_mask, target_prefix(), ifconfig_fn);
-                               }
-                               fclose(f);
+               f = target_fopen("/etc/mygate", "w");
+               if (f != 0) {
+                       fprintf(f, "%s\n", net_defroute);
+                       if (scripting) {
+                               fprintf(script,
+                                   "echo \"%s\" >%s/etc/mygate\n",



Home | Main Index | Thread Index | Old Index