aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-11-14 20:15:56 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-11-14 20:15:56 +0100
commit50f31d9a512012a894d2165d6d04e2d387ac92c4 (patch)
tree2102df501ab741d8356350bf3430607fb8ce3e61
parentb45b2310a57e10e81d6fc86a1e8d8b6c35842960 (diff)
move library to its own create0.8.0-dev
-rw-r--r--Cargo.lock220
-rw-r--r--Cargo.toml8
-rw-r--r--src/addr.rs190
-rw-r--r--src/error.rs27
-rw-r--r--src/lib.rs7
-rw-r--r--src/link.rs194
-rw-r--r--src/main.rs35
-rw-r--r--src/route.rs168
-rw-r--r--src/tunnel.rs295
9 files changed, 136 insertions, 1008 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 558e035..c7c6af8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,9 +4,9 @@ version = 3
[[package]]
name = "addr2line"
-version = "0.20.0"
+version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3"
+checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
dependencies = [
"gimli",
]
@@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "anyhow"
-version = "1.0.72"
+version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854"
+checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "autocfg"
@@ -31,9 +31,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
-version = "0.3.68"
+version = "0.3.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12"
+checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
dependencies = [
"addr2line",
"cc",
@@ -45,12 +45,6 @@ dependencies = [
]
[[package]]
-name = "bitfield"
-version = "0.14.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2d7e60934ceec538daadb9d8432424ed043a904d8e0243f3c6446bce549a46ac"
-
-[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -58,21 +52,24 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "byteorder"
-version = "1.4.3"
+version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
+checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
-version = "1.4.0"
+version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
+checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
[[package]]
name = "cc"
-version = "1.0.79"
+version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
+checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
+dependencies = [
+ "libc",
+]
[[package]]
name = "cfg-if"
@@ -127,9 +124,9 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "futures"
-version = "0.3.28"
+version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
+checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335"
dependencies = [
"futures-channel",
"futures-core",
@@ -142,9 +139,9 @@ dependencies = [
[[package]]
name = "futures-channel"
-version = "0.3.28"
+version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
+checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb"
dependencies = [
"futures-core",
"futures-sink",
@@ -152,15 +149,15 @@ dependencies = [
[[package]]
name = "futures-core"
-version = "0.3.28"
+version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
+checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c"
[[package]]
name = "futures-executor"
-version = "0.3.28"
+version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
+checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc"
dependencies = [
"futures-core",
"futures-task",
@@ -169,15 +166,15 @@ dependencies = [
[[package]]
name = "futures-io"
-version = "0.3.28"
+version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
+checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa"
[[package]]
name = "futures-macro"
-version = "0.3.28"
+version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
+checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb"
dependencies = [
"proc-macro2",
"quote",
@@ -186,21 +183,21 @@ dependencies = [
[[package]]
name = "futures-sink"
-version = "0.3.28"
+version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e"
+checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817"
[[package]]
name = "futures-task"
-version = "0.3.28"
+version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
+checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2"
[[package]]
name = "futures-util"
-version = "0.3.28"
+version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
+checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104"
dependencies = [
"futures-channel",
"futures-core",
@@ -216,9 +213,9 @@ dependencies = [
[[package]]
name = "gimli"
-version = "0.27.3"
+version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e"
+checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
[[package]]
name = "hermit-abi"
@@ -228,9 +225,9 @@ checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
[[package]]
name = "ipnet"
-version = "2.8.0"
+version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6"
+checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
[[package]]
name = "itoa"
@@ -240,21 +237,21 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "libc"
-version = "0.2.149"
+version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
+checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "log"
-version = "0.4.19"
+version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
+checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "memchr"
-version = "2.5.0"
+version = "2.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
+checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "memoffset"
@@ -276,9 +273,9 @@ dependencies = [
[[package]]
name = "mio"
-version = "0.8.8"
+version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
+checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0"
dependencies = [
"libc",
"wasi",
@@ -298,9 +295,9 @@ dependencies = [
[[package]]
name = "netlink-packet-route"
-version = "0.17.0"
+version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f6de2fe935f44cbdfcab77dce2150d68eda75be715cd42d4d6f52b0bd4dcc5b1"
+checksum = "053998cea5a306971f88580d0829e90f270f940befd7cf928da179d4187a5a66"
dependencies = [
"anyhow",
"bitflags",
@@ -352,14 +349,13 @@ dependencies = [
[[package]]
name = "nix"
-version = "0.26.2"
+version = "0.26.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a"
+checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
dependencies = [
"bitflags",
"cfg-if",
"libc",
- "static_assertions",
]
[[package]]
@@ -383,9 +379,9 @@ dependencies = [
[[package]]
name = "object"
-version = "0.31.1"
+version = "0.32.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1"
+checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
dependencies = [
"memchr",
]
@@ -404,9 +400,9 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "pin-project-lite"
-version = "0.2.10"
+version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57"
+checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]]
name = "pin-utils"
@@ -416,18 +412,18 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "proc-macro2"
-version = "1.0.66"
+version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
+checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
-version = "1.0.32"
+version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965"
+checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
@@ -462,21 +458,28 @@ dependencies = [
[[package]]
name = "rsdsl_netlinkd"
-version = "0.7.3"
+version = "0.8.0-dev"
dependencies = [
- "bitfield",
- "futures",
- "futures-util",
"ipnet",
- "libc",
- "netlink-packet-route",
"rsdsl_ip_config",
+ "rsdsl_netlinklib",
"rsdsl_pd_config",
- "rtnetlink",
"serde_json",
"signal-hook",
"sysinfo",
"thiserror",
+]
+
+[[package]]
+name = "rsdsl_netlinklib"
+version = "0.1.2"
+source = "git+https://github.com/rsdsl/netlinklib.git#d12f01295f4a108073e7e8f9f50fc57257300950"
+dependencies = [
+ "futures",
+ "libc",
+ "netlink-packet-route",
+ "rtnetlink",
+ "thiserror",
"tokio",
]
@@ -526,18 +529,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "serde"
-version = "1.0.177"
+version = "1.0.192"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "63ba2516aa6bf82e0b19ca8b50019d52df58455d3cf9bdaf6315225fdd0c560a"
+checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.177"
+version = "1.0.192"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "401797fe7833d72109fedec6bfcbe67c0eed9b99772f26eb8afd261f0abc6fd3"
+checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1"
dependencies = [
"proc-macro2",
"quote",
@@ -546,9 +549,9 @@ dependencies = [
[[package]]
name = "serde_json"
-version = "1.0.104"
+version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c"
+checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@@ -576,34 +579,28 @@ dependencies = [
[[package]]
name = "slab"
-version = "0.4.8"
+version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d"
+checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
dependencies = [
"autocfg",
]
[[package]]
name = "socket2"
-version = "0.4.9"
+version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662"
+checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
dependencies = [
"libc",
- "winapi",
+ "windows-sys",
]
[[package]]
-name = "static_assertions"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
-
-[[package]]
name = "syn"
-version = "2.0.27"
+version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0"
+checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
dependencies = [
"proc-macro2",
"quote",
@@ -627,18 +624,18 @@ dependencies = [
[[package]]
name = "thiserror"
-version = "1.0.44"
+version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90"
+checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
-version = "1.0.44"
+version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96"
+checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
dependencies = [
"proc-macro2",
"quote",
@@ -647,11 +644,10 @@ dependencies = [
[[package]]
name = "tokio"
-version = "1.29.1"
+version = "1.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da"
+checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9"
dependencies = [
- "autocfg",
"backtrace",
"bytes",
"libc",
@@ -664,9 +660,9 @@ dependencies = [
[[package]]
name = "unicode-ident"
-version = "1.0.11"
+version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "wasi"
@@ -707,9 +703,9 @@ dependencies = [
[[package]]
name = "windows-targets"
-version = "0.48.1"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f"
+checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
@@ -722,42 +718,42 @@ dependencies = [
[[package]]
name = "windows_aarch64_gnullvm"
-version = "0.48.0"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
+checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_msvc"
-version = "0.48.0"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
+checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_i686_gnu"
-version = "0.48.0"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
+checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_msvc"
-version = "0.48.0"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
+checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_x86_64_gnu"
-version = "0.48.0"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
+checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnullvm"
-version = "0.48.0"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
+checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_msvc"
-version = "0.48.0"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
+checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
diff --git a/Cargo.toml b/Cargo.toml
index 0a260c0..d75fab0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,17 +6,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-bitfield = "0.14.0"
-futures = "0.3.28"
-futures-util = "0.3.27"
ipnet = "2.8.0"
-libc = "0.2.149"
-netlink-packet-route = "0.17.0"
rsdsl_ip_config = { git = "https://github.com/rsdsl/ip_config.git", version = "0.2.4" }
+rsdsl_netlinklib = { git = "https://github.com/rsdsl/netlinklib.git", version = "0.1.2", features = ["blocking"] }
rsdsl_pd_config = { git = "https://github.com/rsdsl/pd_config.git", version = "0.1.0" }
-rtnetlink = "0.13.1"
serde_json = "1.0"
signal-hook = "0.3.17"
sysinfo = "0.29.10"
thiserror = "1.0"
-tokio = { version = "1.26.0", features = ["rt-multi-thread"] }
diff --git a/src/addr.rs b/src/addr.rs
deleted file mode 100644
index 5f276f5..0000000
--- a/src/addr.rs
+++ /dev/null
@@ -1,190 +0,0 @@
-use crate::{Error, Result};
-
-use std::net::IpAddr;
-
-use futures::future;
-use futures_util::TryStreamExt;
-use netlink_packet_route::{AddressMessage, AF_INET, AF_INET6, RT_SCOPE_LINK, RT_SCOPE_UNIVERSE};
-use tokio::runtime::Runtime;
-
-async fn do_flush(link: String) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let id = link.header.index;
-
- let addrs: Vec<AddressMessage> = handle
- .address()
- .get()
- .set_link_index_filter(id)
- .execute()
- .try_collect()
- .await?;
-
- for addr in addrs {
- handle.address().del(addr).execute().await?;
- }
-
- Ok(())
-}
-
-pub fn flush(link: String) -> Result<()> {
- Runtime::new()?.block_on(do_flush(link))
-}
-
-async fn do_flush4(link: String) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let id = link.header.index;
-
- let addrs: Vec<AddressMessage> = handle
- .address()
- .get()
- .set_link_index_filter(id)
- .execute()
- .try_filter(|addr| future::ready(addr.header.family == AF_INET as u8))
- .try_collect()
- .await?;
-
- for addr in addrs {
- handle.address().del(addr).execute().await?;
- }
-
- Ok(())
-}
-
-pub fn flush4(link: String) -> Result<()> {
- Runtime::new()?.block_on(do_flush4(link))
-}
-
-async fn do_flush6(link: String) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let id = link.header.index;
-
- let addrs: Vec<AddressMessage> = handle
- .address()
- .get()
- .set_link_index_filter(id)
- .execute()
- .try_filter(|addr| future::ready(addr.header.family == AF_INET6 as u8))
- .try_collect()
- .await?;
-
- for addr in addrs {
- handle.address().del(addr).execute().await?;
- }
-
- Ok(())
-}
-
-pub fn flush6(link: String) -> Result<()> {
- Runtime::new()?.block_on(do_flush6(link))
-}
-
-async fn do_flush6_global() -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let addrs: Vec<AddressMessage> = handle
- .address()
- .get()
- .execute()
- .try_filter(|addr| {
- future::ready(
- addr.header.family == AF_INET6 as u8 && addr.header.scope == RT_SCOPE_UNIVERSE,
- )
- })
- .try_collect()
- .await?;
-
- for addr in addrs {
- handle.address().del(addr).execute().await?;
- }
-
- Ok(())
-}
-
-pub fn flush6_global() -> Result<()> {
- Runtime::new()?.block_on(do_flush6_global())
-}
-
-async fn do_add(link: String, addr: IpAddr, prefix_len: u8) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let id = link.header.index;
-
- handle.address().add(id, addr, prefix_len).execute().await?;
-
- Ok(())
-}
-
-pub fn add(link: String, addr: IpAddr, prefix_len: u8) -> Result<()> {
- Runtime::new()?.block_on(do_add(link, addr, prefix_len))
-}
-
-async fn do_add_link_local(link: String, addr: IpAddr, prefix_len: u8) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let id = link.header.index;
-
- let mut req = handle.address().add(id, addr, prefix_len);
- req.message_mut().header.scope = RT_SCOPE_LINK;
-
- req.execute().await?;
-
- Ok(())
-}
-
-pub fn add_link_local(link: String, addr: IpAddr, prefix_len: u8) -> Result<()> {
- Runtime::new()?.block_on(do_add_link_local(link, addr, prefix_len))
-}
diff --git a/src/error.rs b/src/error.rs
deleted file mode 100644
index 26e2444..0000000
--- a/src/error.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-use std::{ffi, io, net};
-
-use thiserror::Error;
-
-#[derive(Debug, Error)]
-pub enum Error {
- #[error("link {0} not found")]
- LinkNotFound(String),
- #[error("not enough ipv6 subnets")]
- NotEnoughIpv6Subnets,
-
- #[error("ffi nul: {0}")]
- Nul(#[from] ffi::NulError),
- #[error("io: {0}")]
- Io(#[from] io::Error),
-
- #[error("ipnet prefix len: {0}")]
- IpnetPrefixLen(#[from] ipnet::PrefixLenError),
- #[error("net: parse ip address: {0}")]
- NetAddrParseError(#[from] net::AddrParseError),
- #[error("rtnetlink: {0}")]
- RtNetlink(#[from] rtnetlink::Error),
- #[error("serde_json: {0}")]
- SerdeJson(#[from] serde_json::Error),
-}
-
-pub type Result<T> = std::result::Result<T, Error>;
diff --git a/src/lib.rs b/src/lib.rs
deleted file mode 100644
index 4f06d33..0000000
--- a/src/lib.rs
+++ /dev/null
@@ -1,7 +0,0 @@
-mod error;
-pub use error::*;
-
-pub mod addr;
-pub mod link;
-pub mod route;
-pub mod tunnel;
diff --git a/src/link.rs b/src/link.rs
deleted file mode 100644
index d9fae05..0000000
--- a/src/link.rs
+++ /dev/null
@@ -1,194 +0,0 @@
-use crate::{Error, Result};
-
-use std::num::NonZeroI32;
-use std::thread;
-use std::time::Duration;
-
-use futures_util::TryStreamExt;
-use netlink_packet_route::rtnl::IFF_UP;
-use rtnetlink::Error::NetlinkError;
-use tokio::runtime::Runtime;
-
-#[derive(Clone, Copy, Debug)]
-enum State {
- Up,
- Down,
-}
-
-async fn set(link: String, state: State) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let id = link.header.index;
-
- match state {
- State::Up => handle.link().set(id).up(),
- State::Down => handle.link().set(id).down(),
- }
- .execute()
- .await?;
-
- Ok(())
-}
-
-pub fn up(link: String) -> Result<()> {
- Runtime::new()?.block_on(set(link, State::Up))
-}
-
-pub fn down(link: String) -> Result<()> {
- Runtime::new()?.block_on(set(link, State::Down))
-}
-
-async fn do_is_up(link: String) -> Result<bool> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let is_up = link.header.flags & IFF_UP == IFF_UP;
- Ok(is_up)
-}
-
-pub fn is_up(link: String) -> Result<bool> {
- Runtime::new()?.block_on(do_is_up(link))
-}
-
-async fn do_set_mtu(link: String, mtu: u32) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let id = link.header.index;
-
- handle.link().set(id).mtu(mtu).execute().await?;
- Ok(())
-}
-
-pub fn set_mtu(link: String, mtu: u32) -> Result<()> {
- Runtime::new()?.block_on(do_set_mtu(link, mtu))
-}
-
-async fn do_add_vlan(link: String, parent: String, vlan_id: u16) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let parent = handle
- .link()
- .get()
- .match_name(parent.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(parent))?;
-
- let parent_id = parent.header.index;
-
- handle
- .link()
- .add()
- .vlan(link, parent_id, vlan_id)
- .execute()
- .await?;
-
- Ok(())
-}
-
-pub fn add_vlan(link: String, parent: String, vlan_id: u16) -> Result<()> {
- Runtime::new()?.block_on(do_add_vlan(link, parent, vlan_id))
-}
-
-pub fn wait_up(link: String) -> Result<()> {
- while !match is_up(link.clone()) {
- Ok(v) => v,
- Err(e) => {
- if let Error::LinkNotFound(_) = e {
- false
- } else if let Error::RtNetlink(NetlinkError(ref msg)) = e {
- // Error -19 is "No such device".
- if msg.code == NonZeroI32::new(-19) {
- false
- } else {
- return Err(e);
- }
- } else {
- return Err(e);
- }
- }
- } {
- thread::sleep(Duration::from_secs(1));
- }
-
- Ok(())
-}
-
-async fn do_exists(link: String) -> Result<bool> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let exists = handle
- .link()
- .get()
- .match_name(link)
- .execute()
- .try_next()
- .await
- .is_ok();
-
- Ok(exists)
-}
-
-pub fn exists(link: String) -> Result<bool> {
- Runtime::new()?.block_on(do_exists(link))
-}
-
-pub fn wait_exists(link: String) -> Result<()> {
- while !exists(link.clone())? {
- thread::sleep(Duration::from_secs(1));
- }
-
- Ok(())
-}
-
-async fn do_index(link: String) -> Result<u32> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- Ok(link.header.index)
-}
-
-pub fn index(link: String) -> Result<u32> {
- Runtime::new()?.block_on(do_index(link))
-}
diff --git a/src/main.rs b/src/main.rs
index 70d491d..32f450d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,25 +1,44 @@
-use rsdsl_netlinkd::{addr, link, route};
-use rsdsl_netlinkd::{Error, Result};
+use rsdsl_netlinklib::blocking::{addr, link, route};
use std::fs::{self, File};
-use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
+use std::io;
+use std::net::{self, IpAddr, Ipv4Addr, Ipv6Addr};
use ipnet::Ipv6Net;
use rsdsl_ip_config::DsConfig;
use rsdsl_pd_config::PdConfig;
use signal_hook::{consts::SIGUSR1, iterator::Signals};
use sysinfo::{ProcessExt, Signal, System, SystemExt};
+use thiserror::Error;
const ADDR_AFTR: Ipv4Addr = Ipv4Addr::new(192, 0, 0, 1);
const ADDR_B4: Ipv4Addr = Ipv4Addr::new(192, 0, 0, 2);
const LINK_LOCAL: Ipv6Addr = Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 1);
+#[derive(Debug, Error)]
+enum Error {
+ #[error("not enough ipv6 subnets")]
+ NotEnoughIpv6Subnets,
+
+ #[error("can't parse network address: {0}")]
+ AddrParse(#[from] net::AddrParseError),
+ #[error("io error: {0}")]
+ Io(#[from] io::Error),
+
+ #[error("invalid prefix length: {0}")]
+ PrefixLen(#[from] ipnet::PrefixLenError),
+ #[error("netlinklib error: {0}")]
+ Netlinklib(#[from] rsdsl_netlinklib::Error),
+}
+
+type Result<T> = std::result::Result<T, Error>;
+
fn main() -> Result<()> {
println!("[info] wait for eth0");
link::wait_exists("eth0".into())?;
println!("[info] detect eth0");
- link::up("eth0".into())?;
+ link::set("eth0".into(), true)?;
configure_lan()?;
println!("[info] config eth0 10.128.0.254/24 fe80::1/64");
@@ -39,7 +58,7 @@ fn main() -> Result<()> {
link::wait_exists("eth1".into())?;
println!("[info] detect eth1");
- link::up("eth1".into())?;
+ link::set("eth1".into(), true)?;
configure_modem()?;
println!("[info] config eth1 192.168.1.2/24 (modem)");
@@ -68,7 +87,7 @@ fn create_vlans() -> Result<()> {
let vlan_name = format!("eth0.{}", vlan_id);
link::add_vlan(vlan_name.clone(), "eth0".to_string(), vlan_id as u16)?;
- link::up(vlan_name.clone())?;
+ link::set(vlan_name.clone(), true)?;
addr::flush(vlan_name.clone())?;
}
@@ -112,7 +131,7 @@ fn configure_wan() -> Result<()> {
// of the interface not being present due to not having a PPP session.
if ds_config.v4.is_some() || ds_config.v6.is_some() {
link::set_mtu("ppp0".to_string(), 1492)?;
- link::up("ppp0".to_string())?;
+ link::set("ppp0".to_string(), true)?;
// Deconfigure everything, just to be safe.
addr::flush("ppp0".to_string())?;
@@ -172,7 +191,7 @@ fn configure_wan() -> Result<()> {
inform_radvd();
if link::exists("dslite0".to_string())? {
- link::up("dslite0".to_string())?;
+ link::set("dslite0".to_string(), true)?;
addr::flush("dslite0".to_string())?;
addr::add("dslite0".to_string(), ADDR_B4.into(), 29)?;
diff --git a/src/route.rs b/src/route.rs
deleted file mode 100644
index c4a8f1c..0000000
--- a/src/route.rs
+++ /dev/null
@@ -1,168 +0,0 @@
-use crate::{Error, Result};
-
-use std::net::{Ipv4Addr, Ipv6Addr};
-
-use futures::future;
-use futures_util::TryStreamExt;
-use netlink_packet_route::{RouteMessage, RT_SCOPE_LINK};
-use rtnetlink::IpVersion;
-use tokio::runtime::Runtime;
-
-async fn do_flush4(link: String) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let id = link.header.index;
-
- let routes: Vec<RouteMessage> = handle
- .route()
- .get(IpVersion::V4)
- .execute()
- .try_filter(|route| {
- future::ready(if let Some(ifi) = route.output_interface() {
- ifi == id
- } else {
- false
- })
- })
- .try_collect()
- .await?;
-
- for route in routes {
- handle.route().del(route).execute().await?;
- }
-
- Ok(())
-}
-
-pub fn flush4(link: String) -> Result<()> {
- Runtime::new()?.block_on(do_flush4(link))
-}
-
-async fn do_flush6(link: String) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let id = link.header.index;
-
- let routes: Vec<RouteMessage> = handle
- .route()
- .get(IpVersion::V6)
- .execute()
- .try_filter(|route| {
- future::ready(if let Some(ifi) = route.output_interface() {
- ifi == id
- } else {
- false
- })
- })
- .try_collect()
- .await?;
-
- for route in routes {
- handle.route().del(route).execute().await?;
- }
-
- Ok(())
-}
-
-pub fn flush6(link: String) -> Result<()> {
- Runtime::new()?.block_on(do_flush6(link))
-}
-
-pub fn flush(link: String) -> Result<()> {
- flush4(link.clone())?;
- flush6(link)?;
-
- Ok(())
-}
-
-async fn do_add4(dst: Ipv4Addr, prefix_len: u8, rtr: Option<Ipv4Addr>, link: String) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let id = link.header.index;
-
- let mut add = handle
- .route()
- .add()
- .v4()
- .destination_prefix(dst, prefix_len)
- .output_interface(id);
-
- if let Some(rtr) = rtr {
- add = add.gateway(rtr);
- } else {
- add = add.scope(RT_SCOPE_LINK);
- }
-
- add.execute().await?;
- Ok(())
-}
-
-pub fn add4(dst: Ipv4Addr, prefix_len: u8, rtr: Option<Ipv4Addr>, link: String) -> Result<()> {
- Runtime::new()?.block_on(do_add4(dst, prefix_len, rtr, link))
-}
-
-async fn do_add6(dst: Ipv6Addr, prefix_len: u8, rtr: Option<Ipv6Addr>, link: String) -> Result<()> {
- let (conn, handle, _) = rtnetlink::new_connection()?;
- tokio::spawn(conn);
-
- let link = handle
- .link()
- .get()
- .match_name(link.clone())
- .execute()
- .try_next()
- .await?
- .ok_or(Error::LinkNotFound(link))?;
-
- let id = link.header.index;
-
- let mut add = handle
- .route()
- .add()
- .v6()
- .destination_prefix(dst, prefix_len)
- .output_interface(id);
-
- if let Some(rtr) = rtr {
- add = add.gateway(rtr);
- } else {
- add = add.scope(RT_SCOPE_LINK);
- }
-
- add.execute().await?;
- Ok(())
-}
-
-pub fn add6(dst: Ipv6Addr, prefix_len: u8, rtr: Option<Ipv6Addr>, link: String) -> Result<()> {
- Runtime::new()?.block_on(do_add6(dst, prefix_len, rtr, link))
-}
diff --git a/src/tunnel.rs b/src/tunnel.rs
deleted file mode 100644
index 74655dd..0000000
--- a/src/tunnel.rs
+++ /dev/null
@@ -1,295 +0,0 @@
-use crate::{Error, Result};
-
-use std::ffi::{c_char, c_int, CString};
-use std::io;
-use std::net::{Ipv4Addr, Ipv6Addr};
-
-use bitfield::bitfield;
-
-const SIOCADDTUNNEL: c_int = 0x89F0 + 1;
-const SIOCDELTUNNEL: c_int = 0x89F0 + 2;
-
-/// A handle to a 6in4 tunnel. The interface is automatically deleted on drop.
-#[derive(Debug)]
-pub struct Sit {
- name: String,
-}
-
-impl Drop for Sit {
- fn drop(&mut self) {
- let _ = self.do_delete();
- }
-}
-
-impl Sit {
- pub fn new(name: String, master: String, laddr: Ipv4Addr, raddr: Ipv4Addr) -> Result<Self> {
- let tnlname = CString::new(&*name)?;
- let ifmaster = CString::new(&*master)?;
- let sit0 = CString::new("sit0")?;
-
- let tnlname_signed = unsafe { &*(tnlname.as_bytes() as *const _ as *const [i8]) };
- let mut tnlname_arr = [0i8; libc::IFNAMSIZ];
- for (&i, o) in tnlname_signed.iter().zip(tnlname_arr.iter_mut()) {
- *o = i;
- }
-
- let sit0_signed = unsafe { &*(sit0.as_bytes() as *const _ as *const [i8]) };
- let mut sit0_arr = [0i8; libc::IFNAMSIZ];
- for (&i, o) in sit0_signed.iter().zip(sit0_arr.iter_mut()) {
- *o = i;
- }
-
- let mut vihl = VerIhl::default();
-
- vihl.set_version(4);
- vihl.set_ihl(5);
-
- let p = IpTunnelParm4 {
- name: tnlname_arr,
- link: unsafe { libc::if_nametoindex(ifmaster.as_ptr()) },
- i_flags: 0,
- o_flags: 0,
- i_key: 0,
- o_key: 0,
- iph: IpHdr4 {
- vihl,
- tos: 0,
- tot_len: 0,
- id: 0,
- frag_off: 0,
- check: 0,
- ttl: 64,
- protocol: libc::IPPROTO_IPV6 as u8,
- saddr: u32::from(laddr).to_be(),
- daddr: u32::from(raddr).to_be(),
- },
- };
-
- if p.link == 0 {
- return Err(Error::LinkNotFound(master));
- }
-
- let ifr = IfReq4 {
- name: sit0_arr,
- ifru_data: &p,
- };
-
- let fd = unsafe { libc::socket(libc::AF_INET, libc::SOCK_DGRAM, libc::IPPROTO_IP) };
- if fd < 0 {
- return Err(io::Error::last_os_error().into());
- }
-
- if unsafe { libc::ioctl(fd, SIOCADDTUNNEL, &ifr) } < 0 {
- return Err(io::Error::last_os_error().into());
- }
-
- // Errors are safe to ignore because they don't affect tunnel creation
- // but do leave the program in an inconsistent state.
- unsafe {
- libc::close(fd);
- }
-
- Ok(Self { name })
- }
-
- fn do_delete(&self) -> Result<()> {
- delete_tunnel(&self.name)
- }
-}
-
-/// A handle to a 4in6 tunnel. The interface is automatically deleted on drop.
-#[derive(Debug)]
-pub struct IpIp6 {
- name: String,
-}
-
-impl Drop for IpIp6 {
- fn drop(&mut self) {
- let _ = self.do_delete();
- }
-}
-
-impl IpIp6 {
- pub fn new(name: String, master: String, laddr: Ipv6Addr, raddr: Ipv6Addr) -> Result<Self> {
- let tnlname = CString::new(&*name)?;
- let ifmaster = CString::new(&*master)?;
- let ip6tnl0 = CString::new("ip6tnl0")?;
-
- let tnlname_signed = unsafe { &*(tnlname.as_bytes() as *const _ as *const [i8]) };
- let mut tnlname_arr = [0i8; libc::IFNAMSIZ];
- for (&i, o) in tnlname_signed.iter().zip(tnlname_arr.iter_mut()) {
- *o = i;
- }
-
- let ip6tnl0_signed = unsafe { &*(ip6tnl0.as_bytes() as *const _ as *const [i8]) };
- let mut ip6tnl0_arr = [0i8; libc::IFNAMSIZ];
- for (&i, o) in ip6tnl0_signed.iter().zip(ip6tnl0_arr.iter_mut()) {
- *o = i;
- }
-
- let p = IpTunnelParm6 {
- name: tnlname_arr,
- link: unsafe { libc::if_nametoindex(ifmaster.as_ptr()) },
- i_flags: 0,
- o_flags: 0,
- i_key: 0,
- o_key: 0,
- iph: IpHdr6 {
- saddr: u128::from(laddr).to_be(),
- daddr: u128::from(raddr).to_be(),
- },
- };
-
- if p.link == 0 {
- return Err(Error::LinkNotFound(master));
- }
-
- let ifr = IfReq6 {
- name: ip6tnl0_arr,
- ifru_data: &p,
- };
-
- let fd = unsafe { libc::socket(libc::AF_INET6, libc::SOCK_DGRAM, libc::IPPROTO_IP) };
- if fd < 0 {
- return Err(io::Error::last_os_error().into());
- }
-
- if unsafe { libc::ioctl(fd, SIOCADDTUNNEL, &ifr) } < 0 {
- return Err(io::Error::last_os_error().into());
- }
-
- // Errors are safe to ignore because they don't affect tunnel creation
- // but do leave the program in an inconsistent state.
- unsafe {
- libc::close(fd);
- }
-
- Ok(Self { name })
- }
-
- fn do_delete(&self) -> Result<()> {
- delete_tunnel(&self.name)
- }
-}
-
-fn delete_tunnel(name: &str) -> Result<()> {
- let tnlname = CString::new(name)?;
-
- let tnlname_signed = unsafe { &*(tnlname.as_bytes() as *const _ as *const [i8]) };
- let mut tnlname_arr = [0i8; libc::IFNAMSIZ];
- for (&i, o) in tnlname_signed.iter().zip(tnlname_arr.iter_mut()) {
- *o = i;
- }
-
- let p = IpTunnelParm4 {
- name: tnlname_arr,
- link: 0,
- i_flags: 0,
- o_flags: 0,
- i_key: 0,
- o_key: 0,
- iph: IpHdr4 {
- vihl: VerIhl::default(),
- tos: 0,
- tot_len: 0,
- id: 0,
- frag_off: 0,
- ttl: 0,
- protocol: 0,
- check: 0,
- saddr: 0,
- daddr: 0,
- },
- };
-
- let ifr = IfReq4 {
- name: tnlname_arr,
- ifru_data: &p,
- };
-
- let fd = unsafe { libc::socket(libc::AF_INET6, libc::SOCK_DGRAM, libc::IPPROTO_IP) };
- if fd < 0 {
- return Err(io::Error::last_os_error().into());
- }
-
- if unsafe { libc::ioctl(fd, SIOCDELTUNNEL, &ifr) } < 0 {
- return Err(io::Error::last_os_error().into());
- }
-
- // Errors are safe to ignore because they don't affect tunnel deletion
- // but do leave the program in an inconsistent state.
- unsafe {
- libc::close(fd);
- }
-
- Ok(())
-}
-
-bitfield! {
- #[derive(Default)]
- struct VerIhl(u8);
- impl Debug;
-
- version, set_version: 7, 4;
- ihl, set_ihl: 3, 0;
-}
-
-#[derive(Debug)]
-#[repr(C)]
-struct IpHdr4 {
- vihl: VerIhl,
- tos: u8,
- tot_len: u16,
- id: u16,
- frag_off: u16,
- ttl: u8,
- protocol: u8,
- check: u16,
- saddr: u32,
- daddr: u32,
-}
-
-#[derive(Debug)]
-#[repr(C)]
-struct IpTunnelParm4 {
- name: [c_char; libc::IFNAMSIZ],
- link: u32,
- i_flags: u16,
- o_flags: u16,
- i_key: u32,
- o_key: u32,
- iph: IpHdr4,
-}
-
-#[derive(Debug)]
-#[repr(C)]
-struct IfReq4 {
- name: [c_char; libc::IFNAMSIZ],
- ifru_data: *const IpTunnelParm4,
-}
-
-#[derive(Debug)]
-#[repr(C)]
-struct IpHdr6 {
- saddr: u128,
- daddr: u128,
-}
-
-#[derive(Debug)]
-#[repr(C)]
-struct IpTunnelParm6 {
- name: [c_char; libc::IFNAMSIZ],
- link: u32,
- i_flags: u16,
- o_flags: u16,
- i_key: u32,
- o_key: u32,
- iph: IpHdr6,
-}
-
-#[derive(Debug)]
-#[repr(C)]
-struct IfReq6 {
- name: [c_char; libc::IFNAMSIZ],
- ifru_data: *const IpTunnelParm6,
-}