From d4886a54a9494b1c31e35401a1c18c7f48c7570d Mon Sep 17 00:00:00 2001 From: Tobias Mueller Date: Wed, 18 Oct 2023 14:27:55 +0200 Subject: [PATCH] volatile-macs: define the service self-sufficiently This makes it hopefully a bit easier to see what we're doing because you don't need to chase the files down. We don't re-use that functionality anywhere. Neither would we. A more important change is not restarting the gl-tertf service. First of all, there seems to be no process attached to gl-tertf. It is the "Bandwidth Monitor" and part of the kmod-gl-sdk4-tertf package, so it's kernel module. It does not appear to be holding the clients.db. There is, however, gl_clients which also makes sense, naming wise. That service defines that /usr/bin/gl_clients_update ought to be run. And stracing it shows that it does indeed touch the database: open("/etc/oui-tertf/client.db", O_RDWR|O_CREAT|O_LARGEFILE|O_NOFOLLOW|O_CLOEXEC, 0644) = 7 It also appears to be re-creating the file when it's missing. Anyway, we have the service stopped during installation so that we can safely delete the file without the process complaining. We also install our volatile mac service s.t. it runs ahead of the gl-client service so that the clientdb gets saved in volatile memory. --- Makefile | 9 +++++++++ files/etc/init.d/blue-merle | 6 ------ files/etc/init.d/volatile-client-macs | 12 +++++++++++- files/lib/blue-merle/mac-wipe.sh | 26 -------------------------- 4 files changed, 20 insertions(+), 33 deletions(-) delete mode 100644 files/lib/blue-merle/mac-wipe.sh diff --git a/Makefile b/Makefile index 122655d..cae664b 100644 --- a/Makefile +++ b/Makefile @@ -81,12 +81,21 @@ define Package/blue-merle/preinst else ABORT_GLVERSION fi + + # Our volatile-mac service gets started during the installation + # but it modifies the client database held by the gl_clients process. + # So we stop that process now, have the database put onto volatile storage + # and start the service after installation + /etc/init.d/gl_clients stop endef define Package/blue-merle/postinst #!/bin/sh uci set switch-button.@main[0].func='sim' uci commit switch-button + + /etc/init.d/gl_clients start + echo {\"msg\": \"Successfully installed Blue Merle\"} > /dev/ttyS0 endef diff --git a/files/etc/init.d/blue-merle b/files/etc/init.d/blue-merle index e0a3653..ecbdc4f 100755 --- a/files/etc/init.d/blue-merle +++ b/files/etc/init.d/blue-merle @@ -11,12 +11,6 @@ START=14 STOP=99 start() { - /lib/blue-merle/mac-wipe.sh RESET_BSSIDS 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 index 8624a2e..7b12913 100644 --- a/files/etc/init.d/volatile-client-macs +++ b/files/etc/init.d/volatile-client-macs @@ -11,7 +11,17 @@ START=59 STOP=99 start() { - /lib/blue-merle/mac-wipe.sh + tmpdir="$(mktemp -d)" + # We mount a tmpfs so that the client database will be stored in memory only + mount -t tmpfs / "$tmpdir" + cp -a /etc/oui-tertf/client.db "$tmpdir" + shred /etc/oui-tertf/client.db || rm -f /etc/oui-tertf/client.db + # If this script runs multiple times, we accumulate mounts; we try to avoid having mounts over mounts, so we unmount any existing tmpfs + umount -t tmpfs -l /etc/oui-tertf + + mount -t tmpfs / /etc/oui-tertf + cp -a "$tmpdir/client.db" /etc/oui-tertf/client.db + umount -t tmpfs -l "$tmpdir" } stop() { diff --git a/files/lib/blue-merle/mac-wipe.sh b/files/lib/blue-merle/mac-wipe.sh deleted file mode 100644 index a8d5157..0000000 --- a/files/lib/blue-merle/mac-wipe.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env ash - -# This script ensures that MAC addresses are stored on volatile memory rather than flash - -tmpdir="$(mktemp -d)" -# We mount a tmpfs so that the client database will be stored in memory only -mount -t tmpfs / "$tmpdir" -## Somehow, we cannot "stop" this service as it does not define such action. There is also no such process. Weird. -# /etc/init.d/gl-tertf stop -cp -a /etc/oui-tertf/client.db "$tmpdir" -shred /etc/oui-tertf/client.db || rm -f /etc/oui-tertf/client.db -# If this script runs multiple times, we accumulate mounts; we try to avoid having mounts over mounts, so we unmount any existing tmpfs -umount -t tmpfs -l /etc/oui-tertf - -mount -t tmpfs / /etc/oui-tertf -cp -a "$tmpdir/client.db" /etc/oui-tertf/client.db -umount -t tmpfs -l "$tmpdir" - - -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