Skip to content

Commit 9554ba6

Browse files
committed
Add dontSNAT subnets rules to mgmtport-snat
This PR adds rules to prevent SNAT if source IP belongs to the mgmtport-no-snat-subnets-v4 or mgmtport-no-snat-subnets-v6 sets, which store IPv4 and IPv6 subnets, respectively. Signed-off-by: Yossi Boaron <[email protected]>
1 parent 15a2c63 commit 9554ba6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

go-controller/pkg/node/managementport/port_linux.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,18 @@ func setupManagementPortNFTSets() error {
321321
Comment: knftables.PtrTo("eTP:Local short-circuit not subject to management port SNAT (IPv6)"),
322322
Type: "ipv6_addr . inet_proto . inet_service",
323323
})
324+
tx.Add(&knftables.Set{
325+
Name: types.NFTMgmtPortNoSNATSubnetsV4,
326+
Comment: knftables.PtrTo("subnets not subject to management port SNAT (IPv4)"),
327+
Type: "ipv4_addr",
328+
Flags: []knftables.SetFlag{knftables.IntervalFlag},
329+
})
330+
tx.Add(&knftables.Set{
331+
Name: types.NFTMgmtPortNoSNATSubnetsV6,
332+
Comment: knftables.PtrTo("subnets not subject to management port SNAT (IPv6)"),
333+
Type: "ipv6_addr",
334+
Flags: []knftables.SetFlag{knftables.IntervalFlag},
335+
})
324336

325337
err = nft.Run(context.TODO(), tx)
326338
if err != nil {
@@ -402,6 +414,14 @@ func setupManagementPortNFTChain(interfaceName string, cfg *managementPortConfig
402414
"return",
403415
),
404416
})
417+
tx.Add(&knftables.Rule{
418+
Chain: nftMgmtPortChain,
419+
Rule: knftables.Concat(
420+
"ip saddr", "@", types.NFTMgmtPortNoSNATSubnetsV4,
421+
counterIfDebug,
422+
"return",
423+
),
424+
})
405425
tx.Add(&knftables.Rule{
406426
Chain: nftMgmtPortChain,
407427
Rule: knftables.Concat(
@@ -441,6 +461,14 @@ func setupManagementPortNFTChain(interfaceName string, cfg *managementPortConfig
441461
"return",
442462
),
443463
})
464+
tx.Add(&knftables.Rule{
465+
Chain: nftMgmtPortChain,
466+
Rule: knftables.Concat(
467+
"ip6 saddr", "@", types.NFTMgmtPortNoSNATSubnetsV6,
468+
counterIfDebug,
469+
"return",
470+
),
471+
})
444472
tx.Add(&knftables.Rule{
445473
Chain: nftMgmtPortChain,
446474
Rule: knftables.Concat(

go-controller/pkg/types/const.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,10 @@ const (
330330
MetricOvsNamespace = "ovs"
331331
MetricOvsSubsystemVswitchd = "vswitchd"
332332
MetricOvsSubsystemDB = "db"
333+
334+
// "mgmtport-no-snat-subnets-v4" and "mgmtport-no-snat-subnets-v6" are sets containing
335+
// subnets, indicating traffic that should not be SNATted when passing through the
336+
// management port.
337+
NFTMgmtPortNoSNATSubnetsV4 = "mgmtport-no-snat-subnets-v4"
338+
NFTMgmtPortNoSNATSubnetsV6 = "mgmtport-no-snat-subnets-v6"
333339
)

0 commit comments

Comments
 (0)