nat: Final NAT44 EI/ED split patch
[vpp.git] / src / plugins / nat / lib / log.h
1 /*
2  * Copyright (c) 2020 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 /**
16  * @file
17  * @brief NAT port/address allocation lib
18  */
19 #ifndef included_nat_log_h__
20 #define included_nat_log_h__
21
22 #include <vppinfra/elog.h>
23
24 #define foreach_nat_log_level                                                 \
25   _ (0x00, LOG_NONE)                                                          \
26   _ (0x01, LOG_ERROR)                                                         \
27   _ (0x02, LOG_WARNING)                                                       \
28   _ (0x03, LOG_NOTICE)                                                        \
29   _ (0x04, LOG_INFO)                                                          \
30   _ (0x05, LOG_DEBUG)
31
32 typedef enum nat_log_level_t_
33 {
34 #define _(n, f) NAT_##f = n,
35   foreach_nat_log_level
36 #undef _
37 } nat_log_level_t;
38
39 #define nat_elog(_pm, _level, _str)                                           \
40   do                                                                          \
41     {                                                                         \
42       if (PREDICT_FALSE (_pm->log_level >= _level))                           \
43         {                                                                     \
44           ELOG_TYPE_DECLARE (e) = {                                           \
45             .format = "nat-msg " _str,                                        \
46             .format_args = "",                                                \
47           };                                                                  \
48           ELOG_DATA (&vlib_global_main.elog_main, e);                         \
49         }                                                                     \
50     }                                                                         \
51   while (0);
52
53 #define nat_elog_addr(_pm, _level, _str, _addr)                               \
54   do                                                                          \
55     {                                                                         \
56       if (PREDICT_FALSE (_pm->log_level >= _level))                           \
57         {                                                                     \
58           ELOG_TYPE_DECLARE (e) = {                                           \
59             .format = "nat-msg " _str " %d.%d.%d.%d",                         \
60             .format_args = "i1i1i1i1",                                        \
61           };                                                                  \
62           CLIB_PACKED (struct {                                               \
63             u8 oct1;                                                          \
64             u8 oct2;                                                          \
65             u8 oct3;                                                          \
66             u8 oct4;                                                          \
67           }) *                                                                \
68             ed;                                                               \
69           ed = ELOG_DATA (&vlib_global_main.elog_main, e);                    \
70           ed->oct4 = _addr >> 24;                                             \
71           ed->oct3 = _addr >> 16;                                             \
72           ed->oct2 = _addr >> 8;                                              \
73           ed->oct1 = _addr;                                                   \
74         }                                                                     \
75     }                                                                         \
76   while (0);
77
78 #define nat_elog_debug_handoff(_pm, _str, _tid, _fib, _src, _dst)             \
79   do                                                                          \
80     {                                                                         \
81       if (PREDICT_FALSE (_pm->log_level >= NAT_LOG_DEBUG))                    \
82         {                                                                     \
83           ELOG_TYPE_DECLARE (e) = {                                           \
84             .format = "nat-msg " _str " ip src: %d.%d.%d.%d dst: %d.%d.%d.%d" \
85                       " tid from: %d to: %d fib: %d",                         \
86             .format_args = "i1i1i1i1i1i1i1i1i4i4i4",                          \
87           };                                                                  \
88           CLIB_PACKED (struct {                                               \
89             u8 src_oct1;                                                      \
90             u8 src_oct2;                                                      \
91             u8 src_oct3;                                                      \
92             u8 src_oct4;                                                      \
93             u8 dst_oct1;                                                      \
94             u8 dst_oct2;                                                      \
95             u8 dst_oct3;                                                      \
96             u8 dst_oct4;                                                      \
97             u32 ftid;                                                         \
98             u32 ttid;                                                         \
99             u32 fib;                                                          \
100           }) *                                                                \
101             ed;                                                               \
102           ed = ELOG_DATA (&vlib_global_main.elog_main, e);                    \
103           ed->src_oct1 = _src >> 24;                                          \
104           ed->src_oct2 = _src >> 16;                                          \
105           ed->src_oct3 = _src >> 8;                                           \
106           ed->src_oct4 = _src;                                                \
107           ed->dst_oct1 = _dst >> 24;                                          \
108           ed->dst_oct2 = _dst >> 16;                                          \
109           ed->dst_oct3 = _dst >> 8;                                           \
110           ed->dst_oct4 = _dst;                                                \
111           ed->ftid = vlib_get_thread_index ();                                \
112           ed->ttid = _tid;                                                    \
113           ed->fib = _fib;                                                     \
114         }                                                                     \
115     }                                                                         \
116   while (0);
117
118 #define nat_elog_debug_handoff_v2(_pm, _str, _prt, _fib, _src, _dst)          \
119   do                                                                          \
120     {                                                                         \
121       if (PREDICT_FALSE (_pm->log_level >= NAT_LOG_DEBUG))                    \
122         {                                                                     \
123           ELOG_TYPE_DECLARE (e) = {                                           \
124             .format =                                                         \
125               "nat-msg " _str " ip_src:%d.%d.%d.%d ip_dst:%d.%d.%d.%d"        \
126               " tid:%d prt:%d fib:%d",                                        \
127             .format_args = "i1i1i1i1i1i1i1i1i4i4i4",                          \
128           };                                                                  \
129           CLIB_PACKED (struct {                                               \
130             u8 src_oct1;                                                      \
131             u8 src_oct2;                                                      \
132             u8 src_oct3;                                                      \
133             u8 src_oct4;                                                      \
134             u8 dst_oct1;                                                      \
135             u8 dst_oct2;                                                      \
136             u8 dst_oct3;                                                      \
137             u8 dst_oct4;                                                      \
138             u32 tid;                                                          \
139             u32 prt;                                                          \
140             u32 fib;                                                          \
141           }) *                                                                \
142             ed;                                                               \
143           ed = ELOG_DATA (&vlib_global_main.elog_main, e);                    \
144           ed->src_oct1 = _src >> 24;                                          \
145           ed->src_oct2 = _src >> 16;                                          \
146           ed->src_oct3 = _src >> 8;                                           \
147           ed->src_oct4 = _src;                                                \
148           ed->dst_oct1 = _dst >> 24;                                          \
149           ed->dst_oct2 = _dst >> 16;                                          \
150           ed->dst_oct3 = _dst >> 8;                                           \
151           ed->dst_oct4 = _dst;                                                \
152           ed->tid = vlib_get_thread_index ();                                 \
153           ed->prt = _prt;                                                     \
154           ed->fib = _fib;                                                     \
155         }                                                                     \
156     }                                                                         \
157   while (0);
158
159 #define nat_elog_X1(_pm, _level, _fmt, _arg, _val1)                           \
160   do                                                                          \
161     {                                                                         \
162       if (PREDICT_FALSE (_pm->log_level >= _level))                           \
163         {                                                                     \
164           ELOG_TYPE_DECLARE (e) = {                                           \
165             .format = "nat-msg " _fmt,                                        \
166             .format_args = _arg,                                              \
167           };                                                                  \
168           CLIB_PACKED (struct { typeof (_val1) val1; }) * ed;                 \
169           ed = ELOG_DATA (&vlib_global_main.elog_main, e);                    \
170           ed->val1 = _val1;                                                   \
171         }                                                                     \
172     }                                                                         \
173   while (0);
174
175 #define nat_elog_notice(_pm, nat_elog_str)                                    \
176   nat_elog (_pm, NAT_LOG_INFO, "[notice] " nat_elog_str)
177 #define nat_elog_warn(_pm, nat_elog_str)                                      \
178   nat_elog (_pm, NAT_LOG_WARNING, "[warning] " nat_elog_str)
179 #define nat_elog_err(_pm, nat_elog_str)                                       \
180   nat_elog (_pm, NAT_LOG_ERROR, "[error] " nat_elog_str)
181 #define nat_elog_debug(_pm, nat_elog_str)                                     \
182   nat_elog (_pm, NAT_LOG_DEBUG, "[debug] " nat_elog_str)
183 #define nat_elog_info(_pm, nat_elog_str)                                      \
184   nat_elog (_pm, NAT_LOG_INFO, "[info] " nat_elog_str)
185
186 #define nat_elog_notice_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg,           \
187                            nat_elog_val1)                                     \
188   nat_elog_X1 (_pm, NAT_LOG_NOTICE, "[notice] " nat_elog_fmt_str,             \
189                nat_elog_fmt_arg, nat_elog_val1)
190 #define nat_elog_warn_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg,             \
191                          nat_elog_val1)                                       \
192   nat_elog_X1 (_pm, NAT_LOG_WARNING, "[warning] " nat_elog_fmt_str,           \
193                nat_elog_fmt_arg, nat_elog_val1)
194 #define nat_elog_err_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg,              \
195                         nat_elog_val1)                                        \
196   nat_elog_X1 (_pm, NAT_LOG_ERROR, "[error] " nat_elog_fmt_str,               \
197                nat_elog_fmt_arg, nat_elog_val1)
198 #define nat_elog_debug_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg,            \
199                           nat_elog_val1)                                      \
200   nat_elog_X1 (_pm, NAT_LOG_DEBUG, "[debug] " nat_elog_fmt_str,               \
201                nat_elog_fmt_arg, nat_elog_val1)
202 #define nat_elog_info_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg,             \
203                          nat_elog_val1)                                       \
204   nat_elog_X1 (_pm, NAT_LOG_INFO, "[info] " nat_elog_fmt_str,                 \
205                nat_elog_fmt_arg, nat_elog_val1)
206
207 #endif /* included_nat_lib_h__ */
208 /*
209  * fd.io coding-style-patch-verification: ON
210  *
211  * Local Variables:
212  * eval: (c-set-style "gnu")
213  * End:
214  */