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