networking: Allow changing DHCP Option Rapid Commit

This option needs to be configurable since some (braindead) ISPs have
started running broken DHCP servers to be bug-compatible with cheap
broken plastic routers.

By default we keep this option enabled, but it can now be turned off
whenever needed.

Suggested-by: Adolf Belka <adolf.belka@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Tested-by: Adolf Belka <adolf.belka@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
This commit is contained in:
Michael Tremer
2024-10-16 10:47:17 +00:00
committed by Arne Fitzenreiter
parent 7350feee58
commit c6282b001b
3 changed files with 50 additions and 15 deletions

View File

@@ -37,11 +37,6 @@ option host_name
# Most distributions have NTP support.
option ntp_servers
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit
# A ServerID is required by RFC2131.
require dhcp_server_identifier

View File

@@ -171,9 +171,20 @@ case "${1}" in
# To determine this we check if a wpa_supplicant is running.
pid="$(pidof wpa_supplicant)"
DHCPCD_ARGS=()
# Enable Rapid Commit (enabled by default)
case "${RED_DHCP_RAPID_COMMIT}" in
""|yes|true|on)
DHCPCD_ARGS+=( "--option" "rapid_commit" )
;;
esac
echo dhcpcd_start "${DEVICE}" "${DHCPCD_ARGS[@]}"
if [ -z "${pid}" ]; then
# No wpa_supplicant is running. So it's save to start dhcpcd.
dhcpcd_start "${DEVICE}"
dhcpcd_start "${DEVICE}" "${DHCPCD_ARGS[@]}"
fi
elif [ "$TYPE" == "PPPOE" ]; then

View File

