forked from SagerNet/sing-tun
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflow.go
More file actions
74 lines (62 loc) · 1.21 KB
/
Copy pathflow.go
File metadata and controls
74 lines (62 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package tun
import (
"net/netip"
"time"
)
type FlowVerdict struct {
Action FlowAction
Port Port
Destination netip.AddrPort
UDPTimeout time.Duration
NewTracker func() FlowTracker
}
type FlowAction uint8
const (
ActionAccept FlowAction = iota
ActionFlow
ActionReject
ActionDrop
ActionBypass
ActionHijackDNS
)
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
)
func (r FlowCloseReason) String() string {
switch r {
case FlowCloseFinished:
return "finished"
case FlowCloseTimeout:
return "idle timeout"
default:
return "connection reset"
}
}
type Port interface {
PortAddresses() (v4 netip.Addr, v6 netip.Addr)
PortMTU() uint32
AttachReturn(returnPath Return) error
DetachReturn(returnPath Return) error
WritePackets(packets [][]byte) error
}
type PortWithSelectorRange interface {
Port
PortSelectorRange() (start uint16, count uint16)
}
type Return interface {
ReturnHeadroom() int
ReturnPackets(packets [][]byte) [][]byte
}