From patchwork Thu Dec 1 17:23:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 6263 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 (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4NNNGK0Bb2z3xkZ for ; Thu, 1 Dec 2022 17:23:53 +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 ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4NNNFy0n9Gz2y1; Thu, 1 Dec 2022 17:23:34 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4NNNFq1BdMz30Cg; Thu, 1 Dec 2022 17:23:27 +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 (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4NNNFl5R4vz30CM for ; Thu, 1 Dec 2022 17:23:23 +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 ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "michael.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4NNNFl4PXxz2sg; Thu, 1 Dec 2022 17:23:23 +0000 (UTC) Received: by michael.haj.ipfire.org (Postfix, from userid 0) id 4NNNFl49fBzTjnJ; Thu, 1 Dec 2022 17:23:23 +0000 (UTC) From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH 27/29] network: Assign "static" MAC addresses to QMI interfaces Date: Thu, 1 Dec 2022 17:23:16 +0000 Message-Id: <20221201172318.3166615-27-michael.tremer@ipfire.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221201172318.3166615-1-michael.tremer@ipfire.org> References: <20221201172318.3166615-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This is really badly hacky, but I do not know a better way to solve this with our existing "setup" program which would be a nightmare to extend. So we are using the device number to generate a static MAC address which can then be used as usual. I doubt many people will have more than one device. Signed-off-by: Michael Tremer --- config/udev/network-hotplug-rename | 9 ++++++++ src/initscripts/networking/functions.network | 24 +++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/config/udev/network-hotplug-rename b/config/udev/network-hotplug-rename index 73e811e94..7c81bdb78 100644 --- a/config/udev/network-hotplug-rename +++ b/config/udev/network-hotplug-rename @@ -19,6 +19,8 @@ # # ############################################################################### +. /etc/rc.d/init.d/networking/functions.network + # Check if all appropriate variables are set [ -n "${INTERFACE}" ] || exit 2 @@ -44,6 +46,13 @@ if [ ! -r "/var/ipfire/ethernet/settings" ]; then exit 1 fi +# Change MAC addresses of QMI interface +if [ -d "/sys/class/net/${INTERFACE}/qmi" ]; then + if ! qmi_assign_address "${INTERFACE}"; then + exit 1 + fi +fi + # Read network settings eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) diff --git a/src/initscripts/networking/functions.network b/src/initscripts/networking/functions.network index 9698424fd..e8f6c28d8 100644 --- a/src/initscripts/networking/functions.network +++ b/src/initscripts/networking/functions.network @@ -179,7 +179,7 @@ qmi_find_device() { local path for path in /dev/cdc-*; do if [ -c "${path}" ]; then - _intf="$(qmicli --device="${path}" --device-open-proxy --get-wwan-iface)" + _intf="$(qmi_find_interface "${path}")" # Check if the interface matches if [ "${intf}" = "${_intf}" ]; then @@ -193,6 +193,12 @@ qmi_find_device() { return 1 } +qmi_find_interface() { + local device="${1}" + + qmicli --device="${device}" --device-open-proxy --get-wwan-iface +} + qmi_enable_rawip_mode() { local intf="${1}" @@ -259,3 +265,19 @@ qmi_reset() { qmicli --device="${device}" --device-open-proxy \ --wds-reset } + +# Assigns a "static" MAC address +qmi_assign_address() { + local intf="${1}" + + # Find the device + local device="$(qmi_find_device "${intf}")" + + local address + + # Generate a "random" MAC address using the device number + printf -v address "02:ff:ff:ff:ff:%02x" "${device:12}" + + # Change the MAC address + ip link set "${intf}" address "${address}" +}