comparison extensions/app_radgw/rgwx_debug.c @ 255:cb4307a1cd29

Added two plugins for RADIUS/Diameter gateway debug.
author Sebastien Decugis <sdecugis@nict.go.jp>
date Thu, 15 Apr 2010 11:56:32 +0900
parents
children 042af0000c0a
comparison
equal deleted inserted replaced
254:a857024cb48b 255:cb4307a1cd29
1 /*********************************************************************************************************
2 * Software License Agreement (BSD License) *
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
4 * *
5 * Copyright (c) 2009, 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 /* Debug plugin for app_radgw */
37
38 #include "rgw_common.h"
39
40 struct rgwp_config {
41 char * confstring;
42 };
43
44 /* The function called at plugin initialization */
45 static struct rgwp_config * debug_conf_parse ( char * conf_file )
46 {
47 struct rgwp_config * ret = NULL;
48
49 TRACE_ENTRY("%p", conf_file);
50
51 CHECK_MALLOC_DO( ret = malloc(sizeof(struct rgwp_config)), return NULL );
52
53 ret->confstring = conf_file;
54
55 return ret;
56 }
57
58 /* This function is called when the plugin is unloaded, to cleanup all the states */
59 static void debug_conf_free(struct rgwp_config * cs)
60 {
61 TRACE_ENTRY("%p", cs);
62 CHECK_PARAMS_DO( cs, );
63 free(cs);
64 return;
65 }
66
67 /* Function to display the content of a RADIUS message (more friendly way than radius_msg_dump) */
68 static void debug_dump_radius(struct radius_msg *msg)
69 {
70 unsigned char *auth;
71 size_t i;
72
73 auth = &(msg->hdr->authenticator[0]);
74 fd_log_debug(" id : 0x%02hhx, code: %hhd (%s)\n", msg->hdr->identifier, msg->hdr->code, rgw_msg_code_str(msg->hdr->code));
75 fd_log_debug(" auth: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx\n",
76 auth[0], auth[1], auth[2], auth[3],
77 auth[4], auth[5], auth[6], auth[7]);
78 fd_log_debug(" %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx\n",
79 auth[8], auth[9], auth[10], auth[11],
80 auth[12], auth[13], auth[14], auth[15]);
81 for (i = 0; i < msg->attr_used; i++) {
82 struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->buf + msg->attr_pos[i]);
83 fd_log_debug(" - len:%3hhu, type:0x%02hhx (%s)\n", attr->length, attr->type, rgw_msg_attrtype_str(attr->type));
84 /* If we need to dump the value, it's better to call directly radius_msg_dump instead... */
85 }
86 }
87
88 /* Function called when a new RADIUS message is being converted to Diameter */
89 static int debug_rad_req( struct rgwp_config * cs, struct session * session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
90 {
91 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);
92
93 fd_log_debug("------------- RADIUS/Diameter Request Debug%s%s%s -------------\n", cs->confstring ? " [" : "", cs->confstring ?: "", cs->confstring ? "]" : "");
94
95 if (!rad_req) {
96 fd_log_debug(" RADIUS request: NULL pointer\n");
97 } else {
98 fd_log_debug(" RADIUS request (%p) DUMP:\n", rad_req);
99 debug_dump_radius(rad_req);
100 }
101
102 if (!rad_ans || ! *rad_ans) {
103 fd_log_debug(" RADIUS answer: NULL pointer\n");
104 } else {
105 fd_log_debug(" RADIUS answer (%p) DUMP:\n", *rad_ans);
106 debug_dump_radius(*rad_ans);
107 }
108
109 if (!diam_fw || ! *diam_fw) {
110 fd_log_debug(" Diameter message: NULL pointer\n");
111 } else {
112 fd_log_debug(" Diameter message (%p) DUMP:\n", *diam_fw);
113 fd_msg_dump_walk(0, *diam_fw);
114 }
115
116 fd_log_debug("=========== Debug%s%s%s complete =============\n", cs->confstring ? " [" : "", cs->confstring ?: "", cs->confstring ? "]" : "");
117
118 return 0;
119 }
120
121 /* This one, when Diameter answer is converted to RADIUS */
122 static int debug_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli )
123 {
124 TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli);
125
126 fd_log_debug("------------- RADIUS/Diameter Answer Debug%s%s%s -------------\n", cs->confstring ? " [" : "", cs->confstring ?: "", cs->confstring ? "]" : "");
127
128 if (!diam_ans || ! *diam_ans) {
129 fd_log_debug(" Diameter message: NULL pointer\n");
130 } else {
131 fd_log_debug(" Diameter message (%p) DUMP:\n", *diam_ans);
132 fd_msg_dump_walk(0, *diam_ans);
133 }
134
135 if (!rad_fw || ! *rad_fw) {
136 fd_log_debug(" RADIUS answer: NULL pointer\n");
137 } else {
138 fd_log_debug(" RADIUS answer (%p) DUMP:\n", *rad_fw);
139 debug_dump_radius(*rad_fw);
140 }
141
142 fd_log_debug("=========== Debug%s%s%s complete =============\n", cs->confstring ? " [" : "", cs->confstring ?: "", cs->confstring ? "]" : "");
143 return 0;
144 }
145
146
147 /* The exported symbol */
148 struct rgw_api rgwp_descriptor = {
149 debug_conf_parse,
150 debug_conf_free,
151 debug_rad_req,
152 debug_diam_ans
153 };
"Welcome to our mercurial repository"