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.
This commit is contained in:
Tobias Mueller 2023-10-18 14:27:55 +02:00
parent d47916552d
commit d4886a54a9
4 changed files with 20 additions and 33 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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() {

View File

@ -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