2025-08-19 20:04:22 +00:00
|
|
|
package pmtud
|
|
|
|
|
|
|
|
|
|
import (
|
2025-09-10 14:43:21 +00:00
|
|
|
"context"
|
2025-08-19 20:04:22 +00:00
|
|
|
"errors"
|
2025-09-10 14:43:21 +00:00
|
|
|
"fmt"
|
|
|
|
|
"net"
|
|
|
|
|
"time"
|
2025-08-19 20:04:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
2025-09-11 14:56:12 +00:00
|
|
|
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
|
|
|
)
|
2025-09-10 14:43:21 +00:00
|
|
|
|
|
|
|
|
func wrapConnErr(err error, timedCtx context.Context, pingTimeout time.Duration) error { //nolint:revive
|
|
|
|
|
switch {
|
|
|
|
|
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
|
|
|
|
|
}
|