mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-03-25 23:30:41 +01:00
remove unused code.
This commit is contained in:
@@ -90,13 +90,15 @@ NEDNSSettings(servers: ["10.0.0.1"])
|
||||
includedRoutes = [NEIPv4Route.default()]
|
||||
|
||||
func protectSocket(_ fd: Int) throws {
|
||||
let index = Int32(if_nametoindex("en0"))
|
||||
setsockopt(Int32(fd), IPPROTO_IP, IP_BOUND_IF, &index, ...)
|
||||
// No action needed - iOS Network Extension sockets
|
||||
// automatically bypass VPN tunnel
|
||||
}
|
||||
|
||||
// DNS Proxy: 127.0.0.1:53
|
||||
```
|
||||
|
||||
**Note:** iOS Network Extensions run in separate process - sockets automatically bypass VPN.
|
||||
|
||||
## Protocol Support
|
||||
|
||||
| Protocol | Support |
|
||||
|
||||
@@ -29,7 +29,6 @@ type UDPForwarder struct {
|
||||
type udpConn struct {
|
||||
tunEP *gonet.UDPConn
|
||||
upstreamConn *net.UDPConn
|
||||
lastActivity time.Time
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
@@ -44,9 +43,6 @@ func NewUDPForwarder(s *stack.Stack, protectSocket func(fd int) error, ctx conte
|
||||
// Create gVisor UDP forwarder with handler callback
|
||||
f.forwarder = udp.NewForwarder(s, f.handlePacket)
|
||||
|
||||
// Start cleanup goroutine
|
||||
go f.cleanupStaleConnections()
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
@@ -85,7 +81,6 @@ func (f *UDPForwarder) handlePacket(req *udp.ForwarderRequest) {
|
||||
ctrld.ProxyLogger.Load().Debug().Msgf("[UDP] New session: %s:%d -> %s:%d (total: %d)",
|
||||
srcAddr, id.RemotePort, dstAddr, id.LocalPort, len(f.connections))
|
||||
}
|
||||
conn.lastActivity = time.Now()
|
||||
f.mu.Unlock()
|
||||
}
|
||||
|
||||
@@ -144,7 +139,6 @@ func (f *UDPForwarder) createConnection(req *udp.ForwarderRequest, connKey strin
|
||||
udpConnection := &udpConn{
|
||||
tunEP: tunConn,
|
||||
upstreamConn: upstreamConn,
|
||||
lastActivity: time.Now(),
|
||||
cancel: cancel,
|
||||
}
|
||||
|
||||
@@ -176,10 +170,6 @@ func (f *UDPForwarder) forwardTunToUpstream(conn *udpConn, ctx context.Context)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
f.mu.Lock()
|
||||
conn.lastActivity = time.Now()
|
||||
f.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,34 +209,6 @@ func (f *UDPForwarder) forwardUpstreamToTun(conn *udpConn, ctx context.Context,
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
f.mu.Lock()
|
||||
conn.lastActivity = time.Now()
|
||||
f.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (f *UDPForwarder) cleanupStaleConnections() {
|
||||
ticker := time.NewTicker(30 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-f.ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
f.mu.Lock()
|
||||
now := time.Now()
|
||||
for key, conn := range f.connections {
|
||||
if now.Sub(conn.lastActivity) > 60*time.Second {
|
||||
conn.cancel()
|
||||
conn.tunEP.Close()
|
||||
conn.upstreamConn.Close()
|
||||
delete(f.connections, key)
|
||||
}
|
||||
}
|
||||
f.mu.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user