Merge pull request #12437 from fmzhen/remove-regex-replace
Removal of the regex to replace ips
This commit is contained in:
commit
5e2aec2983
1 changed files with 1 additions and 9 deletions
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -267,14 +266,7 @@ func Exists(table Table, chain string, rule ...string) bool {
|
||||||
ruleString := strings.Join(rule, " ")
|
ruleString := strings.Join(rule, " ")
|
||||||
existingRules, _ := exec.Command(iptablesPath, "-t", string(table), "-S", chain).Output()
|
existingRules, _ := exec.Command(iptablesPath, "-t", string(table), "-S", chain).Output()
|
||||||
|
|
||||||
// regex to replace ips in rule
|
return strings.Contains(string(existingRules), ruleString)
|
||||||
// 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, "?"),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call 'iptables' system command, passing supplied arguments
|
// Call 'iptables' system command, passing supplied arguments
|
||||||
|
|
Loading…
Reference in a new issue