@ -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 ;
}