]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - src/install+setup/setup/networking.c
Merge branch 'core51'
[people/teissler/ipfire-2.x.git] / src / install+setup / setup / networking.c
index 740f352f4a7e82fe34987edffb3b36388cde5fd4..9c13717158f44f701d33da5886dbf36a262b7550 100644 (file)
@@ -47,7 +47,7 @@ int configtypecards[] = {
 
 int netaddresschange;
 
-int oktoleave(char *errormessage);
+int oktoleave(void);
 int firstmenu(void);
 int configtypemenu(void);
 int drivermenu(void);
@@ -61,7 +61,6 @@ int handlenetworking(void)
        int done;
        int choice;
        int found;
-       char errormessage[STRING_SIZE];
        
        netaddresschange = 0;
 
@@ -92,10 +91,7 @@ int handlenetworking(void)
                                break;
                                
                        case 0:
-                               if (oktoleave(errormessage))
-                                       done = 1;
-                               else
-                                       errorbox(errormessage);
+                               if (oktoleave()) done = 1;
                                break;
                                
                        default:
@@ -121,11 +117,12 @@ int handlenetworking(void)
        return 1;
 }
 
-int oktoleave(char *errormessage)
+int oktoleave(void)
 {
        struct keyvalue *kv = initkeyvalues();
        char temp[STRING_SIZE];
        int configtype;
+       int rc;
        
        if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
        {
@@ -134,35 +131,43 @@ int oktoleave(char *errormessage)
                return 0;
        }       
 
-       strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
-       if (configtype < 1 || configtype > 4) configtype = 0;
+       strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
+       if (configtype < 1 || configtype > 4) configtype = 1;
 
        if (HAS_GREEN)
        {
                strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp);
                if (!(strlen(temp)))
                {
-                       strcpy(errormessage, ctr[TR_NO_GREEN_INTERFACE]);
-                       goto EXIT;
+                       errorbox(ctr[TR_NO_GREEN_INTERFACE]);
+                       freekeyvalues(kv);
+                       return 0;
                }
                if (!(interfacecheck(kv, "GREEN")))
                {
-                       strcpy(errormessage, ctr[TR_MISSING_GREEN_IP]);
-                       goto EXIT;
+                       errorbox(ctr[TR_MISSING_GREEN_IP]);
+                       freekeyvalues(kv);
+                       return 0;
                }
        }
        if (HAS_RED)
        {
+
                strcpy(temp, ""); findkey(kv, "RED_DEV", temp);
                if (!(strlen(temp)))
                {
-                       strcpy(errormessage, ctr[TR_NO_RED_INTERFACE]);
-                       goto EXIT;
+                       rc = newtWinChoice(ctr[TR_ERROR], ctr[TR_OK], ctr[TR_IGNORE], ctr[TR_NO_RED_INTERFACE]);
+                       if (rc == 0 || rc == 1)
+                       {
+                               freekeyvalues(kv);
+                               return 0;
+                       }
                }
                if (!(interfacecheck(kv, "RED")))
                {
-                       strcpy(errormessage, ctr[TR_MISSING_RED_IP]);
-                       goto EXIT;
+                       errorbox(ctr[TR_MISSING_RED_IP]);
+                       freekeyvalues(kv);
+                       return 0;
                }
        }
        if (HAS_ORANGE)
@@ -170,13 +175,15 @@ int oktoleave(char *errormessage)
                strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp);
                if (!(strlen(temp)))
                {
-                       strcpy(errormessage, ctr[TR_NO_ORANGE_INTERFACE]);
-                       goto EXIT;
+                       errorbox(ctr[TR_NO_ORANGE_INTERFACE]);
+                       freekeyvalues(kv);
+                       return 0;
                }
                if (!(interfacecheck(kv, "ORANGE")))
                {
-                       strcpy(errormessage, ctr[TR_MISSING_ORANGE_IP]);
-                       goto EXIT;
+                       errorbox(ctr[TR_MISSING_ORANGE_IP]);
+                       freekeyvalues(kv);
+                       return 0;
                }
        }
        if (HAS_BLUE)
@@ -184,38 +191,37 @@ int oktoleave(char *errormessage)
                strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
                if (!(strlen(temp)))
                {
-                       strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]);
-                       goto EXIT;
+                       errorbox(ctr[TR_NO_BLUE_INTERFACE]);
+                       freekeyvalues(kv);
+                       return 0;
                }
                if (!(interfacecheck(kv, "BLUE")))
                {
-                       strcpy(errormessage, ctr[TR_MISSING_BLUE_IP]);
-                       goto EXIT;
+                       errorbox(ctr[TR_MISSING_BLUE_IP]);
+                       freekeyvalues(kv);
+                       return 0;
                }
        }
-       if (configtype == 0)
+       
+       strcpy(temp, ""); findkey(kv, "RED_TYPE", temp);
+       if ((configtype == 0) || (strcmp(temp, "STATIC") == 0))
        {
                strcpy(temp, ""); findkey(kv, "DNS1", temp);
                if (!(strlen(temp)))
                {
-                       strcpy(errormessage, ctr[TR_MISSING_DNS]);
-                       goto EXIT;
+                       errorbox(ctr[TR_MISSING_DNS]);
+                       freekeyvalues(kv);
+                       return 0;
                }
                strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
                if (!(strlen(temp)))
                {
-                       strcpy(errormessage, ctr[TR_MISSING_DEFAULT]);
-                       goto EXIT;
+                       errorbox(ctr[TR_MISSING_DEFAULT]);
+                       freekeyvalues(kv);
+                       return 0;
                }
        }
