📄 networking.c
字号:
/* SmoothWall setup program. * * This program is distributed under the terms of the GNU General Public * Licence. See the file COPYING for details. * * (c) Lawrence Manning, 2001 * The big one: networking. * * $Id: networking.c,v 1.5.2.5 2005/01/24 17:53:31 riddles Exp $ * */ #include "setup.h"#define DNS1 0#define DNS2 1#define DEFAULT_GATEWAY 2#define DNSGATEWAY_TOTAL 3extern FILE *flog;extern char *mylog;extern char **ctr;extern int automode;#define HAS_ORANGE (configtype == 1 || configtype == 3 || configtype == 5 || configtype == 7)#define HAS_RED (configtype == 2 || configtype == 3 || configtype == 6 || configtype == 7)#define HAS_BLUE (configtype == 4 || configtype == 5 || configtype == 6 || configtype == 7)#define RED_IS_NOT_ETH (configtype == 0 || configtype == 1 || configtype == 4 || configtype == 5)extern struct nic nics[];char *configtypenames[] = { "GREEN (RED is modem/ISDN)", "GREEN + ORANGE (RED is modem/ISDN)", "GREEN + RED", "GREEN + ORANGE + RED", "GREEN + BLUE (RED is modem/ISDN) ", "GREEN + ORANGE + BLUE (RED is modem/ISDN)", "GREEN + BLUE + RED", "GREEN + ORANGE + BLUE + RED", NULL };int netaddresschange;int oktoleave(char *errormessage);int firstmenu(void);int configtypemenu(void);int drivermenu(void);int changedrivers(void);int greenaddressmenu(void);int addressesmenu(void);int dnsgatewaymenu(void);int handlenetworking(void){ int done; int choice; char errormessage[STRING_SIZE]; netaddresschange = 0; done = 0; while (!done) { choice = firstmenu(); switch (choice) { case 1: configtypemenu(); break; case 2: drivermenu(); break; case 3: addressesmenu(); break; case 4: dnsgatewaymenu(); break; case 0: if (oktoleave(errormessage)) done = 1; else errorbox(errormessage); break; default: break; } } if (automode == 0) { /* Restart netowrking! Reboot? BAH! */ if (netaddresschange) { runcommandwithstatus("/etc/rc.d/rc.netaddress.down", ctr[TR_PUSHING_NETWORK_DOWN]); runcommandwithstatus("/etc/rc.d/rc.netaddress.up", ctr[TR_PULLING_NETWORK_UP]); mysystem("/etc/rc.d/rc.pcmcia start"); } } return 1;}int oktoleave(char *errormessage){ struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE]; int configtype; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); if (configtype < 0 || configtype > 7) configtype = 0; if (HAS_BLUE) { strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); if (!(strlen(temp))) { strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]); goto EXIT; } if (!(interfacecheck(kv, "BLUE"))) { strcpy(errormessage, ctr[TR_MISSING_BLUE_IP]); goto EXIT; } } if (HAS_ORANGE) { strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); if (!(strlen(temp))) { strcpy(errormessage, ctr[TR_NO_ORANGE_INTERFACE]); goto EXIT; } if (!(interfacecheck(kv, "ORANGE"))) { strcpy(errormessage, ctr[TR_MISSING_ORANGE_IP]); goto EXIT; } } if (HAS_RED) { strcpy(temp, ""); findkey(kv, "RED_DEV", temp); if (!(strlen(temp))) { strcpy(errormessage, ctr[TR_NO_RED_INTERFACE]); goto EXIT; } if (!(interfacecheck(kv, "RED"))) { strcpy(errormessage, ctr[TR_MISSING_RED_IP]); goto EXIT; } } strcpy(errormessage, "");EXIT: freekeyvalues(kv); if (strlen(errormessage)) return 0; else return 1;} /* Shows the main menu and a summary of the current settings. */int firstmenu(void){ char *sections[] = { ctr[TR_NETWORK_CONFIGURATION_TYPE], ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_ADDRESS_SETTINGS], ctr[TR_DNS_AND_GATEWAY_SETTINGS], NULL }; int rc; static int choice = 0; struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE]; int x; int result; char networkrestart[STRING_SIZE] = ""; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } if (netaddresschange) strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]); strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); x = atol(temp); if (x < 0 || x > 7) x = 0; /* Format heading bit. */ snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x], networkrestart); rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); if (rc == 0 || rc == 1) result = choice + 1; else result = 0; return result;}/* Here they choose general network config, number of nics etc. */int configtypemenu(void){ struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE] = "0"; char message[1000]; int choice; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } findkey(kv, "CONFIG_TYPE", temp); choice = atol(temp); sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME); rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5, 6, configtypenames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 0 || rc == 1) { runcommandwithstatus("/etc/rc.d/rc.netaddress.down NOTGREEN", ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); sprintf(temp, "%d", choice); replacekeyvalue(kv, "CONFIG_TYPE", temp); replacekeyvalue(kv, "ORANGE_DEV", ""); replacekeyvalue(kv, "BLUE_DEV", ""); replacekeyvalue(kv, "RED_DEV", ""); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); netaddresschange = 1; } freekeyvalues(kv); return 0;}/* Driver menu. Choose drivers.. */int drivermenu(void){ struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE], temp1[STRING_SIZE]; char driver[STRING_SIZE], dev[STRING_SIZE]; int configtype; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); if (configtype == 0) { freekeyvalues(kv); errorbox(ctr[TR_YOUR_CONFIGURATION_IS_SINGLE_GREEN_ALREADY_HAS_DRIVER]); return 0; } strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]); /* This horrible big formats the heading :( */ strcpy(driver, ""); findkey(kv, "GREEN_DISPLAYDRIVER", driver); findnicdescription(driver, temp); strcpy(dev, ctr[TR_UNSET]); findkey(kv, "GREEN_DEV", dev); if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); sprintf(temp1, "GREEN: %s (%s)\n", temp, dev); strcat(message, temp1); if (HAS_BLUE) { strcpy(driver, ""); findkey(kv, "BLUE_DISPLAYDRIVER", driver); findnicdescription(driver, temp); strcpy(dev, ctr[TR_UNSET]); findkey(kv, "BLUE_DEV", dev); if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); sprintf(temp1, "BLUE: %s (%s)\n", temp, dev); strcat(message, temp1); } if (HAS_ORANGE) { strcpy(driver, ""); findkey(kv, "ORANGE_DISPLAYDRIVER", driver); findnicdescription(driver, temp); strcpy(dev, ctr[TR_UNSET]); findkey(kv, "ORANGE_DEV", dev); if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); sprintf(temp1, "ORANGE: %s (%s)\n", temp, dev); strcat(message, temp1); } if (HAS_RED) { strcpy(driver, ""); findkey(kv, "RED_DISPLAYDRIVER", driver); findnicdescription(driver, temp); strcpy(dev, ctr[TR_UNSET]); findkey(kv, "RED_DEV", dev); if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]); sprintf(temp1, "RED: %s (%s)\n", temp, dev); strcat(message, temp1); } strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]); rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK], ctr[TR_CANCEL], message); if (rc == 0 || rc == 1) { /* Shit, got to do something.. */ changedrivers(); } freekeyvalues(kv); return 1;}int changedrivers(void){ struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE]; char driver[STRING_SIZE]; int configtype; int rc; int c; int needcards, sofarallocated, countofcards, toallocate; char *orange = "ORANGE"; char *blue = "BLUE"; char *red = "RED"; char *sections[4]; int choice; char nexteth[STRING_SIZE]; int abort; char currentdriver[STRING_SIZE], currentdriveroptions[STRING_SIZE]; char displaydriver[STRING_SIZE]; struct stat st; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); runcommandwithstatus("/etc/rc.d/rc.netaddress.down NOTGREEN", ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); /* Remove all modules not needed for green networking. */ c = 0; strcpy(driver, ""); findkey(kv, "GREEN_DRIVER", driver); if (strcmp(driver, "pcmcia") != 0) { stat("/proc/bus/pccard", &st); mysystem("/etc/rc.d/rc.pcmcia stop"); if (S_ISDIR(st.st_mode)) { mysystem("/sbin/modprobe pcmcia_core"); mysystem("/sbin/modprobe pcmcia-controller"); mysystem("/sbin/modprobe ds"); } } while (nics[c].modulename) { if (strcmp(nics[c].modulename, driver) != 0) { if (checkformodule(nics[c].modulename)) { sprintf(temp, "/sbin/rmmod %s", nics[c].modulename); mysystem(temp); } } c++; } /* Blank them so the rc.netaddress.up dosnt get confused. */ replacekeyvalue(kv, "ORANGE_DEV", ""); replacekeyvalue(kv, "BLUE_DEV", ""); replacekeyvalue(kv, "RED_DEV", "");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -