mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-09 20:29:23 +02:00
chore(pmtud/icmp): do not use net.ErrClosed when inappropriate
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -15,6 +14,7 @@ var (
|
|||||||
ErrCommunicationAdministrativelyProhibited = errors.New("communication administratively prohibited")
|
ErrCommunicationAdministrativelyProhibited = errors.New("communication administratively prohibited")
|
||||||
ErrBodyUnsupported = errors.New("ICMP body type is not supported")
|
ErrBodyUnsupported = errors.New("ICMP body type is not supported")
|
||||||
ErrMTUNotFound = errors.New("MTU not found")
|
ErrMTUNotFound = errors.New("MTU not found")
|
||||||
|
errTimeout = errors.New("operation timed out")
|
||||||
)
|
)
|
||||||
|
|
||||||
func wrapConnErr(err error, timedCtx context.Context, pingTimeout time.Duration) error { //nolint:revive
|
func wrapConnErr(err error, timedCtx context.Context, pingTimeout time.Duration) error { //nolint:revive
|
||||||
@@ -22,7 +22,7 @@ func wrapConnErr(err error, timedCtx context.Context, pingTimeout time.Duration)
|
|||||||
case strings.HasSuffix(err.Error(), "sendto: operation not permitted"):
|
case strings.HasSuffix(err.Error(), "sendto: operation not permitted"):
|
||||||
err = fmt.Errorf("%w", ErrNotPermitted)
|
err = fmt.Errorf("%w", ErrNotPermitted)
|
||||||
case errors.Is(timedCtx.Err(), context.DeadlineExceeded):
|
case errors.Is(timedCtx.Err(), context.DeadlineExceeded):
|
||||||
err = fmt.Errorf("%w (timed out after %s)", net.ErrClosed, pingTimeout)
|
err = fmt.Errorf("%w: after %s", errTimeout, pingTimeout)
|
||||||
case timedCtx.Err() != nil:
|
case timedCtx.Err() != nil:
|
||||||
err = timedCtx.Err()
|
err = timedCtx.Err()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -26,7 +25,7 @@ func PathMTUDiscover(ctx context.Context, ip netip.Addr,
|
|||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
return mtu, nil
|
return mtu, nil
|
||||||
case errors.Is(err, net.ErrClosed) || errors.Is(err, ErrCommunicationAdministrativelyProhibited): // blackhole
|
case errors.Is(err, errTimeout) || errors.Is(err, ErrCommunicationAdministrativelyProhibited): // blackhole
|
||||||
default:
|
default:
|
||||||
return 0, fmt.Errorf("finding IPv4 next hop MTU: %w", err)
|
return 0, fmt.Errorf("finding IPv4 next hop MTU: %w", err)
|
||||||
}
|
}
|
||||||
@@ -36,7 +35,7 @@ func PathMTUDiscover(ctx context.Context, ip netip.Addr,
|
|||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
return mtu, nil
|
return mtu, nil
|
||||||
case errors.Is(err, net.ErrClosed): // blackhole
|
case errors.Is(err, errTimeout): // blackhole
|
||||||
default:
|
default:
|
||||||
return 0, fmt.Errorf("getting IPv6 packet-too-big message: %w", err)
|
return 0, fmt.Errorf("getting IPv6 packet-too-big message: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user