]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/setup/networking.c
1 /* SmoothWall setup program.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
7 * The big one: networking.
13 #define _(x) dgettext("setup", x)
23 #define HAS_RED (configtype == 1 || configtype == 2 || configtype == 3 || configtype == 4)
24 #define HAS_ORANGE (configtype == 2 || configtype == 4)
25 #define HAS_BLUE (configtype == 3 || configtype == 4)
26 #define RED_IS_NOT_ETH (configtype == 0)
28 extern struct nic nics
[];
29 extern struct knic knics
[];
31 char *configtypenames
[] = {
33 "GREEN + RED + ORANGE",
35 "GREEN + RED + ORANGE + BLUE",
37 int configtypecards
[] = {
39 3, // "GREEN + RED + ORANGE",
40 3, // "GREEN + RED + BLUE",
41 4 // "GREEN + RED + ORANGE + BLUE",
49 int configtypemenu(void);
51 int changedrivers(void);
52 int greenaddressmenu(void);
53 int addressesmenu(void);
55 int handlenetworking(void)
63 found
= scan_network_cards();
86 if (oktoleave()) done
= 1;
96 /* Restart networking! */
99 runcommandwithstatus("/etc/rc.d/init.d/network stop",
100 _("Networking"), _("Stopping network..."), NULL
);
104 runcommandwithstatus("/etc/rc.d/init.d/network start",
105 _("Networking"), _("Restarting network..."), NULL
);
106 runcommandwithstatus("/etc/rc.d/init.d/unbound restart",
107 _("Networking"), _("Restarting unbound..."), NULL
);
117 struct keyvalue
*kv
= initkeyvalues();
118 char temp
[STRING_SIZE
];
122 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
125 errorbox(_("Unable to open settings file"));
129 strcpy(temp
, "1"); findkey(kv
, "CONFIG_TYPE", temp
); configtype
= atol(temp
);
130 if (configtype
< 1 || configtype
> 4) configtype
= 1;
134 strcpy(temp
, ""); findkey(kv
, "GREEN_DEV", temp
);
137 rc
= newtWinChoice(_("Error"), _("OK"), _("Ignore"),
138 _("No GREEN interface assigned."));
139 if (rc
== 0 || rc
== 1)
145 if (!(interfacecheck(kv
, "GREEN")))
147 errorbox(_("Missing an IP address on GREEN."));
155 strcpy(temp
, ""); findkey(kv
, "RED_DEV", temp
);
158 rc
= newtWinChoice(_("Error"), _("OK"), _("Ignore"),
159 _("No RED interface assigned."));
160 if (rc
== 0 || rc
== 1)
166 if (!(interfacecheck(kv
, "RED")))
168 errorbox(_("Missing an IP address on RED."));
175 strcpy(temp
, ""); findkey(kv
, "ORANGE_DEV", temp
);
178 rc
= newtWinChoice(_("Error"), _("OK"), _("Ignore"),
179 _("No ORANGE interface assigned."));
180 if (rc
== 0 || rc
== 1)
186 if (!(interfacecheck(kv
, "ORANGE")))
188 errorbox(_("Missing an IP address on ORANGE."));
195 strcpy(temp
, ""); findkey(kv
, "BLUE_DEV", temp
);
198 rc
= newtWinChoice(_("Error"), _("OK"), _("Ignore"),
199 _("No BLUE interface assigned."));
200 if (rc
== 0 || rc
== 1)
206 if (!(interfacecheck(kv
, "BLUE")))
208 errorbox(_("Missing an IP address on BLUE."));
217 /* Shows the main menu and a summary of the current settings. */
221 _("Network configuration type"),
222 _("Drivers and card assignments"),
223 _("Address settings"),
227 static int choice
= 0;
228 struct keyvalue
*kv
= initkeyvalues();
230 char temp
[STRING_SIZE
] = "1";
233 char networkrestart
[STRING_SIZE
] = "";
235 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
238 errorbox(_("Unable to open settings file"));
242 if (netaddresschange
)
243 strcpy(networkrestart
, _("When configuration is complete, a network restart will be required."));
245 strcpy(temp
, ""); findkey(kv
, "CONFIG_TYPE", temp
);
248 if (x
< 0 || x
> 4) x
= 0;
249 /* Format heading bit. */
250 snprintf(message
, 1000, _("Current config: %s\n\n%s"), configtypenames
[x
], networkrestart
);
251 rc
= newtWinMenu(_("Network configuration menu"), message
, 50, 5, 5, 6,
252 sections
, &choice
, _("OK"), _("Done"), NULL
);
254 if (rc
== 0 || rc
== 1)
262 /* Here they choose general network config, number of nics etc. */
263 int configtypemenu(void)
265 struct keyvalue
*kv
= initkeyvalues();
266 char temp
[STRING_SIZE
] = "1";
271 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
274 errorbox(_("Unable to open settings file"));
278 found
= scan_network_cards();
280 findkey(kv
, "CONFIG_TYPE", temp
); choise
= atol(temp
);
283 sprintf(message
, _("Select the network configuration for %s. "
284 "The following configuration types list those interfaces which have ethernet attached. "
285 "If you change this setting, a network restart will be required, and you will have to "
286 "reconfigure the network driver assignments."), NAME
);
287 rc
= newtWinMenu(_("Network configuration type"), message
, 50, 5, 5,
288 6, configtypenames
, &choise
, _("OK"), _("Cancel"), NULL
);
289 if ( configtypecards
[choise
] > found
) {
290 sprintf(message
, _("Not enough netcards for your choice.\n\nNeeded: %d - Available: %d\n"),
291 configtypecards
[choise
], found
);
295 if (rc
== 0 || rc
== 1)
298 sprintf(temp
, "%d", choise
);
299 replacekeyvalue(kv
, "CONFIG_TYPE", temp
);
300 configtype
= atol(temp
);
302 clear_card_entry(_RED_CARD_
);
304 clear_card_entry(_ORANGE_CARD_
);
306 clear_card_entry(_BLUE_CARD_
);
308 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
309 netaddresschange
= 1;
316 /* Driver menu. Choose drivers.. */
319 struct keyvalue
*kv
= initkeyvalues();
320 char message
[STRING_SIZE
];
321 char temp
[STRING_SIZE
] = "1";
324 int i
, rc
, kcount
= 0, neednics
;
326 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
329 errorbox(_("Unable to open settings file"));
333 if (findkey(kv
, "CONFIG_TYPE", temp
))
334 configtype
= atol(temp
);
336 fprintf(flog
,"setting CONFIG_TYPE = %s\n",temp
);
337 configtype
= atol(temp
);
338 replacekeyvalue(kv
, "CONFIG_TYPE", temp
);
339 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
342 strcpy(message
, _("Configure network drivers, and which interface each card is assigned to. "
343 "The current configuration is as follows:\n\n"));
348 sprintf(temp
, "%-6s: %s\n", "GREEN", knics
[_GREEN_CARD_
].description
);
349 strcat(message
, temp
);
350 if (strlen(knics
[_GREEN_CARD_
].macaddr
) ) {
351 sprintf(temp
, "%-6s: (%s)\n", "GREEN", knics
[_GREEN_CARD_
].macaddr
);
352 strcat(message
, temp
);
357 sprintf(temp
, "%-6s: %s\n", "RED", knics
[_RED_CARD_
].description
);
358 strcat(message
, temp
);
359 if (strlen(knics
[_RED_CARD_
].macaddr
) ) {
360 sprintf(temp
, "%-6s: (%s)\n", "RED", knics
[_RED_CARD_
].macaddr
);
361 strcat(message
, temp
);
366 sprintf(temp
, "%-6s: %s\n", "ORANGE", knics
[_ORANGE_CARD_
].description
);
367 strcat(message
, temp
);
368 if ( strlen(knics
[_ORANGE_CARD_
].macaddr
) ) {
369 sprintf(temp
, "%-6s: (%s)\n", "ORANGE", knics
[_ORANGE_CARD_
].macaddr
);
370 strcat(message
, temp
);
375 sprintf(temp
, "%-6s: %s\n", "BLUE", knics
[_BLUE_CARD_
].description
);
376 strcat(message
, temp
);
377 if (strlen(knics
[_BLUE_CARD_
].macaddr
)) {
378 sprintf(temp
, "%-6s: (%s)\n", "BLUE", knics
[_BLUE_CARD_
].macaddr
);
379 strcat(message
, temp
);
384 for ( i
=0 ; i
<4; i
++)
385 if (strcmp(knics
[i
].macaddr
, ""))
388 if (neednics
= kcount
)
390 strcat(message
, "\n");
391 strcat(message
, _("Do you wish to change these settings?"));
392 rc
= newtWinChoice(_("Drivers and card assignments"), _("OK"),
393 _("Cancel"), message
);
394 if (rc
== 0 || rc
== 1)
406 int set_menu_entry_for(int *nr
, int *card
)
411 int changedrivers(void)
413 struct keyvalue
*kv
= initkeyvalues();
414 char temp
[STRING_SIZE
], message
[STRING_SIZE
];
416 int green
= 0, red
= 0, blue
= 0, orange
= 0;
417 char MenuInhalt
[10][180];
418 char *pMenuInhalt
[10];
419 int count
= 0, choise
= 0, rc
;
422 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
425 errorbox(_("Unable to open settings file"));
429 runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
430 _("Networking"), _("Restarting non-local network..."), NULL
);
432 findkey(kv
, "CONFIG_TYPE", temp
); configtype
= atol(temp
);
434 { green
= 1; red
= 1; }
435 else if (configtype
== 2)
436 { green
= 1; red
= 1; orange
= 1; }
437 else if (configtype
== 3)
438 { green
= 1; red
= 1; blue
= 1; }
439 else if (configtype
== 4)
440 { green
= 1; red
=1; orange
=1; blue
= 1; }
441 else if (configtype
== "")
442 { green
= 1; red
= 1; }
447 strcpy(message
, _("Please choose the interface you wish to change.\n\n"));
450 strcpy(MenuInhalt
[count
], "GREEN");
451 pMenuInhalt
[count
] = MenuInhalt
[count
];
452 NicEntry
[_GREEN_CARD_
] = count
;
453 sprintf(temp
, "%-6s: %s\n", "GREEN", knics
[_GREEN_CARD_
].description
);
454 strcat(message
, temp
);
455 if ( strlen(knics
[_GREEN_CARD_
].macaddr
) ) {
456 sprintf(temp
, "%-6s: (%s)\n", "GREEN", knics
[_GREEN_CARD_
].macaddr
);
457 strcat(message
, temp
);
463 strcpy(MenuInhalt
[count
], "RED");
464 pMenuInhalt
[count
] = MenuInhalt
[count
];
465 NicEntry
[_RED_CARD_
] = count
;
466 sprintf(temp
, "%-6s: %s\n", "RED", knics
[_RED_CARD_
].description
);
467 strcat(message
, temp
);
468 if ( strlen(knics
[_RED_CARD_
].macaddr
) ) {
469 sprintf(temp
, "%-6s: (%s)\n", "RED", knics
[_RED_CARD_
].macaddr
);
470 strcat(message
, temp
);
476 strcpy(MenuInhalt
[count
], "ORANGE");
477 pMenuInhalt
[count
] = MenuInhalt
[count
];
478 NicEntry
[_ORANGE_CARD_
] = count
;
479 sprintf(temp
, "%-6s: %s\n", "ORANGE", knics
[_ORANGE_CARD_
].description
);
480 strcat(message
, temp
);
481 if ( strlen(knics
[_ORANGE_CARD_
].macaddr
) ) {
482 sprintf(temp
, "%-6s: (%s)\n", "ORANGE", knics
[_ORANGE_CARD_
].macaddr
);
483 strcat(message
, temp
);
489 strcpy(MenuInhalt
[count
], "BLUE");
490 pMenuInhalt
[count
] = MenuInhalt
[count
];
491 NicEntry
[_BLUE_CARD_
] = count
;
492 sprintf(temp
, "%-6s: %s\n", "BLUE", knics
[_BLUE_CARD_
].description
);
493 strcat(message
, temp
);
494 if ( strlen(knics
[_BLUE_CARD_
].macaddr
) ) {
495 sprintf(temp
, "%-6s: (%s)\n", "BLUE", knics
[_BLUE_CARD_
].macaddr
);
496 strcat(message
, temp
);
500 pMenuInhalt
[count
] = NULL
;
502 rc
= newtWinMenu(_("Assigned Cards"), message
, 70, 5, 5, 6, pMenuInhalt
,
503 &choise
, _("Select"), _("Remove"), _("Done"), NULL
);
505 if ( rc
== 0 || rc
== 1) {
506 if ((green
) && ( choise
== NicEntry
[0])) nicmenu(_GREEN_CARD_
);
507 if ((red
) && ( choise
== NicEntry
[1])) nicmenu(_RED_CARD_
);
508 if ((orange
) && ( choise
== NicEntry
[2])) nicmenu(_ORANGE_CARD_
);
509 if ((blue
) && ( choise
== NicEntry
[3])) nicmenu(_BLUE_CARD_
);
510 netaddresschange
= 1;
511 } else if (rc
== 2) {
512 if ((green
) && ( choise
== NicEntry
[0])) ask_clear_card_entry(_GREEN_CARD_
);
513 if ((red
) && ( choise
== NicEntry
[1])) ask_clear_card_entry(_RED_CARD_
);
514 if ((orange
) && ( choise
== NicEntry
[2])) ask_clear_card_entry(_ORANGE_CARD_
);
515 if ((blue
) && ( choise
== NicEntry
[3])) ask_clear_card_entry(_BLUE_CARD_
);
516 netaddresschange
= 1;
525 // Let user change GREEN address.
526 int greenaddressmenu(void)
528 struct keyvalue
*kv
= initkeyvalues();
532 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
535 errorbox(_("Unable to open settings file"));
539 sprintf(message
, _("If you change this IP address, and you are logged in remotely, "
540 "your connection to the %s machine will be broken, and you will have to reconnect "
541 "on the new IP. This is a risky operation, and should only be attempted if you "
542 "have physical access to the machine, should something go wrong."), NAME
);
543 rc
= newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message
);
545 if (rc
== 0 || rc
== 1)
547 if (changeaddress(kv
, "GREEN", 0, ""))
549 netaddresschange
= 1;
550 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
560 // They can change BLUE, ORANGE and GREEN too :)
561 int addressesmenu(void)
563 struct keyvalue
*kv
= initkeyvalues();
564 struct keyvalue
*mainkv
= initkeyvalues();
567 char *green
= "GREEN";
568 char *orange
= "ORANGE";
572 char greenaddress
[STRING_SIZE
];
573 char oldgreenaddress
[STRING_SIZE
];
574 char temp
[STRING_SIZE
];
575 char temp2
[STRING_SIZE
];
580 char hostname
[STRING_SIZE
];
582 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
585 freekeyvalues(mainkv
);
586 errorbox(_("Unable to open settings file"));
589 if (!(readkeyvalues(mainkv
, CONFIG_ROOT
"/main/settings")))
592 freekeyvalues(mainkv
);
593 errorbox(_("Unable to open settings file"));
597 strcpy(temp
, "0"); findkey(kv
, "CONFIG_TYPE", temp
);
598 configtype
= atol(temp
);
609 sections
[c
] = orange
;
623 rc
= newtWinMenu(_("Address settings"),
624 _("Select the interface you wish to reconfigure."), 50, 5,
625 5, 6, sections
, &choice
, _("OK"), _("Done"), NULL
);
627 if (rc
== 0 || rc
== 1)
629 if (strcmp(sections
[choice
], "GREEN") == 0)
631 findkey(kv
, "GREEN_ADDRESS", oldgreenaddress
);
632 sprintf(message
, _("If you change this IP address, and you are logged in remotely, "
633 "your connection to the %s machine will be broken, and you will have to reconnect "
634 "on the new IP. This is a risky operation, and should only be attempted if you "
635 "have physical access to the machine, should something go wrong."), NAME
);
636 rc
= newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message
);
637 if (rc
== 0 || rc
== 1)
639 if (changeaddress(kv
, "GREEN", 0, ""))
641 netaddresschange
= 1;
642 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
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);
652 if (strcmp(sections
[choice
], "BLUE") == 0)
654 if (changeaddress(kv
, "BLUE", 0, ""))
655 netaddresschange
= 1;
657 if (strcmp(sections
[choice
], "ORANGE") == 0)
659 if (changeaddress(kv
, "ORANGE", 0, ""))
660 netaddresschange
= 1;
662 if (strcmp(sections
[choice
], "RED") == 0)
664 strcpy(hostname
, "");
665 findkey(mainkv
, "HOSTNAME", hostname
);
666 if (changeaddress(kv
, "RED", 1, hostname
))
667 netaddresschange
= 1;
674 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
676 freekeyvalues(mainkv
);