Closed rurirei closed 4 years ago
protectFd := func(s VpnService, fd int) error {
if s.Protect(fd) {
return nil
} else {
return errors.New(fmt.Sprintf("failed to protect fd %v", fd))
}
}
netCtlr := func(network, address string, fd uintptr) error {
return protectFd(vpnService, int(fd))
}
net.DefaultResolver = &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, addr string) (net.Conn, error) {
dialer := &net.Dialer{
DualStack: true,
Control: func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
netCtlr(network, address, fd)
})
},
}
return dialer.DialContext(ctx, network, localDNS)
},
}
great thanks. https://github.com/rurirei/go-libv2ray/commit/9f1e33e
great thanks. rurirei/go-libv2ray@9f1e33e
sorry for asking. how do i forward dns traffic to v2ray inbound from tun2socks
? i set net.defaultResolver with addr 127.0.0.1:10088 (localDns string) and set Dokodemo-Door inbound (listen on port 10088, address 8.8.8.8 port 53)
PrepareDomain err: lookup server.address.domain on [::1]:53: read udp 127.0.0.1:48822->127.0.0.1:10088: read: connection refused
I don't remember the details, but I never use dokodemo-door to handle DNS, instead you could route DNS traffic to a DNS outbound:
{
"inboundTag": ["tun2socks"],
"network": "udp",
"port": 53,
"outboundTag": "dns-out",
"type": "field"
},
though what is inbound tun2socks
, i did thought it to Dokodemo inbound.
You attach a ctx with a "tun2socks" tag when dialing connections with a V instance, then v2ray will recognize those traffic are coming from "tun2socks":
ctx = vsession.ContextWithInbound(ctx, &vsession.Inbound{Tag: "tun2socks"})
c, err := vcore.Dial(ctx, h.v, dest)
You attach a ctx with a "tun2socks" tag when dialing connections with a V instance, then v2ray will recognize those traffic are coming from "tun2socks":
ctx = vsession.ContextWithInbound(ctx, &vsession.Inbound{Tag: "tun2socks"})
c, err := vcore.Dial(ctx, h.v, dest)
thanks for reply, how to handle dns traffic from net.DefaultResolver with vcore.Dial(ctx, h.v, dest) then?
The fd
is protected as you can see in the code snippet above, protected traffic won't go into v2ray, that's why it's called local dns
.
so i was thought meanings of local dns
on anything wrong.
android:defaultValue="223.5.5.5" android:key="@string/local_dns" android:summary="The DNS server that will be used by the freedom outbound (in case you are using AsIs as the freedom outbound's domain strategy) or for resolving domain names of outbound servers, and these DNS requests won't be logged to proxy log. Moreover, non A/AAAA DNS queries from the OS will also be sent to this DNS server, they will be treated as normal UDP traffic." android:title="Local DNS"
sorry but could you give some more function explaination of Local DNS?
i was misunderstood this to the similar to tun2socks --dnsgw 127.0.0.1:10088
.
so i was thought meanings of
local dns
on anything wrong.
I don't remember the details, but I never use dokodemo-door to handle DNS, instead you could route DNS traffic to a DNS outbound:
{ "inboundTag": ["tun2socks"], "network": "udp", "port": 53, "outboundTag": "dns-out", "type": "field" },
but local dns traffic won't into v2ray..
It means DNS traffic initiated from this resolver will definitely go into the internet directly, no proxying, that's it.
net.DefaultResolver = &net.Resolver{
I think what you missed here is only the VPN itself (only the Go code) will use this resolver. And you still need to handle DNS traffic coming from other applications, those traffic should be routed to a DNS outbound.
only the VPN itself (only the Go code) will use this resolver
this is exactly i missed.
need to handle DNS traffic coming from other applications
i dont know how should to done this
those traffic should be routed to a DNS outbound
v2ray dns handle its dns-outbound if IP query. is this "Moreover, non A/AAAA DNS queries from the OS will also be sent to this DNS server"?
v2ray dns handle its dns-outbound if IP query. is this "Moreover, non A/AAAA DNS queries from the OS will also be sent to this DNS server"?
I forgot, I'm not sure about this without looking into the code.
gave this up.
great thanks for if could you open source the implementation of Local DNS of go-tun2socks @eycorsican https://github.com/eycorsican/kitsunebi-android/blob/6bccc618029eb9cd87235c15f868bda82ba1b1de/app/src/main/java/fun/kitsunebi/kitsunebi4android/service/SimpleVpnService.kt#L289-L292