Add flow tracking

This commit is contained in:
世界 2026-07-06 23:37:38 +08:00
parent ed63adda33
commit 14c8f75f7a
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
7 changed files with 240 additions and 39 deletions

43
flow.go
View file

@ -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