FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
acl.h
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 #ifndef included_acl_h
16 #define included_acl_h
17 
18 #include <vnet/vnet.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/l2/l2_output.h>
21 
22 
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>
29 #include <vppinfra/bihash_16_8.h>
30 
31 #include "types.h"
32 #include "fa_node.h"
33 #include "hash_lookup_types.h"
34 #include "lookup_context.h"
35 
36 #define ACL_PLUGIN_VERSION_MAJOR 1
37 #define ACL_PLUGIN_VERSION_MINOR 3
38 
39 #define UDP_SESSION_IDLE_TIMEOUT_SEC 600
40 #define TCP_SESSION_IDLE_TIMEOUT_SEC (3600*24)
41 #define TCP_SESSION_TRANSIENT_TIMEOUT_SEC 120
42 
43 #define SESSION_PURGATORY_TIMEOUT_USEC 10
44 
45 #define ACL_PLUGIN_HASH_LOOKUP_HEAP_SIZE (2 << 25)
46 #define ACL_PLUGIN_HASH_LOOKUP_HASH_BUCKETS 65536
47 #define ACL_PLUGIN_HASH_LOOKUP_HASH_MEMORY (2 << 25)
48 
51 
52 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);
53 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);
54 
61  ACL_TIMEOUT_PURGATORY = ACL_N_USER_TIMEOUTS, /* a special-case queue for deletion-in-progress sessions */
63 };
64 
65 
66 enum address_e { IP4, IP6 };
67 typedef struct
68 {
69  enum address_e type;
70  union {
73  } addr;
74 } address_t;
75 
76 typedef struct
77 {
80  u8 src_mac[6];
81  u8 src_mac_mask[6];
82  ip46_address_t src_ip_addr;
85 
86 /*
87  * ACL
88  */
89 typedef struct
90 {
91  /** Required for pool_get_aligned */
92  CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
93  u8 tag[64];
95 } acl_list_t;
96 
97 typedef struct
98 {
99  /** Required for pool_get_aligned */
100  CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
101  u8 tag[64];
104  /* References to the classifier tables that will enforce the rules */
108  /* outacl classifier tables */
113 
114 /*
115  * An element describing a particular configuration fo the mask,
116  * and how many times it has been used.
117  */
118 typedef struct
119 {
120  /** Required for pool_get_aligned */
121  CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
126 
127 typedef struct {
128  /* mheap to hold all the ACL module related allocations, other than hash */
129  void *acl_mheap;
131 
132  /* API message ID base */
134 
135  /* The pool of users of ACL lookup contexts */
137  /* The pool of ACL lookup contexts */
139 
140  acl_list_t *acls; /* Pool of ACLs */
141  hash_acl_info_t *hash_acl_infos; /* corresponding hash matching housekeeping info */
142  clib_bihash_48_8_t acl_lookup_hash; /* ACL lookup hash table. */
145 
146  /* mheap to hold all the miscellaneous allocations related to hash-based lookups */
150 /*
151  applied_hash_ace_entry_t **input_hash_entry_vec_by_sw_if_index;
152  applied_hash_ace_entry_t **output_hash_entry_vec_by_sw_if_index;
153  applied_hash_acl_info_t *input_applied_hash_acl_info_by_sw_if_index;
154  applied_hash_acl_info_t *output_applied_hash_acl_info_by_sw_if_index;
155 */
158 
159  /* Corresponding lookup context indices for in/out lookups per sw_if_index */
162  /* context user id for interface ACLs */
164 
165  macip_acl_list_t *macip_acls; /* Pool of MAC-IP ACLs */
166 
167  /* ACLs associated with interfaces */
170 
171  /* interfaces on which given ACLs are applied */
174 
175  /* bitmaps 1=sw_if_index has in/out ACL processing enabled */
178 
179  /* lookup contexts where a given ACL is used */
181 
182  /* input and output policy epochs by interface */
185 
186  /* whether we need to take the epoch of the session into account */
188 
189 
190 
191  /* Total count of interface+direction pairs enabled */
193 
194  /* Do we use hash-based ACL matching or linear */
196 
197  /* Do we use the TupleMerge for hash ACLs or not */
199 
200  /* Max collision vector length before splitting the tuple */
201 #define TM_SPLIT_THRESHOLD 39
203 
204  /* a pool of all mask types present in all ACEs */
206 
207  /* vec of vectors of all info of all mask types present in ACEs contained in each lc_index */
209 
210  /*
211  * Classify tables used to grab the packets for the ACL check,
212  * and serving as the 5-tuple session tables at the same time
213  */
218 
223 
226 
229 
230  /* MACIP (input) ACLs associated with the interfaces */
232 
233  /* Vector of interfaces on which given MACIP ACLs are applied */
235 
236  /* bitmaps when set the processing is enabled on the interface */
239  /* bihash holding all of the sessions */
241  clib_bihash_40_8_t fa_ip6_sessions_hash;
242  clib_bihash_16_8_t fa_ip4_sessions_hash;
243  /* The process node which orchestrates the cleanup */
245  /* FA session timeouts, in seconds */
246  u32 session_timeout_sec[ACL_N_TIMEOUTS];
247  /* total session adds/dels */
250  /* how many sessions went into purgatory */
252 
253  /* EH values that we can skip over */
255 
256  /* whether to match L4 ACEs with ports on the non-initial fragment */
258 
259  /* conn table per-interface conn table parameters */
263 
266 
267  /*
268  * If the cleaner has to delete more than this number
269  * of connections, it halves the sleep time.
270  */
271 
272 #define ACL_FA_DEFAULT_MAX_DELETED_SESSIONS_PER_INTERVAL 100
274 
275  /*
276  * If the cleaner deletes less than these connections,
277  * it increases the wait time by the "increment"
278  */
279 
280 #define ACL_FA_DEFAULT_MIN_DELETED_SESSIONS_PER_INTERVAL 1
282 
283 #define ACL_FA_DEFAULT_CLEANER_WAIT_TIME_INCREMENT 0.1
285 
287 
289 
290  /* per-worker data related t conn management */
292 
293  /* Configured session timeout */
294  u64 session_timeout[ACL_N_TIMEOUTS];
295 
296 
297  /* Counters for the cleaner thread */
298 
299 #define foreach_fa_cleaner_counter \
300  _(fa_cleaner_cnt_delete_by_sw_index, "delete_by_sw_index events") \
301  _(fa_cleaner_cnt_delete_by_sw_index_ok, "delete_by_sw_index handled ok") \
302  _(fa_cleaner_cnt_unknown_event, "unknown events received") \
303  _(fa_cleaner_cnt_timer_restarted, "session idle timers restarted") \
304  _(fa_cleaner_cnt_wait_with_timeout, "event wait with timeout called") \
305  _(fa_cleaner_cnt_wait_without_timeout, "event wait w/o timeout called") \
306  _(fa_cleaner_cnt_event_cycles, "total event cycles") \
307 /* end of counters */
308 #define _(id, desc) u32 id;
310 #undef _
311 
312  /* convenience */
315  /* logging */
317 } acl_main_t;
318 
319 #define acl_log_err(...) \
320  vlib_log(VLIB_LOG_LEVEL_ERR, acl_main.log_default, __VA_ARGS__)
321 #define acl_log_warn(...) \
322  vlib_log(VLIB_LOG_LEVEL_WARNING, acl_main.log_default, __VA_ARGS__)
323 #define acl_log_notice(...) \
324  vlib_log(VLIB_LOG_LEVEL_NOTICE, acl_main.log_default, __VA_ARGS__)
325 #define acl_log_info(...) \
326  vlib_log(VLIB_LOG_LEVEL_INFO, acl_main.log_default, __VA_ARGS__)
327 
328 
329 
330 #define foreach_acl_eh \
331  _(HOPBYHOP , 0 , "IPv6ExtHdrHopByHop") \
332  _(ROUTING , 43 , "IPv6ExtHdrRouting") \
333  _(DESTOPT , 60 , "IPv6ExtHdrDestOpt") \
334  _(FRAGMENT , 44 , "IPv6ExtHdrFragment") \
335  _(MOBILITY , 135, "Mobility Header") \
336  _(HIP , 139, "Experimental use Host Identity Protocol") \
337  _(SHIM6 , 140, "Shim6 Protocol") \
338  _(EXP1 , 253, "Use for experimentation and testing") \
339  _(EXP2 , 254, "Use for experimentation and testing")
340 
341 /*
342 
343  "No Next Header" is not a header.
344  Also, Fragment header needs special processing.
345 
346  _(NONEXT , 59 , "NoNextHdr") \
347 
348 
349 ESP is hiding its internal format, so no point in trying to go past it.
350 
351  _(ESP , 50 , "EncapsulatingSecurityPayload") \
352 
353 
354 AH has a special treatment of its length, it is in 32-bit words, not 64-bit words like the rest.
355 
356  _(AUTH , 51 , "Authentication Header") \
357 
358 
359 */
360 
361 
362  typedef enum {
363  #define _(N, v, s) ACL_EH_##N = v,
365  #undef _
366  } acl_eh_t;
367 
368 
369 
370 extern acl_main_t acl_main;
371 
372 void *acl_plugin_set_heap();
373 
374 typedef enum {
378 
379 void aclp_post_session_change_request(acl_main_t *am, u32 target_thread, u32 target_session, acl_fa_sess_req_t request_type);
381 
382 #endif
acl_rule_t * rules
Definition: acl.h:94
u32 * input_policy_epoch_by_sw_if_index
Definition: acl.h:183
u32 sw_if_index
Definition: ipsec_gre.api:37
macip_acl_rule_t * rules
Definition: acl.h:103
u32 * acl_ip4_output_classify_table_by_sw_if_index
Definition: acl.h:216
u32 fa_cleaner_node_index
Definition: acl.h:244
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
u32 * acl_dot1ad_input_classify_table_by_sw_if_index
Definition: acl.h:220
uword * fa_out_acl_on_sw_if_index
Definition: acl.h:238
fa_5tuple_t mask
Definition: acl.h:122
Definition: acl.h:118
u64 fa_current_cleaner_timer_wait_interval
Definition: acl.h:286
clib_bihash_40_8_t fa_ip6_sessions_hash
Definition: acl.h:241
Definition: acl.h:67
u32 ** input_acl_vec_by_sw_if_index
Definition: acl.h:168
u16 msg_id_base
Definition: acl.h:133
u32 out_l2_table_index
Definition: acl.h:111
uword * fa_in_acl_on_sw_if_index
Definition: acl.h:237
void aclp_post_session_change_request(acl_main_t *am, u32 target_thread, u32 target_session, acl_fa_sess_req_t request_type)
unsigned long u64
Definition: types.h:89
int l4_match_nonfirst_fragment
Definition: acl.h:257
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)
u32 * acl_ip6_input_classify_table_by_sw_if_index
Definition: acl.h:215
u32 l2_table_index
Definition: acl.h:107
ip6_address_t ip6
Definition: acl.h:71
u32 * acl_etype_output_classify_table_by_sw_if_index
Definition: acl.h:225
Definition: acl.h:66
u32 * output_policy_epoch_by_sw_if_index
Definition: acl.h:184
acl_fa_sess_req_t
Definition: acl.h:374
vhost_vring_addr_t addr
Definition: vhost_user.h:121
unsigned char u8
Definition: types.h:56
vlib_node_registration_t acl_out_node
vlib_log_class_t log_default
Definition: acl.h:316
double f64
Definition: types.h:142
f64 fa_cleaner_wait_time_increment
Definition: acl.h:284
u32 interface_acl_user_id
Definition: acl.h:163
u32 ** lc_index_vec_by_acl
Definition: acl.h:180
uword fa_conn_table_hash_memory_size
Definition: acl.h:261
u32 vlib_log_class_t
Definition: vlib.h:50
ip46_address_t src_ip_addr
Definition: acl.h:82
Definition: acl.h:66
address_e
Definition: acl.h:66
acl_eh_t
Definition: acl.h:362
u64 fa_conn_table_max_entries
Definition: acl.h:262
vnet_main_t * vnet_main
Definition: acl.h:314
u8 src_prefixlen
Definition: acl.h:83
uword * in_acl_on_sw_if_index
Definition: acl.h:176
unsigned int u32
Definition: types.h:88
u32 ip4_table_index
Definition: acl.h:105
ip4_address_t ip4
Definition: acl.h:72
u32 * acl_ip4_input_classify_table_by_sw_if_index
Definition: acl.h:214
u8 from_tm
Definition: acl.h:124
hash_applied_mask_info_t ** hash_applied_mask_info_vec_by_lc_index
Definition: acl.h:208
unsigned short u16
Definition: types.h:57
uword * fa_ipv6_known_eh_bitmap
Definition: acl.h:254
hash_acl_info_t * hash_acl_infos
Definition: acl.h:141
u32 * output_lc_index_by_sw_if_index
Definition: acl.h:161
clib_bihash_48_8_t acl_lookup_hash
Definition: acl.h:142
#define foreach_acl_eh
Definition: acl.h:330
vlib_node_registration_t acl_in_node
u32 fa_total_enabled_count
Definition: acl.h:192
u64 fa_min_deleted_sessions_per_interval
Definition: acl.h:281
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
u32 refcount
Definition: acl.h:123
u64 fa_session_total_adds
Definition: acl.h:248
applied_hash_acl_info_t * applied_hash_acl_info_by_lc_index
Definition: acl.h:157
int acl_lookup_hash_initialized
Definition: acl.h:149
void * acl_plugin_set_heap()
Definition: acl.c:160
int use_hash_acl_matching
Definition: acl.h:195
applied_hash_ace_entry_t ** hash_entry_vec_by_lc_index
Definition: acl.h:156
uword hash_lookup_hash_memory
Definition: acl.h:144
#define foreach_fa_cleaner_counter
Definition: acl.h:299
int tuple_merge_split_threshold
Definition: acl.h:202
u8 is_ipv6
Definition: acl.h:79
int trace_acl
Definition: acl.h:265
u32 hash_lookup_hash_buckets
Definition: acl.h:143
int trace_sessions
Definition: acl.h:264
u32 out_ip6_table_index
Definition: acl.h:110
uword * out_acl_on_sw_if_index
Definition: acl.h:177
Bitmaps built as vectors of machine words.
u32 ** sw_if_index_vec_by_macip_acl
Definition: acl.h:234
u32 * acl_etype_input_classify_table_by_sw_if_index
Definition: acl.h:224
uword acl_mheap_size
Definition: acl.h:130
ace_mask_type_entry_t * ace_mask_type_pool
Definition: acl.h:205
struct _vlib_node_registration vlib_node_registration_t
u32 * macip_acl_by_sw_if_index
Definition: acl.h:231
u32 * acl_ip6_output_classify_table_by_sw_if_index
Definition: acl.h:217
acl_lookup_context_t * acl_lookup_contexts
Definition: acl.h:138
macip_acl_list_t * macip_acls
Definition: acl.h:165
void aclp_swap_wip_and_pending_session_change_requests(acl_main_t *am, u32 target_thread)
uword hash_lookup_mheap_size
Definition: acl.h:148
u32 ip6_table_index
Definition: acl.h:106
VLIB buffer representation.
Definition: buffer.h:102
acl_fa_per_worker_data_t * per_worker_data
Definition: acl.h:291
u64 uword
Definition: types.h:112
int fa_interrupt_generation
Definition: acl.h:288
u32 ** input_sw_if_index_vec_by_acl
Definition: acl.h:172
int use_tuple_merge
Definition: acl.h:198
u16 ** output_etype_whitelist_by_sw_if_index
Definition: acl.h:228
u64 fa_max_deleted_sessions_per_interval
Definition: acl.h:273
void * acl_mheap
Definition: acl.h:129
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)
u16 ** input_etype_whitelist_by_sw_if_index
Definition: acl.h:227
void * hash_lookup_mheap
Definition: acl.h:147
u64 fa_session_total_deactivations
Definition: acl.h:251
int reclassify_sessions
Definition: acl.h:187
u32 * input_lc_index_by_sw_if_index
Definition: acl.h:160
Definition: acl.h:89
u32 out_ip4_table_index
Definition: acl.h:109
u32 ** output_sw_if_index_vec_by_acl
Definition: acl.h:173
u32 * acl_dot1q_output_classify_table_by_sw_if_index
Definition: acl.h:221
acl_timeout_e
Definition: acl.h:55
clib_bihash_16_8_t fa_ip4_sessions_hash
Definition: acl.h:242
int fa_sessions_hash_is_initialized
Definition: acl.h:240
acl_list_t * acls
Definition: acl.h:140
acl_main_t acl_main
Definition: acl.c:57
acl_lookup_context_user_t * acl_users
Definition: acl.h:136
u32 ** output_acl_vec_by_sw_if_index
Definition: acl.h:169
u8 is_permit
Definition: acl.h:78
u32 fa_conn_table_hash_num_buckets
Definition: acl.h:260
u32 * acl_dot1q_input_classify_table_by_sw_if_index
Definition: acl.h:219
u64 fa_session_total_dels
Definition: acl.h:249
foreach_fa_cleaner_counter vlib_main_t * vlib_main
Definition: acl.h:313
u32 * acl_dot1ad_output_classify_table_by_sw_if_index
Definition: acl.h:222