acl-plugin: warning printed when acl_add_replace already applied ACLs (complete the...
[vpp.git] / src / plugins / acl / hash_lookup_types.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #ifndef _ACL_HASH_LOOKUP_TYPES_H_
19 #define _ACL_HASH_LOOKUP_TYPES_H_
20
21 /* The structure representing the single entry with hash representation */
22 typedef struct {
23   /* these two entries refer to the original ACL# and rule# within that ACL */
24   u32 acl_index;
25   u32 ace_index;
26
27   u32 mask_type_index;
28   u8 src_portrange_not_powerof2;
29   u8 dst_portrange_not_powerof2;
30
31   fa_5tuple_t match;
32   u8 action;
33 } hash_ace_info_t;
34
35 /*
36  * The structure holding the information necessary for the hash-based ACL operation
37  */
38 typedef struct {
39   /* The mask types present in this ACL */
40   uword *mask_type_index_bitmap;
41   /* hash ACL applied on these interfaces */
42   u32 *inbound_sw_if_index_list;
43   u32 *outbound_sw_if_index_list;
44   hash_ace_info_t *rules;
45 } hash_acl_info_t;
46
47 typedef struct {
48   /* original non-compiled ACL */
49   u32 acl_index;
50   u32 ace_index;
51   /* the index of the hash_ace_info_t */
52   u32 hash_ace_info_index;
53   /*
54    * in case of the same key having multiple entries,
55    * this holds the index of the next entry.
56    */
57   u32 next_applied_entry_index;
58   /*
59    * previous entry in the list of the chained ones,
60    * if ~0 then this is entry in the hash.
61    */
62   u32 prev_applied_entry_index;
63   /*
64    * chain tail, if this is the first entry
65    */
66   u32 tail_applied_entry_index;
67   /*
68    * Action of this applied ACE
69    */
70   u8 action;
71 } applied_hash_ace_entry_t;
72
73 typedef struct {
74    /*
75     * A logical OR of all the applied_ace_hash_entry_t=>
76     *                            hash_ace_info_t=>mask_type_index bits set
77     */
78    uword *mask_type_index_bitmap;
79    /* applied ACLs so we can track them independently from main ACL module */
80    u32 *applied_acls;
81 } applied_hash_acl_info_t;
82
83
84 typedef union {
85   u64 as_u64;
86   struct {
87     u32 applied_entry_index;
88     u16 reserved_u16;
89     u8 reserved_u8;
90     /* means there is some other entry in front intersecting with this one */
91     u8 shadowed:1;
92     u8 need_portrange_check:1;
93     u8 reserved_flags:6;
94   };
95 } hash_acl_lookup_value_t;
96
97 #define CT_ASSERT_EQUAL(name, x,y) typedef int assert_ ## name ## _compile_time_assertion_failed[((x) == (y))-1]
98
99 CT_ASSERT_EQUAL(hash_acl_lookup_value_t_is_u64, sizeof(hash_acl_lookup_value_t), sizeof(u64));
100
101 #undef CT_ASSERT_EQUAL
102
103 #endif