blob: 282b02869e1a5ebf0b91910e60733ce1d826a853 [file] [log] [blame]
Brian Waters13d96012017-12-08 16:53:31 -06001/*********************************************************************************************************
2* Software License Agreement (BSD License) *
3* Author: Sebastien Decugis <sdecugis@freediameter.net> *
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/* Debug plugin for app_radgw */
37
38#include "rgw_common.h"
39
40/* Store the configuration string in the state */
41static int debug_conf_parse ( char * conf_file, struct rgwp_config ** state )
42{
43 TRACE_ENTRY("%p %p", conf_file, state);
44 CHECK_PARAMS(state);
45
46 *state = (void *)conf_file;
47
48 return 0;
49}
50
51
52/* Function to display the content of a RADIUS message (more friendly way than radius_msg_dump) */
53static void debug_dump_radius(struct radius_msg *msg)
54{
55 unsigned char *auth;
56 size_t i;
57
58 auth = &(msg->hdr->authenticator[0]);
59 fd_log_debug(" id : 0x%02hhx, code: %hhd (%s)", msg->hdr->identifier, msg->hdr->code, rgw_msg_code_str(msg->hdr->code));
60 fd_log_debug(" auth: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx",
61 auth[0], auth[1], auth[2], auth[3],
62 auth[4], auth[5], auth[6], auth[7]);
63 fd_log_debug(" %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx",
64 auth[8], auth[9], auth[10], auth[11],
65 auth[12], auth[13], auth[14], auth[15]);
66 for (i = 0; i < msg->attr_used; i++) {
67 struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->buf + msg->attr_pos[i]);
68 fd_log_debug(" - len:%3hhu, type:0x%02hhx (%s)", attr->length, attr->type, rgw_msg_attrtype_str(attr->type));
69 /* If we need to dump the value, it's better to call directly radius_msg_dump instead... */
70 }
71}
72
73/* Function called when a new RADIUS message is being converted to Diameter */
74static int debug_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
75{
76 TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli);
77
78 fd_log_debug("------------- RADIUS/Diameter Request Debug%s%s%s -------------", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : "");
79
80 if (!rad_req) {
81 fd_log_debug(" RADIUS request: NULL pointer");
82 } else {
83 fd_log_debug(" RADIUS request (%p) DUMP:", rad_req);
84 debug_dump_radius(rad_req);
85 }
86
87 if (!rad_ans || ! *rad_ans) {
88 fd_log_debug(" RADIUS answer: NULL pointer");
89 } else {
90 fd_log_debug(" RADIUS answer (%p) DUMP:", *rad_ans);
91 debug_dump_radius(*rad_ans);
92 }
93
94 if (!diam_fw || ! *diam_fw) {
95 fd_log_debug(" Diameter message: NULL pointer");
96 } else {
97 char * buf = NULL; size_t buflen;
98 CHECK_MALLOC( fd_msg_dump_treeview(&buf, &buflen, NULL, *diam_fw, NULL, 0, 1) );
99 fd_log_debug(" Diameter message (%p) DUMP: %s", *diam_fw, buf);
100 free(buf);
101 }
102
103 fd_log_debug("=========== Debug%s%s%s complete =============", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : "");
104
105 return 0;
106}
107
108/* This one, when Diameter answer is converted to RADIUS */
109static int debug_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli )
110{
111 TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli);
112
113 fd_log_debug("------------- RADIUS/Diameter Answer Debug%s%s%s -------------", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : "");
114
115 if (!diam_ans || ! *diam_ans) {
116 fd_log_debug(" Diameter message: NULL pointer");
117 } else {
118 char * buf = NULL; size_t buflen;
119 CHECK_MALLOC( fd_msg_dump_treeview(&buf, &buflen, NULL, *diam_ans, NULL, 0, 1) );
120 fd_log_debug(" Diameter message (%p) DUMP: %s", *diam_ans, buf);
121 free(buf);
122 }
123
124 if (!rad_fw || ! *rad_fw) {
125 fd_log_debug(" RADIUS answer: NULL pointer");
126 } else {
127 fd_log_debug(" RADIUS answer (%p) DUMP:", *rad_fw);
128 debug_dump_radius(*rad_fw);
129 }
130
131 fd_log_debug("=========== Debug%s%s%s complete =============", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : "");
132 return 0;
133}
134
135
136/* The exported symbol */
137struct rgw_api rgwp_descriptor = {
138 .rgwp_name = "debug",
139 .rgwp_conf_parse = debug_conf_parse,
140 .rgwp_conf_free = NULL,
141 .rgwp_rad_req = debug_rad_req,
142 .rgwp_diam_ans = debug_diam_ans
143};