# HG changeset patch # User Sebastien Decugis # Date 1267496351 -32400 # Node ID 406f74f0789bcee814f43e45303cd2ebe7dd3f13 # Parent 07e5914b48f712b3cbb5e7c1fada184c5b920b9f Few cosmetics changes diff -r 07e5914b48f7 -r 406f74f0789b freeDiameter/routing_dispatch.c --- a/freeDiameter/routing_dispatch.c Fri Feb 26 11:19:23 2010 +0900 +++ b/freeDiameter/routing_dispatch.c Tue Mar 02 11:19:11 2010 +0900 @@ -451,7 +451,7 @@ /* Read the message header */ CHECK_FCT( fd_msg_hdr(*pmsg, &hdr) ); is_req = hdr->msg_flags & CMD_FLAG_REQUEST; - + /* Note: if the message is for local delivery, we should test for duplicate (draft-asveren-dime-dupcons-00). This may conflict with path validation decisions, no clear answer yet */ diff -r 07e5914b48f7 -r 406f74f0789b include/freeDiameter/libfreeDiameter.h --- a/include/freeDiameter/libfreeDiameter.h Fri Feb 26 11:19:23 2010 +0900 +++ b/include/freeDiameter/libfreeDiameter.h Tue Mar 02 11:19:11 2010 +0900 @@ -77,9 +77,6 @@ /*============================================================*/ /* DEBUG */ /*============================================================*/ -#ifndef ASSERT -#define ASSERT(x) assert(x) -#endif /* ASSERT */ /* * FUNCTION: fd_log_debug @@ -139,6 +136,14 @@ char * fd_log_time ( struct timespec * ts, char * buf, size_t len ); +/*============================================================*/ +/* DEBUG MACROS */ +/*============================================================*/ + +#ifndef ASSERT +#define ASSERT(x) assert(x) +#endif /* ASSERT */ + /* levels definitions */ #define NONE 0 /* Display no debug message */ #define INFO 1 /* Display errors only */ @@ -174,6 +179,7 @@ static char * file_bname = NULL; #define __STRIPPED_FILE__ (file_bname ?: (file_bname = basename(__FILE__))) + /* Boolean for tracing at a certain level */ #ifdef DEBUG #define TRACE_BOOL(_level_) ( ((_level_) <= local_debug_level + fd_g_debug_lvl) \ @@ -183,7 +189,10 @@ #define TRACE_BOOL(_level_) ((_level_) <= local_debug_level + fd_g_debug_lvl) #endif /* DEBUG */ -/* The general debug macro, each call results in two lines of debug messages (change the macro for more compact output) */ + +/************* + The general debug macro, each call results in two lines of debug messages (change the macro for more compact output) + *************/ #define TRACE_DEBUG(level,format,args... ) { \ if ( TRACE_BOOL(level) ) { \ char __buf[25]; \ @@ -195,6 +204,9 @@ } \ } +/************* + Derivatives from this macro + ************/ /* Helper for function entry -- for very detailed trace of the execution */ #define TRACE_ENTRY(_format,_args... ) \ TRACE_DEBUG(FCTS, "[enter] %s(" _format ") {" #_args "}", __PRETTY_FUNCTION__, ##_args ); @@ -217,9 +229,94 @@ "TODO" = _msg ## _args; /* just a stupid compilation error to spot the todo */ #endif /* ERRORS_ON_TODO */ +/* Trace a binary buffer content */ +#define TRACE_DEBUG_BUFFER(level, prefix, buf, bufsz, suffix ) { \ + if ( TRACE_BOOL(level) ) { \ + char __ts[25]; \ + int __i; \ + size_t __sz = (size_t)(bufsz); \ + uint8_t * __buf = (uint8_t *)(buf); \ + char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ + fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ + "\t%s|%*s" prefix , \ + __thn, fd_log_time(NULL, __ts, sizeof(__ts)), __PRETTY_FUNCTION__, __FILE__, __LINE__, \ + (level < FULL)?"@":" ",level, ""); \ + for (__i = 0; __i < __sz; __i++) { \ + fd_log_debug("%02.2hhx", __buf[__i]); \ + } \ + fd_log_debug(suffix "\n"); \ + } \ +} + +/* Some aliases to socket addresses structures */ +#define sSS struct sockaddr_storage +#define sSA struct sockaddr +#define sSA4 struct sockaddr_in +#define sSA6 struct sockaddr_in6 + +/* Dump one sockaddr Node information */ +#define sSA_DUMP_NODE( sa, flag ) { \ + sSA * __sa = (sSA *)(sa); \ + char __addrbuf[INET6_ADDRSTRLEN]; \ + if (__sa) { \ + int __rc = getnameinfo(__sa, \ + sizeof(sSS), \ + __addrbuf, \ + sizeof(__addrbuf), \ + NULL, \ + 0, \ + flag); \ + if (__rc) \ + fd_log_debug("%s", (char *)gai_strerror(__rc)); \ + else \ + fd_log_debug("%s", &__addrbuf[0]); \ + } else { \ + fd_log_debug("(NULL / ANY)"); \ + } \ +} +/* Same but with the port (service) also */ +#define sSA_DUMP_NODE_SERV( sa, flag ) { \ + sSA * __sa = (sSA *)(sa); \ + char __addrbuf[INET6_ADDRSTRLEN]; \ + char __servbuf[32]; \ + if (__sa) { \ + int __rc = getnameinfo(__sa, \ + sizeof(sSS), \ + __addrbuf, \ + sizeof(__addrbuf), \ + __servbuf, \ + sizeof(__servbuf), \ + flag); \ + if (__rc) \ + fd_log_debug("%s", (char *)gai_strerror(__rc)); \ + else \ + fd_log_debug("[%s]:%s", &__addrbuf[0],&__servbuf[0]); \ + } else { \ + fd_log_debug("(NULL / ANY)"); \ + } \ +} + +/* Inside a debug trace */ +#define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix ) { \ + if ( TRACE_BOOL(level) ) { \ + char __buf[25]; \ + char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ + fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ + "\t%s|%*s" prefix , \ + __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\ + (level < FULL)?"@":" ",level, ""); \ + sSA_DUMP_NODE_SERV( sa, flags ); \ + fd_log_debug(suffix "\n"); \ + } \ +} + + +/*============================================================*/ +/* ERROR CHECKING MACRO */ +/*============================================================*/ /* Macros to check a return value and branch out in case of error. - * These macro must be used only when errors are highly improbable, not for expected errors. + * These macro should be used only when errors are improbable, not for expected errors. */ /* Check the return value of a system function and execute fallback in case of error */ @@ -287,8 +384,6 @@ CHECK_MALLOC_DO( __call__, return ENOMEM ); -/* The next macros can be used also for expected errors */ - /* Check parameters at function entry, execute fallback on error */ #define CHECK_PARAMS_DO( __bool__, __fallback__ ) \ TRACE_DEBUG_ALL( "Check PARAMS: " #__bool__ ); \ @@ -318,7 +413,7 @@ /*============================================================*/ -/* MACROS */ +/* OTHER MACROS */ /*============================================================*/ /* helper macros (pre-processor hacks to allow macro arguments) */ @@ -327,67 +422,6 @@ #define __agr( arg1, arg2 ) arg1 ## arg2 #define _aggregate( arg1, arg2 ) __agr( arg1, arg2 ) -/* Some aliases to socket addresses structures */ -#define sSS struct sockaddr_storage -#define sSA struct sockaddr -#define sSA4 struct sockaddr_in -#define sSA6 struct sockaddr_in6 - -/* Dump one sockaddr Node information */ -#define sSA_DUMP_NODE( sa, flag ) { \ - sSA * __sa = (sSA *)(sa); \ - char __addrbuf[INET6_ADDRSTRLEN]; \ - if (__sa) { \ - int __rc = getnameinfo(__sa, \ - sizeof(sSS), \ - __addrbuf, \ - sizeof(__addrbuf), \ - NULL, \ - 0, \ - flag); \ - if (__rc) \ - fd_log_debug("%s", (char *)gai_strerror(__rc)); \ - else \ - fd_log_debug("%s", &__addrbuf[0]); \ - } else { \ - fd_log_debug("(NULL / ANY)"); \ - } \ -} -/* Same but with the port (service) also */ -#define sSA_DUMP_NODE_SERV( sa, flag ) { \ - sSA * __sa = (sSA *)(sa); \ - char __addrbuf[INET6_ADDRSTRLEN]; \ - char __servbuf[32]; \ - if (__sa) { \ - int __rc = getnameinfo(__sa, \ - sizeof(sSS), \ - __addrbuf, \ - sizeof(__addrbuf), \ - __servbuf, \ - sizeof(__servbuf), \ - flag); \ - if (__rc) \ - fd_log_debug("%s", (char *)gai_strerror(__rc)); \ - else \ - fd_log_debug("[%s]:%s", &__addrbuf[0],&__servbuf[0]); \ - } else { \ - fd_log_debug("(NULL / ANY)"); \ - } \ -} -/* Inside a debug trace */ -#define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix ) { \ - if ( TRACE_BOOL(level) ) { \ - char __buf[25]; \ - char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ - fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ - "\t%s|%*s" prefix , \ - __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\ - (level < FULL)?"@":" ",level, ""); \ - sSA_DUMP_NODE_SERV( sa, flags ); \ - fd_log_debug(suffix "\n"); \ - } \ -} - /* A l4 protocol name (TCP / SCTP) */ #ifdef DISABLE_SCTP @@ -424,7 +458,6 @@ (((long int) (a)->s_addr) == 0x00000000) #endif /* IN_IS_ADDR_UNSPECIFIED */ - /* create a V4MAPPED address */ #define IN6_ADDR_V4MAP( a6, a4 ) { \ ((uint32_t *)(a6))[0] = 0; \ @@ -439,7 +472,7 @@ /* We provide macros to convert 64 bit values to and from network byte-order, on systems where it is not already provided. */ -#ifndef HAVE_NTOHLL /* Defined in config.h, if the ntohll symbol is defined on the system */ +#ifndef HAVE_NTOHLL /* Defined by the cmake step, if the ntohll symbol is defined on the system */ # if HOST_BIG_ENDIAN /* In big-endian systems, we don't have to change the values, since the order is the same as network */ # define ntohll(x) (x) @@ -454,7 +487,7 @@ /* This macro will give the next multiple of 4 for an integer (used for padding sizes of AVP). */ #define PAD4(_x) ((_x) + ( (4 - (_x)) & 3 ) ) -/* Useful to display as safe ASCII a value (will garbage UTF-8 output...) */ +/* Useful to display any value as (safe) ASCII (will garbage UTF-8 output...) */ #define ASCII(_c) ( ((_c < 32) || (_c > 127)) ? ( _c ? '?' : ' ' ) : _c ) /* Compare timespec structures */ @@ -463,26 +496,6 @@ || (((ts1)->tv_sec == (ts2)->tv_sec ) && ((ts1)->tv_nsec < (ts2)->tv_nsec) )) -/* Trace a binary buffer content */ -#define TRACE_DEBUG_BUFFER(level, prefix, buf, bufsz, suffix ) { \ - if ( TRACE_BOOL(level) ) { \ - char __ts[25]; \ - int __i; \ - size_t __sz = (size_t)(bufsz); \ - uint8_t * __buf = (uint8_t *)(buf); \ - char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ - fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ - "\t%s|%*s" prefix , \ - __thn, fd_log_time(NULL, __ts, sizeof(__ts)), __PRETTY_FUNCTION__, __FILE__, __LINE__, \ - (level < FULL)?"@":" ",level, ""); \ - for (__i = 0; __i < __sz; __i++) { \ - fd_log_debug("%02.2hhx", __buf[__i]); \ - } \ - fd_log_debug(suffix "\n"); \ - } \ -} - - /*============================================================*/ /* THREADS */ @@ -517,7 +530,9 @@ return 0; } -/* Cleanups for cancellation (all threads should be safely cancelable...) */ +/************* + Cancelation cleanup handlers for common objects + *************/ static __inline__ void fd_cleanup_mutex( void * mutex ) { CHECK_POSIX_DO( pthread_mutex_unlock((pthread_mutex_t *)mutex), /* */); @@ -550,7 +565,7 @@ struct fd_list *next; /* next element in the list */ struct fd_list *prev; /* previous element in the list */ struct fd_list *head; /* head of the list */ - void *o; /* additional avialbe pointer used for start of the parento object or other purpose */ + void *o; /* additional pointer, used for any purpose (ex: start of the parent object) */ }; /* Initialize a list element */ @@ -567,15 +582,21 @@ void fd_list_insert_after ( struct fd_list * ref, struct fd_list * item ); void fd_list_insert_before ( struct fd_list * ref, struct fd_list * item ); -/* Move a list at the end of another */ +/* Move all elements from a list at the end of another */ void fd_list_move_end(struct fd_list * ref, struct fd_list * senti); -/* Insert an item in an ordered list -- ordering function provided. If duplicate object found, EEXIST and it is returned in ref_duplicate */ +/* Insert an item in an ordered list -- ordering function must be provided. If duplicate object found, EEXIST and it is returned in ref_duplicate */ int fd_list_insert_ordered( struct fd_list * head, struct fd_list * item, int (*cmp_fct)(void *, void *), void ** ref_duplicate); /* Unlink an item from a list */ void fd_list_unlink ( struct fd_list * item ); + + +/*============================================================*/ +/* HASH */ +/*============================================================*/ + /* Compute a hash value of a string (session id, diameter id, ...) */ uint32_t fd_hash ( char * string, size_t len ); @@ -912,7 +933,7 @@ char *type_name; /* The name of this type */ dict_avpdata_interpret type_interpret;/* cb to convert the AVP value in more comprehensive format (or NULL) */ dict_avpdata_encode type_encode; /* cb to convert formatted data into an AVP value (or NULL) */ - void (*type_dump)(union avp_value * val); /* cb called by fd_msg_dump_one for this type of data (if != NULL) */ + void (*type_dump)(union avp_value * val); /* cb called by fd_msg_dump_one for this type of data (if != NULL), to dump the AVP value in debug */ }; /* The criteria for searching a type object in the dictionary */ @@ -1428,7 +1449,7 @@ /* This opaque structure represents a session associated with a Session-Id */ struct session; -/* The state information that a module associate with a session -- each module define its own data format */ +/* The state information that a module associate with a session -- each module defines its own data format */ typedef void session_state; /*