@@ -22,29 +22,32 @@ import (
22
22
func (c * ovnNbClient ) UpdateIngressAclOps (pgName , asIngressName , asExceptName , protocol string , npp []netv1.NetworkPolicyPort , logEnable bool , namedPortMap map [string ]* util.NamedPortInfo ) ([]ovsdb.Operation , error ) {
23
23
acls := make ([]* ovnnb.ACL , 0 )
24
24
25
- ipSuffix := "ip4"
26
- if protocol == kubeovnv1 .ProtocolIPv6 {
27
- ipSuffix = "ip6"
28
- }
25
+ if strings .HasSuffix (asIngressName , ".0" ) || strings .HasSuffix (asIngressName , ".all" ) {
26
+ // create the default drop rule for only once
27
+ ipSuffix := "ip4"
28
+ if protocol == kubeovnv1 .ProtocolIPv6 {
29
+ ipSuffix = "ip6"
30
+ }
29
31
30
- /* default drop acl */
31
- allIpMatch := NewAndAclMatch (
32
- NewAclMatch ("outport" , "==" , "@" + pgName , "" ),
33
- NewAclMatch (ipSuffix , "" , "" , "" ),
34
- )
35
- options := func (acl * ovnnb.ACL ) {
36
- if logEnable {
37
- acl .Log = true
38
- acl .Severity = & ovnnb .ACLSeverityWarning
32
+ /* default drop acl */
33
+ allIpMatch := NewAndAclMatch (
34
+ NewAclMatch ("outport" , "==" , "@" + pgName , "" ),
35
+ NewAclMatch (ipSuffix , "" , "" , "" ),
36
+ )
37
+ options := func (acl * ovnnb.ACL ) {
38
+ if logEnable {
39
+ acl .Log = true
40
+ acl .Severity = & ovnnb .ACLSeverityWarning
41
+ }
39
42
}
40
- }
41
43
42
- defaultDropAcl , err := c .newAclWithoutCheck (pgName , ovnnb .ACLDirectionToLport , util .IngressDefaultDrop , allIpMatch .String (), ovnnb .ACLActionDrop , options )
43
- if err != nil {
44
- return nil , fmt .Errorf ("new default drop ingress acl for port group %s: %v" , pgName , err )
45
- }
44
+ defaultDropAcl , err := c .newAclWithoutCheck (pgName , ovnnb .ACLDirectionToLport , util .IngressDefaultDrop , allIpMatch .String (), ovnnb .ACLActionDrop , options )
45
+ if err != nil {
46
+ return nil , fmt .Errorf ("new default drop ingress acl for port group %s: %v" , pgName , err )
47
+ }
46
48
47
- acls = append (acls , defaultDropAcl )
49
+ acls = append (acls , defaultDropAcl )
50
+ }
48
51
49
52
/* allow acl */
50
53
matches := newNetworkPolicyAclMatch (pgName , asIngressName , asExceptName , protocol , ovnnb .ACLDirectionToLport , npp , namedPortMap )
@@ -69,36 +72,39 @@ func (c *ovnNbClient) UpdateIngressAclOps(pgName, asIngressName, asExceptName, p
69
72
func (c * ovnNbClient ) UpdateEgressAclOps (pgName , asEgressName , asExceptName , protocol string , npp []netv1.NetworkPolicyPort , logEnable bool , namedPortMap map [string ]* util.NamedPortInfo ) ([]ovsdb.Operation , error ) {
70
73
acls := make ([]* ovnnb.ACL , 0 )
71
74
72
- ipSuffix := "ip4"
73
- if protocol == kubeovnv1 .ProtocolIPv6 {
74
- ipSuffix = "ip6"
75
- }
75
+ if strings .HasSuffix (asEgressName , ".0" ) || strings .HasSuffix (asEgressName , ".all" ) {
76
+ // create the default drop rule for only once
77
+ ipSuffix := "ip4"
78
+ if protocol == kubeovnv1 .ProtocolIPv6 {
79
+ ipSuffix = "ip6"
80
+ }
76
81
77
- /* default drop acl */
78
- allIpMatch := NewAndAclMatch (
79
- NewAclMatch ("inport" , "==" , "@" + pgName , "" ),
80
- NewAclMatch (ipSuffix , "" , "" , "" ),
81
- )
82
- options := func (acl * ovnnb.ACL ) {
83
- if logEnable {
84
- acl .Log = true
85
- acl .Severity = & ovnnb .ACLSeverityWarning
82
+ /* default drop acl */
83
+ allIpMatch := NewAndAclMatch (
84
+ NewAclMatch ("inport" , "==" , "@" + pgName , "" ),
85
+ NewAclMatch (ipSuffix , "" , "" , "" ),
86
+ )
87
+ options := func (acl * ovnnb.ACL ) {
88
+ if logEnable {
89
+ acl .Log = true
90
+ acl .Severity = & ovnnb .ACLSeverityWarning
91
+ }
92
+
93
+ if acl .Options == nil {
94
+ acl .Options = make (map [string ]string )
95
+ }
96
+ acl .Options ["apply-after-lb" ] = "true"
86
97
}
87
98
88
- if acl .Options == nil {
89
- acl .Options = make (map [string ]string )
99
+ defaultDropAcl , err := c .newAclWithoutCheck (pgName , ovnnb .ACLDirectionFromLport , util .EgressDefaultDrop , allIpMatch .String (), ovnnb .ACLActionDrop , options )
100
+ if err != nil {
101
+ klog .Error (err )
102
+ return nil , fmt .Errorf ("new default drop egress acl for port group %s: %v" , pgName , err )
90
103
}
91
- acl .Options ["apply-after-lb" ] = "true"
92
- }
93
104
94
- defaultDropAcl , err := c .newAclWithoutCheck (pgName , ovnnb .ACLDirectionFromLport , util .EgressDefaultDrop , allIpMatch .String (), ovnnb .ACLActionDrop , options )
95
- if err != nil {
96
- klog .Error (err )
97
- return nil , fmt .Errorf ("new default drop egress acl for port group %s: %v" , pgName , err )
105
+ acls = append (acls , defaultDropAcl )
98
106
}
99
107
100
- acls = append (acls , defaultDropAcl )
101
-
102
108
/* allow acl */
103
109
matches := newNetworkPolicyAclMatch (pgName , asEgressName , asExceptName , protocol , ovnnb .ACLDirectionFromLport , npp , namedPortMap )
104
110
for _ , m := range matches {
0 commit comments