lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | test_log=`nv get telog_path` |
| 3 | if [ "$test_log" == "" ]; then |
| 4 | test_log=`nv get path_log`"te.log" |
| 5 | fi |
| 6 | echo "Info: psext_up.sh $1 start" >> $test_log |
| 7 | path_conf=`nv get path_conf` |
| 8 | |
| 9 | echo 1 > /proc/sys/net/ipv4/ip_forward |
| 10 | c_id=$1 |
| 11 | ps_if=`nv get pswan`$c_id |
| 12 | eth_if=`nv get "ps_ext"$c_id` |
| 13 | ext_br="br"$c_id |
| 14 | pidfile=$path_conf"/udhcpd"$c_id".pid" |
| 15 | confile=$path_conf"/udhcpd"$c_id".conf" |
| 16 | leases=$path_conf"/udhcpd"$c_id".leases" |
| 17 | |
| 18 | arp_proxy_set() |
| 19 | { |
| 20 | (zte_arp_proxy -i $ext_br 2>> $test_log || echo "Error: zte_arp_proxy -i $ext_br failed." >> $test_log) & |
| 21 | } |
| 22 | |
| 23 | dhcp_set() |
| 24 | { |
| 25 | mask=`nv get $ext_br"_nm"` |
| 26 | ifconfig $ext_br netmask $mask 2>>$test_log |
| 27 | if [ $? -ne 0 ];then |
| 28 | echo "Error: ifconfig $eth_br netmask $mask failed." >> $test_log |
| 29 | fi |
| 30 | if [ -e ${pidfile} ]; then |
| 31 | kill `cat $pidfile` |
| 32 | rm -f $pidfile |
| 33 | fi |
| 34 | touch $leases |
| 35 | udhcpd -f $confile & |
| 36 | } |
| 37 | |
| 38 | #»ñÈ¡ip²¢ÅäÖÃps¡¢eth |
| 39 | get_ipaddr() |
| 40 | { |
| 41 | pdp_ip=`nv get $ps_if"_pdp_ip"` |
| 42 | ps_ip=`nv get $ps_if"_ip"` |
| 43 | br_ip=`nv get $ext_br"_ip"` |
| 44 | ifconfig $ps_if $ps_ip up 2>>$test_log |
| 45 | if [ $? -ne 0 ];then |
| 46 | echo "Error: ifconfig $ps_if $ps_ip up failed." >> $test_log |
| 47 | fi |
| 48 | nv set default_wan_rel=$ps_if |
| 49 | nv set default_cid=$c_id |
| 50 | nv set $ext_br"_ip"=$br_ip |
| 51 | ifconfig $ext_br $br_ip 2>>$test_log |
| 52 | if [ $? -ne 0 ];then |
| 53 | echo "Error: ifconfig $ext_br $br_ip up failed." >> $test_log |
| 54 | fi |
| 55 | } |
| 56 | #·ÓɹæÔò£¬psÓëeth¼¶Áª |
| 57 | route_set() |
| 58 | { |
| 59 | marknum=`expr $c_id + 20` |
| 60 | iptables -t mangle -A PREROUTING -i $ps_if -j MARK --set-mark $marknum |
| 61 | rt_num=`expr $c_id + 120` |
| 62 | |
| 63 | ip route add default dev $ext_br table $rt_num |
| 64 | |
| 65 | ip rule add to $pdp_ip fwmark $marknum table $rt_num |
| 66 | |
| 67 | marknum=`expr $c_id + 10` |
| 68 | iptables -t mangle -A PREROUTING -i $ext_br -j MARK --set-mark $marknum |
| 69 | rt_num=`expr $c_id + 100` |
| 70 | |
| 71 | ip route add default dev $ps_if table $rt_num |
| 72 | ip rule add from $pdp_ip fwmark $marknum table $rt_num |
| 73 | |
| 74 | ip route flush cache |
| 75 | |
| 76 | #±¾µØÍøÂçÅäÖà |
| 77 | iptables -t nat -I POSTROUTING -s $ps_ip -o $ps_if -j SNAT --to $pdp_ip |
| 78 | |
| 79 | route_info=`route|grep default` |
| 80 | |
| 81 | if [ "$route_info" == "" ];then |
| 82 | route add default dev $ps_if |
| 83 | else |
| 84 | echo "Debug: default route already exist." >> $test_log |
| 85 | fi |
| 86 | } |
| 87 | |
| 88 | mtu=`nv get mtu` |
| 89 | ifconfig $ps_if mtu $mtu |
| 90 | brctl addbr $ext_br |
| 91 | brctl setfd $ext_br 0.1 |
| 92 | brctl addif $ext_br $eth_if |
| 93 | ifconfig $ext_br up |
| 94 | get_ipaddr |
| 95 | dhcp_set |
| 96 | route_set |
| 97 | arp_proxy_set |
| 98 | ifconfig $eth_if up |
| 99 | ismbim=`ps |grep -v grep |grep -w mbim |awk '{printf $1}'` |
| 100 | if [ "-$ismbim" != "-" ]; then |
| 101 | eth_mac=`cat "/sys/class/net/"$eth_if"/address"` |
| 102 | arp -s $pdp_ip $eth_mac -i $ext_br 2>>$test_log |
| 103 | fi |
| 104 | tc_tbf.sh up $c_id |