Skip to content

Commit

Permalink
Merge pull request #91 from blocklessnetwork/feature/nat
Browse files Browse the repository at this point in the history
Feature/nat
  • Loading branch information
Joinhack authored Jul 29, 2024
2 parents fb1cfdd + eeefe01 commit 9e6e032
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions crates/wasi/src/nat/macos.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{
fs::OpenOptions, io::Write, process::{Command, Stdio}
};
use super::NatError;

fn sysctl(enable: bool) -> Result<(), NatError> {
pub(crate) fn sysctl(enable: bool) -> Result<(), NatError> {
let mut command = Command::new("sysctl");
let enable = if enable { 1 } else { 0 };
command.args(&["-w", &format!("net.inet.ip.forwarding={enable}")]);
Expand All @@ -17,7 +18,7 @@ fn sysctl(enable: bool) -> Result<(), NatError> {
}
}

fn pfctl() -> Result<(), NatError> {
pub(crate) fn pfctl() -> Result<(), NatError> {
let mut command = Command::new("pfctl");
let child = io_wrap!(command.args(&["-f", "/etc/pf.anchors/bls-vm-nat", "-e" ])
.stdout(Stdio::piped())
Expand All @@ -36,11 +37,12 @@ fn pfctl() -> Result<(), NatError> {
}

/// write the archors file
fn write_anchors(name: &str) {
let mut pfctl = OpenOptions::new()
pub(crate) fn write_anchors(name: &str) -> Result<(), NatError> {
let mut pfctl = io_wrap!(OpenOptions::new()
.write(true)
.create(true)
.open("/etc/pf.anchors/bls-vm-nat")?;
.open("/etc/pf.anchors/bls-vm-nat"));
let cmd = format!("nat on en0 from {name}:network to any -> (en0)\n");
pfctl.write_all(cmd.as_bytes())?;
io_wrap!(pfctl.write_all(cmd.as_bytes()));
Ok(())
}

0 comments on commit 9e6e032

Please sign in to comment.