Handle ICMP not permitted errors

This commit is contained in:
Quentin McGaw
2025-10-14 17:56:04 +00:00
parent 6c25ee53f1
commit 5428580b8f
5 changed files with 22 additions and 3 deletions

View File

@@ -7,6 +7,7 @@ import (
"math"
"net"
"net/netip"
"strings"
"time"
"golang.org/x/net/icmp"
@@ -87,6 +88,9 @@ func pmtudMultiSizes(ctx context.Context, ip netip.Addr,
conn, err = listenICMPv6(ctx)
}
if err != nil {
if strings.HasSuffix(err.Error(), "socket: operation not permitted") {
err = fmt.Errorf("%w: you can try adding NET_RAW capability to resolve this", ErrICMPNotPermitted)
}
return 0, fmt.Errorf("listening for ICMP packets: %w", err)
}
@@ -120,6 +124,9 @@ func pmtudMultiSizes(ctx context.Context, ip netip.Addr,
_, err = conn.WriteTo(encodedMessage, &net.IPAddr{IP: ip.AsSlice()})
if err != nil {
if strings.HasSuffix(err.Error(), "sendto: operation not permitted") {
err = fmt.Errorf("%w", ErrICMPNotPermitted)
}
return 0, fmt.Errorf("writing ICMP message: %w", err)
}
}