Navigation


Changeset 550:4c935aecee6c in freeDiameter for extensions/app_radgw/rgw_msg.c


Ignore:
Timestamp:
Sep 15, 2010, 2:24:45 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Hide and automate the Proxy-State attributes management in RADIUS gateway

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_radgw/rgw_msg.c

    r518 r550  
    1 /*********************************************************************************************************
    2 * Software License Agreement (BSD License)                                                               *
    3 * Author: Sebastien Decugis <sdecugis@nict.go.jp>                                                        *
    4 *                                                                                                        *
    5 * Copyright (c) 2010, 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 /* This file contains all support functions to parse, create, and manipulate RADIUS messages. Other
    37 modules do not need to "know" the actual representation of RADIUS messages on the network. They only
    38 receive the logical view as exposed in the rgw.h file. This file extends the content of the radius.c
    39 file functions (from hostap project).*/
    40 
    41 #include "rgw.h"
    42 
    43 /* Destroy a message */
    44 void rgw_msg_free(struct rgw_radius_msg_meta ** msg)
    45 {
    46         if (!msg || !*msg)
    47                 return;
    48        
    49         radius_msg_free(&(*msg)->radius);
    50         free(*msg);
    51         *msg = NULL;
    52 }
    53 
    54 /* This function creates a rgw_radius_msg_meta structure after parsing a RADIUS buffer */
    55 int rgw_msg_parse(unsigned char * buf, size_t len, struct rgw_radius_msg_meta ** msg)
    56 {
    57         struct radius_msg * temp_msg = NULL;
    58        
    59         TRACE_ENTRY("%p %g %p", buf, len, msg);
    60        
    61         CHECK_PARAMS( buf && len && msg );
    62        
    63         *msg = NULL;
    64        
    65         /* Parse the RADIUS message */
    66         temp_msg = radius_msg_parse(buf, len);
    67         if (temp_msg == NULL) {
    68                 TRACE_DEBUG(INFO, "Error parsing the RADIUS message, discarding");
    69                 return EINVAL;
    70         }
    71        
    72         /* Now alloc space for the meta-data */
    73         CHECK_MALLOC( *msg = realloc(temp_msg, sizeof(struct rgw_radius_msg_meta)) );
    74        
    75         /* Clear memory after the parsed data */
    76         memset( &(*msg)->radius + 1, 0, sizeof(struct rgw_radius_msg_meta) - sizeof(struct radius_msg) );
    77        
    78         return 0;
    79 }
    80 
    81 /* Dump a message (inspired from radius_msg_dump) -- can be used safely with a struct radius_msg as parameter (we don't dump the metadata) */
    82 void rgw_msg_dump(struct rgw_radius_msg_meta * msg)
    83 {
    84         unsigned char *auth;
    85         size_t i;
    86         if (! TRACE_BOOL(FULL) )
    87                 return;
    88        
    89         auth =  &(msg->radius.hdr->authenticator[0]);
    90        
    91         fd_log_debug("------ RADIUS msg dump -------\n");
    92         fd_log_debug(" id  : 0x%02hhx, code : %hhd (%s)\n", msg->radius.hdr->identifier, msg->radius.hdr->code, rgw_msg_code_str(msg->radius.hdr->code));
    93         fd_log_debug(" auth: %02hhx %02hhx %02hhx %02hhx  %02hhx %02hhx %02hhx %02hhx\n",
    94                         auth[0], auth[1], auth[2], auth[3],
    95                         auth[4], auth[5], auth[6], auth[7]);
    96         fd_log_debug("       %02hhx %02hhx %02hhx %02hhx  %02hhx %02hhx %02hhx %02hhx\n",
    97                         auth[8],  auth[9],  auth[10], auth[11],
    98                         auth[12], auth[13], auth[14], auth[15]);
    99         for (i = 0; i < msg->radius.attr_used; i++) {
    100                 struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[i]);
    101                 fd_log_debug("    - Type: 0x%02hhx (%s)\n       Len: %-3hhu", attr->type, rgw_msg_attrtype_str(attr->type), attr->length);
    102                 radius_msg_dump_attr_val(attr);
    103         }
    104         fd_log_debug("-----------------------------\n");
    105 }
    106 
Note: See TracChangeset for help on using the changeset viewer.