#!/bin/sh

wan_ifname="$(uci -q get network.wan.ifname)"
wan6_ifname="$(uci -q get network.wan6.ifname)"

rule_exist=`grep "iptables -t mangle -A PREROUTING -i $wan_ifname -j TTL --ttl-inc 1" /etc/firewall.user | wc -l`
rule6_exist=`grep "ip6tables -t mangle -A PREROUTING -i $wan6_ifname -j HL --hl-inc 1" /etc/firewall.user | wc -l`

#ipv4
if [ $rule_exist -eq 0 ]; then
	#remove old ttl rule
	echo "iptables -t mangle -D PREROUTING -i $wan_ifname -j TTL --ttl-inc 1" >> /etc/firewall.user
	echo "iptables -t mangle -A PREROUTING -i $wan_ifname -j TTL --ttl-inc 1" >> /etc/firewall.user
fi

#ipv6
if [ $rule6_exist -eq 0 ]; then
	#remove old ttl rule
	echo "ip6tables -t mangle -D PREROUTING -i $wan6_ifname -j HL --hl-inc 1" >> /etc/firewall.user
	echo "ip6tables -t mangle -A PREROUTING -i $wan6_ifname -j HL --hl-inc 1" >> /etc/firewall.user
fi

exit 0
