blob: b4915a7c304899ee2dfd6955b9f4322f973622b8 [file] [log] [blame]
qumengjiaca65ef52024-11-06 15:42:21 +08001#!/bin/sh
2#
3# $Id: lan.sh
4#
5path_sh=`nv get path_sh`
6. $path_sh/global.sh
7
8br_set()
9{
10 br_name=$lan_if
11
12 #ÉèÖÃÍøÇÅ
13 killall -9 udhcpd
14 echo "ifconfig $br_name down...................."
15 ifconfig $br_name down
16
17 echo "brctl delbr $br_name......................"
18 brctl delbr $br_name
19
20 echo "brctl addbr $br_name......................"
21 brctl addbr $br_name 2>>$test_log
22 if [ $? -ne 0 ];then
23 echo "Error: brctl addbr $br_name failed." >> $test_log
24 fi
25 echo "brctl setfd $br_name 0.1.................."
26 brctl setfd $br_name 0.1 2>>$test_log
27 if [ $? -ne 0 ];then
28 echo "Error: brctl setfd $br_name 0.1 failed." >> $test_log
29 fi
30 echo "ifconfig lo up......................."
31 ifconfig lo up 2>>$test_log
32 if [ $? -ne 0 ];then
33 echo "Error: ifconfig lo up failed." >> $test_log
34 fi
35 echo "ifconfig $br_name up......................"
36 ifconfig $br_name up 2>>$test_log
37 if [ $? -ne 0 ];then
38 echo "Error: ifconfig $br_name up failed." >> $test_log
39 fi
40
41 #´ò¿ªÍøÇŵØÖ·¸Ä±ä֪ͨµÄ¿ª¹Ø
42 echo 1 > /proc/sys/net/ipv4/conf/$br_name/arp_notify
43
44 br_node=`nv get br_node`
45
46 #analysis br_node ex: usb0+wifi0+¡­
47 IFS_OLD=$IFS
48 IFS="+"
49 for device in $br_node
50 do
51 # youchen@2024-09-07 temp fix choke when boot without eth phy, begin
52 if [ "$device" == "eth0" ]; then
53 eth_state=`cat /sys/gmac/gmacconfig/eth_phy_state`
54 if [ "$eth_state" != "1" ]; then
55 continue
56 fi
57 fi
58 # youchen@2024-09-07 temp fix choke when boot without eth phy, end
59 ifconfig $device up
60
61 brctl addif $br_name $device 2>>$test_log
62 if [ $? -ne 0 ];then
63 echo "Error: brctl addif $br_name $device failed." >> $test_log
64 fi
65 done
66 IFS=$IFS_OLD
67
68}
69
70lan_set()
71{
72 ip=`nv get lan_ipaddr`
73 nm=`nv get lan_netmask`
74 ifconfig $lan_if $ip netmask $nm 2>>$test_log
75 if [ $? -ne 0 ];then
76 echo "Error: ifconfig $lan_if $ip netmask $nm failed." >> $test_log
77 fi
78
79 webv6_enable=`nv get webv6_enable`
80 ipv6=`nv get lan_ipv6addr`
81 if [ "x$webv6_enable" == "x1" ]; then
82 ifconfig $lan_if $ipv6
83 if [ $? -ne 0 ];then
84 echo "Error: ifconfig $lan_if $ipv6 failed." >> $test_log
85 fi
86 fi
87}
88
89#½âÎöÄÚÍøµØÖ·¡¢Íø¹ØµØÖ·Í¨¹ýproc»úÖÆ¶¯Ì¬´«µÝ¸øÄںˣ¬ÒÔ±ãÄÚºËʵÏÖ·ÀÖ¹ÄÚÍøµØÖ·Ð¹Â¶¹¦ÄÜ
90lanip_proc()
91{
92 #ipµØÖ·»»Ëã³É4×Ö½ÚÕûÐÍÊÇÍøÂç×Ö½ÚÐò£¬Òªµßµ¹ÏÂ
93 #uclinux²»Ö§³Ö×óÒÆ×Ö·û
94 ip_value=`echo "$ip" | awk -F '.' '{printf $1 + 256* $2 + 256*256* $3 + 256*256*256* $4}'`
95 nm_value=`echo "$nm" | awk -F '.' '{printf $1 + 256* $2 + 256*256* $3 + 256*256*256* $4}'`
96
97 echo $ip_value > /sys/module/lanip_filter_ipv4/parameters/lan_ipaddr
98 echo $nm_value > /sys/module/lanip_filter_ipv4/parameters/lan_netmask
99}
100
101main()
102{
103 lan_enable=`nv get LanEnable`
104 if [ "x$lan_enable" == "x0" ]; then
105 exit 0
106 fi
107
108 echo "Info: lan.sh start" >> $test_log
109
110 if [ "x$lan_enable" == "x1" ]; then
111 br_set
112 fi
113
114 if [ "x$lan_if" != "x" ]; then
115 lan_set
116 fi
117
118 #vlanÅäÖã¬ÔÝʱ·ÅÓÚ´Ë´¦£¬1 ¿ª»úµÄʱºò²»ÐèÒª½«sw¼ÓÈëµ½ÍøÇÅÏÂ
119 #2 ´Ë´¦±ØÐ뽫sw upÆðÀ´£¬Èç¹û²»upµÄ»°½«²»»áÓÐrj45ÈȲå°Îʼþ
120 sw_name=`nv get swvlan`
121 ifconfig $sw_name up
122 natenable=`nv get natenable`
123 dosenable=`nv get dosenable`
124 if [[ "x$natenable" != "x0" || "x$dosenable" != "x0" ]]; then
125 lanip_proc
126 fi
127 if [ "x$dosenable" != "x0" ]; then
128 echo 1 > /sys/module/fast_common/parameters/lan_dos_enable
129 fi
130
131
132
133
134 echo "" > $path_conf/udhcpd.leases
135
136 . $path_sh/user-config-udhcpd.sh
137
138 dhcp=`nv get dhcpEnabled`
139 if [ "$dhcp" == "1" ]; then
140 echo "Info: config-udhcpd.sh lan -r 1 start" >> $test_log
141 . $path_sh/config-udhcpd.sh "lan" -r 1
142 fi
143
144 dnsmasq -i $lan_if -r $path_conf/resolv.conf &
145 . $path_sh/upnp.sh
146
147 #»ñÈ¡br0µÄipv6µØÖ·
148 ipv6lanipaddrcmd="ifconfig $br_name | grep Scope:Link | sed 's/^.*addr: //g' | sed 's/\/.*$//g'"
149 ipv6lanipaddr=`eval $ipv6lanipaddrcmd`
150 nv set ipv6_lan_ipaddr=$ipv6lanipaddr
151}
152
153main