Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for freebsd ipfw firewall #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ nft add rule nat prerouting tcp dport {80, 443} redirect to 2080
# or the legacy iptables equivalent
iptables -t nat -A OUTPUT -p tcp -m multiport --dports 80,443 -j REDIRECT --to-port 2080
iptables -t nat -A PREROUTING -p tcp -m multiport --dports 80,443 -j REDIRECT --to-port 2080

# or ipfw (FreeBSD)
ipfw add 100 fwd 127.0.0.1,2080 tcp from me to not me dst-port 80,443
```

SOCKSv5 server is also launched alongs with transparent proxy on the same port:
Expand Down
9 changes: 9 additions & 0 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ async fn accept_socks5(client: &mut TcpStream) -> io::Result<Destination> {
Ok((addr, port).into())
}

async fn transparent_dest(client: &mut TcpStream) -> io::Result<Destination> {
// Transparent firewall redirection (unmodified destination address)
// (for example, ipfw firewall with 'fwd' rule)
Ok((client.local_addr()?).into())
}

impl NewClient {
#[instrument(name = "retrieve_dest", skip_all)]
pub async fn from_socket(mut left: TcpStream, list: ServerList) -> io::Result<Self> {
Expand All @@ -152,6 +158,9 @@ impl NewClient {
#[cfg(not(target_os = "linux"))]
let dest: Option<SocketAddr> = None;

#[cfg(target_os = "freebsd")]
let dest = (transparent_dest(&mut left).await?).into();

let dest = if let Some(dest) = dest {
debug!(?dest, "Retrived destination via NAT info");
dest.into()
Expand Down