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 #include <nat/lib/nat_types.api_types.h>
26 #define nat_elog(_pm, _level, _str) \
29 if (PREDICT_FALSE (_pm->log_level >= _level)) \
31 ELOG_TYPE_DECLARE (e) = { \
32 .format = "nat-msg " _str, \
35 ELOG_DATA (&vlib_global_main.elog_main, e); \
40 #define nat_elog_addr(_pm, _level, _str, _addr) \
43 if (PREDICT_FALSE (_pm->log_level >= _level)) \
45 ELOG_TYPE_DECLARE (e) = { \
46 .format = "nat-msg " _str " %d.%d.%d.%d", \
47 .format_args = "i1i1i1i1", \
49 CLIB_PACKED (struct { \
56 ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
57 ed->oct4 = _addr >> 24; \
58 ed->oct3 = _addr >> 16; \
59 ed->oct2 = _addr >> 8; \
65 #define nat_elog_debug_handoff(_pm, _str, _tid, _fib, _src, _dst) \
68 if (PREDICT_FALSE (_pm->log_level >= NAT_LOG_DEBUG)) \
70 ELOG_TYPE_DECLARE (e) = { \
71 .format = "nat-msg " _str " ip src: %d.%d.%d.%d dst: %d.%d.%d.%d" \
72 " tid from: %d to: %d fib: %d", \
73 .format_args = "i1i1i1i1i1i1i1i1i4i4i4", \
75 CLIB_PACKED (struct { \
89 ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
90 ed->src_oct1 = _src >> 24; \
91 ed->src_oct2 = _src >> 16; \
92 ed->src_oct3 = _src >> 8; \
93 ed->src_oct4 = _src; \
94 ed->dst_oct1 = _dst >> 24; \
95 ed->dst_oct2 = _dst >> 16; \
96 ed->dst_oct3 = _dst >> 8; \
97 ed->dst_oct4 = _dst; \
98 ed->ftid = vlib_get_thread_index (); \
105 #define nat_elog_debug_handoff_v2(_pm, _str, _prt, _fib, _src, _dst) \
108 if (PREDICT_FALSE (_pm->log_level >= NAT_LOG_DEBUG)) \
110 ELOG_TYPE_DECLARE (e) = { \
112 "nat-msg " _str " ip_src:%d.%d.%d.%d ip_dst:%d.%d.%d.%d" \
113 " tid:%d prt:%d fib:%d", \
114 .format_args = "i1i1i1i1i1i1i1i1i4i4i4", \
116 CLIB_PACKED (struct { \
130 ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
131 ed->src_oct1 = _src >> 24; \
132 ed->src_oct2 = _src >> 16; \
133 ed->src_oct3 = _src >> 8; \
134 ed->src_oct4 = _src; \
135 ed->dst_oct1 = _dst >> 24; \
136 ed->dst_oct2 = _dst >> 16; \
137 ed->dst_oct3 = _dst >> 8; \
138 ed->dst_oct4 = _dst; \
139 ed->tid = vlib_get_thread_index (); \
146 #define nat_elog_X1(_pm, _level, _fmt, _arg, _val1) \
149 if (PREDICT_FALSE (_pm->log_level >= _level)) \
151 ELOG_TYPE_DECLARE (e) = { \
152 .format = "nat-msg " _fmt, \
153 .format_args = _arg, \
155 CLIB_PACKED (struct { typeof (_val1) val1; }) * ed; \
156 ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
162 #define nat_elog_notice(_pm, nat_elog_str) \
163 nat_elog (_pm, NAT_LOG_INFO, "[notice] " nat_elog_str)
164 #define nat_elog_warn(_pm, nat_elog_str) \
165 nat_elog (_pm, NAT_LOG_WARNING, "[warning] " nat_elog_str)
166 #define nat_elog_err(_pm, nat_elog_str) \
167 nat_elog (_pm, NAT_LOG_ERROR, "[error] " nat_elog_str)
168 #define nat_elog_debug(_pm, nat_elog_str) \
169 nat_elog (_pm, NAT_LOG_DEBUG, "[debug] " nat_elog_str)
170 #define nat_elog_info(_pm, nat_elog_str) \
171 nat_elog (_pm, NAT_LOG_INFO, "[info] " nat_elog_str)
173 #define nat_elog_notice_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg, \
175 nat_elog_X1 (_pm, NAT_LOG_NOTICE, "[notice] " nat_elog_fmt_str, \
176 nat_elog_fmt_arg, nat_elog_val1)
177 #define nat_elog_warn_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg, \
179 nat_elog_X1 (_pm, NAT_LOG_WARNING, "[warning] " nat_elog_fmt_str, \
180 nat_elog_fmt_arg, nat_elog_val1)
181 #define nat_elog_err_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg, \
183 nat_elog_X1 (_pm, NAT_LOG_ERROR, "[error] " nat_elog_fmt_str, \
184 nat_elog_fmt_arg, nat_elog_val1)
185 #define nat_elog_debug_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg, \
187 nat_elog_X1 (_pm, NAT_LOG_DEBUG, "[debug] " nat_elog_fmt_str, \
188 nat_elog_fmt_arg, nat_elog_val1)
189 #define nat_elog_info_X1(_pm, nat_elog_fmt_str, nat_elog_fmt_arg, \
191 nat_elog_X1 (_pm, NAT_LOG_INFO, "[info] " nat_elog_fmt_str, \
192 nat_elog_fmt_arg, nat_elog_val1)
194 #endif /* included_nat_lib_h__ */
196 * fd.io coding-style-patch-verification: ON
199 * eval: (c-set-style "gnu")