OpenNHP/opennhp · warning
packet header type does not match device
Error message
packet header type does not match device
What it means
Device.RecvPrecheck checks the packet's header type against the receiving device's allowed incoming types via CheckRecvHeaderType. If this device should never receive a packet of that type (e.g. an AC getting a DHP message it does not handle), the packet is rejected.
Solutions
- Verify the sender's target address/port actually belongs to this device type
- Check d.deviceType — the recv header allowlist is derived from it
- Ensure relay/forward paths tag packets with the correct header type
- Confirm both peers run the same protocol version and packet-type table
Example fix
// before dev, _ := nhpcore.NewDevice(nhpcore.NHP_AGENT) // but receives AOP packets // after dev, _ := nhpcore.NewDevice(nhpcore.NHP_SERVER) // AOP is a server-received type
Defensive patterns
Strategy: validation
Validate before calling
t, _ := pkt.HeaderTypeAndSize()
if !dev.CheckRecvHeaderType(t) {
return fmt.Errorf("type %d not accepted by this device", t)
} Type guard
func accepts(dev *nhpcore.Device, pkt *nhpcore.Packet) bool {
t, _ := pkt.HeaderTypeAndSize()
return dev.CheckRecvHeaderType(t)
} Try / catch
if _, _, err := dev.RecvPrecheck(pkt); err != nil && strings.Contains(err.Error(), "header type does not match") {
log.Warnf("misrouted packet dropped")
return
} Prevention
- Double-check target host:port belongs to the intended device type
- Configure deviceType correctly at startup
- Log and alert on repeated type mismatches (possible misrouting)
When it happens
Trigger: recvPacketRoutine, HandleRelayForward, or PacketToMsg delivers a packet whose header type t is not in the receiving device's CheckRecvHeaderType allowlist — typically packets sent to the wrong device/endpoint or misrouted UDP traffic.
Common situations: Pointing an agent at the wrong endpoint (e.g. AC address instead of server); configuring a device with the wrong deviceType so its recv filter excludes expected types; port reuse by another process.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- no server cluster: set Cluster in resource.toml or use…
- missing connection data for server
- missing remote address
- keepalive packet size is incorrect
- extractInitiatorStaticPubKey: curve scheme expected
AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07).
Data as JSON: /api/errors/6b3a078680d126b4.
Report an issue: GitHub.
Appendix: source
Thrown at nhp/core/packet.go:253
}
log.Info("Device type: %d, recv header type %d not allowed", d.deviceType, t)
return false
}
func (d *Device) RecvPrecheck(pkt *Packet) (int, int, error) {
headerSize := pkt.Header().Size()
// check type and payload size
t, s := pkt.HeaderTypeAndSize()
if t == NHP_KPL {
if s == 0 {
return t, s, nil
} else {
return t, s, fmt.Errorf("keepalive packet size is incorrect")
}
}
if !d.CheckRecvHeaderType(t) {
return t, s, fmt.Errorf("packet header type does not match device")
}
totalLen := len(pkt.Content)
if totalLen != headerSize+s {
return t, s, fmt.Errorf("packet total size is incorrect")
}
return t, s, nil
}
func (d *Device) AllocatePoolPacket() *Packet {
buf := d.pool.Get()
return &Packet{Buf: buf, Content: buf[:], PoolAllocated: true}
}
func (d *Device) ReleasePoolPacket(pkt *Packet) {
if pkt != nil && pkt.Buf != nil && pkt.PoolAllocated {
d.pool.Put(pkt.Buf)View on GitHub (pinned to 6e04ca5ff0)