more fine-grained log level
This commit is contained in:
parent
052b8e9468
commit
f3f3acd4e1
@ -126,7 +126,7 @@ func (p *admission) periodReload(ctx context.Context) error {
|
||||
p.options.logger.Warnf("reload: %v", err)
|
||||
// return err
|
||||
}
|
||||
p.options.logger.Debugf("admission reload done")
|
||||
p.options.logger.Debug("admission reload done")
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func (p *authenticator) periodReload(ctx context.Context) error {
|
||||
p.options.logger.Warnf("reload: %v", err)
|
||||
// return err
|
||||
}
|
||||
p.options.logger.Debugf("auther reload done")
|
||||
p.options.logger.Debug("auther reload done")
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ func (bp *bypass) periodReload(ctx context.Context) error {
|
||||
bp.options.logger.Warnf("reload: %v", err)
|
||||
// return err
|
||||
}
|
||||
bp.options.logger.Debugf("bypass reload done")
|
||||
bp.options.logger.Debug("bypass reload done")
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func (c *forwardConnector) Connect(ctx context.Context, conn net.Conn, network,
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("connect %s/%s", address, network)
|
||||
log.Debugf("connect %s/%s", address, network)
|
||||
|
||||
return conn, nil
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, add
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("connect %s/%s", address, network)
|
||||
log.Debugf("connect %s/%s", address, network)
|
||||
|
||||
req := &http.Request{
|
||||
Method: http.MethodConnect,
|
||||
@ -87,9 +87,9 @@ func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, add
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(req, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
if c.md.connectTimeout > 0 {
|
||||
@ -111,9 +111,9 @@ func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, add
|
||||
// in this case, close body will be blocked, so we leave it untouched.
|
||||
// defer resp.Body.Close()
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
@ -49,7 +49,7 @@ func (c *http2Connector) Connect(ctx context.Context, conn net.Conn, network, ad
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("connect %s/%s", address, network)
|
||||
log.Debugf("connect %s/%s", address, network)
|
||||
|
||||
v, _ := conn.(md.Metadatable)
|
||||
if v == nil {
|
||||
@ -80,9 +80,9 @@ func (c *http2Connector) Connect(ctx context.Context, conn net.Conn, network, ad
|
||||
"Basic "+base64.StdEncoding.EncodeToString([]byte(u+":"+p)))
|
||||
}
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(req, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
if c.md.connectTimeout > 0 {
|
||||
@ -98,9 +98,9 @@ func (c *http2Connector) Connect(ctx context.Context, conn net.Conn, network, ad
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
resp.Body.Close()
|
||||
|
@ -20,7 +20,7 @@ func (c *relayConnector) Bind(ctx context.Context, conn net.Conn, network, addre
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("bind on %s/%s", address, network)
|
||||
log.Debugf("bind on %s/%s", address, network)
|
||||
|
||||
options := connector.BindOptions{}
|
||||
for _, opt := range opts {
|
||||
|
@ -44,7 +44,7 @@ func (c *relayConnector) Connect(ctx context.Context, conn net.Conn, network, ad
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("connect %s/%s", address, network)
|
||||
log.Debugf("connect %s/%s", address, network)
|
||||
|
||||
if c.md.connectTimeout > 0 {
|
||||
conn.SetDeadline(time.Now().Add(c.md.connectTimeout))
|
||||
|
@ -40,7 +40,7 @@ func (c *sniConnector) Connect(ctx context.Context, conn net.Conn, network, addr
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("connect %s/%s", address, network)
|
||||
log.Debugf("connect %s/%s", address, network)
|
||||
|
||||
return &sniClientConn{Conn: conn, host: c.md.host}, nil
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func (c *socks4Connector) Connect(ctx context.Context, conn net.Conn, network, a
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("connect %s/%s", address, network)
|
||||
log.Debugf("connect %s/%s", address, network)
|
||||
|
||||
switch network {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
@ -100,18 +100,18 @@ func (c *socks4Connector) Connect(ctx context.Context, conn net.Conn, network, a
|
||||
userid = []byte(c.options.Auth.Username())
|
||||
}
|
||||
req := gosocks4.NewRequest(gosocks4.CmdConnect, addr, userid)
|
||||
log.Trace(req)
|
||||
if err := req.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(req)
|
||||
|
||||
reply, err := gosocks4.ReadReply(conn)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(reply)
|
||||
log.Trace(reply)
|
||||
|
||||
if reply.Code != gosocks4.Granted {
|
||||
err = errors.New("host unreachable")
|
||||
|
@ -21,7 +21,7 @@ func (c *socks5Connector) Bind(ctx context.Context, conn net.Conn, network, addr
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("bind on %s/%s", address, network)
|
||||
log.Debugf("bind on %s/%s", address, network)
|
||||
|
||||
options := connector.BindOptions{}
|
||||
for _, opt := range opts {
|
||||
@ -98,18 +98,17 @@ func (l *socks5Connector) bind(conn net.Conn, cmd uint8, network, address string
|
||||
addr := gosocks5.Addr{}
|
||||
addr.ParseFrom(address)
|
||||
req := gosocks5.NewRequest(cmd, &addr)
|
||||
log.Trace(req)
|
||||
if err := req.Write(conn); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(req)
|
||||
|
||||
// first reply, bind status
|
||||
reply, err := gosocks5.ReadReply(conn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debug(reply)
|
||||
log.Trace(reply)
|
||||
|
||||
if reply.Rep != gosocks5.Succeeded {
|
||||
return nil, fmt.Errorf("bind on %s/%s failed", address, network)
|
||||
|
@ -93,7 +93,7 @@ func (c *socks5Connector) Connect(ctx context.Context, conn net.Conn, network, a
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("connect %s/%s", address, network)
|
||||
log.Debugf("connect %s/%s", address, network)
|
||||
|
||||
if c.md.connectTimeout > 0 {
|
||||
conn.SetDeadline(time.Now().Add(c.md.connectTimeout))
|
||||
@ -122,18 +122,18 @@ func (c *socks5Connector) Connect(ctx context.Context, conn net.Conn, network, a
|
||||
}
|
||||
|
||||
req := gosocks5.NewRequest(gosocks5.CmdConnect, &addr)
|
||||
log.Trace(req)
|
||||
if err := req.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(req)
|
||||
|
||||
reply, err := gosocks5.ReadReply(conn)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(reply)
|
||||
log.Trace(reply)
|
||||
|
||||
if reply.Rep != gosocks5.Succeeded {
|
||||
err = errors.New("host unreachable")
|
||||
@ -156,18 +156,18 @@ func (c *socks5Connector) connectUDP(ctx context.Context, conn net.Conn, network
|
||||
}
|
||||
|
||||
req := gosocks5.NewRequest(socks.CmdUDPTun, nil)
|
||||
log.Trace(req)
|
||||
if err := req.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(req)
|
||||
|
||||
reply, err := gosocks5.ReadReply(conn)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(reply)
|
||||
log.Trace(reply)
|
||||
|
||||
if reply.Rep != gosocks5.Succeeded {
|
||||
return nil, errors.New("get socks5 UDP tunnel failure")
|
||||
@ -178,18 +178,18 @@ func (c *socks5Connector) connectUDP(ctx context.Context, conn net.Conn, network
|
||||
|
||||
func (c *socks5Connector) relayUDP(ctx context.Context, conn net.Conn, addr net.Addr, log logger.Logger) (net.Conn, error) {
|
||||
req := gosocks5.NewRequest(gosocks5.CmdUdp, nil)
|
||||
log.Trace(req)
|
||||
if err := req.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(req)
|
||||
|
||||
reply, err := gosocks5.ReadReply(conn)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(reply)
|
||||
log.Trace(reply)
|
||||
|
||||
if reply.Rep != gosocks5.Succeeded {
|
||||
return nil, errors.New("get socks5 UDP tunnel failure")
|
||||
|
@ -21,7 +21,7 @@ func (p *tcpListener) Accept() (net.Conn, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.logger.Debug(rep)
|
||||
p.logger.Trace(rep)
|
||||
|
||||
if rep.Rep != gosocks5.Succeeded {
|
||||
return nil, fmt.Errorf("peer connect failed")
|
||||
@ -74,7 +74,7 @@ func (p *tcpMuxListener) getPeerConn(conn net.Conn) (net.Conn, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.logger.Debug(rep)
|
||||
p.logger.Trace(rep)
|
||||
|
||||
if rep.Rep != gosocks5.Succeeded {
|
||||
err = fmt.Errorf("peer connect failed")
|
||||
|
@ -49,18 +49,18 @@ func (s *clientSelector) OnSelected(method uint8, conn net.Conn) (net.Conn, erro
|
||||
}
|
||||
|
||||
req := gosocks5.NewUserPassRequest(gosocks5.UserPassVer, username, password)
|
||||
s.logger.Trace(req)
|
||||
if err := req.Write(conn); err != nil {
|
||||
s.logger.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
s.logger.Debug(req)
|
||||
|
||||
resp, err := gosocks5.ReadUserPassResponse(conn)
|
||||
if err != nil {
|
||||
s.logger.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
s.logger.Debug(resp)
|
||||
s.logger.Trace(resp)
|
||||
|
||||
if resp.Status != gosocks5.Succeeded {
|
||||
return nil, gosocks5.ErrAuthFailure
|
||||
|
@ -57,7 +57,7 @@ func (c *ssConnector) Connect(ctx context.Context, conn net.Conn, network, addre
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("connect %s/%s", address, network)
|
||||
log.Debugf("connect %s/%s", address, network)
|
||||
|
||||
switch network {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
|
@ -56,7 +56,7 @@ func (c *ssuConnector) Connect(ctx context.Context, conn net.Conn, network, addr
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("connect %s/%s", address, network)
|
||||
log.Debugf("connect %s/%s", address, network)
|
||||
|
||||
switch network {
|
||||
case "udp", "udp4", "udp6":
|
||||
|
@ -41,7 +41,7 @@ func (c *sshdConnector) Connect(ctx context.Context, conn net.Conn, network, add
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("connect %s/%s", address, network)
|
||||
log.Debugf("connect %s/%s", address, network)
|
||||
|
||||
cc, ok := conn.(*ssh_util.ClientConn)
|
||||
if !ok {
|
||||
@ -65,7 +65,7 @@ func (c *sshdConnector) Bind(ctx context.Context, conn net.Conn, network, addres
|
||||
"network": network,
|
||||
"address": address,
|
||||
})
|
||||
log.Infof("bind on %s/%s", address, network)
|
||||
log.Debugf("bind on %s/%s", address, network)
|
||||
|
||||
cc, ok := conn.(*ssh_util.ClientConn)
|
||||
if !ok {
|
||||
|
@ -143,9 +143,9 @@ func (d *h2Dialer) Dial(ctx context.Context, address string, opts ...dialer.Dial
|
||||
req.URL.Path = d.md.path
|
||||
}
|
||||
|
||||
if d.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if d.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(req, false)
|
||||
d.logger.Debug(string(dump))
|
||||
d.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
@ -153,9 +153,9 @@ func (d *h2Dialer) Dial(ctx context.Context, address string, opts ...dialer.Dial
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if d.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if d.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
d.logger.Debug(string(dump))
|
||||
d.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
@ -65,9 +65,9 @@ func (c *obfsHTTPConn) handshake() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if c.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
c.logger.Debug(string(dump))
|
||||
c.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -109,8 +109,8 @@ func (c *obfsHTTPConn) drainHeader() (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
if c.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
c.logger.Debug(buf.String())
|
||||
if c.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
c.logger.Trace(buf.String())
|
||||
}
|
||||
|
||||
// cache the extra data for next read.
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-gost/core/handler"
|
||||
"github.com/go-gost/core/logger"
|
||||
md "github.com/go-gost/core/metadata"
|
||||
"github.com/go-gost/gosocks4"
|
||||
"github.com/go-gost/gosocks5"
|
||||
@ -37,17 +38,17 @@ func NewHandler(opts ...handler.Option) handler.Handler {
|
||||
|
||||
if f := registry.HandlerRegistry().Get("http"); f != nil {
|
||||
v := append(opts,
|
||||
handler.LoggerOption(options.Logger.WithFields(map[string]any{"type": "http"})))
|
||||
handler.LoggerOption(options.Logger.WithFields(map[string]any{"handler": "http"})))
|
||||
h.httpHandler = f(v...)
|
||||
}
|
||||
if f := registry.HandlerRegistry().Get("socks4"); f != nil {
|
||||
v := append(opts,
|
||||
handler.LoggerOption(options.Logger.WithFields(map[string]any{"type": "socks4"})))
|
||||
handler.LoggerOption(options.Logger.WithFields(map[string]any{"handler": "socks4"})))
|
||||
h.socks4Handler = f(v...)
|
||||
}
|
||||
if f := registry.HandlerRegistry().Get("socks5"); f != nil {
|
||||
v := append(opts,
|
||||
handler.LoggerOption(options.Logger.WithFields(map[string]any{"type": "socks5"})))
|
||||
handler.LoggerOption(options.Logger.WithFields(map[string]any{"handler": "socks5"})))
|
||||
h.socks5Handler = f(v...)
|
||||
}
|
||||
|
||||
@ -80,13 +81,15 @@ func (h *autoHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler
|
||||
"local": conn.LocalAddr().String(),
|
||||
})
|
||||
|
||||
start := time.Now()
|
||||
log.Infof("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||
defer func() {
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(start),
|
||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||
}()
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
start := time.Now()
|
||||
log.Debugf("%s <> %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||
defer func() {
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(start),
|
||||
}).Debugf("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||
}()
|
||||
}
|
||||
|
||||
br := bufio.NewReader(conn)
|
||||
b, err := br.Peek(1)
|
||||
|
@ -149,16 +149,16 @@ func (h *dnsHandler) exchange(ctx context.Context, msg []byte, log logger.Logger
|
||||
|
||||
resolver_util.AddSubnetOpt(&mq, h.md.clientIP)
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
log.Debug(mq.String())
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
log.Trace(mq.String())
|
||||
}
|
||||
|
||||
var mr *dns.Msg
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
defer func() {
|
||||
if mr != nil {
|
||||
log.Debug(mr.String())
|
||||
log.Trace(mr.String())
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
||||
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
|
||||
})
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
|
||||
cc, err := h.router.Dial(ctx, network, target.Addr)
|
||||
if err != nil {
|
||||
@ -107,11 +107,11 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
||||
target.Marker.Reset()
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||
netpkg.Transport(conn, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
||||
"dst": fmt.Sprintf("%s/%s", target.Addr, network),
|
||||
})
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
|
||||
cc, err := h.router.Dial(ctx, network, target.Addr)
|
||||
if err != nil {
|
||||
@ -101,11 +101,11 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
||||
target.Marker.Reset()
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||
netpkg.Transport(conn, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -122,11 +122,11 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
||||
}
|
||||
log = log.WithFields(fields)
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(req, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), addr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), addr)
|
||||
|
||||
resp := &http.Response{
|
||||
ProtoMajor: 1,
|
||||
@ -140,11 +140,11 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(addr) {
|
||||
resp.StatusCode = http.StatusForbidden
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
log.Info("bypass: ", addr)
|
||||
log.Debug("bypass: ", addr)
|
||||
|
||||
return resp.Write(conn)
|
||||
}
|
||||
@ -161,9 +161,9 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
||||
(req.Method != http.MethodConnect && req.URL.Scheme != "http") {
|
||||
resp.StatusCode = http.StatusBadRequest
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
return resp.Write(conn)
|
||||
@ -175,9 +175,9 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
||||
if err != nil {
|
||||
resp.StatusCode = http.StatusServiceUnavailable
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
resp.Write(conn)
|
||||
return err
|
||||
@ -188,9 +188,9 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
||||
resp.StatusCode = http.StatusOK
|
||||
resp.Status = "200 Connection established"
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
if err = resp.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
@ -205,11 +205,11 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), addr)
|
||||
netpkg.Transport(conn, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(start),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), addr)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -318,7 +318,7 @@ func (h *httpHandler) authenticate(conn net.Conn, req *http.Request, resp *http.
|
||||
resp.Header.Add("Proxy-Connection", "close")
|
||||
}
|
||||
|
||||
log.Info("proxy authentication required")
|
||||
log.Debug("proxy authentication required")
|
||||
} else {
|
||||
resp.Header.Set("Server", "nginx/1.20.1")
|
||||
resp.Header.Set("Date", time.Now().Format(http.TimeFormat))
|
||||
@ -327,9 +327,9 @@ func (h *httpHandler) authenticate(conn net.Conn, req *http.Request, resp *http.
|
||||
}
|
||||
}
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
resp.Write(conn)
|
||||
|
@ -30,9 +30,9 @@ func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, log logger.L
|
||||
if !h.md.enableUDP {
|
||||
resp.StatusCode = http.StatusForbidden
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
log.Error("http: UDP relay is disabled")
|
||||
@ -41,9 +41,9 @@ func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, log logger.L
|
||||
}
|
||||
|
||||
resp.StatusCode = http.StatusOK
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
if err := resp.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
|
@ -122,11 +122,11 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
|
||||
}
|
||||
log = log.WithFields(fields)
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(req, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
log.Infof("%s >> %s", req.RemoteAddr, addr)
|
||||
log.Debugf("%s >> %s", req.RemoteAddr, addr)
|
||||
|
||||
for k := range h.md.header {
|
||||
w.Header().Set(k, h.md.header.Get(k))
|
||||
@ -134,7 +134,7 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(addr) {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
log.Info("bypass: ", addr)
|
||||
log.Debug("bypass: ", addr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -179,21 +179,21 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
|
||||
defer conn.Close()
|
||||
|
||||
start := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), addr)
|
||||
netpkg.Transport(conn, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(start),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), addr)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
log.Infof("%s <-> %s", req.RemoteAddr, addr)
|
||||
log.Debugf("%s <-> %s", req.RemoteAddr, addr)
|
||||
netpkg.Transport(&readWriter{r: req.Body, w: flushWriter{w}}, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(start),
|
||||
}).Infof("%s >-< %s", req.RemoteAddr, addr)
|
||||
}).Debugf("%s >-< %s", req.RemoteAddr, addr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -302,7 +302,7 @@ func (h *http2Handler) authenticate(w http.ResponseWriter, r *http.Request, resp
|
||||
resp.Header.Add("Proxy-Connection", "close")
|
||||
}
|
||||
|
||||
log.Info("proxy authentication required")
|
||||
log.Debug("proxy authentication required")
|
||||
} else {
|
||||
resp.Header = http.Header{}
|
||||
resp.Header.Set("Server", "nginx/1.20.1")
|
||||
@ -312,9 +312,9 @@ func (h *http2Handler) authenticate(w http.ResponseWriter, r *http.Request, resp
|
||||
}
|
||||
}
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
h.writeResponse(w, resp)
|
||||
|
@ -117,10 +117,10 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), dstAddr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), dstAddr)
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(dstAddr.String()) {
|
||||
log.Info("bypass: ", dstAddr)
|
||||
log.Debug("bypass: ", dstAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -132,11 +132,11 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
||||
defer cc.Close()
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
||||
netpkg.Transport(rw, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), dstAddr)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), dstAddr)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -147,9 +147,9 @@ func (h *redirectHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, radd
|
||||
return err
|
||||
}
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(req, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
host := req.Host
|
||||
@ -161,7 +161,7 @@ func (h *redirectHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, radd
|
||||
})
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(host) {
|
||||
log.Info("bypass: ", host)
|
||||
log.Debug("bypass: ", host)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -173,11 +173,11 @@ func (h *redirectHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, radd
|
||||
defer cc.Close()
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", raddr, host)
|
||||
log.Debugf("%s <-> %s", raddr, host)
|
||||
defer func() {
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", raddr, host)
|
||||
}).Debugf("%s >-< %s", raddr, host)
|
||||
}()
|
||||
|
||||
if err := req.Write(cc); err != nil {
|
||||
@ -192,9 +192,9 @@ func (h *redirectHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, radd
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
return resp.Write(rw)
|
||||
@ -224,7 +224,7 @@ func (h *redirectHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, rad
|
||||
})
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(host) {
|
||||
log.Info("bypass: ", host)
|
||||
log.Debug("bypass: ", host)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -236,14 +236,14 @@ func (h *redirectHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, rad
|
||||
defer cc.Close()
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", raddr, host)
|
||||
log.Debugf("%s <-> %s", raddr, host)
|
||||
netpkg.Transport(&readWriter{
|
||||
Reader: io.MultiReader(buf, rw),
|
||||
Writer: rw,
|
||||
}, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", raddr, host)
|
||||
}).Debugf("%s >-< %s", raddr, host)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -69,10 +69,10 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
||||
"dst": fmt.Sprintf("%s/%s", dstAddr, dstAddr.Network()),
|
||||
})
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), dstAddr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), dstAddr)
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(dstAddr.String()) {
|
||||
log.Info("bypass: ", dstAddr)
|
||||
log.Debug("bypass: ", dstAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -84,11 +84,11 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
||||
defer cc.Close()
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
||||
netpkg.Transport(conn, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), dstAddr)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), dstAddr)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ func (h *relayHandler) handleBind(ctx context.Context, conn net.Conn, network, a
|
||||
"cmd": "bind",
|
||||
})
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), address)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), address)
|
||||
|
||||
resp := relay.Response{
|
||||
Version: relay.Version1,
|
||||
@ -119,11 +119,11 @@ func (h *relayHandler) bindUDP(ctx context.Context, conn net.Conn, network, addr
|
||||
r.SetBufferSize(h.md.udpBufferSize)
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||
r.Run()
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -184,10 +184,10 @@ func (h *relayHandler) serveTCPBind(ctx context.Context, conn net.Conn, ln net.L
|
||||
}
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", c.LocalAddr(), c.RemoteAddr())
|
||||
log.Debugf("%s <-> %s", c.LocalAddr(), c.RemoteAddr())
|
||||
netpkg.Transport(sc, c)
|
||||
log.WithFields(map[string]any{"duration": time.Since(t)}).
|
||||
Infof("%s >-< %s", c.LocalAddr(), c.RemoteAddr())
|
||||
Debugf("%s >-< %s", c.LocalAddr(), c.RemoteAddr())
|
||||
}(rc)
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network
|
||||
"cmd": "connect",
|
||||
})
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), address)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), address)
|
||||
|
||||
resp := relay.Response{
|
||||
Version: relay.Version1,
|
||||
@ -34,7 +34,7 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network
|
||||
}
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(address) {
|
||||
log.Info("bypass: ", address)
|
||||
log.Debug("bypass: ", address)
|
||||
resp.Status = relay.StatusForbidden
|
||||
_, err := resp.WriteTo(conn)
|
||||
return err
|
||||
@ -81,11 +81,11 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network
|
||||
}
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), address)
|
||||
netpkg.Transport(conn, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), address)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), address)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network
|
||||
"cmd": "forward",
|
||||
})
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
|
||||
cc, err := h.router.Dial(ctx, network, target.Addr)
|
||||
if err != nil {
|
||||
@ -81,11 +81,11 @@ func (h *relayHandler) handleForward(ctx context.Context, conn net.Conn, network
|
||||
}
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||
netpkg.Transport(conn, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -99,9 +99,9 @@ func (h *sniHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, raddr net
|
||||
return err
|
||||
}
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(req, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
host := req.Host
|
||||
@ -113,7 +113,7 @@ func (h *sniHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, raddr net
|
||||
})
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(host) {
|
||||
log.Info("bypass: ", host)
|
||||
log.Debug("bypass: ", host)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -125,11 +125,11 @@ func (h *sniHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, raddr net
|
||||
defer cc.Close()
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", raddr, host)
|
||||
log.Debugf("%s <-> %s", raddr, host)
|
||||
defer func() {
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", raddr, host)
|
||||
}).Debugf("%s >-< %s", raddr, host)
|
||||
}()
|
||||
|
||||
if err := req.Write(cc); err != nil {
|
||||
@ -144,9 +144,9 @@ func (h *sniHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, raddr net
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if log.IsLevelEnabled(logger.DebugLevel) {
|
||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
return resp.Write(rw)
|
||||
@ -168,10 +168,10 @@ func (h *sniHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, raddr ne
|
||||
log = log.WithFields(map[string]any{
|
||||
"dst": host,
|
||||
})
|
||||
log.Infof("%s >> %s", raddr, host)
|
||||
log.Debugf("%s >> %s", raddr, host)
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(host) {
|
||||
log.Info("bypass: ", host)
|
||||
log.Debug("bypass: ", host)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -183,14 +183,14 @@ func (h *sniHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, raddr ne
|
||||
defer cc.Close()
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", raddr, host)
|
||||
log.Debugf("%s <-> %s", raddr, host)
|
||||
netpkg.Transport(&readWriter{
|
||||
Reader: io.MultiReader(buf, rw),
|
||||
Writer: rw,
|
||||
}, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", raddr, host)
|
||||
}).Debugf("%s >-< %s", raddr, host)
|
||||
|
||||
return nil
|
||||
|
||||
|
@ -81,14 +81,14 @@ func (h *socks4Handler) Handle(ctx context.Context, conn net.Conn, opts ...handl
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
log.Debug(req)
|
||||
log.Trace(req)
|
||||
|
||||
conn.SetReadDeadline(time.Time{})
|
||||
|
||||
if h.options.Auther != nil &&
|
||||
!h.options.Auther.Authenticate(string(req.Userid), "") {
|
||||
resp := gosocks4.NewReply(gosocks4.RejectedUserid, nil)
|
||||
log.Debug(resp)
|
||||
log.Trace(resp)
|
||||
return resp.Write(conn)
|
||||
}
|
||||
|
||||
@ -110,38 +110,38 @@ func (h *socks4Handler) handleConnect(ctx context.Context, conn net.Conn, req *g
|
||||
log = log.WithFields(map[string]any{
|
||||
"dst": addr,
|
||||
})
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), addr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), addr)
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(addr) {
|
||||
resp := gosocks4.NewReply(gosocks4.Rejected, nil)
|
||||
log.Debug(resp)
|
||||
log.Info("bypass: ", addr)
|
||||
log.Trace(resp)
|
||||
log.Debug("bypass: ", addr)
|
||||
return resp.Write(conn)
|
||||
}
|
||||
|
||||
cc, err := h.router.Dial(ctx, "tcp", addr)
|
||||
if err != nil {
|
||||
resp := gosocks4.NewReply(gosocks4.Failed, nil)
|
||||
log.Trace(resp)
|
||||
resp.Write(conn)
|
||||
log.Debug(resp)
|
||||
return err
|
||||
}
|
||||
|
||||
defer cc.Close()
|
||||
|
||||
resp := gosocks4.NewReply(gosocks4.Granted, nil)
|
||||
log.Trace(resp)
|
||||
if err := resp.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
log.Debug(resp)
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), addr)
|
||||
netpkg.Transport(conn, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), addr)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ func (h *socks5Handler) handleBind(ctx context.Context, conn net.Conn, network,
|
||||
"cmd": "bind",
|
||||
})
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), address)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), address)
|
||||
|
||||
if !h.md.enableBind {
|
||||
reply := gosocks5.NewReply(gosocks5.NotAllowed, nil)
|
||||
log.Debug(reply)
|
||||
log.Trace(reply)
|
||||
log.Error("socks5: BIND is disabled")
|
||||
return reply.Write(conn)
|
||||
}
|
||||
@ -51,12 +51,12 @@ func (h *socks5Handler) bindLocal(ctx context.Context, conn net.Conn, network, a
|
||||
socksAddr.Host, _, _ = net.SplitHostPort(conn.LocalAddr().String())
|
||||
socksAddr.Type = 0
|
||||
reply := gosocks5.NewReply(gosocks5.Succeeded, &socksAddr)
|
||||
log.Trace(reply)
|
||||
if err := reply.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
ln.Close()
|
||||
return err
|
||||
}
|
||||
log.Debug(reply)
|
||||
|
||||
log = log.WithFields(map[string]any{
|
||||
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
||||
@ -109,10 +109,10 @@ func (h *socks5Handler) serveBind(ctx context.Context, conn net.Conn, ln net.Lis
|
||||
log.Error(err)
|
||||
|
||||
reply := gosocks5.NewReply(gosocks5.Failure, nil)
|
||||
log.Trace(reply)
|
||||
if err := reply.Write(pc2); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
log.Debug(reply)
|
||||
|
||||
return
|
||||
}
|
||||
@ -128,16 +128,16 @@ func (h *socks5Handler) serveBind(ctx context.Context, conn net.Conn, ln net.Lis
|
||||
raddr := gosocks5.Addr{}
|
||||
raddr.ParseFrom(rc.RemoteAddr().String())
|
||||
reply := gosocks5.NewReply(gosocks5.Succeeded, &raddr)
|
||||
log.Trace(reply)
|
||||
if err := reply.Write(pc2); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
log.Debug(reply)
|
||||
|
||||
start := time.Now()
|
||||
log.Infof("%s <-> %s", rc.LocalAddr(), rc.RemoteAddr())
|
||||
log.Debugf("%s <-> %s", rc.LocalAddr(), rc.RemoteAddr())
|
||||
netpkg.Transport(pc2, rc)
|
||||
log.WithFields(map[string]any{"duration": time.Since(start)}).
|
||||
Infof("%s >-< %s", rc.LocalAddr(), rc.RemoteAddr())
|
||||
Debugf("%s >-< %s", rc.LocalAddr(), rc.RemoteAddr())
|
||||
|
||||
case err := <-pipe():
|
||||
if err != nil {
|
||||
|
@ -16,19 +16,19 @@ func (h *socks5Handler) handleConnect(ctx context.Context, conn net.Conn, networ
|
||||
"dst": fmt.Sprintf("%s/%s", address, network),
|
||||
"cmd": "connect",
|
||||
})
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), address)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), address)
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(address) {
|
||||
resp := gosocks5.NewReply(gosocks5.NotAllowed, nil)
|
||||
log.Debug(resp)
|
||||
log.Info("bypass: ", address)
|
||||
log.Trace(resp)
|
||||
log.Debug("bypass: ", address)
|
||||
return resp.Write(conn)
|
||||
}
|
||||
|
||||
cc, err := h.router.Dial(ctx, network, address)
|
||||
if err != nil {
|
||||
resp := gosocks5.NewReply(gosocks5.NetUnreachable, nil)
|
||||
log.Debug(resp)
|
||||
log.Trace(resp)
|
||||
resp.Write(conn)
|
||||
return err
|
||||
}
|
||||
@ -36,18 +36,18 @@ func (h *socks5Handler) handleConnect(ctx context.Context, conn net.Conn, networ
|
||||
defer cc.Close()
|
||||
|
||||
resp := gosocks5.NewReply(gosocks5.Succeeded, nil)
|
||||
log.Trace(resp)
|
||||
if err := resp.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
log.Debug(resp)
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), address)
|
||||
netpkg.Transport(conn, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), address)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), address)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func (h *socks5Handler) Handle(ctx context.Context, conn net.Conn, opts ...handl
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
log.Debug(req)
|
||||
log.Trace(req)
|
||||
conn.SetReadDeadline(time.Time{})
|
||||
|
||||
address := req.Addr.String()
|
||||
@ -108,8 +108,8 @@ func (h *socks5Handler) Handle(ctx context.Context, conn net.Conn, opts ...handl
|
||||
err = ErrUnknownCmd
|
||||
log.Error(err)
|
||||
resp := gosocks5.NewReply(gosocks5.CmdUnsupported, nil)
|
||||
log.Trace(resp)
|
||||
resp.Write(conn)
|
||||
log.Debug(resp)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,11 @@ func (h *socks5Handler) handleMuxBind(ctx context.Context, conn net.Conn, networ
|
||||
"cmd": "mbind",
|
||||
})
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), address)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), address)
|
||||
|
||||
if !h.md.enableBind {
|
||||
reply := gosocks5.NewReply(gosocks5.NotAllowed, nil)
|
||||
log.Debug(reply)
|
||||
log.Trace(reply)
|
||||
log.Error("socks5: BIND is disabled")
|
||||
return reply.Write(conn)
|
||||
}
|
||||
@ -35,10 +35,10 @@ func (h *socks5Handler) muxBindLocal(ctx context.Context, conn net.Conn, network
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
reply := gosocks5.NewReply(gosocks5.Failure, nil)
|
||||
log.Trace(reply)
|
||||
if err := reply.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
log.Debug(reply)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -52,12 +52,12 @@ func (h *socks5Handler) muxBindLocal(ctx context.Context, conn net.Conn, network
|
||||
socksAddr.Host, _, _ = net.SplitHostPort(conn.LocalAddr().String())
|
||||
socksAddr.Type = 0
|
||||
reply := gosocks5.NewReply(gosocks5.Succeeded, &socksAddr)
|
||||
log.Trace(reply)
|
||||
if err := reply.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
ln.Close()
|
||||
return err
|
||||
}
|
||||
log.Debug(reply)
|
||||
|
||||
log = log.WithFields(map[string]any{
|
||||
"bind": fmt.Sprintf("%s/%s", ln.Addr(), ln.Addr().Network()),
|
||||
@ -116,18 +116,18 @@ func (h *socks5Handler) serveMuxBind(ctx context.Context, conn net.Conn, ln net.
|
||||
addr := gosocks5.Addr{}
|
||||
addr.ParseFrom(c.RemoteAddr().String())
|
||||
reply := gosocks5.NewReply(gosocks5.Succeeded, &addr)
|
||||
log.Trace(reply)
|
||||
if err := reply.Write(sc); err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
log.Debug(reply)
|
||||
}
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", c.LocalAddr(), c.RemoteAddr())
|
||||
log.Debugf("%s <-> %s", c.LocalAddr(), c.RemoteAddr())
|
||||
netpkg.Transport(sc, c)
|
||||
log.WithFields(map[string]any{"duration": time.Since(t)}).
|
||||
Infof("%s >-< %s", c.LocalAddr(), c.RemoteAddr())
|
||||
Debugf("%s >-< %s", c.LocalAddr(), c.RemoteAddr())
|
||||
}(rc)
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func (s *serverSelector) OnSelected(method uint8, conn net.Conn) (net.Conn, erro
|
||||
s.logger.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
s.logger.Debug(req)
|
||||
s.logger.Trace(req)
|
||||
|
||||
if s.Authenticator != nil &&
|
||||
!s.Authenticator.Authenticate(req.Username, req.Password) {
|
||||
@ -76,11 +76,11 @@ func (s *serverSelector) OnSelected(method uint8, conn net.Conn) (net.Conn, erro
|
||||
}
|
||||
|
||||
resp := gosocks5.NewUserPassResponse(gosocks5.UserPassVer, gosocks5.Succeeded)
|
||||
s.logger.Trace(resp)
|
||||
if err := resp.Write(conn); err != nil {
|
||||
s.logger.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
s.logger.Debug(resp)
|
||||
|
||||
case gosocks5.MethodNoAcceptable:
|
||||
return nil, gosocks5.ErrBadMethod
|
||||
|
@ -22,7 +22,7 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, log logger
|
||||
|
||||
if !h.md.enableUDP {
|
||||
reply := gosocks5.NewReply(gosocks5.NotAllowed, nil)
|
||||
log.Debug(reply)
|
||||
log.Trace(reply)
|
||||
log.Error("socks5: UDP relay is disabled")
|
||||
return reply.Write(conn)
|
||||
}
|
||||
@ -31,8 +31,8 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, log logger
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
reply := gosocks5.NewReply(gosocks5.Failure, nil)
|
||||
log.Trace(reply)
|
||||
reply.Write(conn)
|
||||
log.Debug(reply)
|
||||
return err
|
||||
}
|
||||
defer cc.Close()
|
||||
@ -42,11 +42,11 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, log logger
|
||||
saddr.Type = 0
|
||||
saddr.Host, _, _ = net.SplitHostPort(conn.LocalAddr().String()) // replace the IP to the out-going interface's
|
||||
reply := gosocks5.NewReply(gosocks5.Succeeded, &saddr)
|
||||
log.Trace(reply)
|
||||
if err := reply.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
log.Debug(reply)
|
||||
|
||||
log = log.WithFields(map[string]any{
|
||||
"bind": fmt.Sprintf("%s/%s", cc.LocalAddr(), cc.LocalAddr().Network()),
|
||||
@ -76,10 +76,10 @@ func (h *socks5Handler) handleUDP(ctx context.Context, conn net.Conn, log logger
|
||||
go r.Run()
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), cc.LocalAddr())
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), cc.LocalAddr())
|
||||
io.Copy(ioutil.Discard, conn)
|
||||
log.WithFields(map[string]any{"duration": time.Since(t)}).
|
||||
Infof("%s >-< %s", conn.RemoteAddr(), cc.LocalAddr())
|
||||
Debugf("%s >-< %s", conn.RemoteAddr(), cc.LocalAddr())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
|
||||
// relay mode
|
||||
if !h.md.enableUDP {
|
||||
reply := gosocks5.NewReply(gosocks5.NotAllowed, nil)
|
||||
log.Debug(reply)
|
||||
log.Trace(reply)
|
||||
log.Error("socks5: UDP relay is disabled")
|
||||
return reply.Write(conn)
|
||||
}
|
||||
@ -33,7 +33,7 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
|
||||
// BIND mode
|
||||
if !h.md.enableBind {
|
||||
reply := gosocks5.NewReply(gosocks5.NotAllowed, nil)
|
||||
log.Debug(reply)
|
||||
log.Trace(reply)
|
||||
log.Error("socks5: BIND is disabled")
|
||||
return reply.Write(conn)
|
||||
}
|
||||
@ -49,11 +49,11 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
|
||||
saddr := gosocks5.Addr{}
|
||||
saddr.ParseFrom(pc.LocalAddr().String())
|
||||
reply := gosocks5.NewReply(gosocks5.Succeeded, &saddr)
|
||||
log.Trace(reply)
|
||||
if err := reply.Write(conn); err != nil {
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
log.Debug(reply)
|
||||
log.Debugf("bind on %s OK", pc.LocalAddr())
|
||||
|
||||
r := udp.NewRelay(socks.UDPTunServerConn(conn), pc).
|
||||
@ -62,11 +62,11 @@ func (h *socks5Handler) handleUDPTun(ctx context.Context, conn net.Conn, network
|
||||
r.SetBufferSize(h.md.udpBufferSize)
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||
r.Run()
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), pc.LocalAddr())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -95,10 +95,10 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.H
|
||||
"dst": addr.String(),
|
||||
})
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), addr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), addr)
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(addr.String()) {
|
||||
log.Info("bypass: ", addr.String())
|
||||
log.Debug("bypass: ", addr.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -109,11 +109,11 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.H
|
||||
defer cc.Close()
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), addr)
|
||||
netpkg.Transport(conn, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), addr)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -108,10 +108,10 @@ func (h *ssuHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
||||
}
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.LocalAddr(), cc.LocalAddr())
|
||||
log.Debugf("%s <-> %s", conn.LocalAddr(), cc.LocalAddr())
|
||||
h.relayPacket(pc, cc, log)
|
||||
log.WithFields(map[string]any{"duration": time.Since(t)}).
|
||||
Infof("%s >-< %s", conn.LocalAddr(), cc.LocalAddr())
|
||||
Debugf("%s >-< %s", conn.LocalAddr(), cc.LocalAddr())
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -140,7 +140,7 @@ func (h *ssuHandler) relayPacket(pc1, pc2 net.PacketConn, log logger.Logger) (er
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("%s >>> %s data: %d",
|
||||
log.Tracef("%s >>> %s data: %d",
|
||||
pc2.LocalAddr(), addr, n)
|
||||
return nil
|
||||
}()
|
||||
@ -172,7 +172,7 @@ func (h *ssuHandler) relayPacket(pc1, pc2 net.PacketConn, log logger.Logger) (er
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("%s <<< %s data: %d",
|
||||
log.Tracef("%s <<< %s data: %d",
|
||||
pc2.LocalAddr(), raddr, n)
|
||||
return nil
|
||||
}()
|
||||
|
@ -86,10 +86,10 @@ func (h *forwardHandler) handleDirectForward(ctx context.Context, conn *sshd_uti
|
||||
"cmd": "connect",
|
||||
})
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), targetAddr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), targetAddr)
|
||||
|
||||
if h.options.Bypass != nil && h.options.Bypass.Contains(targetAddr) {
|
||||
log.Infof("bypass %s", targetAddr)
|
||||
log.Debugf("bypass %s", targetAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -100,11 +100,11 @@ func (h *forwardHandler) handleDirectForward(ctx context.Context, conn *sshd_uti
|
||||
defer cc.Close()
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", cc.LocalAddr(), targetAddr)
|
||||
log.Debugf("%s <-> %s", cc.LocalAddr(), targetAddr)
|
||||
netpkg.Transport(conn, cc)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", cc.LocalAddr(), targetAddr)
|
||||
}).Debugf("%s >-< %s", cc.LocalAddr(), targetAddr)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -126,7 +126,7 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
|
||||
"cmd": "bind",
|
||||
})
|
||||
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), addr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), addr)
|
||||
|
||||
// tie to the client connection
|
||||
ln, err := net.Listen(network, addr)
|
||||
@ -198,21 +198,21 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
|
||||
go ssh.DiscardRequests(reqs)
|
||||
|
||||
t := time.Now()
|
||||
log.Infof("%s <-> %s", conn.LocalAddr(), conn.RemoteAddr())
|
||||
log.Debugf("%s <-> %s", conn.LocalAddr(), conn.RemoteAddr())
|
||||
netpkg.Transport(ch, conn)
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(t),
|
||||
}).Infof("%s >-< %s", conn.LocalAddr(), conn.RemoteAddr())
|
||||
}).Debugf("%s >-< %s", conn.LocalAddr(), conn.RemoteAddr())
|
||||
}(cc)
|
||||
}
|
||||
}()
|
||||
|
||||
tm := time.Now()
|
||||
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), addr)
|
||||
<-conn.Done()
|
||||
log.WithFields(map[string]any{
|
||||
"duration": time.Since(tm),
|
||||
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), addr)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ func (h *tapHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
||||
log = log.WithFields(map[string]any{
|
||||
"dst": fmt.Sprintf("%s/%s", raddr.String(), raddr.Network()),
|
||||
})
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
}
|
||||
|
||||
config := v.GetMetadata().Get("config").(*tap_util.Config)
|
||||
|
@ -118,7 +118,7 @@ func (h *tunHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
||||
log = log.WithFields(map[string]any{
|
||||
"dst": fmt.Sprintf("%s/%s", raddr.String(), raddr.Network()),
|
||||
})
|
||||
log.Infof("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
log.Debugf("%s >> %s", conn.RemoteAddr(), target.Addr)
|
||||
}
|
||||
|
||||
config := v.GetMetadata().Get("config").(*tun_util.Config)
|
||||
@ -211,7 +211,7 @@ func (h *tunHandler) transport(tun net.Conn, conn net.PacketConn, raddr net.Addr
|
||||
log.Error(err)
|
||||
return nil
|
||||
}
|
||||
log.Debugf("%s >> %s %-4s %d/%-4d %-4x %d",
|
||||
log.Tracef("%s >> %s %-4s %d/%-4d %-4x %d",
|
||||
header.Src, header.Dst, ipProtocol(waterutil.IPv4Protocol((*b)[:n])),
|
||||
header.Len, header.TotalLen, header.ID, header.Flags)
|
||||
|
||||
@ -222,7 +222,7 @@ func (h *tunHandler) transport(tun net.Conn, conn net.PacketConn, raddr net.Addr
|
||||
log.Warn(err)
|
||||
return nil
|
||||
}
|
||||
log.Debugf("%s >> %s %s %d %d",
|
||||
log.Tracef("%s >> %s %s %d %d",
|
||||
header.Src, header.Dst,
|
||||
ipProtocol(waterutil.IPProtocol(header.NextHeader)),
|
||||
header.PayloadLen, header.TrafficClass)
|
||||
@ -280,7 +280,7 @@ func (h *tunHandler) transport(tun net.Conn, conn net.PacketConn, raddr net.Addr
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debugf("%s >> %s %-4s %d/%-4d %-4x %d",
|
||||
log.Tracef("%s >> %s %-4s %d/%-4d %-4x %d",
|
||||
header.Src, header.Dst, ipProtocol(waterutil.IPv4Protocol((*b)[:n])),
|
||||
header.Len, header.TotalLen, header.ID, header.Flags)
|
||||
|
||||
@ -292,7 +292,7 @@ func (h *tunHandler) transport(tun net.Conn, conn net.PacketConn, raddr net.Addr
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debugf("%s > %s %s %d %d",
|
||||
log.Tracef("%s > %s %s %d %d",
|
||||
header.Src, header.Dst,
|
||||
ipProtocol(waterutil.IPProtocol(header.NextHeader)),
|
||||
header.PayloadLen, header.TrafficClass)
|
||||
|
@ -174,7 +174,7 @@ func (h *Hosts) periodReload(ctx context.Context) error {
|
||||
h.options.logger.Warnf("reload: %v", err)
|
||||
// return err
|
||||
}
|
||||
h.options.logger.Debugf("hosts reload done")
|
||||
h.options.logger.Debug("hosts reload done")
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func (r *Relay) Run() (err error) {
|
||||
}
|
||||
|
||||
if r.logger != nil {
|
||||
r.logger.Debugf("%s >>> %s data: %d",
|
||||
r.logger.Tracef("%s >>> %s data: %d",
|
||||
r.pc2.LocalAddr(), raddr, n)
|
||||
|
||||
}
|
||||
@ -107,7 +107,7 @@ func (r *Relay) Run() (err error) {
|
||||
}
|
||||
|
||||
if r.logger != nil {
|
||||
r.logger.Debugf("%s <<< %s data: %d",
|
||||
r.logger.Tracef("%s <<< %s data: %d",
|
||||
r.pc2.LocalAddr(), raddr, n)
|
||||
|
||||
}
|
||||
|
@ -74,9 +74,9 @@ func (c *Client) authorize(ctx context.Context, addr string) (token string, err
|
||||
return
|
||||
}
|
||||
|
||||
if c.Logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if c.Logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
c.Logger.Debug(string(dump))
|
||||
c.Logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
resp, err := c.Client.Do(r)
|
||||
@ -85,9 +85,9 @@ func (c *Client) authorize(ctx context.Context, addr string) (token string, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if c.Logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if c.Logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
c.Logger.Debug(string(dump))
|
||||
c.Logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
|
@ -54,9 +54,9 @@ func (c *clientConn) Write(b []byte) (n int, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if c.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
c.logger.Debug(string(dump))
|
||||
c.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
resp, err := c.client.Do(r)
|
||||
@ -65,9 +65,9 @@ func (c *clientConn) Write(b []byte) (n int, err error) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if c.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if c.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
c.logger.Debug(string(dump))
|
||||
c.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
@ -89,9 +89,9 @@ func (c *clientConn) readLoop() {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if c.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
c.logger.Debug(string(dump))
|
||||
c.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
resp, err := c.client.Do(r)
|
||||
@ -100,9 +100,9 @@ func (c *clientConn) readLoop() {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if c.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if c.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(resp, false)
|
||||
c.logger.Debug(string(dump))
|
||||
c.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
@ -200,9 +200,9 @@ func (s *Server) Close() error {
|
||||
}
|
||||
|
||||
func (s *Server) handleAuthorize(w http.ResponseWriter, r *http.Request) {
|
||||
if s.options.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if s.options.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
s.options.logger.Debug(string(dump))
|
||||
s.options.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
raddr, _ := net.ResolveTCPAddr("tcp", r.RemoteAddr)
|
||||
@ -234,9 +234,9 @@ func (s *Server) handleAuthorize(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) handlePush(w http.ResponseWriter, r *http.Request) {
|
||||
if s.options.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if s.options.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
s.options.logger.Debug(string(dump))
|
||||
s.options.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
if r.Method != http.MethodPost {
|
||||
@ -293,9 +293,9 @@ func (s *Server) handlePush(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) handlePull(w http.ResponseWriter, r *http.Request) {
|
||||
if s.options.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if s.options.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
s.options.logger.Debug(string(dump))
|
||||
s.options.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
if r.Method != http.MethodGet {
|
||||
|
@ -131,9 +131,9 @@ func (l *h2Listener) Close() (err error) {
|
||||
}
|
||||
|
||||
func (l *h2Listener) handleFunc(w http.ResponseWriter, r *http.Request) {
|
||||
if l.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if l.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
l.logger.Debug(string(dump))
|
||||
l.logger.Trace(string(dump))
|
||||
}
|
||||
conn, err := l.upgrade(w, r)
|
||||
if err != nil {
|
||||
|
@ -135,13 +135,13 @@ func (l *mwsListener) Addr() net.Addr {
|
||||
}
|
||||
|
||||
func (l *mwsListener) upgrade(w http.ResponseWriter, r *http.Request) {
|
||||
if l.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if l.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
log := l.logger.WithFields(map[string]any{
|
||||
"local": l.addr.String(),
|
||||
"remote": r.RemoteAddr,
|
||||
})
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
conn, err := l.upgrader.Upgrade(w, r, l.md.header)
|
||||
|
@ -49,9 +49,9 @@ func (c *obfsHTTPConn) handshake() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if c.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
c.logger.Debug(string(dump))
|
||||
c.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
if r.ContentLength > 0 {
|
||||
@ -82,9 +82,9 @@ func (c *obfsHTTPConn) handshake() (err error) {
|
||||
if r.Method != http.MethodGet || r.Header.Get("Upgrade") != "websocket" {
|
||||
resp.StatusCode = http.StatusBadRequest
|
||||
|
||||
if c.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if c.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(&resp, false)
|
||||
c.logger.Debug(string(dump))
|
||||
c.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
resp.Write(c.Conn)
|
||||
@ -96,9 +96,9 @@ func (c *obfsHTTPConn) handshake() (err error) {
|
||||
resp.Header.Set("Upgrade", "websocket")
|
||||
resp.Header.Set("Sec-WebSocket-Accept", c.computeAcceptKey(r.Header.Get("Sec-WebSocket-Key")))
|
||||
|
||||
if c.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if c.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpResponse(&resp, false)
|
||||
c.logger.Debug(string(dump))
|
||||
c.logger.Trace(string(dump))
|
||||
}
|
||||
|
||||
if c.rbuf.Len() > 0 {
|
||||
|
@ -142,7 +142,7 @@ func (l *sshdListener) serveConn(conn net.Conn) {
|
||||
p := directForward{}
|
||||
ssh.Unmarshal(newChannel.ExtraData(), &p)
|
||||
|
||||
l.logger.Debug(p.String())
|
||||
l.logger.Trace(p.String())
|
||||
|
||||
if p.Host1 == "<nil>" {
|
||||
p.Host1 = ""
|
||||
|
@ -130,13 +130,13 @@ func (l *wsListener) Addr() net.Addr {
|
||||
}
|
||||
|
||||
func (l *wsListener) upgrade(w http.ResponseWriter, r *http.Request) {
|
||||
if l.logger.IsLevelEnabled(logger.DebugLevel) {
|
||||
if l.logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
log := l.logger.WithFields(map[string]any{
|
||||
"local": l.addr.String(),
|
||||
"remote": r.RemoteAddr,
|
||||
})
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
log.Debug(string(dump))
|
||||
log.Trace(string(dump))
|
||||
}
|
||||
|
||||
conn, err := l.upgrader.Upgrade(w, r, l.md.header)
|
||||
|
@ -61,11 +61,13 @@ func NewLogger(opts ...LoggerOption) logger.Logger {
|
||||
log.SetFormatter(&logrus.JSONFormatter{
|
||||
DisableHTMLEscape: true,
|
||||
// PrettyPrint: true,
|
||||
TimestampFormat: "2006-01-02T15:04:05.000Z07:00",
|
||||
})
|
||||
}
|
||||
|
||||
switch options.Level {
|
||||
case logger.DebugLevel,
|
||||
case logger.TraceLevel,
|
||||
logger.DebugLevel,
|
||||
logger.InfoLevel,
|
||||
logger.WarnLevel,
|
||||
logger.ErrorLevel,
|
||||
@ -88,6 +90,16 @@ func (l *logrusLogger) WithFields(fields map[string]any) logger.Logger {
|
||||
}
|
||||
}
|
||||
|
||||
// Trace logs a message at level Trace.
|
||||
func (l *logrusLogger) Trace(args ...any) {
|
||||
l.log(logrus.TraceLevel, args...)
|
||||
}
|
||||
|
||||
// Tracef logs a message at level Trace.
|
||||
func (l *logrusLogger) Tracef(format string, args ...any) {
|
||||
l.logf(logrus.TraceLevel, format, args...)
|
||||
}
|
||||
|
||||
// Debug logs a message at level Debug.
|
||||
func (l *logrusLogger) Debug(args ...any) {
|
||||
l.log(logrus.DebugLevel, args...)
|
||||
|
@ -18,6 +18,12 @@ func (l *nopLogger) WithFields(fields map[string]any) logger.Logger {
|
||||
return l
|
||||
}
|
||||
|
||||
func (l *nopLogger) Trace(args ...any) {
|
||||
}
|
||||
|
||||
func (l *nopLogger) Tracef(format string, args ...any) {
|
||||
}
|
||||
|
||||
func (l *nopLogger) Debug(args ...any) {
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user