From d6a3d8ad9903af0c65e0024b81694eaa583e6ee9 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 2 Mar 2016 06:08:29 +0000 Subject: [PATCH] Filled out FreeBSD port forwarding control. --- net_freebsd.go | 14 +++++++++++++- net_linux.go | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/net_freebsd.go b/net_freebsd.go index df0038c..72e1266 100644 --- a/net_freebsd.go +++ b/net_freebsd.go @@ -14,7 +14,19 @@ import ( "strconv" ) -func setupPortForward(ip, port string) { +func setupPortForward(ruleName, ip, port string) { + pfrule := "\"rdr pass on $ext_if proto { tcp, udp } from any to any port {" + port + "} -> " + ip + "\"" + + in, err := exec.Command("pfctl", "-a", "\""+ruleName+"\"", "-f", "-").StdinPipe() + defer in.Close() + if err != nil { + log.Println("Port Forwarding:", err) + } + + _, err = in.Write([]byte(pfrule)) + if err != nil { + log.Println("Port Forwarding:", err) + } } func portUsageCount(ports ...int) int { diff --git a/net_linux.go b/net_linux.go index eed00cf..e1f3efa 100644 --- a/net_linux.go +++ b/net_linux.go @@ -15,7 +15,7 @@ import ( ) // just have this stub to allow building on Linux -func setupPortForward(ip, port string) { +func setupPortForward(ruleName, ip, port string) { log.Print("Port forwarding not currently implemented for Linux/iptables") }