From ec7adcf78e2533a81c43145023aaeaf3740fe729 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 23 Jun 2023 09:36:52 +0200 Subject: update-tunnelbroker: rework the retry-loop --- update-tunnelbroker.rsc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'update-tunnelbroker.rsc') diff --git a/update-tunnelbroker.rsc b/update-tunnelbroker.rsc index a1d5e5e..d0a2d16 100644 --- a/update-tunnelbroker.rsc +++ b/update-tunnelbroker.rsc @@ -25,27 +25,28 @@ $ScriptLock $0; } :foreach Interface in=[ /interface/6to4/find where comment~"^tunnelbroker" !disabled ] do={ - :local I 0; - :local Response ""; + :local Data false; :local InterfaceVal [ /interface/6to4/get $Interface ]; :local Comment [ $ParseKeyValueStore ($InterfaceVal->"comment") ]; - :while ($I < 3 && $Response = "") do={ - :do { - :set Response ([ /tool/fetch check-certificate=yes-without-crl \ + :for I from=2 to=0 do={ + :if ($Data = false) do={ + :do { + :set Data ([ /tool/fetch check-certificate=yes-without-crl \ ("https://ipv4.tunnelbroker.net/nic/update\?hostname=" . $Comment->"id") \ user=($Comment->"user") password=($Comment->"pass") output=user as-value ]->"data"); - } on-error={ - :delay 10s; - :set I ($I + 1); + } on-error={ + $LogPrintExit2 debug $0 ("Failed downloading, " . $I . " retries pending.") false; + :delay 2s; + } } } - :if (!($Response~"^(good|nochg) ")) do={ + :if (!($Data ~ "^(good|nochg) ")) do={ $LogPrintExit2 error $0 ("Failed sending the local address to tunnelbroker or unexpected response!") true; } - :local PublicAddress [ :pick $Response ([ :find $Response " " ] + 1) [ :find $Response "\n" ] ]; + :local PublicAddress [ :pick $Data ([ :find $Data " " ] + 1) [ :find $Data "\n" ] ]; :if ($PublicAddress != $InterfaceVal->"local-address") do={ :if ([ :len [ /ip/address find where address~("^" . $PublicAddress . "/") ] ] < 1) do={ -- cgit v1.2.3-54-g00ecf