embedded IPsec source code documentation


debug.h

Go to the documentation of this file.
00001 /*
00002  * embedded IPsec
00003  * Copyright (c) 2003 Niklaus Schild and Christian Scheurer, HTI Biel/Bienne
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without modification,
00007  * are permitted provided that the following conditions are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright notice,
00010  *    this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright notice,
00012  *    this list of conditions and the following disclaimer in the documentation
00013  *    and/or other materials provided with the distribution.
00014  * 3. The name of the author may not be used to endorse or promote products
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00018  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00020  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00021  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00022  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00025  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00026  * OF SUCH DAMAGE.
00027  *
00028  */
00029 
00042 #ifndef __IPSEC_DEBUG_H__
00043 #define __IPSEC_DEBUG_H__
00044 
00045 #include <stdio.h>
00046 #include "ipsec/util.h"
00047 
00051 #define IPSEC_ERROR                     
00056 //#define IPSEC_DEBUG                   
00060 #define IPSEC_MESSAGE           
00065 //#define IPSEC_TRACE                   
00068 #define IPSEC_AUDIT                     
00071 #define IPSEC_TEST                      
00074 //#define IPSEC_DUMP_BUFFERS    
00077 #define IPSEC_TABLES            
00082 #define IPSEC_LOG_MESSAGE_SIZE (128)
00083 
00084 
00085 /* @def When error logging is activated (IPSEC_ERROR), then we define a logging function for it. Otherwise nothing is printed */
00086 #ifdef IPSEC_ERROR
00087         #define IPSEC_LOG_ERR(__function_name__, __code__, __message__) { \
00088                                 printf("ERR %-28s: %9d : ", __function_name__, __code__); \
00089                                 printf __message__ ;  \
00090                                 printf("\n"); \
00091                         }
00092 #else
00093         #define IPSEC_LOG_ERR(__function_name__, __code__, __message__)
00094 #endif
00095 
00096 
00097 /* @def When debug messages are turned on (IPSEC_DEBUG), then we define a logging function for it. Otherwise nothing is printed. */
00098 #ifdef IPSEC_DEBUG
00099         #define IPSEC_LOG_DBG(__function_name__, __code__, __message__) { \
00100                                 printf("DBG %-28s: %9d : ", __function_name__, __code__); \
00101                                 printf __message__ ;  \
00102                                 printf("\n"); \
00103                         }
00104 #else
00105         #define IPSEC_LOG_DBG(__function_name__, __code__, __message__)
00106 #endif
00107 
00108 /* @def When informative messages are turned on (IPSEC_MESSAGE), then we define a logging function for it. Otherwise nothing is printed. */
00109 #ifdef IPSEC_MESSAGE
00110         #define IPSEC_LOG_MSG(__function_name__, __message__) { \
00111                                 printf("MSG %-28s: ", __function_name__); \
00112                                 printf __message__ ;  \
00113                                 printf("\n"); \
00114                         }
00115 #else
00116         #define IPSEC_LOG_MSG(__function_name__, __message__)
00117 #endif
00118 
00119 /* @def When informative audit messages are turned on (IPSEC_AUDIT), then we define a logging function for it. Otherwise nothing is printed. */
00120 #ifdef IPSEC_AUDIT
00121         #define IPSEC_LOG_AUD(__function_name__, __code__, __message__) { \
00122                                 printf("AUD %-28s: %9d : ", __function_name__, __code__); \
00123                                 printf __message__ ;  \
00124                                 printf("\n"); \
00125                         }
00126 #else
00127         #define IPSEC_LOG_AUD(__function_name__, __code__, __message__)
00128 #endif
00129 
00130 /* @def When test messages are turned on (IPSEC_TEST), then we define a logging function for it. Otherwise nothing is printed. */
00131 #ifdef IPSEC_TEST
00132         #define IPSEC_LOG_TST(__function_name__, __code__, __message__) { \
00133                                 printf("TST %-28s: %9s : ", __function_name__, __code__); \
00134                                 printf __message__ ;  \
00135                                 printf("\n"); \
00136                         }
00137         #define IPSEC_LOG_TST_NOMSG(__function_name__, __code__) printf("TST %-28s: %9s : ", __function_name__, __code__)
00138 #else
00139         #define IPSEC_LOG_TST(__function_name__, __code__, __message__)
00140         #define IPSEC_LOG_TST_NOMSG(__function_name__, __code__)
00141 #endif
00142 
00143 
00144 /* @def When trace messages are turned on (IPSEC_TRACE), then we define a logging function for it. Otherwise nothing is printed. */
00145 #ifdef IPSEC_TRACE
00146         #define IPSEC_TRACE_ENTER   1
00147         #define IPSEC_TRACE_RETURN -1
00148 
00149         extern int __ipsec_trace_indication;            /* variable used inside debug macros */
00150         extern int __ipsec_trace_indication__pos;       /* variable used inside debug macros */
00151 
00152         /* the useless (__ipsec_trace_indication < 0) test is only here to avoid compiler warnings */
00153         #define IPSEC_LOG_TRC(__action__, __function_name__, __message__) { \
00154                                 if(__action__ == IPSEC_TRACE_ENTER | (__ipsec_trace_indication < 0)) { \
00155                                         __ipsec_trace_indication++; \
00156                         for(__ipsec_trace_indication__pos = 0; __ipsec_trace_indication__pos < __ipsec_trace_indication; __ipsec_trace_indication__pos++) {\
00157                                                 printf("  "); \
00158                                         } \
00159                                         printf("ENTER  %s(", __function_name__); \
00160                                 } else { \
00161                         for(__ipsec_trace_indication__pos = 0; __ipsec_trace_indication__pos < __ipsec_trace_indication; __ipsec_trace_indication__pos++) {\
00162                                                 printf("  "); \
00163                                         } \
00164                                         __ipsec_trace_indication--; \
00165                                         printf("RETURN %s(", __function_name__); \
00166                                 } \
00167                                 printf __message__ ;\
00168                                 printf(")\n"); \
00169                         }
00170         #define IPSEC_LOG_TST_NOMSG(__function_name__, __code__) printf("TST %-28s: %9s : ", __function_name__, __code__)
00171 #else
00172         #define IPSEC_LOG_TRC(__action__, __function_name__, __message__)
00173 #endif
00174 
00175 /* @def When buffer dumping is turned on (IPSEC_DUMP_BUFFERS), then we define a dump function for it. Otherwise nothing is printed. */
00176 #ifdef IPSEC_DUMP_BUFFERS
00177         #define IPSEC_DUMP_BUFFER(__prefix__, __buffer__, __offset__, __length__) ipsec_dump_buffer(__prefix__, __buffer__, __offset__, __length__)
00178 #else
00179         #define IPSEC_DUMP_BUFFER(__prefix__, __buffer__, __offset__, __length__)
00180 #endif
00181 
00182 #endif

Copyright 2003 by Christian Scheurer and Niklaus Schild