Repository navigation
Expand file tree
/
Copy pathflow.go
More file actions
104 lines (88 loc) · 1.82 KB
/
Copy pathflow.go
File metadata and controls
104 lines (88 loc) · 1.82 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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 SelectorRange struct {
Start uint16
Count uint16
}
type PortWithSelectorRange interface {
PortSelectorRanges(protocol uint8) []SelectorRange
ExpandSelectorRanges(protocol uint8) bool
}
type PortWithSelectorReservation interface {
ReserveSelector(protocol uint8, address netip.AddrPort) bool
ReleaseSelector(protocol uint8, address netip.AddrPort)
}
type PortWithUpstream interface {
UpstreamPort() any
}
func portCapability[T any](port any) (T, bool) {
for port != nil {
capability, matched := port.(T)
if matched {
return capability, true
}
wrapper, isWrapper := port.(PortWithUpstream)
if !isWrapper {
break
}
port = wrapper.UpstreamPort()
}
var zero T
return zero, false
}
type Return interface {
ReturnHeadroom() int
ReturnPackets(packets [][]byte) [][]byte
}