nat6: fix hotplug not working
This commit is contained in:
parent
17eb5419a3
commit
b3f281dc80
@ -24,6 +24,28 @@ interface() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hotplug_iface() {
|
||||||
|
[ ! -f /etc/hotplug.d/iface/90-nat6 ] && cat > /etc/hotplug.d/iface/90-nat6 << "EOF"
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
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
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
common_config() {
|
common_config() {
|
||||||
if [ -z $(uci -q get network.globals.ula_prefix) ] || [ $(uci -q get network.globals.ula_prefix | grep -c "/48") != 1 ]; then
|
if [ -z $(uci -q get network.globals.ula_prefix) ] || [ $(uci -q get network.globals.ula_prefix | grep -c "/48") != 1 ]; then
|
||||||
r1=$(dd if=/dev/urandom bs=1 count=1 2>/dev/null | hexdump -e '1/1 "%02x"')
|
r1=$(dd if=/dev/urandom bs=1 count=1 2>/dev/null | hexdump -e '1/1 "%02x"')
|
||||||
@ -56,6 +78,7 @@ EOF
|
|||||||
start() {
|
start() {
|
||||||
[ "$(uci -q get firewall.@defaults[0].nat6)" != 1 ] && return 0
|
[ "$(uci -q get firewall.@defaults[0].nat6)" != 1 ] && return 0
|
||||||
interface
|
interface
|
||||||
|
hotplug_iface
|
||||||
[ -z "$device" ] && logger -p error -t network -s "nat6: DHCPv6 interface device not configured, IPv6 NAT failed." && exit 0
|
[ -z "$device" ] && logger -p error -t network -s "nat6: DHCPv6 interface device not configured, IPv6 NAT failed." && exit 0
|
||||||
[ -z "$gateway" ] && logger -p error -t network -s "nat6: DHCPv6 gateway not found, IPv6 NAT failed." && exit 0
|
[ -z "$gateway" ] && logger -p error -t network -s "nat6: DHCPv6 gateway not found, IPv6 NAT failed." && exit 0
|
||||||
common_config
|
common_config
|
||||||
@ -65,25 +88,6 @@ start() {
|
|||||||
nft add chain ip6 nat prerouting { type nat hook prerouting priority 0\; } 2>/dev/null
|
nft add chain ip6 nat prerouting { type nat hook prerouting priority 0\; } 2>/dev/null
|
||||||
nft add chain ip6 nat postrouting { type nat hook postrouting priority 100\; } 2>/dev/null
|
nft add chain ip6 nat postrouting { type nat hook postrouting priority 100\; } 2>/dev/null
|
||||||
nft add rule ip6 nat postrouting oif $device masquerade 2>/dev/null
|
nft add rule ip6 nat postrouting oif $device masquerade 2>/dev/null
|
||||||
[ ! -f /etc/hotplug.d/iface/90-nat6 ] && cat > /etc/hotplug.d/iface/90-nat6 << "EOF"
|
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
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
|
|
||||||
EOF
|
|
||||||
logger -p notice -t network -s "nat6: IPv6 NAT is ready"
|
logger -p notice -t network -s "nat6: IPv6 NAT is ready"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user