diff --git a/net_freebsd.go b/net_freebsd.go index 72e1266..0c59b0c 100644 --- a/net_freebsd.go +++ b/net_freebsd.go @@ -14,10 +14,10 @@ import ( "strconv" ) -func setupPortForward(ruleName, ip, port string) { - pfrule := "\"rdr pass on $ext_if proto { tcp, udp } from any to any port {" + port + "} -> " + ip + "\"" +func addPortForward(ruleName, ip, port string) { + pfrule := "\"rdr pass on $dospin_ext_if proto { tcp, udp } from any to any port {" + port + "} -> " + ip + "\"" - in, err := exec.Command("pfctl", "-a", "\""+ruleName+"\"", "-f", "-").StdinPipe() + in, err := exec.Command("pfctl", "-a", "\"dospin_"+ruleName+"\"", "-f", "-").StdinPipe() defer in.Close() if err != nil { log.Println("Port Forwarding:", err) @@ -29,8 +29,15 @@ func setupPortForward(ruleName, ip, port string) { } } +func rmPortForward(ruleName string) { + _, err := exec.Command("pfctl", "-a", "\"dospin_"+ruleName+"\"", "-F", "rules").Output() + if err != nil { + log.Println("Port Forwarding:", err) + } +} + func portUsageCount(ports ...int) int { - cmd := "/usr/bin/sockstat" + cmd := "sockstat" args := []string{"-4c"} for _, v := range ports { args = append(args, "-p") diff --git a/net_linux.go b/net_linux.go index e1f3efa..bf62b28 100644 --- a/net_linux.go +++ b/net_linux.go @@ -15,7 +15,11 @@ import ( ) // just have this stub to allow building on Linux -func setupPortForward(ruleName, ip, port string) { +func addPortForward(ruleName, ip, port string) { + log.Print("Port forwarding not currently implemented for Linux/iptables") +} + +func rmPortForward(ruleName string) { log.Print("Port forwarding not currently implemented for Linux/iptables") }