blob: 40386c89b89a78007f754a22ecc6949fa44f9221 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/bin/sh
2
3path_sh=`nv get path_sh`
4. $path_sh/global.sh
5echo "Info: defwan_set.sh $1 start" >> $test_log
6nd_dns=`nv get lan_ipaddr`
7#linuxϵͳetcĿ¼¿É¶Áд£¬resolv.conf¿ÉÒÔÖ±½Ó·ÅÔÚetcÏ£¬Í¬²½uc´úÂëʱעÒâ²»Òª½«´Ë´¦Í¬²½
8resolv_conf=/etc/resolv.conf
9dnsmasq_conf=$path_conf/dnsmasq.conf
10
11killall -9 dnsmasq
12def_cid=`nv get default_cid`
13
14if [ "-$1" == "-pswan" ]; then
15 ipaddr_type=`nv get "pdp_act_type"$def_cid`
16elif [ "-$1" == "-ethwan" ]; then
17 ipaddr_type=`nv get eth_act_type`
18elif [ "-$1" == "-wifiwan" ]; then
19 ipaddr_type=`nv get wifi_act_type`
20fi
21
22#»ñȡĬÈÏÍø¿Ú
23wan_if=$defwan_if
24wan6_if=$defwan6_if
25
26echo "" > $dnsmasq_conf
27
28#Èç¹û±¾µØÓ¦ÓÃÐèҪʹÓÃdnsmasqµÄ¹¦ÄÜ£¬ÐèÒªÔÚ"/etc/resolv.conf" ÎļþÖÐÌí¼Ó "127.0.0.1"£¬±ØÐë·ÅÔÚµÚÒ»Ìõ
29echo "" > $resolv_conf
30echo nameserver 127.0.0.1 > $resolv_conf
31
32
33#DNS¶ÔÓÚÍ¬Ò»Íø¿Ú£¬²»Çå³þ½«À´ÐèÇóÊÇ·ñÖ§³Ö·Ö±ð¶Ôv4¡¢v6½øÐÐauto¡¢manualÉèÖ㬴˴¦ÔÝʱ×ö³É¿É·Ö±ðÉèÖÃ
34#ÉèÖÃIPv4 ȱʡ·ÓÉ DNS
35if [ "-$ipaddr_type" == "-IPv4" -o "-$ipaddr_type" == "-IPv4v6" -o "-$ipaddr_type" == "-IPV4V6" -o "-$ipaddr_type" == "-" ];then
36 #ÉèÖÃIPv4µÄĬÈÏÍø¹Ø
37 route del default
xf.li742dd022023-06-08 01:43:32 -070038 Flag=`ip route | grep -w "default"`
lh9ed821d2023-04-07 01:36:19 -070039 if [ "-$Flag" != "-" ];then
40 echo "Error: route del default failed." >> $test_log
41 fi
42
43 defwan_gw=`nv get $wan_if"_gw"`
44 if [ "-$defwan_gw" != "-" -o "-$defwan_rel" != "-" ];then
45 route add default gw $defwan_gw dev $defwan_rel 2>>$test_log
46 if [ $? -ne 0 ];then
47 echo "Error: route add default gw $defwan_gw dev $defwan_rel failed." >> $test_log
48 fi
49 fi
50
51
52
53
54 #dnsmodeÓÉatserver´¦Àí£¬´«Êµ¼ÊʹÓõÄÖµ£¬´Ë´¦½öʹÓÃÒ»¸önv£¬²»Çø·Öauto manual
55 dns_mode=`nv get $1"_dns_mode"`
56 if [ "-$1" == "-pswan" -o "-$dns_mode" == "-auto" -o "-$dns_mode" == "-" ]; then
57 pridns=`nv get $wan_if"_pridns"`
58 secdns=`nv get $wan_if"_secdns"`
59 elif [ "-$dns_mode" == "-manual" ]; then
60 pridns=`nv get $1"_pridns_manual"`
61 secdns=`nv get $1"_secdns_manual"`
62 fi
63
64 if [ "-$pridns" == "-" -o "-$pridns" == "-0.0.0.0" ] && [ "-$secdns" == "-" -o "-$secdns" == "-0.0.0.0" ]; then
65 pridns="114.114.114.114"
66 secdns="8.8.8.8"
67 fi
68
69 if [ "-$pridns" != "-" -a "-$pridns" != "-0.0.0.0" ]; then
70 echo nameserver $pridns > $dnsmasq_conf
71 fi
72 if [ "-$secdns" != "-" -a "-$secdns" != "-0.0.0.0" ]; then
73 echo nameserver $secdns >> $dnsmasq_conf
74 fi
75
76 dns_extern=`nv get dns_extern`
77 if [ -n "$dns_extern" ]; then
78 echo nameserver $dns_extern >> $dnsmasq_conf
79 fi
80 if [ "-$1" == "-pswan" ]; then
81 tc_tbf.sh up $def_cid
82 fi
83fi
84
85#ÒÑÉèÖúÃÍâÍø¿ÚÔò¿ª×ª·¢
86if [ "-$wan_if" != "-" ]; then
87 echo 1 > /proc/sys/net/ipv4/ip_forward
88fi
89
90#ÉèÖÃIPv6 DNS
91if [ "-$ipaddr_type" == "-IPv6" -o "-$ipaddr_type" == "-IPV6" -o "-$ipaddr_type" == "-IPv4v6" -o "-$ipaddr_type" == "-IPV4V6" ];then
92 #dnsmodeÓÉatserver´¦Àí£¬´«Êµ¼ÊʹÓõÄÖµ£¬´Ë´¦½öʹÓÃÒ»¸önv£¬²»Çø·Öauto manual
93 ipv6_dns_mode=`nv get $1"_ipv6_dns_mode"`
94 if [ "-$1" == "-pswan" -o "-$ipv6_dns_mode" == "-auto" -o "-$ipv6_dns_mode" == "-" ]; then
95 ipv6_pridns=`nv get $wan6_if"_ipv6_pridns_auto"`
96 ipv6_secdns=`nv get $wan6_if"_ipv6_secdns_auto"`
97 elif [ "-$ipv6_dns_mode" == "-manual" ]; then
98 ipv6_pridns=`nv get $1"_ipv6_pridns_manual"`
99 ipv6_secdns=`nv get $1"_ipv6_secdns_manual"`
100 fi
101
102 nv set $wan6_if"_radvd_ipv6_dns_servers"=$ipv6_pridns,$ipv6_secdns
103
104 if [ -n "$ipv6_pridns" ] && [ "$ipv6_pridns" != "::" ] && [ "$ipv6_pridns" != "::0" ] && [ "$ipv6_pridns" != "0000:0000:0000:0000:0000:0000:0000:0000" ];then
105 echo nameserver $ipv6_pridns >> $dnsmasq_conf
106 fi
107
108 if [ -n "$ipv6_secdns" ] && [ "$ipv6_secdns" != "::" ] && [ "$ipv6_secdns" != "::0" ] && [ "$ipv6_secdns" != "0000:0000:0000:0000:0000:0000:0000:0000" ];then
109 echo nameserver $ipv6_secdns >> $dnsmasq_conf
110 fi
111
112 ipv6_dns_extern=`nv get ipv6_dns_extern`
113 if [ -n "$ipv6_dns_extern" ]; then
114 echo nameserver $ipv6_dns_extern >> $dnsmasq_conf
115 fi
116 if [ "-$1" == "-pswan" ]; then
117 tc_tbf.sh up $def_cid
118 fi
119fi
120
121nv set $wan6_if"_radvd_ipv6_dns_servers"=$ipv6_pridns,$ipv6_secdns
122
123#ÉèÖøøÒ³ÃæÏÔʾµ±Ç°ÍâÍøIPµØÖ·
124#ÉèÖÃIPv4Ò³ÃæÏÔʾµØÖ·
125if [ "-$ipaddr_type" == "-IPv4" -o "-$ipaddr_type" == "-IPV4" -o "-$ipaddr_type" == "-IPv4v6" -o "-$ipaddr_type" == "-IPV4V6" -o "-$ipaddr_type" == "-" ]; then
126 wan4_ip=`nv get $wan_if"_ip"`
127 nv set wan_ipaddr="$wan4_ip"
128fi
129
130#ÉèÖÃIPv6Ò³ÃæÏÔʾµØÖ·
131if [ "-$ipaddr_type" == "-IPv6" -o "-$ipaddr_type" == "-IPV6" -o "-$ipaddr_type" == "-IPv4v6" -o "-$ipaddr_type" == "-IPV4V6" ]; then
132 wan6_ip=`nv get $wan6_if"_ipv6_ip"`
133 nv set ipv6_wan_ipaddr="$wan6_ip"
134fi
135
136dnsmasq -i $lan_if -r $dnsmasq_conf &
137
138# ppp0ÐèÒªÉèÖÃMSS×Ϊ1440£¬·ñÔò¿ÉÄÜtcp²»Í¨
139if [ "$defwan_rel" == "ppp0" ]; then
140 echo "Info: dns_set ppp0 set MSS 1440" >> $test_log
141 iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1440
142fi
143
144