Browse Source

build netcfg-common, though it didn't work as I had planned, I still have big pl

ans for it.
netcfg-dhcp asks for hostname and dns now
various bug fixes
modify dependancies
if we don't find any interfaces, allow the user to specify one
try to get udpkg to create dirs for me, still some problems there

r290
master
David Whedon 22 years ago
parent
commit
b9c02085d2
  1. 4
      Makefile
  2. 3
      TODO
  3. 11
      debian/control
  4. 17
      debian/netcfg-common.templates
  5. 2
      debian/netcfg-dhcp.dirs
  6. 18
      debian/netcfg-dhcp.templates
  7. 2
      debian/netcfg-static.dirs
  8. 21
      debian/netcfg-static.templates
  9. 346
      netcfg.c

4
Makefile

@ -4,7 +4,7 @@ endif
INCS=-I../cdebconf/src/
LDOPTS=-L../cdebconf/src/ -ldebconf
LDOPTS=-L../cdebconf/src -ldebconf
PREFIX=$(DESTDIR)/usr/
CFLAGS=-Wall -Os -fomit-frame-pointer
INSTALL=install
@ -16,7 +16,7 @@ all: $(PROGS)
install:
$(foreach PROG, $(PROGS), \
cp $(PROG) debian/$(PROG).config)
-cp $(PROG) debian/$(PROG).config)
netcfg-dhcp: netcfg.c
$(CC) $(CFLAGS) -DDHCP netcfg.c -o $@ $(INCS) $(LDOPTS)

3
TODO

@ -9,3 +9,6 @@
* 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?
* dhcp and static config udebs share a fair amount of code, perhaps a shared library? They also share templates, need to make a netcfg-shared udeb?
* /etc/dhcpc needs to be created, udpkg isn't creating it for me right now
* get the /proc filesystem working
* strdup all the dotted quads rather than playing with num2dot etc. all the time

11
debian/control

@ -7,7 +7,7 @@ Standards-Version: 3.1.1
Package: netcfg-dhcp
Architecture: any
Depends: cdebconf-udeb, dhcpcd-udeb
Depends: cdebconf-udeb | cdebconf , dhcpcd-udeb | dhcpcd, netcfg-common
Provides: configured-network
XBC-Installer-Menu-Item: 2
Description: Configure the network via DHCP
@ -19,10 +19,17 @@ Description: Configure the network via DHCP
Package: netcfg-static
Architecture: any
Depends: cdebconf-udeb
Depends: cdebconf-udeb | cdebconf, netcfg-common
Provides: configured-network
XBC-Installer-Menu-Item: 2
Description: Configure a static network
If you have information such as IP address, netmask, gateway, then you will be
able to configure a static network. If you don't know this information, you
should ask you system administrator.
Package: netcfg-common
Architecture: any
Depends:
Provides: configured-network
Description: Share resources between static and dhcp netcfg.
This package contains templates that are shared between netcfg-dhcp and netcfg-static.

17
debian/netcfg-common.templates

@ -0,0 +1,17 @@
Template: netcfg/no_interfaces
Type: string
Description: please enter a network interface.
No network interfaces were found.
Template: netcfg/choose_interface
Type: select
Choices: ${ifchoices}
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/error_cfg
Type: note
Description: An error occured.
Something went wrong when I tried to activate your network.

2
debian/netcfg-dhcp.dirs

@ -0,0 +1,2 @@
etc
etc/network

18
debian/netcfg-dhcp.templates

@ -7,8 +7,8 @@ Description: What is your dhcp hostname?
account number here. Otherwise, you can just leave this blank.
Template: netcfg/no_interfaces
Type: note
Description: no network devices found
Type: string
Description: please enter a network interface.
No network interfaces were found. That means that the installation system
was unable to find a network device. If you do have a network card, then it
is possible that the module for it hasn't been selected yet. Go back to the
@ -16,6 +16,15 @@ Description: no network devices found
first. If your only network connection is PPP, don't worry -- you will be
asked if you want PPP later in the process.
Template: netcfg/get_hostname
Type: string
Default: debian
Description:
The hostname is a single word that identifies your system to the
network. If you don't know what your hostname should be, consult
your network administrator. If you are setting up your own home
network, you can make something up here. Don't enter your full
Template: netcfg/choose_interface
Type: select
Choices: ${ifchoices}
@ -28,3 +37,8 @@ Type: note
Description: An error occured.
Something went wrong when I tried to activate your network.
Template: netcfg/no_interfaces
Type: string
Description: please enter a network interface.
No network interfaces were found.

2
debian/netcfg-static.dirs

@ -0,0 +1,2 @@
etc
etc/network

