xf.li | 8611891 | 2025-03-19 20:07:27 -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_cap |
| 11 | |
| 12 | #ÉèÖÃÍøÇÅ |
| 13 | killall -9 udhcpd |
| 14 | echo "ifconfig $br_name start...................." |
| 15 | ifconfig $br_name down |
| 16 | brctl delbr $br_name |
| 17 | brctl addbr $br_name 2>>$test_log |
| 18 | if [ $? -ne 0 ];then |
| 19 | echo "Error: brctl addbr $br_name failed." >> $test_log |
| 20 | fi |
| 21 | brctl setfd $br_name 0.1 2>>$test_log |
| 22 | if [ $? -ne 0 ];then |
| 23 | echo "Error: brctl setfd $br_name 0.1 failed." >> $test_log |
| 24 | fi |
| 25 | ifconfig lo up 2>>$test_log |
| 26 | if [ $? -ne 0 ];then |
| 27 | echo "Error: ifconfig lo up failed." >> $test_log |
| 28 | fi |
| 29 | ifconfig $br_name up 2>>$test_log |
| 30 | if [ $? -ne 0 ];then |
| 31 | echo "Error: ifconfig $br_name up failed." >> $test_log |
| 32 | fi |
| 33 | |
| 34 | #´ò¿ªÍøÇŵØÖ·¸Ä±ä֪ͨµÄ¿ª¹Ø |
| 35 | echo 1 > /proc/sys/net/ipv4/conf/$br_name/arp_notify |
| 36 | prj=`cat /sys/gmac/gmacconfig/type` |
| 37 | if [ "$prj" == "cpe" ]; then |
| 38 | ifconfig eth0 up 2>>$test_log |
| 39 | brctl addif $br_name eth0 2>>$test_log |
| 40 | fi |
| 41 | br_node=`nv get br_node_cap` |
| 42 | |
| 43 | #analysis br_node ex: usb0+wifi0+¡ |
| 44 | IFS_OLD=$IFS |
| 45 | IFS="+" |
| 46 | for device in $br_node |
| 47 | do |
| 48 | ifconfig $device up |
| 49 | |
| 50 | brctl addif $br_name $device 2>>$test_log |
| 51 | if [ $? -ne 0 ];then |
| 52 | echo "Error: brctl addif $br_name $device failed." >> $test_log |
| 53 | fi |
| 54 | done |
| 55 | IFS=$IFS_OLD |
| 56 | } |
| 57 | |
| 58 | lan_set() |
| 59 | { |
| 60 | ip=`nv get lan_ipaddr_cap` |
| 61 | nm=`nv get lan_netmask_cap` |
| 62 | ifconfig $lan_if_cap $ip netmask $nm 2>>$test_log |
| 63 | if [ $? -ne 0 ];then |
| 64 | echo "Error: ifconfig $lan_if_cap $ip netmask $nm failed." >> $test_log |
| 65 | fi |
| 66 | |
| 67 | webv6_enable=`nv get webv6_enable` |
| 68 | ipv6=`nv get lan_ipv6addr_cap` |
| 69 | if [ "x$webv6_enable" == "x1" ]; then |
| 70 | ifconfig $lan_if_cap $ipv6/64 |
| 71 | if [ $? -ne 0 ];then |
| 72 | echo "Error: ifconfig $lan_if_cap $ipv6 failed." >> $test_log |
| 73 | fi |
| 74 | fi |
| 75 | } |
| 76 | |
| 77 | main() |
| 78 | { |
| 79 | lan_enable=`nv get LanEnable_cap` |
| 80 | if [ "x$lan_enable" == "x0" ]; then |
| 81 | exit 0 |
| 82 | fi |
| 83 | |
| 84 | echo "Info: lan.sh start" >> $test_log |
| 85 | |
| 86 | if [ "x$lan_enable" == "x1" ]; then |
| 87 | br_set |
| 88 | fi |
| 89 | |
| 90 | if [ "x$lan_if_cap" != "x" ]; then |
| 91 | lan_set |
| 92 | fi |
| 93 | |
| 94 | dhcps_in_cap=`nv get dhcps_in_cap` |
| 95 | |
| 96 | if [ "x$dhcps_in_cap" == "x1" ]; then |
| 97 | echo "" > $path_conf/udhcpd.leases |
| 98 | rm -rf $path_conf/udhcpd.conf |
| 99 | . $path_sh/user-config-udhcpd.sh |
| 100 | |
| 101 | dhcp=`nv get dhcpEnabled` |
| 102 | if [ "$dhcp" == "1" ]; then |
| 103 | echo "Info: config-udhcpd.sh lan -r 1 start" >> $test_log |
| 104 | . $path_sh/config-udhcpd.sh "lan" -r 1 |
| 105 | fi |
| 106 | fi |
| 107 | dnsmasq -i $lan_if_cap -r $path_conf/resolv.conf & |
| 108 | gw_in_cap=`nv get gw_in_cap` |
| 109 | if [ "x$gw_in_cap" != "x1" ]; then |
| 110 | ap_ip=`nv get lan_ipaddr` |
| 111 | ap_ipv6=`nv get lan_ipv6addr` |
| 112 | |
| 113 | ip route add default via $ap_ip |
| 114 | ip -6 route add default via $ap_ipv6 dev $lan_if_cap |
| 115 | echo "nameserver $ap_ip" >> /etc/resolv.conf |
| 116 | else |
| 117 | echo 1 > /proc/net/ct_iptables_syn |
| 118 | fi |
| 119 | } |
| 120 | |
| 121 | main |