Commit 50056387 authored by Mygod's avatar Mygod

DNS over UDP

parent 5425b068
...@@ -33,11 +33,10 @@ import java.io.FileNotFoundException ...@@ -33,11 +33,10 @@ import java.io.FileNotFoundException
object Executable { object Executable {
const val REDSOCKS = "libredsocks.so" const val REDSOCKS = "libredsocks.so"
const val SS_LOCAL = "libss-local.so" const val SS_LOCAL = "libss-local.so"
const val SS_TUNNEL = "libss-tunnel.so"
const val TUN2SOCKS = "libtun2socks.so" const val TUN2SOCKS = "libtun2socks.so"
const val OVERTURE = "liboverture.so" const val OVERTURE = "liboverture.so"
private val EXECUTABLES = setOf(SS_LOCAL, SS_TUNNEL, REDSOCKS, TUN2SOCKS, OVERTURE) private val EXECUTABLES = setOf(SS_LOCAL, REDSOCKS, TUN2SOCKS, OVERTURE)
fun killAll() { fun killAll() {
for (process in File("/proc").listFiles { _, name -> TextUtils.isDigitsOnly(name) }) { for (process in File("/proc").listFiles { _, name -> TextUtils.isDigitsOnly(name) }) {
......
...@@ -43,11 +43,11 @@ object LocalDnsService { ...@@ -43,11 +43,11 @@ object LocalDnsService {
interface Interface : BaseService.Interface { interface Interface : BaseService.Interface {
override suspend fun startProcesses() { override suspend fun startProcesses() {
super.startProcesses() super.startProcesses()
val data = data
val profile = data.proxy!!.profile val profile = data.proxy!!.profile
if (!profile.udpdns) servers[this] = LocalDnsServer(this::resolver, servers[this] = LocalDnsServer(this::resolver,
Socks5Endpoint(profile.remoteDns.split(",").first(), 53), Socks5Endpoint(profile.remoteDns.split(",").first(), 53),
DataStore.proxyAddress).apply { DataStore.proxyAddress).apply {
tcp = !profile.udpdns
when (profile.route) { when (profile.route) {
Acl.BYPASS_CHN, Acl.BYPASS_LAN_CHN, Acl.GFWLIST, Acl.CUSTOM_RULES -> { Acl.BYPASS_CHN, Acl.BYPASS_LAN_CHN, Acl.GFWLIST, Acl.CUSTOM_RULES -> {
remoteDomainMatcher = googleApisTester remoteDomainMatcher = googleApisTester
......
...@@ -115,7 +115,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -115,7 +115,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
} }
// for UDP profile, it's only going to operate in UDP relay mode-only so this flag has no effect // for UDP profile, it's only going to operate in UDP relay mode-only so this flag has no effect
if (profile.udpdns) cmd += "-D" if (profile.route == Acl.ALL || profile.route == Acl.BYPASS_LAN) cmd += "-D"
if (DataStore.tcpFastOpen) cmd += "--fast-open" if (DataStore.tcpFastOpen) cmd += "--fast-open"
......
...@@ -36,20 +36,6 @@ class TransproxyService : Service(), LocalDnsService.Interface { ...@@ -36,20 +36,6 @@ class TransproxyService : Service(), LocalDnsService.Interface {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int = override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int =
super<LocalDnsService.Interface>.onStartCommand(intent, flags, startId) super<LocalDnsService.Interface>.onStartCommand(intent, flags, startId)
private fun startDNSTunnel() {
val proxy = data.proxy!!
val cmd = arrayListOf(File(applicationInfo.nativeLibraryDir, Executable.SS_TUNNEL).absolutePath,
"-t", "10",
"-b", DataStore.listenAddress,
"-u",
"-l", DataStore.portLocalDns.toString(), // ss-tunnel listens on the same port as overture
"-L", proxy.profile.remoteDns.split(",").first().trim() + ":53",
// config is already built by BaseService.Interface
"-c", (data.udpFallback ?: proxy).configFile!!.absolutePath)
if (DataStore.tcpFastOpen) cmd += "--fast-open"
data.processes!!.start(cmd)
}
private fun startRedsocksDaemon() { private fun startRedsocksDaemon() {
File(Core.deviceStorage.noBackupFilesDir, "redsocks.conf").writeText("""base { File(Core.deviceStorage.noBackupFilesDir, "redsocks.conf").writeText("""base {
log_debug = off; log_debug = off;
...@@ -73,7 +59,6 @@ redsocks { ...@@ -73,7 +59,6 @@ redsocks {
override suspend fun startProcesses() { override suspend fun startProcesses() {
startRedsocksDaemon() startRedsocksDaemon()
super.startProcesses() super.startProcesses()
if (data.proxy!!.profile.udpdns) startDNSTunnel()
} }
override fun onDestroy() { override fun onDestroy() {
......
...@@ -203,16 +203,13 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { ...@@ -203,16 +203,13 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
"--tunfd", fd.toString(), "--tunfd", fd.toString(),
"--tunmtu", VPN_MTU.toString(), "--tunmtu", VPN_MTU.toString(),
"--sock-path", "sock_path", "--sock-path", "sock_path",
"--dnsgw", "127.0.0.1:${DataStore.portLocalDns}",
"--loglevel", "3") "--loglevel", "3")
if (profile.ipv6) { if (profile.ipv6) {
cmd += "--netif-ip6addr" cmd += "--netif-ip6addr"
cmd += PRIVATE_VLAN6.format(Locale.ENGLISH, "2") cmd += PRIVATE_VLAN6.format(Locale.ENGLISH, "2")
} }
cmd += "--enable-udprelay" cmd += "--enable-udprelay"
if (!profile.udpdns) {
cmd += "--dnsgw"
cmd += "127.0.0.1:${DataStore.portLocalDns}"
}
data.processes!!.start(cmd, onRestartCallback = { data.processes!!.start(cmd, onRestartCallback = {
try { try {
sendFd(conn.fileDescriptor) sendFd(conn.fileDescriptor)
......
...@@ -25,13 +25,12 @@ import androidx.preference.PreferenceDataStore ...@@ -25,13 +25,12 @@ import androidx.preference.PreferenceDataStore
import com.github.shadowsocks.Core import com.github.shadowsocks.Core
import com.github.shadowsocks.database.PrivateDatabase import com.github.shadowsocks.database.PrivateDatabase
import com.github.shadowsocks.database.PublicDatabase import com.github.shadowsocks.database.PublicDatabase
import com.github.shadowsocks.net.TcpFastOpen
import com.github.shadowsocks.utils.DirectBoot import com.github.shadowsocks.utils.DirectBoot
import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.Key
import com.github.shadowsocks.net.TcpFastOpen
import com.github.shadowsocks.utils.parsePort import com.github.shadowsocks.utils.parsePort
import java.net.InetSocketAddress import java.net.InetSocketAddress
import java.net.NetworkInterface import java.net.NetworkInterface
import java.net.Proxy
import java.net.SocketException import java.net.SocketException
object DataStore : OnPreferenceDataStoreChangeListener { object DataStore : OnPreferenceDataStoreChangeListener {
......
...@@ -278,39 +278,6 @@ LOCAL_LDLIBS := -llog ...@@ -278,39 +278,6 @@ LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_EXECUTABLE) include $(BUILD_SHARED_EXECUTABLE)
########################################################
## shadowsocks-libev tunnel
########################################################
include $(CLEAR_VARS)
SHADOWSOCKS_SOURCES := tunnel.c \
cache.c udprelay.c utils.c netutils.c json.c jconf.c \
crypto.c aead.c stream.c base64.c \
plugin.c ppbloom.c \
android.c
LOCAL_MODULE := ss-tunnel
LOCAL_SRC_FILES := $(addprefix shadowsocks-libev/src/, $(SHADOWSOCKS_SOURCES))
LOCAL_CFLAGS := -Wall -fno-strict-aliasing -DMODULE_TUNNEL \
-DUSE_CRYPTO_MBEDTLS -DHAVE_CONFIG_H -DSSTUNNEL_JNI \
-DCONNECT_IN_PROGRESS=EINPROGRESS \
-I$(LOCAL_PATH)/libancillary \
-I$(LOCAL_PATH)/include \
-I$(LOCAL_PATH)/libsodium/src/libsodium/include \
-I$(LOCAL_PATH)/libsodium/src/libsodium/include/sodium \
-I$(LOCAL_PATH)/mbedtls/include \
-I$(LOCAL_PATH)/libev \
-I$(LOCAL_PATH)/shadowsocks-libev/libcork/include \
-I$(LOCAL_PATH)/shadowsocks-libev/libbloom \
-I$(LOCAL_PATH)/include/shadowsocks-libev
LOCAL_STATIC_LIBRARIES := libev libmbedtls libsodium libcork libbloom libancillary
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_EXECUTABLE)
######################################################## ########################################################
## tun2socks ## tun2socks
######################################################## ########################################################
......
...@@ -57,8 +57,8 @@ ...@@ -57,8 +57,8 @@
<string name="tcp_fastopen_summary">Toggling might require ROOT permission</string> <string name="tcp_fastopen_summary">Toggling might require ROOT permission</string>
<string name="tcp_fastopen_summary_unsupported">Unsupported kernel version: %s &lt; 3.7.1</string> <string name="tcp_fastopen_summary_unsupported">Unsupported kernel version: %s &lt; 3.7.1</string>
<string name="tcp_fastopen_failure">Toggle failed</string> <string name="tcp_fastopen_failure">Toggle failed</string>
<string name="udp_dns">DNS Forwarding</string> <string name="udp_dns">Send DNS over UDP</string>
<string name="udp_dns_summary">Forward all DNS requests to remote</string> <string name="udp_dns_summary">Requires UDP forwarding on server side</string>
<string name="udp_fallback">UDP Fallback</string> <string name="udp_fallback">UDP Fallback</string>
<!-- notification category --> <!-- notification category -->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment