Mercurial > hg > freeDiameter
changeset 1126:d6e18ebca0c5
New extension dbg_msg_dumps for debug / learning.
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Wed, 15 May 2013 10:05:22 +0800 |
parents | 98d1ad9bf85a |
children | 1af09cc156d6 |
files | extensions/CMakeLists.txt extensions/dbg_msg_dumps/CMakeLists.txt extensions/dbg_msg_dumps/dbg_msg_dumps.c |
diffstat | 3 files changed, 95 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/CMakeLists.txt Wed May 15 10:04:58 2013 +0800 +++ b/extensions/CMakeLists.txt Wed May 15 10:05:22 2013 +0800 @@ -84,9 +84,10 @@ #### # Debug & test extensions -FD_EXTENSION_SUBDIR(dbg_monitor "Outputs periodical status information" OFF) -FD_EXTENSION_SUBDIR(dbg_msg_timings "Show some timing information for messages" OFF) -FD_EXTENSION_SUBDIR(dbg_rt "Routing extension for debugging the routing module" OFF) +FD_EXTENSION_SUBDIR(dbg_monitor "Outputs periodical status information" ON) +FD_EXTENSION_SUBDIR(dbg_msg_timings "Show some timing information for messages" ON) +FD_EXTENSION_SUBDIR(dbg_msg_dumps "Show human-readable content of the received & sent messages" ON) +FD_EXTENSION_SUBDIR(dbg_rt "Routing extension for debugging the routing module" ON) FD_EXTENSION_SUBDIR(test_app "Testing application to send dummy message to another peer, like a Diameter 'ping'" OFF) FD_EXTENSION_SUBDIR(test_sip "Testing application to simulate Diameter-SIP client (RFC4740)" OFF) FD_EXTENSION_SUBDIR(dbg_interactive "Python-interpreter based module" OFF)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/dbg_msg_dumps/CMakeLists.txt Wed May 15 10:05:22 2013 +0800 @@ -0,0 +1,11 @@ +PROJECT("Messages dump extension" C) +FD_ADD_EXTENSION(dbg_msg_dumps dbg_msg_dumps.c) + + +#### +## INSTALL section ## + +INSTALL(TARGETS dbg_msg_dumps + LIBRARY DESTINATION ${INSTALL_EXTENSIONS_SUFFIX} + COMPONENT freeDiameter-debug-tools) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/dbg_msg_dumps/dbg_msg_dumps.c Wed May 15 10:05:22 2013 +0800 @@ -0,0 +1,80 @@ +/********************************************************************************************************* +* Software License Agreement (BSD License) * +* Author: Sebastien Decugis <sdecugis@freediameter.net> * +* * +* Copyright (c) 2013, WIDE Project and NICT * +* All rights reserved. * +* * +* Redistribution and use of this software in source and binary forms, with or without modification, are * +* permitted provided that the following conditions are met: * +* * +* * Redistributions of source code must retain the above * +* copyright notice, this list of conditions and the * +* following disclaimer. * +* * +* * Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the * +* following disclaimer in the documentation and/or other * +* materials provided with the distribution. * +* * +* * Neither the name of the WIDE Project or NICT nor the * +* names of its contributors may be used to endorse or * +* promote products derived from this software without * +* specific prior written permission of WIDE Project and * +* NICT. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * +* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +*********************************************************************************************************/ + +/* This extension uses the hooks mechanism to display the full content of received and sent messages, for + learning & debugging purpose. + Do NOT use this extension in production environment because it will slow down all operation. */ + +#include <freeDiameter/extension.h> + +static struct fd_hook_hdl *md_hdl = NULL; + +/* The callback called when messages are received and sent */ +static void md_hook_cb(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata) +{ + char * buf = NULL; + size_t len; + + CHECK_MALLOC_DO( fd_msg_dump_treeview(&buf, &len, NULL, msg, fd_g_config->cnf_dict, 1, 1), + { LOG_E("Error while dumping a message"); return; } ); + + LOG_N("%s %s: %s", + (type == HOOK_MESSAGE_RECEIVED) ? "RCV FROM" : "SENT TO", + peer ? peer->info.pi_diamid:"<unknown>", + buf); + + free(buf); +} + +/* Entry point */ +static int md_main(char * conffile) +{ + TRACE_ENTRY("%p", conffile); + + CHECK_FCT( fd_hook_register( ((1 << HOOK_MESSAGE_RECEIVED) | (1 << HOOK_MESSAGE_SENT)), + md_hook_cb, NULL, NULL, &md_hdl) ); + + return 0; +} + +/* Cleanup */ +void fd_ext_fini(void) +{ + TRACE_ENTRY(); + CHECK_FCT_DO( fd_hook_unregister( md_hdl ), ); + return ; +} + +EXTENSION_ENTRY("dbg_msg_dumps", md_main);