From 3af725d819bd8a68ab3efb383ae6f0c3f269d0aa Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Mon, 4 May 2026 15:17:19 +0530 Subject: [PATCH 01/12] LTE-2904: Debug commands enable --- source/scripts/init/service.d/service_sshd.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index a2ba75cc..ef59c8b7 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -208,10 +208,14 @@ do_start() { commandString="$commandString -p [$CM_IPV4]:22" fi elif [ "$BOX_TYPE" = "WNXL11BWL" ]; then + echo_t "[utopia] devicemode `deviceinfo.sh -mode`" + echo_t "[utopia] route `route -n`" + echo_t "[utopia] CMINTERFACE $CMINTERFACE " 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 + echo_t "[utopia] CM_IP $CM_IP " CM_IPv6=`ip -6 addr show dev wwan0 scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1` if [ ! -z $CM_IPv6 ]; then commandString="$commandString -p [$CM_IPv6]:22" @@ -220,6 +224,7 @@ do_start() { if [ ! -z $CM_IPv4 ]; then commandString="$commandString -p [$CM_IPv4]:22" fi + echo_t "[utopia] commandString $commandString" else CM_IP="" if ([ "$BOX_TYPE" = "rpi" ] || [ "$BOX_TYPE" = "bpi" ]) ;then From a985c00cb91df6cf50270db7b339ada853b918cc Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Fri, 15 May 2026 12:55:29 +0530 Subject: [PATCH 02/12] LTE-2904: Register sshd for wan-status sysevent --- source/scripts/init/c_registration/15_ssh_server.c | 1 + source/scripts/init/service.d/service_sshd.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/source/scripts/init/c_registration/15_ssh_server.c b/source/scripts/init/c_registration/15_ssh_server.c index 6143ee73..1e9e8590 100644 --- a/source/scripts/init/c_registration/15_ssh_server.c +++ b/source/scripts/init/c_registration/15_ssh_server.c @@ -47,6 +47,7 @@ const char* SERVICE_CUSTOM_EVENTS[] = { "bridge-status|/etc/utopia/service.d/service_sshd.sh", #ifdef WAN_FAILOVER_SUPPORTED "current_wan_ifname|/etc/utopia/service.d/service_sshd.sh", + "wan-status|/etc/utopia/service.d/service_sshd.sh", #endif #if defined(_ARRIS_XB6_PRODUCT_REQ_) "wan-status|/etc/utopia/service.d/service_sshd.sh", diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index ef59c8b7..ee295994 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -438,7 +438,7 @@ case "$1" in #service_lanwan_status #;; wan-status) - if ([ "$BOX_TYPE" = "XB6" -a "$MANUFACTURE" = "Arris" ]) ;then + if ([ "$BOX_TYPE" = "XB6" -a "$MANUFACTURE" = "Arris" ] || [ "$BOX_TYPE" = "WNXL11BWL" ]) ;then echo_t "utopia: Need to handle the wan-status event." if [ -n "$CURRENT_WAN_STATUS" ]; then if [ "started" = "$CURRENT_WAN_STATUS" ]; then From 8940f6bac73079b71e1e825cbfa2e60251b165c7 Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Mon, 18 May 2026 11:42:31 +0530 Subject: [PATCH 03/12] LTE-2904 : Wait for br-home IP --- source/scripts/init/service.d/service_sshd.sh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index ee295994..9531c32e 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -134,6 +134,36 @@ get_listen_params() { fi } +# wait_for_iface_ip +# Polls every 2 seconds up to 120 seconds for an IPv4 address on the given +# interface, then triggers a sshd restart. Must be called in the background. +# A lock file prevents multiple concurrent pollers from running. +WAIT_FOR_IP_LOCKFILE="/tmp/.sshd_wait_for_ip.lock" +wait_for_iface_ip() { + local IFACE="$1" + # Bail out if a poller is already running + if [ -f "$WAIT_FOR_IP_LOCKFILE" ]; then + echo_t "[utopia] wait_for_iface_ip already running for $IFACE, skipping" + return 1 + fi + touch "$WAIT_FOR_IP_LOCKFILE" + local RETRIES=0 + local MAX_RETRIES=60 # 60 x 2s = 120s max wait + while [ $RETRIES -lt $MAX_RETRIES ]; do + sleep 2 + WAITED_IP=`ip -4 addr show dev $IFACE scope global | awk '/inet/{print $2}' | cut -d '/' -f1` + if [ -n "$WAITED_IP" ]; then + echo_t "[utopia] $IFACE got IP $WAITED_IP, restarting ${SERVICE_NAME}" + rm -f "$WAIT_FOR_IP_LOCKFILE" + /etc/utopia/service.d/service_sshd.sh ${SERVICE_NAME}-restart + return 0 + fi + RETRIES=$((RETRIES + 1)) + done + rm -f "$WAIT_FOR_IP_LOCKFILE" + echo_t "[utopia] Timed out waiting for IP on $IFACE after $((MAX_RETRIES * 2)) seconds" +} + do_start() { #DIR_NAME=/tmp/home/admin #if [ ! -d $DIR_NAME ] ; then @@ -214,6 +244,14 @@ do_start() { 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" + else + DEVICE_MODE=`deviceinfo.sh -mode` + if [ "$DEVICE_MODE" = "Extender" ]; then + echo_t "[utopia] $CMINTERFACE has no IP yet (Extender mode), starting background wait for IP on $CMINTERFACE" + wait_for_iface_ip "$CMINTERFACE" & + else + echo_t "[utopia] $CMINTERFACE has no IP and device is not in Extender mode, skipping wait" + fi fi echo_t "[utopia] CM_IP $CM_IP " CM_IPv6=`ip -6 addr show dev wwan0 scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1` From 7fc80e4c474588601d9c2df12e96e9c2408b19f0 Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Mon, 18 May 2026 11:42:35 +0530 Subject: [PATCH 04/12] Revert "LTE-2904: Register sshd for wan-status sysevent" This reverts commit a985c00cb91df6cf50270db7b339ada853b918cc. --- source/scripts/init/c_registration/15_ssh_server.c | 1 - source/scripts/init/service.d/service_sshd.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/source/scripts/init/c_registration/15_ssh_server.c b/source/scripts/init/c_registration/15_ssh_server.c index 1e9e8590..6143ee73 100644 --- a/source/scripts/init/c_registration/15_ssh_server.c +++ b/source/scripts/init/c_registration/15_ssh_server.c @@ -47,7 +47,6 @@ const char* SERVICE_CUSTOM_EVENTS[] = { "bridge-status|/etc/utopia/service.d/service_sshd.sh", #ifdef WAN_FAILOVER_SUPPORTED "current_wan_ifname|/etc/utopia/service.d/service_sshd.sh", - "wan-status|/etc/utopia/service.d/service_sshd.sh", #endif #if defined(_ARRIS_XB6_PRODUCT_REQ_) "wan-status|/etc/utopia/service.d/service_sshd.sh", diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index 9531c32e..e7429929 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -476,7 +476,7 @@ case "$1" in #service_lanwan_status #;; wan-status) - if ([ "$BOX_TYPE" = "XB6" -a "$MANUFACTURE" = "Arris" ] || [ "$BOX_TYPE" = "WNXL11BWL" ]) ;then + if ([ "$BOX_TYPE" = "XB6" -a "$MANUFACTURE" = "Arris" ]) ;then echo_t "utopia: Need to handle the wan-status event." if [ -n "$CURRENT_WAN_STATUS" ]; then if [ "started" = "$CURRENT_WAN_STATUS" ]; then From a6fb118d8d94b7349aac54c766e94e5d493e2d0f Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Tue, 19 May 2026 12:53:28 +0530 Subject: [PATCH 05/12] Revert "LTE-2904 : Wait for br-home IP" This reverts commit 8940f6bac73079b71e1e825cbfa2e60251b165c7. --- source/scripts/init/service.d/service_sshd.sh | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index e7429929..ef59c8b7 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -134,36 +134,6 @@ get_listen_params() { fi } -# wait_for_iface_ip -# Polls every 2 seconds up to 120 seconds for an IPv4 address on the given -# interface, then triggers a sshd restart. Must be called in the background. -# A lock file prevents multiple concurrent pollers from running. -WAIT_FOR_IP_LOCKFILE="/tmp/.sshd_wait_for_ip.lock" -wait_for_iface_ip() { - local IFACE="$1" - # Bail out if a poller is already running - if [ -f "$WAIT_FOR_IP_LOCKFILE" ]; then - echo_t "[utopia] wait_for_iface_ip already running for $IFACE, skipping" - return 1 - fi - touch "$WAIT_FOR_IP_LOCKFILE" - local RETRIES=0 - local MAX_RETRIES=60 # 60 x 2s = 120s max wait - while [ $RETRIES -lt $MAX_RETRIES ]; do - sleep 2 - WAITED_IP=`ip -4 addr show dev $IFACE scope global | awk '/inet/{print $2}' | cut -d '/' -f1` - if [ -n "$WAITED_IP" ]; then - echo_t "[utopia] $IFACE got IP $WAITED_IP, restarting ${SERVICE_NAME}" - rm -f "$WAIT_FOR_IP_LOCKFILE" - /etc/utopia/service.d/service_sshd.sh ${SERVICE_NAME}-restart - return 0 - fi - RETRIES=$((RETRIES + 1)) - done - rm -f "$WAIT_FOR_IP_LOCKFILE" - echo_t "[utopia] Timed out waiting for IP on $IFACE after $((MAX_RETRIES * 2)) seconds" -} - do_start() { #DIR_NAME=/tmp/home/admin #if [ ! -d $DIR_NAME ] ; then @@ -244,14 +214,6 @@ do_start() { 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" - else - DEVICE_MODE=`deviceinfo.sh -mode` - if [ "$DEVICE_MODE" = "Extender" ]; then - echo_t "[utopia] $CMINTERFACE has no IP yet (Extender mode), starting background wait for IP on $CMINTERFACE" - wait_for_iface_ip "$CMINTERFACE" & - else - echo_t "[utopia] $CMINTERFACE has no IP and device is not in Extender mode, skipping wait" - fi fi echo_t "[utopia] CM_IP $CM_IP " CM_IPv6=`ip -6 addr show dev wwan0 scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1` From ea646dc824b11c5dde7fac72ca7f7ab02f1e4330 Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Tue, 19 May 2026 13:02:40 +0530 Subject: [PATCH 06/12] LTE-2904 : Register for current_wan_ipaddr --- source/scripts/init/c_registration/15_ssh_server.c | 1 + source/scripts/init/service.d/service_sshd.sh | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/source/scripts/init/c_registration/15_ssh_server.c b/source/scripts/init/c_registration/15_ssh_server.c index 6143ee73..a7bd9508 100644 --- a/source/scripts/init/c_registration/15_ssh_server.c +++ b/source/scripts/init/c_registration/15_ssh_server.c @@ -47,6 +47,7 @@ const char* SERVICE_CUSTOM_EVENTS[] = { "bridge-status|/etc/utopia/service.d/service_sshd.sh", #ifdef WAN_FAILOVER_SUPPORTED "current_wan_ifname|/etc/utopia/service.d/service_sshd.sh", + "current_wan_ipaddr|/etc/utopia/service.d/service_sshd.sh", #endif #if defined(_ARRIS_XB6_PRODUCT_REQ_) "wan-status|/etc/utopia/service.d/service_sshd.sh", diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index ef59c8b7..3983463b 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -211,6 +211,7 @@ do_start() { echo_t "[utopia] devicemode `deviceinfo.sh -mode`" echo_t "[utopia] route `route -n`" echo_t "[utopia] CMINTERFACE $CMINTERFACE " + echo_t "[utopia] current_wan_ipaddr `sysevent get current_wan_ipaddr`" 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" @@ -457,6 +458,10 @@ case "$1" in service_stop service_start ;; + current_wan_ipaddr) + service_stop + service_start + ;; *) echo "Usage: $SELF_NAME [${SERVICE_NAME}-start|${SERVICE_NAME}-stop|${SERVICE_NAME}-restart|ssh_server_restart|lan-status|wan-status]" >&2 From a4829e49e917d346fcdc78ada505505e7436f689 Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Wed, 20 May 2026 13:21:47 +0530 Subject: [PATCH 07/12] LTE-2904 : Avoid Getting IPv4 twice for same interface --- source/scripts/init/service.d/service_sshd.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index 3983463b..1501c867 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -212,19 +212,22 @@ do_start() { echo_t "[utopia] route `route -n`" echo_t "[utopia] CMINTERFACE $CMINTERFACE " echo_t "[utopia] current_wan_ipaddr `sysevent get current_wan_ipaddr`" - 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 - echo_t "[utopia] CM_IP $CM_IP " + 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" != "wwan0" ]; 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 + echo_t "[utopia] CM_IP $CM_IP " + fi echo_t "[utopia] commandString $commandString" else CM_IP="" From 1e90e97802c42ad3fb77cceab4bcd6e56caf9754 Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Wed, 20 May 2026 13:25:30 +0530 Subject: [PATCH 08/12] Revert "LTE-2904 : Register for current_wan_ipaddr" This reverts commit ea646dc824b11c5dde7fac72ca7f7ab02f1e4330. --- source/scripts/init/c_registration/15_ssh_server.c | 1 - source/scripts/init/service.d/service_sshd.sh | 5 ----- 2 files changed, 6 deletions(-) diff --git a/source/scripts/init/c_registration/15_ssh_server.c b/source/scripts/init/c_registration/15_ssh_server.c index a7bd9508..6143ee73 100644 --- a/source/scripts/init/c_registration/15_ssh_server.c +++ b/source/scripts/init/c_registration/15_ssh_server.c @@ -47,7 +47,6 @@ const char* SERVICE_CUSTOM_EVENTS[] = { "bridge-status|/etc/utopia/service.d/service_sshd.sh", #ifdef WAN_FAILOVER_SUPPORTED "current_wan_ifname|/etc/utopia/service.d/service_sshd.sh", - "current_wan_ipaddr|/etc/utopia/service.d/service_sshd.sh", #endif #if defined(_ARRIS_XB6_PRODUCT_REQ_) "wan-status|/etc/utopia/service.d/service_sshd.sh", diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index 1501c867..d6559622 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -211,7 +211,6 @@ do_start() { echo_t "[utopia] devicemode `deviceinfo.sh -mode`" echo_t "[utopia] route `route -n`" echo_t "[utopia] CMINTERFACE $CMINTERFACE " - echo_t "[utopia] current_wan_ipaddr `sysevent get current_wan_ipaddr`" CM_IPv6=`ip -6 addr show dev wwan0 scope global | awk '/inet/{print $2}' | cut -d '/' -f1 | head -n1` if [ ! -z "$CM_IPv6" ]; then @@ -461,10 +460,6 @@ case "$1" in service_stop service_start ;; - current_wan_ipaddr) - service_stop - service_start - ;; *) echo "Usage: $SELF_NAME [${SERVICE_NAME}-start|${SERVICE_NAME}-stop|${SERVICE_NAME}-restart|ssh_server_restart|lan-status|wan-status]" >&2 From c1691f804ea531318b4ce2ebd5442059cf8b48df Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Wed, 20 May 2026 13:34:37 +0530 Subject: [PATCH 09/12] Reapply "LTE-2904 : Wait for br-home IP" This reverts commit a6fb118d8d94b7349aac54c766e94e5d493e2d0f. --- source/scripts/init/service.d/service_sshd.sh | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index d6559622..ad2e5d1d 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -134,6 +134,36 @@ get_listen_params() { fi } +# wait_for_iface_ip +# Polls every 2 seconds up to 120 seconds for an IPv4 address on the given +# interface, then triggers a sshd restart. Must be called in the background. +# A lock file prevents multiple concurrent pollers from running. +WAIT_FOR_IP_LOCKFILE="/tmp/.sshd_wait_for_ip.lock" +wait_for_iface_ip() { + local IFACE="$1" + # Bail out if a poller is already running + if [ -f "$WAIT_FOR_IP_LOCKFILE" ]; then + echo_t "[utopia] wait_for_iface_ip already running for $IFACE, skipping" + return 1 + fi + touch "$WAIT_FOR_IP_LOCKFILE" + local RETRIES=0 + local MAX_RETRIES=60 # 60 x 2s = 120s max wait + while [ $RETRIES -lt $MAX_RETRIES ]; do + sleep 2 + WAITED_IP=`ip -4 addr show dev $IFACE scope global | awk '/inet/{print $2}' | cut -d '/' -f1` + if [ -n "$WAITED_IP" ]; then + echo_t "[utopia] $IFACE got IP $WAITED_IP, restarting ${SERVICE_NAME}" + rm -f "$WAIT_FOR_IP_LOCKFILE" + /etc/utopia/service.d/service_sshd.sh ${SERVICE_NAME}-restart + return 0 + fi + RETRIES=$((RETRIES + 1)) + done + rm -f "$WAIT_FOR_IP_LOCKFILE" + echo_t "[utopia] Timed out waiting for IP on $IFACE after $((MAX_RETRIES * 2)) seconds" +} + do_start() { #DIR_NAME=/tmp/home/admin #if [ ! -d $DIR_NAME ] ; then @@ -224,9 +254,18 @@ do_start() { 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 + else + DEVICE_MODE=`deviceinfo.sh -mode` + if [ "$DEVICE_MODE" = "Extender" ]; then + echo_t "[utopia] $CMINTERFACE has no IP yet (Extender mode), starting background wait for IP on $CMINTERFACE" + wait_for_iface_ip "$CMINTERFACE" & + else + echo_t "[utopia] $CMINTERFACE has no IP and device is not in Extender mode, skipping wait" + fi + fi echo_t "[utopia] CM_IP $CM_IP " fi + echo_t "[utopia] commandString $commandString" else CM_IP="" From 807d7ae8b86916a7e04641ae244835bcda7a0051 Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Wed, 20 May 2026 18:03:09 +0530 Subject: [PATCH 10/12] LTE-2904: Register sshd for remote_ssh_server_ip sysevent --- .../init/c_registration/15_ssh_server.c | 3 ++ source/scripts/init/service.d/service_sshd.sh | 44 +++---------------- 2 files changed, 10 insertions(+), 37 deletions(-) diff --git a/source/scripts/init/c_registration/15_ssh_server.c b/source/scripts/init/c_registration/15_ssh_server.c index 6143ee73..29c8688e 100644 --- a/source/scripts/init/c_registration/15_ssh_server.c +++ b/source/scripts/init/c_registration/15_ssh_server.c @@ -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_) + "remote_ssh_server_ip|/etc/utopia/service.d/service_sshd.sh", #endif NULL }; diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index ad2e5d1d..42dca8a4 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -134,36 +134,6 @@ get_listen_params() { fi } -# wait_for_iface_ip -# Polls every 2 seconds up to 120 seconds for an IPv4 address on the given -# interface, then triggers a sshd restart. Must be called in the background. -# A lock file prevents multiple concurrent pollers from running. -WAIT_FOR_IP_LOCKFILE="/tmp/.sshd_wait_for_ip.lock" -wait_for_iface_ip() { - local IFACE="$1" - # Bail out if a poller is already running - if [ -f "$WAIT_FOR_IP_LOCKFILE" ]; then - echo_t "[utopia] wait_for_iface_ip already running for $IFACE, skipping" - return 1 - fi - touch "$WAIT_FOR_IP_LOCKFILE" - local RETRIES=0 - local MAX_RETRIES=60 # 60 x 2s = 120s max wait - while [ $RETRIES -lt $MAX_RETRIES ]; do - sleep 2 - WAITED_IP=`ip -4 addr show dev $IFACE scope global | awk '/inet/{print $2}' | cut -d '/' -f1` - if [ -n "$WAITED_IP" ]; then - echo_t "[utopia] $IFACE got IP $WAITED_IP, restarting ${SERVICE_NAME}" - rm -f "$WAIT_FOR_IP_LOCKFILE" - /etc/utopia/service.d/service_sshd.sh ${SERVICE_NAME}-restart - return 0 - fi - RETRIES=$((RETRIES + 1)) - done - rm -f "$WAIT_FOR_IP_LOCKFILE" - echo_t "[utopia] Timed out waiting for IP on $IFACE after $((MAX_RETRIES * 2)) seconds" -} - do_start() { #DIR_NAME=/tmp/home/admin #if [ ! -d $DIR_NAME ] ; then @@ -255,13 +225,7 @@ do_start() { if [ ! -z "$CM_IP" ]; then commandString="$commandString -p [$CM_IP]:22" else - DEVICE_MODE=`deviceinfo.sh -mode` - if [ "$DEVICE_MODE" = "Extender" ]; then - echo_t "[utopia] $CMINTERFACE has no IP yet (Extender mode), starting background wait for IP on $CMINTERFACE" - wait_for_iface_ip "$CMINTERFACE" & - else - echo_t "[utopia] $CMINTERFACE has no IP and device is not in Extender mode, skipping wait" - fi + echo_t "[utopia] $CMINTERFACE has no IP yet, will retry on remote_ssh_server_ip event" fi echo_t "[utopia] CM_IP $CM_IP " fi @@ -499,6 +463,12 @@ case "$1" in service_stop service_start ;; + remote_ssh_server_ip) + if [ "$BOX_TYPE" = "WNXL11BWL" ]; then + service_stop + service_start + fi + ;; *) echo "Usage: $SELF_NAME [${SERVICE_NAME}-start|${SERVICE_NAME}-stop|${SERVICE_NAME}-restart|ssh_server_restart|lan-status|wan-status]" >&2 From 3b0fc6103dfaf3f23cc3159d525a72553c9be616 Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Thu, 21 May 2026 10:07:12 +0530 Subject: [PATCH 11/12] LTE-2904 : Register for mesh_wan_linkstatus --- .../scripts/init/c_registration/15_ssh_server.c | 2 +- source/scripts/init/service.d/service_sshd.sh | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/source/scripts/init/c_registration/15_ssh_server.c b/source/scripts/init/c_registration/15_ssh_server.c index 29c8688e..42286e24 100644 --- a/source/scripts/init/c_registration/15_ssh_server.c +++ b/source/scripts/init/c_registration/15_ssh_server.c @@ -52,7 +52,7 @@ const char* SERVICE_CUSTOM_EVENTS[] = { "wan-status|/etc/utopia/service.d/service_sshd.sh", #endif #if defined(_WNXL11BWL_PRODUCT_REQ_) - "remote_ssh_server_ip|/etc/utopia/service.d/service_sshd.sh", + "mesh_wan_linkstatus|/etc/utopia/service.d/service_sshd.sh", #endif NULL }; diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index 42dca8a4..bc02cc66 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -225,8 +225,8 @@ do_start() { if [ ! -z "$CM_IP" ]; then commandString="$commandString -p [$CM_IP]:22" else - echo_t "[utopia] $CMINTERFACE has no IP yet, will retry on remote_ssh_server_ip event" - fi + echo_t "[utopia] $CMINTERFACE has no IP yet, will retry on mesh_wan_linkstatus event" + fi echo_t "[utopia] CM_IP $CM_IP " fi @@ -463,10 +463,17 @@ case "$1" in service_stop service_start ;; - remote_ssh_server_ip) + mesh_wan_linkstatus) if [ "$BOX_TYPE" = "WNXL11BWL" ]; then - service_stop - service_start + echo_t "mesh_wan_linkstatus_value $2" + echo_t "mesh_wan_linkstatus_sysevent `sysevent get mesh_wan_linkstatus`" + if [ "$2" = "up" ]; then + DEVICE_MODE=`deviceinfo.sh -mode` + if [ "$DEVICE_MODE" = "Extender" ]; then + service_stop + service_start + fi + fi fi ;; From 61b29d37af92e2d9d9cc3d7893872b7cf2bd3a24 Mon Sep 17 00:00:00 2001 From: Rajkamal CV Date: Fri, 22 May 2026 10:28:32 +0530 Subject: [PATCH 12/12] LTE-2904 : Wait for br-home IP when mesh_wan_linkstatus event is set --- source/scripts/init/service.d/service_sshd.sh | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/source/scripts/init/service.d/service_sshd.sh b/source/scripts/init/service.d/service_sshd.sh index bc02cc66..181ff812 100755 --- a/source/scripts/init/service.d/service_sshd.sh +++ b/source/scripts/init/service.d/service_sshd.sh @@ -134,6 +134,29 @@ get_listen_params() { fi } +# wait_for_iface_ip +# 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() { + local IFACE="$1" + local SLEEP_INTERVAL=2 + local RETRIES=0 + local MAX_RETRIES=150 # 150 x 2s = 300s max wait + while [ $RETRIES -lt $MAX_RETRIES ]; do + sleep $SLEEP_INTERVAL + WAITED_IP=`ip -4 addr show dev $IFACE scope global | awk '/inet/{print $2}' | cut -d '/' -f1` + if [ -n "$WAITED_IP" ]; then + echo_t "[utopia] $IFACE got IP $WAITED_IP after $((RETRIES * SLEEP_INTERVAL)) seconds" + echo "$WAITED_IP" + return 0 + fi + RETRIES=$((RETRIES + 1)) + done + echo_t "[utopia] ERROR: Timed out waiting for IP on $IFACE after $((MAX_RETRIES * SLEEP_INTERVAL)) seconds" + return 1 +} + do_start() { #DIR_NAME=/tmp/home/admin #if [ ! -d $DIR_NAME ] ; then @@ -225,8 +248,24 @@ do_start() { if [ ! -z "$CM_IP" ]; then commandString="$commandString -p [$CM_IP]:22" else - echo_t "[utopia] $CMINTERFACE has no IP yet, will retry on mesh_wan_linkstatus event" - fi + DEVICE_MODE=`deviceinfo.sh -mode` + if [ "$DEVICE_MODE" = "Extender" ]; then + MESH_WAN_STATUS=`sysevent get mesh_wan_linkstatus` + if [ "$MESH_WAN_STATUS" = "up" ]; then + echo_t "[utopia] $CMINTERFACE has no IP (Extender mode, mesh WAN up), waiting up to 300s" + CM_IP=`wait_for_iface_ip "$CMINTERFACE"` + if [ -n "$CM_IP" ]; then + commandString="$commandString -p [$CM_IP]:22" + else + echo_t "[utopia] ERROR: $CMINTERFACE did not get an IP after 300s, dropbear will start without it" + fi + else + echo_t "[utopia] $CMINTERFACE has no IP and mesh_wan_linkstatus is not up, skipping wait" + fi + else + echo_t "[utopia] $CMINTERFACE has no IP and device is not in Extender mode, skipping wait" + fi + fi echo_t "[utopia] CM_IP $CM_IP " fi