@@ -420,19 +420,22 @@ func (c *Controller) setIptables() error {
420
420
klog .V (3 ).Infof ("centralized subnets nat ips %v" , subnetNatips )
421
421
422
422
var (
423
+ v4AbandonedRules = []util.IPTableRule {
424
+ {Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (`-m mark --mark 0x40000/0x40000 -j MASQUERADE` )},
425
+ {Table : "mangle" , Chain : "PREROUTING" , Rule : strings .Fields (`-i ovn0 -m set --match-set ovn40subnets src -m set --match-set ovn40services dst -j MARK --set-xmark 0x40000/0x40000` )},
426
+ }
427
+ v6AbandonedRules = []util.IPTableRule {
428
+ {Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (`-m mark --mark 0x40000/0x40000 -j MASQUERADE` )},
429
+ {Table : "mangle" , Chain : "PREROUTING" , Rule : strings .Fields (`-i ovn0 -m set --match-set ovn60subnets src -m set --match-set ovn60services dst -j MARK --set-xmark 0x40000/0x40000` )},
430
+ }
431
+
423
432
v4Rules = []util.IPTableRule {
424
433
// do not nat route traffic
425
434
{Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (`-m set ! --match-set ovn40subnets src -m set ! --match-set ovn40other-node src -m set --match-set ovn40local-pod-ip-nat dst -j RETURN` )},
426
435
{Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (`-m set ! --match-set ovn40subnets src -m set ! --match-set ovn40other-node src -m set --match-set ovn40subnets-nat dst -j RETURN` )},
427
436
// nat outgoing
428
437
{Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (`-m set --match-set ovn40subnets-nat src -m set ! --match-set ovn40subnets dst -j MASQUERADE` )},
429
438
{Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (`-m set --match-set ovn40local-pod-ip-nat src -m set ! --match-set ovn40subnets dst -j MASQUERADE` )},
430
- // external traffic to overlay pod or to service
431
- // {Table: "nat", Chain: "POSTROUTING", Rule: strings.Fields(fmt.Sprintf(`! -s %s -m set --match-set ovn40subnets dst -j MASQUERADE`, nodeIPv4))},
432
- // masq traffic from overlay pod to service
433
- {Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (`-m mark --mark 0x40000/0x40000 -j MASQUERADE` )},
434
- // mark traffic from overlay pod to service
435
- {Table : "mangle" , Chain : "PREROUTING" , Rule : strings .Fields (`-i ovn0 -m set --match-set ovn40subnets src -m set --match-set ovn40services dst -j MARK --set-xmark 0x40000/0x40000` )},
436
439
// Input Accept
437
440
{Table : "filter" , Chain : "INPUT" , Rule : strings .Fields (`-m set --match-set ovn40subnets src -j ACCEPT` )},
438
441
{Table : "filter" , Chain : "INPUT" , Rule : strings .Fields (`-m set --match-set ovn40subnets dst -j ACCEPT` )},
@@ -453,12 +456,6 @@ func (c *Controller) setIptables() error {
453
456
// nat outgoing
454
457
{Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (`-m set --match-set ovn60subnets-nat src -m set ! --match-set ovn60subnets dst -j MASQUERADE` )},
455
458
{Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (`-m set --match-set ovn60local-pod-ip-nat src -m set ! --match-set ovn60subnets dst -j MASQUERADE` )},
456
- // external traffic to overlay pod or to service
457
- // {Table: "nat", Chain: "POSTROUTING", Rule: strings.Fields(fmt.Sprintf(`! -s %s -m set --match-set ovn60subnets dst -j MASQUERADE`, nodeIPv6))},
458
- // masq traffic from overlay pod to service
459
- {Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (`-m mark --mark 0x40000/0x40000 -j MASQUERADE` )},
460
- // mark traffic from overlay pod to service
461
- {Table : "mangle" , Chain : "PREROUTING" , Rule : strings .Fields (`-i ovn0 -m set --match-set ovn60subnets src -m set --match-set ovn60services dst -j MARK --set-xmark 0x40000/0x40000` )},
462
459
// Input Accept
463
460
{Table : "filter" , Chain : "INPUT" , Rule : strings .Fields (`-m set --match-set ovn60subnets src -j ACCEPT` )},
464
461
{Table : "filter" , Chain : "INPUT" , Rule : strings .Fields (`-m set --match-set ovn60subnets dst -j ACCEPT` )},
@@ -494,19 +491,22 @@ func (c *Controller) setIptables() error {
494
491
var matchset string
495
492
var abandonedRules , iptablesRules []util.IPTableRule
496
493
if protocol == kubeovnv1 .ProtocolIPv4 {
497
- iptablesRules = v4Rules
494
+ iptablesRules , abandonedRules = v4Rules , v4AbandonedRules
498
495
matchset = "ovn40subnets"
499
496
} else {
500
- iptablesRules = v6Rules
497
+ iptablesRules , abandonedRules = v6Rules , v6AbandonedRules
501
498
matchset = "ovn60subnets"
502
499
}
503
500
504
501
if nodeIP := nodeIPs [protocol ]; nodeIP != "" {
505
- abandonedRules = append (abandonedRules , util.IPTableRule {Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (fmt .Sprintf (`-o ovn0 ! -s %s -m mark --mark 0x4000/0x4000 -j MASQUERADE` , nodeIP ))})
502
+ abandonedRules = append (abandonedRules ,
503
+ util.IPTableRule {Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (fmt .Sprintf (`-o ovn0 ! -s %s -m mark --mark 0x4000/0x4000 -j MASQUERADE` , nodeIP ))},
504
+ util.IPTableRule {Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (fmt .Sprintf (`! -s %s -m set --match-set %s dst -j MASQUERADE` , nodeIP , matchset ))},
505
+ )
506
506
507
507
rules := make ([]util.IPTableRule , len (iptablesRules )+ 1 )
508
508
copy (rules [:4 ], iptablesRules [:4 ])
509
- rules [4 ] = util.IPTableRule {Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (fmt .Sprintf (`! -s %s -m set --match-set %s dst -j MASQUERADE` , nodeIP , matchset ))}
509
+ rules [4 ] = util.IPTableRule {Table : "nat" , Chain : "POSTROUTING" , Rule : strings .Fields (fmt .Sprintf (`! -s %s -m set ! --match-set %s src -m set --match-set %s dst -j MASQUERADE` , nodeIP , matchset , matchset ))}
510
510
copy (rules [5 :], iptablesRules [4 :])
511
511
iptablesRules = rules
512
512
}
0 commit comments