Skip to content

Commit

Permalink
Clean original iptables rule if --random-fully is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
coufalja committed Aug 4, 2020
1 parent 8d424ea commit 68dba40
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/controllers/proxy/network_services_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,16 @@ func (nsc *NetworkServicesController) deleteBadMasqueradeIptablesRules() error {
{"-m", "ipvs", "--ipvs", "--vdir", "ORIGINAL", "--vmethod", "MASQ", "-m", "comment", "--comment", "", "!", "-s", nsc.podCidr, "!", "-d", nsc.podCidr, "-j", "MASQUERADE"},
}

// If random fully is supported remove the original rules as well
if iptablesCmdHandler.HasRandomFully() {
argsBad = append(argsBad, []string{"-m", "ipvs", "--ipvs", "--vdir", "ORIGINAL", "--vmethod", "MASQ", "-m", "comment", "--comment", "", "-j", "SNAT", "--to-source", nsc.nodeIP.String()})

if len(nsc.podCidr) > 0 {
argsBad = append(argsBad, []string{"-m", "ipvs", "--ipvs", "--vdir", "ORIGINAL", "--vmethod", "MASQ", "-m", "comment", "--comment", "",
"!", "-s", nsc.podCidr, "!", "-d", nsc.podCidr, "-j", "SNAT", "--to-source", nsc.nodeIP.String()})
}
}

for _, args := range argsBad {
exists, err := iptablesCmdHandler.Exists("nat", "POSTROUTING", args...)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions pkg/controllers/routing/pod_egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ func (nrc *NetworkRoutingController) deleteBadPodEgressRules() error {
if nrc.isIpv6 {
podEgressArgsBad = podEgressArgsBad6
}

// If random fully is supported remove the original rule as well
if iptablesCmdHandler.HasRandomFully() {
if !nrc.isIpv6 {
podEgressArgsBad = append(podEgressArgsBad, podEgressArgs4)
} else {
podEgressArgsBad = append(podEgressArgsBad, podEgressArgs6)
}
}

for _, args := range podEgressArgsBad {
exists, err := iptablesCmdHandler.Exists("nat", "POSTROUTING", args...)
if err != nil {
Expand Down

0 comments on commit 68dba40

Please sign in to comment.