]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/install+setup/libsmooth/netstuff.c
Merge remote-tracking branch 'origin/next' into thirteen
[ipfire-2.x.git] / src / install+setup / libsmooth / netstuff.c
index dd17bf68c1545ce78fea57e4cf673ea7a105d5a8..de5c558c0e6091a1cb5d93194a09d70064f4aff6 100644 (file)
@@ -30,8 +30,8 @@ newtComponent netmaskentry;
 newtComponent statictyperadio;
 newtComponent dhcptyperadio;
 newtComponent pppoetyperadio;
-newtComponent pptptyperadio;
 newtComponent dhcphostnameentry;
+newtComponent dhcpforcemtuentry;
 
 /* acceptable character filter for IP and netmaks entry boxes */
 static int ip_input_filter(newtComponent entry, void * data, int ch, int cursor)
@@ -50,11 +50,13 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
        char *addressresult;
        char *netmaskresult;
        char *dhcphostnameresult;
+       char *dhcpforcemturesult;
        struct newtExitStruct es;
        newtComponent header;
        newtComponent addresslabel;
        newtComponent netmasklabel;
        newtComponent dhcphostnamelabel;
+       newtComponent dhcpforcemtulabel;
        newtComponent ok, cancel;       
        char message[1000];
        char temp[STRING_SIZE];
@@ -62,19 +64,20 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
        char netmaskfield[STRING_SIZE];
        char typefield[STRING_SIZE];
        char dhcphostnamefield[STRING_SIZE];
+       char dhcpforcemtufield[STRING_SIZE];
        int error;
        int result = 0;
        char type[STRING_SIZE];
        int startstatictype = 0;
        int startdhcptype = 0;
        int startpppoetype = 0;
-       int startpptptype = 0;
                
        /* Build some key strings. */
        sprintf(addressfield, "%s_ADDRESS", colour);
        sprintf(netmaskfield, "%s_NETMASK", colour);
        sprintf(typefield, "%s_TYPE", colour);
        sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour);
+       sprintf(dhcpforcemtufield, "%s_DHCP_FORCE_MTU", colour);
                
        sprintf(message, ctr[TR_INTERFACE], colour);
        newtCenteredWindow(44, (typeflag ? 18 : 12), message);
@@ -93,26 +96,33 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
                if (strcmp(temp, "STATIC") == 0) startstatictype = 1;
                if (strcmp(temp, "DHCP") == 0) startdhcptype = 1;
                if (strcmp(temp, "PPPOE") == 0) startpppoetype = 1;
-               if (strcmp(temp, "PPTP") == 0) startpptptype = 1;
                statictyperadio = newtRadiobutton(2, 4, ctr[TR_STATIC], startstatictype, NULL);
-               dhcptyperadio = newtRadiobutton(2, 5, "DHCP", startdhcptype, statictyperadio);
-               pppoetyperadio = newtRadiobutton(2, 6, "PPPOE", startpppoetype, dhcptyperadio);
-               pptptyperadio = newtRadiobutton(2, 7, "PPTP", startpptptype, pppoetyperadio);
+               dhcptyperadio = newtRadiobutton(2, 5, ctr[TR_DHCP], startdhcptype, statictyperadio);
+               pppoetyperadio = newtRadiobutton(2, 6, ctr[TR_PPP_DIALUP], startpppoetype, dhcptyperadio);
                newtFormAddComponents(networkform, statictyperadio, dhcptyperadio, 
-                       pppoetyperadio, pptptyperadio, NULL);
+                       pppoetyperadio, NULL);
                newtComponentAddCallback(statictyperadio, networkdialogcallbacktype, NULL);
                newtComponentAddCallback(dhcptyperadio, networkdialogcallbacktype, NULL);
                newtComponentAddCallback(pppoetyperadio, networkdialogcallbacktype, NULL);
-               newtComponentAddCallback(pptptyperadio, networkdialogcallbacktype, NULL);
-               dhcphostnamelabel = newtTextbox(2, 9, 18, 1, 0);
+               dhcphostnamelabel = newtTextbox(2, 8, 18, 1, 0);
                newtTextboxSetText(dhcphostnamelabel, ctr[TR_DHCP_HOSTNAME]);
+               dhcpforcemtulabel = newtTextbox(2, 9, 18, 1, 0);
+               newtTextboxSetText(dhcpforcemtulabel, ctr[TR_DHCP_FORCE_MTU]);
                strcpy(temp, defaultdhcphostname);
                findkey(kv, dhcphostnamefield, temp);
