From patchwork Wed Oct 16 10:47:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 8188 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature RSA-PSS (4096 bits)) (Client CN "mail01.haj.ipfire.org", Issuer "R10" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4XT72n00lzz3wyH for ; Wed, 16 Oct 2024 10:47:28 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "E6" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4XT72j2Gr0z4Yg; Wed, 16 Oct 2024 10:47:25 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4XT72j0pKhz33g6; Wed, 16 Oct 2024 10:47:25 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mail01.haj.ipfire.org", Issuer "R10" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4XT72g0gzbz30XG for ; Wed, 16 Oct 2024 10:47:22 +0000 (UTC) Received: from michael.haj.ipfire.org (michael.haj.ipfire.org [172.28.1.242]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature ECDSA (secp384r1) client-digest SHA384) (Client CN "michael.haj.ipfire.org", Issuer "E6" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4XT72f1xKzzyc; Wed, 16 Oct 2024 10:47:22 +0000 (UTC) Received: by michael.haj.ipfire.org (Postfix, from userid 0) id 4XT72f0GBNzThhZ; Wed, 16 Oct 2024 10:47:21 +0000 (UTC) From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH] networking: Allow changing DHCP Option Rapid Commit Date: Wed, 16 Oct 2024 10:47:17 +0000 Message-Id: <20241016104717.3778264-1-michael.tremer@ipfire.org> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 Message-ID-Hash: VET6TQTHH2NYDSC42OG64VTNK5THKMVI X-Message-ID-Hash: VET6TQTHH2NYDSC42OG64VTNK5THKMVI X-MailFrom: root@michael.haj.ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Michael Tremer X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 Signed-off-by: Michael Tremer Tested-by: Adolf Belka --- config/dhcpc/dhcpcd.conf | 5 ---- src/initscripts/networking/red | 13 +++++++++- src/setup/netstuff.c | 47 +++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/config/dhcpc/dhcpcd.conf b/config/dhcpc/dhcpcd.conf index 062e3c975..b46c85cab 100644 --- a/config/dhcpc/dhcpcd.conf +++ b/config/dhcpc/dhcpcd.conf @@ -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 diff --git a/src/initscripts/networking/red b/src/initscripts/networking/red index 34ee8cc58..72b9bf0cf 100644 --- a/src/initscripts/networking/red +++ b/src/initscripts/networking/red @@ -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 diff --git a/src/setup/netstuff.c b/src/setup/netstuff.c index 60e27242f..602ef97f5 100644 --- a/src/setup/netstuff.c +++ b/src/setup/netstuff.c @@ -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);