Skip to content

Commit ae226e3

Browse files
committed
iptables: always do SNAT for access from other nodes to nodeport with external traffic policy set to Local (#2844)
1 parent ef78fee commit ae226e3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pkg/daemon/gateway_linux.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,14 @@ func (c *Controller) setIptables() error {
486486
continue
487487
}
488488

489-
var kubeProxyIpsetProtocol, matchset string
489+
var kubeProxyIpsetProtocol, matchset, nodeMatchSet string
490490
var obsoleteRules, iptablesRules []util.IPTableRule
491491
if protocol == kubeovnv1.ProtocolIPv4 {
492492
iptablesRules = v4Rules
493-
matchset = "ovn40subnets"
493+
matchset, nodeMatchSet = "ovn40subnets", "ovn40"+OtherNodeSet
494494
} else {
495495
iptablesRules = v6Rules
496-
kubeProxyIpsetProtocol, matchset = "6-", "ovn60subnets"
496+
kubeProxyIpsetProtocol, matchset, nodeMatchSet = "6-", "ovn60subnets", "ovn60"+OtherNodeSet
497497
}
498498

499499
if nodeIP := nodeIPs[protocol]; nodeIP != "" {
@@ -515,8 +515,12 @@ func (c *Controller) setIptables() error {
515515
continue
516516
}
517517
rule := fmt.Sprintf("-p %s -m addrtype --dst-type LOCAL -m set --match-set %s dst -j MARK --set-xmark 0x80000/0x80000", p, ipset)
518+
rule2 := fmt.Sprintf("-p %s -m set --match-set %s src -m set --match-set %s dst -j MARK --set-xmark 0x4000/0x4000", p, nodeMatchSet, ipset)
518519
obsoleteRules = append(obsoleteRules, util.IPTableRule{Table: NAT, Chain: Prerouting, Rule: strings.Fields(rule)})
519-
iptablesRules = append(iptablesRules, util.IPTableRule{Table: NAT, Chain: OvnPrerouting, Rule: strings.Fields(rule)})
520+
iptablesRules = append(iptablesRules,
521+
util.IPTableRule{Table: NAT, Chain: OvnPrerouting, Rule: strings.Fields(rule)},
522+
util.IPTableRule{Table: NAT, Chain: OvnPrerouting, Rule: strings.Fields(rule2)},
523+
)
520524
}
521525
}
522526

0 commit comments

Comments
 (0)