FD.io VPP  v18.01.2-1-g9b554f3
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 
30 #include "fa_node.h"
31 #include "hash_lookup_types.h"
32 
33 #define ACL_PLUGIN_VERSION_MAJOR 1
34 #define ACL_PLUGIN_VERSION_MINOR 3
35 
36 #define UDP_SESSION_IDLE_TIMEOUT_SEC 600
37 #define TCP_SESSION_IDLE_TIMEOUT_SEC (3600*24)
38 #define TCP_SESSION_TRANSIENT_TIMEOUT_SEC 120
39 
40 #define ACL_FA_DEFAULT_HEAP_SIZE (2 << 29)
41 
42 #define ACL_PLUGIN_HASH_LOOKUP_HEAP_SIZE (2 << 25)
43 #define ACL_PLUGIN_HASH_LOOKUP_HASH_BUCKETS 65536
44 #define ACL_PLUGIN_HASH_LOOKUP_HASH_MEMORY (2 << 25)
45 
48 
49 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);
50 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);
51 
57 };
58 
59 
60 enum address_e { IP4, IP6 };
61 typedef struct
62 {
63  enum address_e type;
64  union {
67  } addr;
68 } address_t;
69 
70 /*
71  * ACL rules
72  */
73 typedef struct
74 {
77  ip46_address_t src;
79  ip46_address_t dst;
88 } acl_rule_t;
89 
90 typedef struct
91 {
94  u8 src_mac[6];
95  u8 src_mac_mask[6];
96  ip46_address_t src_ip_addr;
99 
100 /*
101  * ACL
102  */
103 typedef struct
104 {
105  u8 tag[64];
108 } acl_list_t;
109 
110 typedef struct
111 {
112  u8 tag[64];
115  /* References to the classifier tables that will enforce the rules */
120 
121 /*
122  * An element describing a particular configuration fo the mask,
123  * and how many times it has been used.
124  */
125 typedef struct
126 {
130 
131 typedef struct {
132  /* mheap to hold all the ACL module related allocations, other than hash */
133  void *acl_mheap;
135 
136  /* API message ID base */
138 
139  acl_list_t *acls; /* Pool of ACLs */
140  hash_acl_info_t *hash_acl_infos; /* corresponding hash matching housekeeping info */
141  clib_bihash_48_8_t acl_lookup_hash; /* ACL lookup hash table. */
144 
145  /* mheap to hold all the miscellaneous allocations related to hash-based lookups */
153 
154  macip_acl_list_t *macip_acls; /* Pool of MAC-IP ACLs */
155 
156  /* ACLs associated with interfaces */
159 
160  /* interfaces on which given ACLs are applied */
163 
164  /* Total count of interface+direction pairs enabled */
166 
167  /* Do we use hash-based ACL matching or linear */
169 
170  /* a pool of all mask types present in all ACEs */
172 
173  /*
174  * Classify tables used to grab the packets for the ACL check,
175  * and serving as the 5-tuple session tables at the same time
176  */
181 
186 
187  /* MACIP (input) ACLs associated with the interfaces */
189 
190  /* bitmaps when set the processing is enabled on the interface */
193  /* bihash holding all of the sessions */
195  clib_bihash_40_8_t fa_sessions_hash;
196  /* The process node which orcherstrates the cleanup */
198  /* FA session timeouts, in seconds */
199  u32 session_timeout_sec[ACL_N_TIMEOUTS];
200  /* total session adds/dels */
203 
204  /* L2 datapath glue */
205 
206  /* next indices within L2 classifiers for ip4/ip6 fa L2 nodes */
211  /* next node indices for L2 dispatch */
212  u32 fa_acl_in_ip4_l2_node_feat_next_node_index[32];
213  u32 fa_acl_in_ip6_l2_node_feat_next_node_index[32];
214  u32 fa_acl_out_ip4_l2_node_feat_next_node_index[32];
215  u32 fa_acl_out_ip6_l2_node_feat_next_node_index[32];
216 
217  /* EH values that we can skip over */
219 
220  /* whether to match L4 ACEs with ports on the non-initial fragment */
222 
223  /* conn table per-interface conn table parameters */
227 
228  /*
229  * If the cleaner has to delete more than this number
230  * of connections, it halves the sleep time.
231  */
232 
233 #define ACL_FA_DEFAULT_MAX_DELETED_SESSIONS_PER_INTERVAL 100
235 
236  /*
237  * If the cleaner deletes less than these connections,
238  * it increases the wait time by the "increment"
239  */
240 
241 #define ACL_FA_DEFAULT_MIN_DELETED_SESSIONS_PER_INTERVAL 1
243 
244 #define ACL_FA_DEFAULT_CLEANER_WAIT_TIME_INCREMENT 0.1
246 
248 
250 
251  /* per-worker data related t conn management */
253 
254  /* Configured session timeout */
255  u64 session_timeout[ACL_N_TIMEOUTS];
256 
257 
258  /* Counters for the cleaner thread */
259 
260 #define foreach_fa_cleaner_counter \
261  _(fa_cleaner_cnt_delete_by_sw_index, "delete_by_sw_index events") \
262  _(fa_cleaner_cnt_delete_by_sw_index_ok, "delete_by_sw_index handled ok") \
263  _(fa_cleaner_cnt_unknown_event, "unknown events received") \
264  _(fa_cleaner_cnt_timer_restarted, "session idle timers restarted") \
265  _(fa_cleaner_cnt_wait_with_timeout, "event wait with timeout called") \
266  _(fa_cleaner_cnt_wait_without_timeout, "event wait w/o timeout called") \
267  _(fa_cleaner_cnt_event_cycles, "total event cycles") \
268 /* end of counters */
269 #define _(id, desc) u32 id;
271 #undef _
272 
273  /* convenience */
276 } acl_main_t;
277 
278 #define foreach_acl_eh \
279  _(HOPBYHOP , 0 , "IPv6ExtHdrHopByHop") \
280  _(ROUTING , 43 , "IPv6ExtHdrRouting") \
281  _(DESTOPT , 60 , "IPv6ExtHdrDestOpt") \
282  _(FRAGMENT , 44 , "IPv6ExtHdrFragment") \
283  _(MOBILITY , 135, "Mobility Header") \
284  _(HIP , 139, "Experimental use Host Identity Protocol") \
285  _(SHIM6 , 140, "Shim6 Protocol") \
286  _(EXP1 , 253, "Use for experimentation and testing") \
287  _(EXP2 , 254, "Use for experimentation and testing")
288 
289 /*
290 
291  "No Next Header" is not a header.
292  Also, Fragment header needs special processing.
293 
294  _(NONEXT , 59 , "NoNextHdr") \
295 
296 
297 ESP is hiding its internal format, so no point in trying to go past it.
298 
299  _(ESP , 50 , "EncapsulatingSecurityPayload") \
300 
301 
302 AH has a special treatment of its length, it is in 32-bit words, not 64-bit words like the rest.
303 
304  _(AUTH , 51 , "Authentication Header") \
305 
306 
307 */
308 
309 
310  typedef enum {
311  #define _(N, v, s) ACL_EH_##N = v,
313  #undef _
314  } acl_eh_t;
315 
316 
317 
318 extern acl_main_t acl_main;
319 
320 
321 #endif
acl_rule_t * rules
Definition: acl.h:107
macip_acl_rule_t * rules
Definition: acl.h:114
u32 * acl_ip4_output_classify_table_by_sw_if_index
Definition: acl.h:179
u32 fa_cleaner_node_index
Definition: acl.h:197
u32 * acl_dot1ad_input_classify_table_by_sw_if_index
Definition: acl.h:183
uword * fa_out_acl_on_sw_if_index
Definition: acl.h:192
u8 is_ipv6
Definition: acl.h:76
fa_5tuple_t mask
Definition: acl.h:127
Definition: acl.h:125
u64 fa_current_cleaner_timer_wait_interval
Definition: acl.h:247
Definition: acl.h:61
u32 ** input_acl_vec_by_sw_if_index
Definition: acl.h:157
u16 msg_id_base
Definition: acl.h:137
uword * fa_in_acl_on_sw_if_index
Definition: acl.h:191
int l4_match_nonfirst_fragment
Definition: acl.h:221
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)
u8 dst_prefixlen
Definition: acl.h:80
u32 * acl_ip6_input_classify_table_by_sw_if_index
Definition: acl.h:178
u32 count
Definition: acl.h:106
u32 l2_table_index
Definition: acl.h:118
ip6_address_t ip6
Definition: acl.h:65
struct _vlib_node_registration vlib_node_registration_t
Definition: acl.h:60
u32 l2_input_classify_next_acl_ip4
Definition: acl.h:207
applied_hash_acl_info_t * output_applied_hash_acl_info_by_sw_if_index
Definition: acl.h:152
vlib_node_registration_t acl_out_node
f64 fa_cleaner_wait_time_increment
Definition: acl.h:245
uword fa_conn_table_hash_memory_size
Definition: acl.h:225
u16 dst_port_or_code_last
Definition: acl.h:85
u32 l2_output_classify_next_acl_ip4
Definition: acl.h:209
u8 src_prefixlen
Definition: acl.h:78
ip46_address_t src_ip_addr
Definition: acl.h:96
Definition: acl.h:60
address_e
Definition: acl.h:60
acl_eh_t
Definition: acl.h:310
u64 fa_conn_table_max_entries
Definition: acl.h:226
vnet_main_t * vnet_main
Definition: acl.h:275
ip46_address_t src
Definition: acl.h:77
u8 src_prefixlen
Definition: acl.h:97
u8 is_permit
Definition: acl.h:75
unsigned long u64
Definition: types.h:89
u32 ip4_table_index
Definition: acl.h:116
clib_bihash_40_8_t fa_sessions_hash
Definition: acl.h:195
ip4_address_t ip4
Definition: acl.h:66
u32 * acl_ip4_input_classify_table_by_sw_if_index
Definition: acl.h:177
ip46_address_t dst
Definition: acl.h:79
applied_hash_acl_info_t * input_applied_hash_acl_info_by_sw_if_index
Definition: acl.h:151
u16 dst_port_or_code_first
Definition: acl.h:84
uword * fa_ipv6_known_eh_bitmap
Definition: acl.h:218
hash_acl_info_t * hash_acl_infos
Definition: acl.h:140
clib_bihash_48_8_t acl_lookup_hash
Definition: acl.h:141
#define foreach_acl_eh
Definition: acl.h:278
u32 l2_input_classify_next_acl_ip6
Definition: acl.h:208
vlib_node_registration_t acl_in_node
u32 fa_total_enabled_count
Definition: acl.h:165
u8 proto
Definition: acl.h:81
u16 src_port_or_type_first
Definition: acl.h:82
u64 fa_min_deleted_sessions_per_interval
Definition: acl.h:242
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
u32 refcount
Definition: acl.h:128
applied_hash_ace_entry_t ** output_hash_entry_vec_by_sw_if_index
Definition: acl.h:150
u64 fa_session_total_adds
Definition: acl.h:201
int acl_lookup_hash_initialized
Definition: acl.h:148
Definition: acl.h:73
int use_hash_acl_matching
Definition: acl.h:168
#define foreach_fa_cleaner_counter
Definition: acl.h:260
u8 is_ipv6
Definition: acl.h:93
u32 hash_lookup_hash_buckets
Definition: acl.h:142
unsigned int u32
Definition: types.h:88
u16 src_port_or_type_last
Definition: acl.h:83
Bitmaps built as vectors of machine words.
u64 uword
Definition: types.h:112
ace_mask_type_entry_t * ace_mask_type_pool
Definition: acl.h:171
u32 * macip_acl_by_sw_if_index
Definition: acl.h:188
u32 * acl_ip6_output_classify_table_by_sw_if_index
Definition: acl.h:180
unsigned short u16
Definition: types.h:57
macip_acl_list_t * macip_acls
Definition: acl.h:154
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
u32 ip6_table_index
Definition: acl.h:117
u8 tcp_flags_mask
Definition: acl.h:87
acl_fa_per_worker_data_t * per_worker_data
Definition: acl.h:252
int fa_interrupt_generation
Definition: acl.h:249
u32 ** input_sw_if_index_vec_by_acl
Definition: acl.h:161
u64 fa_max_deleted_sessions_per_interval
Definition: acl.h:234
void * acl_mheap
Definition: acl.h:133
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)
u8 tcp_flags_value
Definition: acl.h:86
void * hash_lookup_mheap
Definition: acl.h:146
u32 acl_mheap_size
Definition: acl.h:134
vhost_vring_addr_t addr
Definition: vhost-user.h:83
u32 ** output_sw_if_index_vec_by_acl
Definition: acl.h:162
u32 * acl_dot1q_output_classify_table_by_sw_if_index
Definition: acl.h:184
u32 hash_lookup_mheap_size
Definition: acl.h:147
acl_timeout_e
Definition: acl.h:52
u32 l2_output_classify_next_acl_ip6
Definition: acl.h:210
int fa_sessions_hash_is_initialized
Definition: acl.h:194
acl_list_t * acls
Definition: acl.h:139
acl_main_t acl_main
Definition: jvpp_acl.h:39
u32 ** output_acl_vec_by_sw_if_index
Definition: acl.h:158
u8 is_permit
Definition: acl.h:92
u32 hash_lookup_hash_memory
Definition: acl.h:143
u32 fa_conn_table_hash_num_buckets
Definition: acl.h:224
u32 * acl_dot1q_input_classify_table_by_sw_if_index
Definition: acl.h:182
u64 fa_session_total_dels
Definition: acl.h:202
applied_hash_ace_entry_t ** input_hash_entry_vec_by_sw_if_index
Definition: acl.h:149
foreach_fa_cleaner_counter vlib_main_t * vlib_main
Definition: acl.h:274
u32 * acl_dot1ad_output_classify_table_by_sw_if_index
Definition: acl.h:185