From patchwork Sun Jul 14 19:39:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Yeryomin X-Patchwork-Id: 1960370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=lo3bCmJp; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=advem.lv header.i=@advem.lv header.a=rsa-sha256 header.s=mail header.b=KeHceYG7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WMbKY1F0Lz1xrK for ; Mon, 15 Jul 2024 05:40:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=YAk/mDVoOMCbzHPZQ/3c8DKrBYJhEzH/GHIXp5UUtow=; b=lo3bCmJppyAPD+ WXRJJWfUPj50bNf8iteW0J7qjU0t7Nub78L4olSyVdUgCYgoQzYkODG0g77DqZkg8LkD+7W16aCNT 0iL99T2SCRiE5p3NBF07jjBy4YK+QJIIS7TshKYQPhnxldsmUWo0K2E0yH9+un2ZDZNipUn5+XHu9 /oQg4YHOYdeG4NV69vP4iyeDVjUFY+/Nm6q4YLE/VRqCaufYVgtSSIQP5727q2ihL4F3CUjQSWlUX Dydbg3tKGHCNX6Zp7sOGiKcMO6QDyRJ/OZUkFqggibHqd1E8WO940WHqXThTFlC+9h6QVRyoujJLE Vw+ItDQfWyMKLUnRO4cg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sT54E-000000051Jk-0cJq; Sun, 14 Jul 2024 19:39:30 +0000 Received: from [213.175.92.62] (helo=mail.pbx.lv) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sT54A-000000051J5-0LDN for openwrt-devel@lists.openwrt.org; Sun, 14 Jul 2024 19:39:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=advem.lv; s=mail; t=1720985963; bh=SBKyu5rGgEvo59FlC8+xA2yAHD1F96YiWnevbjIdluo=; h=From:To:Subject:Date:From; b=KeHceYG7honIQsTfiR6RCrHjqOuUlr9qDNY8dyrTwus+iL+6bSK60XylmAKBYVHc9 /sMwO3l6o/iMcA6AphK5MPVgOBPtsUxsFXgj+v1blf9RM0a/SWANfWqpSmg53JBa9i 0wGppNqg31RyBAkI5lz3N6JgtLQBuwoB/WbOIUdjlws4npMLzQJucLsaHXqChQv7Rs RxsFqdMP2ve4+tBlN+m6NjYynolrUM5/vh6di7jlgf4PIM+Gxy69HacBg7cvuAuul6 CH91USnvVf2Ah4h1HXYrpqxaKoG1dqDS23NxxxKUtk/QWw/t8p6d1igFzcssA3zH68 Yd5BZw5uyUk5w== Received: from server.. (unknown [213.175.92.61]) by mail.pbx.lv (MailSystem) with ESMTPSA id 377E712F8C2 for ; Sun, 14 Jul 2024 22:39:23 +0300 (EEST) From: Roman Yeryomin To: OpenWrt Development List Subject: [PATCH] netifd: add support for dhcp fallback to static ip Date: Sun, 14 Jul 2024 22:39:15 +0300 Message-ID: <20240714193915.12764-1-roman@advem.lv> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240714_123927_744819_501DC2A3 X-CRM114-Status: UNSURE ( 9.93 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.7 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: It is pretty common use case for a network device to be configured as DHCP client but having some fallback static IP address where it would be reachable for, e.g., configuration. This adds 'fallbackip' network config option, which will be used on an interface until device receives an IP from DHCP server. Content analysis details: (0.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 2.0 LONGWORDS Long string of long words 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org It is pretty common use case for a network device to be configured as DHCP client but having some fallback static IP address where it would be reachable for, e.g., configuration. This adds 'fallbackip' network config option, which will be used on an interface until device receives an IP from DHCP server. Signed-off-by: Roman Yeryomin --- .../network/config/netifd/files/lib/netifd/dhcp.script | 8 +++++++- .../network/config/netifd/files/lib/netifd/proto/dhcp.sh | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/package/network/config/netifd/files/lib/netifd/dhcp.script b/package/network/config/netifd/files/lib/netifd/dhcp.script index db8deac9e6..da7c30f72c 100755 --- a/package/network/config/netifd/files/lib/netifd/dhcp.script +++ b/package/network/config/netifd/files/lib/netifd/dhcp.script @@ -98,7 +98,13 @@ setup_interface () { } deconfig_interface() { - proto_init_update "*" 0 + if [ -z "$FALLBACKIP" ]; then + proto_init_update "*" 0 + else + proto_init_update "*" 1 + proto_add_ipv4_address "$FALLBACKIP" "255.255.255.0" + fi + proto_send_update "$INTERFACE" } diff --git a/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh b/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh index 636b4654ff..020038f0f8 100755 --- a/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh +++ b/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh @@ -10,6 +10,7 @@ proto_dhcp_init_config() { renew_handler=1 proto_config_add_string 'ipaddr:ipaddr' + proto_config_add_string 'fallbackip:fallbackip' proto_config_add_string 'hostname:hostname' proto_config_add_string clientid proto_config_add_string vendorid @@ -35,8 +36,8 @@ proto_dhcp_setup() { local config="$1" local iface="$2" - local ipaddr hostname clientid vendorid broadcast norelease reqopts defaultreqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes classlessroute - json_get_vars ipaddr hostname clientid vendorid broadcast norelease reqopts defaultreqopts iface6rd delegate zone6rd zone mtu6rd customroutes classlessroute + local ipaddr fallbackip hostname clientid vendorid broadcast norelease reqopts defaultreqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes classlessroute + json_get_vars ipaddr fallbackip hostname clientid vendorid broadcast norelease reqopts defaultreqopts iface6rd delegate zone6rd zone mtu6rd customroutes classlessroute local opt dhcpopts for opt in $reqopts; do @@ -63,6 +64,8 @@ proto_dhcp_setup() { [ "$classlessroute" = "0" ] || append dhcpopts "-O 121" proto_export "INTERFACE=$config" + proto_export "FALLBACKIP=$fallbackip" + proto_run_command "$config" udhcpc \ -p /var/run/udhcpc-$iface.pid \ -s /lib/netifd/dhcp.script \