Filled out FreeBSD port forwarding control.

This commit is contained in:
Gary Talent 2016-03-02 06:08:29 +00:00
parent fee5f4d293
commit d6a3d8ad99
2 changed files with 14 additions and 2 deletions

View File

@ -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 {

View File

@ -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")
}