summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-03-24 16:47:52 +0100
committerDavid Lönnhager <david.l@mullvad.net>2020-06-02 10:05:01 +0200
commit25e9ec1a0a971e6e2e9ab4e592c48b13fbffa985 (patch)
treee40a91519bf246a077a525a9670da5bfeb36cc97
parent78df018f7177616317f7a564bc8074d0a0982d84 (diff)
downloadmullvadvpn-25e9ec1a0a971e6e2e9ab4e592c48b13fbffa985.tar.xz
mullvadvpn-25e9ec1a0a971e6e2e9ab4e592c48b13fbffa985.zip
Add function for adding PIDs to the cgroup
-rw-r--r--talpid-core/src/split.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/talpid-core/src/split.rs b/talpid-core/src/split.rs
index 73996dde34..b95caaf7f8 100644
--- a/talpid-core/src/split.rs
+++ b/talpid-core/src/split.rs
@@ -20,6 +20,10 @@ pub enum Error {
/// Unable to set class ID for cgroup.
#[error(display = "Unable to set cgroup class ID")]
SetCGroupClassId(#[error(source)] io::Error),
+
+ /// Unable to add PID to cgroup.procs.
+ #[error(display = "Unable to add PID to cgroup.procs")]
+ AddCGroupPid(#[error(source)] io::Error),
}
/// Set up cgroup used to track PIDs for split tunneling.
@@ -33,3 +37,17 @@ pub fn create_cgroup() -> Result<(), Error> {
let classid_path = exclusions_dir.join("net_cls.classid");
fs::write(classid_path, NETCLS_CLASSID.to_string().as_bytes()).map_err(Error::SetCGroupClassId)
}
+
+/// Add a PID to exclude from the tunnel.
+pub fn add_pid(pid: i32) -> Result<(), Error> {
+ let exclusions_path = Path::new(NETCLS_DIR).join(CGROUP_NAME).join("cgroup.procs");
+
+ let mut file = fs::OpenOptions::new()
+ .write(true)
+ .create(true)
+ .open(exclusions_path)
+ .map_err(Error::AddCGroupPid)?;
+
+ file.write_all(pid.to_string().as_bytes())
+ .map_err(Error::AddCGroupPid)
+}