package counters

import "sync"

// CounterType custom counter error type.
type CounterType int

//go:generate stringer -type=CounterType -trimprefix Err
// Error counters used in the enforcerd
const (
	ErrUnknownError CounterType = iota
	ErrNonPUTraffic
	ErrNoConnFound
	ErrRejectPacket
	ErrMarkNotFound
	ErrPortNotFound
	ErrContextIDNotFound
	ErrInvalidProtocol
	ErrConnectionsProcessed
	ErrEncrConnectionsProcessed
	ErrUDPDropFin
	ErrUDPSynDroppedInvalidToken
	ErrUDPSynAckInvalidToken
	ErrUDPAckInvalidToken
	ErrUDPConnectionsProcessed
	ErrUDPContextIDNotFound
	ErrUDPDropQueueFull
	ErrUDPDropInNfQueue
	ErrAppServicePreProcessorFailed
	ErrAppServicePostProcessorFailed
	ErrNetServicePreProcessorFailed
	ErrNetServicePostProcessorFailed
	ErrSynTokenFailed
	ErrSynDroppedInvalidToken
	ErrSynDroppedTCPOption
	ErrSynDroppedInvalidFormat
	ErrSynRejectPacket
	ErrSynUnexpectedPacket
	ErrInvalidNetSynState
	ErrNetSynNotSeen
	ErrSynToExtNetAccept
	ErrSynFromExtNetAccept
	ErrSynToExtNetReject
	ErrSynFromExtNetReject
	ErrSynAckTokenFailed
	ErrOutOfOrderSynAck
	ErrInvalidSynAck
	ErrSynAckInvalidToken
	ErrSynAckMissingToken
	ErrSynAckNoTCPAuthOption
	ErrSynAckInvalidFormat
	ErrSynAckEncryptionMismatch
	ErrSynAckRejected
	ErrSynAckToExtNetAccept
	ErrSynAckFromExtNetAccept
	ErrSynAckFromExtNetReject
	ErrAckTokenFailed
	ErrAckRejected
	ErrAckTCPNoTCPAuthOption //50
	ErrAckInvalidFormat
	ErrAckInvalidToken
	ErrAckInUnknownState
	ErrAckFromExtNetAccept
	ErrAckFromExtNetReject
	ErrUDPAppPreProcessingFailed
	ErrUDPAppPostProcessingFailed
	ErrUDPNetPreProcessingFailed
	ErrUDPNetPostProcessingFailed
	ErrUDPSynInvalidToken
	ErrUDPSynMissingClaims
	ErrUDPSynDroppedPolicy
	ErrUDPSynAckNoConnection
	ErrUDPSynAckPolicy
	ErrDroppedTCPPackets
	ErrDroppedUDPPackets
	ErrDroppedICMPPackets
	ErrDroppedDNSPackets
	ErrDroppedDHCPPackets
	ErrDroppedNTPPackets
	ErrTCPConnectionsExpired
	ErrUDPConnectionsExpired
	ErrSynTokenEncodeFailed
	ErrSynTokenHashFailed
	ErrSynTokenSignFailed
	ErrSynSharedSecretMissing
	ErrSynInvalidSecret
	ErrSynInvalidTokenLength
	ErrSynMissingSignature
	ErrSynInvalidSignature
	ErrSynCompressedTagMismatch
	ErrSynDatapathVersionMismatch
	ErrSynTokenDecodeFailed
	ErrSynTokenExpired
	ErrSynSharedKeyHashFailed
	ErrSynPublicKeyFailed
	ErrSynAckTokenEncodeFailed
	ErrSynAckTokenHashFailed
	ErrSynAckTokenSignFailed
	ErrSynAckSharedSecretMissing
	ErrSynAckInvalidSecret
	ErrSynAckInvalidTokenLength
	ErrSynAckMissingSignature
	ErrSynAckInvalidSignature
	ErrSynAckCompressedTagMismatch
	ErrSynAckDatapathVersionMismatch
	ErrSynAckTokenDecodeFailed
	ErrSynAckTokenExpired
	ErrSynAckSharedKeyHashFailed
	ErrSynAckPublicKeyFailed //100
	ErrAckTokenEncodeFailed
	ErrAckTokenHashFailed
	ErrAckTokenSignFailed
	ErrAckSharedSecretMissing
	ErrAckInvalidSecret
	ErrAckInvalidTokenLength
	ErrAckMissingSignature
	ErrAckCompressedTagMismatch
	ErrAckDatapathVersionMismatch
	ErrAckTokenDecodeFailed
	ErrAckTokenExpired
	ErrAckSignatureMismatch
	ErrUDPSynTokenFailed
	ErrUDPSynTokenEncodeFailed
	ErrUDPSynTokenHashFailed
	ErrUDPSynTokenSignFailed
	ErrUDPSynSharedSecretMissing
	ErrUDPSynInvalidSecret
	ErrUDPSynInvalidTokenLength
	ErrUDPSynMissingSignature
	ErrUDPSynInvalidSignature
	ErrUDPSynCompressedTagMismatch
	ErrUDPSynDatapathVersionMismatch
	ErrUDPSynTokenDecodeFailed
	ErrUDPSynTokenExpired
	ErrUDPSynSharedKeyHashFailed
	ErrUDPSynPublicKeyFailed
	ErrUDPSynAckTokenFailed
	ErrUDPSynAckTokenEncodeFailed
	ErrUDPSynAckTokenHashFailed
	ErrUDPSynAckTokenSignFailed
	ErrUDPSynAckSharedSecretMissing
	ErrUDPSynAckInvalidSecret
	ErrUDPSynAckInvalidTokenLength
	ErrUDPSynAckMissingSignature
	ErrUDPSynAckInvalidSignature
	ErrUDPSynAckCompressedTagMismatch
	ErrUDPSynAckDatapathVersionMismatch
	ErrUDPSynAckTokenDecodeFailed
	ErrUDPSynAckTokenExpired
	ErrUDPSynAckSharedKeyHashFailed
	ErrUDPSynAckPublicKeyFailed
	ErrUDPAckTokenFailed
	ErrUDPAckTokenEncodeFailed
	ErrUDPAckTokenHashFailed
	ErrUDPAckSharedSecretMissing
	ErrUDPAckInvalidSecret
	ErrUDPAckInvalidTokenLength
	ErrUDPAckMissingSignature
	ErrUDPAckCompressedTagMismatch //150
	ErrUDPAckDatapathVersionMismatch
	ErrUDPAckTokenDecodeFailed
	ErrUDPAckTokenExpired
	ErrUDPAckSignatureMismatch
	ErrAppSynAuthOptionSet
	ErrAckToFinAck
	ErrIgnoreFin
	ErrInvalidNetState
	ErrInvalidNetAckState
	ErrAppSynAckAuthOptionSet
	ErrDuplicateAckDrop
	ErrDNSForwardFailed
	ErrDNSResponseFailed
	ErrNfLogError
	ErrSegmentServerContainerEventExceedsProcessingTime
	ErrCorruptPacket
	ErrSynMissingTCPOption
	ErrUDPDropRst
	ErrNonPUUDPTraffic
	ErrIPTablesReset
	ErrDNSInvalidRequest
	// !!!! ADD NEW ERRORS ABOVE THIS LINE !!!!
	// errMax must be the last error counter defined.
	errMax
)

// Counters holds the counters value.
type Counters struct {
	sync.Mutex
	counters [errMax + 1]uint32
}
