]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
network: Assign "static" MAC addresses to QMI interfaces
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Dec 2022 17:23:16 +0000 (17:23 +0000)
committerPeter Müller <peter.mueller@ipfire.org>
Sat, 17 Dec 2022 17:20:46 +0000 (17:20 +0000)
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 <michael.tremer@ipfire.org>
config/udev/network-hotplug-rename
src/initscripts/networking/functions.network

index 73e811e947b5db4c702c3a123515851c593a7db4..7c81bdb7814cacfc658b0859fcbe46532bc192e4 100644 (file)
@@ -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)
 
index 9698424fd1ccb0ceac2de51389a0a76e7e3708bb..e8f6c28d81b00f1ba694511daa81d519395313a4 100644 (file)
@@ -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}"
+}