From d81d665069150c557085f8bba24fc81f716df574 Mon Sep 17 00:00:00 2001 From: zhao Date: Wed, 4 Jun 2025 19:47:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20files/nat6.hotplug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhao --- files/nat6.hotplug | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 files/nat6.hotplug diff --git a/files/nat6.hotplug b/files/nat6.hotplug new file mode 100644 index 0000000..002a2b7 --- /dev/null +++ b/files/nat6.hotplug @@ -0,0 +1,19 @@ +#!/bin/sh + +[ "$(uci -q get firewall.@defaults[0].nat6)" != "1" ] && exit 0 + +dhcpv6_interface=$(uci -q show network | grep dhcpv6 | grep -o 'network\.\([^\.]*\)' | sed 's/network.//') +IFS=$'\n' +for interface_name in $dhcpv6_interface +do + device=$(uci -q show network.$interface_name.device | grep -o "'.*'" | awk -F"'" '{print $2}') + if [ $(ifconfig $device | grep -c "inet6 addr") -gt 0 ]; then + interface_name=$interface_name + fi +done + +[ "$INTERFACE" = "$interface_name" ] || exit 0 + +if [ "$ACTION" = ifup ] || [ "$ACTION" = iflink ] || [ "$ACTION" = ifupdate ] || [ "$ACTION" = reload ]; then + /etc/init.d/nat6 restart +fi \ No newline at end of file