add src field for logger and recorder
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -223,8 +222,9 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
|||||||
ro.Host = addr
|
ro.Host = addr
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"node": target.Name,
|
"node": target.Name,
|
||||||
"dst": fmt.Sprintf("%s/%s", addr, network),
|
"dst": addr,
|
||||||
|
"network": network,
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Debugf("%s >> %s", conn.RemoteAddr(), addr)
|
log.Debugf("%s >> %s", conn.RemoteAddr(), addr)
|
||||||
@@ -246,6 +246,10 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||||
xnet.Transport(conn, cc)
|
xnet.Transport(conn, cc)
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -233,8 +232,9 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
|||||||
ro.Host = target.Addr
|
ro.Host = target.Addr
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"node": target.Name,
|
"node": target.Name,
|
||||||
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
|
"dst": target.Addr,
|
||||||
|
"network": network,
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Debugf("%s >> %s", conn.RemoteAddr(), target.Addr)
|
log.Debugf("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||||
@@ -256,6 +256,10 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
|||||||
marker.Reset()
|
marker.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
cc = proxyproto.WrapClientConn(h.md.proxyProtocol, conn.RemoteAddr(), convertAddr(conn.LocalAddr()), cc)
|
cc = proxyproto.WrapClientConn(h.md.proxyProtocol, conn.RemoteAddr(), convertAddr(conn.LocalAddr()), cc)
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
|
|||||||
+10
-2
@@ -229,8 +229,9 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
|||||||
ro.Host = addr
|
ro.Host = addr
|
||||||
|
|
||||||
fields := map[string]any{
|
fields := map[string]any{
|
||||||
"dst": addr,
|
"dst": addr,
|
||||||
"host": addr,
|
"host": addr,
|
||||||
|
"network": network,
|
||||||
}
|
}
|
||||||
|
|
||||||
if u, _, _ := h.basicProxyAuth(req.Header.Get("Proxy-Authorization")); u != "" {
|
if u, _, _ := h.basicProxyAuth(req.Header.Get("Proxy-Authorization")); u != "" {
|
||||||
@@ -288,6 +289,9 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
|||||||
return errors.New("authentication failed")
|
return errors.New("authentication failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"clientID": clientID})
|
||||||
|
ro.ClientID = clientID
|
||||||
|
|
||||||
if resp.Header.Get("Proxy-Agent") == "" {
|
if resp.Header.Get("Proxy-Agent") == "" {
|
||||||
resp.Header.Set("Proxy-Agent", h.md.proxyAgent)
|
resp.Header.Set("Proxy-Agent", h.md.proxyAgent)
|
||||||
}
|
}
|
||||||
@@ -354,6 +358,10 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
resp.StatusCode = http.StatusOK
|
resp.StatusCode = http.StatusOK
|
||||||
resp.Status = "200 Connection established"
|
resp.Status = "200 Connection established"
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, ro *xrecorde
|
|||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
|
log.WithFields(map[string]any{"src": c.LocalAddr().String()})
|
||||||
|
ro.Src = c.LocalAddr().String()
|
||||||
|
|
||||||
pc, ok := c.(net.PacketConn)
|
pc, ok := c.(net.PacketConn)
|
||||||
if !ok {
|
if !ok {
|
||||||
err = errors.New("wrong connection type")
|
err = errors.New("wrong connection type")
|
||||||
|
|||||||
@@ -111,10 +111,11 @@ func (h *http2Handler) Handle(ctx context.Context, conn net.Conn, opts ...handle
|
|||||||
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
||||||
|
|
||||||
log := h.options.Logger.WithFields(map[string]any{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"sid": ctxvalue.SidFromContext(ctx),
|
"sid": ctxvalue.SidFromContext(ctx),
|
||||||
"client": ro.ClientIP,
|
"client": ro.ClientIP,
|
||||||
|
"network": ro.Network,
|
||||||
})
|
})
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -230,6 +231,10 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
|
|||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("authentication failed")
|
return errors.New("authentication failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"clientID": clientID})
|
||||||
|
ro.ClientID = clientID
|
||||||
|
|
||||||
ctx = ctxvalue.ContextWithClientID(ctx, ctxvalue.ClientID(clientID))
|
ctx = ctxvalue.ContextWithClientID(ctx, ctxvalue.ClientID(clientID))
|
||||||
|
|
||||||
if h.options.Bypass != nil && h.options.Bypass.Contains(ctx, "tcp", host) {
|
if h.options.Bypass != nil && h.options.Bypass.Contains(ctx, "tcp", host) {
|
||||||
@@ -261,6 +266,10 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
if req.Method == http.MethodConnect {
|
if req.Method == http.MethodConnect {
|
||||||
resp.StatusCode = http.StatusOK
|
resp.StatusCode = http.StatusOK
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package http3
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
@@ -58,9 +57,10 @@ func (h *http3Handler) Handle(ctx context.Context, conn net.Conn, opts ...handle
|
|||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log := h.options.Logger.WithFields(map[string]any{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"sid": ctxvalue.SidFromContext(ctx),
|
"sid": ctxvalue.SidFromContext(ctx),
|
||||||
|
"network": "udp",
|
||||||
})
|
})
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -124,7 +124,7 @@ func (h *http3Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
|
|||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", target.Addr, "tcp"),
|
"dst": target.Addr,
|
||||||
"host": target.Addr,
|
"host": target.Addr,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -17,10 +16,10 @@ import (
|
|||||||
xbypass "github.com/go-gost/x/bypass"
|
xbypass "github.com/go-gost/x/bypass"
|
||||||
ctxvalue "github.com/go-gost/x/ctx"
|
ctxvalue "github.com/go-gost/x/ctx"
|
||||||
xnet "github.com/go-gost/x/internal/net"
|
xnet "github.com/go-gost/x/internal/net"
|
||||||
xstats "github.com/go-gost/x/observer/stats"
|
|
||||||
"github.com/go-gost/x/internal/util/sniffing"
|
"github.com/go-gost/x/internal/util/sniffing"
|
||||||
tls_util "github.com/go-gost/x/internal/util/tls"
|
tls_util "github.com/go-gost/x/internal/util/tls"
|
||||||
rate_limiter "github.com/go-gost/x/limiter/rate"
|
rate_limiter "github.com/go-gost/x/limiter/rate"
|
||||||
|
xstats "github.com/go-gost/x/observer/stats"
|
||||||
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
||||||
xrecorder "github.com/go-gost/x/recorder"
|
xrecorder "github.com/go-gost/x/recorder"
|
||||||
"github.com/go-gost/x/registry"
|
"github.com/go-gost/x/registry"
|
||||||
@@ -85,9 +84,10 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
|||||||
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
||||||
|
|
||||||
log := h.options.Logger.WithFields(map[string]any{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"sid": ctxvalue.SidFromContext(ctx),
|
"sid": ctxvalue.SidFromContext(ctx),
|
||||||
|
"network": ro.Network,
|
||||||
})
|
})
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
|||||||
ro.Dst = dstAddr.String()
|
ro.Dst = dstAddr.String()
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", dstAddr, dstAddr.Network()),
|
"dst": dstAddr.String(),
|
||||||
"host": dstAddr.String(),
|
"host": dstAddr.String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -236,6 +236,10 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
||||||
xnet.Transport(conn, cc)
|
xnet.Transport(conn, cc)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package redirect
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -66,15 +65,17 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
|||||||
Service: h.options.Service,
|
Service: h.options.Service,
|
||||||
RemoteAddr: conn.RemoteAddr().String(),
|
RemoteAddr: conn.RemoteAddr().String(),
|
||||||
LocalAddr: conn.LocalAddr().String(),
|
LocalAddr: conn.LocalAddr().String(),
|
||||||
|
Network: "udp",
|
||||||
Time: start,
|
Time: start,
|
||||||
SID: string(ctxvalue.SidFromContext(ctx)),
|
SID: string(ctxvalue.SidFromContext(ctx)),
|
||||||
}
|
}
|
||||||
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
||||||
|
|
||||||
log := h.options.Logger.WithFields(map[string]any{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"sid": ctxvalue.SidFromContext(ctx),
|
"sid": ctxvalue.SidFromContext(ctx),
|
||||||
|
"network": ro.Network,
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
@@ -109,7 +110,7 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
|||||||
ro.Host = dstAddr.String()
|
ro.Host = dstAddr.String()
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", dstAddr, dstAddr.Network()),
|
"dst": dstAddr,
|
||||||
"host": dstAddr.String(),
|
"host": dstAddr.String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -130,6 +131,10 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
||||||
xnet.Transport(conn, cc)
|
xnet.Transport(conn, cc)
|
||||||
|
|||||||
+13
-10
@@ -20,12 +20,13 @@ import (
|
|||||||
traffic_wrapper "github.com/go-gost/x/limiter/traffic/wrapper"
|
traffic_wrapper "github.com/go-gost/x/limiter/traffic/wrapper"
|
||||||
metrics "github.com/go-gost/x/metrics/wrapper"
|
metrics "github.com/go-gost/x/metrics/wrapper"
|
||||||
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
||||||
|
xrecorder "github.com/go-gost/x/recorder"
|
||||||
xservice "github.com/go-gost/x/service"
|
xservice "github.com/go-gost/x/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *relayHandler) handleBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) error {
|
func (h *relayHandler) handleBind(ctx context.Context, conn net.Conn, network, address string, ro *xrecorder.HandlerRecorderObject, log logger.Logger) error {
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", address, network),
|
"dst": address,
|
||||||
"cmd": "bind",
|
"cmd": "bind",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -68,13 +69,13 @@ func (h *relayHandler) handleBind(ctx context.Context, conn net.Conn, network, a
|
|||||||
}
|
}
|
||||||
|
|
||||||
if network == "tcp" {
|
if network == "tcp" {
|
||||||
return h.bindTCP(ctx, conn, network, address, log)
|
return h.bindTCP(ctx, conn, network, address, ro, log)
|
||||||
} else {
|
} else {
|
||||||
return h.bindUDP(ctx, conn, network, address, log)
|
return h.bindUDP(ctx, conn, network, address, ro, log)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *relayHandler) bindTCP(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) error {
|
func (h *relayHandler) bindTCP(ctx context.Context, conn net.Conn, network, address string, ro *xrecorder.HandlerRecorderObject, log logger.Logger) error {
|
||||||
resp := relay.Response{
|
resp := relay.Response{
|
||||||
Version: relay.Version1,
|
Version: relay.Version1,
|
||||||
Status: relay.StatusOK,
|
Status: relay.StatusOK,
|
||||||
@@ -98,7 +99,9 @@ func (h *relayHandler) bindTCP(ctx context.Context, conn net.Conn, network, addr
|
|||||||
"listener": "tcp",
|
"listener": "tcp",
|
||||||
"handler": "ep-tcp",
|
"handler": "ep-tcp",
|
||||||
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
||||||
|
"src": ln.Addr().String(),
|
||||||
})
|
})
|
||||||
|
ro.Src = ln.Addr().String()
|
||||||
|
|
||||||
af := &relay.AddrFeature{}
|
af := &relay.AddrFeature{}
|
||||||
if err := af.ParseFrom(ln.Addr().String()); err != nil {
|
if err := af.ParseFrom(ln.Addr().String()); err != nil {
|
||||||
@@ -157,7 +160,7 @@ func (h *relayHandler) bindTCP(ctx context.Context, conn net.Conn, network, addr
|
|||||||
return srv.Serve()
|
return srv.Serve()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *relayHandler) bindUDP(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) error {
|
func (h *relayHandler) bindUDP(ctx context.Context, conn net.Conn, network, address string, ro *xrecorder.HandlerRecorderObject, log logger.Logger) error {
|
||||||
resp := relay.Response{
|
resp := relay.Response{
|
||||||
Version: relay.Version1,
|
Version: relay.Version1,
|
||||||
Status: relay.StatusOK,
|
Status: relay.StatusOK,
|
||||||
@@ -177,8 +180,11 @@ func (h *relayHandler) bindUDP(ctx context.Context, conn net.Conn, network, addr
|
|||||||
"service": serviceName,
|
"service": serviceName,
|
||||||
"listener": "udp",
|
"listener": "udp",
|
||||||
"handler": "ep-udp",
|
"handler": "ep-udp",
|
||||||
"bind": fmt.Sprintf("%s/%s", pc.LocalAddr(), pc.LocalAddr().Network()),
|
"bind": pc.LocalAddr().String(),
|
||||||
|
"src": pc.LocalAddr().String(),
|
||||||
})
|
})
|
||||||
|
ro.Src = pc.LocalAddr().String()
|
||||||
|
|
||||||
pc = metrics.WrapPacketConn(serviceName, pc)
|
pc = metrics.WrapPacketConn(serviceName, pc)
|
||||||
// pc = admission.WrapPacketConn(l.options.Admission, pc)
|
// pc = admission.WrapPacketConn(l.options.Admission, pc)
|
||||||
// pc = limiter.WrapPacketConn(l.options.TrafficLimiter, pc)
|
// pc = limiter.WrapPacketConn(l.options.TrafficLimiter, pc)
|
||||||
@@ -195,9 +201,6 @@ func (h *relayHandler) bindUDP(ctx context.Context, conn net.Conn, network, addr
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
|
||||||
"bind": pc.LocalAddr().String(),
|
|
||||||
})
|
|
||||||
log.Debugf("bind on %s OK", pc.LocalAddr())
|
log.Debugf("bind on %s OK", pc.LocalAddr())
|
||||||
|
|
||||||
r := udp.NewRelay(relay_util.UDPTunServerConn(conn), pc).
|
r := udp.NewRelay(relay_util.UDPTunServerConn(conn), pc).
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
@@ -33,7 +32,7 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network
|
|||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", address, network),
|
"dst": address,
|
||||||
"cmd": "connect",
|
"cmd": "connect",
|
||||||
"host": address,
|
"host": address,
|
||||||
})
|
})
|
||||||
@@ -114,6 +113,10 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
if h.md.noDelay {
|
if h.md.noDelay {
|
||||||
if _, err := resp.WriteTo(conn); err != nil {
|
if _, err := resp.WriteTo(conn); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package relay
|
package relay
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -15,9 +15,10 @@ import (
|
|||||||
xnet "github.com/go-gost/x/internal/net"
|
xnet "github.com/go-gost/x/internal/net"
|
||||||
"github.com/go-gost/x/limiter/traffic/wrapper"
|
"github.com/go-gost/x/limiter/traffic/wrapper"
|
||||||
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
||||||
|
xrecorder "github.com/go-gost/x/recorder"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network string, log logger.Logger) error {
|
func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network string, ro *xrecorder.HandlerRecorderObject, log logger.Logger) error {
|
||||||
resp := relay.Response{
|
resp := relay.Response{
|
||||||
Version: relay.Version1,
|
Version: relay.Version1,
|
||||||
Status: relay.StatusOK,
|
Status: relay.StatusOK,
|
||||||
@@ -32,7 +33,7 @@ func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network
|
|||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
|
"dst": target.Addr,
|
||||||
"cmd": "forward",
|
"cmd": "forward",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -61,7 +62,9 @@ func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network
|
|||||||
conn = xnet.NewReadWriteConn(rw, rw, conn)
|
conn = xnet.NewReadWriteConn(rw, rw, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
cc, err := h.options.Router.Dial(ctx, network, target.Addr)
|
var buf bytes.Buffer
|
||||||
|
cc, err := h.options.Router.Dial(ctxvalue.ContextWithBuffer(ctx, &buf), network, target.Addr)
|
||||||
|
ro.Route = buf.String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: the router itself may be failed due to the failed node in the router,
|
// TODO: the router itself may be failed due to the failed node in the router,
|
||||||
// the dead marker may be a wrong operation.
|
// the dead marker may be a wrong operation.
|
||||||
@@ -76,6 +79,11 @@ func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
if marker := target.Marker(); marker != nil {
|
if marker := target.Marker(); marker != nil {
|
||||||
marker.Reset()
|
marker.Reset()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,6 +208,8 @@ func (h *relayHandler) Handle(ctx context.Context, conn net.Conn, opts ...handle
|
|||||||
resp.WriteTo(conn)
|
resp.WriteTo(conn)
|
||||||
return ErrUnauthorized
|
return ErrUnauthorized
|
||||||
}
|
}
|
||||||
|
log = log.WithFields(map[string]any{"clientID": clientID})
|
||||||
|
ro.ClientID = clientID
|
||||||
ctx = ctxvalue.ContextWithClientID(ctx, ctxvalue.ClientID(clientID))
|
ctx = ctxvalue.ContextWithClientID(ctx, ctxvalue.ClientID(clientID))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,17 +219,18 @@ func (h *relayHandler) Handle(ctx context.Context, conn net.Conn, opts ...handle
|
|||||||
}
|
}
|
||||||
ro.Network = network
|
ro.Network = network
|
||||||
ro.Host = address
|
ro.Host = address
|
||||||
|
log = log.WithFields(map[string]any{"network": network})
|
||||||
|
|
||||||
if h.hop != nil {
|
if h.hop != nil {
|
||||||
// forward mode
|
// forward mode
|
||||||
return h.handleForward(ctx, conn, network, log)
|
return h.handleForward(ctx, conn, network, ro, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch req.Cmd & relay.CmdMask {
|
switch req.Cmd & relay.CmdMask {
|
||||||
case 0, relay.CmdConnect:
|
case 0, relay.CmdConnect:
|
||||||
return h.handleConnect(ctx, conn, network, address, ro, log)
|
return h.handleConnect(ctx, conn, network, address, ro, log)
|
||||||
case relay.CmdBind:
|
case relay.CmdBind:
|
||||||
return h.handleBind(ctx, conn, network, address, log)
|
return h.handleBind(ctx, conn, network, address, ro, log)
|
||||||
default:
|
default:
|
||||||
resp.Status = relay.StatusBadRequest
|
resp.Status = relay.StatusBadRequest
|
||||||
resp.WriteTo(conn)
|
resp.WriteTo(conn)
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ func (h *sniHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
|||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"sid": ctxvalue.SidFromContext(ctx),
|
"sid": ctxvalue.SidFromContext(ctx),
|
||||||
"client": ro.ClientIP,
|
"client": ro.ClientIP,
|
||||||
|
"network": ro.Network,
|
||||||
})
|
})
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
|
|
||||||
|
|||||||
@@ -121,10 +121,11 @@ func (h *socks4Handler) Handle(ctx context.Context, conn net.Conn, opts ...handl
|
|||||||
}
|
}
|
||||||
|
|
||||||
log := h.options.Logger.WithFields(map[string]any{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"sid": ctxvalue.SidFromContext(ctx),
|
"sid": ctxvalue.SidFromContext(ctx),
|
||||||
"client": ro.ClientIP,
|
"client": ro.ClientIP,
|
||||||
|
"network": ro.Network,
|
||||||
})
|
})
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
|
|
||||||
@@ -163,6 +164,11 @@ func (h *socks4Handler) Handle(ctx context.Context, conn net.Conn, opts ...handl
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if userid := string(req.Userid); userid != "" {
|
||||||
|
log = log.WithFields(map[string]any{"user": userid})
|
||||||
|
ro.ClientID = userid
|
||||||
|
}
|
||||||
|
|
||||||
ro.Host = req.Addr.String()
|
ro.Host = req.Addr.String()
|
||||||
log.Trace(req)
|
log.Trace(req)
|
||||||
|
|
||||||
@@ -177,6 +183,7 @@ func (h *socks4Handler) Handle(ctx context.Context, conn net.Conn, opts ...handl
|
|||||||
}
|
}
|
||||||
ctx = ctxvalue.ContextWithClientID(ctx, ctxvalue.ClientID(clientID))
|
ctx = ctxvalue.ContextWithClientID(ctx, ctxvalue.ClientID(clientID))
|
||||||
ro.ClientID = clientID
|
ro.ClientID = clientID
|
||||||
|
log = log.WithFields(map[string]any{"clientID": clientID})
|
||||||
}
|
}
|
||||||
|
|
||||||
switch req.Cmd {
|
switch req.Cmd {
|
||||||
@@ -254,6 +261,10 @@ func (h *socks4Handler) handleConnect(ctx context.Context, conn net.Conn, req *g
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
resp := gosocks4.NewReply(gosocks4.Granted, nil)
|
resp := gosocks4.NewReply(gosocks4.Granted, nil)
|
||||||
log.Trace(resp)
|
log.Trace(resp)
|
||||||
if err := resp.Write(conn); err != nil {
|
if err := resp.Write(conn); err != nil {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package v5
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -14,11 +13,12 @@ import (
|
|||||||
xnet "github.com/go-gost/x/internal/net"
|
xnet "github.com/go-gost/x/internal/net"
|
||||||
traffic_wrapper "github.com/go-gost/x/limiter/traffic/wrapper"
|
traffic_wrapper "github.com/go-gost/x/limiter/traffic/wrapper"
|
||||||
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
||||||
|
xrecorder "github.com/go-gost/x/recorder"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *socks5Handler) handleBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) error {
|
func (h *socks5Handler) handleBind(ctx context.Context, conn net.Conn, network, address string, ro *xrecorder.HandlerRecorderObject, log logger.Logger) error {
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", address, network),
|
"dst": address,
|
||||||
"cmd": "bind",
|
"cmd": "bind",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -56,10 +56,10 @@ func (h *socks5Handler) handleBind(ctx context.Context, conn net.Conn, network,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BIND does not support chain.
|
// BIND does not support chain.
|
||||||
return h.bindLocal(ctx, conn, network, address, log)
|
return h.bindLocal(ctx, conn, network, address, ro, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *socks5Handler) bindLocal(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) error {
|
func (h *socks5Handler) bindLocal(ctx context.Context, conn net.Conn, network, address string, ro *xrecorder.HandlerRecorderObject, log logger.Logger) error {
|
||||||
lc := xnet.ListenConfig{
|
lc := xnet.ListenConfig{
|
||||||
Netns: h.options.Netns,
|
Netns: h.options.Netns,
|
||||||
}
|
}
|
||||||
@@ -74,6 +74,12 @@ func (h *socks5Handler) bindLocal(ctx context.Context, conn net.Conn, network, a
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{
|
||||||
|
"src": ln.Addr().String(),
|
||||||
|
"bind": ln.Addr().String(),
|
||||||
|
})
|
||||||
|
ro.Src = ln.Addr().String()
|
||||||
|
|
||||||
socksAddr := gosocks5.Addr{}
|
socksAddr := gosocks5.Addr{}
|
||||||
if err := socksAddr.ParseFrom(ln.Addr().String()); err != nil {
|
if err := socksAddr.ParseFrom(ln.Addr().String()); err != nil {
|
||||||
log.Warn(err)
|
log.Warn(err)
|
||||||
@@ -90,10 +96,6 @@ func (h *socks5Handler) bindLocal(ctx context.Context, conn net.Conn, network, a
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
|
||||||
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
|
||||||
})
|
|
||||||
|
|
||||||
log.Debugf("bind on %s OK", ln.Addr())
|
log.Debugf("bind on %s OK", ln.Addr())
|
||||||
|
|
||||||
h.serveBind(ctx, conn, ln, log)
|
h.serveBind(ctx, conn, ln, log)
|
||||||
|
|||||||
@@ -76,6 +76,10 @@ func (h *socks5Handler) handleConnect(ctx context.Context, conn net.Conn, networ
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
resp := gosocks5.NewReply(gosocks5.Succeeded, nil)
|
resp := gosocks5.NewReply(gosocks5.Succeeded, nil)
|
||||||
log.Trace(resp)
|
log.Trace(resp)
|
||||||
if err := resp.Write(conn); err != nil {
|
if err := resp.Write(conn); err != nil {
|
||||||
|
|||||||
@@ -122,10 +122,11 @@ func (h *socks5Handler) Handle(ctx context.Context, conn net.Conn, opts ...handl
|
|||||||
}
|
}
|
||||||
|
|
||||||
log := h.options.Logger.WithFields(map[string]any{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"sid": ctxvalue.SidFromContext(ctx),
|
"sid": ctxvalue.SidFromContext(ctx),
|
||||||
"client": ro.ClientIP,
|
"client": ro.ClientIP,
|
||||||
|
"network": ro.Network,
|
||||||
})
|
})
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
|
|
||||||
@@ -166,7 +167,7 @@ func (h *socks5Handler) Handle(ctx context.Context, conn net.Conn, opts ...handl
|
|||||||
|
|
||||||
if clientID := sc.ID(); clientID != "" {
|
if clientID := sc.ID(); clientID != "" {
|
||||||
ctx = ctxvalue.ContextWithClientID(ctx, ctxvalue.ClientID(clientID))
|
ctx = ctxvalue.ContextWithClientID(ctx, ctxvalue.ClientID(clientID))
|
||||||
log = log.WithFields(map[string]any{"user": clientID})
|
log = log.WithFields(map[string]any{"user": clientID, "clientID": clientID})
|
||||||
ro.ClientID = clientID
|
ro.ClientID = clientID
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,9 +181,9 @@ func (h *socks5Handler) Handle(ctx context.Context, conn net.Conn, opts ...handl
|
|||||||
case gosocks5.CmdConnect:
|
case gosocks5.CmdConnect:
|
||||||
return h.handleConnect(ctx, conn, "tcp", address, ro, log)
|
return h.handleConnect(ctx, conn, "tcp", address, ro, log)
|
||||||
case gosocks5.CmdBind:
|
case gosocks5.CmdBind:
|
||||||
return h.handleBind(ctx, conn, "tcp", address, log)
|
return h.handleBind(ctx, conn, "tcp", address, ro, log)
|
||||||
case socks.CmdMuxBind:
|
case socks.CmdMuxBind:
|
||||||
return h.handleMuxBind(ctx, conn, "tcp", address, log)
|
return h.handleMuxBind(ctx, conn, "tcp", address, ro, log)
|
||||||
case gosocks5.CmdUdp:
|
case gosocks5.CmdUdp:
|
||||||
ro.Network = "udp"
|
ro.Network = "udp"
|
||||||
return h.handleUDP(ctx, conn, ro, log)
|
return h.handleUDP(ctx, conn, ro, log)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package v5
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -15,11 +14,12 @@ import (
|
|||||||
"github.com/go-gost/x/internal/util/mux"
|
"github.com/go-gost/x/internal/util/mux"
|
||||||
traffic_wrapper "github.com/go-gost/x/limiter/traffic/wrapper"
|
traffic_wrapper "github.com/go-gost/x/limiter/traffic/wrapper"
|
||||||
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
stats_wrapper "github.com/go-gost/x/observer/stats/wrapper"
|
||||||
|
xrecorder "github.com/go-gost/x/recorder"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *socks5Handler) handleMuxBind(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) error {
|
func (h *socks5Handler) handleMuxBind(ctx context.Context, conn net.Conn, network, address string, ro *xrecorder.HandlerRecorderObject, log logger.Logger) error {
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", address, network),
|
"dst": address,
|
||||||
"cmd": "mbind",
|
"cmd": "mbind",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -56,10 +56,10 @@ func (h *socks5Handler) handleMuxBind(ctx context.Context, conn net.Conn, networ
|
|||||||
conn = xnet.NewReadWriteConn(rw, rw, conn)
|
conn = xnet.NewReadWriteConn(rw, rw, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
return h.muxBindLocal(ctx, conn, network, address, log)
|
return h.muxBindLocal(ctx, conn, network, address, ro, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *socks5Handler) muxBindLocal(ctx context.Context, conn net.Conn, network, address string, log logger.Logger) error {
|
func (h *socks5Handler) muxBindLocal(ctx context.Context, conn net.Conn, network, address string, ro *xrecorder.HandlerRecorderObject, log logger.Logger) error {
|
||||||
lc := xnet.ListenConfig{
|
lc := xnet.ListenConfig{
|
||||||
Netns: h.options.Netns,
|
Netns: h.options.Netns,
|
||||||
}
|
}
|
||||||
@@ -74,6 +74,12 @@ func (h *socks5Handler) muxBindLocal(ctx context.Context, conn net.Conn, network
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{
|
||||||
|
"src": ln.Addr().String(),
|
||||||
|
"bind": ln.Addr().String(),
|
||||||
|
})
|
||||||
|
|
||||||
|
ro.Src = ln.Addr().String()
|
||||||
socksAddr := gosocks5.Addr{}
|
socksAddr := gosocks5.Addr{}
|
||||||
err = socksAddr.ParseFrom(ln.Addr().String())
|
err = socksAddr.ParseFrom(ln.Addr().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -91,10 +97,6 @@ func (h *socks5Handler) muxBindLocal(ctx context.Context, conn net.Conn, network
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
|
||||||
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
|
||||||
})
|
|
||||||
|
|
||||||
log.Debugf("bind on %s OK", ln.Addr())
|
log.Debugf("bind on %s OK", ln.Addr())
|
||||||
|
|
||||||
return h.serveMuxBind(ctx, conn, ln, log)
|
return h.serveMuxBind(ctx, conn, ln, log)
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
@@ -49,6 +48,12 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, ro *xrecor
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{
|
||||||
|
"src": cc.LocalAddr().String(),
|
||||||
|
"bind": cc.LocalAddr().String(),
|
||||||
|
})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
|
||||||
saddr := gosocks5.Addr{}
|
saddr := gosocks5.Addr{}
|
||||||
saddr.ParseFrom(cc.LocalAddr().String())
|
saddr.ParseFrom(cc.LocalAddr().String())
|
||||||
reply := gosocks5.NewReply(gosocks5.Succeeded, &saddr)
|
reply := gosocks5.NewReply(gosocks5.Succeeded, &saddr)
|
||||||
@@ -58,9 +63,6 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, ro *xrecor
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
|
||||||
"bind": fmt.Sprintf("%s/%s", cc.LocalAddr(), cc.LocalAddr().Network()),
|
|
||||||
})
|
|
||||||
log.Debugf("bind on %s OK", cc.LocalAddr())
|
log.Debugf("bind on %s OK", cc.LocalAddr())
|
||||||
|
|
||||||
// obtain a udp connection
|
// obtain a udp connection
|
||||||
|
|||||||
@@ -102,9 +102,16 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
|
|||||||
reply.Write(conn)
|
reply.Write(conn)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
defer pc.Close()
|
defer pc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{
|
||||||
|
"src": pc.LocalAddr().String(),
|
||||||
|
"bind": pc.LocalAddr().String(),
|
||||||
|
})
|
||||||
|
ro.Src = pc.LocalAddr().String()
|
||||||
|
|
||||||
saddr := gosocks5.Addr{}
|
saddr := gosocks5.Addr{}
|
||||||
saddr.ParseFrom(pc.LocalAddr().String())
|
saddr.ParseFrom(pc.LocalAddr().String())
|
||||||
reply := gosocks5.NewReply(gosocks5.Succeeded, &saddr)
|
reply := gosocks5.NewReply(gosocks5.Succeeded, &saddr)
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.H
|
|||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"sid": ctxvalue.SidFromContext(ctx),
|
"sid": ctxvalue.SidFromContext(ctx),
|
||||||
"client": ro.ClientIP,
|
"client": ro.ClientIP,
|
||||||
|
"network": ro.Network,
|
||||||
})
|
})
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
|
|
||||||
@@ -173,6 +174,10 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.H
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
if h.md.sniffing {
|
if h.md.sniffing {
|
||||||
if h.md.sniffingTimeout > 0 {
|
if h.md.sniffingTimeout > 0 {
|
||||||
conn.SetReadDeadline(time.Now().Add(h.md.sniffingTimeout))
|
conn.SetReadDeadline(time.Now().Add(h.md.sniffingTimeout))
|
||||||
|
|||||||
@@ -82,9 +82,11 @@ func (h *ssuHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
|||||||
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
||||||
|
|
||||||
log := h.options.Logger.WithFields(map[string]any{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"sid": ctxvalue.SidFromContext(ctx),
|
"sid": ctxvalue.SidFromContext(ctx),
|
||||||
|
"client": ro.ClientIP,
|
||||||
|
"network": ro.Network,
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
|
|||||||
+14
-5
@@ -93,9 +93,11 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
|||||||
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
||||||
|
|
||||||
log := h.options.Logger.WithFields(map[string]any{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"sid": ctxvalue.SidFromContext(ctx),
|
"sid": ctxvalue.SidFromContext(ctx),
|
||||||
|
"client": ro.ClientIP,
|
||||||
|
"network": ro.Network,
|
||||||
})
|
})
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
|
|
||||||
@@ -161,6 +163,10 @@ func (h *forwardHandler) handleDirectForward(ctx context.Context, conn *sshd_uti
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
if h.md.sniffing {
|
if h.md.sniffing {
|
||||||
if h.md.sniffingTimeout > 0 {
|
if h.md.sniffingTimeout > 0 {
|
||||||
conn.SetReadDeadline(time.Now().Add(h.md.sniffingTimeout))
|
conn.SetReadDeadline(time.Now().Add(h.md.sniffingTimeout))
|
||||||
@@ -235,7 +241,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
|
|||||||
ro.Host = addr
|
ro.Host = addr
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"dst": fmt.Sprintf("%s/%s", addr, network),
|
"dst": addr,
|
||||||
"cmd": "bind",
|
"cmd": "bind",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -251,8 +257,11 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
|
|||||||
defer ln.Close()
|
defer ln.Close()
|
||||||
|
|
||||||
log = log.WithFields(map[string]any{
|
log = log.WithFields(map[string]any{
|
||||||
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
"src": ln.Addr().String(),
|
||||||
|
"bind": ln.Addr().String(),
|
||||||
})
|
})
|
||||||
|
ro.Src = ln.Addr().String()
|
||||||
|
|
||||||
log.Debugf("bind on %s OK", ln.Addr())
|
log.Debugf("bind on %s OK", ln.Addr())
|
||||||
|
|
||||||
err = func() error {
|
err = func() error {
|
||||||
|
|||||||
@@ -90,9 +90,11 @@ func (h *unixHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler
|
|||||||
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
ro.ClientIP, _, _ = net.SplitHostPort(conn.RemoteAddr().String())
|
||||||
|
|
||||||
log := h.options.Logger.WithFields(map[string]any{
|
log := h.options.Logger.WithFields(map[string]any{
|
||||||
"remote": conn.RemoteAddr().String(),
|
"remote": conn.RemoteAddr().String(),
|
||||||
"local": conn.LocalAddr().String(),
|
"local": conn.LocalAddr().String(),
|
||||||
"sid": ctxvalue.SidFromContext(ctx),
|
"sid": ctxvalue.SidFromContext(ctx),
|
||||||
|
"client": ro.ClientIP,
|
||||||
|
"network": ro.Network,
|
||||||
})
|
})
|
||||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
|
|
||||||
|
|||||||
@@ -175,9 +175,12 @@ func (h *Sniffer) HandleHTTP(ctx context.Context, conn net.Conn, opts ...HandleO
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
ho.Log = ho.Log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
log := ho.Log
|
log := ho.Log
|
||||||
log.Debugf("connected to node %s(%s)", node.Name, node.Addr)
|
log.Debugf("connected to node %s(%s)", node.Name, node.Addr)
|
||||||
|
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
ro.Time = time.Time{}
|
ro.Time = time.Time{}
|
||||||
|
|
||||||
shouldClose, err := h.httpRoundTrip(ctx, xio.NewReadWriter(br, conn), cc, node, req, &pStats, &ho)
|
shouldClose, err := h.httpRoundTrip(ctx, xio.NewReadWriter(br, conn), cc, node, req, &pStats, &ho)
|
||||||
@@ -330,7 +333,11 @@ func (h *Sniffer) serveH2(ctx context.Context, conn net.Conn, ho *HandleOptions)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ho.Log.Debugf("connected to node %s(%s)", node.Name, node.Addr)
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
log.Debugf("connected to node %s(%s)", node.Name, node.Addr)
|
||||||
return cc, nil
|
return cc, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -798,9 +805,12 @@ func (h *Sniffer) HandleTLS(ctx context.Context, conn net.Conn, opts ...HandleOp
|
|||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
ho.Node = node
|
ho.Node = node
|
||||||
|
|
||||||
log := ho.Log
|
log := ho.Log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
log.Debugf("connected to node %s(%s)", node.Name, node.Addr)
|
log.Debugf("connected to node %s(%s)", node.Name, node.Addr)
|
||||||
|
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
if h.Certificate != nil && h.PrivateKey != nil &&
|
if h.Certificate != nil && h.PrivateKey != nil &&
|
||||||
len(clientHello.SupportedProtos) > 0 && (clientHello.SupportedProtos[0] == "h2" || clientHello.SupportedProtos[0] == "http/1.1") {
|
len(clientHello.SupportedProtos) > 0 && (clientHello.SupportedProtos[0] == "h2" || clientHello.SupportedProtos[0] == "http/1.1") {
|
||||||
if host == "" {
|
if host == "" {
|
||||||
|
|||||||
@@ -186,6 +186,10 @@ func (h *Sniffer) HandleHTTP(ctx context.Context, conn net.Conn, opts ...HandleO
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
ro.Time = time.Time{}
|
ro.Time = time.Time{}
|
||||||
|
|
||||||
shouldClose, err := h.httpRoundTrip(ctx, xio.NewReadWriter(br, conn), cc, req, ro, &pStats, log)
|
shouldClose, err := h.httpRoundTrip(ctx, xio.NewReadWriter(br, conn), cc, req, ro, &pStats, log)
|
||||||
@@ -243,6 +247,10 @@ func (h *Sniffer) serveH2(ctx context.Context, conn net.Conn, ho *HandleOptions)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
cc = tls.Client(cc, cfg)
|
cc = tls.Client(cc, cfg)
|
||||||
return cc, nil
|
return cc, nil
|
||||||
},
|
},
|
||||||
@@ -603,6 +611,10 @@ func (h *Sniffer) HandleTLS(ctx context.Context, conn net.Conn, opts ...HandleOp
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
|
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
|
||||||
|
ro.Src = cc.LocalAddr().String()
|
||||||
|
ro.Dst = cc.RemoteAddr().String()
|
||||||
|
|
||||||
if h.Certificate != nil && h.PrivateKey != nil &&
|
if h.Certificate != nil && h.PrivateKey != nil &&
|
||||||
len(clientHello.SupportedProtos) > 0 && (clientHello.SupportedProtos[0] == "h2" || clientHello.SupportedProtos[0] == "http/1.1") {
|
len(clientHello.SupportedProtos) > 0 && (clientHello.SupportedProtos[0] == "h2" || clientHello.SupportedProtos[0] == "http/1.1") {
|
||||||
if host == "" {
|
if host == "" {
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ type HandlerRecorderObject struct {
|
|||||||
RemoteAddr string `json:"remote"`
|
RemoteAddr string `json:"remote"`
|
||||||
LocalAddr string `json:"local"`
|
LocalAddr string `json:"local"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
|
Src string `json:"src"`
|
||||||
Dst string `json:"dst"`
|
Dst string `json:"dst"`
|
||||||
Proto string `json:"proto,omitempty"`
|
Proto string `json:"proto,omitempty"`
|
||||||
ClientIP string `json:"clientIP"`
|
ClientIP string `json:"clientIP"`
|
||||||
|
|||||||
Reference in New Issue
Block a user