I think you can do that by appending iptables rules + ipset. Then add needed MACs to the ipset hash set, why ipset because you can easily add/remove without altering iptables rules
https://ipset.netfilter.org/ipset.man.html
Checking if module:
From my TO2020, TO5.3.9
root@turris:~# modinfo ip_set_hash_mac
module: /lib/modules/4.14.277/ip_set_hash_mac.ko
alias: ip_set_hash:mac
license: GPL
depends: ip_set
Sample:
Create mac hash set and add some mac to the set
ipset create -exist customAllowedMacs hash:mac maxelem 4294967295
ipset add customAllowedMacs XX:XX:XX:XX:XX:XX
ipset add customAllowedMacs YY:YY:YY:YY:YY:YY
The above lines can be added to user rules script(manually or from Luci) to bring up during boot.
MACs can be added/removed(cmd-line) from set at any time without requiring firewall restart/reboot, or can be appended in the user rules script.
Firewall rules can be something like below(if block is for checking if rules added before).
So it can be added to custom user rules script(manually or from Luci), and can survive firewall restart and reboot, additionally I appended with logging option:
if ! iptables -S|grep -q "\-N\ input_log_and_drop"; then
iptables -N input_log_and_drop
iptables -A input_log_and_drop -m limit --limit 5/m --limit-burst 10 -j LOG
iptables -A input_log_and_drop -j DROP
fi
if ! iptables -S|grep -q "\-A\ input_lan_rule\ \-m\ set\ \-\-match\-set\ customAllowedMacs\ src\ \-j\ RETURN"; then
iptables -A input_lan_rule -m set --match-set customAllowedMacs src -j RETURN
iptables -A input_lan_rule -j input_log_and_drop
fi
You may also need to add same rules for the guest network as well, just copy the 2nd one(logging chain is generic) and replace “input_lan_rule” with the guest one.
Regarding disabling/enabling you need to create 2 scripts and add to the cron.
For disabling, which will basically remove the rules:
#!/bin/sh
if iptables -S|grep -q "\-A\ input_lan_rule\ \-m\ set\ \-\-match\-set\ customAllowedMacs\ src\ \-j\ RETURN"; then
iptables -D input_lan_rule -m set --match-set customAllowedMacs src -j RETURN
iptables -D input_lan_rule -j input_log_and_drop
fi
For enabling back:
#!/bin/sh
if ! iptables -S|grep -q "\-A\ input_lan_rule\ \-m\ set\ \-\-match\-set\ customAllowedMacs\ src\ \-j\ RETURN"; then
iptables -A input_lan_rule -m set --match-set customAllowedMacs src -j RETURN
iptables -A input_lan_rule -j input_log_and_drop
fi
Edit: Updated