MCPcopy
hub / github.com/windtf/wireproxy / lockNetwork

Function lockNetwork

cmd/wireproxy/main.go:135–155  ·  view source on GitHub ↗
(sections []wireproxy.RoutineSpawner, infoAddr *string)

Source from the content-addressed store, hash-verified

133}
134
135func lockNetwork(sections []wireproxy.RoutineSpawner, infoAddr *string) {
136 var rules []landlock.Rule
137 if infoAddr != nil && *infoAddr != "" {
138 rules = append(rules, landlock.BindTCP(extractPort(*infoAddr)))
139 }
140
141 for _, section := range sections {
142 switch section := section.(type) {
143 case *wireproxy.TCPServerTunnelConfig:
144 rules = append(rules, landlock.ConnectTCP(extractPort(section.Target)))
145 case *wireproxy.HTTPConfig:
146 rules = append(rules, landlock.BindTCP(extractPort(section.BindAddress)))
147 case *wireproxy.TCPClientTunnelConfig:
148 rules = append(rules, landlock.ConnectTCP(uint16(section.BindAddress.Port)))
149 case *wireproxy.Socks5Config:
150 rules = append(rules, landlock.BindTCP(extractPort(section.BindAddress)))
151 }
152 }
153
154 panicIfError(landlock.V4.BestEffort().RestrictNet(rules...))
155}
156
157func main() {
158 s := make(chan os.Signal, 1)

Callers 1

mainFunction · 0.85

Calls 2

extractPortFunction · 0.85
panicIfErrorFunction · 0.85

Tested by

no test coverage detected