view extensions/radius_gw/radius_gw.h @ 350:c47a045fd4d6

Commit before the golden week
author Sebastien Decugis <sdecugis@nict.go.jp>
date Fri, 01 May 2009 18:29:27 +0900
parents 7907e7cc0aef
children 6d22078428a5
line wrap: on
line source

/*********************************************************************************************************
* Software License Agreement (BSD License)                                                               *
* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
*													 *
* Copyright (c) 2008, 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.								 *
*********************************************************************************************************/
/* This file contains the description of the API between the base radius_gw extension and
  its extensions that add support for specific RADIUS attributes and/or commands.
  The "notes.txt" file contains the basic mechanism for use of this API. */
  
#ifndef _RADIUS_GW_H
#define _RADIUS_GW_H

/* This file extends definitions from the standard waaad API */
#include <waaad/waaad.h>

/* This type is used for all lists in this extension */
struct rgw_list {
	struct rgw_list *next;
	struct rgw_list *prev;
	struct rgw_list *head;
};

/**************************************************************/
/*                  RADIUS messages                           */
/**************************************************************/

/* Note on design: the parsing of RADIUS message is not very efficient since we have to duplicate the memory of all
 attributes, instead of pointing back to them in the original message. Anyway, it makes adding / removing attributes simpler. */

/* This type describes a RADIUS attribute */
struct rad_attr {
	/* Meta data */
	struct rgw_list	chain;	/* link this attribute in a message */
	int		handled; /* Has this attribute already been converted to Diameter? */
	
	/* Data */
	uint8_t		type;
	uint8_t		length;
	union 	{
		uint8_t	buf[253];
		struct {
			uint32_t	vendor_id;
			union {
				uint8_t	string[249];			/* generic format */
				struct {
					uint8_t	vendor_type;
					uint8_t	vendor_length;
					uint8_t vendor_value[247];
				} 	tlv;				/* TLV format defined in rfc2865#section-5.26 */
				struct {
					unsigned	m 	:1;
					unsigned	tag	:7;
					uint8_t		data[248];
				} radext;				/* Extended attributes defined in draft-ietf-radext-extended-attributes-08 */
			};
		} 	vsa; /* vendor-specific attributes */
	}		data; /* Always fits in 253 bytes */
};
	

/* The following type represents a complete RADIUS message (internal representation) with parsing information */
typedef struct _rad_t {
	/* Metadata */
	struct rgw_list	attributes;	/* The list of attributes */
		
	/* Data */
	uint8_t		code;
	uint8_t		identifier;
	uint16_t	length;		/* always stored in host byte-order */
	uint8_t		authenticator[16];
} rad_t;


/**************************************************************/
/*                  Extensions registration                   */
/**************************************************************/

#define RADIUS_GW_API_VER	1 /* increment when making changes to radius_gw_api definition bellow */
struct radius_gw_api {
	void *  (*rga_conf_parse_cb) ( char * conf_file );	/* configuration parser. Returns NULL on error only */
	void	(*rga_conf_free_cb) (void * conf); 		/* Free an object returned by previous cb */
	
	int	(*rga_rad_req_cb) ( void * conf, sess_id_t ** session, rad_t ** rad_req, msg_t ** diam_fw ); /* handle an incoming RADIUS message */
	int	(*rga_diam_ans_cb) ( void * conf, sess_id_t ** session, msg_t ** diam_and, rad_t ** rad_fw ); /* handle the corresponding Diameter answer */
};

/* All extensions must provide the following entry point that is called when the extension is loaded.
Beware, the same extension may be loaded several times, and receive different configuration files. 
No global data should be initialized during this function; instead it should be done during the rga_conf_parse_cb call,
and store in the memory pointed by "conf" that is passed in turn to all callbacks. */
extern int rga_register(int version, struct radius_gw_api * api);



/**************************************************************/
/*      Functions exported by the radius_gw extension         */
/**************************************************************/

/* List management */

/* and so on ... */




#endif /* _RADIUS_GW_H */
  
"Welcome to our mercurial repository"