-               dhcphostnameentry = newtEntry(20, 9, temp, 20, &dhcphostnameresult, 0);
-               newtFormAddComponent(networkform, dhcphostnamelabel);           
-               newtFormAddComponent(networkform, dhcphostnameentry);   
+               dhcphostnameentry = newtEntry(20, 8, temp, 20, &dhcphostnameresult, 0);
+               strcpy(temp, "");
+               findkey(kv, dhcpforcemtufield, temp);
+               dhcpforcemtuentry = newtEntry(20, 9, temp, 20, &dhcpforcemturesult, 0);
+               newtFormAddComponent(networkform, dhcphostnamelabel);
+               newtFormAddComponent(networkform, dhcphostnameentry);
+               newtFormAddComponent(networkform, dhcpforcemtulabel);
+               newtFormAddComponent(networkform, dhcpforcemtuentry);
                if (startdhcptype == 0)
-                       newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
+                       {
+                               newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
+                               newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
+                       }
        }
        /* Address */
        addresslabel = newtTextbox(2, (typeflag ? 11 : 4) + 0, 18, 1, 0);
@@ -121,7 +131,7 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
        findkey(kv, addressfield, temp);
        addressentry = newtEntry(20, (typeflag ? 11 : 4) + 0, temp, 20, &addressresult, 0);
        newtEntrySetFilter(addressentry, ip_input_filter, NULL);
-       if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 )
+       if (typeflag == 1 && startstatictype == 0)
                newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
        newtFormAddComponent(networkform, addresslabel);
        newtFormAddComponent(networkform, addressentry);
@@ -132,7 +142,7 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
        strcpy(temp, "255.255.255.0"); findkey(kv, netmaskfield, temp);
        netmaskentry = newtEntry(20, (typeflag ? 11 : 4) + 1, temp, 20, &netmaskresult, 0);
        newtEntrySetFilter(netmaskentry, ip_input_filter, NULL);
-       if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 
+       if (typeflag == 1 && startstatictype == 0) 
                newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
 
        newtFormAddComponent(networkform, netmasklabel);
@@ -160,7 +170,7 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
                        strcpy(type, "STATIC");
                        if (typeflag)
                                gettype(type);
-                       if (strcmp(type, "STATIC") == 0 || strcmp(type, "PPTP") == 0 )
+                       if (strcmp(type, "STATIC") == 0)
                        {               
                                if (inet_addr(addressresult) == INADDR_NONE)
                                {
@@ -189,7 +199,8 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
                                if (typeflag)
                                {
                                        replacekeyvalue(kv, dhcphostnamefield, dhcphostnameresult);
-                                       if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0)
+                                       replacekeyvalue(kv, dhcpforcemtufield, dhcpforcemturesult);
+                                       if (strcmp(type, "STATIC") != 0)
                                        {
                                                replacekeyvalue(kv, addressfield, "0.0.0.0");
                                                replacekeyvalue(kv, netmaskfield, "0.0.0.0");
@@ -210,7 +221,14 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
                                setnetaddress(kv, colour);
                                result = 1;
                        }
-               }                       
+               }
+               /* Workaround for a bug that dhcp radiobutton also end the dialog at arm
+               */
+               else {
+                       if (es.u.co != cancel) {
+                               error = 1;
+                       }
+               }
        }
        while (error);
 
@@ -231,8 +249,6 @@ int gettype(char *type)
                strcpy(type, "DHCP");
        else if (selected == pppoetyperadio)
                strcpy(type, "PPPOE");
-       else if (selected == pptptyperadio)
-               strcpy(type, "PPTP");
        else
                strcpy(type, "ERROR");
        
@@ -292,7 +308,7 @@ void networkdialogcallbacktype(newtComponent cm, void *data)
        
        gettype(type);
 
-       if (strcmp(type, "STATIC") != 0  && strcmp(type, "PPTP") != 0 )
+       if (strcmp(type, "STATIC") != 0)
        {
                newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
                newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
@@ -303,12 +319,17 @@ void networkdialogcallbacktype(newtComponent cm, void *data)
                newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
        }
        if (strcmp(type, "DHCP") == 0)
+       {
                newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
+               newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
+       }
        else
+       {
                newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);               
-               
+               newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);               
+       }
        newtRefresh();
