summaryrefslogtreecommitdiffstats
path: root/src/plugins/ikev2/ikev2_priv.h
diff options
context:
space:
mode:
authorFilip Tehlar <ftehlar@cisco.com>2019-10-20 10:38:13 +0000
committerDamjan Marion <dmarion@me.com>2020-02-10 11:57:37 +0000
commit8ebcb7a99d7b73a1ee5874780b4efdc69d32c82f (patch)
treef8f70ca32bf025dce498f88d1ec904790e0f86f4 /src/plugins/ikev2/ikev2_priv.h
parent14b804898a5e5b9ec5029d3466621178b85af925 (diff)
ikev2: better logging
Type: refactor Change-Id: Iedcb24684c54f4d78583ab3aa3db1097e73df248 Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Diffstat (limited to 'src/plugins/ikev2/ikev2_priv.h')
-rw-r--r--src/plugins/ikev2/ikev2_priv.h180
1 files changed, 173 insertions, 7 deletions
diff --git a/src/plugins/ikev2/ikev2_priv.h b/src/plugins/ikev2/ikev2_priv.h
index 630ba1ba351..aa85b84727a 100644
--- a/src/plugins/ikev2/ikev2_priv.h
+++ b/src/plugins/ikev2/ikev2_priv.h
@@ -30,13 +30,173 @@
#include <openssl/hmac.h>
#include <openssl/evp.h>
-#define IKEV2_DEBUG_PAYLOAD 1
+#define foreach_ikev2_log_level \
+ _(0x00, LOG_NONE) \
+ _(0x01, LOG_ERROR) \
+ _(0x02, LOG_WARNING) \
+ _(0x03, LOG_INFO) \
+ _(0x04, LOG_DEBUG) \
+ _(0x05, LOG_DETAIL) \
-#if IKEV2_DEBUG_PAYLOAD == 1
-#define DBG_PLD(my_args...) clib_warning(my_args)
-#else
-#define DBG_PLD(my_args...)
-#endif
+
+typedef enum ikev2_log_level_t_
+{
+#define _(n,f) IKEV2_##f = n,
+ foreach_ikev2_log_level
+#undef _
+ IKEV2_LOG_MAX
+} ikev2_log_level_t;
+
+/* dataplane logging */
+#define _ikev2_elog(_level, _msg) \
+do { \
+ ikev2_main_t *km = &ikev2_main; \
+ if (PREDICT_FALSE (km->log_level >= _level)) \
+ { \
+ ELOG_TYPE_DECLARE (e) = \
+ { \
+ .format = "ikev2 " _msg, \
+ .format_args = "", \
+ }; \
+ ELOG_DATA (&vlib_global_main.elog_main, e); \
+ } \
+} while (0)
+
+#define ikev2_elog_sa_state(_format, _ispi) \
+do { \
+ ikev2_main_t *km = &ikev2_main; \
+ if (PREDICT_FALSE (km->log_level >= IKEV2_LOG_DEBUG)) \
+ { \
+ ELOG_TYPE_DECLARE (e) = \
+ { \
+ .format = "ikev2: " _format, \
+ .format_args = "i8", \
+ }; \
+ CLIB_PACKED(struct \
+ { \
+ u64 ispi; \
+ }) *ed; \
+ ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
+ ed->ispi = _ispi; \
+ } \
+} while (0) \
+
+#define ikev2_elog_exchange(_format, _ispi, _rspi, _addr) \
+do { \
+ ikev2_main_t *km = &ikev2_main; \
+ if (PREDICT_FALSE (km->log_level >= IKEV2_LOG_DEBUG)) \
+ { \
+ ELOG_TYPE_DECLARE (e) = \
+ { \
+ .format = "ikev2: " _format, \
+ .format_args = "i8i8i1i1i1i1", \
+ }; \
+ CLIB_PACKED(struct \
+ { \
+ u64 ispi; \
+ u64 rspi; \
+ u8 oct1; \
+ u8 oct2; \
+ u8 oct3; \
+ u8 oct4; \
+ }) *ed; \
+ ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
+ ed->ispi = _ispi; \
+ ed->rspi = _rspi; \
+ ed->oct4 = (_addr) >> 24; \
+ ed->oct3 = (_addr) >> 16; \
+ ed->oct2 = (_addr) >> 8; \
+ ed->oct1 = (_addr); \
+ } \
+} while (0) \
+
+#define ikev2_elog_uint(_level, _format, _val) \
+do { \
+ ikev2_main_t *km = &ikev2_main; \
+ if (PREDICT_FALSE (km->log_level >= _level)) \
+ { \
+ ELOG_TYPE_DECLARE (e) = \
+ { \
+ .format = "ikev2: " _format, \
+ .format_args = "i8", \
+ }; \
+ CLIB_PACKED(struct \
+ { \
+ u64 val; \
+ }) *ed; \
+ ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
+ ed->val = _val; \
+ } \
+} while (0)
+
+#define ikev2_elog_uint_peers(_level, _format, _val, _ip1, _ip2) \
+do { \
+ ikev2_main_t *km = &ikev2_main; \
+ if (PREDICT_FALSE (km->log_level >= _level)) \
+ { \
+ ELOG_TYPE_DECLARE (e) = \
+ { \
+ .format = "ikev2: " _format, \
+ .format_args = "i8i1i1i1i1i1i1i1i1", \
+ }; \
+ CLIB_PACKED(struct { \
+ u64 val; \
+ u8 i11; u8 i12; u8 i13; u8 i14; \
+ u8 i21; u8 i22; u8 i23; u8 i24; }) *ed; \
+ ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
+ ed->val = _val; \
+ ed->i14 = (_ip1) >> 24; \
+ ed->i13 = (_ip1) >> 16; \
+ ed->i12 = (_ip1) >> 8; \
+ ed->i11 = (_ip1); \
+ ed->i24 = (_ip2) >> 24; \
+ ed->i23 = (_ip2) >> 16; \
+ ed->i22 = (_ip2) >> 8; \
+ ed->i21 = (_ip2); \
+ } \
+} while (0)
+
+#define ikev2_elog_peers(_level, _format, _ip1, _ip2) \
+do { \
+ ikev2_main_t *km = &ikev2_main; \
+ if (PREDICT_FALSE (km->log_level >= _level)) \
+ { \
+ ELOG_TYPE_DECLARE (e) = \
+ { \
+ .format = "ikev2: " _format, \
+ .format_args = "i1i1i1i1i1i1i1i1", \
+ }; \
+ CLIB_PACKED(struct { \
+ u8 i11; u8 i12; u8 i13; u8 i14; \
+ u8 i21; u8 i22; u8 i23; u8 i24; }) *ed; \
+ ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
+ ed->i14 = (_ip1) >> 24; \
+ ed->i13 = (_ip1) >> 16; \
+ ed->i12 = (_ip1) >> 8; \
+ ed->i11 = (_ip1); \
+ ed->i24 = (_ip2) >> 24; \
+ ed->i23 = (_ip2) >> 16; \
+ ed->i22 = (_ip2) >> 8; \
+ ed->i21 = (_ip2); \
+ } \
+} while (0)
+
+#define ikev2_elog_error(_msg) \
+ _ikev2_elog(IKEV2_LOG_ERROR, "[error] " _msg)
+#define ikev2_elog_warning(_msg) \
+ _ikev2_elog(IKEV2_LOG_WARNING, "[warning] " _msg)
+#define ikev2_elog_debug(_msg) \
+ _ikev2_elog(IKEV2_LOG_DEBUG, "[debug] " _msg)
+#define ikev2_elog_detail(_msg) \
+ _ikev2_elog(IKEV2_LOG_DETAIL, "[detail] " _msg)
+
+/* logging for main thread */
+#define ikev2_log_error(...) \
+ vlib_log(VLIB_LOG_LEVEL_ERR, ikev2_main.log_class, __VA_ARGS__)
+#define ikev2_log_warning(...) \
+ vlib_log(VLIB_LOG_LEVEL_WARNING, ikev2_main.log_class, __VA_ARGS__)
+#define ikev2_log_debug(...) \
+ vlib_log(VLIB_LOG_LEVEL_DEBUG, ikev2_main.log_class, __VA_ARGS__)
typedef enum
{
@@ -302,6 +462,12 @@ typedef struct
/* API message ID base */
u16 msg_id_base;
+
+ /* log class used for main thread */
+ vlib_log_class_t log_class;
+
+ /* logging level */
+ ikev2_log_level_t log_level;
} ikev2_main_t;
extern ikev2_main_t ikev2_main;
@@ -361,7 +527,7 @@ ikev2_sa_proposal_t *ikev2_parse_sa_payload (ike_payload_header_t * ikep);
ikev2_ts_t *ikev2_parse_ts_payload (ike_payload_header_t * ikep);
ikev2_delete_t *ikev2_parse_delete_payload (ike_payload_header_t * ikep);
ikev2_notify_t *ikev2_parse_notify_payload (ike_payload_header_t * ikep);
-
+int ikev2_set_log_level (ikev2_log_level_t log_level);
#endif /* __included_ikev2_priv_h__ */