Handle administrative prohibition of ICMP
This commit is contained in:
@@ -9,8 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrICMPDestinationUnreachable = errors.New("ICMP destination unreachable")
|
ErrICMPDestinationUnreachable = errors.New("ICMP destination unreachable")
|
||||||
ErrICMPBodyUnsupported = errors.New("ICMP body type is not supported")
|
ErrICMPCommunicationAdministrativelyProhibited = errors.New("communication administratively prohibited")
|
||||||
|
ErrICMPBodyUnsupported = errors.New("ICMP body type is not supported")
|
||||||
)
|
)
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -104,7 +104,15 @@ func findIPv4NextHopMTU(ctx context.Context, ip netip.Addr,
|
|||||||
switch typedBody := inboundMessage.Body.(type) {
|
switch typedBody := inboundMessage.Body.(type) {
|
||||||
case *icmp.DstUnreach:
|
case *icmp.DstUnreach:
|
||||||
const fragmentationRequiredAndDFFlagSetCode = 4
|
const fragmentationRequiredAndDFFlagSetCode = 4
|
||||||
if inboundMessage.Code != fragmentationRequiredAndDFFlagSetCode {
|
const communicationAdministrativelyProhibitedCode = 13
|
||||||
|
switch inboundMessage.Code {
|
||||||
|
case fragmentationRequiredAndDFFlagSetCode:
|
||||||
|
case communicationAdministrativelyProhibitedCode:
|
||||||
|
return 0, fmt.Errorf("%w: %w (code %d)",
|
||||||
|
ErrICMPDestinationUnreachable,
|
||||||
|
ErrICMPCommunicationAdministrativelyProhibited,
|
||||||
|
inboundMessage.Code)
|
||||||
|
default:
|
||||||
return 0, fmt.Errorf("%w: code %d",
|
return 0, fmt.Errorf("%w: code %d",
|
||||||
ErrICMPDestinationUnreachable, inboundMessage.Code)
|
ErrICMPDestinationUnreachable, inboundMessage.Code)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,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, net.ErrClosed) || errors.Is(err, ErrICMPCommunicationAdministrativelyProhibited): // 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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user