Hello,
I'm helping someone setup their GL.iNet Brume 2 with a Tailscale exit node. Previously (as of firmware version 4.2.1), I would simply replace the following line:
/usr/sbin/tailscale up --reset $param --timeout 3s
with
/usr/sbin/tailscale up --advertise-exit-node --reset $param --timeout 3s
But I'm not seeing this line in the file anymore when looking at the below file contents:
root@GL-MT2500:/# cat /usr/bin/gl_tailscale
#!/bin/sh
action="$1"
TS_POLICY_ROUTE=/tmp/ts_policy_route
TS_FIREWALL_SECTION=gltailscale
TAILSCALE_ROUTE_TABLE=52
TAILSCALE_DNS_SERVER="100.100.100.100"
if [ "$action" == "set_route" ];then
sleep 5
ip route add 100.64.0.0/10 dev tailscale0
fi
add_policy_route()
{
target=$1
if [ -n "$target" ]; then
route_param="to $target table main"
/sbin/ip rule add $route_param
echo $route_param >> $TS_POLICY_ROUTE
fi
}
del_policy_route()
{
/sbin/ip rule del to $TAILSCALE_DNS_SERVER lookup $TAILSCALE_ROUTE_TABLE pri 50
if [ -f $TS_POLICY_ROUTE ]; then
while read line; do
if [ -n "$line" ]; then
/sbin/ip rule del $line
fi
done < $TS_POLICY_ROUTE
rm $TS_POLICY_ROUTE
fi
}
add_guest_policy_route()
{
guest_disable=$(uci -q get network.guest.disabled)
exit_node_ip=$(uci -q get tailscale.settings.exit_node_ip)
if [ -n "$exit_node_ip" ] && [ "$guest_disable" == "0" ]; then
guestip=$(ubus call network.interface.guest status|jsonfilter -e '@["ipv4-address"][0].address')
guestmask=$(ubus call network.interface.guest status|jsonfilter -e '@["ipv4-address"][0].mask')
if [ -n "$guestip" ] && [ -n "$guestmask" ] ;then
guest_network=$(ipcalc.sh $guestip $guestmask | awk -F= '/NETWORK/{print $2}')
guest_mask=$(ipcalc.sh $guestip $guestmask | awk -F= '/PREFIX/{print $2}')
fi
if [ -n "$guest_network" ] && [ -n "$guest_mask" ]; then
guest_ip="$guest_network/$guest_mask"
policy_route_param="from $guest_ip table main"
/sbin/ip rule add $policy_route_param
echo $policy_route_param >> $TS_POLICY_ROUTE
fi
fi
}
add_exit_node_rule()
{
count=0
while [ $count -le 5 ]
do
rule_exist=$(ip rule | grep "from all fwmark 0x80000/0x80000 lookup")
ts_prio=$(ip rule | grep "from all lookup 52" | awk -F':' '{print $1}' | head -n 1)
if [ "$rule_exist" == "" ]; then
if [ -n "$ts_prio" ]; then
pre_prio=$(($ts_prio-1))
policy_route_param="from all fwmark 0x80000/0x80000 lookup main prio $pre_prio"
/sbin/ip rule add $policy_route_param
echo $policy_route_param >> $TS_POLICY_ROUTE
fi
else
break
fi
count=$(($count+1))
sleep 1
done
}
add_ts_fw_rule()
{
if [ -f /etc/firewall.tailscale.sh ]; then
/etc/firewall.tailscale.sh &
fi
}
modify_dns_resolv()
{
dns_suffix=$(tailscale status -json | jsonfilter -e '@.MagicDNSSuffix')
rule_exist=$(grep "ts.net/100.100.100.100" /etc/dnsmasq.conf)
domain_orig=$(uci get dhcp.@dnsmasq[0].domain)
domain_orig_clean=$(echo "$domain_orig" | sed "s/.*ts.net //g")
if [ "$1" == "1" ]; then
if [ "$rule_exist" == "" ]; then
[ "$dns_suffix" == "" ] && dns_suffix="ts.net"
echo "server=/$dns_suffix/100.100.100.100" >> /etc/dnsmasq.conf
uci set dhcp.@dnsmasq[0].domain="$dns_suffix $domain_orig_clean"
uci commit dhcp
/etc/init.d/dnsmasq restart
fi
else
uci set dhcp.@dnsmasq[0].domain="$domain_orig_clean"
uci commit dhcp
if [ -n "$rule_exist" ]; then
sed -i '/ts\.net\/100\.100\.100\.100/d' /etc/dnsmasq.conf
/etc/init.d/dnsmasq restart
fi
fi
}
if [ "$action" == "restart" ];then
/etc/init.d/tailscale restart
del_policy_route
add_ts_fw_rule
sys_mode=$(uci -q get glconfig.general.mode)
if [ "$sys_mode" != "router" ]; then
/etc/init.d/tailscale stop
modify_dns_resolv 0
exit 0
fi
enabled=$(uci -q get tailscale.settings.enabled)
if [ "$enabled" == "1" ]; then
/sbin/ip rule add to $TAILSCALE_DNS_SERVER lookup $TAILSCALE_ROUTE_TABLE pri 50
wanip=$(ubus call network.interface.wan status|jsonfilter -e '@["ipv4-address"][0].address')
wanmask=$(ubus call network.interface.wan status|jsonfilter -e '@["ipv4-address"][0].mask')
if [ -n "$wanip" ] && [ -n "$wanmask" ] ;then
wan_network=$(ipcalc.sh $wanip $wanmask | awk -F= '/NETWORK/{print $2}')
wan_mask=$(ipcalc.sh $wanip $wanmask | awk -F= '/PREFIX/{print $2}')
fi
[ -n "$wan_network" -a -n "$wan_mask" ] && wan_ip="$wan_network/$wan_mask"
secondwanip=$(ubus call network.interface.secondwan status|jsonfilter -e '@["ipv4-address"][0].address')
secondwanmask=$(ubus call network.interface.secondwan status|jsonfilter -e '@["ipv4-addr