luci-app-zerotier: fix bugs (#5276)

1.support muilt network id 
2.drop network config when stop 
3.restart service when network changed

code by CN_SZTL 1715173329
https://github.com/project-openwrt/openwrt
This commit is contained in:
mjyhj 2020-08-10 15:26:35 +08:00 committed by GitHub
parent b4bc0d39e2
commit 1a8e657689
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 37 deletions

View File

@ -10,7 +10,7 @@ LUCI_TITLE:=LuCI for Zerotier
LUCI_DEPENDS:=+zerotier
LUCI_PKGARCH:=all
PKG_VERSION:=1.0
PKG_RELEASE:=19
PKG_RELEASE:=20
include $(TOPDIR)/feeds/luci/luci.mk

View File

@ -5,11 +5,11 @@ f = SimpleForm("logview")
t = f:field(TextValue, "conf")
t.rmempty = true
t.rows = 15
t.rows = 19
function t.cfgvalue()
luci.sys.exec("ifconfig $(ifconfig | grep zt | awk '{print $1}') > /tmp/zero.info")
luci.sys.exec("for i in $(ifconfig | grep 'zt' | awk '{print $1}'); do ifconfig $i; done > /tmp/zero.info")
return fs.readfile(conffile) or ""
end
t.readonly="readonly"
return f
return f

View File

@ -7,6 +7,11 @@ USE_PROCD=1
PROG=/usr/bin/zerotier-one
CONFIG_PATH=/var/lib/zerotier-one
service_triggers() {
procd_add_reload_trigger "zerotier"
procd_add_interface_trigger "interface.*.up" wan /etc/init.d/zerotier restart
}
section_enabled() {
config_get_bool enabled "$1" 'enabled' 0
[ $enabled -gt 0 ]
@ -90,7 +95,10 @@ stop_instance() {
rm -f /tmp/zero.log
local cfg="$1"
/etc/zerotier.stop > /tmp/zero.log 2>&1 &
# Remove existing link or folder
rm -f $CONFIG_PATH/networks.d/*.conf
rm -rf $CONFIG_PATH
}
@ -99,3 +107,7 @@ stop_service() {
config_foreach stop_instance 'zerotier'
}
reload_service() {
stop
start
}

View File

@ -1,29 +1,28 @@
#!/bin/sh
zero_enable=$(uci get zerotier.sample_config.enabled)
zero_enable="$(uci get zerotier.sample_config.enabled)"
if [ $zero_enable -eq 1 ]; then
[ "${zero_enable}" -ne "1" ] && exit 0
if [ -f /tmp/zero.log ];then
while [ "$(ifconfig | grep zt | awk '{print $1}')" = "" ]
do
sleep 1
done
fi
[ -f "/tmp/zero.log" ] && {
while [ "$(ifconfig | grep 'zt' | awk '{print $1}')" = "" ]
do
sleep 1
done
}
nat_enable=$(uci get zerotier.sample_config.nat)
zt0=$(ifconfig | grep zt | awk '{print $1}')
nat_enable="$(uci get zerotier.sample_config.nat)"
zt0="$(ifconfig | grep 'zt' | awk '{print $1}')"
echo "${zt0}" > "/tmp/zt.nif"
echo $zt0 > /tmp/zt.nif
iptables -D FORWARD -i $zt0 -j ACCEPT 2>/dev/null
iptables -D FORWARD -o $zt0 -j ACCEPT 2>/dev/null
iptables -t nat -D POSTROUTING -o $zt0 -j MASQUERADE 2>/dev/null
if [ $nat_enable -eq 1 ]; then
iptables -I FORWARD -i $zt0 -j ACCEPT
iptables -I FORWARD -o $zt0 -j ACCEPT
iptables -t nat -I POSTROUTING -o $zt0 -j MASQUERADE
ip_segment=$(ip route | grep "dev $zt0 proto" | awk '{print $1}')
iptables -t nat -I POSTROUTING -s $ip_segment -j MASQUERADE
fi
fi
[ "${nat_enable}" -eq "1" ] && {
for i in ${zt0}
do
ip_segment=""
iptables -I FORWARD -i "$i" -j ACCEPT
iptables -I FORWARD -o "$i" -j ACCEPT
iptables -t nat -I POSTROUTING -o "$i" -j MASQUERADE
ip_segment="$(ip route | grep "dev $i proto" | awk '{print $1}')"
iptables -t nat -I POSTROUTING -s "${ip_segment}" -j MASQUERADE
done
}

View File

@ -1,12 +1,15 @@
#!/bin/sh
zt0=$(ifconfig | grep zt | awk '{print $1}')
if [ "$zt0" = "" ]; then
zt0=$(cat /tmp/cat /tmp/zt.nif)
fi
echo "zt interface $zt0 is stopped!"
iptables -D FORWARD -i $zt0 -j ACCEPT 2>/dev/null
iptables -D FORWARD -o $zt0 -j ACCEPT 2>/dev/null
iptables -t nat -D POSTROUTING -o $zt0 -j MASQUERADE 2>/dev/null
ip_segment=$(ip route | grep "dev $zt0 proto" | awk '{print $1}')
iptables -t nat -D POSTROUTING -s $ip_segment -j MASQUERADE 2>/dev/null
zt0="$(ifconfig | grep 'zt' | awk '{print $1}')"
[ -z "${zt0}" ] && zt0="$(cat "/tmp/zt.nif")"
for i in ${zt0}
do
ip_segment=""
iptables -D FORWARD -i "$i" -j ACCEPT 2>/dev/null
iptables -D FORWARD -o "$i" -j ACCEPT 2>/dev/null
iptables -t nat -D POSTROUTING -o "$i" -j MASQUERADE 2>/dev/null
ip_segment="$(ip route | grep "dev $i proto" | awk '{print $1}')"
iptables -t nat -D POSTROUTING -s "${ip_segment}" -j MASQUERADE 2>/dev/null
echo "zt interface $i is stopped!"
done