@@ -616,6 +616,21 @@ func (c *Controller) setIptables() error {
616
616
kubeProxyIpsetProtocol , matchset , svcMatchset , nodeMatchSet = "6-" , "ovn60subnets" , "ovn60services" , "ovn60" + OtherNodeSet
617
617
}
618
618
619
+ ipset := fmt .Sprintf ("KUBE-%sCLUSTER-IP" , kubeProxyIpsetProtocol )
620
+ ipsetExists , err := c .ipsetExists (ipset )
621
+ if err != nil {
622
+ klog .Error ("failed to check existence of ipset %s: %v" , ipset , err )
623
+ return err
624
+ }
625
+ if ipsetExists {
626
+ iptablesRules [0 ].Rule = strings .Fields (fmt .Sprintf (`-i ovn0 -m set --match-set %s src -m set --match-set %s dst,dst -j MARK --set-xmark 0x4000/0x4000` , matchset , ipset ))
627
+ rejectRule := strings .Fields (fmt .Sprintf (`-m mark ! --mark 0x4000/0x4000 -m set --match-set %s dst -m conntrack --ctstate NEW -j REJECT` , svcMatchset ))
628
+ iptablesRules = append (iptablesRules ,
629
+ util.IPTableRule {Table : "filter" , Chain : "INPUT" , Rule : rejectRule },
630
+ util.IPTableRule {Table : "filter" , Chain : "OUTPUT" , Rule : rejectRule },
631
+ )
632
+ }
633
+
619
634
if nodeIP := nodeIPs [protocol ]; nodeIP != "" {
620
635
obsoleteRules = []util.IPTableRule {
621
636
{Table : NAT , Chain : Postrouting , Rule : strings .Fields (fmt .Sprintf (`! -s %s -m set --match-set %s dst -j MASQUERADE` , nodeIP , matchset ))},
@@ -956,8 +971,8 @@ func (c *Controller) generateNatOutgoingPolicyChainRules(protocol string) ([]uti
956
971
natPolicySubnetUIDs .Add (util .GetTruncatedUID (string (subnet .GetUID ())))
957
972
cidrBlock := getCidrByProtocol (subnet .Spec .CIDRBlock , protocol )
958
973
959
- OvnNatPolicySubnetChainName := OvnNatOutGoingPolicySubnet + util .GetTruncatedUID (string (subnet .GetUID ()))
960
- natPolicySubnetIptables = append (natPolicySubnetIptables , util.IPTableRule {Table : NAT , Chain : OvnNatOutGoingPolicy , Rule : strings .Fields (fmt .Sprintf (`-s %s -m comment --comment natPolicySubnet-%s -j %s` , cidrBlock , subnet .Name , OvnNatPolicySubnetChainName ))})
974
+ ovnNatPolicySubnetChainName := OvnNatOutGoingPolicySubnet + util .GetTruncatedUID (string (subnet .GetUID ()))
975
+ natPolicySubnetIptables = append (natPolicySubnetIptables , util.IPTableRule {Table : NAT , Chain : OvnNatOutGoingPolicy , Rule : strings .Fields (fmt .Sprintf (`-s %s -m comment --comment natPolicySubnet-%s -j %s` , cidrBlock , subnet .Name , ovnNatPolicySubnetChainName ))})
961
976
for _ , rule := range subnet .Status .NatOutgoingPolicyRules {
962
977
var markCode string
963
978
if rule .Action == util .NatPolicyRuleActionNat {
@@ -981,21 +996,21 @@ func (c *Controller) generateNatOutgoingPolicyChainRules(protocol string) ([]uti
981
996
srcMatch := getNatOutGoingPolicyRuleIPSetName (rule .RuleID , "src" , protocol , true )
982
997
dstMatch := getNatOutGoingPolicyRuleIPSetName (rule .RuleID , "dst" , protocol , true )
983
998
984
- var OvnNatoutGoingPolicyRule util.IPTableRule
999
+ var ovnNatoutGoingPolicyRule util.IPTableRule
985
1000
if rule .Match .DstIPs != "" && rule .Match .SrcIPs != "" {
986
- OvnNatoutGoingPolicyRule = util.IPTableRule {Table : NAT , Chain : OvnNatPolicySubnetChainName , Rule : strings .Fields (fmt .Sprintf (`-m set --match-set %s src -m set --match-set %s dst -j MARK --set-xmark %s` , srcMatch , dstMatch , markCode ))}
1001
+ ovnNatoutGoingPolicyRule = util.IPTableRule {Table : NAT , Chain : ovnNatPolicySubnetChainName , Rule : strings .Fields (fmt .Sprintf (`-m set --match-set %s src -m set --match-set %s dst -j MARK --set-xmark %s` , srcMatch , dstMatch , markCode ))}
987
1002
} else if rule .Match .SrcIPs != "" {
988
1003
protocol = getMatchProtocol (rule .Match .SrcIPs )
989
- OvnNatoutGoingPolicyRule = util.IPTableRule {Table : NAT , Chain : OvnNatPolicySubnetChainName , Rule : strings .Fields (fmt .Sprintf (`-m set --match-set %s src -j MARK --set-xmark %s` , srcMatch , markCode ))}
1004
+ ovnNatoutGoingPolicyRule = util.IPTableRule {Table : NAT , Chain : ovnNatPolicySubnetChainName , Rule : strings .Fields (fmt .Sprintf (`-m set --match-set %s src -j MARK --set-xmark %s` , srcMatch , markCode ))}
990
1005
} else if rule .Match .DstIPs != "" {
991
1006
protocol = getMatchProtocol (rule .Match .DstIPs )
992
- OvnNatoutGoingPolicyRule = util.IPTableRule {Table : NAT , Chain : OvnNatPolicySubnetChainName , Rule : strings .Fields (fmt .Sprintf (`-m set --match-set %s dst -j MARK --set-xmark %s` , dstMatch , markCode ))}
1007
+ ovnNatoutGoingPolicyRule = util.IPTableRule {Table : NAT , Chain : ovnNatPolicySubnetChainName , Rule : strings .Fields (fmt .Sprintf (`-m set --match-set %s dst -j MARK --set-xmark %s` , dstMatch , markCode ))}
993
1008
} else {
994
1009
continue
995
1010
}
996
- natPolicyRuleIptables = append (natPolicyRuleIptables , OvnNatoutGoingPolicyRule )
1011
+ natPolicyRuleIptables = append (natPolicyRuleIptables , ovnNatoutGoingPolicyRule )
997
1012
}
998
- natPolicyRuleIptablesMap [OvnNatPolicySubnetChainName ] = natPolicyRuleIptables
1013
+ natPolicyRuleIptablesMap [ovnNatPolicySubnetChainName ] = natPolicyRuleIptables
999
1014
}
1000
1015
1001
1016
existNatChains , err := c .iptables [protocol ].ListChains (NAT )
0 commit comments