Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/scripts/init/c_registration/15_ssh_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const char* SERVICE_CUSTOM_EVENTS[] = {
#endif
#if defined(_ARRIS_XB6_PRODUCT_REQ_)
"wan-status|/etc/utopia/service.d/service_sshd.sh",
#endif
#if defined(_WNXL11BWL_PRODUCT_REQ_)
"ipv4_br-home_dhcp_ipaddr|/etc/utopia/service.d/service_sshd.sh|NULL|"TUPLE_FLAG_EVENT,
#endif
NULL
};
Expand Down
85 changes: 64 additions & 21 deletions source/scripts/init/service.d/service_sshd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@ get_listen_params() {
fi
}

# wait_for_iface_ip <interface>
# Blocks up to 300 seconds (150 x 2s) waiting for an IPv4 address on the
# given interface. Prints the IP to stdout on success; logs an error and
# returns 1 on timeout.
wait_for_iface_ip() {
Comment on lines +137 to +141
local IFACE="$1"
local SLEEP_INTERVAL=2
local RETRIES=0
local MAX_RETRIES=150
local WAITED_IP
while [ $RETRIES -lt $MAX_RETRIES ]; do
WAITED_IP=`ip -4 addr show dev "$IFACE" scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1`
if [ -n "$WAITED_IP" ]; then
echo_t "[utopia] $IFACE got IP $WAITED_IP after $((RETRIES * SLEEP_INTERVAL)) seconds" >&2
echo "$WAITED_IP"
return 0
fi
RETRIES=$((RETRIES + 1))
sleep $SLEEP_INTERVAL
done
echo_t "[utopia] ERROR: Timed out waiting for IP on $IFACE after $((MAX_RETRIES * SLEEP_INTERVAL)) seconds" >&2
return 1
}

do_start() {
#DIR_NAME=/tmp/home/admin
#if [ ! -d $DIR_NAME ] ; then
Expand Down Expand Up @@ -195,31 +219,32 @@ do_start() {
commandString="$commandString -p [$CM_IPV6]:22"
fi
fi
elif [ "$BOX_TYPE" = "SCER11BEL" -a "$LANIPV6Support" = "true" ]; then
# In IPv6 only case (MAP-T), and if IPv6 GUA on LAN enabled case, use brlan0 interface to get v6 global address.
CM_IPV6=`ip -6 addr show dev brlan0 scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1`
if [ ! -z "$CM_IPV6" ]; then
commandString="$commandString -p [$CM_IPV6]:22"
fi

# Check IPv4 address.
CM_IPV4=`ip -4 addr show dev $CMINTERFACE scope global | awk '/inet/{print $2}' | cut -d '/' -f1`
if [ ! -z "$CM_IPV4" ]; then
commandString="$commandString -p [$CM_IPV4]:22"
fi
elif [ "$BOX_TYPE" = "WNXL11BWL" ]; then
CM_IP=`ip -4 addr show dev $CMINTERFACE scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1`
if [ ! -z $CM_IP ]; then
commandString="$commandString -p [$CM_IP]:22"
fi
commandString=""
CM_IPv6=`ip -6 addr show dev wwan0 scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1`
if [ ! -z $CM_IPv6 ]; then
if [ ! -z "$CM_IPv6" ]; then
commandString="$commandString -p [$CM_IPv6]:22"
fi
CM_IPv4=`ip -4 addr show dev wwan0 scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1`
if [ ! -z $CM_IPv4 ]; then
if [ ! -z "$CM_IPv4" ]; then
commandString="$commandString -p [$CM_IPv4]:22"
fi
if [ "$CMINTERFACE" = "br-home" ]; then
CM_IP=`sysevent get ipv4_br-home_dhcp_ipaddr`
echo_t "[utopia] ipv4_br-home_dhcp_ipaddr = $CM_IP"
Comment on lines +232 to +234
if [ -n "$CM_IP" ] && [ "$CM_IP" != "0.0.0.0" ]; then
commandString="$commandString -p [$CM_IP]:22"
else
echo_t "[utopia] ipv4_br-home_dhcp_ipaddr not set or invalid ($CM_IP), skipping $CMINTERFACE listen address"
fi
else
CM_IP=`ip -4 addr show dev "$CMINTERFACE" scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1`
if [ -n "$CM_IP" ]; then
commandString="$commandString -p [$CM_IP]:22"
else
echo_t "[utopia] $CMINTERFACE has no IPv4 address, skipping listen address"
fi
fi
else
CM_IP=""
if ([ "$BOX_TYPE" = "rpi" ] || [ "$BOX_TYPE" = "bpi" ]) ;then
Expand Down Expand Up @@ -270,8 +295,6 @@ do_start() {
if ([ "$MANUFACTURE" = "Technicolor" ] || [ "$MODEL_NUM" = "SG417DBCT" ] || [ "$BOX_TYPE" = "WNXL11BWL" ]) ; then
echo_t "dropbear -E -s -K 60 -b /etc/sshbanner.txt ${commandString} -r ${DROPBEAR_PARAMS_1} -r ${DROPBEAR_PARAMS_2} -a -P ${PID_FILE}"
dropbear -E -s -b /etc/sshbanner.txt $commandString -r $DROPBEAR_PARAMS_1 -r $DROPBEAR_PARAMS_2 -a -P $PID_FILE -K 60 $USE_DEVKEYS 2>>$CONSOLEFILE
elif [ "$BOX_TYPE" = "SCER11BEL" -a "$LANIPV6Support" = "true" ]; then
dropbear -E -s -b /etc/sshbanner.txt $commandString -r $DROPBEAR_PARAMS_1 -r $DROPBEAR_PARAMS_2 -a -P $PID_FILE -K 60 $USE_DEVKEYS 2>>$CONSOLEFILE
else
dropbear -E -s -b /etc/sshbanner.txt -a -r $DROPBEAR_PARAMS_1 -r $DROPBEAR_PARAMS_2 -p [$CM_IP]:22 -P $PID_FILE $USE_DEVKEYS 2>>$CONSOLEFILE
fi
Expand Down Expand Up @@ -452,9 +475,29 @@ case "$1" in
service_stop
service_start
;;
mesh_wan_linkstatus)
if [ "$BOX_TYPE" = "WNXL11BWL" ] && [ "$2" = "up" ]; then
DEVICE_MODE=`deviceinfo.sh -mode`
if [ "$DEVICE_MODE" = "Extender" ]; then
echo_t "commented out intentionall"
#service_stop
Comment on lines +478 to +483
#service_start
fi
Comment on lines +482 to +485
fi
;;
ipv4_br-home_dhcp_ipaddr)
if [ "$BOX_TYPE" = "WNXL11BWL" ]; then
echo_t "ipv4_br-home_dhcp_ipaddr is set with $2"
DEVICE_MODE=`deviceinfo.sh -mode`
if [ "$DEVICE_MODE" = "Extender" ]; then
service_stop
service_start
fi
fi
;;

*)
echo "Usage: $SELF_NAME [${SERVICE_NAME}-start|${SERVICE_NAME}-stop|${SERVICE_NAME}-restart|ssh_server_restart|lan-status|wan-status]" >&2
echo "Usage: $SELF_NAME [${SERVICE_NAME}-start|${SERVICE_NAME}-stop|${SERVICE_NAME}-restart|wan-status|bridge-status|current_wan_ifname|mesh_wan_linkstatus <status>]" >&2
exit 3
;;
esac
Expand Down
Loading