Files
gluetun/internal/pmtud/errors.go

30 lines
904 B
Go
Raw Normal View History

2025-08-19 20:04:22 +00:00
package pmtud
import (
"context"
2025-08-19 20:04:22 +00:00
"errors"
"fmt"
"net"
2025-10-14 17:56:04 +00:00
"strings"
"time"
2025-08-19 20:04:22 +00:00
)
var (
2025-10-14 17:56:04 +00:00
ErrICMPNotPermitted = errors.New("ICMP not permitted")
ErrICMPDestinationUnreachable = errors.New("ICMP destination unreachable")
ErrICMPCommunicationAdministrativelyProhibited = errors.New("communication administratively prohibited")
ErrICMPBodyUnsupported = errors.New("ICMP body type is not supported")
2025-08-19 20:04:22 +00:00
)
func wrapConnErr(err error, timedCtx context.Context, pingTimeout time.Duration) error { //nolint:revive
switch {
2025-10-14 17:56:04 +00:00
case strings.HasSuffix(err.Error(), "sendto: operation not permitted"):
err = fmt.Errorf("%w", ErrICMPNotPermitted)
case errors.Is(timedCtx.Err(), context.DeadlineExceeded):
err = fmt.Errorf("%w (timed out after %s)", net.ErrClosed, pingTimeout)
case timedCtx.Err() != nil:
err = timedCtx.Err()
}
return err
}