-       strcpy(errormessage, "");
-EXIT:
-       freekeyvalues(kv);
-       
-       if (strlen(errormessage))
-               return 0;
-       else
-               return 1;
+       return 1;
 }
 
        
@@ -230,7 +236,7 @@ int firstmenu(void)
        static int choice = 0;
        struct keyvalue *kv = initkeyvalues();
        char message[1000];
-       char temp[STRING_SIZE];
+       char temp[STRING_SIZE] = "1";
        int x;
        int result;
        char networkrestart[STRING_SIZE] = "";
@@ -245,10 +251,12 @@ int firstmenu(void)
        if (netaddresschange) 
                strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]);
 
-       strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); x = atol(temp);
-       if (x < 1 || x > 4) x = 0;
+       strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); 
+       x = atol(temp);
+       x--;
+       if (x < 0 || x > 4) x = 0;
        /* Format heading bit. */
-       snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x-1],
+       snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x],
                networkrestart);
        rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6,
                        sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);
@@ -265,12 +273,10 @@ int firstmenu(void)
 int configtypemenu(void)
 {
        struct keyvalue *kv = initkeyvalues();
-       char temp[STRING_SIZE] = "0";
+       char temp[STRING_SIZE] = "1";
        char message[1000];
        int choise, found;
-       int rc;
-
-       fprintf(flog,"Enter ConfigMenu\n");
+       int rc, configtype;
 
        if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
        {
@@ -284,8 +290,6 @@ int configtypemenu(void)
        findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp);
        choise--;
 
-       do
-       {
                sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME);
                rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5,
                        6, configtypenames, &choise, ctr[TR_OK], ctr[TR_CANCEL], NULL);
@@ -293,17 +297,19 @@ int configtypemenu(void)
                        sprintf(message, ctr[TR_NOT_ENOUGH_INTERFACES] , configtypecards[choise], found);
                        errorbox(message);
                }
-       }
-       while ( configtypecards[choise] > found);
 
        if (rc == 0 || rc == 1)
        {
                choise++;
                sprintf(temp, "%d", choise);
                replacekeyvalue(kv, "CONFIG_TYPE", temp);
-               clear_card_entry(_RED_CARD_);
-               clear_card_entry(_ORANGE_CARD_);
-               clear_card_entry(_BLUE_CARD_);
+               configtype = atol(temp);
+               if (!HAS_RED)
+                       clear_card_entry(_RED_CARD_);
+               if (!HAS_ORANGE)
+                       clear_card_entry(_ORANGE_CARD_);
+               if (!HAS_BLUE)
+                       clear_card_entry(_BLUE_CARD_);
 
                writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
                netaddresschange = 1;
@@ -313,17 +319,15 @@ int configtypemenu(void)
        return 0;
 }
 
-
-
 /* Driver menu.  Choose drivers.. */
 int drivermenu(void)
 {
        struct keyvalue *kv = initkeyvalues();
        char message[STRING_SIZE];
-       char temp[STRING_SIZE];
+       char temp[STRING_SIZE] = "1";
 
        int configtype;
-       int i, rc, kcount = 0, neednics; //i = 0, count = 0,
+       int i, rc, kcount = 0, neednics;
 
        if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
        {
@@ -332,13 +336,19 @@ int drivermenu(void)
                return 0;
        }
 
-       strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
-       configtype = atol(temp);
-       
+       if (findkey(kv, "CONFIG_TYPE", temp))
+               configtype = atol(temp);
+       else {
+               fprintf(flog,"setting CONFIG_TYPE = %s\n",temp);
+               configtype = atol(temp);
+               replacekeyvalue(kv, "CONFIG_TYPE", temp);
+               writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
+       }
+
        strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]);
 
-       kcount = 0;     // counter to find knowing nics.
-       neednics = 0;   // counter to use needing nics.
+       kcount = 0;
+       neednics = 0;
        if (HAS_GREEN) {
                sprintf(temp, "GREEN:  %s\n", knics[_GREEN_CARD_].description);
                strcat(message, temp);
@@ -376,7 +386,9 @@ int drivermenu(void)
                neednics++;
        }
 
-       for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++;
+       for ( i=0 ; i<4; i++)
+               if (strcmp(knics[i].macaddr, ""))
+                       kcount++;
 
        if (neednics = kcount)
        {
@@ -385,11 +397,9 @@ int drivermenu(void)
                ctr[TR_CANCEL], message);
                if (rc == 0 || rc == 1)
                {
-                       /* Shit, got to do something.. */
                        changedrivers();
                }
        } else {
-               /* Shit, got to do something.. */
                changedrivers();
        }
        freekeyvalues(kv);
@@ -419,8 +429,9 @@ int changedrivers(void)
                errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
                return 0;
        }
-       runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
-               ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]);
+       if (automode == 0)
+               runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
+                       ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]);
 
        findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
        if (configtype == 1)
@@ -431,6 +442,8 @@ int changedrivers(void)
                { green = 1; red = 1; blue = 1; }
        else if (configtype == 4)
                { green = 1; red=1; orange=1; blue = 1; }
+       else if (configtype == "")
+         { green = 1; red = 1; }
 
        do
        {