X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Finstall%2Bsetup%2Fsetup%2Fnetworking.c;h=29c00cba1c899f5a17c59421bc1a68ea920b90b9;hb=8cc01c836a674b3c10444dd6ef672aa28f48c6fe;hp=ef5deb2c73704d416a2301546fdb39dd80df017c;hpb=59de0b00db1c180965df666517765ced67509787;p=people%2Fpmueller%2Fipfire-2.x.git diff --git a/src/install+setup/setup/networking.c b/src/install+setup/setup/networking.c index ef5deb2c73..29c00cba1c 100644 --- a/src/install+setup/setup/networking.c +++ b/src/install+setup/setup/networking.c @@ -24,14 +24,21 @@ extern char **ctr; extern int automode; -#define HAS_ORANGE (configtype == 1 || configtype == 3 || configtype == 5 || configtype == 7) -#define HAS_RED (configtype == 2 || configtype == 3 || configtype == 6 || configtype == 7) -#define HAS_BLUE (configtype == 4 || configtype == 5 || configtype == 6 || configtype == 7) -#define RED_IS_NOT_ETH (configtype == 0 || configtype == 1 || configtype == 4 || configtype == 5) +#define HAS_GREEN 1 +#define HAS_RED (configtype == 1 || configtype == 2 || configtype == 3 || configtype == 4) +#define HAS_ORANGE (configtype == 2 || configtype == 4) +#define HAS_BLUE (configtype == 3 || configtype == 4) +#define RED_IS_NOT_ETH (configtype == 0) + +//#define HAS_ORANGE (configtype == 1 || configtype == 3 || configtype == 5 || configtype == 7) +//#define HAS_RED (configtype == 2 || configtype == 3 || configtype == 6 || configtype == 7) +//#define HAS_BLUE (configtype == 4 || configtype == 5 || configtype == 6 || configtype == 7) +//#define RED_IS_NOT_ETH (configtype == 0 || configtype == 1 || configtype == 4 || configtype == 5) extern struct nic nics[]; +extern struct knic knics[]; -char *configtypenames[] = { +/* char *configtypenames[] = { "GREEN (RED is modem/ISDN)", "GREEN + ORANGE (RED is modem/ISDN)", "GREEN + RED", @@ -41,6 +48,23 @@ char *configtypenames[] = { "GREEN + BLUE + RED", "GREEN + ORANGE + BLUE + RED", NULL }; +*/ +char *configtypenames[] = { + "GREEN", + "GREEN + RED", + "GREEN + RED + ORANGE", + "GREEN + RED + BLUE", + "GREEN + RED + ORANGE + BLUE", + NULL }; +int configtypecards[] = { + 1, // "GREEN", + 2, // "GREEN + RED", + 3, // "GREEN + RED + ORANGE", + 3, // "GREEN + RED + BLUE", + 4 // "GREEN + RED + ORANGE + BLUE", +}; + + int netaddresschange; int oktoleave(char *errormessage); @@ -56,10 +80,18 @@ int handlenetworking(void) { int done; int choice; + int found; char errormessage[STRING_SIZE]; netaddresschange = 0; + fprintf(flog,"Enter HandleNetworking\n"); // #### Debug #### + + found = scan_network_cards(); + fprintf(flog,"found %d cards\n",found); // #### Debug #### + found = init_knics(); + fprintf(flog,"found %d kcards\n",found); // #### Debug #### + done = 0; while (!done) { @@ -102,11 +134,14 @@ int handlenetworking(void) { runcommandwithstatus("/etc/rc.d/init.d/network stop", ctr[TR_PUSHING_NETWORK_DOWN]); + + rename_nics(); + runcommandwithstatus("/etc/rc.d/init.d/network start", ctr[TR_PULLING_NETWORK_UP]); } } - + create_udev(); return 1; } @@ -124,19 +159,33 @@ int oktoleave(char *errormessage) } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); - if (configtype < 0 || configtype > 7) configtype = 0; + if (configtype < 1 || configtype > 4) configtype = 0; - if (HAS_BLUE) + if (HAS_GREEN) { - strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); + strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp); if (!(strlen(temp))) { - strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]); + strcpy(errormessage, ctr[TR_NO_GREEN_INTERFACE]); goto EXIT; } - if (!(interfacecheck(kv, "BLUE"))) + if (!(interfacecheck(kv, "GREEN"))) { - strcpy(errormessage, ctr[TR_MISSING_BLUE_IP]); + strcpy(errormessage, "(TR) GRÜNE IP nicht konfiguriert.\n"); //ctr[TR_MISSING_GREEN_IP]); + goto EXIT; + } + } + if (HAS_RED) + { + strcpy(temp, ""); findkey(kv, "RED_DEV", temp); + if (!(strlen(temp))) + { + strcpy(errormessage, ctr[TR_NO_RED_INTERFACE]); + goto EXIT; + } + if (!(interfacecheck(kv, "RED"))) + { + strcpy(errormessage, ctr[TR_MISSING_RED_IP]); goto EXIT; } } @@ -154,17 +203,32 @@ int oktoleave(char *errormessage) goto EXIT; } } - if (HAS_RED) + if (HAS_BLUE) { - strcpy(temp, ""); findkey(kv, "RED_DEV", temp); + strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); if (!(strlen(temp))) { - strcpy(errormessage, ctr[TR_NO_RED_INTERFACE]); + strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]); goto EXIT; } - if (!(interfacecheck(kv, "RED"))) + if (!(interfacecheck(kv, "BLUE"))) { - strcpy(errormessage, ctr[TR_MISSING_RED_IP]); + strcpy(errormessage, ctr[TR_MISSING_BLUE_IP]); + goto EXIT; + } + } + if (configtype == 0) + { + strcpy(temp, ""); findkey(kv, "DNS1", temp); + if (!(strlen(temp))) + { + strcpy(errormessage, "(TR) Kein DNS eingetragen\n"); + goto EXIT; + } + strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); + if (!(strlen(temp))) + { + strcpy(errormessage, "(TR) Kein default Gateway eingetragen.\n"); goto EXIT; } } @@ -206,7 +270,7 @@ int firstmenu(void) strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]); strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); x = atol(temp); - if (x < 0 || x > 7) x = 0; + if (x < 1 || x > 4) x = 0; /* Format heading bit. */ snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x], networkrestart); @@ -227,52 +291,66 @@ int configtypemenu(void) struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE] = "0"; char message[1000]; - int choice; + int choise, found; int rc; + fprintf(flog,"Enter ConfigMenu\n"); + if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } + + found = scan_network_cards(); + fprintf(flog,"found %d Card\'s\n", found ); // #### Debug #### - findkey(kv, "CONFIG_TYPE", temp); choice = atol(temp); - sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME); - rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5, - 6, configtypenames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); + findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp); + + 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); + if ( configtypecards[choise] > found ) { + sprintf(message, "(TR) Nicht genuegend Netzwerkkarten fuer diese Auswahl gefunden.\n\nBenoetigt: %d\nGefunden: %d\n", configtypecards[choise], found); + errorbox(message); + } + } + while ( configtypecards[choise] > found); if (rc == 0 || rc == 1) { - runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange", - ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); - - sprintf(temp, "%d", choice); +// if (automode != 0) runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange", ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); + + sprintf(temp, "%d", choise); replacekeyvalue(kv, "CONFIG_TYPE", temp); - replacekeyvalue(kv, "ORANGE_DEV", ""); - replacekeyvalue(kv, "BLUE_DEV", ""); - replacekeyvalue(kv, "RED_DEV", ""); + clear_card_entry(_RED_CARD_); + clear_card_entry(_ORANGE_CARD_); + clear_card_entry(_BLUE_CARD_); + writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); netaddresschange = 1; } - freekeyvalues(kv); return 0; } + + /* Driver menu. Choose drivers.. */ int drivermenu(void) { - FILE *fp; struct keyvalue *kv = initkeyvalues(); - char message[1000], macaddr[STRING_SIZE]; - char temp_line[STRING_SIZE]; - char temp[STRING_SIZE], temp1[STRING_SIZE]; - struct knic knics[20], *pknics; - pknics = knics; + char message[STRING_SIZE]; + char temp[STRING_SIZE]; + int configtype; - int rc, i = 0, kcount = 0; + int i, rc, kcount = 0, neednics; //i = 0, count = 0, + + fprintf(flog,"Enter drivermenu\n"); // #### Debug #### if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { @@ -284,101 +362,86 @@ int drivermenu(void) strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); - if (configtype == 0) - { - freekeyvalues(kv); - errorbox(ctr[TR_YOUR_CONFIGURATION_IS_SINGLE_GREEN_ALREADY_HAS_DRIVER]); - return 0; - } - strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]); - - if( (fp = fopen(KNOWN_NICS, "r")) == NULL ) - { - fprintf(flog,"Couldn't open " KNOWN_NICS); - return 1; - } - while (fgets(temp_line, STRING_SIZE, fp) != NULL) - { - strcpy(knics[kcount].description, strtok(temp_line,";")); - strcpy(knics[kcount].macaddr , strtok(NULL,";")); - if (strlen(knics[kcount].macaddr) > 5 ) kcount++; - } - fclose(fp); - - strcpy(macaddr, ctr[TR_UNSET]); - findkey(kv, "GREEN_MACADDR", macaddr); - for (i=0; i < kcount; i++) - { // Check if the nic is already in use - if (strcmp(pknics[i].macaddr, macaddr) == NULL ) - break; + + kcount = 0; // counter to find knowing nics. + neednics = 0; // counter to use needing nics. + if (HAS_GREEN) { + sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description); + strcat(message, temp); + if (strlen(knics[_GREEN_CARD_].macaddr) ) { + sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]); + strcat(message, temp); + } + neednics++; } - sprintf(temp1, "GREEN: %s (%s / green0)\n", pknics[i].description, pknics[i].macaddr); - strcat(message, temp1); - - if (HAS_BLUE) { - strcpy(macaddr, ctr[TR_UNSET]); - findkey(kv, "BLUE_MACADDR", macaddr); - for (i=0; i < kcount; i++) - { // Check if the nic is already in use - if (strcmp(pknics[i].macaddr, macaddr) == NULL ) - break; + if (HAS_RED) { + sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description); + strcat(message, temp); + if (strlen(knics[_RED_CARD_].macaddr) ) { + sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]); + strcat(message, temp); } - sprintf(temp1, "BLUE: %s (%s / blue0)\n", pknics[i].description, pknics[i].macaddr); - strcat(message, temp1); + neednics++; } if (HAS_ORANGE) { - strcpy(macaddr, ctr[TR_UNSET]); - findkey(kv, "ORANGE_MACADDR", macaddr); - for (i=0; i < kcount; i++) - { // Check if the nic is already in use - if (strcmp(pknics[i].macaddr, macaddr) == NULL ) - break; + sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description); + strcat(message, temp); + if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { + sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]); + strcat(message, temp); } - sprintf(temp1, "ORANGE: %s (%s / orange0)\n", pknics[i].description, pknics[i].macaddr); - strcat(message, temp1); + neednics++; } - if (HAS_RED) { - strcpy(macaddr, ctr[TR_UNSET]); - findkey(kv, "RED_MACADDR", macaddr); - for (i=0; i < kcount; i++) - { // Check if the nic is already in use - if (strcmp(pknics[i].macaddr, macaddr) == NULL ) - break; + if (HAS_BLUE) { + sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description); + strcat(message, temp); + if (strlen(knics[_BLUE_CARD_].macaddr)) { + sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]); + strcat(message, temp); } - sprintf(temp1, "RED: %s (%s / red0)\n", pknics[i].description, pknics[i].macaddr); - strcat(message, temp1); + neednics++; } - strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]); - rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], - ctr[TR_CANCEL], message); - if (rc == 0 || rc == 1) + + for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++; + fprintf(flog,"found %d knowing Card\'s\n", kcount); // #### DEBUG #### + + if (neednics = kcount) { + strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]); + rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], + ctr[TR_CANCEL], message); + if (rc == 0 || rc == 1) + { + /* Shit, got to do something.. */ + changedrivers(); + } + } else { +// strcat(message, "\nEs wurden noch nicht alle Netzwerkkarten konfiguriert.\n"); +// newtWinMessage(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], message); /* Shit, got to do something.. */ changedrivers(); } - freekeyvalues(kv); return 1; } -int cardassigned(char *colour) +int set_menu_entry_for(int *nr, int *card) { - char command[STRING_SIZE]; - sprintf(command, "grep -q %s < /etc/udev/rules.d/30-persistent-network.rules 2>/dev/null", colour); - if (system(command)) - return 0; - else - return 1; + } int changedrivers(void) { struct keyvalue *kv = initkeyvalues(); - char temp[STRING_SIZE]; + char temp[STRING_SIZE], message[STRING_SIZE]; int configtype; int green = 0, red = 0, blue = 0, orange = 0; + char MenuInhalt[10][180]; + char *pMenuInhalt[10]; + int count = 0, choise = 0, rc; + int NicEntry[10]; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { @@ -386,35 +449,114 @@ int changedrivers(void) errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } - + fprintf(flog,"stop network on red, blue and orange\n"); // #### Debug #### 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 == 0) { green = 1; } else if (configtype == 1) - { green = 1; orange = 1; } - else if (configtype == 2) { green = 1; red = 1; } - else if (configtype == 3) + else if (configtype == 2) { green = 1; red = 1; orange = 1; } - else if (configtype == 4) - { green = 1; blue = 1; } - else if (configtype == 5) - { green = 1; blue = 1; orange = 1; } - else if (configtype == 6) + else if (configtype == 3) { green = 1; red = 1; blue = 1; } - else if (configtype == 7) - { green = 1; red = 1; blue = 1; orange = 1; } - - if (green && !cardassigned("green")) - nicmenu("green"); - if (red && !cardassigned("red")) - nicmenu("red"); - if (blue && !cardassigned("blue")) - nicmenu("blue"); - if (orange && !cardassigned("orange")) - nicmenu("orange"); + else if (configtype == 4) + { green = 1; red=1; orange=1; blue = 1; } +// else if (configtype == 5) +// { green = 1; blue = 1; orange = 1; } +// else if (configtype == 6) +// { green = 1; red = 1; blue = 1; } +// else if (configtype == 7) +// { green = 1; red = 1; blue = 1; orange = 1; } + + fprintf(flog,"found: g=%d r=%d o=%d b=%d\n",green, red, orange, blue); // #### Debug #### + + do + { + count = 0; + strcpy(message, "(TR) Bitte wählen Sie das Interface aus das geaendert werden soll.\n\n"); + + if (green) { + strcpy(MenuInhalt[count], "GREEN"); + pMenuInhalt[count] = MenuInhalt[count]; + NicEntry[_GREEN_CARD_] = count; + sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description); + strcat(message, temp); + if ( strlen(knics[_GREEN_CARD_].macaddr) ) { + sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]); + strcat(message, temp); + } + count++; + } + + if (red) { + strcpy(MenuInhalt[count], "RED"); + pMenuInhalt[count] = MenuInhalt[count]; + NicEntry[_RED_CARD_] = count; +// fprintf(flog,"found: %s as entry %d\n", MenuInhalt[count], NicEntry[count]); // #### Debug #### + sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description); + strcat(message, temp); + if ( strlen(knics[_RED_CARD_].macaddr) ) { + sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]); + strcat(message, temp); + } + count++; + } + + if (orange) { + strcpy(MenuInhalt[count], "ORANGE"); + pMenuInhalt[count] = MenuInhalt[count]; + NicEntry[_ORANGE_CARD_] = count; +// fprintf(flog,"found: %s as entry %d\n", MenuInhalt[count], NicEntry[count]); // #### Debug #### + sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description); + strcat(message, temp); + if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { + sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]); + strcat(message, temp); + } + count++; + } + + if (blue) { + strcpy(MenuInhalt[count], "BLUE"); + pMenuInhalt[count] = MenuInhalt[count]; + NicEntry[_BLUE_CARD_] = count; +// fprintf(flog,"found: %s as entry %d\n", MenuInhalt[count], NicEntry[count]); // #### Debug #### + sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description); + strcat(message, temp); + if ( strlen(knics[_BLUE_CARD_].macaddr) ) { + sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]); + strcat(message, temp); + } + count++; + } + pMenuInhalt[count] = NULL; + + rc = newtWinMenu("(TR) Netcard Farbe", message, 70, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_SELECT], "(TR) Entfernen" , ctr[TR_DONE], NULL); + + if ( rc == 0 || rc == 1) { +// write_configs_netudev(pnics[choise].description, pnics[choise].macaddr, colour); + // insert nic to colourcard + if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_); + if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_); + if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_); + if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_); + netaddresschange = 1; + } else if (rc == 2) { + if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_); + if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_); + if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_); + if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_); + netaddresschange = 1; + } +// else { +// errorbox("Sie haben keine Netzwerkkarte ausgewaehlt.\n"); +// return 1; +// } + } + while ( rc <= 2); // writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); @@ -592,7 +734,7 @@ int dnsgatewaymenu(void) return 0; } - strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); +/* strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); if (RED_IS_NOT_ETH) @@ -601,7 +743,7 @@ int dnsgatewaymenu(void) errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]); return 0; } - +*/ entries[DNS1].text = ctr[TR_PRIMARY_DNS]; strcpy(temp, ""); findkey(kv, "DNS1", temp); values[DNS1] = strdup(temp);