From 4f291fa513509ed7907f64e5eaba7058716a5950 Mon Sep 17 00:00:00 2001 From: x2c3z4 Date: Fri, 2 Sep 2022 16:59:00 +0800 Subject: [PATCH] Chore: show the source ip in log (#2284) Co-authored-by: Li Feng --- tunnel/tunnel.go | 50 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index f5d9ed2..0936056 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -233,9 +233,15 @@ func handleUDPConn(packet *inbound.PacketAdapter) { rawPc, err := proxy.ListenPacketContext(ctx, metadata.Pure()) if err != nil { if rule == nil { - log.Warnln("[UDP] dial %s to %s error: %s", proxy.Name(), metadata.RemoteAddress(), err.Error()) + log.Warnln( + "[UDP] dial %s %s --> %s error: %s", + proxy.Name(), + metadata.SourceAddress(), + metadata.RemoteAddress(), + err.Error(), + ) } else { - log.Warnln("[UDP] dial %s (match %s/%s) to %s error: %s", proxy.Name(), rule.RuleType().String(), rule.Payload(), metadata.RemoteAddress(), err.Error()) + log.Warnln("[UDP] dial %s (match %s/%s) %s --> %s error: %s", proxy.Name(), rule.RuleType().String(), rule.Payload(), metadata.SourceAddress(), metadata.RemoteAddress(), err.Error()) } return } @@ -244,13 +250,24 @@ func handleUDPConn(packet *inbound.PacketAdapter) { switch true { case rule != nil: - log.Infoln("[UDP] %s --> %s match %s(%s) using %s", metadata.SourceAddress(), metadata.RemoteAddress(), rule.RuleType().String(), rule.Payload(), rawPc.Chains().String()) + log.Infoln( + "[UDP] %s --> %s match %s(%s) using %s", + metadata.SourceAddress(), + metadata.RemoteAddress(), + rule.RuleType().String(), + rule.Payload(), + rawPc.Chains().String(), + ) case mode == Global: log.Infoln("[UDP] %s --> %s using GLOBAL", metadata.SourceAddress(), metadata.RemoteAddress()) case mode == Direct: log.Infoln("[UDP] %s --> %s using DIRECT", metadata.SourceAddress(), metadata.RemoteAddress()) default: - log.Infoln("[UDP] %s --> %s doesn't match any rule using DIRECT", metadata.SourceAddress(), metadata.RemoteAddress()) + log.Infoln( + "[UDP] %s --> %s doesn't match any rule using DIRECT", + metadata.SourceAddress(), + metadata.RemoteAddress(), + ) } oAddr, _ := netip.AddrFromSlice(metadata.DstIP) @@ -287,9 +304,15 @@ func handleTCPConn(connCtx C.ConnContext) { remoteConn, err := proxy.DialContext(ctx, metadata.Pure()) if err != nil { if rule == nil { - log.Warnln("[TCP] dial %s to %s error: %s", proxy.Name(), metadata.RemoteAddress(), err.Error()) + log.Warnln( + "[TCP] dial %s %s --> %s error: %s", + proxy.Name(), + metadata.SourceAddress(), + metadata.RemoteAddress(), + err.Error(), + ) } else { - log.Warnln("[TCP] dial %s (match %s/%s) to %s error: %s", proxy.Name(), rule.RuleType().String(), rule.Payload(), metadata.RemoteAddress(), err.Error()) + log.Warnln("[TCP] dial %s (match %s/%s) %s --> %s error: %s", proxy.Name(), rule.RuleType().String(), rule.Payload(), metadata.SourceAddress(), metadata.RemoteAddress(), err.Error()) } return } @@ -298,13 +321,24 @@ func handleTCPConn(connCtx C.ConnContext) { switch true { case rule != nil: - log.Infoln("[TCP] %s --> %s match %s(%s) using %s", metadata.SourceAddress(), metadata.RemoteAddress(), rule.RuleType().String(), rule.Payload(), remoteConn.Chains().String()) + log.Infoln( + "[TCP] %s --> %s match %s(%s) using %s", + metadata.SourceAddress(), + metadata.RemoteAddress(), + rule.RuleType().String(), + rule.Payload(), + remoteConn.Chains().String(), + ) case mode == Global: log.Infoln("[TCP] %s --> %s using GLOBAL", metadata.SourceAddress(), metadata.RemoteAddress()) case mode == Direct: log.Infoln("[TCP] %s --> %s using DIRECT", metadata.SourceAddress(), metadata.RemoteAddress()) default: - log.Infoln("[TCP] %s --> %s doesn't match any rule using DIRECT", metadata.SourceAddress(), metadata.RemoteAddress()) + log.Infoln( + "[TCP] %s --> %s doesn't match any rule using DIRECT", + metadata.SourceAddress(), + metadata.RemoteAddress(), + ) } handleSocket(connCtx, remoteConn)