diff options
Diffstat (limited to 'mdk-stage1/network.c')
-rw-r--r-- | mdk-stage1/network.c | 89 |
1 files changed, 88 insertions, 1 deletions
diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index 13085cfcc..3e6039494 100644 --- a/mdk-stage1/network.c +++ b/mdk-stage1/network.c @@ -31,6 +31,7 @@ #include <stdio.h> #include <netdb.h> #include <resolv.h> +#include <dirent.h> #include "stage1.h" #include "frontend.h" @@ -85,7 +86,7 @@ int configure_net_device(struct interface_info * intf) s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { log_perror("socket"); - error_message_net(); + error_message_net(); return 1; } @@ -187,6 +188,7 @@ char * domain = NULL; struct in_addr gateway = { 0 }; struct in_addr dns_server = { 0 }; struct in_addr dns_server2 = { 0 }; +struct in_addr next_server = { 0 }; static int add_default_route(void) { @@ -888,3 +890,88 @@ enum return_type http_prepare(void) return RETURN_OK; } + + +enum return_type ka_prepare(void) +{ + int server_failure=1; /* Number of time we've failed to find a ka server */ + + enum return_type results; + + if (!ramdisk_possible()) { + stg1_error_message("KA install needs more than %d Mbytes of memory (detected %d Mbytes).", + MEM_LIMIT_RAMDISK, total_memory()); + return RETURN_ERROR; + } + + results = intf_select_and_up(); + + if (results != RETURN_OK) + return results; + + FILE *f = fopen ("/ka/tftpserver","w"); + if (f != NULL) + { fprintf(f,"%s\n",inet_ntoa(next_server)); /* Writing the NEXT_SERVER value of the DHCP Request in the /ka/tftpserver file */ + fclose(f); + } + + log_message("KA: Trying to retrieve stage2 from server"); + do { + results=ka_wait_for_stage2(); /* We are trying to get a valid stage 2 (rescue) */ + if (results != RETURN_OK) { + return results; } + else { + char dir[255] = STAGE2_LOCATION; + strcat(dir,"/ka"); + DIR *dp = opendir(dir); /* Trying to open STAGE2_LOCATION/ka directory */ + + if (! dp) { /* Does the STAGE2_LOCATION/ka directory exists ? = Does the rescue with ka well downloaded ?*/ + log_message("KA: Server not found !"); + if (umount (STAGE2_LOCATION)) { /* Be sure that the STAGE2_LOCATION isn't mounted after receiving a wrong rescue */ + log_perror("KA: Unable to umount STAGE2"); + } + int cpt; + + if (server_failure++ == KA_MAX_RETRY){ /* if the KA server can't be reach KA_MAX_RETRY times */ + char * reboot_launch[] = { "/sbin/reboot", NULL}; + for (cpt=5; cpt>0; cpt--) { + wait_message("!!! Can t reach a valid KA server !!! (Rebooting in %d sec)",cpt); + sleep (1); + } + execve(reboot_launch[0], reboot_launch, grab_env()); /* Rebooting the computer to avoid infinite loop on ka mode */ + } + + for (cpt=5; cpt>0; cpt--) { + wait_message("KA server not found ! (Try %d/%d in %d sec)",server_failure,KA_MAX_RETRY,cpt); + sleep (1); + } + remove_wait_message(); + results=RETURN_BACK; /* We should try another time*/ + continue; + } + + if (dp) { + log_message("KA: Stage 2 downloaded successfully"); + closedir(dp); /* Closing the /ka directory */ + server_failure=1; /* Resetting server_failure */ + results=RETURN_OK; + } + } + + log_message("KA: Preparing chroot"); + set_param(MODE_RAMDISK); + return RETURN_OK; + + // if (IS_RESCUE) { /* if we are in rescue mode */ + // save_stuff_for_rescue(); /* Saving resolve.conf */ + // if (umount (STAGE2_LOCATION)) { /* Unmounting STAGE2 elseif kernel can't mount it ! */ + // log_perror("KA: Unable to umount STAGE2"); + // return RETURN_ERROR; + // } + // } + } while (results == RETURN_BACK); + + + method_name = strdup("ka"); + return RETURN_OK; +} |