FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
cnat_logging.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * cnat_logging.h
4  *
5  * Copyright (c) 2009, 2012 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #ifndef __CNAT_LOGGING_H__
21 #define __CNAT_LOGGING_H__
22 
23 #include <stdio.h>
24 #include <vlib/vlib.h>
25 #include <vnet/vnet.h>
26 #include <vppinfra/vec.h>
27 #include <vppinfra/bitmap.h>
28 #include <vppinfra/hash.h>
29 #include <vppinfra/pool.h>
30 #include <vppinfra/clib.h>
31 
32 #include "nat64_db.h"
33 #include "cnat_log_common.h"
34 #include "dslite_defs.h"
35 
36 #define NFV9_DEF_PATH_MTU 1500
37 #define NFV9_VRF_NAME_LEN 12
38 
39 /* one time call at the beginning */
41 
42 /*
43  * unconditional call
44  * will check logging config inside
45  */
47  cnat_vrfmap_t *vrfmap
48 #ifndef NO_BULK_LOGGING
49  , int bulk_alloc
50 #endif
51  );
52 
55  cnat_vrfmap_t *vrfmap);
56 
59  cnat_vrfmap_t *vrfmap);
60 
61 
62 /*
63  * unconditional call
64  * will check logging config inside
65  */
67  cnat_vrfmap_t *vrfmap
68 #ifndef NO_BULK_LOGGING
69  , int bulk_alloc
70 #endif
71  );
72 
73 /* nat44 syslog APIs */
75  cnat_vrfmap_t *vrfmap, cnat_session_entry_t * sdb
76 #ifndef NO_BULK_LOGGING
77  , int bulk_alloc
78 #endif
79  );
80 
83 #ifndef NO_BULK_LOGGING
84  , int bulk_alloc
85 #endif
86  );
87 
88 /*
89  * dslite
90  */
92  dslite_table_entry_t *dslite_entry
93 #ifndef NO_BULK_LOGGING
94  , int bulk_alloc
95 #endif
96  );
97 
99  dslite_table_entry_t *dslite_entry
100 #ifndef NO_BULK_LOGGING
101  , int bulk_alloc
102 #endif
103  );
105  dslite_table_entry_t *dslite_entry,
106  cnat_session_entry_t * sdb);
107 
109  dslite_table_entry_t *dslite_entry,
110  cnat_session_entry_t * sdb);
111 
112 /*
113  * nat64
114  */
115 
117  nat64_table_entry_t *nat64_entry);
118 
121  nat64_table_entry_t *nat64_entry_ptr);
122 
124  nat64_table_entry_t *nat64_entry);
125 
128  nat64_table_entry_t *nat64_entry_ptr);
129 
130 typedef enum {
151 
152 typedef enum {
156 
157 #define cnat_nfv9_get_sys_up_time_in_ms cnat_get_sys_up_time_in_ms
158 
159 #define cnat_nfv9_get_unix_time_in_seconds cnat_get_unix_time_in_seconds
160 
161 #define cnat_nfv9_dump_time_change_logs cnat_dump_time_change_logs
162 
163 
164 /*
165  * Netflow V9 Specific Defines and structures
166  */
167 
168 #define CNAT_NFV9_VERSION_NUMBER 9
169 
170 #define CNAT_NFV9_TEMPLATE_FLOWSET_ID 0
171 #define CNAT_NFV9_OPTION_TEMPLATE_FLOWSET_ID 1
172 
173 #define CNAT_NFV9_ADD_FIELD_COUNT 7
174 #define CNAT_NFV9_DEL_FIELD_COUNT 4
175 #define CNAT_NFV9_DS_LITE_ADD_FIELD_COUNT 8
176 #define CNAT_NFV9_DS_LITE_DEL_FIELD_COUNT 5
177 #define CNAT_NFV9_NAT64_ADD_BIB_FIELD_COUNT 5
178 #define CNAT_NFV9_NAT64_DEL_BIB_FIELD_COUNT 3
179 #define CNAT_NFV9_NAT64_ADD_SESSION_FIELD_COUNT 8
180 #define CNAT_NFV9_NAT64_DEL_SESSION_FIELD_COUNT 5
181 #define CNAT_NFV9_NAT44_ADD_SESSION_FIELD_COUNT 9
182 #define CNAT_NFV9_NAT44_DEL_SESSION_FIELD_COUNT 6
183 #define CNAT_NFV9_DS_LITE_ADD_SESSION_FIELD_COUNT 10
184 #define CNAT_NFV9_DS_LITE_DEL_SESSION_FIELD_COUNT 7
185 
186 #define CNAT_NFV9_ADD_TEMPLATE_ID 256
187 #define CNAT_NFV9_DEL_TEMPLATE_ID 257
188 #define CNAT_NFV9_NAT64_ADD_BIB_TEMPLATE_ID 258
189 #define CNAT_NFV9_NAT64_DEL_BIB_TEMPLATE_ID 259
190 #define CNAT_NFV9_NAT64_ADD_SESSION_TEMPLATE_ID 260
191 #define CNAT_NFV9_NAT64_DEL_SESSION_TEMPLATE_ID 261
192 #define CNAT_NFV9_INGRESS_VRF_ID_NAME_TEMPLATE_ID 262
193 #define CNAT_NFV9_DS_LITE_ADD_TEMPLATE_ID 267
194 #define CNAT_NFV9_DS_LITE_DEL_TEMPLATE_ID 268
195 #define CNAT_NFV9_NAT44_ADD_SESSION_TEMPLATE_ID 271
196 #define CNAT_NFV9_NAT44_DEL_SESSION_TEMPLATE_ID 272
197 #define CNAT_NFV9_DS_LITE_ADD_SESSION_TEMPLATE_ID 273
198 #define CNAT_NFV9_DS_LITE_DEL_SESSION_TEMPLATE_ID 274
199 
200 #ifndef NO_BULK_LOGGING
201 #define CNAT_NFV9_NAT44_BULK_ADD_TEMPLATE_ID 265
202 #define CNAT_NFV9_NAT44_BULK_DEL_TEMPLATE_ID 266
203 #define CNAT_NFV9_DS_LITE_BULK_ADD_TEMPLATE_ID 269
204 #define CNAT_NFV9_DS_LITE_BULK_DEL_TEMPLATE_ID 270
205 
206 #define CNAT_NFV9_NAT44_BULK_ADD_FIELD_COUNT 6
207 #define CNAT_NFV9_NAT44_BULK_DEL_FIELD_COUNT 3
208 #define CNAT_NFV9_DS_LITE_BULK_ADD_FIELD_COUNT 7
209 #define CNAT_NFV9_DS_LITE_BULK_DEL_FIELD_COUNT 4
210 
211 #define CNAT_NFV9_OUTSIDE_IP_PORT_START_FIELD_TYPE 361
212 #define CNAT_NFV9_OUTSIDE_IP_PORT_START_FIELD_SIZE 2
213 
214 #define CNAT_NFV9_OUTSIDE_IP_PORT_END_FIELD_TYPE 362
215 #define CNAT_NFV9_OUTSIDE_IP_PORT_END_FIELD_SIZE 2
216 
217 #endif /* #ifndef NO_BULK_LOGGING */
218 
219 #define CNAT_NFV9_INGRESS_VRF_NAME_FIELD_TYPE 236
220 #define CNAT_NFV9_INGRESS_VRF_NAME_FIELD_SIZE 12
221 /* 4 byte for vrf_id + 4 byte for vrf_name (option fields) */
222 #define CNAT_NFV9_INGRESS_VRF_ID_NAME_OPTION_LEN 8
224 
225 #define CNAT_NFV9_INSIDE_VRFID_FIELD_TYPE 234
226 #define CNAT_NFV9_INSIDE_VRFID_FIELD_SIZE 4
227 
228 #define CNAT_NFV9_OUTSIDE_VRFID_FIELD_TYPE 235
229 #define CNAT_NFV9_OUTSIDE_VRFID_FIELD_SIZE 4
230 
231 #define CNAT_NFV9_INSIDE_IP_ADDR_FIELD_TYPE 8
232 #define CNAT_NFV9_INSIDE_IP_ADDR_FIELD_SIZE 4
233 
234 #define CNAT_NFV9_OUTSIDE_IP_ADDR_FIELD_TYPE 225
235 #define CNAT_NFV9_OUTSIDE_IP_ADDR_FIELD_SIZE 4
236 
237 #define CNAT_NFV9_INSIDE_IP_PORT_FIELD_TYPE 7
238 #define CNAT_NFV9_INSIDE_IP_PORT_FIELD_SIZE 2
239 
240 #define CNAT_NFV9_OUTSIDE_IP_PORT_FIELD_TYPE 227
241 #define CNAT_NFV9_OUTSIDE_IP_PORT_FIELD_SIZE 2
242 
243 #define CNAT_NFV9_PROTOCOL_FIELD_TYPE 4
244 #define CNAT_NFV9_PROTOCOL_FIELD_SIZE 1
245 
246 /* IPv6 related info */
247 
248 #define CNAT_NFV9_INSIDE_IPV6_SRC_ADDR_FIELD_TYPE 27
249 #define CNAT_NFV9_INSIDE_IPV6_SRC_ADDR_FIELD_SIZE 16
250 
251 #define CNAT_NFV9_INSIDE_IPV6_DST_ADDR_FIELD_TYPE 28
252 #define CNAT_NFV9_INSIDE_IPV6_DST_ADDR_FIELD_SIZE 16
253 
254 #define CNAT_NFV9_OUTSIDE_IP_DST_ADDR_FIELD_TYPE 226
255 #define CNAT_NFV9_OUTSIDE_IP_DST_ADDR_FIELD_SIZE 4
256 
257 #define CNAT_NFV9_INSIDE_DST_PORT_FIELD_TYPE 11
258 #define CNAT_NFV9_INSIDE_DST_PORT_FIELD_SIZE 2
259 
260 #define CNAT_NFV9_DESTINATION_IP_ADDR_FIELD_TYPE 12
261 #define CNAT_NFV9_DESTINATION_IP_ADDR_FIELD_SIZE 4
262 
263 
264 typedef struct {
267  u32 sys_up_time; /* time in ms since system was booted */
268  u32 timestamp; /* UNIX time in seconds since 1970 */
271 } nfv9_header_t;
272 
273 /*
274  * Hardcoded - need to be fixed
275  */
276 #define CNAT_NFV9_SOURCE_ID_VALUE 0x1234
277 
278 typedef struct {
281 
289  /*
290  * Adding the padding so as to make the tempalate
291  * structure end on a 4 byte boundary
292  */
294 
296 
297 /*
298  * The following structure defines the Netflow Template that
299  * will be exported to the Netflow Collector
300  */
301 
302 typedef struct {
305 
322 
333 #if 0
334  /* NAT64 related info */
335  u16 nat64_add_bib_template_id;
336  u16 nat64_add_bib_field_count;
337  u16 nat64_add_bib_inside_ipv6_addr_field_type;
338  u16 nat64_add_bib_inside_ipv6_addr_field_size;
339  u16 nat64_add_bib_outside_ip_addr_field_type;
340  u16 nat64_add_bib_outside_ip_addr_field_size;
341  u16 nat64_add_bib_inside_ip_port_field_type;
342  u16 nat64_add_bib_inside_ip_port_field_size;
343  u16 nat64_add_bib_outside_ip_port_field_type;
344  u16 nat64_add_bib_outside_ip_port_field_size;
345  u16 nat64_add_bib_protocol_field_type;
346  u16 nat64_add_bib_protocol_field_size;
347 
348  u16 nat64_del_bib_template_id;
349  u16 nat64_del_bib_field_count;
350  u16 nat64_del_bib_inside_ip_addr_field_type;
351  u16 nat64_del_bib_inside_ip_addr_field_size;
352  u16 nat64_del_bib_inside_ip_port_field_type;
353  u16 nat64_del_bib_inside_ip_port_field_size;
354  u16 nat64_del_bib_protocol_field_type;
355  u16 nat64_del_bib_protocol_field_size;
356 
357 
358  u16 nat64_add_session_template_id;
359  u16 nat64_add_session_field_count;
360  u16 nat64_add_session_inside_ipv6_src_addr_field_type;
361  u16 nat64_add_session_inside_ipv6_src_addr_field_size;
362  u16 nat64_add_session_outside_ip_src_addr_field_type;
363  u16 nat64_add_session_outside_ip_src_addr_field_size;
364  u16 nat64_add_session_inside_ipv6_dst_addr_field_type;
365  u16 nat64_add_session_inside_ipv6_dst_addr_field_size;
366  u16 nat64_add_session_outside_ip_dst_addr_field_type;
367  u16 nat64_add_session_outside_ip_dst_addr_field_size;
368  u16 nat64_add_session_inside_ip_src_port_field_type;
369  u16 nat64_add_session_inside_ip_src_port_field_size;
370  u16 nat64_add_session_outside_ip_src_port_field_type;
371  u16 nat64_add_session_outside_ip_src_port_field_size;
372  u16 nat64_add_session_ip_dest_port_field_type;
373  u16 nat64_add_session_ip_dest_port_field_size;
374  u16 nat64_add_session_protocol_field_type;
375  u16 nat64_add_session_protocol_field_size;
376 
377  u16 nat64_del_session_template_id;
378  u16 nat64_del_session_field_count;
379  u16 nat64_del_session_inside_ip_src_addr_field_type;
380  u16 nat64_del_session_inside_ip_src_addr_field_size;
381  u16 nat64_del_session_inside_ip_dst_addr_field_type;
382  u16 nat64_del_session_inside_ip_dst_addr_field_size;
383  u16 nat64_del_session_inside_ip_src_port_field_type;
384  u16 nat64_del_session_inside_ip_src_port_field_size;
385  u16 nat64_del_session_inside_ip_dst_port_field_type;
386  u16 nat64_del_session_inside_ip_dst_port_field_size;
387  u16 nat64_del_session_protocol_field_type;
388  u16 nat64_del_session_protocol_field_size;
389 
390  /*
391  * Ds-Lite specific info
392  */
393  u16 add_dslite_template_id;
394  u16 add_dslite_field_count;
395  u16 add_dslite_inside_vrf_id_field_type;
396  u16 add_dslite_inside_vrf_id_field_size;
397  u16 add_dslite_outside_vrf_id_field_type;
398  u16 add_dslite_outside_vrf_id_field_size;
399  u16 add_dslite_inside_ip_addr_field_type;
400  u16 add_dslite_inside_ip_addr_field_size;
401  u16 add_dslite_inside_ipv6_addr_field_type;
402  u16 add_dslite_inside_ipv6_addr_field_size;
403  u16 add_dslite_outside_ip_addr_field_type;
404  u16 add_dslite_outside_ip_addr_field_size;
405  u16 add_dslite_inside_ip_port_field_type;
406  u16 add_dslite_inside_ip_port_field_size;
407  u16 add_dslite_outside_ip_port_field_type;
408  u16 add_dslite_outside_ip_port_field_size;
409  u16 add_dslite_protocol_field_type;
410  u16 add_dslite_protocol_field_size;
411 
412  u16 del_dslite_template_id;
413  u16 del_dslite_field_count;
414  u16 del_dslite_inside_vrf_id_field_type;
415  u16 del_dslite_inside_vrf_id_field_size;
416  u16 del_dslite_inside_ip_addr_field_type;
417  u16 del_dslite_inside_ip_addr_field_size;
418  u16 del_dslite_inside_ipv6_addr_field_type;
419  u16 del_dslite_inside_ipv6_addr_field_size;
420  u16 del_dslite_inside_ip_port_field_type;
421  u16 del_dslite_inside_ip_port_field_size;
422  u16 del_dslite_protocol_field_type;
423  u16 del_dslite_protocol_field_size;
424 #endif
425 
426 //#ifndef NO_BULK_LOGGING /* commenting for time being */
427 #if 0
428  u16 bulk_add_template_id;
429  u16 bulk_add_field_count;
430  u16 bulk_add_inside_vrf_id_field_type;
431  u16 bulk_add_inside_vrf_id_field_size;
432  u16 bulk_add_outside_vrf_id_field_type;
433  u16 bulk_add_outside_vrf_id_field_size;
434  u16 bulk_add_inside_ip_addr_field_type;
435  u16 bulk_add_inside_ip_addr_field_size;
436  u16 bulk_add_outside_ip_addr_field_type;
437  u16 bulk_add_outside_ip_addr_field_size;
438  u16 bulk_add_outside_start_port_field_type;
439  u16 bulk_add_outside_start_port_field_size;
440  u16 bulk_add_outside_end_port_field_type;
441  u16 bulk_add_outside_end_port_field_size;
442 
443  u16 bulk_del_template_id;
444  u16 bulk_del_field_count;
445  u16 bulk_del_inside_vrf_id_field_type;
446  u16 bulk_del_inside_vrf_id_field_size;
447  u16 bulk_del_inside_ip_addr_field_type;
448  u16 bulk_del_inside_ip_addr_field_size;
449  u16 bulk_del_outside_start_port_field_type;
450  u16 bulk_del_outside_start_port_field_size;
451 
452  /* ds-lite bulk logging create delete event */
453 
454  u16 bulk_dslite_add_template_id;
455  u16 bulk_dslite_add_field_count;
456  u16 bulk_dslite_add_inside_vrf_id_field_type;
457  u16 bulk_dslite_add_inside_vrf_id_field_size;
458  u16 bulk_dslite_add_outside_vrf_id_field_type;
459  u16 bulk_dslite_add_outside_vrf_id_field_size;
460  u16 bulk_dslite_add_inside_ip_addr_field_type;
461  u16 bulk_dslite_add_inside_ip_addr_field_size;
462  u16 bulk_dslite_add_inside_ipv6_addr_field_type;
463  u16 bulk_dslite_add_inside_ipv6_addr_field_size;
464  u16 bulk_dslite_add_outside_ip_addr_field_type;
465  u16 bulk_dslite_add_outside_ip_addr_field_size;
466  u16 bulk_dslite_add_outside_start_port_field_type;
467  u16 bulk_dslite_add_outside_start_port_field_size;
468  u16 bulk_dslite_add_outside_end_port_field_type;
469  u16 bulk_dslite_add_outside_end_port_field_size;
470 
471  u16 bulk_dslite_del_template_id;
472  u16 bulk_dslite_del_field_count;
473  u16 bulk_dslite_del_inside_vrf_id_field_type;
474  u16 bulk_dslite_del_inside_vrf_id_field_size;
475  u16 bulk_dslite_del_inside_ip_addr_field_type;
476  u16 bulk_dslite_del_inside_ip_addr_field_size;
477  u16 bulk_dslite_del_inside_ipv6_addr_field_type;
478  u16 bulk_dslite_del_inside_ipv6_addr_field_size;
479  u16 bulk_dslite_del_outside_start_port_field_type;
480  u16 bulk_dslite_del_outside_start_port_field_size;
481 
482 #endif /* NO_BULK_LOGGING */
483 
504 
519 
520 #if 0
521  u16 add_dslite_session_template_id;
522  u16 add_dslite_session_field_count;
523  u16 add_dslite_session_inside_vrf_id_field_type;
524  u16 add_dslite_session_inside_vrf_id_field_size;
525  u16 add_dslite_session_outside_vrf_id_field_type;
526  u16 add_dslite_session_outside_vrf_id_field_size;
527  u16 add_dslite_session_inside_ip_addr_field_type;
528  u16 add_dslite_session_inside_ip_addr_field_size;
529  u16 add_dslite_session_inside_ipv6_addr_field_type;
530  u16 add_dslite_session_inside_ipv6_addr_field_size;
531  u16 add_dslite_session_outside_ip_addr_field_type;
532  u16 add_dslite_session_outside_ip_addr_field_size;
533  u16 add_dslite_session_inside_ip_port_field_type;
534  u16 add_dslite_session_inside_ip_port_field_size;
535  u16 add_dslite_session_outside_ip_port_field_type;
536  u16 add_dslite_session_outside_ip_port_field_size;
537  u16 add_dslite_session_dest_ip_addr_field_type;
538  u16 add_dslite_session_dest_ip_addr_field_size;
539  u16 add_dslite_session_dest_port_field_type;
540  u16 add_dslite_session_dest_port_field_size;
541  u16 add_dslite_session_protocol_field_type;
542  u16 add_dslite_session_protocol_field_size;
543 
544  u16 del_dslite_session_template_id;
545  u16 del_dslite_session_field_count;
546  u16 del_dslite_session_inside_vrf_id_field_type;
547  u16 del_dslite_session_inside_vrf_id_field_size;
548  u16 del_dslite_session_inside_ip_addr_field_type;
549  u16 del_dslite_session_inside_ip_addr_field_size;
550  u16 del_dslite_session_inside_ipv6_addr_field_type;
551  u16 del_dslite_session_inside_ipv6_addr_field_size;
552  u16 del_dslite_session_dest_ip_addr_field_type;
553  u16 del_dslite_session_dest_ip_addr_field_size;
554  u16 del_dslite_session_inside_ip_port_field_type;
555  u16 del_dslite_session_inside_ip_port_field_size;
556  u16 del_dslite_session_dest_port_field_type;
557  u16 del_dslite_session_dest_port_field_size;
558  u16 del_dslite_session_protocol_field_type;
559  u16 del_dslite_session_protocol_field_size;
560 #endif
561 
562  /*
563  * Netflow option template
564  * Ingress VRF ID - Name mapping
565  * This template will be sent under flowset id 1
566  */
569 
570 /*
571  * The Dataflow header for each add/delete record group
572  */
573 typedef struct {
577 
578 /*
579  * NFv9 Add record definition
580  */
581 
582 /*
583  * pad bytes needed to make the structure a multiple of 4 bytes
584  */
585 #define CNAT_NFV9_ADD_RECORD_PAD_BYTES (3)
586 #define CNAT_NFV9_DEL_RECORD_PAD_BYTES (1)
587 
588 #define CNAT_NFV9_NAT64_ADD_BIB_RECORD_PAD_BYTES (3)
589 #define CNAT_NFV9_NAT64_DEL_BIB_RECORD_PAD_BYTES (1)
590 #define CNAT_NFV9_NAT64_ADD_SESSION_RECORD_PAD_BYTES (1)
591 #define CNAT_NFV9_NAT64_DEL_SESSION_RECORD_PAD_BYTES (3)
592 #define CNAT_NFV9_NAT44_ADD_SESSION_RECORD_PAD_BYTES (1)
593 #define CNAT_NFV9_NAT44_DEL_SESSION_RECORD_PAD_BYTES (3)
594 
595 #define CNAT_NFV9_DS_LITE_ADD_RECORD_PAD_BYTES (3)
596 #define CNAT_NFV9_DS_LITE_DEL_RECORD_PAD_BYTES (1)
597 #define CNAT_NFV9_DS_LITE_ADD_SESSION_RECORD_PAD_BYTES (1)
598 #define CNAT_NFV9_DS_LITE_DEL_SESSION_RECORD_PAD_BYTES (3)
599 
600 #define CNAT_NFV9_INGRESS_VRFID_NAME_RECORD_PAD_BYTES (0)
601 
602 typedef struct {
612 
613 /*
614  * NFv9 Delete record definition
615  */
616 typedef struct {
623 
624 #ifndef NO_BULK_LOGGING
625 
626 #define CNAT_NFV9_BULK_ADD_RECORD_PAD_BYTES (0)
627 #define CNAT_NFV9_BULK_DEL_RECORD_PAD_BYTES (2)
628 
629 typedef struct {
638 
639 /*
640  * NFv9 Delete record definition
641  */
642 typedef struct {
648 
649 /*
650  * DS-lite bulk port (user based) add record definition
651  */
652 
653 #define CNAT_NFV9_DS_LITE_BULK_ADD_RECORD_PAD_BYTES (0)
654 #define CNAT_NFV9_DS_LITE_BULK_DEL_RECORD_PAD_BYTES (2)
655 
656 typedef struct {
660  u32 inside_v6_src_addr[4];
666 
667 
668 /*
669  * DS-lite bulk port (user based) delete record definition
670  */
671 
672 typedef struct {
675  u32 inside_v6_src_addr[4];
679 
680 #endif /* NO_BULK_LOGGING */
681 
682 /* NAT64 related structures */
683 
684 typedef struct {
685  u32 inside_v6_src_addr[4];
692 
693 
694 typedef struct {
695  u32 inside_v6_src_addr[4];
697  u32 inside_v6_dest_addr[4];
705 
706 
707 typedef struct {
708  u32 inside_v6_src_addr[4];
713 
714 
715 typedef struct {
716  u32 inside_v6_src_addr[4];
717  u32 inside_v6_dest_addr[4];
723 
724 /*
725  * NFv9 Session based Add record definition
726  */
727 typedef struct {
739 
740 /*
741  * NFv9 Session based del record definition
742  */
743 typedef struct {
752 
753 /*
754  * DS-lite NFv9 create record structure
755  */
756 typedef struct {
760  u32 inside_v6_src_addr[4];
767 
768 typedef struct {
771  u32 inside_v6_src_addr[4];
776 
777 /*
778  * NFv9 Session based Add record definition
779  */
780 typedef struct {
784  u32 inside_v6_src_addr[4];
793 
794 /*
795  * NFv9 Session based del record definition
796  */
797 typedef struct {
800  u32 inside_v6_src_addr[4];
807 
808 
809 typedef struct {
811  u8 ingress_vrf_name[NFV9_VRF_NAME_LEN];
814 
815 #define CNAT_NFV9_TEMPLATE_OFFSET \
816  (CNAT_NFV9_HDR_OFFSET + sizeof(nfv9_header_t))
817 
818 #define CNAT_NFV9_TEMPLATE_LENGTH (sizeof(cnat_nfv9_template_t))
819 #define CNAT_NFV9_OPTION_TEMPLATE_LENGTH (sizeof(cnat_nfv9_option_template_t))
820 
821 #define CNAT_NFV9_DATAFLOW_RECORD_HEADER_LENGTH \
822  (sizeof(nfv9_dataflow_record_header_t))
823 
824 /*
825  * No padding is needed for the add/delete records - reduce padding bytes
826  */
827 
828 #define CNAT_NFV9_ADD_RECORD_LENGTH (sizeof(nfv9_add_record_t) - \
829  CNAT_NFV9_ADD_RECORD_PAD_BYTES)
830 
831 #define CNAT_NFV9_DEL_RECORD_LENGTH (sizeof(nfv9_del_record_t) - \
832  CNAT_NFV9_DEL_RECORD_PAD_BYTES)
833 
834 #define CNAT_NFV9_DS_LITE_ADD_RECORD_LENGTH (sizeof(nfv9_ds_lite_add_record_t) - \
835  CNAT_NFV9_DS_LITE_ADD_RECORD_PAD_BYTES)
836 #define CNAT_NFV9_DS_LITE_DEL_RECORD_LENGTH (sizeof(nfv9_ds_lite_del_record_t) - \
837  CNAT_NFV9_DS_LITE_DEL_RECORD_PAD_BYTES)
838 #ifndef NO_BULK_LOGGING
839 #define CNAT_NFV9_BULK_ADD_RECORD_LENGTH (sizeof(nfv9_bulk_add_record_t) - \
840  CNAT_NFV9_BULK_ADD_RECORD_PAD_BYTES)
841 #define CNAT_NFV9_BULK_DEL_RECORD_LENGTH (sizeof(nfv9_bulk_del_record_t) - \
842  CNAT_NFV9_BULK_DEL_RECORD_PAD_BYTES)
843 
844 #define CNAT_NFV9_DS_LITE_BULK_ADD_RECORD_LENGTH (sizeof(nfv9_ds_lite_bulk_add_record_t) - \
845  CNAT_NFV9_DS_LITE_BULK_ADD_RECORD_PAD_BYTES)
846 #define CNAT_NFV9_DS_LITE_BULK_DEL_RECORD_LENGTH (sizeof(nfv9_ds_lite_bulk_del_record_t) - \
847  CNAT_NFV9_DS_LITE_BULK_DEL_RECORD_PAD_BYTES)
848 
849 
850 #endif /* NO_BULK_LOGGING */
851 
852 #define CNAT_NFV9_INGRESS_VRFID_NAME_RECORD_LENGTH (sizeof(nfv9_ingress_vrfid_name_record_t) - \
853  CNAT_NFV9_INGRESS_VRFID_NAME_RECORD_PAD_BYTES)
854 
855 #define CNAT_NFV9_NAT64_ADD_BIB_RECORD_LENGTH \
856  (sizeof(nfv9_nat64_add_bib_record_t) - \
857  CNAT_NFV9_NAT64_ADD_BIB_RECORD_PAD_BYTES)
858 
859 #define CNAT_NFV9_NAT64_DEL_BIB_RECORD_LENGTH \
860  (sizeof(nfv9_nat64_del_bib_record_t) - \
861  CNAT_NFV9_NAT64_DEL_BIB_RECORD_PAD_BYTES)
862 
863 #define CNAT_NFV9_NAT64_ADD_SESSION_RECORD_LENGTH \
864  (sizeof(nfv9_nat64_add_session_record_t) - \
865  CNAT_NFV9_NAT64_ADD_SESSION_RECORD_PAD_BYTES)
866 
867 #define CNAT_NFV9_NAT64_DEL_SESSION_RECORD_LENGTH \
868  (sizeof(nfv9_nat64_del_session_record_t) - \
869  CNAT_NFV9_NAT64_DEL_SESSION_RECORD_PAD_BYTES)
870 
871 #define CNAT_NFV9_MAX_SINGLE_RECORD_LENGTH \
872  (sizeof(nfv9_ds_lite_add_session_record_t) - \
873  CNAT_NFV9_DS_LITE_ADD_SESSION_RECORD_PAD_BYTES)
874 
875 #define CNAT_NFV9_NAT44_ADD_SESSION_RECORD_LENGTH \
876  (sizeof(nfv9_add_session_record_t) -\
877  CNAT_NFV9_NAT44_ADD_SESSION_RECORD_PAD_BYTES)
878 
879 #define CNAT_NFV9_NAT44_DEL_SESSION_RECORD_LENGTH \
880  (sizeof(nfv9_del_session_record_t) -\
881  CNAT_NFV9_NAT44_DEL_SESSION_RECORD_PAD_BYTES)
882 
883 #define CNAT_NFV9_DS_LITE_ADD_SESSION_RECORD_LENGTH \
884  (sizeof(nfv9_ds_lite_add_session_record_t) -\
885  CNAT_NFV9_DS_LITE_ADD_SESSION_RECORD_PAD_BYTES)
886 
887 #define CNAT_NFV9_DS_LITE_DEL_SESSION_RECORD_LENGTH \
888  (sizeof(nfv9_ds_lite_del_session_record_t) -\
889  CNAT_NFV9_DS_LITE_DEL_SESSION_RECORD_PAD_BYTES)
890 
891 /*
892  * Minimum value of the path MTU value
893  */
894 #define CNAT_NFV9_MIN_RECORD_SIZE (60 + \
895  CNAT_NFV9_DATAFLOW_RECORD_HEADER_LENGTH + \
896  CNAT_NFV9_TEMPLATE_LENGTH + \
897  CNAT_NFV9_MAX_SINGLE_RECORD_LENGTH)
898 
899 /*
900  * Let us put the maximum length of the netflow data to be 1400
901  */
902 #define CNAT_NFV9_MAX_PKT_LENGTH 1400
903 
904 /*
905  * Data structures and defines to store NFV9 specific info
906  */
907 #define CNAT_NFV9_INVALID_LOGGING_INDEX 0xffffffff
908 
909 /*
910  * Padding value between ADD and DELETE records. This can be atmost 3 bytes
911  */
912 #define NFV9_PAD_VALUE (3)
913 
914 typedef struct {
915  /* NFV9 server specific info
916  * For now, it will maintain only package sequence count.
917  * Later it will maintain server address, port, etc.
918  * Though it currently has server address and port, it is only for
919  * cross refernce
920  */
921  u32 ipv4_address; /* Destination IP address of the collector */
922  u16 port; /* Destination port number of the collector */
923  u16 refresh_rate; /* Refresh rate in packets after which template is sent */
924  u16 timeout_rate; /* Timeout rate in seconds after which template is sent */
925  u16 ref_count; /* Num of instances using this data */
926  u32 sequence_num; /* Sequence number of the logging packet */
927  /*
928  * Keep track of the time and packets since last template send
929  */
932  u8 template_sent; /* used while sending vrfid-name mapping */
933 
935 
936 /*
937  * This structure store the Netflow Logging information on per NFv9
938  * collector basis. This structure is allocated from a pool and index
939  * to this structure is stored VRF MAP structures
940  */
941 typedef struct {
942  /*
943  * nat64_id will be 0 for nat44 config and i_vrf_id, i_vrf will be 0
944  * for nat64 config. Nat64_id will be used while nat64 collector is
945  * search and i_vrf* for nat44 collector
946  */
947  /* Similarly for ds_lite, ds_lite_id will be used and nat64_id,
948  * ivrf_id shall be set to 0
949  */
950  u32 i_vrf_id; /* Inside VRF ID corresponding to this collector */
951  u16 i_vrf; /* Inside VRF (uidb_index) corresponding to this collector */
952  u16 nat64_id; /* NAT64 instance for to this collector */
953  u16 ds_lite_id; /* DS Lite instance for this collector */
954 
955  /*
956  * This field determines the maximum size of the Netflow V9 information
957  * that can be stored in a logging packet
958  */
960 
961  /*
962  * Indicates if the entry is already deleted
963  */
965 
966  u16 pkt_length; /* Length of the currently NFv9 information */
967  u16 record_length[MAX_RECORDS]; /* Length of delete record */
968  u16 total_record_count; /* Total number of records including templates */
969 
971 
972  /*
973  * Keep track of the time and packets since last template send
974  */
977 
978  /* Server info */
980 
981  /*
982  * current logging context
983  */
985 
986  /*
987  * Timestamp in UNIX seconds corresponding to when the current
988  * logging packet was created
989  */
991 
992  /*
993  * Queued logging context waiting to be sent to the l3 infra node
994  */
996 
997  /*
998  * Headers corresponding to various records in this
999  * current nfv9 logging context
1000  */
1004  u8 *record[MAX_RECORDS];
1012 
1013 
1014 /*
1015  * Global structure for CGN APP configuration
1016  */
1017 typedef struct {
1018  /*
1019  * Global NFv9 Logging Collector Index
1020  */
1022 
1023  /*
1024  * Node index corresponding to the infra L3 output node
1025  * to which the nfv9 logging node will send the packet
1026  */
1028 
1029  /*
1030  * Whether we have initialized the NFv9 information
1031  */
1034 
1035 typedef enum {
1039 
1041 
1044 
1047 
1048 /* #define DEBUG_NF_SERVER_CONFIG 1 */
1050 {
1051  nfv9_server_info_t *server = nfv9_server_info_pool +
1052  nfv9_info->server_index;
1053  if(nfv9_info->server_index == EMPTY) {
1054 #ifdef DEBUG_NF_SERVER_CONFIG
1055  if(my_instance_number == 1) {
1056  PLATFORM_DEBUG_PRINT("Deleting empty server info\n");
1057  }
1058 #endif /* #ifdef DEBUG_NF_SERVER_CONFIG */
1059  return;
1060  }
1061 
1062  /* Check if this server is not used by anyone.. if not delete */
1063  /* Caller of this function does not need it..so decrement ref count */
1064  server->ref_count--;
1065  if(!(server->ref_count)) {
1066 #ifdef DEBUG_NF_SERVER_CONFIG
1067  if(my_instance_number == 1) {
1068  PLATFORM_DEBUG_PRINT("Deleting nfv9 server %x, %d at %d\n",
1069  server->ipv4_address,
1070  server->port,
1071  nfv9_info->server_index);
1072  }
1073 #endif /* #ifdef DEBUG_NF_SERVER_CONFIG */
1074  pool_put(nfv9_server_info_pool, server);
1075  nfv9_info->server_index = EMPTY;
1076  }
1077 #ifdef DEBUG_NF_SERVER_CONFIG
1078  else {
1079  if(my_instance_number == 1) {
1080  PLATFORM_DEBUG_PRINT("Not Deleting nfv9 server %x, %d rc %d\n",
1081  server->ipv4_address,
1082  server->port,
1083  server->ref_count);
1084  }
1085  }
1086 #endif /* #ifdef DEBUG_NF_SERVER_CONFIG */
1087  return;
1088 }
1089 
1091 #endif /* __CNAT_LOGGING_H__ */
void cnat_nfv9_log_mapping_delete(cnat_main_db_entry_t *db, cnat_vrfmap_t *vrfmap, int bulk_alloc)
u8 pad[3]
log2 (size of the packing page block)
Definition: bihash_doc.h:61
u16 nat44_session_del_dest_port_field_size
Definition: cnat_logging.h:516
#define CNAT_NFV9_DS_LITE_BULK_DEL_RECORD_PAD_BYTES
Definition: cnat_logging.h:654
cnat_nfv9_template_add_flag_t
u16 nat44_session_del_inside_ip_port_field_type
Definition: cnat_logging.h:513
u16 nat44_session_del_dest_ip_addr_field_type
Definition: cnat_logging.h:511
#define CNAT_NFV9_NAT64_DEL_SESSION_RECORD_PAD_BYTES
Definition: cnat_logging.h:591
netflow_template_sent
Definition: cnat_logging.h:152
Fixed length block allocator.
u16 nat44_session_add_protocol_field_type
Definition: cnat_logging.h:502
nfv9_header_t * nfv9_header
u16 nat44_session_del_inside_ip_addr_field_type
Definition: cnat_logging.h:509
#define CNAT_NFV9_NAT64_DEL_BIB_RECORD_PAD_BYTES
Definition: cnat_logging.h:589
void cnat_nfv9_nat44_log_session_delete(cnat_main_db_entry_t *db, cnat_session_entry_t *sdb, cnat_vrfmap_t *vrfmap)
Definition: cnat_db.h:153
nfv9_dataflow_record_header_t * dataflow_header
u16 nat44_session_add_dest_port_field_type
Definition: cnat_logging.h:500
u16 nat44_session_del_inside_ip_port_field_size
Definition: cnat_logging.h:514
u16 nat44_session_add_outside_vrf_id_field_type
Definition: cnat_logging.h:488
Definition: nat64_db.h:128
u16 nat44_session_add_outside_ip_port_field_type
Definition: cnat_logging.h:496
cnat_nfv9_global_info_t cnat_nfv9_global_info
Definition: cnat_logging.c:63
#define CNAT_NFV9_DS_LITE_DEL_SESSION_RECORD_PAD_BYTES
Definition: cnat_logging.h:598
u16 nat44_session_add_outside_ip_port_field_size
Definition: cnat_logging.h:497
u16 nat44_session_add_dest_ip_addr_field_size
Definition: cnat_logging.h:499
#define CNAT_NFV9_DS_LITE_ADD_SESSION_RECORD_PAD_BYTES
Definition: cnat_logging.h:597
#define PLATFORM_DEBUG_PRINT(...)
vlib_buffer_t * queued_logging_context
Definition: cnat_logging.h:995
void cnat_syslog_nat44_mapping_delete(cnat_main_db_entry_t *db, cnat_vrfmap_t *vrfmap, cnat_session_entry_t *sdb, int bulk_alloc)
Definition: cnat_syslog.c:453
Definition: dslite_defs.h:106
u16 nat44_session_add_inside_vrf_id_field_size
Definition: cnat_logging.h:487
void cnat_nfv9_logging_init()
void cnat_nfv9_bib_mapping_create(nat64_bib_entry_t *db, nat64_table_entry_t *nat64_entry)
u16 nat44_session_del_dest_port_field_type
Definition: cnat_logging.h:515
Definition: nat64_db.h:225
#define CNAT_NFV9_DS_LITE_DEL_RECORD_PAD_BYTES
Definition: cnat_logging.h:596
void cnat_nfv9_nat44_log_session_create(cnat_main_db_entry_t *db, cnat_session_entry_t *sdb, cnat_vrfmap_t *vrfmap)
u16 nat44_session_del_inside_vrf_id_field_type
Definition: cnat_logging.h:507
u16 nat44_session_del_protocol_field_type
Definition: cnat_logging.h:517
#define CNAT_NFV9_ADD_RECORD_PAD_BYTES
Definition: cnat_logging.h:585
nfv9_server_info_t * nfv9_server_info_pool
Definition: cnat_logging.c:95
u16 nat44_session_del_dest_ip_addr_field_size
Definition: cnat_logging.h:512
#define CNAT_NFV9_INGRESS_VRFID_NAME_RECORD_PAD_BYTES
Definition: cnat_logging.h:600
Definition: nat64_defs.h:306
void cnat_nfv9_session_mapping_create(nat64_bib_entry_t *bdb, nat64_session_entry_t *sdb, nat64_table_entry_t *nat64_entry_ptr)
u16 nat44_session_add_inside_ip_port_field_type
Definition: cnat_logging.h:494
#define NFV9_VRF_NAME_LEN
Definition: cnat_logging.h:37
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:214
void cnat_nfv9_ds_lite_mapping_create(cnat_main_db_entry_t *db, dslite_table_entry_t *dslite_entry, int bulk_alloc)
u16 nat44_session_add_outside_ip_addr_field_size
Definition: cnat_logging.h:493
cnat_nfv9_logging_info_t * cnat_nfv9_logging_info_pool
Definition: cnat_logging.c:93
u16 nat44_session_add_inside_ip_addr_field_type
Definition: cnat_logging.h:490
void cnat_nfv9_session_mapping_delete(nat64_bib_entry_t *bdb, nat64_session_entry_t *sdb, nat64_table_entry_t *nat64_entry_ptr)
void handle_pending_nfv9_pkts()
u8 my_instance_number
Definition: cnat_ports.c:51
cnat_nfv9_template_t cnat_nfv9_template_info
Definition: cnat_logging.c:65
u16 nat44_session_add_dest_ip_addr_field_type
Definition: cnat_logging.h:498
static void nfv9_delete_server_info(cnat_nfv9_logging_info_t *nfv9_info)
#define CNAT_NFV9_NAT64_ADD_BIB_RECORD_PAD_BYTES
Definition: cnat_logging.h:588
u16 nat44_session_add_inside_vrf_id_field_type
Definition: cnat_logging.h:486
#define CNAT_NFV9_NAT44_ADD_SESSION_RECORD_PAD_BYTES
Definition: cnat_logging.h:592
u16 nat44_session_del_protocol_field_size
Definition: cnat_logging.h:518
void cnat_nfv9_log_mapping_create(cnat_main_db_entry_t *db, cnat_vrfmap_t *vrfmap, int bulk_alloc)
#define CNAT_NFV9_NAT64_ADD_SESSION_RECORD_PAD_BYTES
Definition: cnat_logging.h:590
unsigned int u32
Definition: types.h:88
cnat_nfv9_template_t * nfv9_template_header
u16 nat44_session_add_outside_vrf_id_field_size
Definition: cnat_logging.h:489
u16 nat44_session_del_inside_ip_addr_field_size
Definition: cnat_logging.h:510
#define CNAT_NFV9_DEL_RECORD_PAD_BYTES
Definition: cnat_logging.h:586
u16 nat44_session_add_inside_ip_port_field_size
Definition: cnat_logging.h:495
Bitmaps built as vectors of machine words.
cnat_nfv9_logging_info_t cnat_default_nfv9_logging_info
Definition: cnat_logging.c:92
void cnat_nfv9_ds_lite_mapping_delete(cnat_main_db_entry_t *db, dslite_table_entry_t *dslite_entry, int bulk_alloc)
Definition: cnat_db.h:336
netflow_record
Definition: cnat_logging.h:130
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
#define CNAT_NFV9_BULK_DEL_RECORD_PAD_BYTES
Definition: cnat_logging.h:627
void cnat_nfv9_ds_lite_log_session_delete(cnat_main_db_entry_t *db, dslite_table_entry_t *dslite_entry, cnat_session_entry_t *sdb)
u16 nat44_session_add_outside_ip_addr_field_type
Definition: cnat_logging.h:492
#define CNAT_NFV9_DS_LITE_ADD_RECORD_PAD_BYTES
Definition: cnat_logging.h:595
u16 cnat_template_id[MAX_RECORDS]
Definition: cnat_logging.c:69
#define CNAT_NFV9_NAT44_DEL_SESSION_RECORD_PAD_BYTES
Definition: cnat_logging.h:593
#define CNAT_NFV9_BULK_ADD_RECORD_PAD_BYTES
Definition: cnat_logging.h:626
vlib_buffer_t * current_logging_context
Definition: cnat_logging.h:984
#define EMPTY
Definition: index_list.h:24
u16 nat44_session_add_protocol_field_size
Definition: cnat_logging.h:503
u16 nat44_session_del_inside_vrf_id_field_size
Definition: cnat_logging.h:508
#define CNAT_NFV9_DS_LITE_BULK_ADD_RECORD_PAD_BYTES
Definition: cnat_logging.h:653
cnat_nfv9_option_template_t cnat_nfv9_option_template
Definition: cnat_logging.h:567
void cnat_syslog_nat44_mapping_create(cnat_main_db_entry_t *db, cnat_vrfmap_t *vrfmap, cnat_session_entry_t *sdb, int bulk_alloc)
Definition: cnat_syslog.c:436
void cnat_nfv9_ds_lite_log_session_create(cnat_main_db_entry_t *db, dslite_table_entry_t *dslite_entry, cnat_session_entry_t *sdb)
u16 nat44_session_add_dest_port_field_size
Definition: cnat_logging.h:501
void cnat_nfv9_bib_mapping_delete(nat64_bib_entry_t *db, nat64_table_entry_t *nat64_entry)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
u16 nat44_session_add_inside_ip_addr_field_size
Definition: cnat_logging.h:491