Skip to content

intra/tcp.go: don't create TCP endpoint before Dial() returns #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: n2
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions intra/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,6 @@ func (h *tcpHandler) Proxy(gconn *netstack.GTCPConn, src, target netip.AddrPort)
return deny
}

// handshake; since we assume a duplex-stream from here on
if open, err = gconn.Establish(); !open {
log.E("tcp: %s connect err %v; %s => %s for %s", cid, err, src, target, uid)
clos(gconn)
h.queueSummary(smm.done(err))
return deny // == !open
}

if isAnyBasePid(pids) { // see udp.go:Connect
if h.dnsOverride(gconn, target, uid) {
// SocketSummary not sent; x.DNSSummary supercedes it
Expand Down Expand Up @@ -270,6 +262,11 @@ func (h *tcpHandler) handle(px ipn.Proxy, src net.Conn, boundSrc, target netip.A
return err
}

gconn := src.(*netstack.GTCPConn)
if open, err := gconn.Establish(); !open {
Copy link
Contributor

@ignoramous ignoramous Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check here should be err != nil.

- if open, err := gconn.Establish(); !open {
+ if _, err := gconn.Establish(); err != nil {
+     clos(pc)

Code is called in a loop, and so, subsequent Establish() will result in open==false (but err would be nil).

if g.ok() { // already setup
return false, nil // open, err free
}


Think I'll have to look more closely on what other changes might be needed to move Establish here.

What is the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this change?

To complete the experiment in commit b139771

I will play with this draft later.

return err
}

core.Go("tcp.forward."+smm.ID, func() {
h.forward(src, rwext{dst, tcptimeout}, smm) // src always *gonet.TCPConn
})
Expand Down
Loading