setup: move gateway setting to red address setting.

DEFAULT_GATEWAY is used only in RED_STATIC config so it
fits better to this menu and is only selectable if red
is set to static mode.

Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Arne Fitzenreiter
2021-01-09 18:39:00 +01:00
committed by Michael Tremer
parent f0b53518e5
commit 14cb18a539
2 changed files with 33 additions and 89 deletions

View File

@@ -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];
@@ -80,12 +84,13 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
/* 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);
@@ -129,6 +134,18 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
}
/* 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);
}
/* Address */
addresslabel = newtTextbox(2, (typeflag ? 11 : 4) + 0, 18, 1, 0);
@@ -154,9 +171,10 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
newtFormAddComponent(networkform, netmasklabel);
newtFormAddComponent(networkform, netmaskentry);
/* 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);
@@ -191,6 +209,13 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
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)
{
@@ -214,13 +239,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
{
@@ -311,11 +338,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)
{

View File

@@ -51,7 +51,6 @@ int drivermenu(void);
int changedrivers(void);
int greenaddressmenu(void);
int addressesmenu(void);
int gatewaymenu(void);
int handlenetworking(void)
{
@@ -83,10 +82,6 @@ int handlenetworking(void)
addressesmenu();
break;
case 4:
gatewaymenu();
break;
case 0:
if (oktoleave()) done = 1;
break;
@@ -215,18 +210,6 @@ int oktoleave(void)
return 0;
}
}
strcpy(temp, ""); findkey(kv, "RED_TYPE", temp);
if ((configtype == 0) || (strcmp(temp, "STATIC") == 0))
{
strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
if (!(strlen(temp)))
{
errorbox(_("Missing Default Gateway."));
freekeyvalues(kv);
return 0;
}
}
return 1;
}
@@ -238,7 +221,6 @@ int firstmenu(void)
_("Network configuration type"),
_("Drivers and card assignments"),
_("Address settings"),
_("Gateway settings"),
NULL
};
int rc;
@@ -695,70 +677,3 @@ int addressesmenu(void)
return 0;
}
/* default gateway.... */
int gatewaymenu(void)
{
struct keyvalue *kv = initkeyvalues();
char message[1000];
char temp[STRING_SIZE] = "0";
struct newtWinEntry entries[2];
char* values[1]; /* pointers for the values. */
int error;
int configtype;
int rc;
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(_("Unable to open settings file"));
return 0;
}
entries[0].text = _("Default gateway:");
strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
values[0] = strdup(temp);
entries[0].value = &values[0];
entries[0].flags = 0;
entries[1].text = NULL;
entries[1].value = NULL;
entries[1].flags = 0;
do
{
error = 0;
rc = newtWinEntries(_("Gateway settings"),
_("Enter the gateway information. "
"These settings are used only with Static IP on the RED interface."),
50, 5, 5, 18, entries, _("OK"), _("Cancel"), NULL);
if (rc == 0 || rc == 1)
{
if (strlen(values[0]))
{
if (inet_addr(values[0]) == INADDR_NONE)
{
strcat(message, _("Default gateway"));
strcat(message, "\n");
error = 1;
}
}
if (error)
errorbox(message);
else
{
replacekeyvalue(kv, "DEFAULT_GATEWAY", values[0]);
netaddresschange = 1;
free(values[0]);
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
}
}
}
while (error);
freekeyvalues(kv);
return 1;
}