Browse Source

choose b/w dhclient and pump at runtime, with a preference towards dhclient.

r363
master
David Whedon 23 years ago
parent
commit
8cae2faa12
  1. 11
      Makefile
  2. 2
      README
  3. 1
      TODO
  4. 8
      debian/control
  5. 7
      debian/copyright
  6. 5
      debian/netcfg-dhcp.templates
  7. 114
      netcfg-dhcp.c
  8. 18
      netcfg-static.c
  9. 54
      netcfg.c

11
Makefile

@ -1,15 +1,6 @@
# this is the size of the non-shared udebs
#-rw-r--r-- 1 davidw root 7114 Jan 16 20:49 netcfg-dhcp_0.04_i386.udeb
#-rw-r--r-- 1 davidw root 7556 Jan 16 20:49 netcfg-static_0.04_i386.udeb
ifndef TARGETS
TARGETS=netcfg-dhcp netcfg-static
endif
DHCP_CLIENT=-DDHCLIENT
#-DPUMP
#-DDHCPCD
MAJOR=0
MINOR=1
@ -32,7 +23,7 @@ STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment
all: $(TARGETS)
#$(LIBS)
netcfg-dhcp netcfg-static: netcfg-dhcp.c utils.o netcfg.o
$(CC) $(CFLAGS) $@.c -o $@ $(INCS) $(LDOPTS) $(DHCP_CLIENT) utils.o netcfg.o
$(CC) $(CFLAGS) $@.c -o $@ $(INCS) $(LDOPTS) utils.o netcfg.o
$(STRIP) $@
size $@

2
README

@ -10,7 +10,7 @@ debian system the network is brought up automatically.
netcfg is written specifically for the debian-installer and probably won't work
as expected is you try to run it on a full Debian system. If you want
something for a full system, take a look at etherconf.
something for a full system, take a look at etherconf or ppp-config (eventually).
Currently static and dhcp configuration is supported.

1
TODO

@ -1,4 +1,3 @@
* put in checks so the user can't enter data that is clearly invalid (perhaps this will be done through debconf.
* do other sorts of network configurations (pcmcia, ppp)
* dhcp and static udebs share a fair amount, perhaps that can be fixed.
* pppconfig would be a good starting point for the ppp udeb. There is also an example in there of how to use pppd to detect a modem.

8
debian/control

@ -1,13 +1,13 @@
Source: netcfg
Section: debian-installer
Priority: optional
Maintainer: David Whedon <dwhedon@gordian.com>
Maintainer: David Whedon <dwhedon@debian.org>
Build-Depends: debhelper (>= 2.1.18), dpkg-dev (>= 1.7.0), cdebconf-dev
Standards-Version: 3.1.1
Package: netcfg-dhcp
Architecture: any
Depends: ${shlibs:Depends}, cdebconf-udeb, dhcpcd-udeb
Depends: ${shlibs:Depends}, cdebconf-udeb, dhcp-client-udeb | pump-udeb
Provides: configured-network
XBC-Installer-Menu-Item: 2
Description: Configure the network via DHCP
@ -15,7 +15,9 @@ Description: Configure the network via DHCP
Configuration Protocol). If you are on a corporate network, a cable modem,
some DSL connections, or have any other sort of dynamic IP for Ethernet, you
will likely be able to configure via DHCP. If you have information such as IP
address, netmask, gateway, then DHCP is not appropriate.
address, netmask, gateway, then DHCP is not appropriate. This package uses
the Internet Software Consortium's dhclient or Red Hat Linux's pump, whichever
is available.
Package: netcfg-static
Architecture: any

7
debian/copyright

@ -1,7 +1,10 @@
This is a network configuration for Debian/GNU Linux installer.
Author(s): David Whedon, Karl Hammar, Aspö Data
Author(s): David Whedon,
Copyright 2000 David Whedon <dwhedon@gordian.com>
Some pieces of code from ithe debian boot-floppies as well as
Karl Hammar, Aspö Data
Copyright 2000 David Whedon <dwhedon@debian.org>
The copyright of this package is GPL, version 2 or later.

