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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @brief NAT port/address allocation lib
19 #ifndef included_nat_log_h__
20 #define included_nat_log_h__
22 #include <vppinfra/elog.h>
24 #define foreach_nat_log_level \
27 _ (0x02, LOG_WARNING) \
28 _ (0x03, LOG_NOTICE) \
32 typedef enum nat_log_level_t_
34 #define _(n, f) NAT_##f = n,
39 #define nat_elog(_pm, _level, _str) \
42 if (PREDICT_FALSE (_pm->log_level >= _level)) \
44 ELOG_TYPE_DECLARE (e) = { \
45 .format = "nat-msg " _str, \
48 ELOG_DATA (&vlib_global_main.elog_main, e); \
53 #define nat_elog_addr(_pm, _level, _str, _addr) \
56 if (PREDICT_FALSE (_pm->log_level >= _level)) \
58 ELOG_TYPE_DECLARE (e) = { \
59 .format = "nat-msg " _str " %d.%d.%d.%d", \
60 .format_args = "i1i1i1i1", \
62 CLIB_PACKED (struct { \
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; \
78 #define nat_elog_debug_handoff(_pm, _str, _tid, _fib, _src, _dst) \
81 if (PREDICT_FALSE (_pm->log_level >= NAT_LOG_DEBUG)) \
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", \
88 CLIB_PACKED (struct { \
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 (); \
118 #define nat_elog_debug_handoff_v2(_pm, _str, _prt, _fib, _src, _dst) \
121 if (PREDICT_FALSE (_pm->log_level >= NAT_LOG_DEBUG)) \
123 ELOG_TYPE_DECLARE (e) = { \
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", \
129 CLIB_PACKED (struct { \
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 (); \
159 #define nat_elog_X1(_pm, _level, _fmt, _arg, _val1) \
162 if (PREDICT_FALSE (_pm->log_level >= _level)) \
164 ELOG_TYPE_DECLARE (e) = { \
165 .format = "nat-msg " _fmt, \
166 .format_args = _arg, \
168 CLIB_PACKED (struct { typeof (_val1) val1; }) * ed; \
169 ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
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)
186 #define nat_elog_notice_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg, \
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, \
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, \
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, \
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, \
204 nat_elog_X1 (_pm, NAT_LOG_INFO, "[info] " nat_elog_fmt_str, \
205 nat_elog_fmt_arg, nat_elog_val1)
207 #endif /* included_nat_lib_h__ */
209 * fd.io coding-style-patch-verification: ON
212 * eval: (c-set-style "gnu")