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