Skip to content

Commit f531e3d

Browse files
committed
[node/gateway] make PatchedNetConfigs internal, remove locking
Signed-off-by: Nadia Pinaeva <[email protected]>
1 parent fd5e791 commit f531e3d

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

go-controller/pkg/node/bridgeconfig/bridgeconfig.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,8 @@ func (b *BridgeConfiguration) GetActiveNetworkBridgeConfigCopy(networkName strin
336336
return nil
337337
}
338338

339-
func (b *BridgeConfiguration) PatchedNetConfigs() []*BridgeUDNConfiguration {
340-
b.mutex.Lock()
341-
defer b.mutex.Unlock()
339+
// must be called with mutex held
340+
func (b *BridgeConfiguration) patchedNetConfigs() []*BridgeUDNConfiguration {
342341
result := make([]*BridgeUDNConfiguration, 0, len(b.netConfig))
343342
for _, netConfig := range b.netConfig {
344343
if netConfig.OfPortPatch == "" {

go-controller/pkg/node/bridgeconfig/bridgeflows.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (b *BridgeConfiguration) flowsForDefaultBridge(extraIPs []net.IP) ([]string
7979
if err != nil {
8080
return nil, fmt.Errorf("unable to determine IPv4 physical IP of host: %v", err)
8181
}
82-
for _, netConfig := range b.PatchedNetConfigs() {
82+
for _, netConfig := range b.patchedNetConfigs() {
8383
// table 0, SVC Hairpin from OVN destined to local host, DNAT and go to table 4
8484
dftFlows = append(dftFlows,
8585
fmt.Sprintf("cookie=%s, priority=500, in_port=%s, ip, ip_dst=%s, ip_src=%s,"+
@@ -103,7 +103,7 @@ func (b *BridgeConfiguration) flowsForDefaultBridge(extraIPs []net.IP) ([]string
103103
continue
104104
}
105105

106-
for _, netConfig := range b.PatchedNetConfigs() {
106+
for _, netConfig := range b.patchedNetConfigs() {
107107
dftFlows = append(dftFlows,
108108
fmt.Sprintf("cookie=%s, priority=500, in_port=%s, ip, ip_dst=%s, ip_src=%s,"+
109109
"actions=ct(commit,zone=%d,table=4)",
@@ -142,7 +142,7 @@ func (b *BridgeConfiguration) flowsForDefaultBridge(extraIPs []net.IP) ([]string
142142
return nil, fmt.Errorf("unable to determine IPv6 physical IP of host: %v", err)
143143
}
144144
// table 0, SVC Hairpin from OVN destined to local host, DNAT to host, send to table 4
145-
for _, netConfig := range b.PatchedNetConfigs() {
145+
for _, netConfig := range b.patchedNetConfigs() {
146146
dftFlows = append(dftFlows,
147147
fmt.Sprintf("cookie=%s, priority=500, in_port=%s, ipv6, ipv6_dst=%s, ipv6_src=%s,"+
148148
"actions=ct(commit,zone=%d,nat(dst=%s),table=4)",
@@ -165,7 +165,7 @@ func (b *BridgeConfiguration) flowsForDefaultBridge(extraIPs []net.IP) ([]string
165165
continue
166166
}
167167

168-
for _, netConfig := range b.PatchedNetConfigs() {
168+
for _, netConfig := range b.patchedNetConfigs() {
169169
dftFlows = append(dftFlows,
170170
fmt.Sprintf("cookie=%s, priority=500, in_port=%s, ipv6, ipv6_dst=%s, ipv6_src=%s,"+
171171
"actions=ct(commit,zone=%d,table=4)",
@@ -216,7 +216,7 @@ func (b *BridgeConfiguration) flowsForDefaultBridge(extraIPs []net.IP) ([]string
216216
// we match on the UDNPodSubnet itself and we also don't SNAT to 169.254.0.2
217217
// sample flow: cookie=0xdeff105, duration=1472.742s, table=0, n_packets=9, n_bytes=666, priority=550
218218
// ip,in_port=LOCAL,nw_src=103.103.0.0/16,nw_dst=10.96.0.0/16 actions=ct(commit,table=2,zone=64001)
219-
for _, netConfig := range b.PatchedNetConfigs() {
219+
for _, netConfig := range b.patchedNetConfigs() {
220220
if netConfig.IsDefaultNetwork() {
221221
continue
222222
}
@@ -249,7 +249,7 @@ func (b *BridgeConfiguration) flowsForDefaultBridge(extraIPs []net.IP) ([]string
249249
// In UDN match on the whole masquerade subnet to handle replies from UDN enabled services
250250
masqDst = masqSubnet
251251
}
252-
for _, netConfig := range b.PatchedNetConfigs() {
252+
for _, netConfig := range b.patchedNetConfigs() {
253253
// table 0, Reply hairpin traffic to host, coming from OVN, unSNAT
254254
dftFlows = append(dftFlows,
255255
fmt.Sprintf("cookie=%s, priority=500, in_port=%s, %s, %s_src=%s, %s_dst=%s,"+
@@ -272,7 +272,7 @@ func (b *BridgeConfiguration) flowsForDefaultBridge(extraIPs []net.IP) ([]string
272272
dftFlows = append(dftFlows, reassemblyFlows...)
273273
}
274274
if ofPortPhys != "" {
275-
for _, netConfig := range b.PatchedNetConfigs() {
275+
for _, netConfig := range b.patchedNetConfigs() {
276276
var actions string
277277
if config.Gateway.Mode != config.GatewayModeLocal || config.Gateway.DisablePacketMTUCheck {
278278
actions = fmt.Sprintf("output:%s", netConfig.OfPortPatch)
@@ -351,7 +351,7 @@ func (b *BridgeConfiguration) flowsForDefaultBridge(extraIPs []net.IP) ([]string
351351
// table 2, priority 200, dispatch from UDN -> Host -> OVN. These packets have
352352
// already been SNATed to the UDN's masq IP or have been marked with the UDN's packet mark.
353353
if config.IPv4Mode {
354-
for _, netConfig := range b.PatchedNetConfigs() {
354+
for _, netConfig := range b.patchedNetConfigs() {
355355
if netConfig.IsDefaultNetwork() {
356356
continue
357357
}
@@ -389,7 +389,7 @@ func (b *BridgeConfiguration) flowsForDefaultBridge(extraIPs []net.IP) ([]string
389389
}
390390

391391
if config.IPv6Mode {
392-
for _, netConfig := range b.PatchedNetConfigs() {
392+
for _, netConfig := range b.patchedNetConfigs() {
393393
if netConfig.IsDefaultNetwork() {
394394
continue
395395
}
@@ -516,7 +516,7 @@ func (b *BridgeConfiguration) commonFlows(hostSubnets []*net.IPNet) ([]string, e
516516
if ofPortPhys != "" {
517517
// table 0, we check to see if this dest mac is the shared mac, if so flood to all ports
518518
actions := ""
519-
for _, netConfig := range b.PatchedNetConfigs() {
519+
for _, netConfig := range b.patchedNetConfigs() {
520520
actions += "output:" + netConfig.OfPortPatch + ","
521521
}
522522

@@ -528,7 +528,7 @@ func (b *BridgeConfiguration) commonFlows(hostSubnets []*net.IPNet) ([]string, e
528528

529529
// table 0, check packets coming from OVN have the correct mac address. Low priority flows that are a catch all
530530
// for non-IP packets that would normally be forwarded with NORMAL action (table 0, priority 0 flow).
531-
for _, netConfig := range b.PatchedNetConfigs() {
531+
for _, netConfig := range b.patchedNetConfigs() {
532532
dftFlows = append(dftFlows,
533533
fmt.Sprintf("cookie=%s, priority=10, table=0, in_port=%s, dl_src=%s, actions=output:NORMAL",
534534
nodetypes.DefaultOpenFlowCookie, netConfig.OfPortPatch, bridgeMacAddress))
@@ -543,7 +543,7 @@ func (b *BridgeConfiguration) commonFlows(hostSubnets []*net.IPNet) ([]string, e
543543
return nil, fmt.Errorf("unable to determine IPv4 physical IP of host: %v", err)
544544
}
545545
if ofPortPhys != "" {
546-
for _, netConfig := range b.PatchedNetConfigs() {
546+
for _, netConfig := range b.patchedNetConfigs() {
547547
// table0, packets coming from egressIP pods that have mark 1008 on them
548548
// will be SNAT-ed a final time into nodeIP to maintain consistency in traffic even if the GR
549549
// SNATs these into egressIP prior to reaching external bridge.
@@ -602,7 +602,7 @@ func (b *BridgeConfiguration) commonFlows(hostSubnets []*net.IPNet) ([]string, e
602602
nodetypes.DefaultOpenFlowCookie, ofPortHost, config.Default.ConntrackZone, nodetypes.CtMarkHost, mod_vlan_id, ofPortPhys))
603603
}
604604
if config.Gateway.Mode == config.GatewayModeLocal {
605-
for _, netConfig := range b.PatchedNetConfigs() {
605+
for _, netConfig := range b.patchedNetConfigs() {
606606
// table 0, any packet coming from OVN send to host in LGW mode, host will take care of sending it outside if needed.
607607
// exceptions are traffic for egressIP and egressGW features and ICMP related traffic which will hit the priority 100 flow instead of this.
608608
dftFlows = append(dftFlows,
@@ -642,7 +642,7 @@ func (b *BridgeConfiguration) commonFlows(hostSubnets []*net.IPNet) ([]string, e
642642
return nil, fmt.Errorf("unable to determine IPv6 physical IP of host: %v", err)
643643
}
644644
if ofPortPhys != "" {
645-
for _, netConfig := range b.PatchedNetConfigs() {
645+
for _, netConfig := range b.patchedNetConfigs() {
646646
// table0, packets coming from egressIP pods that have mark 1008 on them
647647
// will be DNAT-ed a final time into nodeIP to maintain consistency in traffic even if the GR
648648
// DNATs these into egressIP prior to reaching external bridge.
@@ -701,7 +701,7 @@ func (b *BridgeConfiguration) commonFlows(hostSubnets []*net.IPNet) ([]string, e
701701

702702
}
703703
if config.Gateway.Mode == config.GatewayModeLocal {
704-
for _, netConfig := range b.PatchedNetConfigs() {
704+
for _, netConfig := range b.patchedNetConfigs() {
705705
// table 0, any packet coming from OVN send to host in LGW mode, host will take care of sending it outside if needed.
706706
// exceptions are traffic for egressIP and egressGW features and ICMP related traffic which will hit the priority 100 flow instead of this.
707707
dftFlows = append(dftFlows,
@@ -761,7 +761,7 @@ func (b *BridgeConfiguration) commonFlows(hostSubnets []*net.IPNet) ([]string, e
761761
}
762762

763763
if ofPortPhys != "" {
764-
for _, netConfig := range b.PatchedNetConfigs() {
764+
for _, netConfig := range b.patchedNetConfigs() {
765765
isNetworkAdvertised := netConfig.Advertised.Load()
766766
// disableSNATMultipleGWs only applies to default network
767767
disableSNATMultipleGWs := netConfig.IsDefaultNetwork() && config.Gateway.DisableSNATMultipleGWs
@@ -839,7 +839,7 @@ func (b *BridgeConfiguration) commonFlows(hostSubnets []*net.IPNet) ([]string, e
839839
"actions=output:%s", nodetypes.DefaultOpenFlowCookie, ofPortHost))
840840

841841
// Send UDN destined traffic to right patch port
842-
for _, netConfig := range b.PatchedNetConfigs() {
842+
for _, netConfig := range b.patchedNetConfigs() {
843843
if netConfig.MasqCTMark != nodetypes.CtMarkOVN {
844844
dftFlows = append(dftFlows,
845845
fmt.Sprintf("cookie=%s, priority=5, table=11, ct_mark=%s, "+
@@ -868,7 +868,7 @@ func (b *BridgeConfiguration) PMTUDDropFlows(ipAddrs []string) []string {
868868
return nil
869869
}
870870
for _, addr := range ipAddrs {
871-
for _, netConfig := range b.PatchedNetConfigs() {
871+
for _, netConfig := range b.patchedNetConfigs() {
872872
flows = append(flows,
873873
nodeutil.GenerateICMPFragmentationFlow(addr, nodetypes.OutputPortDrop, netConfig.OfPortPatch, nodetypes.PmtudOpenFlowCookie, 700))
874874
}

0 commit comments

Comments
 (0)