Mercurial > hg > freeDiameter
changeset 82:b6344f1d521a
Some cleanups
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 02 Dec 2009 14:20:38 +0900 |
parents | 66a00b701f02 |
children | c662d3eb6ff6 |
files | freeDiameter/CMakeLists.txt freeDiameter/events.c freeDiameter/fD.h freeDiameter/main.c freeDiameter/routing.c include/freeDiameter/freeDiameter.h |
diffstat | 6 files changed, 197 insertions(+), 131 deletions(-) [+] |
line wrap: on
line diff
--- a/freeDiameter/CMakeLists.txt Wed Dec 02 14:06:05 2009 +0900 +++ b/freeDiameter/CMakeLists.txt Wed Dec 02 14:20:38 2009 +0900 @@ -15,6 +15,7 @@ cnxctx.c dispatch.c endpoints.c + events.c extensions.c dict_base_proto.c messages.c @@ -28,6 +29,7 @@ p_out.c p_psm.c p_sr.c + routing.c server.c tcp.c )
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/freeDiameter/events.c Wed Dec 02 14:20:38 2009 +0900 @@ -0,0 +1,118 @@ +/********************************************************************************************************* +* 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. * +*********************************************************************************************************/ + +#include "fD.h" + +int fd_event_send(struct fifo *queue, int code, size_t datasz, void * data) +{ + struct fd_event * ev; + CHECK_MALLOC( ev = malloc(sizeof(struct fd_event)) ); + ev->code = code; + ev->size = datasz; + ev->data = data; + CHECK_FCT( fd_fifo_post(queue, &ev) ); + return 0; +} + +int fd_event_get(struct fifo *queue, int *code, size_t *datasz, void ** data) +{ + struct fd_event * ev; + CHECK_FCT( fd_fifo_get(queue, &ev) ); + if (code) + *code = ev->code; + if (datasz) + *datasz = ev->size; + if (data) + *data = ev->data; + free(ev); + return 0; +} + +int fd_event_timedget(struct fifo *queue, struct timespec * timeout, int timeoutcode, int *code, size_t *datasz, void ** data) +{ + struct fd_event * ev; + int ret = 0; + ret = fd_fifo_timedget(queue, &ev, timeout); + if (ret == ETIMEDOUT) { + if (code) + *code = timeoutcode; + if (datasz) + *datasz = 0; + if (data) + *data = NULL; + } else { + CHECK_FCT( ret ); + if (code) + *code = ev->code; + if (datasz) + *datasz = ev->size; + if (data) + *data = ev->data; + free(ev); + } + return 0; +} + +void fd_event_destroy(struct fifo **queue, void (*free_cb)(void * data)) +{ + struct fd_event * ev; + /* Purge all events, and free the associated data if any */ + while (fd_fifo_tryget( *queue, &ev ) == 0) { + (*free_cb)(ev->data); + free(ev); + } + CHECK_FCT_DO( fd_fifo_del(queue), /* continue */ ); + return ; +} + +const char * fd_ev_str(int event) +{ + switch (event) { + #define case_str( _val )\ + case _val : return #_val + case_str(FDEV_TERMINATE); + case_str(FDEV_DUMP_DICT); + case_str(FDEV_DUMP_EXT); + case_str(FDEV_DUMP_SERV); + case_str(FDEV_DUMP_QUEUES); + case_str(FDEV_DUMP_CONFIG); + case_str(FDEV_DUMP_PEERS); + + default: + TRACE_DEBUG(FULL, "Unknown event : %d", event); + return "Unknown event"; + } +} +
--- a/freeDiameter/fD.h Wed Dec 02 14:06:05 2009 +0900 +++ b/freeDiameter/fD.h Wed Dec 02 14:20:38 2009 +0900 @@ -104,6 +104,10 @@ /* Create all the dictionary objects defined in the Diameter base RFC. */ int fd_dict_base_protocol(struct dictionary * dict); +/* Routing */ +int fd_rt_init(void); +int fd_rt_fini(void); + /* Sentinel for the sent requests list */ struct sr_list { struct fd_list srs;
--- a/freeDiameter/main.c Wed Dec 02 14:06:05 2009 +0900 +++ b/freeDiameter/main.c Wed Dec 02 14:20:38 2009 +0900 @@ -99,6 +99,7 @@ CHECK_FCT( fd_queues_init() ); CHECK_FCT( fd_msg_init() ); CHECK_FCT( fd_p_expi_init() ); + CHECK_FCT( fd_rt_init() ); /* Parse the configuration file */ CHECK_FCT( fd_conf_parse() ); @@ -173,25 +174,6 @@ return ret; } -const char * fd_ev_str(int event) -{ - switch (event) { - #define case_str( _val )\ - case _val : return #_val - case_str(FDEV_TERMINATE); - case_str(FDEV_DUMP_DICT); - case_str(FDEV_DUMP_EXT); - case_str(FDEV_DUMP_SERV); - case_str(FDEV_DUMP_QUEUES); - case_str(FDEV_DUMP_CONFIG); - case_str(FDEV_DUMP_PEERS); - - default: - TRACE_DEBUG(FULL, "Unknown event : %d", event); - return "Unknown event"; - } -} - /* Parse the command-line */ static int main_cmdline(int argc, char *argv[]) {
--- a/freeDiameter/routing.c Wed Dec 02 14:06:05 2009 +0900 +++ b/freeDiameter/routing.c Wed Dec 02 14:20:38 2009 +0900 @@ -39,3 +39,15 @@ (draft-ietf-dime-nai-routing-04 section 4.4) */ /* Note2: if the message is still for local delivery, we should test for duplicate (draft-asveren-dime-dupcons-00). This may conflict with path validation decisions, no clear answer yet */ + +/* Initialize the routing module */ +int fd_rt_init(void) +{ + return ENOTSUP; +} + +/* Terminate the routing module */ +int fd_rt_fini(void) +{ + return ENOTSUP; +}
--- a/include/freeDiameter/freeDiameter.h Wed Dec 02 14:06:05 2009 +0900 +++ b/include/freeDiameter/freeDiameter.h Wed Dec 02 14:20:38 2009 +0900 @@ -114,118 +114,6 @@ }; extern struct fd_config *fd_g_config; /* The pointer to access the global configuration, initalized in main */ -/* Endpoints */ -struct fd_endpoint { - struct fd_list chain; /* link in cnf_endpoints list */ - - union { - sSS ss; /* the socket information. List is always ordered by ss value (memcmp) -- see fd_ep_add_merge */ - sSA4 sin; - sSA6 sin6; - sSA sa; - }; - -#define EP_FL_CONF (1 << 0) /* This endpoint is statically configured in a configuration file */ -#define EP_FL_DISC (1 << 1) /* This endpoint was resolved from the Diameter Identity or other DNS query */ -#define EP_FL_ADV (1 << 2) /* This endpoint was advertized in Diameter CER/CEA exchange */ -#define EP_FL_LL (1 << 3) /* Lower layer mechanism provided this endpoint */ -#define EP_FL_PRIMARY (1 << 4) /* This endpoint is primary in a multihomed SCTP association */ - uint32_t flags; /* Additional information about the endpoint */ - - /* To add: a validity timestamp for DNS records ? How do we retrieve this lifetime from DNS ? */ -}; - -/* Applications */ -struct fd_app { - struct fd_list chain; /* link in cnf_apps list. List ordered by appid. */ - struct { - unsigned auth : 1; - unsigned acct : 1; - unsigned common : 1; - } flags; - vendor_id_t vndid; /* if not 0, Vendor-Specific-App-Id AVP will be used */ - application_id_t appid; /* The identifier of the application */ -}; - - -/* Events */ -struct fd_event { - int code; /* codespace depends on the queue */ - size_t size; - void *data; -}; - -/* Daemon's codespace: 1000->1999 */ -enum { - FDEV_TERMINATE = 1000 /* request to terminate */ - ,FDEV_DUMP_DICT /* Dump the content of the dictionary */ - ,FDEV_DUMP_EXT /* Dump state of extensions */ - ,FDEV_DUMP_SERV /* Dump the server socket status */ - ,FDEV_DUMP_QUEUES /* Dump the message queues */ - ,FDEV_DUMP_CONFIG /* Dump the configuration */ - ,FDEV_DUMP_PEERS /* Dump the list of peers */ -}; - -static __inline__ int fd_event_send(struct fifo *queue, int code, size_t datasz, void * data) -{ - struct fd_event * ev; - CHECK_MALLOC( ev = malloc(sizeof(struct fd_event)) ); - ev->code = code; - ev->size = datasz; - ev->data = data; - CHECK_FCT( fd_fifo_post(queue, &ev) ); - return 0; -} -static __inline__ int fd_event_get(struct fifo *queue, int *code, size_t *datasz, void ** data) -{ - struct fd_event * ev; - CHECK_FCT( fd_fifo_get(queue, &ev) ); - if (code) - *code = ev->code; - if (datasz) - *datasz = ev->size; - if (data) - *data = ev->data; - free(ev); - return 0; -} -static __inline__ int fd_event_timedget(struct fifo *queue, struct timespec * timeout, int timeoutcode, int *code, size_t *datasz, void ** data) -{ - struct fd_event * ev; - int ret = 0; - ret = fd_fifo_timedget(queue, &ev, timeout); - if (ret == ETIMEDOUT) { - if (code) - *code = timeoutcode; - if (datasz) - *datasz = 0; - if (data) - *data = NULL; - } else { - CHECK_FCT( ret ); - if (code) - *code = ev->code; - if (datasz) - *datasz = ev->size; - if (data) - *data = ev->data; - free(ev); - } - return 0; -} -static __inline__ void fd_event_destroy(struct fifo **queue, void (*free_cb)(void * data)) -{ - struct fd_event * ev; - /* Purge all events, and free the associated data if any */ - while (fd_fifo_tryget( *queue, &ev ) == 0) { - (*free_cb)(ev->data); - free(ev); - } - CHECK_FCT_DO( fd_fifo_del(queue), /* continue */ ); - return ; -} -const char * fd_ev_str(int event); /* defined in freeDiameter/main.c */ - /***************************************/ /* Peers information */ @@ -538,9 +426,58 @@ /***************************************/ +/* Events helpers */ +/***************************************/ + +/* Events */ +struct fd_event { + int code; /* codespace depends on the queue */ + size_t size; + void *data; +}; + +/* Daemon's codespace: 1000->1999 */ +enum { + FDEV_TERMINATE = 1000 /* request to terminate */ + ,FDEV_DUMP_DICT /* Dump the content of the dictionary */ + ,FDEV_DUMP_EXT /* Dump state of extensions */ + ,FDEV_DUMP_SERV /* Dump the server socket status */ + ,FDEV_DUMP_QUEUES /* Dump the message queues */ + ,FDEV_DUMP_CONFIG /* Dump the configuration */ + ,FDEV_DUMP_PEERS /* Dump the list of peers */ +}; + +int fd_event_send(struct fifo *queue, int code, size_t datasz, void * data); +int fd_event_get(struct fifo *queue, int *code, size_t *datasz, void ** data); +int fd_event_timedget(struct fifo *queue, struct timespec * timeout, int timeoutcode, int *code, size_t *datasz, void ** data); +void fd_event_destroy(struct fifo **queue, void (*free_cb)(void * data)); +const char * fd_ev_str(int event); + + +/***************************************/ /* Endpoints lists helpers */ /***************************************/ +struct fd_endpoint { + struct fd_list chain; /* link in cnf_endpoints list */ + + union { + sSS ss; /* the socket information. List is always ordered by ss value (memcmp) -- see fd_ep_add_merge */ + sSA4 sin; + sSA6 sin6; + sSA sa; + }; + +#define EP_FL_CONF (1 << 0) /* This endpoint is statically configured in a configuration file */ +#define EP_FL_DISC (1 << 1) /* This endpoint was resolved from the Diameter Identity or other DNS query */ +#define EP_FL_ADV (1 << 2) /* This endpoint was advertized in Diameter CER/CEA exchange */ +#define EP_FL_LL (1 << 3) /* Lower layer mechanism provided this endpoint */ +#define EP_FL_PRIMARY (1 << 4) /* This endpoint is primary in a multihomed SCTP association */ + uint32_t flags; /* Additional information about the endpoint */ + + /* To add: a validity timestamp for DNS records ? How do we retrieve this lifetime from DNS ? */ +}; + int fd_ep_add_merge( struct fd_list * list, sSA * sa, socklen_t sl, uint32_t flags ); int fd_ep_filter( struct fd_list * list, uint32_t flags ); int fd_ep_filter_family( struct fd_list * list, int af ); @@ -552,6 +489,17 @@ /* Applications lists helpers */ /***************************************/ +struct fd_app { + struct fd_list chain; /* link in cnf_apps list. List ordered by appid. */ + struct { + unsigned auth : 1; + unsigned acct : 1; + unsigned common : 1; + } flags; + vendor_id_t vndid; /* if not 0, Vendor-Specific-App-Id AVP will be used */ + application_id_t appid; /* The identifier of the application */ +}; + int fd_app_merge(struct fd_list * list, application_id_t aid, vendor_id_t vid, int auth, int acct); int fd_app_find_common(struct fd_list * target, struct fd_list * reference); int fd_app_gotcommon(struct fd_list * apps);