Add flow tracking
This commit is contained in:
parent
ed63adda33
commit
14c8f75f7a
7 changed files with 240 additions and 39 deletions
43
flow.go
43
flow.go
|
|
@ -6,6 +6,7 @@ type FlowVerdict struct {
|
|||
Action FlowAction
|
||||
Port Port
|
||||
Destination netip.AddrPort
|
||||
NewTracker func() FlowTracker
|
||||
}
|
||||
|
||||
type FlowAction uint8
|
||||
|
|
@ -18,6 +19,48 @@ const (
|
|||
ActionBypass
|
||||
)
|
||||
|
||||
type FlowTracker interface {
|
||||
AttachFlow(handle FlowHandle)
|
||||
CountForward(n int)
|
||||
CountReverse(n int)
|
||||
FlowEstablished()
|
||||
CloseFlow(reason FlowCloseReason)
|
||||
}
|
||||
|
||||
type FlowHandle interface {
|
||||
CloseFlow()
|
||||
}
|
||||
|
||||
type FlowCloseReason uint8
|
||||
|
||||
const (
|
||||
FlowCloseReset FlowCloseReason = iota
|
||||
FlowCloseFinished
|
||||
FlowCloseTimeout
|
||||
FlowCloseEvicted
|
||||
FlowCloseShutdown
|
||||
FlowCloseInterrupted
|
||||
)
|
||||
|
||||
func (r FlowCloseReason) String() string {
|
||||
switch r {
|
||||
case FlowCloseReset:
|
||||
return "connection reset"
|
||||
case FlowCloseFinished:
|
||||
return "finished"
|
||||
case FlowCloseTimeout:
|
||||
return "idle timeout"
|
||||
case FlowCloseEvicted:
|
||||
return "evicted"
|
||||
case FlowCloseShutdown:
|
||||
return "stack closed"
|
||||
case FlowCloseInterrupted:
|
||||
return "interrupted"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
type Port interface {
|
||||
PortAddresses() (v4 netip.Addr, v6 netip.Addr)
|
||||
PortMTU() uint32
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue