blob: e324c8d489020ad84c9bfb36d010938dc242f268 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/bin/sh
2test_log=`nv get telog_path`
3if [ "$test_log" == "" ]; then
4 test_log=`nv get path_log`"te.log"
5fi
6echo "Info: psext_up.sh $1 start" >> $test_log
7path_conf=`nv get path_conf`
lh758261d2023-07-13 05:52:04 -07008dhcps_in_cap=`nv get dhcps_in_cap`
lh9ed821d2023-04-07 01:36:19 -07009
10echo 1 > /proc/sys/net/ipv4/ip_forward
11c_id=$1
12ps_if=`nv get pswan`$c_id
13eth_if=`nv get "ps_ext"$c_id`
14ext_br="br"$c_id
15pidfile=$path_conf"/udhcpd"$c_id".pid"
16confile=$path_conf"/udhcpd"$c_id".conf"
17leases=$path_conf"/udhcpd"$c_id".leases"
18
19arp_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
24dhcp_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
lh758261d2023-07-13 05:52:04 -070031 if [ "x$dhcps_in_cap" != "x1" ]; then
lh9ed821d2023-04-07 01:36:19 -070032 if [ -e ${pidfile} ]; then
33 kill `cat $pidfile`
34 rm -f $pidfile
35 fi
36 touch $leases
37 udhcpd -f $confile &
lh758261d2023-07-13 05:52:04 -070038 fi
lh9ed821d2023-04-07 01:36:19 -070039}
40
41#»ñÈ¡ip²¢ÅäÖÃps¡¢eth
42get_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"`
xf.lidf7f8ba2024-09-12 23:53:34 -070047 ifconfig $ps_if $ps_ip up 2>>$test_log
48 wan_nm=`nv get static_wan_netmask`
49 ifconfig $ps_if netmask $wan_nm 2>>$test_log
lh9ed821d2023-04-07 01:36:19 -070050 if [ $? -ne 0 ];then
51 echo "Error: ifconfig $ps_if $ps_ip up failed." >> $test_log
52 fi
53 nv set default_wan_rel=$ps_if
xf.li742dd022023-06-08 01:43:32 -070054 #nv set default_cid=$c_id
lh9ed821d2023-04-07 01:36:19 -070055 nv set $ext_br"_ip"=$br_ip
56 ifconfig $ext_br $br_ip 2>>$test_log
57 if [ $? -ne 0 ];then
58 echo "Error: ifconfig $ext_br $br_ip up failed." >> $test_log
59 fi
60}
61#·ÓɹæÔò£¬psÓëeth¼¶Áª
62route_set()
63{
64 marknum=`expr $c_id + 20`
65 iptables -t mangle -A PREROUTING -i $ps_if -j MARK --set-mark $marknum
66 rt_num=`expr $c_id + 120`
67
68 ip route add default dev $ext_br table $rt_num
69
70 ip rule add to $pdp_ip fwmark $marknum table $rt_num
71
72 marknum=`expr $c_id + 10`
73 iptables -t mangle -A PREROUTING -i $ext_br -j MARK --set-mark $marknum
74 rt_num=`expr $c_id + 100`
75
76 ip route add default dev $ps_if table $rt_num
77 ip rule add from $pdp_ip fwmark $marknum table $rt_num
78
79 ip route flush cache
80
81 #±¾µØÍøÂçÅäÖÃ
82 iptables -t nat -I POSTROUTING -s $ps_ip -o $ps_if -j SNAT --to $pdp_ip
83
xf.li742dd022023-06-08 01:43:32 -070084 route_info=`ip route|grep default`
lh9ed821d2023-04-07 01:36:19 -070085
86 if [ "$route_info" == "" ];then
87 route add default dev $ps_if
88 else
89 echo "Debug: default route already exist." >> $test_log
90 fi
91}
92
xf.li7ccf8372024-03-07 00:08:02 -080093ra_mtu_enable=`nv get ra_mtu_enable`
94if [ "$ra_mtu_enable" != "1" ]; then
95 mtu=`nv get mtu`
96 ifconfig $ps_if mtu $mtu
97fi
lh9ed821d2023-04-07 01:36:19 -070098brctl addbr $ext_br
99brctl setfd $ext_br 0.1
100brctl addif $ext_br $eth_if
xf.li6c8fc1e2023-08-12 00:11:09 -0700101if [ "$eth_if" != "zvnet"$c_id ]; then
lh9ed821d2023-04-07 01:36:19 -0700102ifconfig $ext_br up
xf.li6c8fc1e2023-08-12 00:11:09 -0700103else
104ifconfig $ext_br -arp up
105fi
lh9ed821d2023-04-07 01:36:19 -0700106get_ipaddr
107dhcp_set
108route_set
109arp_proxy_set
110ifconfig $eth_if up
111ismbim=`ps |grep -v grep |grep -w mbim |awk '{printf $1}'`
112if [ "-$ismbim" != "-" ]; then
113 eth_mac=`cat "/sys/class/net/"$eth_if"/address"`
114 arp -s $pdp_ip $eth_mac -i $ext_br 2>>$test_log
115fi
116tc_tbf.sh up $c_id