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