Mercurial > hg > waaad
view extensions/radius_gw/sub_acct.c @ 403:bcc13af0825a
Improved initialization message
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 03 Jun 2009 18:14:17 +0900 |
parents | f63adc1b3e99 |
children | 3a8e91184d4d |
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. * *********************************************************************************************************/ /* Sub extension for handling RADIUS Accounting-Request messages */ #define IN_EXTENSION #define DEFINE_DEBUG_MACRO sub_acct #define DECLARE_API_POINTERS #include <waaad/waaad.h> #include "rg_common.h" #ifndef SUB_ACCT_VERBO #define SUB_ACCT_VERBO 0 #endif /* SUB_ACCT_VERBO */ int sub_acct_verbosity = SUB_ACCT_VERBO; struct rga_conf_state { char * conffile; }; static struct rga_conf_state * acct_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)); cs->conffile = conffile; if (conffile) { TRACE_DEBUG(INFO, "Sub extension Accounting (RFC2866) initialized with configuration: '%s'", cs->conffile); } else { TRACE_DEBUG(INFO, "Sub extension Accounting (RFC2866) initialized with default configuration"); } return cs; } static void acct_conf_free(struct rga_conf_state * cs) { TRACE_ENTRY("%p", cs); CHECK_PARAMS_DO( cs, ); free(cs); return; } static int acct_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 ) { int idx; int got_id = 0; uint32_t status_type; TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli); CHECK_PARAMS(rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCOUNTING_REQUEST) && rad_ans && diam_fw && *diam_fw); /* Check the message contains the NAS idnetification */ for (idx = 0; idx < rad_req->attr_used; idx++) { struct radius_attr_hdr * attr = (struct radius_attr_hdr *)(rad_req->buf + rad_req->attr_pos[idx]); switch (attr->type) { case RADIUS_ATTR_NAS_IP_ADDRESS: case RADIUS_ATTR_NAS_IDENTIFIER: case RADIUS_ATTR_NAS_IPV6_ADDRESS: got_id = 1; break; } } /* Check basic information is there */ if (!got_id || radius_msg_get_attr_int32(rad_req, RADIUS_ATTR_ACCT_STATUS_TYPE, &status_type)) { TRACE_DEBUG(INFO, "RADIUS Account-Request did not contain a NAS ip/identifier or Acct-Status-Type attribute, reject."); return EINVAL; } /* Handle the Accounting-On case: nothing to do, just reply OK, since Diameter does not support this */ if (status_type == RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_ON) { TRACE_DEBUG(FULL, "Received Accounting-On Acct-Status-Type attribute, replying directly."); CHECK_MALLOC( *rad_ans = radius_msg_new(RADIUS_CODE_ACCOUNTING_RESPONSE, rad_req->hdr->identifier) ); return -3; } return ENOTSUP; } static int acct_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); return ENOTSUP; } 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_acct", waaad_api ); /* Initialize the radius_gw api callbacks */ api->rga_conf_parse_cb = acct_conf_parse; api->rga_conf_free_cb = acct_conf_free; api->rga_rad_req_cb = acct_rad_req; api->rga_diam_ans_cb = acct_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; }