X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Fsetup%2Fnetstuff.c;h=1e196dc1e088ab1df5a5d0f4dad530d95252fb5d;hb=2e2170bfb541ea1238f1dcc9f026fab1c3f28d51;hp=a656e9f910b183a8520b95308c7f02ed02503caa;hpb=b8df63aeabbd2c54305bc255ae9abf7d67251d7c;p=ipfire-2.x.git diff --git a/src/setup/netstuff.c b/src/setup/netstuff.c index a656e9f910..1e196dc1e0 100644 --- a/src/setup/netstuff.c +++ b/src/setup/netstuff.c @@ -31,6 +31,7 @@ int scanned_nics_read_done = 0; newtComponent networkform; newtComponent addressentry; newtComponent netmaskentry; +newtComponent gatewayentry; newtComponent statictyperadio; newtComponent dhcptyperadio; newtComponent pppoetyperadio; @@ -53,12 +54,14 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag, { char *addressresult; char *netmaskresult; + char *gatewayresult; char *dhcphostnameresult; char *dhcpforcemturesult; struct newtExitStruct es; newtComponent header; newtComponent addresslabel; newtComponent netmasklabel; + newtComponent gatewaylabel; newtComponent dhcphostnamelabel; newtComponent dhcpforcemtulabel; newtComponent ok, cancel; @@ -66,6 +69,7 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag, char temp[STRING_SIZE]; char addressfield[STRING_SIZE]; char netmaskfield[STRING_SIZE]; + char gatewayfield[STRING_SIZE]; char typefield[STRING_SIZE]; char dhcphostnamefield[STRING_SIZE]; char dhcpforcemtufield[STRING_SIZE]; @@ -75,16 +79,18 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag, int startstatictype = 0; int startdhcptype = 0; int startpppoetype = 0; - + unsigned char buffer[sizeof(struct in_addr)]; + /* Build some key strings. */ sprintf(addressfield, "%s_ADDRESS", colour); sprintf(netmaskfield, "%s_NETMASK", colour); + sprintf(gatewayfield, "DEFAULT_GATEWAY"); sprintf(typefield, "%s_TYPE", colour); sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour); sprintf(dhcpforcemtufield, "%s_DHCP_FORCE_MTU", colour); sprintf(message, _("Interface - %s"), colour); - newtCenteredWindow(44, (typeflag ? 18 : 12), message); + newtCenteredWindow(44, (typeflag ? 19 : 12), message); networkform = newtForm(NULL, NULL, 0); @@ -153,9 +159,24 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag, newtFormAddComponent(networkform, netmasklabel); newtFormAddComponent(networkform, netmaskentry); + if (typeflag) + { + /* Gateway */ + gatewaylabel = newtTextbox(2, (typeflag ? 11 : 4) + 2, 18, 1, 0); + newtTextboxSetText(gatewaylabel, _("Gateway:")); + strcpy(temp, ""); + findkey(kv, gatewayfield, temp); + gatewayentry = newtEntry(20, (typeflag ? 11 : 4) + 2, temp, 20, &gatewayresult, 0); + newtEntrySetFilter(gatewayentry, ip_input_filter, NULL); + if (typeflag == 1 && startstatictype == 0) + newtEntrySetFlags(gatewayentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); + newtFormAddComponent(networkform, gatewaylabel); + newtFormAddComponent(networkform, gatewayentry); + } + /* Buttons. */ - ok = newtButton(8, (typeflag ? 14 : 7), _("OK")); - cancel = newtButton(26, (typeflag ? 14 : 7), _("Cancel")); + ok = newtButton(8, (typeflag ? 15 : 7), _("OK")); + cancel = newtButton(26, (typeflag ? 15 : 7), _("Cancel")); newtFormAddComponents(networkform, ok, cancel, NULL); @@ -184,12 +205,19 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag, strcat(message, "\n"); error = 1; } - if (inet_addr(netmaskresult) == INADDR_NONE) + if (inet_pton(AF_INET, netmaskresult, &buffer) == 0) { strcat(message, _("Network mask")); strcat(message, "\n"); error = 1; } + if (typeflag && (inet_addr(gatewayresult) == INADDR_NONE)) + { + strcat(message, _("Gateway")); + strcat(message, "\n"); + error = 1; + } + } if (strcmp(type, "DHCP") == 0) { @@ -213,13 +241,15 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag, { replacekeyvalue(kv, addressfield, "0.0.0.0"); replacekeyvalue(kv, netmaskfield, "0.0.0.0"); + replacekeyvalue(kv, gatewayfield, "0.0.0.0"); } else { replacekeyvalue(kv, addressfield, addressresult); replacekeyvalue(kv, netmaskfield, netmaskresult); + replacekeyvalue(kv, gatewayfield, gatewayresult); } - replacekeyvalue(kv, typefield, type); + replacekeyvalue(kv, typefield, type); } else { @@ -264,28 +294,23 @@ int gettype(char *type) return 0; } -/* 0.9.9: calculates broadcast too. */ int setnetaddress(struct keyvalue *kv, char *colour) { char addressfield[STRING_SIZE]; char netaddressfield[STRING_SIZE]; char netmaskfield[STRING_SIZE]; - char broadcastfield[STRING_SIZE]; char address[STRING_SIZE]; char netmask[STRING_SIZE]; unsigned long int intaddress; unsigned long int intnetaddress; unsigned long int intnetmask; - unsigned long int intbroadcast; struct in_addr temp; char *netaddress; - char *broadcast; - + /* Build some key strings. */ sprintf(addressfield, "%s_ADDRESS", colour); sprintf(netaddressfield, "%s_NETADDRESS", colour); sprintf(netmaskfield, "%s_NETMASK", colour); - sprintf(broadcastfield, "%s_BROADCAST", colour); strcpy(address, ""); findkey(kv, addressfield, address); strcpy(netmask, ""); findkey(kv, netmaskfield, netmask); @@ -300,12 +325,6 @@ int setnetaddress(struct keyvalue *kv, char *colour) replacekeyvalue(kv, netaddressfield, netaddress); - intbroadcast = intnetaddress | ~intnetmask; - temp.s_addr = intbroadcast; - broadcast = inet_ntoa(temp); - - replacekeyvalue(kv, broadcastfield, broadcast); - return 1; } @@ -321,11 +340,13 @@ void networkdialogcallbacktype(newtComponent cm, void *data) { newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); + newtEntrySetFlags(gatewayentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); } else { newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET); newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET); + newtEntrySetFlags(gatewayentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET); } if (strcmp(type, "DHCP") == 0) { @@ -527,27 +548,6 @@ int rename_nics(void) { } } -int create_udev(void) -{ - #define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules" - FILE *fp; - int i; - - if ( (fp = fopen(UDEV_NET_CONF, "w")) == NULL ) { - fprintf(stderr,"Couldn't open" UDEV_NET_CONF); - return 1; - } - - for (i = 0 ; i < 4 ; i++) - { - if (strcmp(knics[i].macaddr, "")) { - fprintf(fp,"\n# %s\nACTION==\"add\", SUBSYSTEM==\"net\", ATTR{type}==\"1\", ATTR{address}==\"%s\", NAME=\"%s0\"\n", knics[i].description, knics[i].macaddr, lcolourcard[i]); - } - } - fclose(fp); - return 0; -} - int write_configs_netudev(int card , int colour) { char commandstring[STRING_SIZE]; @@ -622,16 +622,16 @@ int scan_network_cards(void) int nicmenu(int colour) { int rc, choise = 0, count = 0, kcount = 0, mcount = 0, i, j, nic_in_use; - int found_NIC_as_Card[4]; + int found_NIC_as_Card[MAX_NICS]; char message[STRING_SIZE]; char temp[STRING_SIZE]; char cMenuInhalt[STRING_SIZE]; - char MenuInhalt[20][180]; - char *pMenuInhalt[20]; + char MenuInhalt[MAX_NICS][STRING_SIZE]; + char *pMenuInhalt[MAX_NICS]; while (strcmp(nics[count].macaddr, "")) count++; // 2 find how many nics in system - for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++; // loop to find all knowing nics + for (i=0; i kcount) { @@ -669,7 +669,7 @@ int nicmenu(int colour) sprintf(message, _("Please choose a networkcard for the following interface - %s."), ucolourcard[colour]); rc=2; while ( rc == 2 ) { - rc = newtWinMenu(_("Extended Network Menu"), message, 50, 5, 5, 6, pMenuInhalt, &choise, + rc = newtWinMenu(_("Extended Network Menu"), message, 50, 5, 5, mcount, pMenuInhalt, &choise, _("Select"), _("Identify"), _("Cancel"), NULL); if ( rc == 2 ) { sprintf(temp, "/sbin/ip link set %s up", nics[found_NIC_as_Card[choise]].nic);