Skip to content

Commit 413015f

Browse files
author
Dhruv Jain
committed
ICMP Rule with NodeLatencyMonitor
This PR provides the solution to an edge case with NodeLatencyMonitor, where the feature does not work if ICMP queries are blocked by default. To fix this, an iptable rule will be added if NodeLatencyMonitor is enabled, such that ICMP requests via the Antrea gateway will be allowed. Fixes issue #6952 Signed-off-by: Dhruv Jain <[email protected]>
1 parent d82a0b6 commit 413015f

File tree

5 files changed

+212
-23
lines changed

5 files changed

+212
-23
lines changed

cmd/antrea-agent/agent.go

+2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ func run(o *Options) error {
154154
enableBridgingMode := enableAntreaIPAM && o.config.EnableBridgingMode
155155
l7NetworkPolicyEnabled := features.DefaultFeatureGate.Enabled(features.L7NetworkPolicy)
156156
nodeNetworkPolicyEnabled := features.DefaultFeatureGate.Enabled(features.NodeNetworkPolicy)
157+
nodeLatencyMonitorEnabled := o.config.FeatureGates[string(features.NodeLatencyMonitor)]
157158
l7FlowExporterEnabled := features.DefaultFeatureGate.Enabled(features.L7FlowExporter)
158159
enableMulticlusterGW := features.DefaultFeatureGate.Enabled(features.Multicluster) && o.config.Multicluster.EnableGateway
159160
_, multiclusterEncryptionMode := config.GetTrafficEncryptionModeFromStr(o.config.Multicluster.TrafficEncryptionMode)
@@ -241,6 +242,7 @@ func run(o *Options) error {
241242
o.config.AntreaProxy.ProxyAll,
242243
connectUplinkToBridge,
243244
nodeNetworkPolicyEnabled,
245+
nodeLatencyMonitorEnabled,
244246
multicastEnabled,
245247
o.config.SNATFullyRandomPorts,
246248
*o.config.Egress.SNATFullyRandomPorts,

pkg/agent/route/route_linux.go

+52-6
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,14 @@ type Client struct {
123123
// markToSNATIP caches marks to SNAT IPs. It's used in Egress feature.
124124
markToSNATIP sync.Map
125125
// 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
132134
// serviceRoutes caches ip routes about Services.
133135
serviceRoutes sync.Map
134136
// serviceExternalIPReferences tracks the references of Service IP. The key is the Service IP and the value is
@@ -163,6 +165,10 @@ type Client struct {
163165
wireguardIPTablesIPv4 sync.Map
164166
// wireguardIPTablesIPv6 caches all existing IPv6 iptables chains and rules for WireGuard.
165167
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
166172
// deterministic represents whether to write iptables chains and rules for NodeNetworkPolicy deterministically when
167173
// syncIPTables is called. Enabling it may carry a performance impact. It's disabled by default and should only be
168174
// used in testing.
@@ -178,6 +184,7 @@ func NewClient(networkConfig *config.NetworkConfig,
178184
proxyAll bool,
179185
connectUplinkToBridge bool,
180186
nodeNetworkPolicyEnabled bool,
187+
nodeLatencyMonitorEnabled bool,
181188
multicastEnabled bool,
182189
nodeSNATRandomFully bool,
183190
egressSNATRandomFully bool,
@@ -192,6 +199,7 @@ func NewClient(networkConfig *config.NetworkConfig,
192199
multicastEnabled: multicastEnabled,
193200
connectUplinkToBridge: connectUplinkToBridge,
194201
nodeNetworkPolicyEnabled: nodeNetworkPolicyEnabled,
202+
nodeLatencyMonitorEnabled: nodeLatencyMonitorEnabled,
195203
ipset: ipset.NewClient(),
196204
netlink: &netlink.Handle{},
197205
isCloudEKS: env.IsCloudEKS(),
@@ -278,6 +286,10 @@ func (c *Client) Initialize(nodeConfig *config.NodeConfig, done func()) error {
278286
if c.networkConfig.TrafficEncryptionMode == config.TrafficEncryptionModeWireGuard {
279287
c.initWireguard()
280288
}
289+
if c.nodeLatencyMonitorEnabled {
290+
c.initNodeLatency()
291+
}
292+
281293
return nil
282294
}
283295

@@ -737,10 +749,12 @@ func (c *Client) syncIPTables() error {
737749
// for performance reasons.
738750
addFilterRulesToChain(iptablesFilterRulesByChainV4, &c.wireguardIPTablesIPv4)
739751
addFilterRulesToChain(iptablesFilterRulesByChainV4, &c.nodeNetworkPolicyIPTablesIPv4)
752+
addFilterRulesToChain(iptablesFilterRulesByChainV4, &c.nodeLatencyMonitorIPTablesIPv4)
740753

741754
iptablesFilterRulesByChainV6 := make(map[string][]string)
742755
addFilterRulesToChain(iptablesFilterRulesByChainV6, &c.wireguardIPTablesIPv6)
743756
addFilterRulesToChain(iptablesFilterRulesByChainV6, &c.nodeNetworkPolicyIPTablesIPv6)
757+
addFilterRulesToChain(iptablesFilterRulesByChainV6, &c.nodeLatencyMonitorIPTablesIPv6)
744758

745759
// Use iptables-restore to configure IPv4 settings.
746760
if c.networkConfig.IPv4Enabled {
@@ -1245,6 +1259,38 @@ func (c *Client) initWireguard() {
12451259
}
12461260
}
12471261

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+
12481294
// Reconcile removes orphaned podCIDRs from ipset and removes routes to orphaned podCIDRs
12491295
// based on the desired podCIDRs.
12501296
func (c *Client) Reconcile(podCIDRs []string) error {

0 commit comments

Comments
 (0)