1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-15 16:56:08 -05:00

add packet addr support in outbound handler

This commit is contained in:
Shelikhoo 2021-12-27 16:21:13 +00:00 committed by Xiaokang Wang (Shelikhoo)
parent 5b536a7d02
commit 552a15085d

View File

@ -8,6 +8,7 @@ import (
"github.com/v2fly/v2ray-core/v5/common" "github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/mux" "github.com/v2fly/v2ray-core/v5/common/mux"
"github.com/v2fly/v2ray-core/v5/common/net" "github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/net/packetaddr"
"github.com/v2fly/v2ray-core/v5/common/serial" "github.com/v2fly/v2ray-core/v5/common/serial"
"github.com/v2fly/v2ray-core/v5/common/session" "github.com/v2fly/v2ray-core/v5/common/session"
"github.com/v2fly/v2ray-core/v5/features/outbound" "github.com/v2fly/v2ray-core/v5/features/outbound"
@ -208,6 +209,15 @@ func (h *Handler) Dial(ctx context.Context, dest net.Destination) (internet.Conn
ctx = session.SetTransportLayerProxyTagToContext(ctx, tag) ctx = session.SetTransportLayerProxyTagToContext(ctx, tag)
} }
if isStream, err := packetaddr.GetDestinationSubsetOf(dest); err == nil {
packetConn, err := internet.ListenSystemPacket(ctx, nil, h.streamSettings.SocketSettings)
if err != nil {
return nil, newError("unable to listen socket").Base(err)
}
conn := packetaddr.ToPacketAddrConnWrapper(packetConn, isStream)
return h.getStatCouterConnection(conn), nil
}
conn, err := internet.Dial(ctx, dest, h.streamSettings) conn, err := internet.Dial(ctx, dest, h.streamSettings)
return h.getStatCouterConnection(conn), err return h.getStatCouterConnection(conn), err
} }