21
debian/netcfg-static.templates

@ -54,15 +54,20 @@ Description: Is this configuration correct?
secondary DNS = ${secondary_DNS}
tertiary DNS = ${tertiary_DNS}
Template: netcfg/get_hostname
Type: string
Default: debian
Description:
The hostname is a single word that identifies your system to the
network. If you don't know what your hostname should be, consult
your network administrator. If you are setting up your own home
network, you can make something up here. Don't enter your full
domain name here; you'll be asked for that next.
Template: netcfg/no_interfaces
Type: note
Description: no network devices found
No network interfaces were found. That means that the installation system
was unable to find a network device. If you do have a network card, then it
is possible that the module for it hasn't been selected yet. Go back to the
'Configure Device Driver Modules' menu and load the required kernel modules
first. If your only network connection is PPP, don't worry -- you will be
asked if you want PPP later in the process.
Type: string
Description: please enter a network interface.
No network interfaces were found.
Template: netcfg/choose_interface
Type: select

346
netcfg.c

@ -22,9 +22,13 @@
#define RESOLV_FILE "/etc/resolv.conf"
#define DHCPCD_FILE "/etc/dhcpc/config"
#define MAXLINE 1024
#define DEBUG
static char *interface = NULL;
static char *hostname = NULL;
static char *domain = NULL;
static u_int32_t ipaddress = 0;
static u_int32_t nameservers[4] = { 0 };
static struct debconfclient *client;
static char buf[MAXLINE];
@ -41,12 +45,18 @@ int activate_net ();
void debconf_unseen (char *template);
void debconf_subst (char *template, char *key, char *string);
char *debconf_input (char *priority, char *template);
int do_system(char *);
void write_common(void);
void get_common(void);
char *dot2num (u_int32_t * num, char *dot);
char *num2dot (u_int32_t num);
#ifdef DHCP
static char *dhcp_hostname = NULL;
void write_dhcp_cfg (void);
int activate_dhcp_net (void);
int
main (int argc, char *argv[])
@ -54,11 +64,13 @@ main (int argc, char *argv[])
client = debconfclient_new ();
client->command (client, "title", "Network Configuration", NULL);
get_common();
get_interface ();
client->command (client, "input", "high", "netcfg/dhcp_hostname", NULL);
client->command (client, "go", NULL);
client->command (client, "get", "netcfg/dhcp_hostname", NULL);
dhcp_hostname = client->value;
write_common();
write_dhcp_cfg ();
activate_dhcp_net ();
@ -80,28 +92,28 @@ write_dhcp_cfg (void)
{
fprintf (fp,
"\n# dhcpcd configuration: created during the Debian installation\n");
fprintf (fp, "IFACE=%s", interface);
fprintf (fp, "IFACE=%s\n", interface);
if (dhcp_hostname)
fprintf (fp, "OPTIONS='-h %s'", dhcp_hostname);
fprintf (fp, "OPTIONS='-h %s'\n", dhcp_hostname);
}
}
int
activate_dhcp_net ()
activate_dhcp_net (void)
{
char *ptr;
int rv;
system ("/sbin/ifconfig lo 127.0.0.1");
do_system ("/sbin/ifconfig lo 127.0.0.1");
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);
ptr += snprintf (ptr, sizeof (buf) - (ptr - buf), " -h %s", dhcp_hostname);
ptr += snprintf (ptr, sizeof (buf) - (ptr - buf), " %s", interface);
rv = system (buf);
fprintf (stderr, "rv = %d\n", rv);
rv = do_system (buf);
if (rv != 0)
{
client->command (client, "input", "critical", "netcfg/error_cfg", NULL);
@ -116,14 +128,11 @@ activate_dhcp_net ()
#ifdef STATIC
static char *domain = NULL;
static u_int32_t ipaddress = 0;
static u_int32_t network = 0;
static u_int32_t broadcast = 0;
static u_int32_t netmask = 0;
static u_int32_t gateway = 0;
static u_int32_t nameservers[4] = { 0 };
static struct debconfclient *client;
@ -132,8 +141,7 @@ static char buf[MAXLINE];
void get_static_cfg (void);
void write_static_cfg (void);
char *dot2num (u_int32_t * num, char *dot);
char *num2dot (u_int32_t num);
int activate_static_net ();
int
main (int argc, char *argv[])
@ -153,7 +161,7 @@ void
get_static_cfg (void)
{
char finished = 0;
char *ptr, *ns;
char *ptr;
do
{
@ -174,21 +182,16 @@ get_static_cfg (void)
ipaddress = network = broadcast = netmask = gateway =
nameservers[0] = 0;
hostname = strdup (debconf_input ("high", "netcfg/get_hostname"));
debconf_subst ("netcfg/confirm_static_cfg", "hostname", hostname);
if ((ptr = debconf_input ("high", "netcfg/get_domain")))
domain = strdup (ptr);
debconf_subst ("netcfg/confirm_static_cfg", "domain", domain);
if ((ptr = debconf_input ("high", "netcfg/get_ipaddress")))
dot2num (&ipaddress, ptr);
debconf_subst ("netcfg/confirm_static_cfg", "ipaddress",
num2dot (ipaddress));
get_common();
if ((ptr = debconf_input ("high", "netcfg/get_netmask")))
dot2num (&netmask, ptr);
debconf_subst ("netcfg/confirm_static_cfg", "netmask",
@ -216,35 +219,6 @@ get_static_cfg (void)
broadcast = (network | ~netmask);
debconf_subst ("netcfg/confirm_static_cfg", "broadcast",
num2dot (broadcast));
ptr = debconf_input ("high", "netcfg/get_nameservers");
if (ptr)
{
char *save;
save = ptr = strdup (ptr);
ns = strtok_r (ptr, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "primary_DNS", ns);
dot2num (&nameservers[0], ns);
ns = strtok_r (NULL, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "secondary_DNS", ns);
dot2num (&nameservers[1], ns);
ns = strtok_r (NULL, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "tertiary_DNS", ns);
dot2num (&nameservers[2], ns);
free (save);
}
else
{
debconf_subst ("netcfg/confirm_static_cfg", "primary_DNS", NULL);
debconf_subst ("netcfg/confirm_static_cfg", "secondary_DNS", NULL);
debconf_subst ("netcfg/confirm_static_cfg", "tertiary_DNS", NULL);
}
ptr = debconf_input ("high", "netcfg/confirm_static_cfg");
if (strstr (ptr, "true"))
@ -261,42 +235,16 @@ void
write_static_cfg (void)
{
FILE *fp;
int i;
if ((fp = file_open (HOSTS_FILE)))
{
fprintf (fp, "127.0.0.1\tlocalhost\n");
if (domain)
{
fprintf (fp, "%s\t%s.%s\t%s\n", num2dot (ipaddress),
hostname, domain, hostname);
}
else
{
fprintf (fp, "%s\t%s\n", num2dot (ipaddress), hostname);
}
fclose (fp);
}
if ((fp = file_open (NETWORKS_FILE)))
{
fprintf (fp, "localnet %s\n", num2dot (network));
fclose (fp);
}
if ((fp = file_open (RESOLV_FILE)))
{
i = 0;
if (domain)
fprintf (fp, "search %s\n", domain);
while (nameservers[i])
{
fprintf (fp, "nameserver %s\n", num2dot (nameservers[i++]));
}
fclose (fp);
}
write_common();
if ((fp = file_open (INTERFACES_FILE)))
{
fprintf (fp,
@ -313,85 +261,116 @@ write_static_cfg (void)
}
/**
* dot2num and num2dot
* Copyright: Karl Hammar, Aspö Data
*/
char *
dot2num (u_int32_t * num, char *dot)
int
activate_static_net ()
{
char *p = dot - 1;
char *e;
int ix;
unsigned long val;
int rv;
char *ptr;
do_system ("/sbin/ifconfig lo 127.0.0.1");
if (!dot)
return NULL;
*num = 0;
for (ix = 0; ix < 4; ix++)
ptr = buf;
ptr += snprintf (buf, sizeof (buf), "/sbin/ifconfig %s %s", interface, num2dot (ipaddress));
ptr += snprintf (ptr, sizeof (buf) - (ptr - buf), " netmask %s", num2dot (netmask));
ptr += snprintf (ptr, sizeof (buf) - (ptr - buf), " broadcast %s", num2dot (broadcast));
rv = do_system (buf);
if (rv != 0)
{
*num <<= 8;
p++;
val = strtoul (p, &e, 10);
if (e == p)
val = 0;
else if (val > 255)
return NULL;
*num += val;
/*printf("%#8x, %#2x\n", *num, val); */
if (ix < 3 && *e != '.')
return NULL;
p = e;
client->command (client, "input", "critical", "netcfg/error_cfg", NULL);
client->command (client, "go", NULL);
}
return p;
return 0;
}
static char num2dot_buf[16];
#endif /* STATIC */
char *
num2dot (u_int32_t num)
{
int byte[4];
int ix;
char *dot = num2dot_buf;
void
get_common(void){
char *ptr, *ns;
if (num == 0)
return NULL;
for (ix = 3; ix >= 0; ix--)
hostname = strdup (debconf_input ("high", "netcfg/get_hostname"));
if ((ptr = debconf_input ("high", "netcfg/get_domain")))
domain = strdup (ptr);
debconf_subst ("netcfg/confirm_static_cfg", "domain", domain);
ptr = debconf_input ("high", "netcfg/get_nameservers");
if (ptr)
{
char *save;
save = ptr = strdup (ptr);
ns = strtok_r (ptr, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "primary_DNS", ns);
dot2num (&nameservers[0], ns);
ns = strtok_r (NULL, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "secondary_DNS", ns);
dot2num (&nameservers[1], ns);
ns = strtok_r (NULL, " ", &ptr);
debconf_subst ("netcfg/confirm_static_cfg", "tertiary_DNS", ns);
dot2num (&nameservers[2], ns);
free (save);
}
else
{
debconf_subst ("netcfg/confirm_static_cfg", "primary_DNS", NULL);
debconf_subst ("netcfg/confirm_static_cfg", "secondary_DNS", NULL);
debconf_subst ("netcfg/confirm_static_cfg", "tertiary_DNS", NULL);
}
}
void
write_common(void){
FILE *fp;
int i;
if ((fp = file_open (HOSTS_FILE)))
{
byte[ix] = num & 0xff;
num >>= 8;
fprintf (fp, "127.0.0.1\tlocalhost\n");
if (domain)
{
fprintf (fp, "%s\t%s.%s\t%s\n", num2dot (ipaddress),
hostname, domain, hostname);
}
else
{
fprintf (fp, "%s\t%s\n", num2dot (ipaddress), hostname);
}
fclose (fp);
}
sprintf (dot, "%d.%d.%d.%d", byte[0], byte[1], byte[2], byte[3]);
return dot;
}
int
activate_static_net ()
{
int rv;
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));
rv = system (buf);
fprintf (stderr, "rv = %d\n", rv);
if (rv != 0)
if ((fp = file_open (RESOLV_FILE)))
{
client->command (client, "input", "critical", "netcfg/error_cfg", NULL);
client->command (client, "go", NULL);
i = 0;
if (domain)
fprintf (fp, "search %s\n", domain);
while (nameservers[i])
{
fprintf (fp, "nameserver %s\n", num2dot (nameservers[i++]));
}
fclose (fp);
}
return 0;
}
#endif /* STATIC */
}
char *
@ -587,7 +566,6 @@ get_interface ()
char *ptr = buf;
char *inter;
debconf_unseen ("netcfg/choose_interface");
getif_start ();
while ((inter = getif (1)) != NULL)
@ -605,12 +583,18 @@ get_interface ()
if (ptr == buf)
{
client->command (client, "input", "high", "netcfg/no_interfaces", NULL);
client->command (client, "go", NULL);
return -1;
debconf_unseen ("netcfg/no_interfaces");
ptr = debconf_input ("critical", "netcfg/no_interfaces");
if (ptr) {
interface = strdup (ptr);
return 0;
}
else
return -1;
}
debconf_unseen ("netcfg/choose_interface");
debconf_subst ("netcfg/choose_interface", "ifchoices", buf);
ptr = debconf_input ("critical", "netcfg/choose_interface");
@ -638,3 +622,77 @@ file_open (char *path)
}
}
int
do_system (char *s){
int rv;
#ifdef DEBUG
fprintf(stderr, "executing '%s'\n", s);
#endif
rv = system(s);
#ifdef DEBUG
fprintf(stderr, "rv = %d\n", rv);
#endif
return rv;
}
/**
* dot2num and num2dot
* Copyright: Karl Hammar, Aspö Data
*/
char *
dot2num (u_int32_t * num, char *dot)
{
char *p = dot - 1;
char *e;
int ix;
unsigned long val;
if (!dot)
return NULL;
*num = 0;
for (ix = 0; ix < 4; ix++)
{
*num <<= 8;
p++;
val = strtoul (p, &e, 10);
if (e == p)
val = 0;
else if (val > 255)
return NULL;
*num += val;
/*printf("%#8x, %#2x\n", *num, val); */
if (ix < 3 && *e != '.')
return NULL;
p = e;
}
return p;
}
static char num2dot_buf[16];
char *
num2dot (u_int32_t num)
{
int byte[4];
int ix;
char *dot = num2dot_buf;
if (num == 0)
return NULL;
for (ix = 3; ix >= 0; ix--)
{
byte[ix] = num & 0xff;
num >>= 8;
}
sprintf (dot, "%d.%d.%d.%d", byte[0], byte[1], byte[2], byte[3]);
return dot;
}

Loading…
Cancel
Save