Browse Source

* Reworked state engine of netcfg-static to change order of

questions:
  -IP address
  (-Point to Point)
  -Netmask
  -Gateway
  -DNS servers
  -Machine name
  -Domain name

* change debconf priority of nameserver question to high, don't
  know how this was supposed to work without nameservers

r6052
master
Gaudenz Steinlin 20 years ago
parent
commit
359c225b24
  1. 5
      debian/changelog
  2. 243
      netcfg-static.c
  3. 45
      netcfg.c
  4. 6
      netcfg.h

5
debian/changelog

@ -6,8 +6,11 @@ netcfg (0.31) unstable; urgency=low
- apply debconf templates polishing
(Thanks to Christian Perrier and
Chris Tillman) (Closes: #219633)
- reworked state machine in netcfg-static to
show iface, ipaddr, p2p, netmask, gateway,
nameservers, hostname, domain, confirm
-- Gaudenz Steinlin <steinlin@sowipc4.unibe.ch> Thu, 13 Nov 2003 20:44:54 +0100
-- Gaudenz Steinlin <steinlin@sowipc4.unibe.ch> Thu, 13 Nov 2003 22:31:31 +0100
netcfg (0.30) unstable; urgency=low

243
netcfg-static.c

@ -46,103 +46,71 @@ static u_int32_t pointopoint = 0;
static struct debconfclient *client;
static char *none;
static int netcfg_get_static()
int netcfg_get_ipaddress(struct debconfclient *client)
{
char *ptr;
int ret = 0;
enum { STATE_QUIT, STATE_GET_IPADDR, STATE_GET_POINTTOPOINT, STATE_GET_NETMASK,
STATE_GET_GATEWAY, STATE_GATEWAY_UNREACHABLE } state = STATE_GET_IPADDR;
ipaddress = network = broadcast = netmask = gateway = pointopoint =
0;
/* Simple state machine to handle goback buttons */
while (state != STATE_QUIT) {
switch (state) {
case STATE_GET_IPADDR:
ret = my_debconf_input(client,"critical", "netcfg/get_ipaddress", &ptr);
if (ret == 30) {
/* back the whole way out */
return 30;
} else {
dot2num(&ipaddress, ptr);
debconf_subst(client, "netcfg/confirm_static", "ipaddress",
(ipaddress ? num2dot(ipaddress) : none));
if (strncmp(interface, "plip", 4) == 0
|| strncmp(interface, "slip", 4) == 0
|| strncmp(interface, "ctc", 3) == 0
|| strncmp(interface, "escon", 5) == 0)
state = STATE_GET_POINTTOPOINT;
else
state = STATE_GET_NETMASK;
}
break;
case STATE_GET_POINTTOPOINT:
ret = my_debconf_input(client,"critical", "netcfg/get_pointopoint", &ptr);
if (ret == 30) {
state = STATE_GET_IPADDR;
} else {
dot2num(&pointopoint, ptr);
dot2num(&netmask, "255.255.255.255");
network = ipaddress;
gateway = pointopoint;
state = STATE_QUIT;
}
break;
case STATE_GET_NETMASK:
ret = my_debconf_input(client,"critical", "netcfg/get_netmask", &ptr);
if (ret == 30) {
state = STATE_GET_IPADDR;
} else {
dot2num(&netmask, ptr);
gateway = ipaddress & netmask;
debconf_set(client, "netcfg/get_gateway", num2dot(gateway+1));
state = STATE_GET_GATEWAY;
}
break;
int ret;
char *ptr;
ret = my_debconf_input(client,"critical", "netcfg/get_ipaddress", &ptr);
if (ret)
return ret;
case STATE_GET_GATEWAY:
ret = my_debconf_input(client, "critical", "netcfg/get_gateway", &ptr);
if (ret == 30) {
state = STATE_GET_NETMASK;
} else {
dot2num(&gateway, ptr);
network = ipaddress & netmask;
if (gateway && ((gateway & netmask) != network))
state = STATE_GATEWAY_UNREACHABLE;
else
state = STATE_QUIT;
}
break;
case STATE_GATEWAY_UNREACHABLE:
debconf_input(client, "high", "netcfg/gateway_unreachable");
debconf_go(client);
state = STATE_GET_GATEWAY;
break;
dot2num(&ipaddress, ptr);
return 0;
}
case STATE_QUIT:
break;
}
}
int netcfg_get_pointopoint(struct debconfclient *client)
{
int ret;
char *ptr;
ret = my_debconf_input(client,"critical", "netcfg/get_pointopoint", &ptr);
if (ret)
return ret;
dot2num(&pointopoint, ptr);
dot2num(&netmask, "255.255.255.255");
network = ipaddress;
gateway = pointopoint;
return 0;
}
debconf_subst(client, "netcfg/confirm_static", "netmask",
(netmask ? num2dot(netmask) : none));
int netcfg_get_netmask(struct debconfclient *client)
{
int ret;
char *ptr;
ret = my_debconf_input(client,"critical", "netcfg/get_netmask", &ptr);
debconf_subst(client, "netcfg/confirm_static", "gateway",
(gateway ? num2dot(gateway) : none));
if (ret)
return ret;
dot2num(&netmask, ptr);
network = ipaddress & netmask;
broadcast = (network | ~netmask);
debconf_subst(client, "netcfg/confirm_static", "pointopoint",
(pointopoint ? num2dot(pointopoint) : none));
/* Preseed gateway */
gateway = ipaddress & netmask;
debconf_set(client, "netcfg/get_gateway", num2dot(gateway+1));
broadcast = (network | ~netmask);
return 0;
}
int netcfg_get_gateway(struct debconfclient *client)
{
int ret;
char *ptr;
ret = my_debconf_input(client, "critical", "netcfg/get_gateway", &ptr);
if (ret)
return ret;
dot2num(&gateway, ptr);
return 0;
}
static int netcfg_write_static()
{
@ -237,10 +205,14 @@ static int netcfg_activate_static()
int main(int argc, char *argv[])
{
int ret = 0, goback = 0;
int num_interfaces =0;
char *ptr;
char *nameservers = NULL;
enum { QUIT, GET_COMMON, GET_STATIC, CONFIRM_STATIC} state = GET_COMMON;
ipaddress = network = broadcast = netmask = gateway = pointopoint =
0;
enum { BACKUP, GET_INTERFACE, GET_HOSTNAME, GET_DOMAIN, GET_NAMESERVERS,
GET_IPADDRESS, GET_POINTTOPOINT, GET_NETMASK, GET_GATEWAY,
GATEWAY_UNREACHABLE, CONFIRM, QUIT} state = GET_INTERFACE;
client = debconfclient_new();
debconf_capb(client, "backup");
@ -250,42 +222,89 @@ int main(int argc, char *argv[])
while (state != QUIT) {
switch (state) {
case GET_COMMON:
ret = netcfg_get_common(client, &interface, &hostname, &domain,
&nameservers, goback);
if (ret == 30) {
exit (10); /* goback the whole way out */
} else {
goback = 0;
state = GET_STATIC;
}
case BACKUP:
exit (10); // Back the whole way out
break;
case GET_INTERFACE:
state = (netcfg_get_interface (client, &interface, &num_interfaces)) ?
BACKUP : GET_IPADDRESS;
break;
case GET_STATIC:
ret = netcfg_get_static();
if (ret == 30) {
goback = 1;
state = GET_COMMON;
} else {
state = CONFIRM_STATIC;
case GET_IPADDRESS:
if (netcfg_get_ipaddress (client)) {
// if num_interfaces ==1 , interface question won't be asked. Go further back
state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE;
} else {
if (strncmp(interface, "plip", 4) == 0
|| strncmp(interface, "slip", 4) == 0
|| strncmp(interface, "ctc", 3) == 0
|| strncmp(interface, "escon", 5) == 0)
state = GET_POINTTOPOINT;
else
state = GET_NETMASK;
}
break;
case CONFIRM_STATIC:
case GET_POINTTOPOINT:
state = netcfg_get_pointopoint(client) ?
GET_IPADDRESS : GET_NAMESERVERS;
break;
case GET_NETMASK:
state = netcfg_get_netmask(client) ?
GET_IPADDRESS : GET_GATEWAY;
break;
case GET_GATEWAY:
if (netcfg_get_gateway(client))
state = GET_NETMASK;
else
if (gateway && ((gateway & netmask) != network))
state = GATEWAY_UNREACHABLE;
else
state = GET_NAMESERVERS;
break;
case GATEWAY_UNREACHABLE:
debconf_capb(client); // Turn off backup
debconf_input(client, "high", "netcfg/gateway_unreachable");
debconf_go(client);
state = GET_GATEWAY;
debconf_capb(client, "backup");
break;
case GET_NAMESERVERS:
state = (netcfg_get_nameservers (client, &nameservers)) ?
GET_GATEWAY : GET_HOSTNAME;
break;
case GET_HOSTNAME:
state = (netcfg_get_hostname(client, &hostname)) ?
GET_NAMESERVERS : GET_DOMAIN;
break;
case GET_DOMAIN:
state = (netcfg_get_domain (client, &domain)) ?
GET_HOSTNAME : CONFIRM;
break;
case CONFIRM:
debconf_subst(client, "netcfg/confirm_static", "interface", interface);
debconf_subst(client, "netcfg/confirm_static", "ipaddress",
(ipaddress ? num2dot(ipaddress) : none));
debconf_subst(client, "netcfg/confirm_static", "pointopoint",
(pointopoint ? num2dot(pointopoint) : none));
debconf_subst(client, "netcfg/confirm_static", "netmask",
(netmask ? num2dot(netmask) : none));
debconf_subst(client, "netcfg/confirm_static", "gateway",
(gateway ? num2dot(gateway) : none));
debconf_subst(client, "netcfg/confirm_static", "hostname", hostname);
debconf_subst(client, "netcfg/confirm_static", "domain", (domain ? domain : none));
debconf_subst(client, "netcfg/confirm_static", "domain",
(domain ? domain : none));
debconf_subst(client, "netcfg/confirm_static", "nameservers",
(nameservers ? nameservers : none));
netcfg_nameservers_to_array(nameservers, nameserver_array);
debconf_capb(client); // Turn off backup for yes/no confirmation
my_debconf_input(client, "medium", "netcfg/confirm_static", &ptr);
state = strstr(ptr, "true") ? QUIT : GET_COMMON;
state = strstr(ptr, "true") ? QUIT : GET_INTERFACE;
debconf_capb(client, "backup");
break;
case QUIT:
break;
}

45
netcfg.c

@ -400,7 +400,7 @@ netcfg_get_nameservers (struct debconfclient *client, char **nameservers)
char *ptr;
int ret;
ret = my_debconf_input(client, "medium", "netcfg/get_nameservers", &ptr);
ret = my_debconf_input(client, "high", "netcfg/get_nameservers", &ptr);
if (*nameservers)
free(*nameservers);
*nameservers = NULL;
@ -408,49 +408,6 @@ netcfg_get_nameservers (struct debconfclient *client, char **nameservers)
*nameservers = strdup(ptr);
return ret;
}
/*
* @brief Get details common to both static & DHCP net configurations
* @return 0 on success, 30 to goback.
* If ret==0, interface, hostname, domain, nameservers set.
*/
int
netcfg_get_common(struct debconfclient *client, char **interface,
char **hostname, char **domain, char **nameservers, int goback)
{
int num_interfaces =0;
enum { GET_INTERFACE, GET_HOSTNAME, GET_DOMAIN, GET_NAMESERVERS, GOBACK, QUIT }
state;
state = goback ? GET_NAMESERVERS : GET_INTERFACE ;
/* netcfg_get_*() return either 30 to goback, or 0 to continue */
while (state != QUIT) {
switch (state) {
case GOBACK:
return 30;
break;
case GET_INTERFACE:
state = (netcfg_get_interface (client, interface, &num_interfaces)) ? GOBACK: GET_HOSTNAME;
break;
case GET_HOSTNAME:
state = (netcfg_get_hostname (client, hostname)) ? GOBACK: GET_DOMAIN;
break;
case GET_DOMAIN:
state = (netcfg_get_domain (client, domain)) ? GET_HOSTNAME : GET_NAMESERVERS;
break;
case GET_NAMESERVERS:
state = (netcfg_get_nameservers (client, nameservers)) ? GET_DOMAIN : QUIT;
break;
case QUIT:
break;
}
}
return 0;
}
void netcfg_nameservers_to_array(char *nameservers, u_int32_t array[])

6
netcfg.h

@ -40,9 +40,9 @@ extern int netcfg_get_interface(struct debconfclient *client, char **interface,
extern int netcfg_get_hostname(struct debconfclient *client, char **hostname);
extern int netcfg_get_common (struct debconfclient *client, char **interface,
char **hostname, char **domain,
char **nameservers, int goback);
extern int netcfg_get_nameservers (struct debconfclient *client, char **nameservers);
extern int netcfg_get_domain(struct debconfclient *client, char **domain);
extern int my_debconf_input(struct debconfclient *client, char *priority, char *template, char **result);

Loading…
Cancel
Save