add(proxyjail): first commit
This commit is contained in:
commit
39bb332ecd
31 files changed
+3634
No files matched your search
@@ -0,0 +1 @@
|
||||
/target
|
||||
Generated
+836
@@ -0,0 +1,836 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
|
||||
|
||||
[[package]]
|
||||
name = "camino"
|
||||
version = "1.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbbad30e4b4c14a39e3cc8aed085a12a327257c316619c93581e017bc52be591"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cargo-platform"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cargo_metadata"
|
||||
version = "0.19.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba"
|
||||
dependencies = [
|
||||
"camino",
|
||||
"cargo-platform",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ff2a8126fff0f8c839080d619675a585e61720bb12d2baceae45769fd66f155"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
||||
|
||||
[[package]]
|
||||
name = "cfg_aliases"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
|
||||
dependencies = [
|
||||
"iana-time-zone",
|
||||
"num-traits",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223"
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"pin-project-lite",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.65"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"log",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
|
||||
|
||||
[[package]]
|
||||
name = "libbpf-cargo"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78da1f54d4070442b5911ea2ace04f0b102ef162a5f2aaaa51ba59b6dc3863fe"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cargo_metadata",
|
||||
"clap",
|
||||
"libbpf-rs",
|
||||
"memmap2",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libbpf-rs"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffef943d6690772a293abe80412ca438c227867cac93448af2518166df1b1a7b"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libbpf-sys",
|
||||
"libc",
|
||||
"vsprintf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libbpf-sys"
|
||||
version = "1.7.0+v1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a109478760b2900aa2a6f2087e9d0de1d9c535b1758602af2845d5d2ccfaed7c"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"nix",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.191"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
|
||||
[[package]]
|
||||
name = "memmap2"
|
||||
version = "0.9.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b0ca1155a9ecc25aa12e8313a119f32edf0255fea2f44839c4ac0a12b2ac157"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.31.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.50.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proxyjail-cli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proxyjail-core",
|
||||
"proxyjail-ebpf",
|
||||
"proxyjail-runtime",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proxyjail-core"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "proxyjail-ebpf"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"libbpf-cargo",
|
||||
"libbpf-rs",
|
||||
"proxyjail-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proxyjail-runtime"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proxyjail-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "1.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.154"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.27.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
|
||||
dependencies = [
|
||||
"pin-project-lite",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"nu-ansi-term",
|
||||
"sharded-slab",
|
||||
"thread_local",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "vsprintf"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aec2f81b75ca063294776b4f7e8da71d1d5ae81c2b1b149c8d89969230265d63"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.62.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-link",
|
||||
"windows-result",
|
||||
"windows-strings",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.60.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.59.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-strings"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||
@@ -0,0 +1,8 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = [
|
||||
"crates/proxyjail-core",
|
||||
"crates/proxyjail-ebpf",
|
||||
"crates/proxyjail-runtime",
|
||||
"apps/proxyjail-cli",
|
||||
]
|
||||
@@ -0,0 +1,26 @@
|
||||
## Build
|
||||
|
||||
```bash
|
||||
cargo check --workspace
|
||||
cargo build --feature ebpf
|
||||
```
|
||||
|
||||
Without the `ebpf` feature, the CLI starts the TCP runtime without an eBPF
|
||||
event producer. This is useful for compiling and testing the runtime pieces,
|
||||
but intercepted connections cannot be correlated or proxied.
|
||||
|
||||
## Current behavior
|
||||
|
||||
- eBPF events and accepted TCP sockets may arrive in either order.
|
||||
- The coordinator stores unmatched items and expires them after
|
||||
`pending_timeout`.
|
||||
- A matched connection opens `original_destination` and relays bytes in both
|
||||
directions.
|
||||
- The blocking relay uses two OS threads per active proxied connection.
|
||||
- The internal standard-library `mpsc::channel` is unbounded. Before production,
|
||||
add queue limits, pending-item limits, and explicit overload behavior.
|
||||
- The CLI currently does not implement child-process supervision or graceful
|
||||
cancellation of the eBPF polling loop; those are application-lifecycle tasks
|
||||
for a later iteration.
|
||||
|
||||
The listener defaults to `127.0.0.1:10000`.
|
||||
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "proxyjail-cli"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
ebpf = ["dep:proxyjail-ebpf", "proxyjail-ebpf/libbpf"]
|
||||
|
||||
[dependencies]
|
||||
proxyjail-core = { path = "../../crates/proxyjail-core" }
|
||||
proxyjail-runtime = { path = "../../crates/proxyjail-runtime" }
|
||||
proxyjail-ebpf = { path = "../../crates/proxyjail-ebpf", optional = true }
|
||||
@@ -0,0 +1,50 @@
|
||||
use std::{
|
||||
io,
|
||||
net::SocketAddr,
|
||||
sync::mpsc,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use proxyjail_core::EbpfEvent;
|
||||
use proxyjail_runtime::std_runtime::{self, StdRuntimeConfig};
|
||||
|
||||
#[cfg(feature = "ebpf")]
|
||||
use std::{path::PathBuf, thread};
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let (event_tx, event_rx) = mpsc::channel::<EbpfEvent>();
|
||||
|
||||
#[cfg(feature = "ebpf")]
|
||||
{
|
||||
let cgroup_path = std::env::var_os("PROXY_EBPF_CGROUP")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| PathBuf::from("/sys/fs/cgroup/ebpf-demo"));
|
||||
|
||||
let ebpf_config = proxyjail_ebpf::EbpfConfig {
|
||||
cgroup_path,
|
||||
..proxyjail_ebpf::EbpfConfig::default()
|
||||
};
|
||||
|
||||
thread::Builder::new()
|
||||
.name("proxyjail-ebpf-poller".into())
|
||||
.spawn(move || {
|
||||
if let Err(err) = proxyjail_ebpf::run(ebpf_config, event_tx) {
|
||||
eprintln!("eBPF poller failed: {err:#}");
|
||||
}
|
||||
})?;
|
||||
}
|
||||
|
||||
// Without the `ebpf` feature this CLI is useful for developing/testing
|
||||
// the runtime, but it has no event producer and cannot match connections.
|
||||
#[cfg(not(feature = "ebpf"))]
|
||||
drop(event_tx);
|
||||
|
||||
let config = StdRuntimeConfig {
|
||||
listen_addr: SocketAddr::from(([127, 0, 0, 1], 10000)),
|
||||
connect_timeout: Duration::from_secs(5),
|
||||
pending_timeout: Duration::from_secs(10),
|
||||
cleanup_interval: Duration::from_millis(250),
|
||||
};
|
||||
|
||||
std_runtime::run(config, event_rx)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "proxyjail-core"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,160 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
net::SocketAddr,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use crate::EbpfEvent;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum PendingSide {
|
||||
EbpfEvent,
|
||||
TcpConnection,
|
||||
}
|
||||
|
||||
pub struct MatchedConnection<C> {
|
||||
pub event: EbpfEvent,
|
||||
pub stream: C,
|
||||
pub peer_addr: SocketAddr,
|
||||
}
|
||||
|
||||
pub enum CorrelationOutcome<C> {
|
||||
/// The item was saved until its counterpart arrives.
|
||||
Pending {
|
||||
key: SocketAddr,
|
||||
side: PendingSide,
|
||||
},
|
||||
/// Both observations are now available.
|
||||
Matched(MatchedConnection<C>),
|
||||
/// Another unmatched item with the same key was already pending.
|
||||
/// The duplicate item is dropped.
|
||||
Duplicate {
|
||||
key: SocketAddr,
|
||||
side: PendingSide,
|
||||
},
|
||||
}
|
||||
|
||||
struct Pending<T> {
|
||||
value: T,
|
||||
since: Instant,
|
||||
}
|
||||
|
||||
pub struct Correlator<C> {
|
||||
pending_events: HashMap<SocketAddr, Pending<EbpfEvent>>,
|
||||
pending_connections: HashMap<SocketAddr, Pending<C>>,
|
||||
}
|
||||
|
||||
impl<C> Default for Correlator<C> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pending_events: HashMap::new(),
|
||||
pending_connections: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ExpiredItems {
|
||||
pub events: Vec<SocketAddr>,
|
||||
pub connections: Vec<SocketAddr>,
|
||||
}
|
||||
|
||||
impl<C> Correlator<C> {
|
||||
pub fn on_event(&mut self, event: EbpfEvent) -> CorrelationOutcome<C> {
|
||||
let key = event.client;
|
||||
|
||||
if let Some(pending) = self.pending_connections.remove(&key) {
|
||||
return CorrelationOutcome::Matched(MatchedConnection {
|
||||
event,
|
||||
stream: pending.value,
|
||||
peer_addr: key,
|
||||
});
|
||||
}
|
||||
|
||||
if self.pending_events.contains_key(&key) {
|
||||
return CorrelationOutcome::Duplicate {
|
||||
key,
|
||||
side: PendingSide::EbpfEvent,
|
||||
};
|
||||
}
|
||||
|
||||
self.pending_events.insert(
|
||||
key,
|
||||
Pending {
|
||||
value: event,
|
||||
since: Instant::now(),
|
||||
},
|
||||
);
|
||||
|
||||
CorrelationOutcome::Pending {
|
||||
key,
|
||||
side: PendingSide::EbpfEvent,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_connection(
|
||||
&mut self,
|
||||
stream: C,
|
||||
peer_addr: SocketAddr,
|
||||
) -> CorrelationOutcome<C> {
|
||||
if let Some(pending) = self.pending_events.remove(&peer_addr) {
|
||||
return CorrelationOutcome::Matched(MatchedConnection {
|
||||
event: pending.value,
|
||||
stream,
|
||||
peer_addr,
|
||||
});
|
||||
}
|
||||
|
||||
if self.pending_connections.contains_key(&peer_addr) {
|
||||
// `stream` is dropped here, closing the duplicate connection.
|
||||
return CorrelationOutcome::Duplicate {
|
||||
key: peer_addr,
|
||||
side: PendingSide::TcpConnection,
|
||||
};
|
||||
}
|
||||
|
||||
self.pending_connections.insert(
|
||||
peer_addr,
|
||||
Pending {
|
||||
value: stream,
|
||||
since: Instant::now(),
|
||||
},
|
||||
);
|
||||
|
||||
CorrelationOutcome::Pending {
|
||||
key: peer_addr,
|
||||
side: PendingSide::TcpConnection,
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove unmatched observations older than `ttl`.
|
||||
/// Removing a pending TCP connection drops its stream.
|
||||
pub fn expire(&mut self, now: Instant, ttl: Duration) -> ExpiredItems {
|
||||
let mut expired = ExpiredItems::default();
|
||||
|
||||
self.pending_events.retain(|key, pending| {
|
||||
let keep = now.duration_since(pending.since) < ttl;
|
||||
if !keep {
|
||||
expired.events.push(*key);
|
||||
}
|
||||
keep
|
||||
});
|
||||
|
||||
self.pending_connections.retain(|key, pending| {
|
||||
let keep = now.duration_since(pending.since) < ttl;
|
||||
if !keep {
|
||||
expired.connections.push(*key);
|
||||
}
|
||||
keep
|
||||
});
|
||||
|
||||
expired
|
||||
}
|
||||
|
||||
pub fn pending_counts(&self) -> (usize, usize) {
|
||||
(
|
||||
self.pending_events.len(),
|
||||
self.pending_connections.len(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
/// A fully assembled observation of one outgoing connection.
|
||||
///
|
||||
/// `client` must be the exact peer endpoint that the local TCP listener will
|
||||
/// observe through `TcpStream::peer_addr()`. It is the correlation key.
|
||||
/// `original_destination` is where the proxy should open the upstream socket.
|
||||
///
|
||||
/// The eBPF layer should publish one `EbpfEvent` only after it has collected
|
||||
/// enough information to populate both endpoints reliably.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EbpfEvent {
|
||||
pub pid_tgid: u64,
|
||||
pub client: SocketAddr,
|
||||
pub original_destination: SocketAddr,
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
mod correlator;
|
||||
mod event;
|
||||
|
||||
pub use correlator::{
|
||||
CorrelationOutcome, Correlator, ExpiredItems, MatchedConnection, PendingSide,
|
||||
};
|
||||
pub use event::EbpfEvent;
|
||||
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "proxyjail-ebpf"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
# Enable the libbpf loader after placing the generated redirect skeleton at
|
||||
libbpf = ["dep:anyhow", "dep:libbpf-rs"]
|
||||
|
||||
[dependencies]
|
||||
proxyjail-core = { path = "../proxyjail-core" }
|
||||
anyhow = { version = "1", optional = true }
|
||||
libbpf-rs = { version = "0.27.2", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
libbpf-cargo = "0.27.2"
|
||||
@@ -0,0 +1,21 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
|
||||
int get_set_sk_priority(void *ctx)
|
||||
{
|
||||
int prio;
|
||||
|
||||
/* Verify that context allows calling bpf_getsockopt and
|
||||
* bpf_setsockopt by reading and writing back socket
|
||||
* priority.
|
||||
*/
|
||||
|
||||
if (bpf_getsockopt(ctx, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)))
|
||||
return 0;
|
||||
if (bpf_setsockopt(ctx, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef PROXY_EBPF_EVENT_H
|
||||
#define PROXY_EBPF_EVENT_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
/*
|
||||
* Original destination metadata stored against the client socket.
|
||||
*
|
||||
* This storage is created in connect4 and retrieved later
|
||||
* from the sockops callback.
|
||||
*/
|
||||
struct svc_addr {
|
||||
__be32 addr;
|
||||
__be16 port;
|
||||
__u16 _pad;
|
||||
__u64 pid_tgid;
|
||||
};
|
||||
|
||||
/*
|
||||
* Ring-buffer event.
|
||||
*
|
||||
* IMPORTANT: Keep this layout synchronized with the Rust parser.
|
||||
*
|
||||
* Total size: 24 bytes.
|
||||
*
|
||||
* Offset:
|
||||
* 0 - 8: pid_tgid
|
||||
* 8 - 12: client_ip4
|
||||
* 12 - 14: client_port
|
||||
* 14 - 16: padding
|
||||
* 16 - 20: original_ip4
|
||||
* 20 - 22: original_port
|
||||
* 22 - 24: padding
|
||||
*/
|
||||
struct proxy_event {
|
||||
__u64 pid_tgid;
|
||||
|
||||
__be32 client_ip4;
|
||||
__be16 client_port;
|
||||
__u16 _pad0;
|
||||
|
||||
__be32 original_ip4;
|
||||
__be16 original_port;
|
||||
__u16 _pad1;
|
||||
};
|
||||
|
||||
#endif /* PROXY_EBPF_EVENT_H */
|
||||
@@ -0,0 +1,176 @@
|
||||
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <linux/bpf.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/in6.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_endian.h>
|
||||
|
||||
#include "bpf_sockopt_helpers.h"
|
||||
#include "event.h"
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
|
||||
/*
|
||||
* Per-socket metadata.
|
||||
*/
|
||||
struct {
|
||||
__uint(type, BPF_MAP_TYPE_SK_STORAGE);
|
||||
__uint(map_flags, BPF_F_NO_PREALLOC);
|
||||
__type(key, int);
|
||||
__type(value, struct svc_addr);
|
||||
} service_mapping SEC(".maps");
|
||||
|
||||
/*
|
||||
* Userspace event channel.
|
||||
*/
|
||||
struct {
|
||||
__uint(type, BPF_MAP_TYPE_RINGBUF);
|
||||
__uint(max_entries, 1 << 20);
|
||||
} events SEC(".maps");
|
||||
|
||||
|
||||
/*
|
||||
* Intercept outgoing IPv4 TCP connections.
|
||||
*
|
||||
* Preserve the original destination and redirect the connection
|
||||
* to the local proxy listener.
|
||||
*/
|
||||
SEC("cgroup/connect4")
|
||||
int connect4(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
struct svc_addr *orig;
|
||||
|
||||
// This proxy currently handles TCP only.
|
||||
if (ctx->type != SOCK_STREAM ||
|
||||
ctx->protocol != IPPROTO_TCP)
|
||||
return 1;
|
||||
|
||||
orig = bpf_sk_storage_get(
|
||||
&service_mapping,
|
||||
ctx->sk,
|
||||
0,
|
||||
BPF_SK_STORAGE_GET_F_CREATE
|
||||
);
|
||||
|
||||
// Fail closed if we cannot preserve the original destination.
|
||||
if (!orig)
|
||||
return 0;
|
||||
|
||||
orig->addr = ctx->user_ip4;
|
||||
orig->port = (__be16)ctx->user_port;
|
||||
orig->pid_tgid = bpf_get_current_pid_tgid();
|
||||
orig->_pad = 0;
|
||||
|
||||
// Redirect to local proxy.
|
||||
ctx->user_ip4 = bpf_htonl(0x7f000001);
|
||||
ctx->user_port = bpf_htons(10000);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Capture the actual local endpoint after TCP has allocated
|
||||
* its source port.
|
||||
*
|
||||
* This callback runs for the outgoing TCP socket.
|
||||
*/
|
||||
SEC("sockops")
|
||||
int proxy_sockops(struct bpf_sock_ops *skops)
|
||||
{
|
||||
struct svc_addr *orig;
|
||||
struct proxy_event *event;
|
||||
|
||||
if (skops->op != BPF_SOCK_OPS_TCP_CONNECT_CB)
|
||||
return 1;
|
||||
|
||||
if (skops->family != AF_INET)
|
||||
return 1;
|
||||
|
||||
if (!skops->sk)
|
||||
return 1;
|
||||
|
||||
// Retrieve metadata saved by connect4.
|
||||
orig = bpf_sk_storage_get(
|
||||
&service_mapping,
|
||||
skops->sk,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
// Ignore connections that were not intercepted.
|
||||
if (!orig)
|
||||
return 1;
|
||||
|
||||
event = bpf_ringbuf_reserve(
|
||||
&events,
|
||||
sizeof(*event),
|
||||
0
|
||||
);
|
||||
|
||||
/*
|
||||
* SOCK_OPS callback return values cannot abort the connection.
|
||||
* If the ring buffer is full, this event is lost.
|
||||
*/
|
||||
if (!event)
|
||||
return 1;
|
||||
|
||||
event->pid_tgid = orig->pid_tgid;
|
||||
|
||||
// Local endpoint of the redirected client socket.
|
||||
event->client_ip4 = skops->local_ip4;
|
||||
|
||||
// SOCK_OPS local_port is host byte order.
|
||||
// Store it in network byte order for userspace.
|
||||
event->client_port = bpf_htons(
|
||||
(__u16)skops->local_port
|
||||
);
|
||||
|
||||
event->_pad0 = 0;
|
||||
|
||||
// Original destination saved by connect4.
|
||||
event->original_ip4 = orig->addr;
|
||||
event->original_port = orig->port;
|
||||
|
||||
event->_pad1 = 0;
|
||||
|
||||
bpf_ringbuf_submit(event, 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Expose the original destination through getpeername().
|
||||
*/
|
||||
SEC("cgroup/getpeername4")
|
||||
int getpeername4(struct bpf_sock_addr *ctx)
|
||||
{
|
||||
struct svc_addr *orig;
|
||||
|
||||
if (!get_set_sk_priority(ctx))
|
||||
return 1;
|
||||
|
||||
orig = bpf_sk_storage_get(
|
||||
&service_mapping,
|
||||
ctx->sk,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
if (!orig)
|
||||
return 1;
|
||||
|
||||
ctx->user_ip4 = orig->addr;
|
||||
ctx->user_port = orig->port;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use libbpf_cargo::SkeletonBuilder;
|
||||
|
||||
fn main() {
|
||||
let out_dir = PathBuf::from(
|
||||
env::var_os("OUT_DIR").expect("OUT_DIR must be set")
|
||||
);
|
||||
|
||||
let out = out_dir.join("redirect_cgroup.skel.rs");
|
||||
|
||||
SkeletonBuilder::new()
|
||||
.source("bpf/redirect_cgroup.bpf.c")
|
||||
.build_and_generate(&out)
|
||||
.expect("failed to build BPF program and generate skeleton");
|
||||
|
||||
println!("cargo:rerun-if-changed=bpf/redirect_cgroup.bpf.c");
|
||||
println!("cargo:rerun-if-changed=bpf/bpf_sockopt_helpers.h");
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
//! eBPF event producer for the proxy workspace.
|
||||
//!
|
||||
//! The libbpf-backed loader is opt-in because it requires Linux, libbpf build
|
||||
//! dependencies, and the generated `redirect_cgroup.skel.rs` skeleton.
|
||||
|
||||
#[cfg(feature = "libbpf")]
|
||||
mod libbpf;
|
||||
|
||||
#[cfg(feature = "libbpf")]
|
||||
pub use libbpf::{run, EbpfConfig};
|
||||
@@ -0,0 +1,137 @@
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
fs::File,
|
||||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||
os::fd::AsRawFd,
|
||||
path::PathBuf,
|
||||
sync::mpsc::Sender,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use libbpf_rs::{
|
||||
skel::{OpenSkel, SkelBuilder},
|
||||
RingBufferBuilder,
|
||||
};
|
||||
|
||||
use proxyjail_core::EbpfEvent;
|
||||
|
||||
// Generated from the BPF object named `redirect`.
|
||||
mod redirect {
|
||||
include!(concat!(env!("OUT_DIR"), "/redirect_cgroup.skel.rs"));
|
||||
}
|
||||
|
||||
use redirect::*;
|
||||
|
||||
/// Configuration for the blocking libbpf ring-buffer poller.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EbpfConfig {
|
||||
/// Cgroup v2 directory to which the cgroup programs are attached.
|
||||
pub cgroup_path: PathBuf,
|
||||
/// Maximum time spent in one ring-buffer poll call before returning.
|
||||
pub poll_interval: Duration,
|
||||
}
|
||||
|
||||
impl Default for EbpfConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
cgroup_path: PathBuf::from("/sys/fs/cgroup/ebpf-demo"),
|
||||
poll_interval: Duration::from_millis(100),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ABI shared with the BPF program in bpf/event.h.
|
||||
// C layout: u64, be32, be16, 2-byte padding, be32, be16, 2-byte tail padding.
|
||||
const EVENT_SIZE: usize = 24;
|
||||
|
||||
/// Load and attach the redirect programs, then publish decoded ring-buffer
|
||||
/// events to the proxy runtime.
|
||||
///
|
||||
/// This function blocks while polling the ring buffer. Run it on a dedicated
|
||||
/// OS thread; do not call it from a latency-sensitive thread.
|
||||
pub fn run(config: EbpfConfig, event_tx: Sender<EbpfEvent>) -> Result<()> {
|
||||
if config.poll_interval.is_zero() {
|
||||
anyhow::bail!("poll_interval must be non-zero");
|
||||
}
|
||||
|
||||
let builder = RedirectCgroupSkelBuilder::default();
|
||||
let mut open_object = std::mem::MaybeUninit::uninit();
|
||||
let open_skel = builder.open(&mut open_object)?;
|
||||
let mut skel = open_skel.load()?;
|
||||
|
||||
// Keep the cgroup file descriptor alive while the attached links exist.
|
||||
let cgroup = File::open(&config.cgroup_path)
|
||||
.with_context(|| format!("opening cgroup {}", config.cgroup_path.display()))?;
|
||||
let cgroup_fd = cgroup.as_raw_fd();
|
||||
|
||||
let progs = &mut skel.progs;
|
||||
let _connect4 = progs
|
||||
.connect4
|
||||
.attach_cgroup(cgroup_fd)
|
||||
.context("attaching connect4 cgroup program")?;
|
||||
let _getpeername4 = progs
|
||||
.getpeername4
|
||||
.attach_cgroup(cgroup_fd)
|
||||
.context("attaching getpeername4 cgroup program")?;
|
||||
let _sockops = progs
|
||||
.proxy_sockops
|
||||
.attach_cgroup(cgroup_fd)
|
||||
.context("attaching sockops cgroup program")?;
|
||||
|
||||
let mut ring_buffer_builder = RingBufferBuilder::new();
|
||||
ring_buffer_builder.add(&skel.maps.events, move |data| {
|
||||
let Some(event) = parse_event(data) else {
|
||||
eprintln!("Ignoring malformed eBPF event ({} bytes)", data.len());
|
||||
return 0;
|
||||
};
|
||||
|
||||
match event_tx.send(event) {
|
||||
Ok(()) => 0,
|
||||
Err(err) => {
|
||||
eprintln!("Proxy runtime receiver disconnected: {err}");
|
||||
// A negative callback result stops ring-buffer consumption.
|
||||
-1
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
||||
let ring_buffer = ring_buffer_builder.build()?;
|
||||
|
||||
println!(
|
||||
"eBPF programs attached to {}; polling ring buffer",
|
||||
config.cgroup_path.display()
|
||||
);
|
||||
|
||||
loop {
|
||||
ring_buffer.poll(config.poll_interval)?;
|
||||
}
|
||||
}
|
||||
|
||||
/// Decode the fixed-size event emitted by the BPF program.
|
||||
///
|
||||
/// The source endpoint must be the endpoint visible to the proxy listener,
|
||||
/// such that it matches `TcpStream::peer_addr()` exactly.
|
||||
fn parse_event(data: &[u8]) -> Option<EbpfEvent> {
|
||||
if data.len() < EVENT_SIZE {
|
||||
return None;
|
||||
}
|
||||
|
||||
let pid_tgid = u64::from_ne_bytes(data[0..8].try_into().ok()?);
|
||||
|
||||
let client_ip = Ipv4Addr::from(<[u8; 4]>::try_from(&data[8..12]).ok()?);
|
||||
let client_port = u16::from_be_bytes(data[12..14].try_into().ok()?);
|
||||
|
||||
// Bytes 14..16 are ABI padding.
|
||||
let original_ip = Ipv4Addr::from(<[u8; 4]>::try_from(&data[16..20]).ok()?);
|
||||
let original_port = u16::from_be_bytes(data[20..22].try_into().ok()?);
|
||||
|
||||
Some(EbpfEvent {
|
||||
pid_tgid,
|
||||
client: SocketAddr::V4(SocketAddrV4::new(client_ip, client_port)),
|
||||
original_destination: SocketAddr::V4(SocketAddrV4::new(
|
||||
original_ip,
|
||||
original_port,
|
||||
)),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "proxyjail-runtime"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
proxyjail-core = { path = "../proxyjail-core" }
|
||||
@@ -0,0 +1 @@
|
||||
pub mod std_runtime;
|
||||
@@ -0,0 +1,40 @@
|
||||
use std::{
|
||||
io,
|
||||
net::SocketAddr,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StdRuntimeConfig {
|
||||
pub listen_addr: SocketAddr,
|
||||
pub connect_timeout: Duration,
|
||||
pub pending_timeout: Duration,
|
||||
pub cleanup_interval: Duration,
|
||||
}
|
||||
|
||||
impl Default for StdRuntimeConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
listen_addr: SocketAddr::from(([127, 0, 0, 1], 10000)),
|
||||
connect_timeout: Duration::from_secs(5),
|
||||
pending_timeout: Duration::from_secs(10),
|
||||
cleanup_interval: Duration::from_millis(250),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StdRuntimeConfig {
|
||||
pub(super) fn validate(&self) -> io::Result<()> {
|
||||
if self.connect_timeout.is_zero()
|
||||
|| self.pending_timeout.is_zero()
|
||||
|| self.cleanup_interval.is_zero()
|
||||
{
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"timeouts and cleanup_interval must be non-zero",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
use std::{
|
||||
io,
|
||||
net::TcpStream,
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use proxyjail_core::MatchedConnection;
|
||||
|
||||
use super::relay;
|
||||
|
||||
pub(super) fn dispatch(
|
||||
matched: MatchedConnection<TcpStream>,
|
||||
connect_timeout: Duration,
|
||||
) -> io::Result<()> {
|
||||
let peer_addr = matched.peer_addr;
|
||||
let destination = matched.event.original_destination;
|
||||
let pid_tgid = matched.event.pid_tgid;
|
||||
|
||||
thread::Builder::new()
|
||||
.name(format!("proxyjail-connection-{peer_addr}"))
|
||||
.spawn(move || {
|
||||
println!(
|
||||
"Matched client {peer_addr} (pid/tgid={pid_tgid}); connecting to {destination}"
|
||||
);
|
||||
|
||||
match TcpStream::connect_timeout(
|
||||
&destination,
|
||||
connect_timeout,
|
||||
) {
|
||||
Ok(upstream) => {
|
||||
if let Err(err) = relay::relay(
|
||||
matched.stream,
|
||||
upstream,
|
||||
) {
|
||||
eprintln!(
|
||||
"Relay failed for {peer_addr} -> {destination}: {err}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Err(err) => {
|
||||
eprintln!(
|
||||
"Upstream connection to {destination} failed: {err}"
|
||||
);
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
use std::{
|
||||
io,
|
||||
net::TcpStream,
|
||||
sync::mpsc::{Receiver, RecvTimeoutError},
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use proxyjail_core::{
|
||||
CorrelationOutcome,
|
||||
Correlator,
|
||||
PendingSide,
|
||||
};
|
||||
|
||||
use super::{
|
||||
config::StdRuntimeConfig,
|
||||
connection,
|
||||
message::RuntimeMessage,
|
||||
};
|
||||
|
||||
pub(super) fn run(
|
||||
config: &StdRuntimeConfig,
|
||||
rx: Receiver<RuntimeMessage>,
|
||||
) -> io::Result<()> {
|
||||
let mut correlator: Correlator<TcpStream> = Correlator::default();
|
||||
|
||||
loop {
|
||||
match rx.recv_timeout(config.cleanup_interval) {
|
||||
Ok(RuntimeMessage::EbpfEvent(event)) => {
|
||||
let outcome = correlator.on_event(event);
|
||||
handle_outcome(outcome, config)?;
|
||||
}
|
||||
|
||||
Ok(RuntimeMessage::AcceptedConnection {
|
||||
stream,
|
||||
peer_addr,
|
||||
}) => {
|
||||
let outcome = correlator.on_connection(stream, peer_addr);
|
||||
handle_outcome(outcome, config)?;
|
||||
}
|
||||
|
||||
Ok(RuntimeMessage::ListenerFailed(message)) => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
message,
|
||||
));
|
||||
}
|
||||
|
||||
Err(RecvTimeoutError::Timeout) => {}
|
||||
|
||||
Err(RecvTimeoutError::Disconnected) => {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
// Expire unmatched observations.
|
||||
let expired = correlator.expire(
|
||||
Instant::now(),
|
||||
config.pending_timeout,
|
||||
);
|
||||
|
||||
for key in expired.events {
|
||||
eprintln!(
|
||||
"Timed out waiting for TCP connection matching eBPF event: {key}"
|
||||
);
|
||||
}
|
||||
|
||||
for key in expired.connections {
|
||||
eprintln!(
|
||||
"Timed out waiting for eBPF event matching TCP connection: {key}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_outcome(
|
||||
outcome: CorrelationOutcome<TcpStream>,
|
||||
config: &StdRuntimeConfig,
|
||||
) -> io::Result<()> {
|
||||
match outcome {
|
||||
CorrelationOutcome::Pending { key, side } => {
|
||||
match side {
|
||||
PendingSide::EbpfEvent => {
|
||||
println!(
|
||||
"Waiting for TCP connection matching {key}"
|
||||
);
|
||||
}
|
||||
|
||||
PendingSide::TcpConnection => {
|
||||
println!(
|
||||
"Waiting for eBPF event matching {key}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CorrelationOutcome::Duplicate { key, side } => {
|
||||
eprintln!(
|
||||
"Duplicate pending {side:?} for {key}; dropping duplicate"
|
||||
);
|
||||
}
|
||||
|
||||
CorrelationOutcome::Matched(matched) => {
|
||||
connection::dispatch(matched, config.connect_timeout)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
use std::{
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
mpsc::{Receiver, RecvTimeoutError, Sender},
|
||||
Arc,
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use proxyjail_core::EbpfEvent;
|
||||
|
||||
use super::message::RuntimeMessage;
|
||||
|
||||
const EVENT_RECV_INTERVAL: Duration = Duration::from_millis(100);
|
||||
|
||||
pub(super) fn forward_events(
|
||||
event_rx: Receiver<EbpfEvent>,
|
||||
tx: Sender<RuntimeMessage>,
|
||||
stopping: Arc<AtomicBool>,
|
||||
) {
|
||||
while !stopping.load(Ordering::Acquire) {
|
||||
match event_rx.recv_timeout(EVENT_RECV_INTERVAL) {
|
||||
Ok(event) => {
|
||||
if tx.send(RuntimeMessage::EbpfEvent(event)).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Err(RecvTimeoutError::Timeout) => {}
|
||||
|
||||
Err(RecvTimeoutError::Disconnected) => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
use std::{
|
||||
io,
|
||||
net::TcpListener,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
mpsc::Sender,
|
||||
Arc,
|
||||
},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use super::message::RuntimeMessage;
|
||||
|
||||
const ACCEPT_RETRY_DELAY: Duration = Duration::from_millis(10);
|
||||
|
||||
pub(super) fn accept_loop(
|
||||
listener: TcpListener,
|
||||
tx: Sender<RuntimeMessage>,
|
||||
stopping: Arc<AtomicBool>,
|
||||
) {
|
||||
while !stopping.load(Ordering::Acquire) {
|
||||
match listener.accept() {
|
||||
Ok((stream, peer_addr)) => {
|
||||
if tx
|
||||
.send(RuntimeMessage::AcceptedConnection {
|
||||
stream,
|
||||
peer_addr,
|
||||
})
|
||||
.is_err()
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {
|
||||
thread::sleep(ACCEPT_RETRY_DELAY);
|
||||
}
|
||||
|
||||
Err(err) => {
|
||||
let _ = tx.send(RuntimeMessage::ListenerFailed(
|
||||
err.to_string(),
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
use std::{
|
||||
net::{SocketAddr, TcpStream},
|
||||
};
|
||||
|
||||
use proxyjail_core::EbpfEvent;
|
||||
|
||||
pub(super) enum RuntimeMessage {
|
||||
EbpfEvent(EbpfEvent),
|
||||
|
||||
AcceptedConnection {
|
||||
stream: TcpStream,
|
||||
peer_addr: SocketAddr,
|
||||
},
|
||||
|
||||
ListenerFailed(String),
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
mod config;
|
||||
mod connection;
|
||||
mod coordinator;
|
||||
mod event_forwarder;
|
||||
mod listener;
|
||||
mod message;
|
||||
mod relay;
|
||||
|
||||
pub use config::StdRuntimeConfig;
|
||||
|
||||
use std::{
|
||||
io,
|
||||
net::TcpListener,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
mpsc::{self, Receiver},
|
||||
Arc,
|
||||
},
|
||||
thread,
|
||||
};
|
||||
|
||||
use proxyjail_core::EbpfEvent;
|
||||
|
||||
pub fn run(
|
||||
config: StdRuntimeConfig,
|
||||
event_rx: Receiver<EbpfEvent>,
|
||||
) -> io::Result<()> {
|
||||
config.validate()?;
|
||||
|
||||
let listener = TcpListener::bind(config.listen_addr)?;
|
||||
listener.set_nonblocking(true)?;
|
||||
|
||||
println!("Proxy listener ready on {}", config.listen_addr);
|
||||
|
||||
let (message_tx, message_rx) = mpsc::channel();
|
||||
let stopping = Arc::new(AtomicBool::new(false));
|
||||
|
||||
// Start TCP listener thread.
|
||||
let accept_thread = {
|
||||
let tx = message_tx.clone();
|
||||
let worker_stopping = Arc::clone(&stopping);
|
||||
|
||||
thread::Builder::new()
|
||||
.name("proxy-accept".into())
|
||||
.spawn(move || {
|
||||
listener::accept_loop(listener, tx, worker_stopping);
|
||||
})?
|
||||
};
|
||||
|
||||
// Forward eBPF events to the coordinator.
|
||||
let event_thread = {
|
||||
let tx = message_tx.clone();
|
||||
let worker_stopping = Arc::clone(&stopping);
|
||||
|
||||
match thread::Builder::new()
|
||||
.name("proxy-event-forwarder".into())
|
||||
.spawn(move || {
|
||||
event_forwarder::forward_events(
|
||||
event_rx,
|
||||
tx,
|
||||
worker_stopping,
|
||||
);
|
||||
})
|
||||
{
|
||||
Ok(handle) => handle,
|
||||
|
||||
Err(err) => {
|
||||
stopping.store(true, Ordering::Release);
|
||||
let _ = accept_thread.join();
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
drop(message_tx);
|
||||
|
||||
// Run coordinator on the current thread.
|
||||
let result = coordinator::run(&config, message_rx);
|
||||
|
||||
// Stop background workers.
|
||||
stopping.store(true, Ordering::Release);
|
||||
|
||||
let accept_join = accept_thread.join();
|
||||
let event_join = event_thread.join();
|
||||
|
||||
if accept_join.is_err() || event_join.is_err() {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"a proxy runtime worker thread panicked",
|
||||
));
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
use std::{
|
||||
io::{self, copy},
|
||||
net::{Shutdown, TcpStream},
|
||||
thread,
|
||||
};
|
||||
|
||||
pub(super) fn relay(
|
||||
client: TcpStream,
|
||||
upstream: TcpStream,
|
||||
) -> io::Result<()> {
|
||||
client.set_nodelay(true)?;
|
||||
upstream.set_nodelay(true)?;
|
||||
|
||||
let mut client_reader = client.try_clone()?;
|
||||
let mut upstream_writer = upstream.try_clone()?;
|
||||
|
||||
let mut client_writer = client;
|
||||
let mut upstream_reader = upstream;
|
||||
|
||||
// Client -> Upstream
|
||||
let upload_thread = thread::Builder::new()
|
||||
.name("proxyjail-client-to-upstream".into())
|
||||
.spawn(move || {
|
||||
match copy(
|
||||
&mut client_reader,
|
||||
&mut upstream_writer,
|
||||
) {
|
||||
Ok(bytes_copied) => {
|
||||
upstream_writer.shutdown(Shutdown::Write)?;
|
||||
Ok(bytes_copied)
|
||||
}
|
||||
|
||||
Err(err) => {
|
||||
let _ = client_reader.shutdown(Shutdown::Both);
|
||||
let _ = upstream_writer.shutdown(Shutdown::Both);
|
||||
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
||||
// Upstream -> Client
|
||||
let download_result = copy(
|
||||
&mut upstream_reader,
|
||||
&mut client_writer,
|
||||
);
|
||||
|
||||
match &download_result {
|
||||
Ok(_) => {
|
||||
let _ = client_writer.shutdown(Shutdown::Write);
|
||||
}
|
||||
|
||||
Err(_) => {
|
||||
let _ = client_writer.shutdown(Shutdown::Both);
|
||||
let _ = upstream_reader.shutdown(Shutdown::Both);
|
||||
}
|
||||
}
|
||||
|
||||
let upload_result = upload_thread
|
||||
.join()
|
||||
.map_err(|_| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"upload relay thread panicked",
|
||||
)
|
||||
})?;
|
||||
|
||||
download_result?;
|
||||
upload_result?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1561 891.5" width="4683" height="2674.5"><!-- svg-source:excalidraw --><metadata></metadata><defs><style class="style-fonts">
|
||||
@font-face { font-family: Excalifont; src: url(data:font/woff2;base64,d09GMgABAAAAAByQAA4AAAAAMjwAABw5AAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGhwbjE4cgUwGYACBRBEICssct1YL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+voCGigyQ6jYTiyl/8v9jK4DXca+VN0901iPZkgem4hbsH64yCy6H/eJNa96ddIXXTA61eXhTENbzCCSw5NMG2GeCR7cxhtkQKOx38Ic4BA/+6w+b5RDlK73xCsorvX1MGzamnKzg0awDOuiwcPkMOEuw0RNbyt549el0H56p92Zj7fCEgb/D9xgZymXdbd+8Wy9J2TkszuTTrpSFumVanYxT0JSALPkm1oG9twLNE4l6yjlxi2vN3POpdyjbX04ozZtG4w7jLxFueSIPMcyGtt3dPtbhsIHXuVZ3Zz9pxThi+AzXp8TAzwplpo3GhEkbuhQV4uXkrOdQ/ZPZRVDUxf3ilIiG+8uDB2egoWJkWpXB+1py/9QmsCH/HluVjc1o1QYXTNDA1ggbmqaWsbFYJkqKv8F++BdOrYsedB0NYDp0VFu2eh64oXwxIDmHc6zz2KbWl5NbCXmvHh9mxVjn9su2lOwzl1/g+h4SSAS9+lWh8q64ri+6gUYUFg58To5ToqW9OLine truncated
|
||||
|
After Width: | Height: | Size: 40 KiB |
@@ -0,0 +1,34 @@
|
||||
- why not using tokio? cause it's overkill.
|
||||
|
||||
## eBPF event contract
|
||||
|
||||
`proxyjail-core` defines the userspace event:
|
||||
|
||||
```rust
|
||||
pub struct EbpfEvent {
|
||||
pub pid_tgid: u64,
|
||||
pub client: SocketAddr,
|
||||
pub original_destination: SocketAddr,
|
||||
}
|
||||
```
|
||||
|
||||
The ring-buffer ABI expected by `proxyjail-ebpf` is documented in
|
||||
`crates/proxyjail-ebpf/bpf/event.h` and `crates/proxyjail-ebpf/bpf/README.md`. It is a
|
||||
24-byte record:
|
||||
|
||||
- `pid_tgid`: native-endian `u64` at offset 0
|
||||
- `client_ip`: network-order IPv4 at offset 8
|
||||
- `client_port`: network-order port at offset 12
|
||||
- 2 bytes padding
|
||||
- `original_ip`: network-order IPv4 at offset 16
|
||||
- `original_port`: network-order port at offset 20
|
||||
- 2 bytes tail padding
|
||||
|
||||
The `client` endpoint **must exactly match** the address returned by
|
||||
`TcpStream::peer_addr()` on the accepted local TCP connection. The original
|
||||
16-byte event containing only PID and original destination is not enough for
|
||||
the matching strategy implemented here. Your BPF program must reliably
|
||||
populate the client tuple before publishing the event. Do not assume the
|
||||
source port is available in the initial cgroup `connect4` hook without
|
||||
verifying the hook's socket state and the exact endpoint seen after any NAT or
|
||||
redirection.
|
||||
@@ -0,0 +1,14 @@
|
||||
# Experiment phase journal
|
||||
- let's start with cgroup and ebpf at first
|
||||
- future cli:
|
||||
|
||||
target: --pid 1234 | --cgroup <path> | --netns <path> | --container <name>
|
||||
│
|
||||
└─ container resolver (Docker/Podman API) → { pid, cgroup, netns }
|
||||
│
|
||||
backend: LD_PRELOAD | eBPF cgroup/connect | nftables (TPROXY/REDIRECT) | TUN
|
||||
|
||||
proxyjail attach --container my-app --chain work
|
||||
proxyjail attach --netns /run/netns/vpn1 --chain tor
|
||||
proxyjail run --chain work -- curl https://example.com # plain process, as before
|
||||
proxyjail daemon --watch-label yourtool.profile # auto-capture labeled containers
|
||||
Reference in new issue
Block a user