lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Created by LiuWei @ 2010.8.27 |
| 3 | # init firewall |
| 4 | # |
| 5 | |
| 6 | path_sh=`nv get path_sh` |
| 7 | . $path_sh/global.sh |
| 8 | echo "Info: firewall_init.sh start" >> $test_log |
| 9 | |
| 10 | |
| 11 | ZTE_FILTER_CHAIN=macipport_filter |
| 12 | ZTE_WEB_FILTER_CHAIN=web_filter |
| 13 | ZTE_CLILDREN_CHAIN=children_filter |
| 14 | ZTE_CLILDREN_WEB_CHAIN=children_web_filter |
| 15 | ZTE_CLILDREN_WEB_PHONECHAIN=children_web_filter_phone |
| 16 | |
| 17 | #clear filter |
| 18 | iptables -t filter -F |
| 19 | iptables -t filter -X $ZTE_FILTER_CHAIN |
| 20 | iptables -t filter -X $ZTE_WEB_FILTER_CHAIN |
| 21 | iptables -t filter -X $ZTE_CLILDREN_CHAIN |
| 22 | iptables -t filter -X $ZTE_CLILDREN_WEB_CHAIN |
| 23 | iptables -t filter -X $ZTE_CLILDREN_WEB_PHONECHAIN |
| 24 | |
| 25 | ip6tables -t filter -F |
| 26 | ip6tables -t filter -X $ZTE_FILTER_CHAIN |
| 27 | |
| 28 | #make a new chain for filter |
| 29 | iptables -t filter -N $ZTE_FILTER_CHAIN |
| 30 | iptables -t filter -N $ZTE_WEB_FILTER_CHAIN |
| 31 | iptables -t filter -N $ZTE_CLILDREN_CHAIN |
| 32 | iptables -t filter -N $ZTE_CLILDREN_WEB_CHAIN |
| 33 | iptables -t filter -N $ZTE_CLILDREN_WEB_PHONECHAIN |
| 34 | ip6tables -t filter -N $ZTE_FILTER_CHAIN |
| 35 | |
| 36 | iptables -t filter -A FORWARD -j $ZTE_WEB_FILTER_CHAIN |
| 37 | iptables -t filter -A FORWARD -j $ZTE_FILTER_CHAIN |
| 38 | iptables -t filter -A FORWARD -j $ZTE_CLILDREN_CHAIN |
| 39 | iptables -t filter -A INPUT -j $ZTE_CLILDREN_WEB_CHAIN |
| 40 | iptables -t filter -A FORWARD -j $ZTE_CLILDREN_WEB_PHONECHAIN |
| 41 | ip6tables -t filter -A FORWARD -j $ZTE_FILTER_CHAIN |
| 42 | |
| 43 | ip6tables -t filter -A $ZTE_FILTER_CHAIN -m state --state RELATED,ESTABLISHED -j ACCEPT |
| 44 | |
| 45 | #Close unused port |
| 46 | iptables -t filter -A INPUT -i $defwan_rel -p udp --dport 53 -j DROP |
| 47 | iptables -t filter -A INPUT -i $defwan_rel -p tcp --dport 53 -j DROP |
| 48 | iptables -t filter -A INPUT -p tcp --dport 7777 -j DROP |
| 49 | iptables -t filter -A INPUT -p udp --dport 7777 -j DROP |
| 50 | iptables -t filter -I INPUT -i $defwan_rel -p icmp --icmp-type echo-reply -j ACCEPT |
| 51 | |
| 52 | permit_gw=`nv get permit_gw` |
| 53 | permit_nm=`nv get permit_nm` |
| 54 | if [ "-${permit_gw}" != "-" ]; then |
| 55 | iptables -A FORWARD -o $defwan_rel -d $permit_gw/$permit_nm -j ACCEPT |
| 56 | iptables -A FORWARD -o $defwan_rel -j DROP |
| 57 | iptables -A OUTPUT -o $defwan_rel -d $permit_gw/$permit_nm -j ACCEPT |
| 58 | iptables -A OUTPUT -o $defwan_rel -j DROP |
| 59 | fi |
| 60 | |
| 61 | permit_ip6=`nv get permit_ip6` |
| 62 | if [ "-${permit_ip6}" != "-" ]; then |
| 63 | ip6tables -A FORWARD -o $defwan6_rel -d $permit_ip6 -j ACCEPT |
| 64 | ip6tables -A FORWARD -o $defwan6_rel -j DROP |
| 65 | ip6tables -A OUTPUT -o $defwan6_rel -d $permit_ip6 -j ACCEPT |
| 66 | ip6tables -A OUTPUT -o $defwan6_rel -j DROP |
| 67 | fi |
| 68 | |
| 69 | |
| 70 | if [ "-$defwan_rel" == "-ppp0" ]; then |
| 71 | mtu=`nv get mtu` |
| 72 | pppoe_mtu=`expr $mtu - 60` |
| 73 | iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss $pppoe_mtu |
| 74 | else |
| 75 | iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu |
| 76 | fi |
| 77 | # firewall will flush nat and filter, so upnp should run after it. |
| 78 | #sh $path_sh/upnp.sh |
| 79 | |