More janitorial work
[vpp.git] / plugins / plugins / vcgn / cnat_syslog.h
1 /*
2  *------------------------------------------------------------------
3  * cnat_syslog.h
4  *
5  * Copyright (c) 2011-2013 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_SYSLOG_H__ 
21 #define __CNAT_SYSLOG_H__ 
22
23 #include <vlib/vlib.h>
24 #include <vnet/vnet.h>
25 #include <vnet/pg/pg.h>
26 #include <vppinfra/error.h>
27
28 #include "cnat_db.h"
29 #include "nat64_db.h"
30 #include "cnat_log_common.h"
31 #include "dslite_defs.h"
32
33 #define SYSLOG_CONFIG_DEBUG_PRINTF(level, ...)  \
34     if (config_debug_level > level) PLATFORM_DEBUG_PRINT(__VA_ARGS__);
35
36
37 /* one time call at the beginning */
38 void cnat_syslog_logging_init(); 
39
40 /* 
41  * unconditional call
42  * will check logging config inside
43  */
44 void cnat_syslog_log_mapping_create(cnat_main_db_entry_t * db,
45                                   cnat_vrfmap_t *vrfmap);
46
47 /* 
48  * unconditional call
49  * will check logging config inside
50  */
51 void cnat_syslog_log_mapping_delete(cnat_main_db_entry_t * db,
52                                   cnat_vrfmap_t *vrfmap);
53
54 void cnat_syslog_ds_lite_mapping_create(cnat_main_db_entry_t *db,
55         dslite_table_entry_t *dslite_entry, cnat_session_entry_t *sdb
56 #ifndef NO_BULK_LOGGING
57         , int bulk_alloc
58 #endif
59     );
60
61 void cnat_syslog_ds_lite_port_limit_exceeded(
62    dslite_key_t   * key,
63    dslite_table_entry_t *dslite_entry);
64
65 #define SYSLOG_TIMESTAMP_LENGTH 20
66
67 #define CNAT_SYSLOG_VERSION_NUMBER        1
68 #define CNAT_SYSLOG_PRIORITY              16*8+6  
69 /* facility = local0 + severity = info */
70
71 #define MAX_SYSLOG_HOSTNAME_LEN          32
72
73 /* 6 for priority + space
74  * 2 for version + space
75  * 21  YYYY MMM DD HH:MM:SS + space
76  * 33 for hostname + space
77  * 4 for App Name (-) + space + Proc ID (-) + space
78  * 7 for Msg ID (DSLite is the longest Msg ID so far  + space
79  * 2 for Structured data (-) + space
80  */
81 #define MAX_SYSLOG_HEADER_LEN           75
82
83 /* 18 for Event Name (Portblockrunout is the longest as of now) 
84  * 3 for L4 (including space)
85  * 16 for original souce IP + space
86  * 33 for inside vrf name + space
87  * 40 for original source IPV6 + space
88  * 16 for translated source IP + space
89  * 6 for original port + space
90  * 6 for translated first source port + space
91  * 5 for translated last source port
92  * 2 for [] enclosure
93  */
94 #define MAX_SYSLOG_RECORD_LEN 145
95
96 typedef enum {
97     NAT44,
98     DSLite
99 } syslog_service_type_t; 
100
101 typedef enum {
102     userbased_assign,
103     userbased_withdraw,
104     sessionbased_assign,
105     sessionbased_withdraw,
106     sessionbased_assignD,
107     sessionbased_withdrawD,
108     port_block_runout,
109     tcp_seq_mismatch,
110     max_syslog_event_type
111 } syslog_event_type_t;
112
113 /*
114  * This structure store the Syslog Logging information on per 
115  * collector basis. This structure is allocated from a pool and index
116  * to this structure is stored VRF MAP structures
117  */
118 typedef struct {
119     /* 
120      * nat64_id will be 0 for nat44 config and i_vrf_id, i_vrf will be 0
121      * for nat64 config. Nat64_id will be used while nat64 collector is 
122      * search and i_vrf* for nat44 collector
123      */
124      /* Similarly for ds_lite, ds_lite_id will be used and nat64_id, 
125       * ivrf_id shall be set to 0 
126       */
127     u32 i_vrf_id; /* Inside VRF ID corresponding to this collector */
128     u16 i_vrf;    /* Inside VRF (uidb_index) corresponding to this collector */
129     u16 ds_lite_id; /* DS Lite instance for this collector */
130     u16 port;     /* Destination port number of the collector */
131
132     /*
133      * This field determines the maximum size of the Syslog information
134      * that can be stored in a logging packet
135      */
136     u16 max_length_minus_max_record_size;
137     u32 ipv4_address; /* Destination IP address of the collector */
138     /*
139      * Timestamp in UNIX seconds corresponding to when the current
140      * logging packet was created
141      */
142     u32 current_logging_context_timestamp;
143
144     /*
145      * Indicates if the entry is already deleted
146      */
147     u8 deleted;
148
149     u8 header_priority;
150     u16 pkt_length;
151
152     char header_hostname[MAX_SYSLOG_HOSTNAME_LEN];
153     char vrf_name[VRF_NAME_LEN_STORED];
154     u16  vrf_name_len;
155     u8   logging_policy;
156     /*
157      * current logging context
158      */
159     spp_ctx_t *current_logging_context;
160     spp_ctx_t *queued_logging_context;
161
162 } cnat_syslog_logging_info_t;
163
164
165 /*
166  * Global structure for CGN APP configuration
167  */
168 typedef struct {
169
170     u16 cnat_syslog_disp_node_index;
171
172     /*
173      * Whether we have initialized the Syslog information
174      */
175     u8 cnat_syslog_init_done;
176
177 } cnat_syslog_global_info_t;
178
179 typedef struct {
180     u64 logging_context_creation_fail_count;
181     u64 downstream_constipation_count;
182     u64 logging_context_creation_deferred_count;
183 } cnat_syslog_global_counters_t;
184
185 extern cnat_syslog_logging_info_t *cnat_syslog_logging_info_pool;
186 extern cnat_syslog_global_info_t cnat_syslog_global_info;
187
188 #define SYSLOG_DEF_PATH_MTU     1500
189
190 #endif /* __CNAT_SYSLOG_H__ */