From patchwork Mon Nov 4 21:22:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Schmutzler X-Patchwork-Id: 1189175 X-Patchwork-Delegate: freifunk@adrianschmutzler.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adrianschmutzler.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="KcKm98BZ"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 476Qkb5FZLz9s7T for ; Tue, 5 Nov 2019 08:23:03 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date: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=XewuDucK/chx0+loeGR3pkkGaC4fhLon67rKlmHPRT4=; b=KcKm98BZBLVcMs tU4yvsoDdsjtGnSwfZ509fjUAB39YR5NLrFjX71TfaAQJYPhAJ5ZqNB2QYqbfFSS8wBrblKUw4BTF Gnv+iDZf3IEVgqNNbFrKBsF/AYfiyZgzoTfNiAMxUVl/TpjMgPB1d4P2G9uZkDwaNjBvMD/G2V5L1 o1uA0XHkra5spthn8rkrPkGSyfr6+RsxGFsjKnPuVxeSOIsC6SsaBuENBRuTlTqj57YrYTzc9C2mE kN3/VrqGjZOmlDxgRU0zIJJB3cxR7pb7+SFtUoX+5QKT0FjBoffIHJgXlLM2YbOu5sYhHYn7EEZci TRMiNmiQOxumdoKuQhyQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iRjoR-0000uJ-QS; Mon, 04 Nov 2019 21:22:59 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iRjoO-0000tF-Me for openwrt-devel@lists.openwrt.org; Mon, 04 Nov 2019 21:22:58 +0000 Received: from buildfff.adridolf.com ([188.192.135.195]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N5n81-1hr7YH1uLD-017AuV for ; Mon, 04 Nov 2019 22:22:50 +0100 From: Adrian Schmutzler To: openwrt-devel@lists.openwrt.org Date: Mon, 4 Nov 2019 22:22:45 +0100 Message-Id: <20191104212246.37827-1-freifunk@adrianschmutzler.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Provags-ID: V03:K1:FEPf/x3HNa6cXjwF7yngLe27VAbjumfmxZk68UVy63VLiLB2Xpe sMXTtTqSRTFSiSwn4k/6oWUFfwcmyRfozJGu76kXm7E8xE0cBrJ8Y05lhHadhJ2gfZM1/d2 nMUqAO+iL3tRKca1h1yEAI1Fnlz46xAq0AYbyfvEbiQz2k6gh/gjhGfiWO6ASdDpOys0moW AHTTY+IU/Li602fh1VXyg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:xyuVg8AQc10=:rW+EvyFPPQHTqkdoV4PQl1 CZDBcHLuo4KJb4ewF9VAlCnIvFSzjjOMvY2z8z4p1nhKpeW+A+T5NQKu17RLxcxzdeqgc8uFb WjjrRcvS/VRg9Jn/GeCO7oO600dFxAw6dIEeQ5+lfw25MXSg2i4pCDNXWNJUvKftYW+X3W6co Dy/7WyDuqIugF0zJJVxGOAUeLMXlp9VA9R73E9X7IppQoL7gtnRVov3mUWhSfDJhxQRvFy5dr emRD8HVRRf+47QquOH5vVa1n7LEv6Xh+F1QV8wEqXDOKcyHKo2WUmxm9E+Y9qvCNAfkr9GwBa rAA+113Vcag3ZyltkFKDXPm/N0YQy/+0bh6sZhWEH3QLw60M4aK2Vcf9juq7yEUFbINiFR7oc YQKzxgEgBv5uFWOMRyqyVDvaVhKzz+/8QDkw0DOrwFiMC2vrDivE2iGfNiLXWAclbWDLfdBQT vhvBfmHSD9I6bDTSOTpbVE66JVA9vnEuDOWe45zObStMKVUsKf6EE83E5cdiXsCuZ6ENyBCrx UvNINvwbAHfNlYVnYpdFBIj/brt9d6s28WKPuOiBdLIzUEiM3t6MHid4RVGPD+3rBLyecBL+H UEBNaDVlYZqikJnIKO9R6sRdGDY4HfevejeU97PtZFziIGZhVDpGMoRu3dhJLk44SlAQE3m0f LRkO3JXGQx5CTTEctnF+frkbcbLKj8te1tj0B9ups4r2fG1FfjlWo/Xjmym6SvlE0t3RKgXSE 8Ol8AGCoeDmtVteosR9eIK5eRS/HcJHIoRA7pL6DwbwUSsT8uCMwNWhX1ab8xMGJwTOC88BUo DUlgNTxSaEAa4zBtRCQBL9ZJe1rQegvhJXRrtQpTL3HPfNvqCzGJBvRkIt8nrp5fq53Qd4JU+ 8DSSN1FLVwz9SwxAX4JHga4femFyQCV4iLey4m+ow= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191104_132257_043140_C035C970 X-CRM114-Status: GOOD ( 15.33 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [217.72.192.75 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH v3 1/2] base-files: don't store label MAC address in uci system config X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 If set, label MAC address is available from one of two sources, device tree or board.json. So far, the function get_mac_label was meant for retrieving the address, while an option in uci system config was specified only for case 2 (board.json). The uci config option has several drawbacks: - it is only used for a fraction of devices (those not in DT) - label MAC address is a device property, while config implies user interaction - label_macaddr option will only be set if /etc/config/system does not exist (i.e. only for new installations) Thus, this patch changes the behavior of get_mac_label: Instead of writing the value in board.json to uci system config and reading from this location afterwards, get_mac_label now extracts data from board.json directly. The uci config option won't be used anymore. In addition, two utility functions for extraction only from DT or from board.json are introduced. Since this is only changing the access to the label MAC address, it won't interfere with the addresses stored in the code base so far. Signed-off-by: Adrian Schmutzler --- This is an ALTERNATE version for discussion in competition to the v2 patchset. It has been tested on device already. --- package/base-files/files/bin/config_generate | 5 --- .../base-files/files/lib/functions/system.sh | 35 +++++++++++++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate index 0b26afe57f..3ca035ca8b 100755 --- a/package/base-files/files/bin/config_generate +++ b/package/base-files/files/bin/config_generate @@ -260,11 +260,6 @@ generate_static_system() { uci -q set "system.@system[-1].hostname=$hostname" fi - local label_macaddr - if json_get_var label_macaddr label_macaddr; then - uci -q set "system.@system[-1].label_macaddr=$label_macaddr" - fi - if json_is_a ntpserver array; then local keys key json_get_keys keys ntpserver diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh index cb0508fe9c..be7efe4e2e 100644 --- a/package/base-files/files/lib/functions/system.sh +++ b/package/base-files/files/lib/functions/system.sh @@ -1,5 +1,7 @@ # Copyright (C) 2006-2013 OpenWrt.org +. /usr/share/libubox/jshn.sh + get_mac_binary() { local path="$1" local offset="$2" @@ -12,14 +14,41 @@ get_mac_binary() { hexdump -v -n 6 -s $offset -e '5/1 "%02x:" 1/1 "%02x"' $path 2>/dev/null } -get_mac_label() { +get_mac_label_dt() { local basepath="/proc/device-tree" local macdevice="$(cat "$basepath/aliases/label-mac-device" 2>/dev/null)" local macaddr - [ -n "$macdevice" ] && macaddr=$(get_mac_binary "$basepath/$macdevice/mac-address" 0 2>/dev/null) + [ -n "$macdevice" ] || return + + macaddr=$(get_mac_binary "$basepath/$macdevice/mac-address" 0 2>/dev/null) [ -n "$macaddr" ] || macaddr=$(get_mac_binary "$basepath/$macdevice/local-mac-address" 0 2>/dev/null) - [ -n "$macaddr" ] || macaddr=$(uci -q get system.@system[0].label_macaddr) + + echo $macaddr +} + +get_mac_label_json() { + local cfg="/etc/board.json" + local macaddr + + [ -s "$cfg" ] || return + + json_init + json_load "$(cat $cfg)" + if json_is_a system object; then + json_select system + json_get_var macaddr label_macaddr + json_select .. + fi + + echo $macaddr +} + +get_mac_label() { + local macaddr=$(get_mac_label_dt) + + [ -n "$macaddr" ] || macaddr=$(get_mac_label_json) + echo $macaddr } From patchwork Mon Nov 4 21:22:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Schmutzler X-Patchwork-Id: 1189176 X-Patchwork-Delegate: freifunk@adrianschmutzler.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adrianschmutzler.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="booNy/tQ"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 476Qkn0gTdz9sP4 for ; Tue, 5 Nov 2019 08:23:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RXHSZEq9pAlCXG2qFB0Y1LMnJ3FBwZbaGP3SEGzD3a4=; b=booNy/tQpZ0Bmk uFx4Wk7NSXVPAj/lBkBrqupTsKZRyiqvTroyGKcsG0cj5lMRtEPV9vQrfjwB8rBW0vgaVyafAmOT9 ysmTSOgVuyfB6YSbQjWetqYyR2yDj0z8AK7jhnvPsMsR3VZjClQrOYhNJ8ogr7UHcke/CG8VThSom Dg2Q1N1m1uAglapIRiqM7WCEnngCX/xXJE37CNWCLKCsWEy032CabbwJ2Zwv2msZnmjv2vErfWOmF iwQJy4Zw9hqNuOpUYu3WisElT8dVOvaO2FNLqVw62d6VkMS8ywlZn7+XdJApRwFGOgbglJ7Yzs9Im ePcSu8NyaihrJHQ5noFQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iRjoa-00016Z-Er; Mon, 04 Nov 2019 21:23:08 +0000 Received: from mout.kundenserver.de ([217.72.192.73]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iRjoP-0000tM-MI for openwrt-devel@lists.openwrt.org; Mon, 04 Nov 2019 21:22:59 +0000 Received: from buildfff.adridolf.com ([188.192.135.195]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N18I8-1hmSiP0ubK-012U5G; Mon, 04 Nov 2019 22:22:51 +0100 From: Adrian Schmutzler To: openwrt-devel@lists.openwrt.org Date: Mon, 4 Nov 2019 22:22:46 +0100 Message-Id: <20191104212246.37827-2-freifunk@adrianschmutzler.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191104212246.37827-1-freifunk@adrianschmutzler.de> References: <20191104212246.37827-1-freifunk@adrianschmutzler.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:c7kiD8AEcj0gQehf/UGFmyyvd/cEsqtgRN+1WT8f2zWFr+RttGn YVk2uAJjx05z954mfVF9IeEJDZRsL9wVPWIUlApKHns4sGAMrDsvm6efPkhRSLqzyNzNqkl tzZZNQI9sY7fST8gD+Yo5VMlhAgRartf+b4UeRXZME+n3Cqdd4ohV6kW6b6eBEbY5zHkYTH o4rvd0ijqo+ZdPOzX1iMw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:zbTJTzIbE/k=:+G2/uGnNk6fw0FE5sKCz/v VEU3dmk3IePxDjHhwMsk8bt0mEhd5vIqlB/ahRFZADTxb/sxacjPTd7zcVq+Qcy+H66HOIlCi t4dkbumf/+OT2tQF4ssIbTNlkpZUs1K39eC9DQnY6Q+cusC46yGKODthqVcYWzm1OdX2JhNFp 7UWjX/PKWF6yZH0f0FZflroJYGZ4K8NA1xwopwLEj3y22EL9Vdw1PO+CVvtQiSKUv6axozMUr pLv9dkVvD7HzCJR6Oeb0h2mRomjf6X41sIeDaIaWyskc185XRCFPcZPMsFP5qpp9XM/Xv8V9Q fMCL0XEmPdBYwd2YX8we2jGquKu4ijosTYIcUd8sKVNYOEpbM7MYImjYxBkZH4EPP8OLMK40F 6gwbyxa1xpJibXVxzTs/uieKiEZ44lO5LdD+aAhQVlFt+QOa3tIgSeHwmIu9TnEwvEee/2rsV it+xHqCRsNl07gaENdqFBNl2TvYHM9QkmAykleMfB7vakrkkMAmWSj6sIKMjdGhoxA5T2fONx pc6XHkjQHvm9fVcuxM04hTyW2JD1PMAwz5xnMMWXSrUJ505Ttro4ex+SJKl8W+7YleHyyAuZZ iWqFAtCIm5Szez2VA8ht/XxI1gBOuXU6v+FggkQobSF5SgGaSaWe8+yUjcQZn4zg/8KriOcdq KGtpoUlZrBV5aHM2Mr7KXm5+84jMaL/1slMWD+MEt1p3ASLffupyzXbcTWXsVYalkyOFxKqX9 g9lhU2lIK3TDBFAObv01PKtbRQIkq2fTBPwnIzyGn70OvcLK8IPdZtFrs3wqRYnOEOFzkQBSa csg2SdHv2yO65IxLDL9HPygVqYZVrcS0QzupHX3MWDEoUsXfXhrrIhwsGURRMFvZjfGRlTMBr 3ZtrRAcBYMbLh45BfZZdzJncXEyeHB/BeNOBbC55Q= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191104_132258_014521_D3DC6FF6 X-CRM114-Status: GOOD ( 10.33 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [217.72.192.73 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH v3 2/2] base-files: rename hostname with EUI of mac address X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rosy Song Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Rosy Song If a label MAC address is provided for device, system will rename the hostname with OpenWrt_{eui mac address}. This helps to distinguish between different devices. Since it's no good idea to nest json_* functions, this code does not use get_mac_label directly, but only get_mac_label_dt as external resource. Signed-off-by: Rosy Song [merged with commit introducing macaddr_geteui, rebased on updated label MAC address storage, extended commit message] Signed-off-by: Adrian Schmutzler --- package/base-files/files/bin/config_generate | 16 +++++++++++++++- package/base-files/files/lib/functions/system.sh | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate index 3ca035ca8b..b473eba9e9 100755 --- a/package/base-files/files/bin/config_generate +++ b/package/base-files/files/bin/config_generate @@ -3,6 +3,7 @@ CFG=/etc/board.json . /usr/share/libubox/jshn.sh +. /lib/functions/system.sh [ -s $CFG ] || /bin/board_detect || exit 1 [ -s /etc/config/network -a -s /etc/config/system ] && exit 0 @@ -253,9 +254,22 @@ generate_static_system() { add_list system.ntp.server='3.openwrt.pool.ntp.org' EOF + local label_macaddr=$(get_mac_label_dt) + local hostname + + if json_is_a system object; then + json_select system + [ -n "$label_macaddr" ] || json_get_var label_macaddr label_macaddr + json_select .. + fi + + if [ -n "$label_macaddr" ]; then + hostname="OpenWrt-$(macaddr_geteui $label_macaddr)" + uci -q set "system.@system[-1].hostname=$hostname" + fi + if json_is_a system object; then json_select system - local hostname if json_get_var hostname hostname; then uci -q set "system.@system[-1].hostname=$hostname" fi diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh index be7efe4e2e..c4dc3cc3a9 100644 --- a/package/base-files/files/lib/functions/system.sh +++ b/package/base-files/files/lib/functions/system.sh @@ -144,6 +144,13 @@ macaddr_add() { echo $oui:$nic } +macaddr_geteui() { + local mac=$1 + local sep=$2 + + echo ${mac:9:2}$sep${mac:12:2}$sep${mac:15:2} +} + macaddr_setbit_la() { local mac=$1