Skip to content

Commit 6d68c87

Browse files
committed
Add OpenFlow rules for NodePort in shared gateway mode
This commit introduces new OpenFlow rules to correctly handle NodePort service traffic in a shared gateway configuration. The new rules address two scenarios: 1. A rule with priority 109 is added to drop traffic originating from OVN towards a NodePort. This prevents ingress traffic from being incorrectly forwarded to the host during OVN logical router resynchronizations. 2. A higher-priority rule (110) is added to allow traffic from the local host or pods destined for a NodePort service to egress to the physical network. This ensures that local clients can access services via their NodePort.
1 parent 2663105 commit 6d68c87

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

go-controller/pkg/node/gateway_localnet_linux_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,10 @@ var _ = Describe("Node Operations", func() {
11951195
"cookie=0x453ae29bcbbc08bd, priority=110, in_port=eth0, tcp, tp_dst=31111, actions=output:patch-breth0_ov",
11961196
fmt.Sprintf("cookie=0x453ae29bcbbc08bd, priority=110, in_port=patch-breth0_ov, dl_src=%s, tcp, tp_src=31111, actions=output:eth0",
11971197
gwMAC),
1198+
fmt.Sprintf("cookie=0x453ae29bcbbc08bd, priority=110, in_port=patch-breth0_ov, dl_src=%s, tcp, tp_dst=31111, ip, nw_src=%s, actions=normal",
1199+
gwMAC, v4localnetGatewayIP),
1200+
fmt.Sprintf("cookie=0x453ae29bcbbc08bd, priority=109, in_port=patch-breth0_ov, dl_src=%s, tcp, tp_dst=31111, actions=drop",
1201+
gwMAC),
11981202
}
11991203
expectedLBIngressFlows := []string{
12001204
"cookie=0x10c6b89e483ea111, priority=110, in_port=eth0, arp, arp_op=1, arp_tpa=5.5.5.5, actions=output:LOCAL",
@@ -2308,6 +2312,10 @@ var _ = Describe("Node Operations", func() {
23082312
"cookie=0x453ae29bcbbc08bd, priority=110, in_port=eth0, tcp, tp_dst=31111, actions=output:patch-breth0_ov",
23092313
fmt.Sprintf("cookie=0x453ae29bcbbc08bd, priority=110, in_port=patch-breth0_ov, dl_src=%s, tcp, tp_src=31111, actions=output:eth0",
23102314
gwMAC),
2315+
fmt.Sprintf("cookie=0x453ae29bcbbc08bd, priority=110, in_port=patch-breth0_ov, dl_src=%s, tcp, tp_dst=31111, ip, nw_src=%s, actions=normal",
2316+
gwMAC, v4localnetGatewayIP),
2317+
fmt.Sprintf("cookie=0x453ae29bcbbc08bd, priority=109, in_port=patch-breth0_ov, dl_src=%s, tcp, tp_dst=31111, actions=drop",
2318+
gwMAC),
23112319
}
23122320

23132321
f4 := iptV4.(*util.FakeIPTables)
@@ -2598,6 +2606,10 @@ var _ = Describe("Node Operations", func() {
25982606
"cookie=0x453ae29bcbbc08bd, priority=110, in_port=eth0, tcp, tp_dst=31111, actions=output:patch-breth0_ov",
25992607
fmt.Sprintf("cookie=0x453ae29bcbbc08bd, priority=110, in_port=patch-breth0_ov, dl_src=%s, tcp, tp_src=31111, actions=output:eth0",
26002608
gwMAC),
2609+
fmt.Sprintf("cookie=0x453ae29bcbbc08bd, priority=110, in_port=patch-breth0_ov, dl_dst=%s, tcp, tp_dst=31111, ip, nw_src=%s, actions=normal",
2610+
gwMAC, v4localnetGatewayIP),
2611+
fmt.Sprintf("cookie=0x453ae29bcbbc08bd, priority=109, in_port=patch-breth0_ov, dl_dst=%s, tcp, tp_dst=31111, actions=drop",
2612+
gwMAC),
26012613
}
26022614

26032615
f4 := iptV4.(*util.FakeIPTables)

go-controller/pkg/node/gateway_shared_intf.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,31 @@ func (npw *nodePortWatcher) updateServiceFlowCache(service *corev1.Service, netI
329329
npw.ofm.updateFlowCacheEntry(key, nodeportFlows)
330330
} else if config.Gateway.Mode == config.GatewayModeShared {
331331
// case2 (see function description for details)
332+
var ipProtocol, gwIP string
333+
if strings.Contains(flowProtocol, "6") {
334+
ipProtocol = "ip6"
335+
gwIP = npw.gatewayIPv6
336+
} else {
337+
ipProtocol = "ip"
338+
gwIP = npw.gatewayIPv4
339+
}
340+
332341
npw.ofm.updateFlowCacheEntry(key, []string{
333342
// table=0, matches on service traffic towards nodePort and sends it to OVN pipeline
334343
fmt.Sprintf("cookie=%s, priority=110, in_port=%s, %s, tp_dst=%d, "+
335344
"actions=%s",
336345
cookie, npw.ofportPhys, flowProtocol, svcPort.NodePort, actions),
346+
// table=0, matches on service traffic towards nodePort from OVN and drops it, to prevent the ingress traffic goes to the host.
347+
// This is to prevent ingress traffic to nodePort from being forwarded to the host accidentally during GR OVN LB resyncs.
348+
fmt.Sprintf("cookie=%s, priority=109, in_port=%s, dl_src=%s, %s, tp_dst=%d, "+
349+
"actions=drop",
350+
cookie, netConfig.OfPortPatch, npw.ofm.getDefaultBridgeMAC(), flowProtocol, svcPort.NodePort),
351+
// table=0, matches on local host/pods egress traffic to service nodePort and sends it out to physical network.
352+
// This is needed for the case where a local pod/host is trying to access the service via nodePort. It gets higher
353+
// priority than the previous rule to allow local traffic to nodePort to be sent out.
354+
fmt.Sprintf("cookie=%s, priority=110, in_port=%s, dl_src=%s, %s, tp_dst=%d, %s, nw_src=%s, "+
355+
"actions=normal",
356+
cookie, netConfig.OfPortPatch, npw.ofm.getDefaultBridgeMAC(), flowProtocol, svcPort.NodePort, ipProtocol, gwIP),
337357
// table=0, matches on return traffic from service nodePort and sends it out to primary node interface (br-ex)
338358
fmt.Sprintf("cookie=%s, priority=110, in_port=%s, dl_src=%s, %s, tp_src=%d, "+
339359
"actions=output:%s",

0 commit comments

Comments
 (0)