lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # $Id: lan.sh |
| 4 | # |
| 5 | path_sh=`nv get path_sh` |
| 6 | . $path_sh/global.sh |
| 7 | |
| 8 | br_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 | ifconfig $device up |
| 52 | |
| 53 | brctl addif $br_name $device 2>>$test_log |
| 54 | if [ $? -ne 0 ];then |
| 55 | echo "Error: brctl addif $br_name $device failed." >> $test_log |
| 56 | fi |
| 57 | done |
| 58 | IFS=$IFS_OLD |
| 59 | |
| 60 | } |
| 61 | |
| 62 | lan_set() |
| 63 | { |
| 64 | ip=`nv get lan_ipaddr` |
| 65 | nm=`nv get lan_netmask` |
| 66 | ifconfig $lan_if $ip netmask $nm 2>>$test_log |
| 67 | if [ $? -ne 0 ];then |
| 68 | echo "Error: ifconfig $lan_if $ip netmask $nm failed." >> $test_log |
| 69 | fi |
| 70 | |
| 71 | webv6_enable=`nv get webv6_enable` |
| 72 | ipv6=`nv get lan_ipv6addr` |
| 73 | if [ "x$webv6_enable" == "x1" ]; then |
| 74 | ifconfig $lan_if $ipv6 |
| 75 | if [ $? -ne 0 ];then |
| 76 | echo "Error: ifconfig $lan_if $ipv6 failed." >> $test_log |
| 77 | fi |
| 78 | fi |
| 79 | } |
| 80 | |
| 81 | #½âÎöÄÚÍøµØÖ·¡¢Íø¹ØµØÖ·Í¨¹ýproc»úÖÆ¶¯Ì¬´«µÝ¸øÄںˣ¬ÒÔ±ãÄÚºËʵÏÖ·ÀÖ¹ÄÚÍøµØÖ·Ð¹Â¶¹¦ÄÜ |
| 82 | lanip_proc() |
| 83 | { |
| 84 | #ipµØÖ·»»Ëã³É4×Ö½ÚÕûÐÍÊÇÍøÂç×Ö½ÚÐò£¬Òªµßµ¹Ï |
| 85 | #uclinux²»Ö§³Ö×óÒÆ×Ö·û |
| 86 | ip_value=`echo "$ip" | awk -F '.' '{printf $1 + 256* $2 + 256*256* $3 + 256*256*256* $4}'` |
| 87 | nm_value=`echo "$nm" | awk -F '.' '{printf $1 + 256* $2 + 256*256* $3 + 256*256*256* $4}'` |
| 88 | |
| 89 | echo $ip_value > /sys/module/lanip_filter_ipv4/parameters/lan_ipaddr |
| 90 | echo $nm_value > /sys/module/lanip_filter_ipv4/parameters/lan_netmask |
| 91 | } |
| 92 | |
| 93 | main() |
| 94 | { |
| 95 | lan_enable=`nv get LanEnable` |
| 96 | if [ "x$lan_enable" == "x0" ]; then |
| 97 | exit 0 |
| 98 | fi |
| 99 | |
| 100 | echo "Info: lan.sh start" >> $test_log |
| 101 | |
| 102 | if [ "x$lan_enable" == "x1" ]; then |
| 103 | br_set |
| 104 | fi |
| 105 | |
| 106 | if [ "x$lan_if" != "x" ]; then |
| 107 | lan_set |
| 108 | fi |
| 109 | |
| 110 | #vlanÅäÖã¬ÔÝʱ·ÅÓÚ´Ë´¦£¬1 ¿ª»úµÄʱºò²»ÐèÒª½«sw¼ÓÈëµ½ÍøÇÅÏ |
| 111 | #2 ´Ë´¦±ØÐ뽫sw upÆðÀ´£¬Èç¹û²»upµÄ»°½«²»»áÓÐrj45ÈȲå°Îʼþ |
| 112 | sw_name=`nv get swvlan` |
| 113 | ifconfig $sw_name up |
| 114 | natenable=`nv get natenable` |
| 115 | dosenable=`nv get dosenable` |
| 116 | if [[ "x$natenable" != "x0" || "x$dosenable" != "x0" ]]; then |
| 117 | lanip_proc |
| 118 | fi |
| 119 | if [ "x$dosenable" != "x0" ]; then |
| 120 | echo 1 > /sys/module/fast_common/parameters/lan_dos_enable |
| 121 | fi |
| 122 | |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 123 | dhcps_in_cap=`nv get dhcps_in_cap` |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 124 | |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 125 | if [ "x$dhcps_in_cap" != "x1" ]; then |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 126 | echo "" > $path_conf/udhcpd.leases |
| 127 | |
| 128 | . $path_sh/user-config-udhcpd.sh |
| 129 | |
| 130 | dhcp=`nv get dhcpEnabled` |
| 131 | if [ "$dhcp" == "1" ]; then |
| 132 | echo "Info: config-udhcpd.sh lan -r 1 start" >> $test_log |
| 133 | . $path_sh/config-udhcpd.sh "lan" -r 1 |
| 134 | fi |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 135 | fi |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 136 | dnsmasq -i $lan_if -r $path_conf/resolv.conf & |
| 137 | . $path_sh/upnp.sh |
| 138 | |
| 139 | #»ñÈ¡br0µÄipv6µØÖ· |
| 140 | ipv6lanipaddrcmd="ifconfig $br_name | grep Scope:Link | sed 's/^.*addr: //g' | sed 's/\/.*$//g'" |
| 141 | ipv6lanipaddr=`eval $ipv6lanipaddrcmd` |
| 142 | nv set ipv6_lan_ipaddr=$ipv6lanipaddr |
| 143 | } |
| 144 | |
| 145 | main |