-       newtDrawForm(networkform);      
+       newtDrawForm(networkform);
 }
 
 int interfacecheck(struct keyvalue *kv, char *colour)
@@ -335,37 +356,6 @@ int probecards(char *driver, char *driveroptions )
        return 0;
 }
 
-/* ### alter strupper ###
-char *strupper(char *s)
-{
- int n;
- for (n=0;s[n];n++) s[n]=toupper(s[n]);
- return s;
-}
-*/
-
-/* neuer StringUpper, wird zur Zeit nicht benutzt da UTF-8 nicht geht.
-void strupper(unsigned char *string)
-{
-       unsigned char *str;
-       for (str = string; *str != '\0'; str++)
-               if (!(*str & 0x80) && islower(*str)) 
-                       *str = toupper(*str);
-}
-*/
-
-/* int ismacaddr(char *ismac)
-{
-       char *a;
-       fprintf(flog,"Check is MAC true\n"); // #### Debug ####
-       for (a = ismac; *a; a++) {
-               sprintf(flog,"%c\n", *a);       // #### Debug ####
-               if (*a != ':' && !isxdigit(*a)) return 0;       // is int != ':' or not hexdigit then exit
-       }
-       return 1;
-}
-*/
-
 int get_knic(int card)         //returns "0" for zero cards or error and "1" card is found.
 {
        struct keyvalue *kv = initkeyvalues();
@@ -383,7 +373,7 @@ int get_knic(int card)              //returns "0" for zero cards or error and "1" card is fo
        strcpy(temp, ""); findkey(kv, searchstr, temp);
        if (strlen(temp)) {
                strcpy(knics[ card ].macaddr, temp);
-               strcpy(knics[ card ].colour, "GREEN");
+               strcpy(knics[ card ].colour, ucolourcard[card]);
 
                sprintf(searchstr, "%s_DESCRIPTION", ucolourcard[card]);
                findkey(kv, searchstr, temp);
@@ -397,6 +387,7 @@ int get_knic(int card)              //returns "0" for zero cards or error and "1" card is fo
                strcpy(knics[ card ].description, ctr[TR_UNSET]);
                ret_value = 0;
        }
+       freekeyvalues(kv);
 
        return ret_value;
 }
@@ -412,13 +403,13 @@ int init_knics(void)
        return found;
 }
 
