]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/setup/networking.c
8d398f365fac9662140e365203a6c058f23e8b16
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 changedrivers(void)
408 struct keyvalue
*kv
= initkeyvalues();
409 char temp
[STRING_SIZE
], message
[STRING_SIZE
];
411 int green
= 0, red
= 0, blue
= 0, orange
= 0;
412 char MenuInhalt
[10][180];
413 char *pMenuInhalt
[10];
414 int count
= 0, choise
= 0, rc
;
417 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
420 errorbox(_("Unable to open settings file"));
424 runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
425 _("Networking"), _("Restarting non-local network..."), NULL
);
427 findkey(kv
, "CONFIG_TYPE", temp
); configtype
= atol(temp
);
429 { green
= 1; red
= 1; }
430 else if (configtype
== 2)
431 { green
= 1; red
= 1; orange
= 1; }
432 else if (configtype
== 3)
433 { green
= 1; red
= 1; blue
= 1; }
434 else if (configtype
== 4)
435 { green
= 1; red
=1; orange
=1; blue
= 1; }
437 { green
= 1; red
= 1; }
442 strcpy(message
, _("Please choose the interface you wish to change.\n\n"));
445 strcpy(MenuInhalt
[count
], "GREEN");
446 pMenuInhalt
[count
] = MenuInhalt
[count
];
447 NicEntry
[_GREEN_CARD_
] = count
;
448 sprintf(temp
, "%-6s: %s\n", "GREEN", knics
[_GREEN_CARD_
].description
);
449 strcat(message
, temp
);
450 if ( strlen(knics
[_GREEN_CARD_
].macaddr
) ) {
451 sprintf(temp
, "%-6s: (%s)\n", "GREEN", knics
[_GREEN_CARD_
].macaddr
);
452 strcat(message
, temp
);
458 strcpy(MenuInhalt
[count
], "RED");
459 pMenuInhalt
[count
] = MenuInhalt
[count
];
460 NicEntry
[_RED_CARD_
] = count
;
461 sprintf(temp
, "%-6s: %s\n", "RED", knics
[_RED_CARD_
].description
);
462 strcat(message
, temp
);
463 if ( strlen(knics
[_RED_CARD_
].macaddr
) ) {
464 sprintf(temp
, "%-6s: (%s)\n", "RED", knics
[_RED_CARD_
].macaddr
);
465 strcat(message
, temp
);
471 strcpy(MenuInhalt
[count
], "ORANGE");
472 pMenuInhalt
[count
] = MenuInhalt
[count
];
473 NicEntry
[_ORANGE_CARD_
] = count
;
474 sprintf(temp
, "%-6s: %s\n", "ORANGE", knics
[_ORANGE_CARD_
].description
);
475 strcat(message
, temp
);
476 if ( strlen(knics
[_ORANGE_CARD_
].macaddr
) ) {
477 sprintf(temp
, "%-6s: (%s)\n", "ORANGE", knics
[_ORANGE_CARD_
].macaddr
);
478 strcat(message
, temp
);
484 strcpy(MenuInhalt
[count
], "BLUE");
485 pMenuInhalt
[count
] = MenuInhalt
[count
];
486 NicEntry
[_BLUE_CARD_
] = count
;
487 sprintf(temp
, "%-6s: %s\n", "BLUE", knics
[_BLUE_CARD_
].description
);
488 strcat(message
, temp
);
489 if ( strlen(knics
[_BLUE_CARD_
].macaddr
) ) {
490 sprintf(temp
, "%-6s: (%s)\n", "BLUE", knics
[_BLUE_CARD_
].macaddr
);
491 strcat(message
, temp
);
495 pMenuInhalt
[count
] = NULL
;
497 rc
= newtWinMenu(_("Assigned Cards"), message
, 70, 5, 5, 6, pMenuInhalt
,
498 &choise
, _("Select"), _("Remove"), _("Done"), NULL
);
500 if ( rc
== 0 || rc
== 1) {
501 if ((green
) && ( choise
== NicEntry
[0])) nicmenu(_GREEN_CARD_
);
502 if ((red
) && ( choise
== NicEntry
[1])) nicmenu(_RED_CARD_
);
503 if ((orange
) && ( choise
== NicEntry
[2])) nicmenu(_ORANGE_CARD_
);
504 if ((blue
) && ( choise
== NicEntry
[3])) nicmenu(_BLUE_CARD_
);
505 netaddresschange
= 1;
506 } else if (rc
== 2) {
507 if ((green
) && ( choise
== NicEntry
[0])) ask_clear_card_entry(_GREEN_CARD_
);
508 if ((red
) && ( choise
== NicEntry
[1])) ask_clear_card_entry(_RED_CARD_
);
509 if ((orange
) && ( choise
== NicEntry
[2])) ask_clear_card_entry(_ORANGE_CARD_
);
510 if ((blue
) && ( choise
== NicEntry
[3])) ask_clear_card_entry(_BLUE_CARD_
);
511 netaddresschange
= 1;
520 // Let user change GREEN address.
521 int greenaddressmenu(void)
523 struct keyvalue
*kv
= initkeyvalues();
527 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
530 errorbox(_("Unable to open settings file"));
534 sprintf(message
, _("If you change this IP address, and you are logged in remotely, "
535 "your connection to the %s machine will be broken, and you will have to reconnect "
536 "on the new IP. This is a risky operation, and should only be attempted if you "
537 "have physical access to the machine, should something go wrong."), NAME
);
538 rc
= newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message
);
540 if (rc
== 0 || rc
== 1)
542 if (changeaddress(kv
, "GREEN", 0, ""))
544 netaddresschange
= 1;
545 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
555 // They can change BLUE, ORANGE and GREEN too :)
556 int addressesmenu(void)
558 struct keyvalue
*kv
= initkeyvalues();
559 struct keyvalue
*mainkv
= initkeyvalues();
562 char *green
= "GREEN";
563 char *orange
= "ORANGE";
567 char greenaddress
[STRING_SIZE
];
568 char oldgreenaddress
[STRING_SIZE
];
569 char temp
[STRING_SIZE
];
570 char temp2
[STRING_SIZE
];
575 char hostname
[STRING_SIZE
];
577 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
580 freekeyvalues(mainkv
);
581 errorbox(_("Unable to open settings file"));
584 if (!(readkeyvalues(mainkv
, CONFIG_ROOT
"/main/settings")))
587 freekeyvalues(mainkv
);
588 errorbox(_("Unable to open settings file"));
592 strcpy(temp
, "0"); findkey(kv
, "CONFIG_TYPE", temp
);
593 configtype
= atol(temp
);
604 sections
[c
] = orange
;
618 rc
= newtWinMenu(_("Address settings"),
619 _("Select the interface you wish to reconfigure."), 50, 5,
620 5, 6, sections
, &choice
, _("OK"), _("Done"), NULL
);
622 if (rc
== 0 || rc
== 1)
624 if (strcmp(sections
[choice
], "GREEN") == 0)
626 findkey(kv
, "GREEN_ADDRESS", oldgreenaddress
);
627 sprintf(message
, _("If you change this IP address, and you are logged in remotely, "
628 "your connection to the %s machine will be broken, and you will have to reconnect "
629 "on the new IP. This is a risky operation, and should only be attempted if you "
630 "have physical access to the machine, should something go wrong."), NAME
);
631 rc
= newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message
);
632 if (rc
== 0 || rc
== 1)
634 if (changeaddress(kv
, "GREEN", 0, ""))
636 netaddresschange
= 1;
637 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
639 findkey(kv
, "GREEN_ADDRESS", greenaddress
);
640 snprintf(temp
, STRING_SIZE
-1, "option routers %s", oldgreenaddress
);
641 snprintf(temp2
, STRING_SIZE
-1, "option routers %s", greenaddress
);
642 replace (CONFIG_ROOT
"/dhcp/dhcpd.conf", temp
, temp2
);
643 chown (CONFIG_ROOT
"/dhcp/dhcpd.conf", 99, 99);
647 if (strcmp(sections
[choice
], "BLUE") == 0)
649 if (changeaddress(kv
, "BLUE", 0, ""))
650 netaddresschange
= 1;
652 if (strcmp(sections
[choice
], "ORANGE") == 0)
654 if (changeaddress(kv
, "ORANGE", 0, ""))
655 netaddresschange
= 1;
657 if (strcmp(sections
[choice
], "RED") == 0)
659 strcpy(hostname
, "");
660 findkey(mainkv
, "HOSTNAME", hostname
);
661 if (changeaddress(kv
, "RED", 1, hostname
))
662 netaddresschange
= 1;
669 writekeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings");
671 freekeyvalues(mainkv
);