update-tunnelbroker: work around timing issue

Looks like fetch command has a timing issue with the tunnelbroker
endpoint... We have to try several times to work around this.
Consider the update failed on third error.
This commit is contained in:
Christian Hesse 2022-10-08 23:03:29 +02:00
parent ebaa9b617d
commit 16e93018ef

View file

@ -32,17 +32,26 @@
:local InterfaceVal [ /interface/6to4/get $Interface ];
:if ($PublicAddress != $InterfaceVal->"local-address") do={
:local I 0;
:local Success false;
:local Comment [ $ParseKeyValueStore ($InterfaceVal->"comment") ];
:if ([ $CertificateAvailable "Starfield Secure Certificate Authority - G2" ] = false) do={
$LogPrintExit2 error $0 ("Downloading required certificate failed.") true;
}
$LogPrintExit2 info $0 ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $PublicAddress) false;
:do {
/tool/fetch check-certificate=yes-without-crl \
("https://ipv4.tunnelbroker.net/nic/update\?hostname=" . $Comment->"id") \
user=($Comment->"user") password=($Comment->"pass") output=none as-value;
} on-error={
:while ($I < 3 && $Success = false) do={
:do {
/tool/fetch check-certificate=yes-without-crl \
("https://ipv4.tunnelbroker.net/nic/update\?hostname=" . $Comment->"id") \
user=($Comment->"user") password=($Comment->"pass") output=none as-value;
:set Success true;
} on-error={
:delay 10s;
:set I ($I + 1);
}
}
:if ($Success = false) do={
$LogPrintExit2 error $0 ("Failed sending the local address to tunnelbroker! Wrong credentials?") true;
}
/interface/6to4/set $Interface local-address=$PublicAddress;