forwarder: connect to sni host for empty node
This commit is contained in:
@@ -160,8 +160,9 @@ func (h *Sniffer) HandleHTTP(ctx context.Context, conn net.Conn, opts ...HandleO
|
|||||||
}
|
}
|
||||||
|
|
||||||
if clientIP := xhttp.GetClientIP(req); clientIP != nil {
|
if clientIP := xhttp.GetClientIP(req); clientIP != nil {
|
||||||
ro.ClientIP = clientIP.String()
|
clientAddr := &net.TCPAddr{IP: clientIP}
|
||||||
ctx = xctx.ContextWithSrcAddr(ctx, &net.TCPAddr{IP: clientIP})
|
ro.ClientAddr = clientAddr.String()
|
||||||
|
ctx = xctx.ContextWithSrcAddr(ctx, clientAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// http/2
|
// http/2
|
||||||
@@ -250,12 +251,15 @@ func (h *Sniffer) dial(ctx context.Context, conn net.Conn, req *http.Request, ho
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node = &chain.Node{
|
node = &chain.Node{}
|
||||||
Addr: host,
|
|
||||||
}
|
|
||||||
if ho.Hop != nil {
|
if ho.Hop != nil {
|
||||||
|
var clientIP net.IP
|
||||||
|
if clientAddr, _ := net.ResolveTCPAddr("tcp", ro.ClientAddr); clientAddr != nil {
|
||||||
|
clientIP = clientAddr.IP
|
||||||
|
}
|
||||||
|
|
||||||
node = ho.Hop.Select(ctx,
|
node = ho.Hop.Select(ctx,
|
||||||
hop.ClientIPSelectOption(net.ParseIP(ro.ClientIP)),
|
hop.ClientIPSelectOption(clientIP),
|
||||||
hop.ProtocolSelectOption(sniffing.ProtoHTTP),
|
hop.ProtocolSelectOption(sniffing.ProtoHTTP),
|
||||||
hop.HostSelectOption(host),
|
hop.HostSelectOption(host),
|
||||||
hop.MethodSelectOption(req.Method),
|
hop.MethodSelectOption(req.Method),
|
||||||
@@ -271,6 +275,12 @@ func (h *Sniffer) dial(ctx context.Context, conn net.Conn, req *http.Request, ho
|
|||||||
res.Write(conn)
|
res.Write(conn)
|
||||||
return nil, nil, errors.New("node not available")
|
return nil, nil, errors.New("node not available")
|
||||||
}
|
}
|
||||||
|
if node.Addr == "" {
|
||||||
|
node = &chain.Node{
|
||||||
|
Name: node.Name,
|
||||||
|
Addr: host,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ro.Host = node.Addr
|
ro.Host = node.Addr
|
||||||
ho.Log = ho.Log.WithFields(map[string]any{
|
ho.Log = ho.Log.WithFields(map[string]any{
|
||||||
@@ -874,16 +884,17 @@ func (h *Sniffer) dialTLS(ctx context.Context, host string, ho *HandleOptions) (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if host != "" {
|
node = &chain.Node{}
|
||||||
node = &chain.Node{
|
|
||||||
Addr: host,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ro := ho.RecorderObject
|
ro := ho.RecorderObject
|
||||||
if ho.Hop != nil {
|
if ho.Hop != nil {
|
||||||
|
var clientIP net.IP
|
||||||
|
if clientAddr, _ := net.ResolveTCPAddr("tcp", ro.ClientAddr); clientAddr != nil {
|
||||||
|
clientIP = clientAddr.IP
|
||||||
|
}
|
||||||
|
|
||||||
node = ho.Hop.Select(ctx,
|
node = ho.Hop.Select(ctx,
|
||||||
hop.ClientIPSelectOption(net.ParseIP(ro.ClientIP)),
|
hop.ClientIPSelectOption(clientIP),
|
||||||
hop.HostSelectOption(host),
|
hop.HostSelectOption(host),
|
||||||
hop.ProtocolSelectOption(sniffing.ProtoTLS),
|
hop.ProtocolSelectOption(sniffing.ProtoTLS),
|
||||||
)
|
)
|
||||||
@@ -892,6 +903,12 @@ func (h *Sniffer) dialTLS(ctx context.Context, host string, ho *HandleOptions) (
|
|||||||
err = errors.New("node not available")
|
err = errors.New("node not available")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if node.Addr == "" {
|
||||||
|
node = &chain.Node{
|
||||||
|
Name: node.Name,
|
||||||
|
Addr: host,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addr := node.Addr
|
addr := node.Addr
|
||||||
if opts := node.Options(); opts != nil {
|
if opts := node.Options(); opts != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user