network.c revision 8791
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last attempt in the `sysinstall' line, the next
5 * generation being slated to essentially a complete rewrite.
6 *
7 * $Id: media_strategy.c,v 1.28 1995/05/26 20:30:59 jkh Exp $
8 *
9 * Copyright (c) 1995
10 *	Jordan Hubbard.  All rights reserved.
11 * Copyright (c) 1995
12 * 	Gary J Palmer. All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer,
19 *    verbatim and that no modifications are made prior to this
20 *    point in the file.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 *    notice, this list of conditions and the following disclaimer in the
23 *    documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 *    must display the following acknowledgement:
26 *	This product includes software developed by Jordan Hubbard
27 *	for the FreeBSD Project.
28 * 4. The name of Jordan Hubbard or the FreeBSD project may not be used to
29 *    endorse or promote products derived from this software without specific
30 *    prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 */
45
46/*
47 * These routines deal with getting things off of floppy media, though
48 * with one exception:  genericGetDist() is actually used from lots of places
49 * since it can think of the world as just "one big floppy" too if that's
50 * appropriate.
51 */
52
53#include "sysinstall.h"
54
55static Boolean networkInitialized;
56
57Boolean
58mediaInitNetwork(Device *dev)
59{
60    int i;
61    char *rp;
62
63    if (networkInitialized)
64	return TRUE;
65
66    configResolv();
67    if (!strncmp("cuaa", dev->name, 4)) {
68	if (!tcpStartPPP(dev)) {
69	    msgConfirm("Unable to start PPP!  This installation method\ncannot be used.");
70	    return FALSE;
71	}
72    }
73    else {
74	char *cp, ifconfig[64];
75
76	snprintf(ifconfig, 64, "%s%s", VAR_IFCONFIG, dev->name);
77	cp = getenv(ifconfig);
78	if (!cp) {
79	    msgConfirm("The %s device is not configured.  You will need to do so\nin the Networking configuration menu before proceeding.");
80	    return FALSE;
81	}
82	i = vsystem("ifconfig %s %s", dev->name, cp);
83	if (i) {
84	    msgConfirm("Unable to configure the %s interface!\nThis installation method cannot be used.", dev->name);
85	    return FALSE;
86	}
87    }
88
89    rp = getenv(VAR_GATEWAY);
90    if (!rp)
91	msgConfirm("No gateway has been set. You will not be able to access hosts\n
92not on the local network\n");
93    else
94	vsystem("route add default %s", rp);
95    networkInitialized = TRUE;
96    return TRUE;
97}
98
99void
100mediaShutdownNetwork(Device *dev)
101{
102    char *cp;
103
104    if (!networkInitialized)
105	return;
106
107    if (!strncmp("cuaa", dev->name, 4)) {
108	msgConfirm("You may now go to the 3rd screen (ALT-F3) and shut down\nyour PPP connection.  It shouldn't be needed any longer\n(unless you wish to create a shell by typing ESC and\nexperiment with it further, in which case go right ahead!)");
109	return;
110    }
111    else {
112	int i;
113	char ifconfig[64];
114
115	snprintf(ifconfig, 64, "%s%s", VAR_IFCONFIG, dev->name);
116	cp = getenv(ifconfig);
117	if (!cp)
118	    return;
119	i = vsystem("ifconfig %s down", dev->name);
120	if (i)
121	    msgConfirm("Warning: Unable to down the %s interface properly", dev->name);
122    }
123
124    cp = getenv(VAR_GATEWAY);
125    if (cp)
126	vsystem("route delete default");
127    networkInitialized = FALSE;
128}
129