Skip to content

Commit

Permalink
feat: add sniffing for tun
Browse files Browse the repository at this point in the history
  • Loading branch information
AkinoKaede authored and xiaokangwang committed Nov 1, 2023
1 parent 5ac91da commit c0a0ce2
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 71 deletions.
138 changes: 81 additions & 57 deletions app/tun/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions app/tun/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ option go_package = "github.com/v2fly/v2ray-core/v5/app/tun";
option java_package = "com.v2ray.core.app.tun";
option java_multiple_files = true;


import "app/proxyman/config.proto";
import "app/router/routercommon/common.proto";
import "common/protoext/extensions.proto";
import "common/net/packetaddr/config.proto";
import "transport/internet/config.proto";

message Config {
option (v2ray.core.common.protoext.message_opt).type = "service";
option (v2ray.core.common.protoext.message_opt).short_name = "tun";
option (v2ray.core.common.protoext.message_opt).type = "service";
option (v2ray.core.common.protoext.message_opt).short_name = "tun";

string name = 1;
uint32 mtu = 2;
uint32 user_level = 3;
v2ray.core.net.packetaddr.PacketAddrType packet_encoding = 4;
string tag = 5;
repeated v2ray.core.app.router.routercommon.CIDR ips = 6;
repeated v2ray.core.app.router.routercommon.CIDR routes = 7;
bool enable_promiscuous_mode = 8;
bool enable_spoofing = 9;
v2ray.core.transport.internet.SocketConfig socket_settings = 10;
string name = 1;
uint32 mtu = 2;
uint32 user_level = 3;
v2ray.core.net.packetaddr.PacketAddrType packet_encoding = 4;
string tag = 5;
repeated v2ray.core.app.router.routercommon.CIDR ips = 6;
repeated v2ray.core.app.router.routercommon.CIDR routes = 7;
bool enable_promiscuous_mode = 8;
bool enable_spoofing = 9;
v2ray.core.transport.internet.SocketConfig socket_settings = 10;
v2ray.core.app.proxyman.SniffingConfig sniffing_settings = 11;
}
7 changes: 7 additions & 0 deletions app/tun/handler_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ func (h *TCPHandler) Handle(conn tun_net.TCPConn) error {
Status: log.AccessAccepted,
Reason: "",
})
content := new(session.Content)
if h.config.SniffingSettings != nil {
content.SniffingRequest.Enabled = h.config.SniffingSettings.Enabled
content.SniffingRequest.OverrideDestinationForProtocol = h.config.SniffingSettings.DestinationOverride
content.SniffingRequest.MetadataOnly = h.config.SniffingSettings.MetadataOnly
}
ctx = session.ContextWithContent(ctx, content)
ctx, cancel := context.WithCancel(ctx)
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
link, err := h.dispatcher.Dispatch(ctx, dest)
Expand Down
7 changes: 7 additions & 0 deletions app/tun/handler_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ func (h *UDPHandler) Handle(conn tun_net.UDPConn) error {
defer conn.Close()
id := conn.ID()
ctx := session.ContextWithInbound(h.ctx, &session.Inbound{Tag: h.config.Tag})
content := new(session.Content)
if h.config.SniffingSettings != nil {
content.SniffingRequest.Enabled = h.config.SniffingSettings.Enabled
content.SniffingRequest.OverrideDestinationForProtocol = h.config.SniffingSettings.DestinationOverride
content.SniffingRequest.MetadataOnly = h.config.SniffingSettings.MetadataOnly
}
ctx = session.ContextWithContent(ctx, content)

udpDispatcherConstructor := udp.NewSplitDispatcher

Expand Down

0 comments on commit c0a0ce2

Please sign in to comment.