2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 #ifndef included_acl_h
16 #define included_acl_h
18 #include <vnet/vnet.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/l2/l2_output.h>
23 #include <vppinfra/hash.h>
24 #include <vppinfra/error.h>
25 #include <vppinfra/bitmap.h>
26 #include <vppinfra/elog.h>
27 #include <vppinfra/bihash_48_8.h>
28 #include <vppinfra/bihash_40_8.h>
31 #include "hash_lookup_types.h"
32 #include "lookup_context.h"
34 #define ACL_PLUGIN_VERSION_MAJOR 1
35 #define ACL_PLUGIN_VERSION_MINOR 3
37 #define UDP_SESSION_IDLE_TIMEOUT_SEC 600
38 #define TCP_SESSION_IDLE_TIMEOUT_SEC (3600*24)
39 #define TCP_SESSION_TRANSIENT_TIMEOUT_SEC 120
41 #define ACL_PLUGIN_HASH_LOOKUP_HEAP_SIZE (2 << 25)
42 #define ACL_PLUGIN_HASH_LOOKUP_HASH_BUCKETS 65536
43 #define ACL_PLUGIN_HASH_LOOKUP_HASH_MEMORY (2 << 25)
45 extern vlib_node_registration_t acl_in_node;
46 extern vlib_node_registration_t acl_out_node;
48 void input_acl_packet_match(u32 sw_if_index, vlib_buffer_t * b0, u32 *nextp, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap);
49 void output_acl_packet_match(u32 sw_if_index, vlib_buffer_t * b0, u32 *nextp, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap);
52 ACL_TIMEOUT_UDP_IDLE = 0,
54 ACL_TIMEOUT_TCP_TRANSIENT,
59 enum address_e { IP4, IP6 };
81 u16 src_port_or_type_first;
82 u16 src_port_or_type_last;
83 u16 dst_port_or_code_first;
84 u16 dst_port_or_code_last;
95 ip46_address_t src_ip_addr;
113 macip_acl_rule_t *rules;
114 /* References to the classifier tables that will enforce the rules */
118 /* outacl classifier tables */
119 u32 out_ip4_table_index;
120 u32 out_ip6_table_index;
121 u32 out_l2_table_index;
125 * An element describing a particular configuration fo the mask,
126 * and how many times it has been used.
132 } ace_mask_type_entry_t;
135 /* mheap to hold all the ACL module related allocations, other than hash */
137 uword acl_mheap_size;
139 /* API message ID base */
142 /* The pool of users of ACL lookup contexts */
143 acl_lookup_context_user_t *acl_users;
144 /* The pool of ACL lookup contexts */
145 acl_lookup_context_t *acl_lookup_contexts;
147 acl_list_t *acls; /* Pool of ACLs */
148 hash_acl_info_t *hash_acl_infos; /* corresponding hash matching housekeeping info */
149 clib_bihash_48_8_t acl_lookup_hash; /* ACL lookup hash table. */
150 u32 hash_lookup_hash_buckets;
151 u32 hash_lookup_hash_memory;
153 /* mheap to hold all the miscellaneous allocations related to hash-based lookups */
154 void *hash_lookup_mheap;
155 uword hash_lookup_mheap_size;
156 int acl_lookup_hash_initialized;
158 applied_hash_ace_entry_t **input_hash_entry_vec_by_sw_if_index;
159 applied_hash_ace_entry_t **output_hash_entry_vec_by_sw_if_index;
160 applied_hash_acl_info_t *input_applied_hash_acl_info_by_sw_if_index;
161 applied_hash_acl_info_t *output_applied_hash_acl_info_by_sw_if_index;
163 applied_hash_ace_entry_t **hash_entry_vec_by_lc_index;
164 applied_hash_acl_info_t *applied_hash_acl_info_by_lc_index;
166 /* Corresponding lookup context indices for in/out lookups per sw_if_index */
167 u32 *input_lc_index_by_sw_if_index;
168 u32 *output_lc_index_by_sw_if_index;
169 /* context user id for interface ACLs */
170 u32 interface_acl_user_id;
172 macip_acl_list_t *macip_acls; /* Pool of MAC-IP ACLs */
174 /* ACLs associated with interfaces */
175 u32 **input_acl_vec_by_sw_if_index;
176 u32 **output_acl_vec_by_sw_if_index;
178 /* interfaces on which given ACLs are applied */
179 u32 **input_sw_if_index_vec_by_acl;
180 u32 **output_sw_if_index_vec_by_acl;
182 /* bitmaps 1=sw_if_index has in/out ACL processing enabled */
183 uword *in_acl_on_sw_if_index;
184 uword *out_acl_on_sw_if_index;
186 /* lookup contexts where a given ACL is used */
187 u32 **lc_index_vec_by_acl;
189 /* input and output policy epochs by interface */
190 u32 *input_policy_epoch_by_sw_if_index;
191 u32 *output_policy_epoch_by_sw_if_index;
193 /* whether we need to take the epoch of the session into account */
194 int reclassify_sessions;
198 /* Total count of interface+direction pairs enabled */
199 u32 fa_total_enabled_count;
201 /* Do we use hash-based ACL matching or linear */
202 int use_hash_acl_matching;
204 /* a pool of all mask types present in all ACEs */
205 ace_mask_type_entry_t *ace_mask_type_pool;
208 * Classify tables used to grab the packets for the ACL check,
209 * and serving as the 5-tuple session tables at the same time
211 u32 *acl_ip4_input_classify_table_by_sw_if_index;
212 u32 *acl_ip6_input_classify_table_by_sw_if_index;
213 u32 *acl_ip4_output_classify_table_by_sw_if_index;
214 u32 *acl_ip6_output_classify_table_by_sw_if_index;
216 u32 *acl_dot1q_input_classify_table_by_sw_if_index;
217 u32 *acl_dot1ad_input_classify_table_by_sw_if_index;
218 u32 *acl_dot1q_output_classify_table_by_sw_if_index;
219 u32 *acl_dot1ad_output_classify_table_by_sw_if_index;
221 u32 *acl_etype_input_classify_table_by_sw_if_index;
222 u32 *acl_etype_output_classify_table_by_sw_if_index;
224 u16 **input_etype_whitelist_by_sw_if_index;
225 u16 **output_etype_whitelist_by_sw_if_index;
227 /* MACIP (input) ACLs associated with the interfaces */
228 u32 *macip_acl_by_sw_if_index;
230 /* Vector of interfaces on which given MACIP ACLs are applied */
231 u32 **sw_if_index_vec_by_macip_acl;
233 /* bitmaps when set the processing is enabled on the interface */
234 uword *fa_in_acl_on_sw_if_index;
235 uword *fa_out_acl_on_sw_if_index;
236 /* bihash holding all of the sessions */
237 int fa_sessions_hash_is_initialized;
238 clib_bihash_40_8_t fa_sessions_hash;
239 /* The process node which orcherstrates the cleanup */
240 u32 fa_cleaner_node_index;
241 /* FA session timeouts, in seconds */
242 u32 session_timeout_sec[ACL_N_TIMEOUTS];
243 /* total session adds/dels */
244 u64 fa_session_total_adds;
245 u64 fa_session_total_dels;
247 /* L2 datapath glue */
249 /* next indices within L2 classifiers for ip4/ip6 fa L2 nodes */
250 u32 l2_input_classify_next_acl_ip4;
251 u32 l2_input_classify_next_acl_ip6;
252 u32 l2_output_classify_next_acl_ip4;
253 u32 l2_output_classify_next_acl_ip6;
254 /* next node indices for L2 dispatch */
255 u32 fa_acl_in_ip4_l2_node_feat_next_node_index[32];
256 u32 fa_acl_in_ip6_l2_node_feat_next_node_index[32];
257 u32 fa_acl_out_ip4_l2_node_feat_next_node_index[32];
258 u32 fa_acl_out_ip6_l2_node_feat_next_node_index[32];
260 /* EH values that we can skip over */
261 uword *fa_ipv6_known_eh_bitmap;
263 /* whether to match L4 ACEs with ports on the non-initial fragment */
264 int l4_match_nonfirst_fragment;
266 /* conn table per-interface conn table parameters */
267 u32 fa_conn_table_hash_num_buckets;
268 uword fa_conn_table_hash_memory_size;
269 u64 fa_conn_table_max_entries;
275 * If the cleaner has to delete more than this number
276 * of connections, it halves the sleep time.
279 #define ACL_FA_DEFAULT_MAX_DELETED_SESSIONS_PER_INTERVAL 100
280 u64 fa_max_deleted_sessions_per_interval;
283 * If the cleaner deletes less than these connections,
284 * it increases the wait time by the "increment"
287 #define ACL_FA_DEFAULT_MIN_DELETED_SESSIONS_PER_INTERVAL 1
288 u64 fa_min_deleted_sessions_per_interval;
290 #define ACL_FA_DEFAULT_CLEANER_WAIT_TIME_INCREMENT 0.1
291 f64 fa_cleaner_wait_time_increment;
293 u64 fa_current_cleaner_timer_wait_interval;
295 int fa_interrupt_generation;
297 /* per-worker data related t conn management */
298 acl_fa_per_worker_data_t *per_worker_data;
300 /* Configured session timeout */
301 u64 session_timeout[ACL_N_TIMEOUTS];
304 /* Counters for the cleaner thread */
306 #define foreach_fa_cleaner_counter \
307 _(fa_cleaner_cnt_delete_by_sw_index, "delete_by_sw_index events") \
308 _(fa_cleaner_cnt_delete_by_sw_index_ok, "delete_by_sw_index handled ok") \
309 _(fa_cleaner_cnt_unknown_event, "unknown events received") \
310 _(fa_cleaner_cnt_timer_restarted, "session idle timers restarted") \
311 _(fa_cleaner_cnt_wait_with_timeout, "event wait with timeout called") \
312 _(fa_cleaner_cnt_wait_without_timeout, "event wait w/o timeout called") \
313 _(fa_cleaner_cnt_event_cycles, "total event cycles") \
314 /* end of counters */
315 #define _(id, desc) u32 id;
316 foreach_fa_cleaner_counter
320 vlib_main_t * vlib_main;
321 vnet_main_t * vnet_main;
324 #define foreach_acl_eh \
325 _(HOPBYHOP , 0 , "IPv6ExtHdrHopByHop") \
326 _(ROUTING , 43 , "IPv6ExtHdrRouting") \
327 _(DESTOPT , 60 , "IPv6ExtHdrDestOpt") \
328 _(FRAGMENT , 44 , "IPv6ExtHdrFragment") \
329 _(MOBILITY , 135, "Mobility Header") \
330 _(HIP , 139, "Experimental use Host Identity Protocol") \
331 _(SHIM6 , 140, "Shim6 Protocol") \
332 _(EXP1 , 253, "Use for experimentation and testing") \
333 _(EXP2 , 254, "Use for experimentation and testing")
337 "No Next Header" is not a header.
338 Also, Fragment header needs special processing.
340 _(NONEXT , 59 , "NoNextHdr") \
343 ESP is hiding its internal format, so no point in trying to go past it.
345 _(ESP , 50 , "EncapsulatingSecurityPayload") \
348 AH has a special treatment of its length, it is in 32-bit words, not 64-bit words like the rest.
350 _(AUTH , 51 , "Authentication Header") \
357 #define _(N, v, s) ACL_EH_##N = v,
364 extern acl_main_t acl_main;
366 void *acl_plugin_set_heap();