package awgserver
import "encoding/binary"
// WireGuard message sizes (from noise-protocol.go).
const (
messageInitiationSize = 148
messageResponseSize = 92
messageCookieReplySize = 64
messageTransportHeaderSize = 16
)
// isAWGPacket checks if the packet matches any AmneziaWG message type
// using the S1-S4 size offsets and H1-H4 header ranges.
func isAWGPacket(pkt []byte, cfg *Config) bool {
size := len(pkt)
// Initiation: exact size S1+148, H1 at offset S1.
if size == cfg.S1+messageInitiationSize && size >= cfg.S1+4 {
hdr := binary.LittleEndian.Uint32(pkt[cfg.S1:])
if cfg.H1.Contains(hdr) {
return true
}
}
// Response: exact size S2+92, H2 at offset S2.
if size == cfg.S2+messageResponseSize && size >= cfg.S2+4 {
hdr := binary.LittleEndian.Uint32(pkt[cfg.S2:])
if cfg.H2.Contains(hdr) {
return true
}
}
// Cookie Reply: exact size S3+64, H3 at offset S3.
if size == cfg.S3+messageCookieReplySize && size >= cfg.S3+4 {
hdr := binary.LittleEndian.Uint32(pkt[cfg.S3:])
if cfg.H3.Contains(hdr) {
return true
}
}
// Transport: size >= S4+16, H4 at offset S4.
if size >= cfg.S4+messageTransportHeaderSize && size >= cfg.S4+4 {
hdr := binary.LittleEndian.Uint32(pkt[cfg.S4:])
if cfg.H4.Contains(hdr) {
return true
}
}
return false
}