forked from rdkcentral/sysint-broadband
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartTunnel.sh
More file actions
executable file
·184 lines (173 loc) · 7.11 KB
/
startTunnel.sh
File metadata and controls
executable file
·184 lines (173 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/sh
##########################################################################
# If not stated otherwise in this file or this component's Licenses.txt
# file the following copyright and licenses apply:
#
# Copyright 2016 RDK Management
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##########################################################################
#
. /etc/include.properties
. /etc/device.properties
source /etc/waninfo.sh
UseLANIFIPV6=`sysevent get LANIPv6GUASupport`
if [ -f /lib/rdk/t2Shared_api.sh ]; then
source /lib/rdk/t2Shared_api.sh
fi
WAN_INTERFACE=$(getWanInterfaceName)
usage()
{
echo "USAGE: startTunnel.sh {start|stop} {args}"
}
if [ -f /lib/rdk/utils.sh ]; then
. /lib/rdk/utils.sh
fi
if [ $# -lt 1 ]; then
usage
exit 1
fi
ip_to_hex() {
printf '%02x' ${1//./ }
}
oper=$1
shift
# XB6 Arris Class devices need to utilize erouter0.
if [ "$BOX_TYPE" = "XB6" -a "$MANUFACTURE" = "Arris" ]; then
CMINTERFACE=$(getWanInterfaceName)
fi
case $oper in
h)
usage
exit 1
;;
start)
WAN_INTERFACE=$(getWanInterfaceName)
DEF_WAN_INTERFACE=$(getWanMacInterfaceName)
if [ -f "/nvram/ETHWAN_ENABLE" ];then
CM_IPV4=`ifconfig $WAN_INTERFACE | grep "inet addr" | awk '/inet/{print $2}' | cut -f2 -d: | head -n1`
IpCheckVal=$(echo ${CM_IPV4} | tr "." " " | awk '{ print $3"."$4 }')
Check=$(ip_to_hex $IpCheckVal)
# getting the IPV6 address for CM
if [ "$BOX_TYPE" = "SCER11BEL" -a "$UseLANIFIPV6" = "true" ] ; then
if [ -z "$CM_IPV4" ]; then
# In IPv6 only case (MAP-T), and if IPv6 GUA on LAN enabled case, use brlan0 interface to get v6 global address.
CM_IP=`ip -6 addr show dev brlan0 scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1`
else
CM_IP=$CM_IPV4
fi
echo "CM_IP-$CM_IP"
# creating a ssh tunnel directly to the LANIP:22 for IPV6 only scenario
elif [ "x$BOX_TYPE" = "xHUB4" ] || [ "x$BOX_TYPE" = "xSR300" ] || [ "x$BOX_TYPE" = "xSR213" ] || [ "x$BOX_TYPE" = "xSE501" ] || [ "x$BOX_TYPE" = "xWNXL11BWL" ] || [ "$UseLANIFIPV6" = "true" ]; then
if [ -z "$CM_IPV4" ]; then
CM_IP=`syscfg get lan_ipaddr`
else
CM_IP=$CM_IPV4
fi
else
CM_IP=`ifconfig $WAN_INTERFACE | grep Global | awk '/inet6/{print $3}' | cut -d '/' -f1`
if [ -z "$CM_IP" ]; then
CM_IP=$CM_IPV4
fi
fi
else
if ( [ "$MANUFACTURE" = "Technicolor" ] || [ "$MANUFACTURE" = "Sercomm" ] ) && [ "$BOX_TYPE" != "XB3" ]; then
if [ "$WAN_INTERFACE" = "$DEF_WAN_INTERFACE" ]; then
CM_IPV4=`ifconfig privbr:0 | grep "inet addr" | awk '/inet/{print $2}' | cut -f2 -d: | head -n1`
IpCheckVal=$(echo ${CM_IPV4} | tr "." " " | awk '{ print $3"."$4 }')
Check=$(ip_to_hex $IpCheckVal)
# Get Gobal scope IPv6 address from interface privbr
CM_IP=`ifconfig privbr | grep $Check | grep Global | awk '/inet6/{print $3}' | cut -d '/' -f1 | head -n1`
# If Gobal scope IPv6 address is not present
if [ -z "$CM_IP" ]; then
# Get Link local scope IPv6 address from interface privbr
CM_IP=`ifconfig privbr | grep $Check | awk '/inet6/{print $3}' | cut -d '/' -f1`
# If Link local scope IPv6 address is present
if [ ! -z "$CM_IP" ]; then
CM_IP="$CM_IP%privbr"
else
CM_IP=$CM_IPV4
fi
fi
else
CM_IPV4=`ifconfig $WAN_INTERFACE | grep "inet addr" | awk '/inet/{print $2}' | cut -f2 -d: | head -n1`
IpCheckVal=$(echo ${CM_IPV4} | tr "." " " | awk '{ print $3"."$4 }')
Check=$(ip_to_hex $IpCheckVal)
CM_IP=`ifconfig $WAN_INTERFACE | grep Global | awk '/inet6/{print $3}' | cut -d '/' -f1`
if [ -z "$CM_IP" ]; then
CM_IP=$CM_IPV4
fi
fi
elif [ "$BOX_TYPE" = "XB6" -a "$MANUFACTURE" = "Arris" ] ; then
CM_IPV4=""
CM_IP=""
CM_IPV4=`ifconfig $CMINTERFACE | grep "inet addr" | awk '/inet/{print $2}' | cut -f2 -d: | head -n1`
if [ ! "$CM_IPV4" ]; then
echo "Error: There is no valid CM interface configured and error getting IP address for the device."
fi
CM_IP=`ifconfig $CMINTERFACE| grep inet6 | tr -s " " | grep -v Link | cut -d " " -f4 | cut -d "/" -f1 | head -n1`
if [ ! "$CM_IP" ]; then
echo "Error: There is no valid CM interface configured and error getting IPv6 address for the device"
echo "As there is no valid IPV6 configured, assigning a valid IPv4 for the device"
if [ ! -z "$CM_IPV4" ]; then
CM_IP=$CM_IPV4
fi
fi
if [ -z "$CM_IP" -a -z "$CM_IPV4" ]; then
echo "Error: There is no valid CM interface configured and error while starting ssh process."
t2CountNotify "REVSSH_CMINTERFACE_FAILURE"
exit 127
fi
elif [ $BOX_TYPE = "XF3" ]; then
# PACE XF3 and PACE CFG3
CM_IP=`ifconfig $CMINTERFACE | grep inet6 | tr -s " " | grep -v Link | cut -d " " -f4 | cut -d "/" -f1 | head -n1`
if [ -z "$CM_IP" ]; then
CM_IP=`ifconfig $CMINTERFACE | grep "inet addr" | awk '/inet/{print $2}' | cut -f2 -d: | head -n1`
fi
else
CM_IP=`getCMIPAddress`
fi #if [ "$MANUFACTURE" = "Technicolor" -a "$BOX_TYPE" != "XB3" ]; then
fi #if [ -f "/nvram/ETHWAN_ENABLE" ];then
# Replace CM_IP with value
args=`echo $* | sed "s/CM_IP/$CM_IP/g"`
if [ ! -f /usr/bin/GetConfigFile ];then
echo "Error: GetConfigFile Not Found"
t2CountNotify "REVSSH_GETCONFIGFILE_FAILURE"
exit 127
fi
if [ -f /var/tmp/rssh.pid ];then
REVSSH_PID1=`cat /var/tmp/rssh.pid `
else
REVSSH_PID1=""
fi
GetConfigFile /tmp/nvgeajacl.ipe stdout | /usr/bin/ssh -i /dev/stdin $args &
sleep 10
REVSSH_PID2=`cat /var/tmp/rssh.pid `
if [ -z "$REVSSH_PID2" ] ||[ "$REVSSH_PID1" == "$REVSSH_PID2" ]; then
echo "SSH Tunnel failure. "
t2CountNotify "REVSSH_FAILURE"
else
echo " SSH Tunnel success. "
t2CountNotify "REVSSH_SUCCESS"
fi
exit 1
;;
stop)
cat /var/tmp/rssh.pid |xargs kill -9
rm /var/tmp/rssh.pid
exit 1
;;
*)
usage
exit 1
esac