Skip to content

Commit 90c8305

Browse files
authored
iptables: add --random-fully to SNAT rules (#3066)
1 parent 1350397 commit 90c8305

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/daemon/gateway_linux.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ func (c *Controller) setIptables() error {
698698
var natPreroutingRules, natPostroutingRules, ovnMasqueradeRules []util.IPTableRule
699699
for _, rule := range iptablesRules {
700700
if rule.Table == NAT {
701-
if c.k8siptables[protocol].HasRandomFully() && rule.Rule[len(rule.Rule)-1] == "MASQUERADE" {
701+
if c.k8siptables[protocol].HasRandomFully() &&
702+
(rule.Rule[len(rule.Rule)-1] == "MASQUERADE" || util.ContainsString(rule.Rule, "SNAT")) {
702703
rule.Rule = append(rule.Rule, "--random-fully")
703704
}
704705

@@ -721,13 +722,18 @@ func (c *Controller) setIptables() error {
721722
}
722723
}
723724

725+
var randomFully string
726+
if c.k8siptables[protocol].HasRandomFully() {
727+
randomFully = "--random-fully"
728+
}
729+
724730
// add iptables rule for nat gw with designative ip in centralized subnet
725731
for cidr, ip := range centralGwNatIPs {
726732
if util.CheckProtocol(cidr) != protocol {
727733
continue
728734
}
729735

730-
s := fmt.Sprintf("-s %s -m set ! --match-set %s dst -j SNAT --to-source %s", cidr, matchset, ip)
736+
s := fmt.Sprintf("-s %s -m set ! --match-set %s dst -j SNAT --to-source %s %s", cidr, matchset, ip, randomFully)
731737
rule := util.IPTableRule{
732738
Table: NAT,
733739
Chain: OvnPostrouting,

0 commit comments

Comments
 (0)