| 1 |
/********************************************************************************************************* |
| 2 |
* Software License Agreement (BSD License) * |
| 3 |
* Author: Sebastien Decugis <[email protected]> * |
| 4 |
* * |
| 5 |
* Copyright (c) 2013, WIDE Project and NICT * |
| 6 |
* All rights reserved. * |
| 7 |
* * |
| 8 |
* Redistribution and use of this software in source and binary forms, with or without modification, are * |
| 9 |
* permitted provided that the following conditions are met: * |
| 10 |
* * |
| 11 |
* * Redistributions of source code must retain the above * |
| 12 |
* copyright notice, this list of conditions and the * |
| 13 |
* following disclaimer. * |
| 14 |
* * |
| 15 |
* * Redistributions in binary form must reproduce the above * |
| 16 |
* copyright notice, this list of conditions and the * |
| 17 |
* following disclaimer in the documentation and/or other * |
| 18 |
* materials provided with the distribution. * |
| 19 |
* * |
| 20 |
* * Neither the name of the WIDE Project or NICT nor the * |
| 21 |
* names of its contributors may be used to endorse or * |
| 22 |
* promote products derived from this software without * |
| 23 |
* specific prior written permission of WIDE Project and * |
| 24 |
* NICT. * |
| 25 |
* * |
| 26 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
| 27 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
| 28 |
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
| 29 |
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
| 30 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
| 31 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
| 32 |
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
| 33 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
| 34 |
*********************************************************************************************************/ |
| 35 |
|
| 36 |
/* |
| 37 |
* Debug-only extension for routing module; |
| 38 |
* displays state information at the end of routing information process. |
| 39 |
*/ |
| 40 |
#include <freeDiameter/extension.h> |
| 41 |
|
| 42 |
static struct fd_rt_fwd_hdl * fwd_hdl = NULL; |
| 43 |
static struct fd_rt_out_hdl * out_hdl = NULL; |
| 44 |
|
| 45 |
/* Proxying debug callback */ |
| 46 |
static int dbgrt_fwd_cb(void * cbdata, struct msg ** msg) |
| 47 |
{ |
| 48 |
char * buf = NULL; size_t buflen; |
| 49 |
TRACE_ENTRY("%p %p", cbdata, msg); |
| 50 |
|
| 51 |
LOG_D("[dbg_rt] FWD routing message: %p", msg ? *msg : NULL); |
| 52 |
if (msg) { |
| 53 |
CHECK_MALLOC( fd_msg_dump_treeview(&buf, &buflen, NULL, *msg, NULL, 0, 1) ); |
| 54 |
LOG_D("%s", buf); |
| 55 |
} |
| 56 |
free(buf); |
| 57 |
return 0; |
| 58 |
} |
| 59 |
|
| 60 |
/* Path selection debug callback */ |
| 61 |
static int dbgrt_out_cb(void * cbdata, struct msg ** pmsg, struct fd_list * candidates) |
| 62 |
{ |
| 63 |
struct fd_list * li; |
| 64 |
struct msg * msg = *pmsg; |
| 65 |
char * buf = NULL; size_t buflen; |
| 66 |
|
| 67 |
TRACE_ENTRY("%p %p %p", cbdata, msg, candidates); |
| 68 |
|
| 69 |
LOG_D("[dbg_rt] OUT routing message: %p", msg); |
| 70 |
CHECK_MALLOC( fd_msg_dump_treeview(&buf, &buflen, NULL, msg, NULL, 0, 1) ); |
| 71 |
LOG_D("%s", buf); |
| 72 |
LOG_D("[dbg_rt] Current list of candidates (%p): (score - id)", msg); |
| 73 |
|
| 74 |
for (li = candidates->next; li != candidates; li = li->next) { |
| 75 |
struct rtd_candidate *c = (struct rtd_candidate *) li; |
| 76 |
LOG_D("[dbg_rt] %d -\t%s", c->score, c->diamid); |
| 77 |
} |
| 78 |
|
| 79 |
return 0; |
| 80 |
} |
| 81 |
|
| 82 |
/* Register the callbacks to the daemon */ |
| 83 |
static int dbgrt_main(char * conffile) |
| 84 |
{ |
| 85 |
TRACE_ENTRY("%p", conffile); |
| 86 |
|
| 87 |
CHECK_FCT( fd_rt_fwd_register ( dbgrt_fwd_cb, NULL, RT_FWD_ALL, &fwd_hdl ) ); |
| 88 |
CHECK_FCT( fd_rt_out_register ( dbgrt_out_cb, NULL, -1 /* so that it is called late */, &out_hdl ) ); |
| 89 |
|
| 90 |
return 0; |
| 91 |
} |
| 92 |
|
| 93 |
/* Cleanup the callbacks */ |
| 94 |
void fd_ext_fini(void) |
| 95 |
{ |
| 96 |
TRACE_ENTRY(); |
| 97 |
|
| 98 |
/* Unregister the modules */ |
| 99 |
CHECK_FCT_DO( fd_rt_fwd_unregister ( fwd_hdl, NULL ), /* continue */ ); |
| 100 |
CHECK_FCT_DO( fd_rt_out_unregister ( out_hdl, NULL ), /* continue */ ); |
| 101 |
|
| 102 |
return ; |
| 103 |
} |
| 104 |
|
| 105 |
/* Define the entry point function */ |
| 106 |
EXTENSION_ENTRY("dbg_rt", dbgrt_main); |