diff options
author | Antonio Cardace <acardace@redhat.com> | 2020-08-11 18:55:06 +0200 |
---|---|---|
committer | Antonio Cardace <acardace@redhat.com> | 2020-08-21 10:15:31 +0200 |
commit | 6451fe9202904e8110ebdd0b372c1e04ecbdfc87 (patch) | |
tree | 4e8ae57641397212353a60b20b4228701f56723d | |
parent | bc0d4e610f261ed0718aa6f9b0ec87f8f033af44 (diff) | |
download | NetworkManager-ac/dhcp_rust.tar.gz |
ndhcp4: trying sandboxing with rustac/dhcp_rust
-rw-r--r-- | dhcp-client/.gitignore | 1 | ||||
-rw-r--r-- | dhcp-client/Cargo.lock | 718 | ||||
-rw-r--r-- | dhcp-client/Cargo.toml | 20 | ||||
-rw-r--r-- | dhcp-client/build.rs | 43 | ||||
m--------- | dhcp-client/n-dhcp4 | 0 | ||||
-rw-r--r-- | dhcp-client/src/com.redhat.dhcp | 3 | ||||
-rw-r--r-- | dhcp-client/src/com_redhat.rs | 203 | ||||
-rw-r--r-- | dhcp-client/src/main.rs | 233 | ||||
-rw-r--r-- | dhcp-client/wrapper.h | 1 |
9 files changed, 1222 insertions, 0 deletions
diff --git a/dhcp-client/.gitignore b/dhcp-client/.gitignore new file mode 100644 index 0000000000..eb5a316cbd --- /dev/null +++ b/dhcp-client/.gitignore @@ -0,0 +1 @@ +target diff --git a/dhcp-client/Cargo.lock b/dhcp-client/Cargo.lock new file mode 100644 index 0000000000..23bac0d878 --- /dev/null +++ b/dhcp-client/Cargo.lock @@ -0,0 +1,718 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" +dependencies = [ + "memchr", +] + +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "bindgen" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c72a978d268b1d70b0e963217e60fdabd9523a941457a6c42a7315d15c7e89e5" +dependencies = [ + "bitflags", + "cexpr", + "cfg-if", + "clang-sys", + "clap", + "env_logger", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "which", +] + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "cc" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" + +[[package]] +name = "cexpr" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "chainerror" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57f069866bc1ac85f8ad1806c01081ed2be733802f90a6447af76c75bedd9de4" + +[[package]] +name = "clang-sys" +version = "0.29.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe6837df1d5cba2397b835c8530f51723267e16abbf83892e9e5af4f0e5dd10a" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "2.33.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10040cdf04294b565d9e0319955430099ec3813a64c952b86a41200ad714ae48" +dependencies = [ + "ansi_term 0.11.0", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "dhcp-client" +version = "0.1.0" +dependencies = [ + "bindgen", + "libc", + "meson", + "serde", + "serde_derive", + "serde_json", + "unix_socket", + "varlink", + "varlink_generator", +] + +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "hermit-abi" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + +[[package]] +name = "itoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" + +[[package]] +name = "libc" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10" + +[[package]] +name = "libloading" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" +dependencies = [ + "cc", + "winapi 0.3.9", +] + +[[package]] +name = "log" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "meson" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de6e688268407ad0a7c589bf2d7313db6c2079dae5c96df0f2d5903bc6343a91" + +[[package]] +name = "nom" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +dependencies = [ + "memchr", + "version_check", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "peg" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f76678828272f177ac33b7e2ac2e3e73cc6c1cd1e3e387928aa69562fa51367" +dependencies = [ + "peg-macros", + "peg-runtime", +] + +[[package]] +name = "peg-macros" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "636d60acf97633e48d266d7415a9355d4389cea327a193f87df395d88cd2b14d" +dependencies = [ + "peg-runtime", + "proc-macro2", + "quote", +] + +[[package]] +name = "peg-runtime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9555b1514d2d99d78150d3c799d4c357a3e2c2a8062cd108e93a06d9057629c5" + +[[package]] +name = "ppv-lite86" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" + +[[package]] +name = "proc-macro2" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi 0.3.9", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core 0.5.1", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "regex" +version = "1.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "serde" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" + +[[package]] +name = "serde_derive" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "syn" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "tempdir" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" +dependencies = [ + "rand 0.4.6", + "remove_dir_all", +] + +[[package]] +name = "tempfile" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +dependencies = [ + "cfg-if", + "libc", + "rand 0.7.3", + "redox_syscall", + "remove_dir_all", + "winapi 0.3.9", +] + +[[package]] +name = "termcolor" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "uds_windows" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f0497369defbdcde081067715cc9bf9313b695cb9157f45fee823977d4fbb55" +dependencies = [ + "kernel32-sys", + "tempdir", + "winapi 0.2.8", + "ws2_32-sys", +] + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "unix_socket" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aa2700417c405c38f5e6902d699345241c28c0b7ade4abaad71e35a87eb1564" +dependencies = [ + "cfg-if", + "libc", +] + +[[package]] +name = "varlink" +version = "11.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e67bef648cf1968e3864ad093087f5d91fe2467444c75b05f9c566a9db4ec15" +dependencies = [ + "libc", + "serde", + "serde_derive", + "serde_json", + "tempfile", + "uds_windows", + "unix_socket", + "winapi 0.3.9", +] + +[[package]] +name = "varlink_generator" +version = "9.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a56e7bf98749ac88a93149700cbddb9da8b9639b54d2d87958d872a38d28db9" +dependencies = [ + "chainerror", + "getopts", + "proc-macro2", + "quote", + "syn", + "varlink_parser", +] + +[[package]] +name = "varlink_parser" +version = "4.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a63258ed1db0f33125967976d717708be22f165089fca9b12a9c5c42328be4b1" +dependencies = [ + "ansi_term 0.12.1", + "chainerror", + "peg", +] + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "which" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" +dependencies = [ + "libc", +] + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] diff --git a/dhcp-client/Cargo.toml b/dhcp-client/Cargo.toml new file mode 100644 index 0000000000..b633b1dd13 --- /dev/null +++ b/dhcp-client/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "dhcp-client" +version = "0.1.0" +authors = ["Antonio Cardace <acardace@redhat.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[build-dependencies] +bindgen = "0.53.1" +meson = "1.0.0" +varlink_generator = "9.0.0" + +[dependencies] +libc = "0.2.74" +varlink = "11.0.0" +serde = "1.0.115" +serde_derive = "1.0.115" +serde_json = "1.0.57" +unix_socket = "0.5.0" diff --git a/dhcp-client/build.rs b/dhcp-client/build.rs new file mode 100644 index 0000000000..966c965092 --- /dev/null +++ b/dhcp-client/build.rs @@ -0,0 +1,43 @@ +use bindgen; +use meson; +use std::env; +use std::path::PathBuf; +use varlink_generator; + +fn main() { + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + let meson_path = out_path.join("build"); + let build_path_ndhcp4 = meson_path.join("src"); + let build_path_c_siphash = meson_path.join("subprojects/c-siphash/src"); + + meson::build("n-dhcp4", meson_path.to_str().unwrap()); + + bindgen::Builder::default() + // The input header we would like to generate + // bindings for. + .header("wrapper.h") + .clang_arg("-In-dhcp4/src") + // Tell cargo to invalidate the built crate whenever any of the + // included header files changed. + .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + // Finish the builder and generate the bindings. + .generate() + // Unwrap the Result and panic on failure. + .expect("Unable to generate bindings") + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); + + println!("cargo:rerun-if-changed=wrapper.h"); + println!("cargo:rustc-link-lib=static=ndhcp4-private"); + println!("cargo:rustc-link-lib=static=csiphash-private"); + println!( + "cargo:rustc-link-search={}", + build_path_ndhcp4.to_str().unwrap() + ); + println!( + "cargo:rustc-link-search={}", + build_path_c_siphash.to_str().unwrap() + ); + + varlink_generator::cargo_build_tosource("src/com.redhat.dhcp", true); +} diff --git a/dhcp-client/n-dhcp4 b/dhcp-client/n-dhcp4 new file mode 160000 +Subproject 03d38e83e558802a82cb0e4847cb1f1ef75ccd1 diff --git a/dhcp-client/src/com.redhat.dhcp b/dhcp-client/src/com.redhat.dhcp new file mode 100644 index 0000000000..05e5b92b7d --- /dev/null +++ b/dhcp-client/src/com.redhat.dhcp @@ -0,0 +1,3 @@ +interface com.redhat.dhcp + +method Ping(ping: string) -> (pong: string) diff --git a/dhcp-client/src/com_redhat.rs b/dhcp-client/src/com_redhat.rs new file mode 100644 index 0000000000..e903eff2f0 --- /dev/null +++ b/dhcp-client/src/com_redhat.rs @@ -0,0 +1,203 @@ +#![doc = "This file was automatically generated by the varlink rust generator"] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +use serde_derive::{Deserialize, Serialize}; +use serde_json; +use std::io::BufRead; +use std::sync::{Arc, RwLock}; +use varlink::{self, CallTrait}; +#[allow(dead_code)] +#[derive(Clone, PartialEq, Debug)] +pub enum ErrorKind { + Varlink_Error, + VarlinkReply_Error, +} +impl ::std::fmt::Display for ErrorKind { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + match self { + ErrorKind::Varlink_Error => write!(f, "Varlink Error"), + ErrorKind::VarlinkReply_Error => write!(f, "Varlink error reply"), + } + } +} +pub struct Error( + pub ErrorKind, + pub Option<Box<dyn std::error::Error + 'static + Send + Sync>>, + pub Option<&'static str>, +); +impl Error { + #[allow(dead_code)] + pub fn kind(&self) -> &ErrorKind { + &self.0 + } +} +impl From<ErrorKind> for Error { + fn from(e: ErrorKind) -> Self { + Error(e, None, None) + } +} +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + self.1 + .as_ref() + .map(|e| e.as_ref() as &(dyn std::error::Error + 'static)) + } +} +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Display::fmt(&self.0, f) + } +} +impl std::fmt::Debug for Error { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + use std::error::Error as StdError; + if let Some(ref o) = self.2 { + std::fmt::Display::fmt(o, f)?; + } + std::fmt::Debug::fmt(&self.0, f)?; + if let Some(e) = self.source() { + std::fmt::Display::fmt("\nCaused by:\n", f)?; + std::fmt::Debug::fmt(&e, f)?; + } + Ok(()) + } +} +#[allow(dead_code)] +pub type Result<T> = std::result::Result<T, Error>; +impl From<varlink::Error> for Error { + fn from(e: varlink::Error) -> Self { + match e.kind() { + varlink::ErrorKind::VarlinkErrorReply(r) => Error( + ErrorKind::from(r), + Some(Box::from(e)), + Some(concat!(file!(), ":", line!(), ": ")), + ), + _ => Error( + ErrorKind::Varlink_Error, + Some(Box::from(e)), + Some(concat!(file!(), ":", line!(), ": ")), + ), + } + } +} +#[allow(dead_code)] +impl Error { + pub fn source_varlink_kind(&self) -> Option<&varlink::ErrorKind> { + use std::error::Error as StdError; + let mut s: &dyn StdError = self; + while let Some(c) = s.source() { + let k = self + .source() + .and_then(|e| e.downcast_ref::<varlink::Error>()) + .and_then(|e| Some(e.kind())); + if k.is_some() { + return k; + } + s = c; + } + None + } +} +impl From<&varlink::Reply> for ErrorKind { + #[allow(unused_variables)] + fn from(e: &varlink::Reply) -> Self { + match e { + _ => ErrorKind::VarlinkReply_Error, + } + } +} +pub trait VarlinkCallError: varlink::CallTrait {} +impl<'a> VarlinkCallError for varlink::Call<'a> {} +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Ping_Reply { + pub r#pong: String, +} +impl varlink::VarlinkReply for Ping_Reply {} +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Ping_Args { + pub r#ping: String, +} +pub trait Call_Ping: VarlinkCallError { + fn reply(&mut self, r#pong: String) -> varlink::Result<()> { + self.reply_struct(Ping_Reply { r#pong }.into()) + } +} +impl<'a> Call_Ping for varlink::Call<'a> {} +pub trait VarlinkInterface { + fn ping(&self, call: &mut dyn Call_Ping, r#ping: String) -> varlink::Result<()>; + fn call_upgraded( + &self, + _call: &mut varlink::Call, + _bufreader: &mut dyn BufRead, + ) -> varlink::Result<Vec<u8>> { + Ok(Vec::new()) + } +} +pub trait VarlinkClientInterface { + fn ping(&mut self, r#ping: String) -> varlink::MethodCall<Ping_Args, Ping_Reply, Error>; +} +#[allow(dead_code)] +pub struct VarlinkClient { + connection: Arc<RwLock<varlink::Connection>>, +} +impl VarlinkClient { + #[allow(dead_code)] + pub fn new(connection: Arc<RwLock<varlink::Connection>>) -> Self { + VarlinkClient { connection } + } +} +impl VarlinkClientInterface for VarlinkClient { + fn ping(&mut self, r#ping: String) -> varlink::MethodCall<Ping_Args, Ping_Reply, Error> { + varlink::MethodCall::<Ping_Args, Ping_Reply, Error>::new( + self.connection.clone(), + "com.redhat.dhcp.Ping", + Ping_Args { r#ping }, + ) + } +} +#[allow(dead_code)] +pub struct VarlinkInterfaceProxy { + inner: Box<dyn VarlinkInterface + Send + Sync>, +} +#[allow(dead_code)] +pub fn new(inner: Box<dyn VarlinkInterface + Send + Sync>) -> VarlinkInterfaceProxy { + VarlinkInterfaceProxy { inner } +} +impl varlink::Interface for VarlinkInterfaceProxy { + fn get_description(&self) -> &'static str { + "interface com.redhat.dhcp\n\nmethod Ping(ping: string) -> (pong: string)\n" + } + fn get_name(&self) -> &'static str { + "com.redhat.dhcp" + } + fn call_upgraded( + &self, + call: &mut varlink::Call, + bufreader: &mut dyn BufRead, + ) -> varlink::Result<Vec<u8>> { + self.inner.call_upgraded(call, bufreader) + } + fn call(&self, call: &mut varlink::Call) -> varlink::Result<()> { + let req = call.request.unwrap(); + match req.method.as_ref() { + "com.redhat.dhcp.Ping" => { + if let Some(args) = req.parameters.clone() { + let args: Ping_Args = match serde_json::from_value(args) { + Ok(v) => v, + Err(e) => { + let es = format!("{}", e); + let _ = call.reply_invalid_parameter(es.clone()); + return Err( + varlink::context!(varlink::ErrorKind::SerdeJsonDe(es)).into() + ); + } + }; + self.inner.ping(call as &mut dyn Call_Ping, args.r#ping) + } else { + call.reply_invalid_parameter("parameters".into()) + } + } + m => call.reply_method_not_found(String::from(m)), + } + } +} diff --git a/dhcp-client/src/main.rs b/dhcp-client/src/main.rs new file mode 100644 index 0000000000..03573c3cd1 --- /dev/null +++ b/dhcp-client/src/main.rs @@ -0,0 +1,233 @@ +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#[allow(improper_ctypes)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +mod com_redhat; + +use std::convert::From; +use std::env; +use std::ffi::CStr; +use std::fmt; +use std::fs; +use std::io::prelude::*; +use std::marker::Send; +use std::ops::Fn; +use std::ops::{Deref, Drop}; +use std::ptr::null_mut; +use std::sync::Arc; +use std::thread; + +#[repr(u32)] +#[derive(Debug)] +enum NDHCP4Event { + N_DHCP4_CLIENT_EVENT_DOWN, + N_DHCP4_CLIENT_EVENT_OFFER, + N_DHCP4_CLIENT_EVENT_GRANTED, + N_DHCP4_CLIENT_EVENT_RETRACTED, + N_DHCP4_CLIENT_EVENT_EXTENDED, + N_DHCP4_CLIENT_EVENT_EXPIRED, + N_DHCP4_CLIENT_EVENT_CANCELLED, + N_DHCP4_CLIENT_EVENT_LOG, +} + +impl From<u32> for NDHCP4Event { + fn from(u: u32) -> Self { + unsafe { std::mem::transmute::<u32, NDHCP4Event>(u) } + } +} + +impl fmt::Display for NDHCP4Event { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self) + } +} + +struct NDHCP4ClientConfig(*mut NDhcp4ClientConfig); + +impl NDHCP4ClientConfig { + fn new(ifindex: i32, mac_addr: &Vec<u8>) -> Result<NDHCP4ClientConfig, &'static str> { + let mut configp = null_mut(); + + unsafe { + if n_dhcp4_client_config_new(&mut configp) == 0 { + let bcast_mac_addr: [u8; 6] = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]; + let mut client_id = vec![0x1]; + + n_dhcp4_client_config_set_ifindex(configp, ifindex); + n_dhcp4_client_config_set_transport(configp, N_DHCP4_TRANSPORT_ETHERNET); + n_dhcp4_client_config_set_mac(configp, mac_addr.as_ptr(), 6); + n_dhcp4_client_config_set_broadcast_mac(configp, bcast_mac_addr.as_ptr(), 6); + + client_id.extend(mac_addr); + n_dhcp4_client_config_set_client_id( + configp, + client_id.as_ptr(), + client_id.len() as u64, + ); + + Ok(NDHCP4ClientConfig(configp)) + } else { + Err("n_dhcp4_client_config_new() failed") + } + } + } +} + +impl Deref for NDHCP4ClientConfig { + type Target = *mut NDhcp4ClientConfig; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl Drop for NDHCP4ClientConfig { + fn drop(&mut self) { + unsafe { + n_dhcp4_client_config_free(self.0); + } + } +} + +struct NDHCP4Client(Arc<*mut NDhcp4Client>); + +impl NDHCP4Client { + fn new(config: NDHCP4ClientConfig) -> Result<NDHCP4Client, &'static str> { + let mut client = null_mut(); + + unsafe { + if n_dhcp4_client_new(&mut client, *config) == 0 { + n_dhcp4_client_set_log_level(client, 7); + + let mut probe_config = null_mut(); + if n_dhcp4_client_probe_config_new(&mut probe_config) != 0 { + return Err("n_dhcp4_client_probe_config_new() failed"); + } + + n_dhcp4_client_probe_config_set_start_delay(probe_config, 1); + + let mut probe = null_mut(); + if n_dhcp4_client_probe(client, &mut probe, probe_config) != 0 { + return Err("n_dhcp4_client_probe() failed"); + } + + Ok(NDHCP4Client(Arc::new(client))) + } else { + Err("invalid config") + } + } + } + + fn run<F>(&self, f: F) + where + F: Fn(NDHCP4Event, Option<&str>), + { + unsafe { + loop { + if n_dhcp4_client_dispatch(*self.0) == 0 { + let mut event = null_mut(); + + if n_dhcp4_client_pop_event(*self.0, &mut event) == 0 && event != null_mut() { + let mut log = None; + let event_enum = NDHCP4Event::from((*event).event); + + if let NDHCP4Event::N_DHCP4_CLIENT_EVENT_LOG = event_enum { + log = if let Ok(s) = + CStr::from_ptr((*event).__bindgen_anon_1.log.message).to_str() + { + Some(s) + } else { + None + }; + } + + f(event_enum, log); + } + } + } + } + } +} + +impl Drop for NDHCP4Client { + fn drop(&mut self) { + unsafe { + n_dhcp4_client_unref(*self.0); + } + } +} + +unsafe impl Send for NDHCP4Client {} + +struct DHCPClientVarlink; + +impl com_redhat::VarlinkInterface for DHCPClientVarlink { + fn ping(&self, call: &mut dyn com_redhat::Call_Ping, ping: String) -> varlink::Result<()> { + println!("Varlink: {}", ping); + call.reply(ping) + } +} + +fn main() -> std::result::Result<(), Box<dyn std::error::Error>> { + if let Some(iface) = env::args().skip(1).next() { + let mut file = fs::File::open(format!("/sys/class/net/{}/address", iface))?; + let mut contents = String::new(); + file.read_to_string(&mut contents)?; + contents.pop(); + + eprintln!( + "dhcp-client started on {} with mac_addr {}", + iface, contents + ); + + let mac_addr = contents.into_bytes(); + let mut client_id = Vec::from(mac_addr.clone()); + client_id.insert(0, 0x1); + + let mut file = fs::File::open(format!("/sys/class/net/{}/ifindex", iface))?; + let mut contents = String::new(); + file.read_to_string(&mut contents)?; + contents.pop(); + let ifindex = contents.parse::<i32>().unwrap(); + + let client = + NDHCP4Client::new(NDHCP4ClientConfig::new(ifindex, &mac_addr).unwrap()).unwrap(); + + let handle = thread::spawn(move || { + client.run(|event, log_msg| match event { + NDHCP4Event::N_DHCP4_CLIENT_EVENT_LOG if log_msg.is_some() => { + println!("{}", log_msg.unwrap()); + } + _ => println!("Event: {}", event), + }) + }); + + let service = varlink::VarlinkService::new( + "com.redhat.dhcp", + "test service", + "0.1", + "https://gitlab.freedesktop.org/NetworkManager/NetworkManager", + vec![Box::new(com_redhat::new(Box::new(DHCPClientVarlink)))], + ); + + println!("Start varlink unix socket"); + if let Err(e) = varlink::listen( + service, + "unix:com.redhat.dhcp", + &varlink::ListenConfig { + idle_timeout: 0, + ..Default::default() + }, + ) { + eprintln!("{}", e); + } + + // handle.join(); + } else { + eprintln!("no interface name supplied"); + } + Ok(()) +} diff --git a/dhcp-client/wrapper.h b/dhcp-client/wrapper.h new file mode 100644 index 0000000000..db22dec5fd --- /dev/null +++ b/dhcp-client/wrapper.h @@ -0,0 +1 @@ +#include <n-dhcp4.h>
\ No newline at end of file |