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