summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-04-17 07:53:30 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-04-17 07:53:30 -0300
commit41a5db158de9ade895f85dd252e8cbba37080e30 (patch)
tree9b7ed2ff209d2956eefc5dbe9f53264c39e7ce97
parent6939b5ef97b34d4052c6a55768ae18c382e8633b (diff)
parent653026d4f7e4240c7150e48170d737bf9c6ce3ea (diff)
downloadmullvadvpn-41a5db158de9ade895f85dd252e8cbba37080e30.tar.xz
mullvadvpn-41a5db158de9ade895f85dd252e8cbba37080e30.zip
Merge branch 'linux-dns'
-rw-r--r--Cargo.lock140
-rw-r--r--talpid-core/Cargo.toml7
-rw-r--r--talpid-core/src/firewall/linux.rs21
-rw-r--r--talpid-core/src/firewall/linux/dns.rs190
-rw-r--r--talpid-core/src/firewall/linux/mod.rs47
5 files changed, 381 insertions, 24 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c0043253e7..55b4f9fe29 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -72,6 +72,16 @@ dependencies = [
[[package]]
name = "bitflags"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "bitflags"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "bitflags"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -87,6 +97,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bytes"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "bytes"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -283,6 +298,24 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "fsevent"
+version = "0.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "fsevent-sys"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -384,6 +417,14 @@ dependencies = [
]
[[package]]
+name = "inotify"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "ioctl-sys"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -592,6 +633,22 @@ dependencies = [
[[package]]
name = "mio"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
+ "miow 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "net2 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "nix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "slab 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "mio"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -610,6 +667,17 @@ dependencies = [
[[package]]
name = "miow"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "net2 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "miow"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -728,6 +796,15 @@ dependencies = [
[[package]]
name = "nix"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "nix"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -738,6 +815,23 @@ dependencies = [
]
[[package]]
+name = "notify"
+version = "4.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "filetime 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fsevent 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "inotify 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "walkdir 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "num"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -957,6 +1051,14 @@ dependencies = [
]
[[package]]
+name = "resolv-conf"
+version = "0.6.0"
+source = "git+https://github.com/tailhook/resolv-conf.git#95d629bdd333916ac4659571ddf03b495329f191"
+dependencies = [
+ "quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "rustc-demangle"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -967,6 +1069,14 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "same-file"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "schannel"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1078,6 +1188,11 @@ dependencies = [
[[package]]
name = "slab"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "slab"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1158,8 +1273,10 @@ dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "notify 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"openvpn-plugin 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pfctl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "resolv-conf 0.6.0 (git+https://github.com/tailhook/resolv-conf.git)",
"shell-escape 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"system-configuration 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"talpid-ipc 0.1.0",
@@ -1412,6 +1529,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "walkdir"
+version = "2.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "widestring"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1492,9 +1618,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum backtrace 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ebbbf59b1c43eefa8c3ede390fcc36820b4999f7914104015be25025e0d62af2"
"checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661"
"checksum base64 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "229d032f1a99302697f10b27167ae6d03d49d032e6a8e2550e8d3fc13356d2b4"
+"checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3"
+"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23"
+"checksum bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c129aff112dcc562970abb69e2508b40850dd24c274761bb50fb8a0067ba6c27"
"checksum bytes 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1b7db437d718977f6dc9b2e3fd6fc343c02ac6b899b73fdd2179163447bd9ce9"
"checksum cc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "9be26b24e988625409b19736d130f0c7d224f01d06454b5f81d8d23d6c1a618f"
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
@@ -1518,6 +1647,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
+"checksum fsevent 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "c4bbbf71584aeed076100b5665ac14e3d85eeb31fdbb45fbd41ef9a682b5ec05"
+"checksum fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a772d36c338d07a032d5375a36f15f9a7043bf0cb8ce7cee658e037c6032874"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum futures 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0bab5b5e94f5c31fc764ba5dd9ad16568aae5d4825538c01d6bca680c9bf94a7"
@@ -1528,6 +1659,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum hyper 0.11.21 (registry+https://github.com/rust-lang/crates.io-index)" = "a3a77dea5dccbf32ba4e9ddd7d80a5a3bb3b9f1f3835e18daf5dbea6bee0efbf"
"checksum hyper-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c81fa95203e2a6087242c38691a0210f23e9f3f8f944350bd676522132e2985"
"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
+"checksum inotify 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887fcc180136e77a85e6a6128579a719027b1bab9b1c38ea4444244fe262c20c"
"checksum ioctl-sys 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5e2c4b26352496eaaa8ca7cfa9bd99e93419d3f7983dc6e99c2a35fe9e33504a"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
"checksum ipnetwork 0.12.7 (registry+https://github.com/rust-lang/crates.io-index)" = "2134e210e2a024b5684f90e1556d5f71a1ce7f8b12e9ac9924c67fb36f63b336"
@@ -1553,11 +1685,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a"
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
"checksum mime 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e2e00e17be181010a91dbfefb01660b17311059dc8c7f48b9017677721e732bd"
+"checksum mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a637d1ca14eacae06296a008fa7ad955347e34efcb5891cfd8ba05491a37907e"
"checksum mio 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "7da01a5e23070d92d99b1ecd1cd0af36447c6fd44b0fe283c2db199fa136724f"
+"checksum miow 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3e690c5df6b2f60acd45d56378981e827ff8295562fc8d34f573deb267a59cd1"
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
"checksum native-tls 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f74dbadc8b43df7864539cedb7bc91345e532fdd913cfdc23ad94f4d2d40fbc0"
"checksum net2 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)" = "9044faf1413a1057267be51b5afba8eb1090bd2231c693664aa1db716fe1eae0"
+"checksum nix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bfb3ddedaa14746434a02041940495bf11325c22f6d36125d3bdd56090d50a79"
"checksum nix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a2c5afeb0198ec7be8569d666644b574345aad2e95a53baf3a532da3e0f3fb32"
+"checksum notify 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5c3812da3098f210a0bb440f9c008471a031aa4c1de07a264fdd75456c95a4eb"
"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
"checksum num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f8d26da319fb45674985c78f1d1caf99aa4941f785d384a2ae36d0740bc3e2fe"
"checksum num-iter 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "4b226df12c5a59b63569dd57fafb926d91b385dfce33d8074a412411b689d593"
@@ -1584,8 +1720,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e"
"checksum relay 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1576e382688d7e9deecea24417e350d3062d97e32e45d70b1cde65994ff1489a"
"checksum remove_dir_all 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5d2f806b0fcdabd98acd380dc8daef485e22bcb7cddc811d1337967f2528cf5"
+"checksum resolv-conf 0.6.0 (git+https://github.com/tailhook/resolv-conf.git)" = "<none>"
"checksum rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11fb43a206a04116ffd7cfcf9bcb941f8eb6cc7ff667272246b0a1c74259a3cb"
"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"
+"checksum same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfb6eded0b06a0b512c8ddbcf04089138c9b4362c2f696f3c3d76039d68f3637"
"checksum schannel 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "fbaffce35eb61c5b00846e73128b0cd62717e7c0ec46abbec132370d013975b4"
"checksum scoped-tls 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8674d439c964889e2476f474a3bf198cc9e199e77499960893bac5de7e9218a4"
"checksum security-framework 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "dfa44ee9c54ce5eecc9de7d5acbad112ee58755239381f687e564004ba4a2332"
@@ -1599,6 +1737,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum shell-escape 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "dd5cc96481d54583947bfe88bf30c23d53f883c6cd0145368b69989d97b84ef8"
"checksum shell32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9ee04b46101f57121c9da2b151988283b6beb79b34f5bb29a58ee48cb695122c"
"checksum simple-signal 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c1eb01a0c2d12db9e52684e73038eac812494e5937571ae2631f5cf53dc56687"
+"checksum slab 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d807fd58c4181bbabed77cb3b891ba9748241a552bcc5be698faaebefc54f46e"
"checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23"
"checksum slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdeff4cd9ecff59ec7e3744cbca73dfe5ac35c2aedb2cfba8a1c715a18912e9d"
"checksum smallvec 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c8cbcd6df1e117c2210e13ab5109635ad68a929fcbb8964dc965b76cb5ee013"
@@ -1635,6 +1774,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c"
"checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
+"checksum walkdir 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "63636bd0eb3d00ccb8b9036381b526efac53caf112b7783b730ab3f8e44da369"
"checksum widestring 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a212922ea58fbf5044f83663aa4fc6281ff890f1fd7546c0c3f52f5290831781"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
diff --git a/talpid-core/Cargo.toml b/talpid-core/Cargo.toml
index a95d46eb9e..addb9f61d7 100644
--- a/talpid-core/Cargo.toml
+++ b/talpid-core/Cargo.toml
@@ -11,6 +11,7 @@ error-chain = "0.11"
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc", tag = "v8.0.1" }
jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc", tag = "v8.0.1" }
lazy_static = "1.0"
+libc = "0.2.20"
log = "0.4"
uuid = { version = "0.6", features = ["v4"] }
shell-escape = "0.1"
@@ -19,8 +20,9 @@ openvpn-plugin = { version = "0.3", features = ["serde"] }
talpid-ipc = { path = "../talpid-ipc" }
talpid-types = { path = "../talpid-types" }
-[target.'cfg(unix)'.dependencies]
-libc = "0.2.20"
+[target.'cfg(target_os = "linux")'.dependencies]
+notify = "4.0"
+resolv-conf = { git = "https://github.com/tailhook/resolv-conf.git" }
[target.'cfg(target_os = "macos")'.dependencies]
pfctl = "0.1"
@@ -29,5 +31,4 @@ core-foundation = "0.5"
tokio-core = "0.1"
[target.'cfg(windows)'.dependencies]
-libc = "0.2.20"
widestring = "0.3"
diff --git a/talpid-core/src/firewall/linux.rs b/talpid-core/src/firewall/linux.rs
deleted file mode 100644
index 53c3bfb12f..0000000000
--- a/talpid-core/src/firewall/linux.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-use super::{Firewall, SecurityPolicy};
-
-error_chain!{}
-
-/// The Linux implementation for the `Firewall` trait.
-pub struct Netfilter;
-impl Firewall for Netfilter {
- type Error = Error;
-
- fn new() -> Result<Self> {
- Ok(Netfilter)
- }
-
- fn apply_policy(&mut self, _policy: SecurityPolicy) -> Result<()> {
- Ok(())
- }
-
- fn reset_policy(&mut self) -> Result<()> {
- Ok(())
- }
-}
diff --git a/talpid-core/src/firewall/linux/dns.rs b/talpid-core/src/firewall/linux/dns.rs
new file mode 100644
index 0000000000..1dd582afa1
--- /dev/null
+++ b/talpid-core/src/firewall/linux/dns.rs
@@ -0,0 +1,190 @@
+extern crate notify;
+extern crate resolv_conf;
+
+use std::fs::File;
+use std::io::{self, Read, Write};
+use std::net::IpAddr;
+use std::ops::DerefMut;
+use std::sync::{mpsc, Arc, Mutex, MutexGuard};
+use std::thread;
+
+use error_chain::ChainedError;
+
+use self::notify::{RecommendedWatcher, RecursiveMode, Watcher};
+use self::resolv_conf::{Config, ScopedIp};
+
+static RESOLV_CONF_PATH: &str = "/etc/resolv.conf";
+
+error_chain!{
+ errors {
+ ParseResolvConf {
+ description("failed to parse contents of /etc/resolv.conf")
+ }
+
+ ReadResolvConf {
+ description("failed to read /etc/resolv.conf")
+ }
+
+ WatchResolvConf {
+ description("failed to watch /etc/resolv.conf for changes")
+ }
+
+ WriteResolvConf {
+ description("failed to write to /etc/resolv.conf")
+ }
+ }
+}
+
+pub struct DnsSettings {
+ state: Arc<Mutex<Option<State>>>,
+ _watcher: DnsWatcher,
+}
+
+impl DnsSettings {
+ pub fn new() -> Result<Self> {
+ let state = Arc::new(Mutex::new(None));
+ let watcher = DnsWatcher::start(state.clone())?;
+
+ Ok(DnsSettings {
+ state,
+ _watcher: watcher,
+ })
+ }
+
+ pub fn set_dns(&mut self, servers: Vec<IpAddr>) -> Result<()> {
+ let mut state = self.lock_state();
+ let new_state = match state.take() {
+ None => State {
+ backup: read_config()?,
+ desired_dns: servers,
+ },
+ Some(previous_state) => State {
+ backup: previous_state.backup,
+ desired_dns: servers,
+ },
+ };
+
+ let new_config = new_state.desired_config();
+
+ *state = Some(new_state);
+
+ write_config(&new_config)
+ }
+
+ pub fn reset(&mut self) -> Result<()> {
+ if let Some(state) = self.lock_state().take() {
+ write_config(&state.backup)
+ } else {
+ Ok(())
+ }
+ }
+
+ fn lock_state(&self) -> MutexGuard<Option<State>> {
+ self.state
+ .lock()
+ .expect("a thread panicked while using the DNS configuration state")
+ }
+}
+
+struct State {
+ backup: Config,
+ desired_dns: Vec<IpAddr>,
+}
+
+impl State {
+ fn desired_config(&self) -> Config {
+ let mut config = self.backup.clone();
+
+ config.nameservers = self.desired_dns
+ .iter()
+ .map(|&address| ScopedIp::from(address))
+ .collect();
+
+ config
+ }
+}
+
+struct DnsWatcher {
+ _watcher: RecommendedWatcher,
+}
+
+impl DnsWatcher {
+ fn start(state: Arc<Mutex<Option<State>>>) -> Result<Self> {
+ let (event_tx, event_rx) = mpsc::channel();
+ let mut watcher = notify::raw_watcher(event_tx).chain_err(|| ErrorKind::WatchResolvConf)?;
+
+ watcher
+ .watch(RESOLV_CONF_PATH, RecursiveMode::NonRecursive)
+ .chain_err(|| ErrorKind::WatchResolvConf)?;
+
+ thread::spawn(move || Self::event_loop(event_rx, state));
+
+ Ok(DnsWatcher { _watcher: watcher })
+ }
+
+ fn event_loop(events: mpsc::Receiver<notify::RawEvent>, state: Arc<Mutex<Option<State>>>) {
+ for _ in events {
+ let locked_state = state
+ .lock()
+ .expect("a thread panicked while using the DNS configuration state");
+
+ if let Err(error) = Self::update(locked_state) {
+ let chained_error = error
+ .chain_err(|| "Failed to update DNS state after DNS settings have changed.");
+ error!("{}", chained_error.display_chain());
+ }
+ }
+ }
+
+ fn update(mut locked_state: MutexGuard<Option<State>>) -> Result<()> {
+ if let &mut Some(ref mut state) = locked_state.deref_mut() {
+ let mut new_config = read_config()?;
+ let desired_nameservers = state
+ .desired_dns
+ .iter()
+ .map(|&address| ScopedIp::from(address))
+ .collect();
+
+ if new_config.nameservers != desired_nameservers {
+ state.backup = new_config.clone();
+ new_config.nameservers = desired_nameservers;
+
+ write_config(&new_config)
+ } else {
+ new_config.nameservers.clear();
+ new_config.nameservers.append(&mut state.backup.nameservers);
+ state.backup = new_config;
+
+ Ok(())
+ }
+ } else {
+ Ok(())
+ }
+ }
+}
+
+fn read_config() -> Result<Config> {
+ let contents = read_resolv_conf().chain_err(|| ErrorKind::ReadResolvConf)?;
+ let config = Config::parse(&contents).chain_err(|| ErrorKind::ParseResolvConf)?;
+
+ Ok(config)
+}
+
+fn read_resolv_conf() -> io::Result<String> {
+ let mut file = File::open(RESOLV_CONF_PATH)?;
+ let mut contents = String::new();
+
+ file.read_to_string(&mut contents)?;
+
+ Ok(contents)
+}
+
+fn write_config(config: &Config) -> Result<()> {
+ write_resolv_conf(&config.to_string()).chain_err(|| ErrorKind::WriteResolvConf)
+}
+
+fn write_resolv_conf(contents: &str) -> io::Result<()> {
+ let mut file = File::create(RESOLV_CONF_PATH)?;
+
+ file.write_all(contents.as_bytes())
+}
diff --git a/talpid-core/src/firewall/linux/mod.rs b/talpid-core/src/firewall/linux/mod.rs
new file mode 100644
index 0000000000..6b8e213f54
--- /dev/null
+++ b/talpid-core/src/firewall/linux/mod.rs
@@ -0,0 +1,47 @@
+use error_chain::ChainedError;
+
+use super::{Firewall, SecurityPolicy};
+
+mod dns;
+
+use self::dns::DnsSettings;
+
+error_chain! {
+ links {
+ DnsSettings(self::dns::Error, self::dns::ErrorKind) #[doc = "DNS error"];
+ }
+}
+
+/// The Linux implementation for the `Firewall` trait.
+pub struct Netfilter {
+ dns_settings: DnsSettings,
+}
+
+impl Firewall for Netfilter {
+ type Error = Error;
+
+ fn new() -> Result<Self> {
+ Ok(Netfilter {
+ dns_settings: DnsSettings::new()?,
+ })
+ }
+
+ fn apply_policy(&mut self, policy: SecurityPolicy) -> Result<()> {
+ match policy {
+ SecurityPolicy::Connected { tunnel, .. } => {
+ self.dns_settings.set_dns(vec![tunnel.gateway.into()])?;
+ }
+ _ => (),
+ }
+
+ Ok(())
+ }
+
+ fn reset_policy(&mut self) -> Result<()> {
+ if let Err(error) = self.dns_settings.reset() {
+ warn!("Failed to reset DNS settings: {}", error.display_chain());
+ }
+
+ Ok(())
+ }
+}