Browse Source

added dhcp support via dhcpcd, untested

r263
master
David Whedon 22 years ago
parent
commit
d0c1dfaebd
  1. 3
      TODO
  2. 4
      debian/control
  3. 30
      debian/templates
  4. 164
      netcfg.c

3
TODO

@ -1,5 +1,4 @@
* put in checks so the user can't enter data that is clearly invalid (perhaps this will be done through debconf.
* dhcp: either another module, or in here
* fall back to safe defaults if the user doesn't enter a particular value (ex. gateway)
* do other sorts of network configurations (pcmcia)
* inderstand the target_path() thing, and do it properly
@ -7,3 +6,5 @@
* decide what numbers you will actually present the user with for confirmation (you have overkill now)
* fix the note about what the user should do if we don't find any network interfaces. Since I don't now know what the flow of the installer is going to be I can't suggest what they should do, I've got the test in there from the old installer now.
* currently we get an internal error if the user has lots of network interfaces, find a better way of handling that.
* etherconf has some good descriptive text, perhaps I want to use it in place of the existing text.
* when the real dhcpcd installs itself we want to make sure it doesn't destroy our nice working configuration, how to do that?

4
debian/control

@ -2,12 +2,12 @@ Source: netcfg
Section: debian-installer
Priority: standard
Maintainer: David Whedon <dwhedon@gordian.com>
Build-Depends: debhelper (>= 2.1.18), dpkg-dev (>= 1.7.0)
Build-Depends: debhelper (>= 2.1.18), dpkg-dev (>= 1.7.0), cdebconf-dev
Standards-Version: 3.1.1
Package: netcfg
Architecture: any
Depends: ${shlibs:Depends}
Depends: ${shlibs:Depends}, dhcpcd-udeb
Provides: network-configuration
XBC-Installer-Menu-Item: 2
Description: Configure the network

30
debian/templates

@ -11,17 +11,28 @@ Description: no network devices found
Template: netcfg/choose_interface
Type: select
Choices: ${ifchoices}
Description: Choose an interface
Description: Choose an interface.
The following interfaces were detected. Choose the type of your primary
network interface that you will need for installing Debian (via NFS or HTTP).
Template: netcfg/dhcp_option
Type: boolean
Default: true
Description: Automatic Network Configuration
Configuration for (FIXME) Do you want to use DHCP or BOOTP to automatically
configure this interface? You'll need a DHCP or BOOTP server in the local
network for this to work.
Description: Automatically configure with DHCP?
Many networks allow automatic configuration by using DHCP. If you
are on a corporate network, a cable modem, some DSL connections,
or have any other sort of dynamic IP for Ethernet, you should say yes
here. If you have information such as IP address, netmask, gateway,
then you should say no.
Template: netcfg/dhcp_hostname
Type: string
Description: What is your dhcp hostname?
In some situations, you may need to supply a DHCP host name. These
situations are rare. Most commonly, it applies to cable modem users.
If you are a cable modem user, you might often need to specify an
account number here. Otherwise, you can just leave this blank.
Template: netcfg/get_hostname
Type: string
@ -33,8 +44,7 @@ Description: Choose the hostname.
administrator of the network before you choose a hostname. If not, you may
choose any name you like. The hostname must not contain dots or underscores,
and you must not append the domain name here. If you can't think of a
hostname for your new system, you may press <ENTER> to use the default hostname
of "debian".
hostname for your new system, you may press <ENTER> to use the default hostname.
Template: netcfg/get_domain
Type: string
@ -94,6 +104,12 @@ Description: Is this configuration correct?
secondary DNS = ${secondary_DNS}
tertiary DNS = ${tertiary_DNS}
Template: netcfg/error_cfg
Type: note
Description: An error occured.
Something went wrong when I tried to activate your network.
Template: netcfg/get_pcmcia_tranceiver
Type: string
Description: PCMCIA Transceiver

164
netcfg.c

@ -18,6 +18,8 @@
static char *interface = NULL;
static char *hostname = NULL;
static char *domain = NULL;
static char *dhcp_hostname = NULL;
static int do_dhcp=0;
static u_int32_t ipaddress = 0;
static u_int32_t network = 0;
static u_int32_t broadcast = 0;
@ -36,11 +38,13 @@ static char buf[MAXLINE];
#define HOSTS_FILE "etc/hosts"
#define NETWORKS_FILE "etc/networks"
#define RESOLV_FILE "etc/resolv.conf"
#define DHCPCD_FILE "etc/dhcpc/config"
#else
#define INTERFACES_FILE "/etc/network/interfaces"
#define HOSTS_FILE "/etc/hosts"
#define NETWORKS_FILE "/etc/networks"
#define RESOLV_FILE "/etc/resolv.conf"
#define DHCPCD_FILE "/etc/dhcpc/config"
#endif
@ -127,6 +131,55 @@ debconf_unseen (char *template)
client->command (client, "fset", template, "seen", "false", NULL);
}
/*
* Get all available interfaces from the kernel and ask the user which one
* he wants to configure
*/
int
get_interface ()
{
char *ptr = buf;
char *inter;
debconf_unseen ("netcfg/choose_interface");
getif_start ();
while ((inter = getif (1)) != NULL)
{
ptr +=
snprintf (ptr, sizeof (buf) - strlen (buf), "%s: %s, ", inter,
get_ifdsc (inter));
if (ptr > (buf + sizeof (buf)))
{
fprintf (stderr, "Internal error.\n");
exit (1);
}
}
getif_end ();
if (ptr == buf)
{
client->command (client, "input", "high", "netcfg/no_interfaces", NULL);
client->command (client, "go", NULL);
return -1;
}
debconf_subst ("netcfg/choose_interface", "ifchoices", buf);
ptr = debconf_input ("critical", "netcfg/choose_interface");
/* grab just the interface name, not the description too */
*(strchr (ptr, ':')) = '\0';
interface = strdup (ptr);
debconf_subst ("netcfg/confirm_static_cfg", "interface", interface);
return 0;
}
void
get_static_cfg (void)
{
@ -135,7 +188,7 @@ get_static_cfg (void)
do
{
get_interface ();
get_interface ();
debconf_unseen ("netcfg/get_hostname");
debconf_unseen ("netcfg/get_ipaddress");
@ -293,7 +346,7 @@ write_static_cfg (void)
if ((fp = file_open (INTERFACES_FILE)))
{
fprintf (fp,
"\n# The first network card - this entry was created during the Debian installation\n");
"\n# This entry was created during the Debian installation\n");
fprintf (fp, "# (network, broadcast and gateway are optional)\n");
fprintf (fp, "iface %s inet static\n", interface);
fprintf (fp, "\taddress %s\n", num2dot (ipaddress));
@ -307,64 +360,52 @@ write_static_cfg (void)
}
int
activate_static_net ()
{
system ("/sbin/ifconfig lo 127.0.0.1");
snprintf (buf, sizeof (buf),
"/sbin/ifconfig %s %s netmask %s broadcast %s", interface,
num2dot (ipaddress), num2dot (netmask), num2dot (broadcast));
system ("buf");
return 0;
void
write_dhcp_cfg(void){
FILE *fp;
if ((fp = file_open (INTERFACES_FILE)))
{
fprintf (fp, "\n# This entry was created during the Debian installation\n");
fprintf (fp, "iface %s inet dhcp\n", interface);
}
if ((fp = file_open (DHCPCD_FILE)))
{
fprintf (fp, "\n# dhcpcd configuration: created during the Debian installation\n");
fprintf (fp, "IFACE=%s", interface);
if (dhcp_hostname)
fprintf (fp, "OPTIONS='-h %s'", dhcp_hostname);
}
}
/*
* Get all available interfaces from the kernel and ask the user which one
* he wants to configure
*/
int
get_interface ()
activate_net ()
{
char *ptr = buf;
char *inter;
debconf_unseen ("netcfg/choose_interface");
getif_start ();
while ((inter = getif (1)) != NULL)
{
ptr +=
snprintf (ptr, sizeof (buf) - strlen (buf), "%s: %s, ", inter,
get_ifdsc (inter));
if (ptr > (buf + sizeof (buf)))
{
fprintf (stderr, "Internal error.\n");
exit (1);
}
}
getif_end ();
char *ptr;
int rv;
system ("/sbin/ifconfig lo 127.0.0.1");
if (ptr == buf)
{
client->command (client, "input", "high", "netcfg/no_interfaces", NULL);
if (do_dhcp) {
ptr=buf;
ptr += snprintf (buf, sizeof (buf), "/sbin/dhcpcd-2.2.x");
if (dhcp_hostname)
snprintf(ptr, sizeof(buf)-(ptr-buf), " -h %s", dhcp_hostname);
}
else {
snprintf (buf, sizeof (buf),
"/sbin/ifconfig %s %s netmask %s broadcast %s", interface,
num2dot (ipaddress), num2dot (netmask), num2dot (broadcast));
}
rv = system (buf);
fprintf(stderr, "rv = %d\n", rv);
if (rv != 0) {
client->command (client, "input", "critical", "netcfg/error_cfg", NULL);
client->command (client, "go", NULL);
return -1;
}
debconf_subst ("netcfg/choose_interface", "ifchoices", buf);
ptr = debconf_input ("critical", "netcfg/choose_interface");
*(strchr (ptr, ':')) = '\0';
interface = strdup (ptr);
debconf_subst ("netcfg/confirm_static_cfg", "interface", interface);
}
return 0;
}
@ -374,13 +415,26 @@ int
main (int argc, char *argv[])
{
char *ptr;
client = debconfclient_new ();
client->command (client, "title", "Network Configuration", NULL);
get_static_cfg ();
write_static_cfg ();
ptr = debconf_input ("critical", "netcfg/dhcp_option");
if (strstr (ptr, "true"))
{
do_dhcp=1;
dhcp_hostname = debconf_input ("high", "netcfg/dhcp_hostname");
write_dhcp_cfg();
}
else
{
get_static_cfg ();
write_static_cfg ();
}
activate_net();
return 0;
}

Loading…
Cancel
Save