add interface xnet.SrcAddr/DstAddr

This commit is contained in:
ginuerzh
2025-08-03 10:15:53 +08:00
parent 79203e407c
commit f71351f5ef
42 changed files with 518 additions and 295 deletions
+3 -6
View File
@@ -81,12 +81,8 @@ func (h *sniHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
SID: string(ctxvalue.SidFromContext(ctx)),
}
ro.ClientIP = conn.RemoteAddr().String()
if clientAddr := ctxvalue.ClientAddrFromContext(ctx); clientAddr != "" {
ro.ClientIP = string(clientAddr)
}
if h, _, _ := net.SplitHostPort(ro.ClientIP); h != "" {
ro.ClientIP = h
if srcAddr := ctxvalue.SrcAddrFromContext(ctx); srcAddr != nil {
ro.ClientIP = srcAddr.String()
}
log := h.options.Logger.WithFields(map[string]any{
@@ -131,6 +127,7 @@ func (h *sniHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
var buf bytes.Buffer
cc, err := h.options.Router.Dial(ctxvalue.ContextWithBuffer(ctx, &buf), "tcp", address)
ro.Route = buf.String()
return cc, err
}
dialTLS := func(ctx context.Context, network, address string, cfg *tls.Config) (net.Conn, error) {