Skip to content

Commit c466951

Browse files
committed
update-tunnelbroker: drop extra detection, use response from update
Why hammer on another service? The tunnelbroker response contains the address we need. So send the update every time, and use that information.
1 parent d0eda95 commit c466951

File tree

1 file changed

+25
-34
lines changed

1 file changed

+25
-34
lines changed

update-tunnelbroker

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,39 @@
1717
:global LogPrintExit2;
1818
:global ParseKeyValueStore;
1919

20-
:if ([ $CertificateAvailable "Starfield Secure Certificate Authority - G2" ] = false || \
21-
[ $CertificateAvailable "R3" ] = false) do={
20+
:if ([ $CertificateAvailable "Starfield Secure Certificate Authority - G2" ] = false) do={
2221
$LogPrintExit2 error $0 ("Downloading required certificate failed.") true;
2322
}
2423

25-
:local PublicAddress;
26-
:do {
27-
:set PublicAddress ([ /tool/fetch check-certificate=yes-without-crl \
28-
"https://ipv4.showipv6.de/short" output=user as-value ]->"data");
29-
} on-error={
30-
$LogPrintExit2 error $0 ("Failed getting public address.") true;
31-
}
32-
33-
:if ([ :len [ /ip/address find where address~("^" . $PublicAddress . "/") ] ] < 1) do={
34-
$LogPrintExit2 warning $0 ("Looks like your device does not have the public address. NAT by ISP?") false;
35-
}
36-
3724
:foreach Interface in=[ /interface/6to4/find where comment~"^tunnelbroker" !disabled ] do={
25+
:local I 0;
26+
:local Response "";
3827
:local InterfaceVal [ /interface/6to4/get $Interface ];
28+
:local Comment [ $ParseKeyValueStore ($InterfaceVal->"comment") ];
29+
30+
:while ($I < 3 && $Response = "") do={
31+
:do {
32+
:set Response ([ /tool/fetch check-certificate=yes-without-crl \
33+
("https://ipv4.tunnelbroker.net/nic/update\?hostname=" . $Comment->"id") \
34+
user=($Comment->"user") password=($Comment->"pass") output=user as-value ]->"data");
35+
} on-error={
36+
:delay 10s;
37+
:set I ($I + 1);
38+
}
39+
}
3940

40-
:if ($PublicAddress != $InterfaceVal->"local-address") do={
41-
:local I 0;
42-
:local Success false;
43-
:local Comment [ $ParseKeyValueStore ($InterfaceVal->"comment") ];
41+
:if (!($Response~"^(good|nochg) ")) do={
42+
$LogPrintExit2 error $0 ("Failed sending the local address to tunnelbroker or unexpected response!") true;
43+
}
4444

45-
$LogPrintExit2 info $0 ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $PublicAddress) false;
46-
:while ($I < 3 && $Success = false) do={
47-
:do {
48-
/tool/fetch check-certificate=yes-without-crl \
49-
("https://ipv4.tunnelbroker.net/nic/update\?hostname=" . $Comment->"id") \
50-
user=($Comment->"user") password=($Comment->"pass") output=none as-value;
51-
:set Success true;
52-
} on-error={
53-
:delay 10s;
54-
:set I ($I + 1);
55-
}
56-
}
57-
:if ($Success = false) do={
58-
$LogPrintExit2 error $0 ("Failed sending the local address to tunnelbroker! Wrong credentials?") true;
45+
:local PublicAddress [ :pick $Response ([ :find $Response " " ] + 1) [ :find $Response "\n" ] ];
46+
47+
:if ($PublicAddress != $InterfaceVal->"local-address") do={
48+
:if ([ :len [ /ip/address find where address~("^" . $PublicAddress . "/") ] ] < 1) do={
49+
$LogPrintExit2 warning $0 ("Looks like your device does not have the public address. NAT by ISP?") false;
5950
}
51+
52+
$LogPrintExit2 info $0 ("Local address changed, updating tunnel configuration with address: " . $PublicAddress) false;
6053
/interface/6to4/set $Interface local-address=$PublicAddress;
61-
} else={
62-
$LogPrintExit2 debug $0 ("All tunnelbroker configuration is up to date for interface " . $InterfaceVal->"name" . ".") false;
6354
}
6455
}

0 commit comments

Comments
 (0)