@@ -37,6 +37,7 @@ newtComponent dhcptyperadio;
newtComponent pppoetyperadio;
newtComponent dhcphostnameentry;
newtComponent dhcpforcemtuentry;
newtComponent dhcprapidcommitentry;
/* acceptable character filter for IP and netmaks entry boxes */
static int ip_input_filter(newtComponent entry, void * data, int ch, int cursor)
@@ -64,6 +65,7 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
newtComponent gatewaylabel;
newtComponent dhcphostnamelabel;
newtComponent dhcpforcemtulabel;
newtComponent dhcprapidcommitlabel;
newtComponent ok, cancel;
char message[1000];
char temp[STRING_SIZE];
@@ -73,6 +75,8 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
char typefield[STRING_SIZE];
char dhcphostnamefield[STRING_SIZE];
char dhcpforcemtufield[STRING_SIZE];
char dhcprapidcommitfield[STRING_SIZE];
char enablerapidcommit;
int error;
int result = 0;
char type[STRING_SIZE];
@@ -88,9 +92,10 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
sprintf(typefield, "%s_TYPE", colour);
sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour);
sprintf(dhcpforcemtufield, "%s_DHCP_FORCE_MTU", colour);
sprintf(dhcprapidcommitfield, "%s_DHCP_RAPID_COMMIT", colour);
sprintf(message, _("Interface - %s"), colour);
newtCenteredWindow(44, (typeflag ? 19 : 12), message);
newtCenteredWindow(44, (typeflag ? 20 : 12), message);
networkform = newtForm(NULL, NULL, 0);
@@ -102,6 +107,15 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
* of the window down two rows to make room. */
if (typeflag)
{
*temp = '\0';
// Find RapidCommit setting
findkey(kv, dhcprapidcommitfield, temp);
if (strcmp(temp, "yes") == 0 || strcmp(temp, "true") == 0 || strcmp(temp, "on") == 0 || strcmp(temp, "") == 0)
enablerapidcommit = '*';
else
enablerapidcommit = ' ';
strcpy(temp, "STATIC"); findkey(kv, typefield, temp);
if (strcmp(temp, "STATIC") == 0) startstatictype = 1;
if (strcmp(temp, "DHCP") == 0) startdhcptype = 1;
@@ -119,28 +133,35 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
newtTextboxSetText(dhcphostnamelabel, _("DHCP Hostname:"));
dhcpforcemtulabel = newtTextbox(2, 9, 18, 1, 0);
newtTextboxSetText(dhcpforcemtulabel, _("Force DHCP MTU:"));
dhcprapidcommitlabel = newtTextbox(2, 10, 18, 1, 0);
newtTextboxSetText(dhcprapidcommitlabel, _("Rapid Commit:"));
strcpy(temp, defaultdhcphostname);
findkey(kv, dhcphostnamefield, temp);
dhcphostnameentry = newtEntry(20, 8, temp, 20, &dhcphostnameresult, 0);
strcpy(temp, "");
findkey(kv, dhcpforcemtufield, temp);
dhcpforcemtuentry = newtEntry(20, 9, temp, 20, &dhcpforcemturesult, 0);
dhcprapidcommitentry = newtCheckbox(20, 10, "", enablerapidcommit, " *", &enablerapidcommit);
newtComponentAddCallback(dhcprapidcommitentry, networkdialogcallbacktype, NULL);
newtFormAddComponent(networkform, dhcphostnamelabel);
newtFormAddComponent(networkform, dhcphostnameentry);
newtFormAddComponent(networkform, dhcpforcemtulabel);
newtFormAddComponent(networkform, dhcpforcemtuentry);
newtFormAddComponent(networkform, dhcprapidcommitlabel);
newtFormAddComponent(networkform, dhcprapidcommitentry);
if (startdhcptype == 0)
{
newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtCheckboxSetFlags(dhcprapidcommitentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
}
}
/* Address */
addresslabel = newtTextbox(2, (typeflag ? 11 : 4) + 0, 18, 1, 0);
addresslabel = newtTextbox(2, (typeflag ? 12 : 4) + 0, 18, 1, 0);
newtTextboxSetText(addresslabel, _("IP address:"));
strcpy(temp, "");
findkey(kv, addressfield, temp);
addressentry = newtEntry(20, (typeflag ? 11 : 4) + 0, temp, 20, &addressresult, 0);
addressentry = newtEntry(20, (typeflag ? 12 : 4) + 0, temp, 20, &addressresult, 0);
newtEntrySetFilter(addressentry, ip_input_filter, NULL);
if (typeflag == 1 && startstatictype == 0)
newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
@@ -148,10 +169,10 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
newtFormAddComponent(networkform, addressentry);
/* Netmask */
netmasklabel = newtTextbox(2, (typeflag ? 11 : 4) + 1, 18, 1, 0);
netmasklabel = newtTextbox(2, (typeflag ? 12 : 4) + 1, 18, 1, 0);
newtTextboxSetText(netmasklabel, _("Network mask:"));
strcpy(temp, "255.255.255.0"); findkey(kv, netmaskfield, temp);
netmaskentry = newtEntry(20, (typeflag ? 11 : 4) + 1, temp, 20, &netmaskresult, 0);
netmaskentry = newtEntry(20, (typeflag ? 12 : 4) + 1, temp, 20, &netmaskresult, 0);
newtEntrySetFilter(netmaskentry, ip_input_filter, NULL);
if (typeflag == 1 && startstatictype == 0)
newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
@@ -162,11 +183,11 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
if (typeflag)
{
/* Gateway */
gatewaylabel = newtTextbox(2, (typeflag ? 11 : 4) + 2, 18, 1, 0);
gatewaylabel = newtTextbox(2, (typeflag ? 12 : 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);
gatewayentry = newtEntry(20, (typeflag ? 12 : 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);
@@ -175,8 +196,8 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
}
/* Buttons. */
ok = newtButton(8, (typeflag ? 15 : 7), _("OK"));
cancel = newtButton(26, (typeflag ? 15 : 7), _("Cancel"));
ok = newtButton(8, (typeflag ? 16 : 7), _("OK"));
cancel = newtButton(26, (typeflag ? 16 : 7), _("Cancel"));
newtFormAddComponents(networkform, ok, cancel, NULL);
@@ -237,6 +258,12 @@ int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
{
replacekeyvalue(kv, dhcphostnamefield, dhcphostnameresult);
replacekeyvalue(kv, dhcpforcemtufield, dhcpforcemturesult);
if (enablerapidcommit == '*')
replacekeyvalue(kv, dhcprapidcommitfield, "on");
else
replacekeyvalue(kv, dhcprapidcommitfield, "off");
if (strcmp(type, "STATIC") != 0)
{
replacekeyvalue(kv, addressfield, "0.0.0.0");
@@ -352,11 +379,13 @@ void networkdialogcallbacktype(newtComponent cm, void *data)
{
newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
newtCheckboxSetFlags(dhcprapidcommitentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
}
else
{
newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtCheckboxSetFlags(dhcprapidcommitentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
}
newtRefresh();
newtDrawForm(networkform);