Skip to content

Commit 0df1684

Browse files
committed
tcp,udp,icmp: verbose logs
1 parent 4715f9e commit 0df1684

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

intra/common.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,3 +701,10 @@ func logwif(cond bool) log.LogFn {
701701
}
702702
return log.VV
703703
}
704+
705+
func pidstr(p ipn.Proxy) string {
706+
if p == nil {
707+
return "nil"
708+
}
709+
return p.ID().V()
710+
}

intra/tcp.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (h *tcpHandler) Proxy(gconn *netstack.GTCPConn, src, target netip.AddrPort)
163163

164164
if h.status.Load() == HDLEND {
165165
err = errTcpEnd
166-
log.D("tcp: proxy: end %s => %s", src, target)
166+
log.D("tcp: proxy: %s end %s => %s [%v]", cid, src, target, actualTargets)
167167
clos(gconn)
168168
h.queueSummary(smm.done(err))
169169
return deny
@@ -201,10 +201,15 @@ func (h *tcpHandler) Proxy(gconn *netstack.GTCPConn, src, target netip.AddrPort)
201201
} // else not a dns request
202202
} // if ipn.Exit then let it connect as-is (aka exit)
203203

204+
log.VV("tcp: %s proxying %s => %s [%v] for %s; pids: %s",
205+
cid, src, target, actualTargets, uid, pids)
206+
204207
// pick all realips to connect to
205208
for i, dstipp := range actualTargets {
206209
var px ipn.Proxy = nil
207210
if px, err = h.prox.ProxyTo(dstipp, uid, pids); err != nil || px == nil {
211+
log.W("tcp: dial: #%d: %s proxy(%s) to dst(%s) for %s; err %v",
212+
i, cid, pidstr(px), dstipp, uid, err)
208213
continue
209214
}
210215

@@ -233,6 +238,9 @@ func (h *tcpHandler) handle(px ipn.Proxy, src net.Conn, boundSrc, target netip.A
233238

234239
start := time.Now()
235240

241+
log.VV("tcp: %s dial %s: attempt: %s [%s] => %s for %s",
242+
smm.ID, pidstr(px), src.LocalAddr(), boundSrc, target, smm.UID)
243+
236244
// github.com/google/gvisor/blob/5ba35f516b5c2/test/benchmarks/tcp/tcp_proxy.go#L359
237245
// ref: stackoverflow.com/questions/63656117
238246
// ref: stackoverflow.com/questions/40328025

intra/udp.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,16 @@ func (h *udpHandler) Connect(gconn *netstack.GUDPConn, src, target netip.AddrPor
261261
pids = []string{muxpid}
262262
} // else: mxr will dial this conn with a different pid
263263
}
264+
265+
log.VV("udp: connect: %s proxying %s => %s [%v] for %s; pids: %s, mux? %t",
266+
cid, src, target, actualTargets, uid, pids, mux)
267+
264268
// note: fake-dns-ips shouldn't be un-nated / un-alg'd
265269
for i, dstipp := range actualTargets {
266270
rttstart := time.Now()
267271

268272
if px, err = h.prox.ProxyTo(dstipp, uid, pids); err != nil || px == nil {
269-
log.W("udp: connect: %s failed to get proxy from %s: %v", cid, pids, err)
273+
log.W("udp: connect: #%d: %s failed to get proxy from %s: %v", i, cid, pidstr(px), err)
270274
errs = err // disconnect if loop terminates
271275
continue
272276
}
@@ -275,6 +279,10 @@ func (h *udpHandler) Connect(gconn *netstack.GUDPConn, src, target netip.AddrPor
275279
if mux { // mux is not supported by all proxies (few like Exit, Base, WG support it)
276280
pc, err = h.mux.associate(cid, pxid, uid, src, selectedTarget, px.Dialer().Announce, vendor(dmx))
277281
} else {
282+
283+
log.VV("udp: connect: #%d: attempt: %s proxy(%s) to dst(%s) for %s; mux? %t",
284+
i, cid, pxid, selectedTarget, uid, mux)
285+
278286
if settings.PortForward.Load() {
279287
boundSrc := makeAnyAddrPort(src)
280288
pc, err = px.Dialer().DialBind("udp", boundSrc.String(), selectedTarget.String())

0 commit comments

Comments
 (0)