Don't shoot self in the foot if / is on NFS.

This commit is contained in:
ad 2008-11-25 14:25:20 +00:00
parent ad71247a89
commit a93bd7922f

View File

@ -1,4 +1,4 @@
/* $NetBSD: net.c,v 1.120 2008/11/21 15:31:20 ad Exp $ */
/* $NetBSD: net.c,v 1.121 2008/11/25 14:25:20 ad Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -52,6 +52,7 @@
#endif
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/statvfs.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/if_media.h>
@ -530,11 +531,12 @@ config_network(void)
char *textbuf;
int octet0;
int dhcp_config;
int nfs_root = 0;
int slip = 0;
int pid, status;
char **ap, *slcmd[10], *in_buf;
char buffer[STRSIZE];
struct statvfs sb;
int l;
char dhcp_host[STRSIZE];
@ -591,9 +593,16 @@ again:
slip = net_dev[0] == 's' && net_dev[1] == 'l' &&
isdigit((unsigned char)net_dev[2]);
if (slip)
/* If root is on NFS do not reconfigure the interface. */
if (statvfs("/", &sb) == 0 && strcmp(sb.f_fstypename, "nfs") == 0) {
nfs_root = 1;
dhcp_config = 0;
else {
get_ifinterface_info();
get_if6interface_info();
get_host_info();
} else if (slip) {
dhcp_config = 0;
} else {
/* Preload any defaults we can find */
get_ifinterface_info();
get_if6interface_info();
@ -706,11 +715,13 @@ again:
if (!dhcp_config) {
/* Manually configure IPv4 */
msg_prompt_add(MSG_net_ip, net_ip, net_ip, sizeof net_ip);
if (!nfs_root)
msg_prompt_add(MSG_net_ip, net_ip, net_ip,
sizeof net_ip);
if (slip)
msg_prompt_add(MSG_net_srv_ip, net_srv_ip, net_srv_ip,
sizeof net_srv_ip);
else {
else if (!nfs_root) {
/* We don't want netmasks for SLIP */
octet0 = atoi(net_ip);
if (!net_mask[0]) {
@ -822,7 +833,7 @@ done:
run_program(0, "/sbin/ifconfig lo0 127.0.0.1");
#ifdef INET6
if (v6config) {
if (v6config && !nfs_root) {
init_v6kernel(1);
run_program(0, "/sbin/ifconfig %s up", net_dev);
sleep(get_v6wait() + 1);
@ -855,7 +866,7 @@ done:
execvp(slcmd[0], slcmd);
} else
wait4(pid, &status, WNOHANG, 0);
} else {
} else if (!nfs_root) {
if (net_mask[0] != '\0') {
run_program(0, "/sbin/ifconfig %s inet %s netmask %s",
net_dev, net_ip, net_mask);
@ -871,7 +882,7 @@ done:
sethostname(net_host, strlen(net_host));
/* Set a default route if one was given */
if (net_defroute[0] != '\0') {
if (!nfs_root && net_defroute[0] != '\0') {
run_program(RUN_DISPLAY | RUN_PROGRESS,
"/sbin/route -n flush -inet");
run_program(RUN_DISPLAY | RUN_PROGRESS,
@ -881,8 +892,10 @@ done:
/*
* wait a couple of seconds for the interface to go live.
*/
msg_display_add(MSG_wait_network);
sleep(5);
if (!nfs_root) {
msg_display_add(MSG_wait_network);
sleep(5);
}
/*
* ping should be verbose, so users can see the cause