From 8b4d371c9f2cc54ff237b29e42383df7be8ec06e Mon Sep 17 00:00:00 2001 From: Tobias Mueller Date: Tue, 17 Oct 2023 19:42:22 +0200 Subject: [PATCH] functions: Do not automatically restart the wifi on RESET_BSSIDS Instead of restarting the service we have the service started *after* our modification to its configuration. This makes it slightly more inconvenient to reset the WiFi BSSIDs while the device is booted but that capability can be restored and made better through an executable, say, /usr/bin/reset-wifi-bssids or something. We also split the volatile client MACs into its own service to have a bit of a clearer separation of duties. This will allow us to eventually split the package more easily into sub-packages with finer-grained control. --- files/etc/init.d/blue-merle | 18 ++++++++++++------ files/etc/init.d/volatile-client-macs | 19 +++++++++++++++++++ files/lib/blue-merle/functions.sh | 11 ++++++++++- files/lib/blue-merle/mac-wipe.sh | 11 ++++++++--- 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 files/etc/init.d/volatile-client-macs diff --git a/files/etc/init.d/blue-merle b/files/etc/init.d/blue-merle index 6c45c78..e0a3653 100755 --- a/files/etc/init.d/blue-merle +++ b/files/etc/init.d/blue-merle @@ -2,15 +2,21 @@ . /lib/blue-merle/functions.sh -START=81 +# We intend to be started before the first network-related service is started. +# According to https://openwrt.org/docs/techref/initscripts, /etc/rc.d/ determines +# the order of the services to be started (or stopped). The lower the number, +# the earlier the service is started. +# We observe "repeater" having the value 15. "network" 20. We certainly want to ahead of those. +START=14 STOP=99 - -start() { + +start() { /lib/blue-merle/mac-wipe.sh RESET_BSSIDS -} - -stop() { + RANDOMIZE_MACADDR +} + +stop() { /lib/blue-merle/mac-wipe.sh } diff --git a/files/etc/init.d/volatile-client-macs b/files/etc/init.d/volatile-client-macs new file mode 100644 index 0000000..128d06f --- /dev/null +++ b/files/etc/init.d/volatile-client-macs @@ -0,0 +1,19 @@ +#!/bin/sh /etc/rc.common + +# MAC addresses of connected clients are stored in a sqlite database. +# Having the database seems to be necessary for the device to be working properly. +# We intent to have the device store the database in RAM rather than on flash. +# We replace the directory with a memory-backed tmpfs which is as volatile as we can make it. + +# We want to run ahead of "gl-tertf" which, currently, has a prioprity of 20. +START=19 +STOP=99 + +start() { + /lib/blue-merle/mac-wipe.sh +} + +stop() { + shred /etc/oui-tertf/client.db || rm -f /etc/oui-tertf/client.db +} + diff --git a/files/lib/blue-merle/functions.sh b/files/lib/blue-merle/functions.sh index 7136c36..ff47a49 100644 --- a/files/lib/blue-merle/functions.sh +++ b/files/lib/blue-merle/functions.sh @@ -14,7 +14,16 @@ RESET_BSSIDS () { uci set wireless.@wifi-iface[1].macaddr=`UNICAST_MAC_GEN` uci set wireless.@wifi-iface[0].macaddr=`UNICAST_MAC_GEN` uci commit wireless - wifi # need to reset wifi for changes to apply + # you need to reset wifi for changes to apply, i.e. executing "wifi" +} + + +# This chaneges the MAC address clients see when connecting to the WiFi spawned by the device. +# You can check with "arp -a" that your endpoint, e.g. your laptop, sees a different MAC after a reboot of the Mudi. +RANDOMIZE_MACADDR () { + uci set network.@device[1].macaddr=`UNICAST_MAC_GEN` + uci commit network + # You need to restart the network, i.e. /etc/init.d/network restart } READ_IMEI () { diff --git a/files/lib/blue-merle/mac-wipe.sh b/files/lib/blue-merle/mac-wipe.sh index 29a3fba..306f7fb 100644 --- a/files/lib/blue-merle/mac-wipe.sh +++ b/files/lib/blue-merle/mac-wipe.sh @@ -15,6 +15,11 @@ mount -t tmpfs / /etc/oui-tertf cp -a "$tmpdir/client.db" /etc/oui-tertf/client.db umount -t tmpfs -l "$tmpdir" -logger -p notice -t blue-merle-mac-wipe "Restarting tertf..." -/etc/init.d/gl-tertf start -logger -p notice -t blue-merle-mac-wipe "... Finished" + +if [ $1 == "restart" ]; then + logger -p notice -t blue-merle-mac-wipe "Restarting tertf..." + /etc/init.d/gl-tertf start + logger -p notice -t blue-merle-mac-wipe "... Finished" +else + echo You will need to restart the gl-tertf service, i.e. /etc/init.d/gl-tertf restart +fi