Re: Static network configuration
Adam Di Carlo wrote:
> Stefan, please send a patch to this list so we may peruse it. You
> should be patching form the boot-floppies CVS area.
Here it is.
--
Stefan Gybas
--- boot-floppies/utilities/dbootstrap/netconfig.c.orig Tue Jan 11 16:14:29 2000
+++ boot-floppies/utilities/dbootstrap/netconfig.c Tue Jan 11 17:38:21 2000
@@ -1,3 +1,11 @@
+/* Network configuration during Debian installation
+ *
+ * Ask the user for the network configuration (static IP adress or
+ * dynamic addresses using DHCP/BOOTP), write the static configuration
+ * (which includes at least the loopback interface) to /etc/network/interfaces
+ * and activate this configuration
+ */
+
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
@@ -13,15 +21,15 @@
/*
* Strings and other constants
*/
-#define NC_ETC_DIR "/etc"
-#define NC_ETC_INIT_DIR "/etc/init.d"
-#define NC_HOSTNAME_FILE "/etc/hostname"
-#define NC_NETWORKS_FILE "/etc/networks"
-#define NC_RESOLV_FILE "/etc/resolv.conf"
-#define NC_NETWORK_FILE "/etc/init.d/network"
-#define NC_HOSTS_FILE "/etc/hosts"
-#define NC_PCMCIA_DIR "/etc/pcmcia"
-#define NC_PCMCIA_FILE "/etc/pcmcia/network.opts"
+#define NC_ETC_DIR "/etc"
+#define NC_HOSTNAME_FILE "/etc/hostname"
+#define NC_NETWORKS_FILE "/etc/networks"
+#define NC_RESOLV_FILE "/etc/resolv.conf"
+#define NC_ETC_NETWORK_DIR "/etc/network"
+#define NC_INTERFACES_FILE "/etc/network/interfaces"
+#define NC_HOSTS_FILE "/etc/hosts"
+#define NC_PCMCIA_DIR "/etc/pcmcia"
+#define NC_PCMCIA_FILE "/etc/pcmcia/network.opts"
#define OPT_LIM (100)
#define NC_NI_NONE (0)
@@ -58,7 +66,7 @@
int atoIP(char*, ip_addr_t*);
char* IPtoa(ip_addr_t);
char* IPtostr(char*, ip_addr_t);
-int activate_network();
+int activate_static_network();
extern int activate_pcmcia();
/*
@@ -430,14 +438,14 @@
int ix;
/*
- * Create /target/etc and /target/etc/init.d if they don't exist
+ * Create /target/etc and /target/etc/network if they don't exist
*/
check_target_path();
path = target_path(NC_ETC_DIR);
if (check_dir(path) == -1)
mkdir(path, 0755);
- path = target_path(NC_ETC_INIT_DIR);
+ path = target_path(NC_ETC_NETWORK_DIR);
if (check_dir(path) == -1)
mkdir(path, 0755);
@@ -467,10 +475,11 @@
fclose(p_file);
}
- path = target_path(NC_NETWORK_FILE);
+ path = target_path(NC_INTERFACES_FILE);
p_file = fopen(path, "w");
- fprintf(p_file,
- "#! /bin/sh\nifconfig lo 127.0.0.1\n");
+ fprintf(p_file, "# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)\n\n");
+ fprintf(p_file, "# The loopback interface\n");
+ fprintf(p_file, "iface lo inet loopback\n");
fclose(p_file);
chmod(path, 0755);
@@ -478,20 +487,15 @@
if (strcmp(netinterface, "none"))
if (strcmp(netinterface, "pcmcia")) { /* PCMCIA uses a different file */
p_file = fopen(path, "a");
- fprintf(p_file, "IPADDR=%s\n", IPtostr(prtbuf, ipaddr));
- fprintf(p_file, "NETMASK=%s\n", IPtostr(prtbuf, netmask));
- fprintf(p_file, "NETWORK=%s\n", IPtostr(prtbuf, network));
- fprintf(p_file, "BROADCAST=%s\n", IPtostr(prtbuf, broadcast));
+ fprintf(p_file, "\n# The first network card - this entry was created during the Debian installation\n");
+ fprintf(p_file, "# (network, broadcast and gateway are optional)\n");
+ fprintf(p_file, "iface %s inet static\n", netinterface);
+ fprintf(p_file, "\taddress %s\n", IPtostr(prtbuf, ipaddr));
+ fprintf(p_file, "\tnetmask %s\n", IPtostr(prtbuf, netmask));
+ fprintf(p_file, "\tnetwork %s\n", IPtostr(prtbuf, network));
+ fprintf(p_file, "\tbroadcast %s\n", IPtostr(prtbuf, broadcast));
if (has_gw)
- fprintf(p_file, "GATEWAY=%s\n", IPtostr(prtbuf, gateway));
- else
- fprintf(p_file, "GATEWAY=\n");
-
- fprintf(p_file,
- "ifconfig %s ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST}\n",
- netinterface);
- fprintf(p_file,
- "[ \"${GATEWAY}\" ] && route add default gw ${GATEWAY} metric 1\n");
+ fprintf(p_file, "\tgateway %s\n", IPtostr(prtbuf, gateway));
fclose(p_file);
}
@@ -561,6 +565,44 @@
return 0;
}
+
+/*
+ * Activates the static network configuration (we don't add the network
+ * route to the interfaces, this is not required for kernel 2.2)
+ */
+int activate_static_network()
+{
+ struct stat tmp;
+ if (stat("/sbin/ifconfig", &tmp) == 0) {
+ getcwd(prtbuf, PRTBUFSIZE);
+ chdir("/etc");
+ unlink("resolv.conf");
+ symlink(target_path(NC_RESOLV_FILE), "resolv.conf");
+ chdir(prtbuf);
+
+ /*
+ * Always activate the loopback interface, and don't
+ * activate PCMCIA (this is done in activate_pcmcia)
+ */
+
+ execlog("/sbin/ifconfig lo0 127.0.0.1", LOG_INFO);
+ if (strcmp(netinterface, "none") && strcmp(netinterface, "pcmcia")) {
+ char cmdline[MAXLINE];
+ snprintf(cmdline, MAXLINE-5, "/sbin/ifconfig %s %s netmask %s broadcast %s",
+ netinterface,
+ IPtostr(prtbuf, ipaddr),
+ IPtostr(prtbuf, netmask),
+ IPtostr(prtbuf, broadcast));
+ execlog(cmdline, LOG_INFO);
+ if (has_gw) {
+ snprintf(cmdline, MAXLINE-5, "/sbin/route add default gw %s metric 1",
+ IPtostr(prtbuf, gateway));
+ execlog(cmdline, LOG_INFO);
+ }
+ }
+ }
+ return 0;
+}
/*
* Main configuration routine
@@ -666,14 +708,15 @@
break;
}
}
+
write_network_configuration();
+ activate_static_network();
+
free(nameserver);
free(hostname);
free(host);
free(domain);
- activate_network();
-
if (! (strcmp(netinterface, "pcmcia"))) {
free(transceiver);
if (activate_pcmcia())
@@ -684,23 +727,6 @@
return 0;
}
-/*
- * Activates the network interface
- */
-int activate_network()
-{
- struct stat tmp;
- if (stat("/sbin/ifconfig", &tmp) == 0) {
- getcwd(prtbuf, PRTBUFSIZE);
- chdir("/etc");
- unlink("resolv.conf");
- symlink(target_path(NC_RESOLV_FILE), "resolv.conf");
- chdir(prtbuf);
- execlog(target_path(NC_NETWORK_FILE), LOG_INFO);
- }
- return 0;
-}
-
#ifdef _TESTING_
/*
* To test, compile using: make netconfig_test
@@ -716,8 +742,6 @@
configure_network();
boxFinished();
- free(netinterface);
-
return 0;
}
#endif
Reply to: