Removal of the regex to replace ips

Signed-off-by: Mingzhen Feng <fmzhen@zju.edu.cn>
This commit is contained in:
Mingzhen Feng
2015-05-19 10:15:18 +08:00
parent e4855eebf2
commit 3ab7ceb5d7
2 changed files with 36 additions and 9 deletions
+1 -9
View File
@@ -5,7 +5,6 @@ import (
"fmt"
"net"
"os/exec"
"regexp"
"strconv"
"strings"
"sync"
@@ -267,14 +266,7 @@ func Exists(table Table, chain string, rule ...string) bool {
ruleString := strings.Join(rule, " ")
existingRules, _ := exec.Command(iptablesPath, "-t", string(table), "-S", chain).Output()
// regex to replace ips in rule
// because MASQUERADE rule will not be exactly what was passed
re := regexp.MustCompile(`[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}`)
return strings.Contains(
re.ReplaceAllString(string(existingRules), "?"),
re.ReplaceAllString(ruleString, "?"),
)
return strings.Contains(string(existingRules), ruleString)
}
// Call 'iptables' system command, passing supplied arguments