Skip to content

Commit

Permalink
Fix ETP iptables for shared gateway mode
Browse files Browse the repository at this point in the history
For NodePort Services with ExternalTrafficPolicy = Local,
incoming connections shouldn't be DNATted to masqueradeIP.

Signed-off-by: Andrea Panattoni <apanatto@redhat.com>
  • Loading branch information
zeeke committed Apr 21, 2023
1 parent dde7ea8 commit 8bd9b3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 3 additions & 1 deletion go-controller/pkg/node/gateway_iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,9 @@ func getGatewayIPTRules(service *kapi.Service, localEndpoints []string, svcHasLo
if svcTypeIsETPLocal && !svcHasLocalHostNetEndPnt {
// case1 (see function description for details)
// A DNAT rule to masqueradeIP is added that takes priority over DNAT to clusterIP.
rules = append(rules, getNodePortIPTRules(svcPort, clusterIP, svcPort.NodePort, svcHasLocalHostNetEndPnt, svcTypeIsETPLocal)...)
if config.Gateway.Mode == config.GatewayModeLocal {
rules = append(rules, getNodePortIPTRules(svcPort, clusterIP, svcPort.NodePort, svcHasLocalHostNetEndPnt, svcTypeIsETPLocal)...)
}
// add a skip SNAT rule to OVN-KUBE-SNAT-MGMTPORT to preserve sourceIP for etp=local traffic.
rules = append(rules, getNodePortETPLocalIPTRules(svcPort, clusterIP)...)
}
Expand Down
11 changes: 3 additions & 8 deletions go-controller/pkg/node/gateway_localnet_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,6 @@ var _ = Describe("Node Operations", func() {
"OVN-KUBE-ETP": []string{
fmt.Sprintf("-p %s -d %s --dport %v -j DNAT --to-destination %s:%v", service.Spec.Ports[0].Protocol, service.Status.LoadBalancer.Ingress[0].IP, service.Spec.Ports[0].Port, types.V4HostETPLocalMasqueradeIP, service.Spec.Ports[0].NodePort),
fmt.Sprintf("-p %s -d %s --dport %v -j DNAT --to-destination %s:%v", service.Spec.Ports[0].Protocol, externalIP, service.Spec.Ports[0].Port, types.V4HostETPLocalMasqueradeIP, service.Spec.Ports[0].NodePort),
fmt.Sprintf("-p %s -m addrtype --dst-type LOCAL --dport %v -j DNAT --to-destination %s:%v", service.Spec.Ports[0].Protocol, service.Spec.Ports[0].NodePort, types.V4HostETPLocalMasqueradeIP, service.Spec.Ports[0].NodePort),
},
"OVN-KUBE-ITP": []string{},
"OVN-KUBE-EGRESS-SVC": []string{"-m mark --mark 0x3f0 -m comment --comment Do not SNAT to SVC VIP -j RETURN"},
Expand Down Expand Up @@ -2116,9 +2115,7 @@ var _ = Describe("Node Operations", func() {
"OVN-KUBE-SNAT-MGMTPORT": []string{
fmt.Sprintf("-p TCP --dport %v -j RETURN", service.Spec.Ports[0].NodePort),
},
"OVN-KUBE-ETP": []string{
fmt.Sprintf("-p %s -m addrtype --dst-type LOCAL --dport %v -j DNAT --to-destination %s:%v", service.Spec.Ports[0].Protocol, service.Spec.Ports[0].NodePort, types.V4HostETPLocalMasqueradeIP, service.Spec.Ports[0].NodePort),
},
"OVN-KUBE-ETP": []string{},
"OVN-KUBE-ITP": []string{},
"OVN-KUBE-EGRESS-SVC": []string{"-m mark --mark 0x3f0 -m comment --comment Do not SNAT to SVC VIP -j RETURN"},
},
Expand Down Expand Up @@ -2405,10 +2402,8 @@ var _ = Describe("Node Operations", func() {
"OVN-KUBE-SNAT-MGMTPORT": []string{
fmt.Sprintf("-p TCP --dport %v -j RETURN", service.Spec.Ports[0].NodePort),
},
"OVN-KUBE-ITP": []string{},
"OVN-KUBE-ETP": []string{
fmt.Sprintf("-p %s -m addrtype --dst-type LOCAL --dport %v -j DNAT --to-destination %s:%v", service.Spec.Ports[0].Protocol, service.Spec.Ports[0].NodePort, types.V4HostETPLocalMasqueradeIP, service.Spec.Ports[0].NodePort),
},
"OVN-KUBE-ITP": []string{},
"OVN-KUBE-ETP": []string{},
"OVN-KUBE-EGRESS-SVC": []string{"-m mark --mark 0x3f0 -m comment --comment Do not SNAT to SVC VIP -j RETURN"},
},
"filter": {},
Expand Down

0 comments on commit 8bd9b3e

Please sign in to comment.