Added rmPortForward and added anchor namespacing.

This commit is contained in:
Gary Talent 2016-03-04 05:53:17 +00:00
parent d6a3d8ad99
commit ff49b1be3f
2 changed files with 16 additions and 5 deletions

View File

@ -14,10 +14,10 @@ import (
"strconv" "strconv"
) )
func setupPortForward(ruleName, ip, port string) { func addPortForward(ruleName, ip, port string) {
pfrule := "\"rdr pass on $ext_if proto { tcp, udp } from any to any port {" + port + "} -> " + ip + "\"" 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() defer in.Close()
if err != nil { if err != nil {
log.Println("Port Forwarding:", err) 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 { func portUsageCount(ports ...int) int {
cmd := "/usr/bin/sockstat" cmd := "sockstat"
args := []string{"-4c"} args := []string{"-4c"}
for _, v := range ports { for _, v := range ports {
args = append(args, "-p") args = append(args, "-p")

View File

@ -15,7 +15,11 @@ import (
) )
// just have this stub to allow building on Linux // 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") log.Print("Port forwarding not currently implemented for Linux/iptables")
} }