-int fmt_exists(const char *fname) {    /* Check it's any File or Directory */
+int fmt_exists(const char *fname) {    /* Check if it is any file or directory */
        struct stat st;
        if (stat(fname, &st) == -1) return 0;
        else return 1;
 }
 
-int is_interface_up(char *card) {      /* Check is interface UP */
+int is_interface_up(char *card) {      /* Check if the interface is UP */
        char temp[STRING_SIZE];
 
        sprintf(temp,"ip link show dev %s | grep -q UP", card);
@@ -433,7 +424,6 @@ int rename_device(char *old_name, char *new_name) {
                fprintf(flog,"Device not found: %s\n",old_name);
                return 0;
        }
-//     fprintf(flog,"NIC: %s wurde in %s umbenannt.\n", old_name, new_name);   // #### Debug ####
        sprintf(temp,"/sbin/ip link set dev %s name %s",old_name ,new_name );
        mysystem(temp);
 
@@ -442,7 +432,6 @@ int rename_device(char *old_name, char *new_name) {
 
 char g_temp[STRING_SIZE]="";
 char* readmac(char *card) {
-//     fprintf(flog,"Enter readmac... NIC: %s\n", card);       // #### Debug ####
        FILE *fp;
        char temp[STRING_SIZE], mac[20];
 
@@ -459,8 +448,6 @@ char* readmac(char *card) {
 }
 
 char* find_nic4mac(char *findmac) {
-       fprintf(flog,"Enter find_name4nic... Search for %s\n", findmac);        // #### Debug ####
-
        DIR *dir;
        struct dirent *dirzeiger;
        char temp[STRING_SIZE], temp2[STRING_SIZE];
@@ -476,7 +463,6 @@ char* find_nic4mac(char *findmac) {
                        sprintf(temp2, "%s", readmac((*dirzeiger).d_name) );
                        if (strcmp(findmac, temp2) == 0) {
                                sprintf(temp,"%s", (*dirzeiger).d_name);
-//                             fprintf(flog,"MAC: %s is NIC: %s\n", findmac, temp);    // #### Debug ####
                                break;
                        }
                }
@@ -507,43 +493,27 @@ int rename_nics(void) {
        int fnics = scan_network_cards();
        char nic2find[STRING_SIZE], temp[STRING_SIZE];
 
-       fprintf(flog,"Renaming Nics\n");        // #### Debug ####
-
        for(i=0; i<4; i++)
-               if (strcmp(knics[i].macaddr, ""))                                                                       // Wird das Interface benutzt ?
+               if (strcmp(knics[i].macaddr, ""))
                        for(j=0; j<fnics; j++)
-                               if(strcmp(knics[i].macaddr, nics[j].macaddr) == 0) {                                    // suche den aktuellen Namen
+                               if(strcmp(knics[i].macaddr, nics[j].macaddr) == 0) {
                                        sprintf(nic2find,"%s0",lcolourcard[i]);
-//                                     fprintf(flog,"search4: %s\n", nic2find);        // #### Debug ####
-                                       if(strcmp(nic2find, nics[j].nic)) {                                             // hat das Interface nicht den Namen ?
-//                                             fprintf(flog,"cmp nic2find false\n");   // #### Debug ####
-//                                             fprintf(flog,"is nic( %s ) up ?\n",nics[j].nic);        // #### Debug ####
-
-                                               if(is_interface_up(nics[j].nic)) {                                      // wurde das Interface gestartet ?
-//                                                     fprintf(flog,"%s is UP, shutting down...\n",nics[j].nic);       // #### Debug ####
+                                       if(strcmp(nic2find, nics[j].nic)) {
+                                               if(is_interface_up(nics[j].nic)) {
                                                        nic_shutdown(nics[j].nic);
                                                }
                                                sprintf(temp,SYSDIR "/%s", nic2find);
-//                                             fprintf(flog,"exists ?--> %s\n", temp); // #### Debug ####
-                                               if(fmt_exists(temp)) {                                                  // Ist der Name schon in Benutzung ?
-//                                                     fprintf(flog,"is exists %s\n", nic2find);       // #### Debug ####
-                                                       for(k=0; k<fnics; k++)                          // Suche das Interface
+                                               if(fmt_exists(temp)) {
+                                                       for(k=0; k<fnics; k++)
                                                                if (strcmp(nics[k].nic, nic2find) == 0 ) {
-                                                                       if(is_interface_up(nics[k].nic)) {              // wurde das Interface gestartet ?
-//                                                                             fprintf(flog,"%s is UP, shutting down...\n",nics[k].nic);       // #### Debug ####
+                                                                       if(is_interface_up(nics[k].nic)) {
                                                                                nic_shutdown(nics[k].nic);
                                                                        }
-                                                                       sprintf(temp,"dummy%i",k);                      // Benenne NIC nach "dummy[k]" um.
-//                                                                     fprintf(flog,"set dummy%i\n", k);       // #### Debug ####
+                                                                       sprintf(temp,"dummy%i",k);
                                                                        if (rename_device(nics[k].nic, temp)) strcpy(nics[k].nic, temp);
                                                                }
                                                }
-                                               if (rename_device(nics[j].nic, nic2find)) strcpy(nics[j].nic, nic2find);        // Benenne NIC um.
-
-//                                             if(strncmp(nics[j].nic,"dummy",5)) {
-//                                                     fprintf(flog,"%s is down, start up...\n",nics[j].nic);  // #### Debug ####
-//                                                     nic_startup(nics[j].nic);
-//                                             }
+                                               if (rename_device(nics[j].nic, nic2find)) strcpy(nics[j].nic, nic2find);
                                        }
                                }
 }
@@ -554,7 +524,6 @@ int create_udev(void)
        FILE *fp;
        int i;
 
-       fprintf(flog,"Enter create_udev: "UDEV_NET_CONF"\n"); // #### Debug ####
        if ( (fp = fopen(UDEV_NET_CONF, "w")) == NULL ) {
                fprintf(stderr,"Couldn't open" UDEV_NET_CONF);
                return 1;
@@ -563,8 +532,7 @@ int create_udev(void)
        for (i = 0 ; i < 4 ; i++)
        {
                if (strcmp(knics[i].macaddr, "")) {
-                       fprintf(fp,"ACTION==\"add\", SUBSYSTEM==\"net\", SYSFS{address}==\"%s\", NAME=\"%s0\" # %s\n", knics[i].macaddr, lcolourcard[i], knics[i].description);
-                       fprintf(flog,"Write %s\n",lcolourcard[i]); // #### Debug ####
+                       fprintf(fp,"ACTION==\"add\", SUBSYSTEM==\"net\", SYSFS{type}==\"1\", SYSFS{address}==\"%s\", NAME=\"%s0\" # %s\n", knics[i].macaddr, lcolourcard[i], knics[i].description);
                }
        }
        fclose(fp);
@@ -617,9 +585,7 @@ int scan_network_cards(void)
        
        if (!(scanned_nics_read_done))
        {
-               fprintf(flog,"Enter scan_network_cards\n"); // #### Debug ####
                mysystem("/bin/probenic.sh");
-               // Read our scanned nics
                if( (fp = fopen(SCANNED_NICS, "r")) == NULL )
                {
                        fprintf(stderr,"Couldn't open "SCANNED_NICS);
@@ -654,16 +620,8 @@ int nicmenu(int colour)
        char MenuInhalt[20][180];
        char *pMenuInhalt[20];
        
-//     strcpy( message , pnics[count].macaddr);
-//     while (strcmp(message, "")) {
-//             count++;
-//             strcpy( message , pnics[count].macaddr);
-//     }
-
        while (strcmp(nics[count].macaddr, "")) count++;                        // 2 find how many nics in system
        for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++;        // loop to find all knowing nics
-       fprintf(flog, "Enter NicMenu\n");                                       // #### Debug ####
-       fprintf(flog, "count nics %i\ncount knics %i\n", count, kcount);        // #### Debug ####
 
        // If new nics are found...
        if (count > kcount) {
@@ -673,12 +631,10 @@ int nicmenu(int colour)
                        for (j=0 ; j <= kcount ; j++) {
                                if (strcmp(nics[ i ].macaddr, knics[ j ].macaddr) == 0 ) {
                                        nic_in_use = 1;
-                                       fprintf(flog,"NIC \"%s\" is in use.\n", nics[ i ].macaddr); // #### Debug ####
                                        break;
                                }
                        }
                        if (!(nic_in_use)) {
-                               fprintf(flog,"NIC \"%s\" is free.\n", nics[ i ].macaddr); // #### Debug ####
                                if ( strlen(nics[i].description) < 55 ) 
                                        sprintf(MenuInhalt[mcount], "%.*s",  strlen(nics[i].description)-2, nics[i].description+1);
                                else {
@@ -700,17 +656,12 @@ int nicmenu(int colour)
 
                pMenuInhalt[mcount] = NULL;
 
-//             sprintf(message, "Es wurde(n) %d freie Netzwerkkarte(n) in Ihrem System gefunden.\nBitte waehlen Sie im naechsten Dialog eine davon aus.\n", count);
-//             newtWinMessage("NetcardMenu", ctr[TR_OK], message);
-
                sprintf(message, ctr[TR_CHOOSE_NETCARD], ucolourcard[colour]);
                rc = newtWinMenu( ctr[TR_NETCARDMENU2], message, 50, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_OK], ctr[TR_SELECT], ctr[TR_CANCEL], NULL);
                                
                if ( rc == 0 || rc == 1) {
                        write_configs_netudev(found_NIC_as_Card[choise], colour);
-               } else if (rc == 2) {
-//                     manualdriver("pcnet32","");
-               }
+               }
                return 0;
        } else {
                // We have to add here that you can manually add a device
@@ -747,7 +698,6 @@ int clear_card_entry(int card)
        writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
        freekeyvalues(kv);
 
-       fprintf(flog,"Card \"%s\" cleared\n",ucolourcard[card]); // #### Debug ####
        return 0;
 }
 
@@ -756,19 +706,11 @@ int ask_clear_card_entry(int card)
        char message[STRING_SIZE];
        int rc;
 
-       sprintf(message, ctr[TR_REMOVE_CARD] "%s \n", ucolourcard[card]);
+       sprintf(message, ctr[TR_REMOVE_CARD], ucolourcard[card]);
        rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message);                               
 
        if ( rc = 0 || rc == 1) {
                clear_card_entry(card);
-//             sprintf(temp1, "%s_DEV", ucolour);
-//             sprintf(temp2, "%s_MACADDR", ucolour);
-//             replacekeyvalue(kv, temp1, "");
-//             replacekeyvalue(kv, temp2, "");
-//             sprintf(temp1, "%s_DESCRIPTION", ucolour);
-//             replacekeyvalue(kv, temp1, "");
-
-//             writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
        } else return 1;
 
        return 0;