From patchwork Sun Jul 14 00:34:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Yeryomin X-Patchwork-Id: 1960263 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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 4WM5y12jNPz1xqc for ; Sun, 14 Jul 2024 10:37:08 +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=zqzF3MEZbBalJn5DNDKJ1NmoLXVn+oAzrUsHQzMqcAI=; b=qQy1atN04seEJ8 ImKuexBBT51XkTi3PONQtDnbQ/bKKjKHh8ZQYcN46hliu7OlC5t2BlGqCW7gcQWGRaD4TkKnr41j0 ecPi9tua+GYw/jBuRA5n55NXi1P8hU3GY0k7znUAKf0yk7COF6gaXIurTBcYSN420bE0caspR37b3 DtIlN+uOshGLBrcwMYoOlN8TbhAD2CJk249IuKCYGgdoUt1dfbHBUX0SCSNwi221uGq6mrkJallH1 CFRms3/g2OqgELkHUN3MEeqC6bycLwW6mmdCL+um48+AD4mltiORubY0oiBfMTv4IaTZouSGkgORz wsxRsufnVQJzr+RfWWlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sSnCv-00000003Tpv-2dsN; Sun, 14 Jul 2024 00:35:17 +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 1sSnCr-00000003Tof-1hcx for openwrt-devel@lists.openwrt.org; Sun, 14 Jul 2024 00:35:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=advem.lv; s=mail; t=1720917306; bh=q+LbsOSGRJEzOk3sMztS6ypqluy2iEl70SvExsP0hqg=; h=From:To:Subject:Date:From; b=o25tjcZj5Wn2/gnXVI/tX6f7sre8rZaaC3HVS8FF6FojvNcbrVIBHf/L0tnTY6NbD mE8AVmIcI0FwkInE3eWzI0Dc+v8XdXMPTl2hP4jQrvwyCfZBtr78+7+//Wpa/o0YZF bt6uS58uW5Q6eRuEySpHgtAr4LznNp+mMGaEw1/HuWu4hvqxoq63kfoZ/4ZDP8a/w1 AyKTt3jWT7ZQq7rpni0twV+rPCMXVtoipm5L8oS/NaQXbpDIOvPjIR9ice1q9ayorU RNxswfMdDv1k0W8pGINnIUebz3xmrHnXNjpGyZPInLHb6K6c+rOtSTmqn+PX/nIX7Y P09bg9AYJ/jtA== Received: from server.. (unknown [213.175.92.61]) by mail.pbx.lv (MailSystem) with ESMTPSA id 5DA831A5FE5 for ; Sun, 14 Jul 2024 03:35:06 +0300 (EEST) From: Roman Yeryomin To: OpenWrt Development List Subject: [RFC] netifd: add support for dhcp fallback to static ip Date: Sun, 14 Jul 2024 03:34:57 +0300 Message-ID: <20240714003458.11832-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-20240713_173514_332424_EE2B9458 X-CRM114-Status: GOOD ( 15.45 ) X-Spam-Score: -1.3 (-) 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 reacts on udhcpc events and sets/removes ipaddr which is configured on an iface from network config. This means that for an interface with proto set to dhcp but with fallback static IP disabled ( [...] Content analysis details: (-1.3 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_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 reacts on udhcpc events and sets/removes ipaddr which is configured on an iface from network config. This means that for an interface with proto set to dhcp but with fallback static IP disabled (ipaddr parameter is not set in config) cost of this feature is one uci call. If static fallback is enabled (ipaddr is present) then the cost is 3 uci calls and one ip call for each deconfig/renew/bound udhcpc event. It is not nothing but to me it seem like it's a very small overhead for such a convenience and I think it should be OpenWrt default at least for targets with one ethernet port. Signed-off-by: Roman Yeryomin --- package/network/config/netifd/Makefile | 1 - .../files/etc/udhcpc.user.d/fallbackip.sh | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 package/network/config/netifd/files/etc/udhcpc.user.d/fallbackip.sh diff --git a/package/network/config/netifd/Makefile b/package/network/config/netifd/Makefile index d80c2eeed6..8ef391d913 100644 --- a/package/network/config/netifd/Makefile +++ b/package/network/config/netifd/Makefile @@ -42,7 +42,6 @@ define Package/netifd/install $(INSTALL_DIR) $(1)/sbin $(INSTALL_BIN) $(PKG_BUILD_DIR)/netifd $(1)/sbin/ $(CP) ./files/* $(1)/ - $(INSTALL_DIR) $(1)/etc/udhcpc.user.d/ $(CP) \ $(PKG_BUILD_DIR)/scripts/utils.sh \ $(PKG_BUILD_DIR)/scripts/netifd-proto.sh \ diff --git a/package/network/config/netifd/files/etc/udhcpc.user.d/fallbackip.sh b/package/network/config/netifd/files/etc/udhcpc.user.d/fallbackip.sh new file mode 100644 index 0000000000..79984e9a2f --- /dev/null +++ b/package/network/config/netifd/files/etc/udhcpc.user.d/fallbackip.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1 + +ipaddr=$(uci get network.$INTERFACE.ipaddr) +[ -z "$ipaddr" ] && exit 0 + +ifname=$(uci get network.$INTERFACE.ifname) +[ -z "$ifname" ] && exit 0 + +netmask=$(uci get network.$INTERFACE.netmask) +[ -z "$netmask" ] && netmask=24 + +case "$1" in + deconfig) + ip ad add $ipaddr/$netmask dev $ifname + ;; + renew|bound) + ip ad del $ipaddr dev $ifname + ;; +esac + +exit 0