@@ -123,12 +123,14 @@ type Client struct {
123
123
// markToSNATIP caches marks to SNAT IPs. It's used in Egress feature.
124
124
markToSNATIP sync.Map
125
125
// iptablesInitialized is used to notify when iptables initialization is done.
126
- iptablesInitialized chan struct {}
127
- proxyAll bool
128
- connectUplinkToBridge bool
129
- multicastEnabled bool
130
- isCloudEKS bool
131
- nodeNetworkPolicyEnabled bool
126
+ iptablesInitialized chan struct {}
127
+ proxyAll bool
128
+ connectUplinkToBridge bool
129
+ multicastEnabled bool
130
+ isCloudEKS bool
131
+ nodeNetworkPolicyEnabled bool
132
+ nodeLatencyMonitorEnabled bool
133
+ networkPolicyOnlyMode bool
132
134
// serviceRoutes caches ip routes about Services.
133
135
serviceRoutes sync.Map
134
136
// serviceExternalIPReferences tracks the references of Service IP. The key is the Service IP and the value is
@@ -163,6 +165,10 @@ type Client struct {
163
165
wireguardIPTablesIPv4 sync.Map
164
166
// wireguardIPTablesIPv6 caches all existing IPv6 iptables chains and rules for WireGuard.
165
167
wireguardIPTablesIPv6 sync.Map
168
+ // nodeLatencyMonitorIPTablesIPv4 caches all existing IPv4 iptables chains and rules for NodeLatencyMonitor.
169
+ nodeLatencyMonitorIPTablesIPv4 sync.Map
170
+ // nodeLatencyMonitorIPTablesIPv6 caches all existing IPv6 iptables chains and rules for NodeLatencyMonitor.
171
+ nodeLatencyMonitorIPTablesIPv6 sync.Map
166
172
// deterministic represents whether to write iptables chains and rules for NodeNetworkPolicy deterministically when
167
173
// syncIPTables is called. Enabling it may carry a performance impact. It's disabled by default and should only be
168
174
// used in testing.
@@ -178,6 +184,7 @@ func NewClient(networkConfig *config.NetworkConfig,
178
184
proxyAll bool ,
179
185
connectUplinkToBridge bool ,
180
186
nodeNetworkPolicyEnabled bool ,
187
+ nodeLatencyMonitorEnabled bool ,
181
188
multicastEnabled bool ,
182
189
nodeSNATRandomFully bool ,
183
190
egressSNATRandomFully bool ,
@@ -192,6 +199,7 @@ func NewClient(networkConfig *config.NetworkConfig,
192
199
multicastEnabled : multicastEnabled ,
193
200
connectUplinkToBridge : connectUplinkToBridge ,
194
201
nodeNetworkPolicyEnabled : nodeNetworkPolicyEnabled ,
202
+ nodeLatencyMonitorEnabled : nodeLatencyMonitorEnabled ,
195
203
ipset : ipset .NewClient (),
196
204
netlink : & netlink.Handle {},
197
205
isCloudEKS : env .IsCloudEKS (),
@@ -278,6 +286,10 @@ func (c *Client) Initialize(nodeConfig *config.NodeConfig, done func()) error {
278
286
if c .networkConfig .TrafficEncryptionMode == config .TrafficEncryptionModeWireGuard {
279
287
c .initWireguard ()
280
288
}
289
+ if c .nodeLatencyMonitorEnabled {
290
+ c .initNodeLatency ()
291
+ }
292
+
281
293
return nil
282
294
}
283
295
@@ -737,10 +749,12 @@ func (c *Client) syncIPTables() error {
737
749
// for performance reasons.
738
750
addFilterRulesToChain (iptablesFilterRulesByChainV4 , & c .wireguardIPTablesIPv4 )
739
751
addFilterRulesToChain (iptablesFilterRulesByChainV4 , & c .nodeNetworkPolicyIPTablesIPv4 )
752
+ addFilterRulesToChain (iptablesFilterRulesByChainV4 , & c .nodeLatencyMonitorIPTablesIPv4 )
740
753
741
754
iptablesFilterRulesByChainV6 := make (map [string ][]string )
742
755
addFilterRulesToChain (iptablesFilterRulesByChainV6 , & c .wireguardIPTablesIPv6 )
743
756
addFilterRulesToChain (iptablesFilterRulesByChainV6 , & c .nodeNetworkPolicyIPTablesIPv6 )
757
+ addFilterRulesToChain (iptablesFilterRulesByChainV6 , & c .nodeLatencyMonitorIPTablesIPv6 )
744
758
745
759
// Use iptables-restore to configure IPv4 settings.
746
760
if c .networkConfig .IPv4Enabled {
@@ -1245,6 +1259,38 @@ func (c *Client) initWireguard() {
1245
1259
}
1246
1260
}
1247
1261
1262
+ func (c * Client ) initNodeLatency () {
1263
+ gateway := "antrea-gw0"
1264
+ if c .networkConfig .TrafficEncapMode .String () == "networkPolicyOnly" {
1265
+ gateway = "transport"
1266
+ }
1267
+ antreaInputChainRules := []string {
1268
+ iptables .NewRuleBuilder (antreaInputChain ).
1269
+ MatchInputInterface (gateway ).
1270
+ SetComment ("Antrea: allow ICMP packets from NodeLatencyMonitor" ).
1271
+ SetTarget (iptables .AcceptTarget ).
1272
+ Done ().
1273
+ GetRule (),
1274
+ }
1275
+ antreaOutputChainRules := []string {
1276
+ iptables .NewRuleBuilder (antreaOutputChain ).
1277
+ MatchOutputInterface (gateway ).
1278
+ SetComment ("Antrea: allow egress packets from NodeLatencyMonitor" ).
1279
+ SetTarget (iptables .AcceptTarget ).
1280
+ Done ().
1281
+ GetRule (),
1282
+ }
1283
+
1284
+ if c .networkConfig .IPv6Enabled {
1285
+ c .nodeLatencyMonitorIPTablesIPv6 .Store (antreaInputChain , antreaInputChainRules )
1286
+ c .nodeLatencyMonitorIPTablesIPv6 .Store (antreaOutputChain , antreaOutputChainRules )
1287
+ }
1288
+ if c .networkConfig .IPv4Enabled {
1289
+ c .nodeLatencyMonitorIPTablesIPv4 .Store (antreaInputChain , antreaInputChainRules )
1290
+ c .nodeLatencyMonitorIPTablesIPv4 .Store (antreaOutputChain , antreaOutputChainRules )
1291
+ }
1292
+ }
1293
+
1248
1294
// Reconcile removes orphaned podCIDRs from ipset and removes routes to orphaned podCIDRs
1249
1295
// based on the desired podCIDRs.
1250
1296
func (c * Client ) Reconcile (podCIDRs []string ) error {
0 commit comments