mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-23 01:27:13 +02:00
remove unused code.
This commit is contained in:
@@ -90,13 +90,15 @@ NEDNSSettings(servers: ["10.0.0.1"])
|
|||||||
includedRoutes = [NEIPv4Route.default()]
|
includedRoutes = [NEIPv4Route.default()]
|
||||||
|
|
||||||
func protectSocket(_ fd: Int) throws {
|
func protectSocket(_ fd: Int) throws {
|
||||||
let index = Int32(if_nametoindex("en0"))
|
// No action needed - iOS Network Extension sockets
|
||||||
setsockopt(Int32(fd), IPPROTO_IP, IP_BOUND_IF, &index, ...)
|
// automatically bypass VPN tunnel
|
||||||
}
|
}
|
||||||
|
|
||||||
// DNS Proxy: 127.0.0.1:53
|
// DNS Proxy: 127.0.0.1:53
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Note:** iOS Network Extensions run in separate process - sockets automatically bypass VPN.
|
||||||
|
|
||||||
## Protocol Support
|
## Protocol Support
|
||||||
|
|
||||||
| Protocol | Support |
|
| Protocol | Support |
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ type UDPForwarder struct {
|
|||||||
type udpConn struct {
|
type udpConn struct {
|
||||||
tunEP *gonet.UDPConn
|
tunEP *gonet.UDPConn
|
||||||
upstreamConn *net.UDPConn
|
upstreamConn *net.UDPConn
|
||||||
lastActivity time.Time
|
|
||||||
cancel context.CancelFunc
|
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
|
// Create gVisor UDP forwarder with handler callback
|
||||||
f.forwarder = udp.NewForwarder(s, f.handlePacket)
|
f.forwarder = udp.NewForwarder(s, f.handlePacket)
|
||||||
|
|
||||||
// Start cleanup goroutine
|
|
||||||
go f.cleanupStaleConnections()
|
|
||||||
|
|
||||||
return f
|
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)",
|
ctrld.ProxyLogger.Load().Debug().Msgf("[UDP] New session: %s:%d -> %s:%d (total: %d)",
|
||||||
srcAddr, id.RemotePort, dstAddr, id.LocalPort, len(f.connections))
|
srcAddr, id.RemotePort, dstAddr, id.LocalPort, len(f.connections))
|
||||||
}
|
}
|
||||||
conn.lastActivity = time.Now()
|
|
||||||
f.mu.Unlock()
|
f.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +139,6 @@ func (f *UDPForwarder) createConnection(req *udp.ForwarderRequest, connKey strin
|
|||||||
udpConnection := &udpConn{
|
udpConnection := &udpConn{
|
||||||
tunEP: tunConn,
|
tunEP: tunConn,
|
||||||
upstreamConn: upstreamConn,
|
upstreamConn: upstreamConn,
|
||||||
lastActivity: time.Now(),
|
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,10 +170,6 @@ func (f *UDPForwarder) forwardTunToUpstream(conn *udpConn, ctx context.Context)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
return
|
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