5
debian/netcfg-dhcp.templates

@ -21,3 +21,8 @@ Type: note
Description: I will now configure the network.
This may take some time. It shouldn't take more than a minute or two.
Template: netcfg/no_dhcp_client
Type: note
Description: No dhcp client found. I cannot continue.
This package requires pump or dhcp-client.

114
netcfg-dhcp.c

@ -24,7 +24,14 @@ static char *domain = NULL;
static u_int32_t ipaddress = 0;
static u_int32_t nameserver_array[4] = { 0 };
static struct debconfclient *client;
enum
{
PUMP,
DHCLIENT,
}
dhcp_client_choices;
int dhcp_client = PUMP;
static char *dhcp_hostname = NULL;
@ -49,11 +56,11 @@ netcfg_get_dhcp ()
client->command (client, "get", "netcfg/dhcp_hostname", NULL);
if (client->value)
dhcp_hostname = strdup (client->value);
dhcp_hostname = strdup (client->value);
client->command (client, "subst", "netcfg/confirm_dhcp",
"dhcp_hostname",
(dhcp_hostname ? dhcp_hostname : "<none>"), NULL);
"dhcp_hostname",
(dhcp_hostname ? dhcp_hostname : "<none>"), NULL);
}
@ -70,25 +77,25 @@ netcfg_write_dhcp ()
fprintf (fp, "iface %s inet dhcp\n", interface);
fclose (fp);
}
#if defined PUMP
/* nothing to do */
if (dhcp_client == DHCLIENT)
{
netcfg_mkdir (DHCLIENT_DIR);
if (dhcp_hostname)
if ((fp = file_open (DHCLIENT_FILE)))
{
fprintf (fp,
"\n# dhclient configuration: created during the Debian installation\n\
interface \"%s\" {\nsend host-name \"%s\";\n}\n",
interface, dhcp_hostname);
fclose (fp);
}
}
/* else if (dhcp_client == PUMP) {
nothing to do?
}
*/
#elif defined DHCLIENT
netcfg_mkdir (DHCLIENT_DIR);
if (dhcp_hostname)
if ((fp = file_open (DHCLIENT_FILE)))
{
fprintf (fp,
"\n# dhclient configuration: created during the Debian installation\n\
interface \"%s\" {\nsend host-name \"%s\";\n}\n",
interface, dhcp_hostname);
fclose (fp);
}
#else
#error "Must specify a dhcp client"
#endif
}
@ -100,21 +107,15 @@ netcfg_activate_dhcp ()
execlog ("/sbin/ifconfig lo 127.0.0.1");
ptr = buf;
#if defined PUMP
ptr += snprintf (buf, sizeof (buf), "/sbin/pump -i %s", interface);
if (dhcp_hostname)
ptr +=
snprintf (ptr, sizeof (buf) - (ptr - buf), " -h %s", dhcp_hostname);
#elif defined DHCLIENT
ptr += snprintf (buf, sizeof (buf), "/sbin/dhclient-2.2.x %s", interface);
#else
#error "Must specify a dhcp client"
#endif
if (dhcp_client == PUMP)
{
ptr += snprintf (buf, sizeof (buf), "/sbin/pump -i %s", interface);
if (dhcp_hostname)
ptr +=
snprintf (ptr, sizeof (buf) - (ptr - buf), " -h %s", dhcp_hostname);
}
else /* dhcp_client == DHCLIENT */
ptr += snprintf (buf, sizeof (buf), "/sbin/dhclient-2.2.x %s", interface);
if (execlog (buf))
netcfg_die (client);
@ -125,31 +126,48 @@ int
main (int argc, char *argv[])
{
char *ptr;
char *nameservers=NULL;
char *nameservers = NULL;
int finished = 0;
struct stat buf;
client = debconfclient_new ();
client->command (client, "title", "DHCP Network Configuration", NULL);
if (stat ("/sbin/dhclient", &buf) == 0)
dhcp_client = DHCLIENT;
else if (stat ("/sbin/pump", &buf) == 0)
dhcp_client = PUMP;
else
{
client->command (client, "input", "critical", "netcfg/no_dhcp_client",
NULL);
client->command (client, "go", NULL);
exit (1);
}
do
{
netcfg_get_common (client, &interface, &hostname, &domain, &nameservers);
netcfg_get_common (client, &interface, &hostname, &domain,
&nameservers);
client->command (client, "subst", "netcfg/confirm_dhcp", "interface",
interface, NULL);
client->command (client, "subst", "netcfg/confirm_dhcp", "hostname",
hostname, NULL);
client->command (client, "subst", "netcfg/confirm_dhcp", "domain",
(domain ? domain : "<none>"), NULL);
netcfg_nameservers_to_array(nameservers, nameserver_array);
netcfg_nameservers_to_array (nameservers, nameserver_array);
client->command (client, "subst", "netcfg/confirm_dhcp",
"nameservers", (nameservers ? nameservers : "<none>"), NULL);
"nameservers", (nameservers ? nameservers : "<none>"),
NULL);
netcfg_get_dhcp ();
ptr = debconf_input ("medium", "netcfg/confirm_dhcp");
if (strstr (ptr, "true"))

18
netcfg-static.c

@ -147,27 +147,29 @@ main (int argc, char *argv[])
{
int finished = 0;
char *ptr;
char *nameservers=NULL;
char *nameservers = NULL;
client = debconfclient_new ();
client->command (client, "title", "Static Network Configuration", NULL);
do
{
netcfg_get_common (client, &interface, &hostname, &domain, &nameservers);
netcfg_get_common (client, &interface, &hostname, &domain,
&nameservers);
client->command (client, "subst", "netcfg/confirm_static", "interface",
interface, NULL);
interface, NULL);
client->command (client, "subst", "netcfg/confirm_static",
"hostname", hostname, NULL);
client->command (client, "subst", "netcfg/confirm_static", "domain",
(domain ? domain : "<none>"), NULL);
client->command (client, "subst", "netcfg/confirm_static",
"nameservers", (nameservers ? nameservers : "<none>") , NULL);
netcfg_nameservers_to_array(nameservers, nameserver_array);
"nameservers", (nameservers ? nameservers : "<none>"),
NULL);
netcfg_nameservers_to_array (nameservers, nameserver_array);
netcfg_get_static ();

54
netcfg.c

@ -360,7 +360,8 @@ netcfg_get_common (struct debconfclient *client, char **interface,
free (*hostname);
*hostname = NULL;
}
*hostname = strdup (debconf_input (client, "medium", "netcfg/get_hostname"));
*hostname =
strdup (debconf_input (client, "medium", "netcfg/get_hostname"));
if (*domain)
{
@ -372,37 +373,38 @@ netcfg_get_common (struct debconfclient *client, char **interface,
if (*nameservers)
{
free(*nameservers);
}
{
free (*nameservers);
}
*nameservers = NULL;
if (ptr = debconf_input (client, "medium", "netcfg/get_nameservers"))
*nameservers = strdup(ptr);
*nameservers = strdup (ptr);
}
void
netcfg_nameservers_to_array(char *nameservers, u_int32_t array[]){
netcfg_nameservers_to_array (char *nameservers, u_int32_t array[])
{
char *save, *ptr, *ns;
if (nameservers)
{
save = ptr = strdup (ptr);
ns = strtok_r (ptr, " ", &ptr);
dot2num (&array[0], ns);
ns = strtok_r (NULL, " ", &ptr);
dot2num (&array[1], ns);
ns = strtok_r (NULL, " ", &ptr);
dot2num (&array[2], ns);
array[3]=0;
free (save);
}
else
array[0] = 0;
char *save, *ptr, *ns;
if (nameservers)
{
save = ptr = strdup (ptr);
ns = strtok_r (ptr, " ", &ptr);
dot2num (&array[0], ns);
ns = strtok_r (NULL, " ", &ptr);
dot2num (&array[1], ns);
ns = strtok_r (NULL, " ", &ptr);
dot2num (&array[2], ns);
array[3] = 0;
free (save);
}
else
array[0] = 0;
}

Loading…
Cancel
Save