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

Open
wants to merge 2 commits into
base: n2
Choose a base branch
from
Open
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
25 changes: 16 additions & 9 deletions intra/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,18 @@ 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) {
if target.IsValid() && h.resolver.IsDnsAddr(target) {
// SocketSummary not sent; x.DNSSummary supercedes it
if _, err := gconn.Establish(); err != nil {
clos(gconn)
h.queueSummary(smm.done(err))
return deny // == !open
}
// conn closed by the resolver
core.Gx(h.proto+".dns", func() {
h.resolver.Serve(h.proto, gconn, uid)
})
return allow
} // else not a dns request
} // if ipn.Exit then let it connect as-is (aka exit)
Expand Down Expand Up @@ -270,6 +271,12 @@ func (h *tcpHandler) handle(px ipn.Proxy, src net.Conn, boundSrc, target netip.A
return err
}

gconn := src.(*netstack.GTCPConn)
if _, err := gconn.Establish(); err != nil {
clos(pc)
return err
}

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