{"record":{"id":"6b3a078680d126b4","repo":"OpenNHP/opennhp","slug":"packet-header-type-does-not-match-device","errorCode":null,"errorMessage":"packet header type does not match device","messagePattern":"packet header type does not match device","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"nhp/core/packet.go","lineNumber":253,"sourceCode":"\t}\n\tlog.Info(\"Device type: %d, recv header type %d not allowed\", d.deviceType, t)\n\treturn false\n}\n\nfunc (d *Device) RecvPrecheck(pkt *Packet) (int, int, error) {\n\theaderSize := pkt.Header().Size()\n\n\t// check type and payload size\n\tt, s := pkt.HeaderTypeAndSize()\n\tif t == NHP_KPL {\n\t\tif s == 0 {\n\t\t\treturn t, s, nil\n\t\t} else {\n\t\t\treturn t, s, fmt.Errorf(\"keepalive packet size is incorrect\")\n\t\t}\n\t}\n\tif !d.CheckRecvHeaderType(t) {\n\t\treturn t, s, fmt.Errorf(\"packet header type does not match device\")\n\t}\n\n\ttotalLen := len(pkt.Content)\n\tif totalLen != headerSize+s {\n\t\treturn t, s, fmt.Errorf(\"packet total size is incorrect\")\n\t}\n\n\treturn t, s, nil\n}\n\nfunc (d *Device) AllocatePoolPacket() *Packet {\n\tbuf := d.pool.Get()\n\treturn &Packet{Buf: buf, Content: buf[:], PoolAllocated: true}\n}\n\nfunc (d *Device) ReleasePoolPacket(pkt *Packet) {\n\tif pkt != nil && pkt.Buf != nil && pkt.PoolAllocated {\n\t\td.pool.Put(pkt.Buf)","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/nhp/core/packet.go#L235-L271","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ndev, _ := nhpcore.NewDevice(nhpcore.NHP_AGENT) // but receives AOP packets\n// after\ndev, _ := nhpcore.NewDevice(nhpcore.NHP_SERVER) // AOP is a server-received type","handlingStrategy":"validation","validationCode":"t, _ := pkt.HeaderTypeAndSize()\nif !dev.CheckRecvHeaderType(t) {\n    return fmt.Errorf(\"type %d not accepted by this device\", t)\n}","typeGuard":"func accepts(dev *nhpcore.Device, pkt *nhpcore.Packet) bool {\n    t, _ := pkt.HeaderTypeAndSize()\n    return dev.CheckRecvHeaderType(t)\n}","tryCatchPattern":"if _, _, err := dev.RecvPrecheck(pkt); err != nil && strings.Contains(err.Error(), \"header type does not match\") {\n    log.Warnf(\"misrouted packet dropped\")\n    return\n}","preventionTips":["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)"],"tags":["go","protocol","routing"],"backgroundTag":"invalid-enum-value","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}