Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add sniffing for TUN #2733

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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