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