-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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: TUN Support #2541
feat: TUN Support #2541
Conversation
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #2541 +/- ##
==========================================
- Coverage 38.27% 37.74% -0.53%
==========================================
Files 637 654 +17
Lines 38147 38720 +573
==========================================
+ Hits 14600 14616 +16
- Misses 21938 22489 +551
- Partials 1609 1615 +6
☔ View full report in Codecov by Sentry. |
One use case of tun may be for supporting ICMP for Fake IPs. With tproxy, only TCP and UDP can be handled by V2Ray, but with tun, v2ray can convert Fake IP to real IP and forward ICMP requests for it. I may help to do such ICMP forwarding, write corresponding tests, and add v2ray v4 config support.
|
1 app/tun/handler_tcp.go app/tun/handler_udp.go a unneed channel (unbuffered even) to receives the conn. |
@rurirei Thanks for your suggestions. I don't know much about how gVisor's UDP works, can you give some advice? |
The goal of handling ICMP can be difficult to achieve, most proxy protocols do not support ICMP forwarding. |
One of the reason may be related to this issue: May need dig into the source code to find a way out. If achieved, there may be following icmp forward options: 1) |
https://github.com/xjasonlyu/tun2socks/blob/main/core/udp.go https://github.com/SagerNet/sing-tun/blob/dev/gvisor_udp.go |
Consider that TUN is not a proxy, so I implements it as App. |
I think the first option and the third option are feasible. |
I test it on my Fedora VM, its' works. {
"services": {
"tun": {
"name": "tun0",
"mtu": 1500,
"tag": "tun",
"ips": [
{
"ip": [192, 18, 0, 1],
"prefix": 24
}
],
"routes": [
{
"ip": [0, 0, 0, 0],
"prefix": 0
}
],
"enablePromiscuousMode": true,
"enableSpoofing": true
}
},
"log": {
"error": {
"level": "Debug",
"type": "Console"
},
"access": {
"type": "None"
}
},
"outbounds": [
{
"protocol": "freedom",
"streamSettings": {
"socketSettings": {
"bindToDevice": "eth0"
}
}
}
]
} |
It has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days |
I have added You can test it by: On a environment with network accessRun a server provides network access to other process with access to its domain socket with:
Run tun with fullcone enabled in a separate network namespaceCreate a separate user, network, mount namespace with
In this environment, run the v2ray with following configuration in the background:
Finalize network setup with:
You may need to fix the dns settings, as the default system setting may not work in this environment:
Then you have finished the setup of a separate tun based network ready for testing. |
Got error message using this template config: Is the format changed ? |
V5才支持 |
Same config parsing issue with this. Renamed the config to config.v5.json to no avail. |
Considering that the PR has been merged, it is recommended to submit issues for questions about use. |
Does anyone have an example how to tunnel ALL QUERIES from only specific application under Windows but at the same time also support SOCKS inbounds as well for others? |
v5 config is WIP status, is it possible to add v2ray v4 config support for TUN? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package specs
import (
"encoding/json"
)
type OutboundConfig struct {
Protocol string json:"protocol"
Settings json.RawMessage json:"settings"
StreamSetting *StreamConfig json:"streamSettings"
Metadata map[string]string json:"metadata"
}
type StreamConfig struct {
Transport string json:"transport"
TransportSettings json.RawMessage json:"transportSettings"
Security string json:"security"
SecuritySettings json.RawMessage json:"securitySettings"
}
TODO