Skip to content

Commit 54de369

Browse files
tommyv1987Tommy Verrall
andauthored
Skip ipv6 metadata endpoint request (#6118)
Co-authored-by: Tommy Verrall <[email protected]>
1 parent 6d6ce28 commit 54de369

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

nym-gateway-probe/netstack_ping/lib.go

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,20 @@ func ping(req NetstackRequestGo) (NetstackResponse, error) {
192192

193193
response.CanHandshake = true
194194

195-
version, duration, err := queryMetadata(req.MetadataEndpoint, req.MetadataTimeoutSec, tnet)
196-
if err != nil {
197-
log.Printf("Failed to query metadata URLs: %v\n", err)
198-
response.CanQueryMetadata = false
195+
// Skip metadata query if endpoint is empty (e.g., for IPv6 where the IPv4 metadata endpoint is not reachable)
196+
if req.MetadataEndpoint != "" {
197+
version, duration, err := queryMetadata(req.MetadataEndpoint, req.MetadataTimeoutSec, tnet)
198+
if err != nil {
199+
log.Printf("Failed to query metadata URLs: %v\n", err)
200+
response.CanQueryMetadata = false
201+
} else {
202+
log.Printf("Queried metadata endpoint with version: %v\n", version)
203+
log.Printf("Query duration: %v\n", duration)
204+
response.CanQueryMetadata = true
205+
}
199206
} else {
200-
log.Printf("Queried metadata endpoint with version: %v\n", version)
201-
log.Printf("Query duration: %v\n", duration)
202-
response.CanQueryMetadata = true
207+
log.Printf("Skipping metadata query (no endpoint provided)")
208+
response.CanQueryMetadata = false
203209
}
204210

205211
for _, host := range req.PingHosts {
@@ -540,25 +546,25 @@ func queryMetadata(url string, timeoutSecs uint64, tnet *netstack.Net) (int, tim
540546
func main() {
541547
// uncomment the lines below to run locally and see README.md for how to get the Wireguard config
542548
/* var _, err = ping(NetstackRequestGo{
543-
WgIp: "10.1.155.153",
544-
PrivateKey: "...",
545-
PublicKey: "...",
546-
Endpoint: "13.245.9.123:51822",
547-
MetadataEndpoint: "http://10.1.0.1:51830",
548-
Dns: "1.1.1.1",
549-
IpVersion: 4,
550-
//PingHosts: nil,
551-
//PingIps: nil,
552-
//NumPing: 0,
553-
//SendTimeoutSec: 0,
554-
//RecvTimeoutSec: 0,
555-
//DownloadTimeoutSec: 0,
556-
MetadataTimeoutSec: 5,
557-
//AwgArgs: "",
558-
})
559-
560-
if err != nil {
561-
log.Fatal(err)
562-
}
549+
WgIp: "10.1.155.153",
550+
PrivateKey: "...",
551+
PublicKey: "...",
552+
Endpoint: "13.245.9.123:51822",
553+
MetadataEndpoint: "http://10.1.0.1:51830",
554+
Dns: "1.1.1.1",
555+
IpVersion: 4,
556+
//PingHosts: nil,
557+
//PingIps: nil,
558+
//NumPing: 0,
559+
//SendTimeoutSec: 0,
560+
//RecvTimeoutSec: 0,
561+
//DownloadTimeoutSec: 0,
562+
MetadataTimeoutSec: 5,
563+
//AwgArgs: "",
564+
})
565+
566+
if err != nil {
567+
log.Fatal(err)
568+
}
563569
*/
564570
}

nym-gateway-probe/netstack_ping/lib_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ func TestPingFunction(t *testing.T) {
215215
// Create a request with valid IP but will fail due to network setup
216216
req := NetstackRequestGo{
217217
WgIp: "10.0.0.1",
218-
PrivateKey: "test-key",
219-
PublicKey: "test-pub-key",
218+
PrivateKey: "0000000000000000000000000000000000000000000000000000000000000000",
219+
PublicKey: "0000000000000000000000000000000000000000000000000000000000000000",
220220
Endpoint: "1.1.1.1:51820",
221221
Dns: "1.1.1.1",
222222
IpVersion: 4,
@@ -275,10 +275,11 @@ func TestResultStructs(t *testing.T) {
275275
// TestConsecutiveFailureExit validates that the ping loop exits cleanly after consecutive failures
276276
func TestConsecutiveFailureExit(t *testing.T) {
277277
// Create a test request that will trigger consecutive failures
278+
// Using valid hex-encoded keys (32 bytes = 64 hex chars)
278279
req := NetstackRequestGo{
279280
WgIp: "10.0.0.1",
280-
PrivateKey: "test-key",
281-
PublicKey: "test-pub-key",
281+
PrivateKey: "0000000000000000000000000000000000000000000000000000000000000000",
282+
PublicKey: "0000000000000000000000000000000000000000000000000000000000000000",
282283
Endpoint: "1.1.1.1:51820",
283284
Dns: "1.1.1.1",
284285
IpVersion: 4,

nym-gateway-probe/src/netstack.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ impl NetstackRequestGo {
145145
private_key: req.private_key.clone(),
146146
public_key: req.public_key.clone(),
147147
endpoint: req.endpoint.clone(),
148-
metadata_endpoint: req.metadata_endpoint.clone(),
148+
// Skip metadata endpoint for IPv6 as it's an IPv4-only address (10.1.0.1)
149+
metadata_endpoint: String::new(),
149150
dns: req.v6_ping_config.dns.clone(),
150151
ip_version: 6,
151152
ping_hosts: req.v6_ping_config.ping_hosts.clone(),

0 commit comments

Comments
 (0)