feat(health/icmp): log out return address on errors

This commit is contained in:
Quentin McGaw
2025-10-23 19:22:31 +00:00
parent 9803fa1cfd
commit c48189c1c4

View File

@@ -153,7 +153,7 @@ func receiveEchoReply(conn net.PacketConn, id int, buffer []byte, ipVersion stri
// Note we need to read the whole packet in one call to ReadFrom, so the buffer // Note we need to read the whole packet in one call to ReadFrom, so the buffer
// must be large enough to read the entire reply packet. See: // must be large enough to read the entire reply packet. See:
// https://groups.google.com/g/golang-nuts/c/5dy2Q4nPs08/m/KmuSQAGEtG4J // https://groups.google.com/g/golang-nuts/c/5dy2Q4nPs08/m/KmuSQAGEtG4J
bytesRead, _, err := conn.ReadFrom(buffer) bytesRead, returnAddr, err := conn.ReadFrom(buffer)
if err != nil { if err != nil {
return nil, fmt.Errorf("reading from ICMP connection: %w", err) return nil, fmt.Errorf("reading from ICMP connection: %w", err)
} }
@@ -168,23 +168,26 @@ func receiveEchoReply(conn net.PacketConn, id int, buffer []byte, ipVersion stri
switch body := message.Body.(type) { switch body := message.Body.(type) {
case *icmp.Echo: case *icmp.Echo:
if id != body.ID { if id != body.ID {
logger.Warnf("ignoring ICMP echo reply mismatching expected id %d (id: %d, type: %d, code: %d, length: %d)", logger.Warnf("ignoring ICMP echo reply mismatching expected id %d "+
id, body.ID, message.Type, message.Code, len(packetBytes)) "(id: %d, type: %d, code: %d, length: %d, return address %s)",
id, body.ID, message.Type, message.Code, len(packetBytes), returnAddr)
continue // not the ID we are looking for continue // not the ID we are looking for
} }
return body.Data, nil return body.Data, nil
case *icmp.DstUnreach: case *icmp.DstUnreach:
logger.Debugf("ignoring ICMP destination unreachable message (type: 3, code: %d, expected-id %d)", message.Code, id) logger.Debugf("ignoring ICMP destination unreachable message (type: 3, code: %d, return address %s, expected-id %d)",
message.Code, returnAddr, id)
// See https://github.com/qdm12/gluetun/pull/2923#issuecomment-3377532249 // See https://github.com/qdm12/gluetun/pull/2923#issuecomment-3377532249
// on why we ignore this message. If it is actually unreachable, the timeout on waiting for // on why we ignore this message. If it is actually unreachable, the timeout on waiting for
// the echo reply will do instead of returning an error error. // the echo reply will do instead of returning an error error.
continue continue
case *icmp.TimeExceeded: case *icmp.TimeExceeded:
logger.Debugf("ignoring ICMP time exceeded message (type: 11, code: %d, expected-id %d)", message.Code, id) logger.Debugf("ignoring ICMP time exceeded message (type: 11, code: %d, return address %s, expected-id %d)",
message.Code, returnAddr, id)
continue continue
default: default:
return nil, fmt.Errorf("%w: %T (type %d, code %d, expected-id %d)", return nil, fmt.Errorf("%w: %T (type %d, code %d, return address %s, expected-id %d)",
ErrICMPBodyUnsupported, body, message.Type, message.Code, id) ErrICMPBodyUnsupported, body, message.Type, message.Code, returnAddr, id)
} }
} }
} }