Mercurial > hg > waaad
view extensions/radius_gw/sub_debug.c @ 406:3a8e91184d4d
Added code to handle RADIUS client deconnection
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 10 Jun 2009 15:33:26 +0900 |
parents | 03b512313cc1 |
children | 540ed390c04f |
line wrap: on
line source
/********************************************************************************************************* * Software License Agreement (BSD License) * * Author: Sebastien Decugis <sdecugis@nict.go.jp> * * * * Copyright (c) 2009, 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. * *********************************************************************************************************/ /* Debug sub extension for radius_gw */ #define IN_EXTENSION #define DEFINE_DEBUG_MACRO sub_debug #define DECLARE_API_POINTERS #include <waaad/waaad.h> #include "rg_common.h" int sub_debug_verbosity = 2; struct rga_conf_state { char * conffile; void * waaad_handle; void (*waaad_msg_dump_walk)( int level, void * obj ); }; static struct rga_conf_state * debug_conf_parse(char * conffile) { struct rga_conf_state * cs; TRACE_ENTRY("%p", conffile); CHECK_MALLOC_DO( cs = malloc(sizeof(struct rga_conf_state)), return NULL ); memset(cs, 0, sizeof(struct rga_conf_state)); if (conffile) cs->conffile = conffile; else cs->conffile = "-"; /* Resolve the msg_dump_walk function from main waaad image */ CHECK_FCT_DO( rg_pointers_init(&cs->waaad_handle), return NULL ); rg_pointers_resolve(cs->waaad_msg_dump_walk, cs->waaad_handle, "msg_dump_walk", NULL); TRACE_DEBUG(INFO, "Sub extension Debug initialized with id: '%s'", cs->conffile); return cs; } static void debug_conf_free(struct rga_conf_state * cs) { TRACE_ENTRY("%p", cs); CHECK_PARAMS_DO(cs, return); rg_pointers_fini(&cs->waaad_handle); free(cs); return; } #include "rgw_msg_attrtype.c" #include "rgw_msg_codes.c" static void debug_dump_radius(struct radius_msg *msg) { unsigned char *auth; size_t i; auth = &(msg->hdr->authenticator[0]); log_debug(" --- Dump method 1:\n"); log_debug(" id : 0x%02hhx, code: %hhd (%s)\n", msg->hdr->identifier, msg->hdr->code, rgw_msg_code_str(msg->hdr->code)); log_debug(" auth: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx\n", auth[0], auth[1], auth[2], auth[3], auth[4], auth[5], auth[6], auth[7]); log_debug(" %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx\n", auth[8], auth[9], auth[10], auth[11], auth[12], auth[13], auth[14], auth[15]); for (i = 0; i < msg->attr_used; i++) { struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->buf + msg->attr_pos[i]); log_debug(" - len:%3hhd, type:0x%02hhx (%s)\n", attr->length, attr->type, rgw_msg_attrtype_str(attr->type)); /* If we need to dump the value, it's better to call directly radius_msg_dump instead... */ } log_debug(" --- Dump method 2:\n"); radius_msg_dump(msg); } static int debug_rad_req(struct rga_conf_state * cs, sess_id_t ** session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, msg_t ** diam_fw, void * cli ) { TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli); log_debug("sub_debug ( c:'%s' ) state dump start for incoming RADIUS message (session: %p->%p)\n", cs->conffile, session, session?*session:NULL); if (!rad_req) { log_debug(" RADIUS request: NULL pointer\n"); } else { log_debug(" RADIUS request (%p) DUMP:\n", rad_req); debug_dump_radius(rad_req); } if (!rad_ans || ! *rad_ans) { log_debug(" RADIUS answer: NULL pointer\n"); } else { log_debug(" RADIUS answer (%p) DUMP:\n", *rad_ans); debug_dump_radius(*rad_ans); } if (!diam_fw || ! *diam_fw) { log_debug(" Diameter message: NULL pointer\n"); } else { log_debug(" Diameter message (%p) DUMP:\n", *diam_fw); (*cs->waaad_msg_dump_walk)(0, *diam_fw); } log_debug("sub_debug ( c:'%s' ) state dump complete\n", cs->conffile); return 0; } static int debug_diam_ans(struct rga_conf_state * cs, sess_id_t ** session, msg_t ** diam_ans, struct radius_msg ** rad_fw, void * cli ) { TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli); CHECK_PARAMS(cs); log_debug("sub_debug ( c:'%s' ) state dump start for incoming Diameter answer (session: %p->%p)\n", cs->conffile, session, session?*session:NULL); if (!diam_ans || ! *diam_ans) { log_debug(" Diameter message: NULL pointer\n"); } else { log_debug(" Diameter message (%p) DUMP:\n", *diam_ans); debug_dump_diameter(*diam_ans); } if (!rad_fw || ! *rad_fw) { log_debug(" RADIUS answer: NULL pointer\n"); } else { log_debug(" RADIUS answer (%p) DUMP:\n", *rad_fw); debug_dump_radius(*rad_fw); } log_debug("sub_debug ( c:'%s' ) state dump complete\n", cs->conffile); return 0; } int rga_register(int version, waaad_api_t * waaad_api, struct radius_gw_api * api) { TRACE_ENTRY("%d %p %p", version, waaad_api, api); CHECK_PARAMS( waaad_api && api ); if (version != RADIUS_GW_API_VER) { log_error("ABI version mismatch, please recompile this extension (%s)\n", __FILE__); return EINVAL; } /* Required to use the waaad api from this sub-extension: */ EXTENSION_API_INIT_INTERN( API_MODULE_ALL, "sub_debug", waaad_api ); /* Initialize the radius_gw api callbacks */ api->rga_conf_parse_cb = debug_conf_parse; api->rga_conf_free_cb = debug_conf_free; api->rga_rad_req_cb = debug_rad_req; api->rga_diam_ans_cb = debug_diam_ans; /* We're done, we must not initialize any state here since the extension must be re-entrant, but in sample_conf_parse */ return 0; }