Return an error if all MTUs failed to test

This commit is contained in:
Quentin McGaw
2025-10-02 16:47:31 +00:00
parent 00bc8bbbbb
commit 5b1dc295fe

View File

@@ -12,6 +12,8 @@ import (
"golang.org/x/net/icmp" "golang.org/x/net/icmp"
) )
var ErrICMPAllMTUsFailed = errors.New("all MTU sizes tested failed")
// PathMTUDiscover discovers the maximum MTU for the path to the given ip address. // PathMTUDiscover discovers the maximum MTU for the path to the given ip address.
// If the physicalLinkMTU is zero, it defaults to 1500 which is the ethernet standard MTU. // If the physicalLinkMTU is zero, it defaults to 1500 which is the ethernet standard MTU.
// If the pingTimeout is zero, it defaults to 1 second. // If the pingTimeout is zero, it defaults to 1 second.
@@ -138,7 +140,7 @@ func pmtudMultiSizes(ctx context.Context, ip netip.Addr,
} }
if tests[0].mtu == minMTU+1 { // All MTUs failed. if tests[0].mtu == minMTU+1 { // All MTUs failed.
return minMTU, nil return 0, fmt.Errorf("%w", ErrICMPAllMTUsFailed)
} }
// Re-test with MTUs between the minimum MTU // Re-test with MTUs between the minimum MTU
// and the smallest next MTU we tested. // and the smallest next MTU we tested.