From e28ef6a47dabe7a2630751d230ce8c6410b6f44d Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Thu, 30 Dec 2021 22:20:10 +0000 Subject: [PATCH] shadowsockets fullcone inbound support --- proxy/shadowsocks/config.proto | 2 ++ proxy/shadowsocks/server.go | 18 ++++++++++++++++-- proxy/shadowsocks/simplified/config.proto | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/proxy/shadowsocks/config.proto b/proxy/shadowsocks/config.proto index fb1d12e42..d489663d1 100644 --- a/proxy/shadowsocks/config.proto +++ b/proxy/shadowsocks/config.proto @@ -9,6 +9,7 @@ option java_multiple_files = true; import "common/net/network.proto"; import "common/protocol/user.proto"; import "common/protocol/server_spec.proto"; +import "common/net/packetaddr/config.proto"; message Account { string password = 1; @@ -31,6 +32,7 @@ message ServerConfig { bool udp_enabled = 1 [deprecated = true]; v2ray.core.common.protocol.User user = 2; repeated v2ray.core.common.net.Network network = 3; + v2ray.core.net.packetaddr.PacketAddrType packet_encoding = 4; } message ClientConfig { diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index f78440016..7d2a9da3a 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -2,6 +2,7 @@ package shadowsocks import ( "context" + "github.com/v2fly/v2ray-core/v5/common/net/packetaddr" "time" core "github.com/v2fly/v2ray-core/v5" @@ -70,10 +71,23 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet } func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection, dispatcher routing.Dispatcher) error { - udpServer := udp.NewSplitDispatcher(dispatcher, func(ctx context.Context, packet *udp_proto.Packet) { + udpDispatcherConstructor := udp.NewSplitDispatcher + switch s.config.PacketEncoding { + case packetaddr.PacketAddrType_None: + break + case packetaddr.PacketAddrType_Packet: + packetAddrDispatcherFactory := udp.NewPacketAddrDispatcherCreator(ctx) + udpDispatcherConstructor = packetAddrDispatcherFactory.NewPacketAddrDispatcher + } + + udpServer := udpDispatcherConstructor(dispatcher, func(ctx context.Context, packet *udp_proto.Packet) { request := protocol.RequestHeaderFromContext(ctx) if request == nil { - return + request = &protocol.RequestHeader{ + Port: packet.Source.Port, + Address: packet.Source.Address, + User: s.user, + } } payload := packet.Payload diff --git a/proxy/shadowsocks/simplified/config.proto b/proxy/shadowsocks/simplified/config.proto index 04c710f74..f959b9d9a 100644 --- a/proxy/shadowsocks/simplified/config.proto +++ b/proxy/shadowsocks/simplified/config.proto @@ -8,6 +8,7 @@ option java_multiple_files = true; import "common/protoext/extensions.proto"; import "common/net/address.proto"; +import "common/net/packetaddr/config.proto"; message ServerConfig{ option (v2ray.core.common.protoext.message_opt).type = "inbound"; @@ -16,6 +17,7 @@ message ServerConfig{ string method = 1; string password = 2; string network = 3; + v2ray.core.net.packetaddr.PacketAddrType packet_encoding = 4; } message ClientConfig {