blob: 1cdeae03ab2d2b3447ca1fb427bd550002bcc9e1 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/bin/sh
2# udhcpc script edited by Tim Riker <Tim@Rikers.org>
3
4path_sh=`nv get path_sh`
5. $path_sh/global.sh
6
7echo "Info: udhcpc.sh $1 $2 start" >> $test_log
8
9[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
10
11RESOLV_CONF=$path_conf"/resolv.conf"
12#broadcast´æÔÚʱºò£¬ÉèÖÃBROADCAST
13[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
14#subnet´æÔÚʱºò£¬ÉèÖÃNETMASK
15[ -n "$subnet" ] && NETMASK="netmask $subnet"
16
17deconfig_wan()
18{
19 nv set $1"_ip"=0.0.0.0
20 nv set $1"_nm"=0.0.0.0
21 nv set $1"_gw"=0.0.0.0
22 nv set $1"_pridns"=0.0.0.0
23 nv set $1"_secdns"=0.0.0.0
24}
25
26get_wan_name()
27{
28 c_id="0"
29 ps_name=`nv get pswan`
30 rj45_name=`nv get ethwan`
31 wifi_name=`nv get wifiwan`
32 case "$1" in
33 $ps_name"1")
34 wanname="pswan"
35 c_id="1" ;;
36 $ps_name"2")
37 wanname="pswan"
38 c_id="2" ;;
39 $ps_name"3")
40 wanname="pswan"
41 c_id="3" ;;
42 $ps_name"4")
43 wanname="pswan"
44 c_id="4" ;;
45 $rj45_name)
46 wanname="ethwan" ;;
47 $wifi_name)
48 wanname="wifiwan" ;;
49 esac
50}
51
52
53case "$1" in
54 deconfig)
55 echo "case deconfig "
56 ifconfig $interface 0.0.0.0 2>>$test_log
57 if [ $? -ne 0 ];then
58 echo "Error: ifconfig $interface 0.0.0.0 failed." >> $test_log
59 fi
60 deconfig_wan $interface 2>>$test_log
61 (router_msg_proxy ipv4 udhcpc.sh >> $test_log 2>&1 || echo "Error: router_msg_proxy ipv4 udhcpc.sh failed." >> $test_log) &
62 echo "case deconfig over"
63
64 step=`nvram_get 2860 step_tmp`
65 if [ "-$step" = "-" ];then
66 step=0
67 fi
68
69 echo "step=$step"
70
71 step=`expr $step + 1`
72 nv set step_tmp=$step
73
74 if [ "-$step" = "-3" ];then
75 nv set step_tmp=0
76 fi
77
78 ;;
79
80 renew|bound)
81 echo "case renew bound"
82
83 get_wan_name $interface
84 if [ "-$wanname" == "-ethwan" -o "-$wanname" == "-wifiwan" ]; then
85 (router_msg_proxy del_timer $wanname >> $test_log 2>&1 || echo "Error: router_msg_proxy del_timer failed." >> $test_log) &
86 fi
87
88 #µ÷Óøýű¾Æðudhcpʱºò£¬ÅжÏinterfaceÊÇ·ñºÍethwanÆ¥Å䣬ƥÅäÔòÆðethwan,·ñÔòÓÃÔ­interface
89 ethwan_tmp=`nv get ethwan`
90 sw0_flag=`echo $ethwan_tmp | grep $interface`
91 if [ "-${sw0_flag}" != "-" ];then
92 interface=${ethwan_tmp}
93 fi
94 ifconfig $interface $ip $BROADCAST $NETMASK 2>>$test_log
95 if [ $? -ne 0 ];then
96 echo "Error: ifconfig $interface $ip $BROADCAST $NETMASK failed." >> $test_log
97 fi
98 if [ "-$wanname" == "-wifiwan" ]; then
99 nv set wifi_state="working"
100 elif [ "-$wanname" == "-ethwan" ]; then
101 #×ÔÊÊÓ¦£¬dhcp»ñÈ¡ip³É¹¦ÔòɱËÀpppoe½ø³Ì
102 pppoe_pid=`ps | grep -v grep | grep $interface | grep pppoecd | awk '{print $1}'`
103 kill $pppoe_pid
104 nv set rj45_state="working"
105 nv set eth_curmode="dhcp"
106 fi
107
108 echo "interface:$interface, ip:$ip, NETMASK:$subnet"
109 echo "router:$router"
110 echo "dns:$dns"
111
112 #set new value to ip, netmask, gateway and dns in nv
113 nv set $interface"_ip"=$ip
114 nv set $interface"_nm"=$subnet
115 nv set $interface"_gw"=$router
116 #set dns to nv
117 for i in $dns ; do
118 [ -n "$pspridns" ] || { nv set $interface"_pridns"=$i; pspridns="pspridns"; }
119 nv set $interface"_secdns"=$i
120 done
121
122 #c_id=0ÔòÊÇrj45»òWiFi£¬c_id=defaultÔòΪÓÃÓÚÍâÍøµÄps¿Ú
123 def_cid=`nv get default_cid`
124 if [ "-$c_id" == "-0" -o "-$c_id" == "-$def_cid" ]; then
125 (router_msg_proxy ipv4 udhcpc.sh >> $test_log 2>&1 || echo "Error: router_msg_proxy ipv4 udhcpc.sh failed." >> $test_log) &
126 else
127 #policy router
128 wan_pri=`nv get $wanname"_priority"`
129 rt_num=`expr $wan_pri \* 10 + $c_id`
130 ip rule add from $ip table $rt_num 2>>$test_log
131 if [ $? -ne 0 ];then
132 echo "Error: ip rule add from $ip table $rt_num failed." >> $test_log
133 fi
134 ip route add default via $router table $rt_num 2>>$test_log
135 if [ $? -ne 0 ];then
136 echo "Error: ip route add default via $router table $rt_num failed." >> $test_log
137 fi
138 ip route flush cache 2>>$test_log
139 if [ $? -ne 0 ];then
140 echo "Error: ip route flush cache failed." >> $test_log
141 fi
142 fi
143
144 # notify goahead when the WAN IP has been acquired. --yy
145 echo "case renew bound over"
146
147 #nv set ppp_status=ppp_connected
148 nv set step_tmp=0
149 ;;
150esac
151
152
153
154exit 0
155