Merge pull request #977 from gravitl/feature_v0.12.2_ip_table_check

serverctl/iptables: added iptables check cmd
This commit is contained in:
dcarns 2022-03-28 10:10:45 -04:00 committed by GitHub
commit fd20cfec56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -110,16 +110,19 @@ func iptablesPortForward(entry string, inport string, outport string, isIP bool)
return errors.New("could not locate ip for " + entry)
}
_, err := ncutils.RunCmd("iptables -t nat -A PREROUTING -p tcp --dport "+inport+" -j DNAT --to-destination "+address+":"+outport, false)
if err != nil {
if output, _ := ncutils.RunCmd("iptables -t nat -C PREROUTING -p tcp --dport "+inport+" -j DNAT --to-destination "+address+":"+outport, false); output == "" {
_, err := ncutils.RunCmd("iptables -t nat -A PREROUTING -p tcp --dport "+inport+" -j DNAT --to-destination "+address+":"+outport, false)
if err != nil {
return err
}
_, err = ncutils.RunCmd("iptables -t nat -A PREROUTING -p udp --dport "+inport+" -j DNAT --to-destination "+address+":"+outport, false)
if err != nil {
return err
}
_, err = ncutils.RunCmd("iptables -t nat -A POSTROUTING -j MASQUERADE", false)
return err
}
_, err = ncutils.RunCmd("iptables -t nat -A PREROUTING -p udp --dport "+inport+" -j DNAT --to-destination "+address+":"+outport, false)
if err != nil {
return err
}
_, err = ncutils.RunCmd("iptables -t nat -A POSTROUTING -j MASQUERADE", false)
return err
return nil
}
// if running in host networking mode, run iptables to map to CoreDNS container