]> git.ipfire.org Git - ipfire-2.x.git/blob - src/install+setup/setup/networking.c
ethtool: Update to 3.16
[ipfire-2.x.git] / src / install+setup / setup / networking.c
1 /* SmoothWall setup program.
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 * (c) Lawrence Manning, 2001
7 * The big one: networking.
8 *
9 */
10
11 #include "setup.h"
12
13 #define DNS1 0
14 #define DNS2 1
15 #define DEFAULT_GATEWAY 2
16 #define DNSGATEWAY_TOTAL 3
17
18 extern FILE *flog;
19 extern char *mylog;
20
21 extern char **ctr;
22
23 extern int automode;
24
25 #define HAS_GREEN 1
26 #define HAS_RED (configtype == 1 || configtype == 2 || configtype == 3 || configtype == 4)
27 #define HAS_ORANGE (configtype == 2 || configtype == 4)
28 #define HAS_BLUE (configtype == 3 || configtype == 4)
29 #define RED_IS_NOT_ETH (configtype == 0)
30
31 extern struct nic nics[];
32 extern struct knic knics[];
33
34 char *configtypenames[] = {
35 "GREEN + RED",
36 "GREEN + RED + ORANGE",
37 "GREEN + RED + BLUE",
38 "GREEN + RED + ORANGE + BLUE",
39 NULL };
40 int configtypecards[] = {
41 2, // "GREEN + RED",
42 3, // "GREEN + RED + ORANGE",
43 3, // "GREEN + RED + BLUE",
44 4 // "GREEN + RED + ORANGE + BLUE",
45 };
46
47
48 int netaddresschange;
49
50 int oktoleave(void);
51 int firstmenu(void);
52 int configtypemenu(void);
53 int drivermenu(void);
54 int changedrivers(void);
55 int greenaddressmenu(void);
56 int addressesmenu(void);
57 int dnsgatewaymenu(void);
58
59 int handlenetworking(void)
60 {
61 int done;
62 int choice;
63 int found;
64
65 netaddresschange = 0;
66
67 found = scan_network_cards();
68 found = init_knics();
69
70 done = 0;
71 while (!done)
72 {
73 choice = firstmenu();
74
75 switch (choice)
76 {
77 case 1:
78 configtypemenu();
79 break;
80
81 case 2:
82 drivermenu();
83 break;
84
85 case 3:
86 addressesmenu();
87 break;
88
89 case 4:
90 dnsgatewaymenu();
91 break;
92
93 case 0:
94 if (oktoleave()) done = 1;
95 break;
96
97 default:
98 break;
99 }
100 }
101
102 if (automode == 0)
103 {
104 /* Restart networking! */
105 if (netaddresschange)
106 {
107 runcommandwithstatus("/etc/rc.d/init.d/network stop",
108 ctr[TR_PUSHING_NETWORK_DOWN]);
109
110 rename_nics();
111
112 runcommandwithstatus("/etc/rc.d/init.d/network start",
113 ctr[TR_PULLING_NETWORK_UP]);
114 }
115 } else {
116 rename_nics();
117 }
118 create_udev();
119 return 1;
120 }
121
122 int oktoleave(void)
123 {
124 struct keyvalue *kv = initkeyvalues();
125 char temp[STRING_SIZE];
126 int configtype;
127 int rc;
128
129 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
130 {
131 freekeyvalues(kv);
132 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
133 return 0;
134 }
135
136 strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
137 if (configtype < 1 || configtype > 4) configtype = 1;
138
139 if (HAS_GREEN)
140 {
141 strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp);
142 if (!(strlen(temp)))
143 {
144 errorbox(ctr[TR_NO_GREEN_INTERFACE]);
145 freekeyvalues(kv);
146 return 0;
147 }
148 if (!(interfacecheck(kv, "GREEN")))
149 {
150 errorbox(ctr[TR_MISSING_GREEN_IP]);
151 freekeyvalues(kv);
152 return 0;
153 }
154 }
155 if (HAS_RED)
156 {
157
158 strcpy(temp, ""); findkey(kv, "RED_DEV", temp);
159 if (!(strlen(temp)))
160 {
161 rc = newtWinChoice(ctr[TR_ERROR], ctr[TR_OK], ctr[TR_IGNORE], ctr[TR_NO_RED_INTERFACE]);
162 if (rc == 0 || rc == 1)
163 {
164 freekeyvalues(kv);
165 return 0;
166 }
167 }
168 if (!(interfacecheck(kv, "RED")))
169 {
170 errorbox(ctr[TR_MISSING_RED_IP]);
171 freekeyvalues(kv);
172 return 0;
173 }
174 }
175 if (HAS_ORANGE)
176 {
177 strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp);
178 if (!(strlen(temp)))
179 {
180 errorbox(ctr[TR_NO_ORANGE_INTERFACE]);
181 freekeyvalues(kv);
182 return 0;
183 }
184 if (!(interfacecheck(kv, "ORANGE")))
185 {
186 errorbox(ctr[TR_MISSING_ORANGE_IP]);
187 freekeyvalues(kv);
188 return 0;
189 }
190 }
191 if (HAS_BLUE)
192 {
193 strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
194 if (!(strlen(temp)))
195 {
196 errorbox(ctr[TR_NO_BLUE_INTERFACE]);
197 freekeyvalues(kv);
198 return 0;
199 }
200 if (!(interfacecheck(kv, "BLUE")))
201 {
202 errorbox(ctr[TR_MISSING_BLUE_IP]);
203 freekeyvalues(kv);
204 return 0;
205 }
206 }
207
208 strcpy(temp, ""); findkey(kv, "RED_TYPE", temp);
209 if ((configtype == 0) || (strcmp(temp, "STATIC") == 0))
210 {
211 strcpy(temp, ""); findkey(kv, "DNS1", temp);
212 if (!(strlen(temp)))
213 {
214 errorbox(ctr[TR_MISSING_DNS]);
215 freekeyvalues(kv);
216 return 0;
217 }
218 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
219 if (!(strlen(temp)))
220 {
221 errorbox(ctr[TR_MISSING_DEFAULT]);
222 freekeyvalues(kv);
223 return 0;
224 }
225 }
226 return 1;
227 }
228
229
230 /* Shows the main menu and a summary of the current settings. */
231 int firstmenu(void)
232 {
233 char *sections[] = { ctr[TR_NETWORK_CONFIGURATION_TYPE],
234 ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS],
235 ctr[TR_ADDRESS_SETTINGS],
236 ctr[TR_DNS_AND_GATEWAY_SETTINGS], NULL };
237 int rc;
238 static int choice = 0;
239 struct keyvalue *kv = initkeyvalues();
240 char message[1000];
241 char temp[STRING_SIZE] = "1";
242 int x;
243 int result;
244 char networkrestart[STRING_SIZE] = "";
245
246 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
247 {
248 freekeyvalues(kv);
249 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
250 return 0;
251 }
252
253 if (netaddresschange)
254 strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]);
255
256 strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp);
257 x = atol(temp);
258 x--;
259 if (x < 0 || x > 4) x = 0;
260 /* Format heading bit. */
261 snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x],
262 networkrestart);
263 rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6,
264 sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);
265
266 if (rc == 0 || rc == 1)
267 result = choice + 1;
268 else
269 result = 0;
270
271 return result;
272 }
273
274 /* Here they choose general network config, number of nics etc. */
275 int configtypemenu(void)
276 {
277 struct keyvalue *kv = initkeyvalues();
278 char temp[STRING_SIZE] = "1";
279 char message[1000];
280 int choise, found;
281 int rc, configtype;
282
283 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
284 {
285 freekeyvalues(kv);
286 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
287 return 0;
288 }
289
290 found = scan_network_cards();
291
292 findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp);
293 choise--;
294
295 sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME);
296 rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5,
297 6, configtypenames, &choise, ctr[TR_OK], ctr[TR_CANCEL], NULL);
298 if ( configtypecards[choise] > found ) {
299 sprintf(message, ctr[TR_NOT_ENOUGH_INTERFACES] , configtypecards[choise], found);
300 errorbox(message);
301 }
302
303 if (rc == 0 || rc == 1)
304 {
305 choise++;
306 sprintf(temp, "%d", choise);
307 replacekeyvalue(kv, "CONFIG_TYPE", temp);
308 configtype = atol(temp);
309 if (!HAS_RED)
310 clear_card_entry(_RED_CARD_);
311 if (!HAS_ORANGE)
312 clear_card_entry(_ORANGE_CARD_);
313 if (!HAS_BLUE)
314 clear_card_entry(_BLUE_CARD_);
315
316 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
317 netaddresschange = 1;
318 }
319 freekeyvalues(kv);
320
321 return 0;
322 }
323
324 /* Driver menu. Choose drivers.. */
325 int drivermenu(void)
326 {
327 struct keyvalue *kv = initkeyvalues();
328 char message[STRING_SIZE];
329 char temp[STRING_SIZE] = "1";
330
331 int configtype;
332 int i, rc, kcount = 0, neednics;
333
334 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
335 {
336 freekeyvalues(kv);
337 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
338 return 0;
339 }
340
341 if (findkey(kv, "CONFIG_TYPE", temp))
342 configtype = atol(temp);
343 else {
344 fprintf(flog,"setting CONFIG_TYPE = %s\n",temp);
345 configtype = atol(temp);
346 replacekeyvalue(kv, "CONFIG_TYPE", temp);
347 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
348 }
349
350 strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]);
351
352 kcount = 0;
353 neednics = 0;
354 if (HAS_GREEN) {
355 sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description);
356 strcat(message, temp);
357 if (strlen(knics[_GREEN_CARD_].macaddr) ) {
358 sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]);
359 strcat(message, temp);
360 }
361 neednics++;
362 }
363 if (HAS_RED) {
364 sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description);
365 strcat(message, temp);
366 if (strlen(knics[_RED_CARD_].macaddr) ) {
367 sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]);
368 strcat(message, temp);
369 }
370 neednics++;
371 }
372 if (HAS_ORANGE) {
373 sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description);
374 strcat(message, temp);
375 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
376 sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]);
377 strcat(message, temp);
378 }
379 neednics++;
380 }
381 if (HAS_BLUE) {
382 sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description);
383 strcat(message, temp);
384 if (strlen(knics[_BLUE_CARD_].macaddr)) {
385 sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]);
386 strcat(message, temp);
387 }
388 neednics++;
389 }
390
391 for ( i=0 ; i<4; i++)
392 if (strcmp(knics[i].macaddr, ""))
393 kcount++;
394
395 if (neednics = kcount)
396 {
397 strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]);
398 rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK],
399 ctr[TR_CANCEL], message);
400 if (rc == 0 || rc == 1)
401 {
402 changedrivers();
403 }
404 } else {
405 changedrivers();
406 }
407 freekeyvalues(kv);
408
409 return 1;
410 }
411
412 int set_menu_entry_for(int *nr, int *card)
413 {
414
415 }
416
417 int changedrivers(void)
418 {
419 struct keyvalue *kv = initkeyvalues();
420 char temp[STRING_SIZE], message[STRING_SIZE];
421 int configtype;
422 int green = 0, red = 0, blue = 0, orange = 0;
423 char MenuInhalt[10][180];
424 char *pMenuInhalt[10];
425 int count = 0, choise = 0, rc;
426 int NicEntry[10];
427
428 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
429 {
430 freekeyvalues(kv);
431 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
432 return 0;
433 }
434 if (automode == 0)
435 runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
436 ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]);
437
438 findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
439 if (configtype == 1)
440 { green = 1; red = 1; }
441 else if (configtype == 2)
442 { green = 1; red = 1; orange = 1; }
443 else if (configtype == 3)
444 { green = 1; red = 1; blue = 1; }
445 else if (configtype == 4)
446 { green = 1; red=1; orange=1; blue = 1; }
447 else if (configtype == "")
448 { green = 1; red = 1; }
449
450 do
451 {
452 count = 0;
453 strcpy(message, ctr[TR_INTERFACE_CHANGE]);
454
455 if (green) {
456 strcpy(MenuInhalt[count], "GREEN");
457 pMenuInhalt[count] = MenuInhalt[count];
458 NicEntry[_GREEN_CARD_] = count;
459 sprintf(temp, "GREEN: %s\n", knics[_GREEN_CARD_].description);
460 strcat(message, temp);
461 if ( strlen(knics[_GREEN_CARD_].macaddr) ) {
462 sprintf(temp, "GREEN: (%s) %s green0\n", knics[_GREEN_CARD_].macaddr, ctr[TR_AS]);
463 strcat(message, temp);
464 }
465 count++;
466 }
467
468 if (red) {
469 strcpy(MenuInhalt[count], "RED");
470 pMenuInhalt[count] = MenuInhalt[count];
471 NicEntry[_RED_CARD_] = count;
472 sprintf(temp, "RED: %s\n", knics[_RED_CARD_].description);
473 strcat(message, temp);
474 if ( strlen(knics[_RED_CARD_].macaddr) ) {
475 sprintf(temp, "RED: (%s) %s red0\n", knics[_RED_CARD_].macaddr, ctr[TR_AS]);
476 strcat(message, temp);
477 }
478 count++;
479 }
480
481 if (orange) {
482 strcpy(MenuInhalt[count], "ORANGE");
483 pMenuInhalt[count] = MenuInhalt[count];
484 NicEntry[_ORANGE_CARD_] = count;
485 sprintf(temp, "ORANGE: %s\n", knics[_ORANGE_CARD_].description);
486 strcat(message, temp);
487 if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
488 sprintf(temp, "ORANGE: (%s) %s orange0\n", knics[_ORANGE_CARD_].macaddr, ctr[TR_AS]);
489 strcat(message, temp);
490 }
491 count++;
492 }
493
494 if (blue) {
495 strcpy(MenuInhalt[count], "BLUE");
496 pMenuInhalt[count] = MenuInhalt[count];
497 NicEntry[_BLUE_CARD_] = count;
498 sprintf(temp, "BLUE: %s\n", knics[_BLUE_CARD_].description);
499 strcat(message, temp);
500 if ( strlen(knics[_BLUE_CARD_].macaddr) ) {
501 sprintf(temp, "BLUE: (%s) %s blue0\n", knics[_BLUE_CARD_].macaddr, ctr[TR_AS]);
502 strcat(message, temp);
503 }
504 count++;
505 }
506 pMenuInhalt[count] = NULL;
507
508 rc = newtWinMenu( ctr[TR_NETCARD_COLOR], message, 70, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_SELECT], ctr[TR_REMOVE], ctr[TR_DONE], NULL);
509
510 if ( rc == 0 || rc == 1) {
511 if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_);
512 if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_);
513 if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_);
514 if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_);
515 netaddresschange = 1;
516 } else if (rc == 2) {
517 if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_);
518 if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_);
519 if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_);
520 if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_);
521 netaddresschange = 1;
522 }
523 }
524 while ( rc <= 2);
525
526 freekeyvalues(kv);
527 return 1;
528 }
529
530 // Let user change GREEN address.
531 int greenaddressmenu(void)
532 {
533 struct keyvalue *kv = initkeyvalues();
534 char message[1000];
535 int rc;
536
537 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
538 {
539 freekeyvalues(kv);
540 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
541 return 0;
542 }
543
544 sprintf(message, ctr[TR_WARNING_LONG], NAME);
545 rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message);
546
547 if (rc == 0 || rc == 1)
548 {
549 if (changeaddress(kv, "GREEN", 0, ""))
550 {
551 netaddresschange = 1;
552 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
553 writehostsfiles();
554 }
555 }
556
557 freekeyvalues(kv);
558
559 return 0;
560 }
561
562 // They can change BLUE, ORANGE and GREEN too :)
563 int addressesmenu(void)
564 {
565 struct keyvalue *kv = initkeyvalues();
566 struct keyvalue *mainkv = initkeyvalues();
567 int rc = 0;
568 char *sections[5];
569 char *green = "GREEN";
570 char *orange = "ORANGE";
571 char *blue = "BLUE";
572 char *red = "RED";
573 int c = 0;
574 char greenaddress[STRING_SIZE];
575 char oldgreenaddress[STRING_SIZE];
576 char temp[STRING_SIZE];
577 char temp2[STRING_SIZE];
578 char message[1000];
579 int configtype;
580 int done;
581 int choice;
582 char hostname[STRING_SIZE];
583
584 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
585 {
586 freekeyvalues(kv);
587 freekeyvalues(mainkv);
588 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
589 return 0;
590 }
591 if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
592 {
593 freekeyvalues(kv);
594 freekeyvalues(mainkv);
595 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
596 return 0;
597 }
598
599 strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
600 configtype = atol(temp);
601
602 sections[c] = green;
603 c++;
604 if (HAS_BLUE)
605 {
606 sections[c] = blue;
607 c++;
608 }
609 if (HAS_ORANGE)
610 {
611 sections[c] = orange;
612 c++;
613 }
614 if (HAS_RED)
615 {
616 sections[c] = red;
617 c++;
618 }
619 sections[c] = NULL;
620
621 choice = 0;
622 done = 0;
623 while (!done)
624 {
625 rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS],
626 ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5,
627 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);
628
629 if (rc == 0 || rc == 1)
630 {
631 if (strcmp(sections[choice], "GREEN") == 0)
632 {
633 findkey(kv, "GREEN_ADDRESS", oldgreenaddress);
634 sprintf(message, ctr[TR_WARNING_LONG], NAME);
635 rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL],
636 message);
637 if (rc == 0 || rc == 1)
638 {
639 if (changeaddress(kv, "GREEN", 0, ""))
640 {
641 netaddresschange = 1;
642 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
643 writehostsfiles();
644 findkey(kv, "GREEN_ADDRESS", greenaddress);
645 snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress);
646 snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress);
647 replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2);
648 chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
649 }
650 }
651 }
652 if (strcmp(sections[choice], "BLUE") == 0)
653 {
654 if (changeaddress(kv, "BLUE", 0, ""))
655 netaddresschange = 1;
656 }
657 if (strcmp(sections[choice], "ORANGE") == 0)
658 {
659 if (changeaddress(kv, "ORANGE", 0, ""))
660 netaddresschange = 1;
661 }
662 if (strcmp(sections[choice], "RED") == 0)
663 {
664 strcpy(hostname, "");
665 findkey(mainkv, "HOSTNAME", hostname);
666 if (changeaddress(kv, "RED", 1, hostname))
667 netaddresschange = 1;
668 }
669 }
670 else
671 done = 1;
672 }
673
674 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
675 freekeyvalues(kv);
676 freekeyvalues(mainkv);
677
678 return 0;
679 }
680
681 /* DNS and default gateway.... */
682 int dnsgatewaymenu(void)
683 {
684 struct keyvalue *kv = initkeyvalues();
685 char message[1000];
686 char temp[STRING_SIZE] = "0";
687 struct newtWinEntry entries[DNSGATEWAY_TOTAL+1];
688 char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */
689 int error;
690 int configtype;
691 int rc;
692
693 if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
694 {
695 freekeyvalues(kv);
696 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
697 return 0;
698 }
699
700 entries[DNS1].text = ctr[TR_PRIMARY_DNS];
701 strcpy(temp, ""); findkey(kv, "DNS1", temp);
702 values[DNS1] = strdup(temp);
703 entries[DNS1].value = &values[DNS1];
704 entries[DNS1].flags = 0;
705
706 entries[DNS2].text = ctr[TR_SECONDARY_DNS];
707 strcpy(temp, ""); findkey(kv, "DNS2", temp);
708 values[DNS2] = strdup(temp);
709 entries[DNS2].value = &values[DNS2];
710 entries[DNS2].flags = 0;
711
712 entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY];
713 strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
714 values[DEFAULT_GATEWAY] = strdup(temp);
715 entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY];
716 entries[DEFAULT_GATEWAY].flags = 0;
717
718 entries[DNSGATEWAY_TOTAL].text = NULL;
719 entries[DNSGATEWAY_TOTAL].value = NULL;
720 entries[DNSGATEWAY_TOTAL].flags = 0;
721
722 do
723 {
724 error = 0;
725
726 rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS],
727 ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries,
728 ctr[TR_OK], ctr[TR_CANCEL], NULL);
729 if (rc == 0 || rc == 1)
730 {
731 strcpy(message, ctr[TR_INVALID_FIELDS]);
732 if (strlen(values[DNS1]))
733 {
734 if (inet_addr(values[DNS1]) == INADDR_NONE)
735 {
736 strcat(message, ctr[TR_PRIMARY_DNS_CR]);
737 error = 1;
738 }
739 }
740 if (strlen(values[DNS2]))
741 {
742 if (inet_addr(values[DNS2]) == INADDR_NONE)
743 {
744 strcat(message, ctr[TR_SECONDARY_DNS_CR]);
745 error = 1;
746 }
747 }
748 if (strlen(values[DEFAULT_GATEWAY]))
749 {
750 if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE)
751 {
752 strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]);
753 error = 1;
754 }
755 }
756 if (!strlen(values[DNS1]) && strlen(values[DNS2]))
757 {
758 strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]);
759 error = 1;
760 }
761
762 if (error)
763 errorbox(message);
764 else
765 {
766 replacekeyvalue(kv, "DNS1", values[DNS1]);
767 replacekeyvalue(kv, "DNS2", values[DNS2]);
768 replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]);
769 netaddresschange = 1;
770 free(values[DNS1]);
771 free(values[DNS2]);
772 free(values[DEFAULT_GATEWAY]);
773 writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
774 }
775 }
776 }
777 while (error);
778
779 freekeyvalues(kv);
780
781 return 1;
782 }