103 lines
2.1 KiB
Go
103 lines
2.1 KiB
Go
package bcap
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type ParseErrorType int
|
|
|
|
const (
|
|
ErrTypeNone ParseErrorType = iota
|
|
ErrTypeLinkLayer
|
|
ErrTypeNetwork
|
|
ErrTypeTransport
|
|
ErrTypeUnsupported
|
|
)
|
|
|
|
type ParseError struct {
|
|
Type ParseErrorType
|
|
Layer string
|
|
Message string
|
|
Err error
|
|
}
|
|
|
|
func (e *ParseError) Error() string {
|
|
if e.Err != nil {
|
|
return fmt.Sprintf("[%s] %s: %v", e.Layer, e.Message, e.Err)
|
|
}
|
|
return fmt.Sprintf("[%s] %s", e.Layer, e.Message)
|
|
}
|
|
|
|
func NewParseError(errType ParseErrorType, layer, message string, err error) *ParseError {
|
|
return &ParseError{
|
|
Type: errType,
|
|
Layer: layer,
|
|
Message: message,
|
|
Err: err,
|
|
}
|
|
}
|
|
|
|
const (
|
|
StateUnknown uint8 = 0
|
|
StateTcpConnect1 uint8 = 1
|
|
StateTcpConnect2 uint8 = 2
|
|
StateTcpConnect3 uint8 = 3
|
|
StateTcpDisconnect1 uint8 = 4
|
|
StateTcpDisconnect2 uint8 = 5
|
|
StateTcpDisconnect23 uint8 = 6
|
|
StateTcpDisconnect3 uint8 = 7
|
|
StateTcpDisconnect4 uint8 = 8
|
|
StateTcpAckOk uint8 = 9
|
|
StateTcpRetransmit uint8 = 10
|
|
StateTcpEce uint8 = 11
|
|
StateTcpCwr uint8 = 12
|
|
StateTcpRst uint8 = 13
|
|
StateTcpKeepalive uint8 = 14
|
|
StateUdp uint8 = 20
|
|
StateIcmp uint8 = 30
|
|
StateIcmpv6 uint8 = 31
|
|
)
|
|
|
|
const (
|
|
DefaultConnectionTimeout = 5 * time.Minute
|
|
DefaultCleanupInterval = 1 * time.Minute
|
|
)
|
|
|
|
type PacketsConfig struct {
|
|
ConnectionTimeout time.Duration
|
|
CleanupInterval time.Duration
|
|
}
|
|
|
|
func DefaultConfig() *PacketsConfig {
|
|
return &PacketsConfig{
|
|
ConnectionTimeout: DefaultConnectionTimeout,
|
|
CleanupInterval: DefaultCleanupInterval,
|
|
}
|
|
}
|
|
|
|
type ErrorStats struct {
|
|
LinkLayerErrors uint64
|
|
NetworkErrors uint64
|
|
TransportErrors uint64
|
|
UnsupportedErrors uint64
|
|
TotalErrors uint64
|
|
}
|
|
|
|
type ConnectionStats struct {
|
|
ActiveConnections int64
|
|
TotalConnections uint64
|
|
ClosedConnections uint64
|
|
TimeoutConnections uint64
|
|
TcpConnections int64
|
|
UdpConnections int64
|
|
IcmpConnections int64
|
|
}
|
|
|
|
type Stats struct {
|
|
Errors ErrorStats
|
|
Connections ConnectionStats
|
|
StartTime time.Time
|
|
LastCleanup time.Time
|
|
}
|