@@ -187,17 +187,16 @@ func (h *tcpHandler) Proxy(gconn *netstack.GTCPConn, src, target netip.AddrPort)
187
187
}
188
188
189
189
if isAnyBasePid (pids ) { // see udp.go:Connect
190
- if target .IsValid () && h .resolver .IsDnsAddr (target ) {
190
+ // handshake; since we assume a duplex-stream from here on
191
+ if _ , err := gconn .Establish (); err != nil {
192
+ log .E ("tcp: %s connect1 err %v; %s => %s for %s" , cid , err , src , target , uid )
193
+ clos (gconn )
194
+ h .queueSummary (smm .done (err ))
195
+ return deny // == !open
196
+ }
197
+ if h .dnsOverride (gconn , target , uid ) {
191
198
// SocketSummary not sent; x.DNSSummary supercedes it
192
- if _ , err := gconn .Establish (); err != nil {
193
- clos (gconn )
194
- h .queueSummary (smm .done (err ))
195
- return deny // == !open
196
- }
197
- // conn closed by the resolver
198
- core .Gx (h .proto + ".dns" , func () {
199
- h .resolver .Serve (h .proto , gconn , uid )
200
- })
199
+ // conn closed by resolver
201
200
return allow
202
201
} // else not a dns request
203
202
} // if ipn.Exit then let it connect as-is (aka exit)
@@ -240,7 +239,7 @@ func (h *tcpHandler) Proxy(gconn *netstack.GTCPConn, src, target netip.AddrPort)
240
239
}
241
240
242
241
// handle connects to the target via the proxy, and pipes data between the src, target; thread-safe.
243
- func (h * tcpHandler ) handle (px ipn.Proxy , src net. Conn , boundSrc , target netip.AddrPort , smm * SocketSummary ) (err error ) {
242
+ func (h * tcpHandler ) handle (px ipn.Proxy , src * netstack. GTCPConn , boundSrc , target netip.AddrPort , smm * SocketSummary ) (err error ) {
244
243
var pc protect.Conn
245
244
var dst net.Conn
246
245
@@ -283,15 +282,16 @@ func (h *tcpHandler) handle(px ipn.Proxy, src net.Conn, boundSrc, target netip.A
283
282
smm .RPID = ipn .ViaID (px )
284
283
285
284
if err != nil {
286
- clos (pc )
285
+ clos (src , pc )
287
286
log .W ("tcp: err dialing %s proxy(%s) to dst(%v) for %s: %v" ,
288
287
smm .ID , px .ID (), target , smm .UID , err )
289
288
return err
290
289
}
291
290
292
- gconn := src .(* netstack.GTCPConn )
293
- if _ , err := gconn .Establish (); err != nil {
294
- clos (pc )
291
+ if _ , err := src .Establish (); err != nil {
292
+ log .E ("tcp: %s connect2 err %v; %s => %s for %s" ,
293
+ smm .ID , err , src .LocalAddr (), target , smm .UID )
294
+ clos (src , pc )
295
295
return err
296
296
}
297
297
0 commit comments