2 * The new sysinstall program.
4 * This is probably the last attempt in the `sysinstall' line, the next
5 * generation being slated to essentially a complete rewrite.
10 * Jordan Hubbard. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer,
17 * verbatim and that no modifications are made prior to this
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 /* These routines deal with getting things off of network media */
40 #include "sysinstall.h"
43 #include <sys/fcntl.h>
44 #include <sys/ioctl.h>
47 static Boolean networkInitialized;
50 mediaInitNetwork(Device *dev)
54 char *cp, ifconfig[255];
57 if (!RunningAsInit || networkInitialized)
61 msgDebug("Init routine called for network device %s.\n", dev->name);
63 if (!file_readable("/etc/resolv.conf")) {
64 if (DITEM_STATUS(configResolv(NULL)) == DITEM_FAILURE) {
65 msgConfirm("Can't seem to write out /etc/resolv.conf. Net cannot be used.");
71 dialog_clear_norefresh();
73 snprintf(ifconfig, 255, "%s%s", VAR_IFCONFIG, dev->name);
74 cp = variable_get(ifconfig);
77 * If this interface isn't a DHCP one, bring it up.
78 * If it is, then it's already up.
80 if (strstr(cp, "DHCP") == NULL) {
81 msgDebug("Not a DHCP interface.\n");
82 i = vsystem("ifconfig %s %s", dev->name, cp);
84 msgConfirm("Unable to configure the %s interface!\n"
85 "This installation method cannot be used.",
89 rp = variable_get(VAR_GATEWAY);
90 if (!rp || *rp == '0') {
91 msgConfirm("No gateway has been set. You will be unable to access hosts\n"
92 "not on your local network");
96 * Explicitly flush all routes to get back to a known sane
97 * state. We don't need to check this exit code because if
98 * anything fails it will show up in the route add below.
100 system("route -n flush");
101 msgDebug("Adding default route to %s.\n", rp);
102 if (vsystem("route -n add default %s", rp) != 0) {
103 msgConfirm("Failed to add a default route; please check "
104 "your network configuration");
109 msgDebug("A DHCP interface. Should already be up.\n");
111 } else if ((cp = variable_get(VAR_IPV6ADDR)) == NULL || *cp == '\0') {
112 msgConfirm("The %s device is not configured. You will need to do so\n"
113 "in the Networking configuration menu before proceeding.", dev->name);
118 msgDebug("Network initialized successfully.\n");
119 networkInitialized = TRUE;
124 mediaShutdownNetwork(Device *dev)
128 if (!RunningAsInit || !networkInitialized)
131 msgDebug("Shutdown called for network device %s\n", dev->name);
135 snprintf(ifconfig, 255, "%s%s", VAR_IFCONFIG, dev->name);
136 cp = variable_get(ifconfig);
139 msgDebug("ifconfig %s down\n", dev->name);
140 i = vsystem("ifconfig %s down", dev->name);
142 msgConfirm("Warning: Unable to down the %s interface properly", dev->name);
143 cp = variable_get(VAR_GATEWAY);
145 msgDebug("Deleting default route.\n");
146 vsystem("route -n delete default");