nat: cleanup & reorganization
[vpp.git] / src / plugins / nat / lib / ipfix_logging.h
1 /*
2  * ipfix_logging.h - NAT Events IPFIX logging
3  *
4  * Copyright (c) 2016 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef __included_nat_lib_ipfix_logging_h__
18 #define __included_nat_lib_ipfix_logging_h__
19
20 #include <vlib/buffer.h>
21 #include <vlib/node.h>
22
23 #include <nat/lib/lib.h>
24
25 typedef enum {
26   NAT_ADDRESSES_EXHAUTED = 3,
27   NAT44_SESSION_CREATE = 4,
28   NAT44_SESSION_DELETE = 5,
29   NAT64_SESSION_CREATE = 6,
30   NAT64_SESSION_DELETE = 7,
31   NAT64_BIB_CREATE = 10,
32   NAT64_BIB_DELETE = 11,
33   NAT_PORTS_EXHAUSTED = 12,
34   QUOTA_EXCEEDED = 13,
35 } nat_event_t;
36
37 typedef enum {
38   MAX_SESSION_ENTRIES = 1,
39   MAX_BIB_ENTRIES = 2,
40   MAX_ENTRIES_PER_USER = 3,
41 } quota_exceed_event_t;
42
43 typedef struct {
44
45   /** ipfix buffers under construction */
46   vlib_buffer_t *nat44_session_buffer;
47   vlib_buffer_t *addr_exhausted_buffer;
48   vlib_buffer_t *max_entries_per_user_buffer;
49   vlib_buffer_t *max_sessions_buffer;
50   vlib_buffer_t *max_bibs_buffer;
51   vlib_buffer_t *max_frags_ip4_buffer;
52   vlib_buffer_t *max_frags_ip6_buffer;
53   vlib_buffer_t *nat64_bib_buffer;
54   vlib_buffer_t *nat64_ses_buffer;
55
56   /** frames containing ipfix buffers */
57   vlib_frame_t *nat44_session_frame;
58   vlib_frame_t *addr_exhausted_frame;
59   vlib_frame_t *max_entries_per_user_frame;
60   vlib_frame_t *max_sessions_frame;
61   vlib_frame_t *max_bibs_frame;
62   vlib_frame_t *max_frags_ip4_frame;
63   vlib_frame_t *max_frags_ip6_frame;
64   vlib_frame_t *nat64_bib_frame;
65   vlib_frame_t *nat64_ses_frame;
66
67   /** next record offset */
68   u32 nat44_session_next_record_offset;
69   u32 addr_exhausted_next_record_offset;
70   u32 max_entries_per_user_next_record_offset;
71   u32 max_sessions_next_record_offset;
72   u32 max_bibs_next_record_offset;
73   u32 max_frags_ip4_next_record_offset;
74   u32 max_frags_ip6_next_record_offset;
75   u32 nat64_bib_next_record_offset;
76   u32 nat64_ses_next_record_offset;
77
78 } nat_ipfix_per_thread_data_t;
79
80 typedef struct {
81   /** NAT plugin IPFIX logging enabled */
82   u8 enabled;
83
84   /** Time reference pair */
85   u64 milisecond_time_0;
86   f64 vlib_time_0;
87
88   /* Per thread data */
89   nat_ipfix_per_thread_data_t *per_thread_data;
90
91   /** template IDs */
92   u16 nat44_session_template_id;
93   u16 addr_exhausted_template_id;
94   u16 max_entries_per_user_template_id;
95   u16 max_sessions_template_id;
96   u16 max_bibs_template_id;
97   u16 max_frags_ip4_template_id;
98   u16 max_frags_ip6_template_id;
99   u16 nat64_bib_template_id;
100   u16 nat64_ses_template_id;
101
102   /** stream index */
103   u32 stream_index;
104
105   /** vector of worker vlib mains */
106   vlib_main_t **worker_vms;
107
108   /** nat data callbacks call counter */
109   u16 call_counter;
110
111 } nat_ipfix_logging_main_t;
112
113 extern nat_ipfix_logging_main_t nat_ipfix_logging_main;
114
115 int nat_ipfix_logging_enabled ();
116
117 void nat_ipfix_logging_init (vlib_main_t * vm);
118 int nat_ipfix_logging_enable_disable (int enable, u32 domain_id, u16 src_port);
119 void nat_ipfix_logging_nat44_ses_create (u32 thread_index, u32 src_ip,
120                                           u32 nat_src_ip,
121                                           nat_protocol_t nat_proto,
122                                           u16 src_port, u16 nat_src_port,
123                                           u32 fib_index);
124 void nat_ipfix_logging_nat44_ses_delete (u32 thread_index, u32 src_ip,
125                                           u32 nat_src_ip,
126                                           nat_protocol_t nat_proto,
127                                           u16 src_port, u16 nat_src_port,
128                                           u32 fib_index);
129 void nat_ipfix_logging_addresses_exhausted(u32 thread_index, u32 pool_id);
130 void nat_ipfix_logging_max_entries_per_user(u32 thread_index,
131                                              u32 limit, u32 src_ip);
132 void nat_ipfix_logging_max_sessions(u32 thread_index, u32 limit);
133 void nat_ipfix_logging_max_bibs(u32 thread_index, u32 limit);
134 void nat_ipfix_logging_nat64_session(u32 thread_index,
135                                      ip6_address_t * src_ip,
136                                      ip4_address_t * nat_src_ip, u8 proto,
137                                      u16 src_port, u16 nat_src_port,
138                                      ip6_address_t * dst_ip,
139                                      ip4_address_t * nat_dst_ip,
140                                      u16 dst_port, u16 nat_dst_port,
141                                      u32 vrf_id, u8 is_create);
142 void nat_ipfix_logging_nat64_bib(u32 thread_index,
143                                  ip6_address_t * src_ip,
144                                  ip4_address_t * nat_src_ip, u8 proto,
145                                  u16 src_port, u16 nat_src_port,
146                                  u32 vrf_id, u8 is_create);
147
148 #endif /* __included_nat_lib_ipfix_logging_h__ */