Mercurial > hg > freeDiameter
changeset 1120:c473581adff2
Cleanup some traces
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Tue, 14 May 2013 12:32:28 +0800 |
parents | 79dd22145f52 |
children | ccbd1426e04a |
files | extensions/app_diameap/diameap.c extensions/app_diameap/diameap_server.c extensions/dbg_monitor/dbg_monitor.c extensions/dict_dcca/dict_dcca.c extensions/dict_dcca_3gpp/dict_dcca_3gpp.c extensions/dict_dcca_starent/dict_dcca_starent.c extensions/dict_eap/dict_eap.c extensions/dict_mip6a/dict_mip6a.c extensions/dict_mip6i/dict_mip6i.c extensions/dict_nas_mipv6/dict_nas_mipv6.c extensions/dict_nasreq/dict_nasreq.c extensions/dict_rfc5777/dict_rfc5777.c extensions/dict_sip/dict_sip.c extensions/test_netemul/tne_process.c include/freeDiameter/libfdcore.h include/freeDiameter/libfdproto.h libfdcore/core.c libfdcore/extensions.c libfdcore/hooks.c libfdcore/messages.c libfdcore/p_psm.c libfdcore/routing_dispatch.c libfdproto/messages.c tests/testappacct.c |
diffstat | 24 files changed, 95 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/app_diameap/diameap.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/app_diameap/diameap.c Tue May 14 12:32:28 2013 +0800 @@ -59,7 +59,7 @@ /* Announce the support of Diameter EAP Application to other peers */ CHECK_FCT(fd_disp_app_support(dataobj_diameap_app, dataobj_diameap_ven, 1, 0)); - TRACE_DEBUG(INFO,"%sDiameter EAP Application Extension started successfully.",DIAMEAP_EXTENSION); + LOG_D("%sDiameter EAP Application Extension started successfully.",DIAMEAP_EXTENSION); return 0; }
--- a/extensions/app_diameap/diameap_server.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/app_diameap/diameap_server.c Tue May 14 12:32:28 2013 +0800 @@ -3283,6 +3283,8 @@ { TRACE_DEBUG(INFO,"%s Adding EAP-Payload AVP failed.",DIAMEAP_EXTENSION); goto s_end;}) ; + LOG_N("%s Auth FAIL: %.*s",DIAMEAP_EXTENSION, diameap_sm->eap_sm.user.useridLength, diameap_sm->eap_sm.user.userid); + CHECK_FCT_DO( diameap_send(rmsg), goto s_end) ; @@ -3322,6 +3324,9 @@ CHECK_FCT_DO(diameap_add_accounting_eap_auth_method(diameap_sm, ans), { TRACE_DEBUG(INFO,"%s Adding accounting AVP failed",DIAMEAP_EXTENSION); goto s_end;}) ; + + LOG_N("%s Auth Success: %.*s",DIAMEAP_EXTENSION, diameap_sm->eap_sm.user.useridLength, diameap_sm->eap_sm.user.userid); + CHECK_FCT_DO( diameap_send(rmsg), goto s_end) ;
--- a/extensions/dbg_monitor/dbg_monitor.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/dbg_monitor/dbg_monitor.c Tue May 14 12:32:28 2013 +0800 @@ -142,7 +142,7 @@ TRACE_DEBUG(INFO, "[dbg_monitor] Dumping config information"); TRACE_DEBUG(INFO, "%s", fd_conf_dump(&buf, &len, NULL)); TRACE_DEBUG(INFO, "[dbg_monitor] Dumping extensions information"); - TRACE_DEBUG(INFO, "%s", fd_ext_dump(&buf, &len, NULL)); + TRACE_DEBUG(INFO, "%s", fd_ext_dump(&buf, &len, NULL, 0)); TRACE_DEBUG(INFO, "[dbg_monitor] Dumping dictionary information"); TRACE_DEBUG(INFO, "%s", fd_dict_dump(&buf, &len, NULL, fd_g_config->cnf_dict)); free(buf);
--- a/extensions/dict_dcca/dict_dcca.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/dict_dcca/dict_dcca.c Tue May 14 12:32:28 2013 +0800 @@ -1464,7 +1464,7 @@ PARSE_loc_rules( rules, cmd ); } } - TRACE_DEBUG(INFO, "Extension 'Dictionary definitions for DCCA (rfc4006)' initialized"); + LOG_D( "Extension 'Dictionary definitions for DCCA (rfc4006)' initialized"); return 0; }
--- a/extensions/dict_dcca_3gpp/dict_dcca_3gpp.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/dict_dcca_3gpp/dict_dcca_3gpp.c Tue May 14 12:32:28 2013 +0800 @@ -10756,7 +10756,7 @@ PARSE_loc_rules(rules, rule_avp); } - TRACE_DEBUG(INFO, "Extension 'Dictionary definitions for DCCA 3GPP' initialized"); + LOG_D( "Extension 'Dictionary definitions for DCCA 3GPP' initialized"); return 0; }
--- a/extensions/dict_dcca_starent/dict_dcca_starent.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/dict_dcca_starent/dict_dcca_starent.c Tue May 14 12:32:28 2013 +0800 @@ -282,7 +282,7 @@ }; - TRACE_DEBUG(INFO, "Extension 'Dictionary definitions for DCCA Starent' initialized"); + LOG_D( "Extension 'Dictionary definitions for DCCA Starent' initialized"); return 0; }
--- a/extensions/dict_eap/dict_eap.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/dict_eap/dict_eap.c Tue May 14 12:32:28 2013 +0800 @@ -512,7 +512,7 @@ } - TRACE_DEBUG(INFO, "Extension 'Dictionary definitions for EAP' initialized"); + LOG_D( "Extension 'Dictionary definitions for EAP' initialized"); return 0; }
--- a/extensions/dict_mip6a/dict_mip6a.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/dict_mip6a/dict_mip6a.c Tue May 14 12:32:28 2013 +0800 @@ -1088,7 +1088,7 @@ PARSE_loc_rules( rules, cmd ); } } - TRACE_DEBUG(INFO, "Dictionary Extension 'Diameter Mobile IPv6 Auth (MIP6A)' initialized"); + LOG_D( "Dictionary Extension 'Diameter Mobile IPv6 Auth (MIP6A)' initialized"); return 0; } EXTENSION_ENTRY("dict_mip6a", dict_mip6a_init, "dict_rfc5777");
--- a/extensions/dict_mip6i/dict_mip6i.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/dict_mip6i/dict_mip6i.c Tue May 14 12:32:28 2013 +0800 @@ -1131,7 +1131,7 @@ } } - TRACE_DEBUG(INFO, "Dictionary Extension 'Diameter Mobile IPv6 IKE (MIP6I)' initialized"); + LOG_D( "Dictionary Extension 'Diameter Mobile IPv6 IKE (MIP6I)' initialized"); return 0; } EXTENSION_ENTRY("dict_mip6i", dict_mip6i_init, "dict_rfc5777");
--- a/extensions/dict_nas_mipv6/dict_nas_mipv6.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/dict_nas_mipv6/dict_nas_mipv6.c Tue May 14 12:32:28 2013 +0800 @@ -252,7 +252,7 @@ } } - TRACE_DEBUG(INFO, "Dictionary Extension 'MIPv6 NAS-to-HAAA Interaction' initialized"); + LOG_D( "Dictionary Extension 'MIPv6 NAS-to-HAAA Interaction' initialized"); return 0; } EXTENSION_ENTRY("dict_nas_mipv6", dict_nas_mipv6_init);
--- a/extensions/dict_nasreq/dict_nasreq.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/dict_nasreq/dict_nasreq.c Tue May 14 12:32:28 2013 +0800 @@ -3728,7 +3728,7 @@ } } - TRACE_DEBUG(INFO, "Extension 'Dictionary definitions for NASREQ' initialized"); + LOG_D( "Extension 'Dictionary definitions for NASREQ' initialized"); return 0; }
--- a/extensions/dict_rfc5777/dict_rfc5777.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/dict_rfc5777/dict_rfc5777.c Tue May 14 12:32:28 2013 +0800 @@ -2135,7 +2135,7 @@ } } - TRACE_DEBUG(INFO, "Dictionary Extension 'Traffic Classification and Quality of Service (QoS) Attributes for Diameter (RFC 5777)' initialized"); + LOG_D( "Dictionary Extension 'Traffic Classification and Quality of Service (QoS) Attributes for Diameter (RFC 5777)' initialized"); return 0; } EXTENSION_ENTRY("dict_rfc5777", dict_rfc5777_init);
--- a/extensions/dict_sip/dict_sip.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/dict_sip/dict_sip.c Tue May 14 12:32:28 2013 +0800 @@ -2946,7 +2946,7 @@ } } - TRACE_DEBUG(INFO, "Extension 'Dictionary definitions for SIP' initialized"); + LOG_D( "Extension 'Dictionary definitions for SIP' initialized"); return 0; } EXTENSION_ENTRY("dict_sip", ds_dict_init);
--- a/extensions/test_netemul/tne_process.c Tue May 14 11:04:20 2013 +0800 +++ b/extensions/test_netemul/tne_process.c Tue May 14 12:32:28 2013 +0800 @@ -105,7 +105,7 @@ /* Duplicate the message */ CHECK_FCT( fd_msg_bufferize(m, &buf, &len) ); CHECK_FCT( fd_msg_parse_buffer(&buf, len, &nm) ); - CHECK_FCT( fd_msg_source_set(nm, src, srclen, 0, NULL) ); + CHECK_FCT( fd_msg_source_set(nm, src, srclen) ); CHECK_FCT( fd_msg_hdr(nm, &nh) ); nh->msg_flags |= CMD_FLAG_RETRANSMIT; /* Add the 'T' flag */ TRACE_DEBUG(FULL, "[tne] Duplicated message %p as %p", m, nm);
--- a/include/freeDiameter/libfdcore.h Tue May 14 11:04:20 2013 +0800 +++ b/include/freeDiameter/libfdcore.h Tue May 14 12:32:28 2013 +0800 @@ -812,7 +812,7 @@ /* The "old" FD_EV_DUMP_* events are replaced with direct calls to the following dump functions */ DECLARE_FD_DUMP_PROTOTYPE(fd_conf_dump); -DECLARE_FD_DUMP_PROTOTYPE(fd_ext_dump); +DECLARE_FD_DUMP_PROTOTYPE(fd_ext_dump, int indent_next); DECLARE_FD_DUMP_PROTOTYPE(fd_servers_dump, int details); #endif /* SWIG */ DECLARE_FD_DUMP_PROTOTYPE(fd_peer_dump_list, int details);
--- a/include/freeDiameter/libfdproto.h Tue May 14 11:04:20 2013 +0800 +++ b/include/freeDiameter/libfdproto.h Tue May 14 12:32:28 2013 +0800 @@ -2499,8 +2499,7 @@ * PARAMETERS: * msg : A msg object. * diamid,len : The diameter id of the peer from which this message was received. - * add_rr : if true, a Route-Record AVP is added to the message with content diamid. In that case, dict must be supplied. - * dict : a dictionary with definition of Route-Record AVP (if add_rr is true) + * dict : a dictionary with definition of Route-Record AVP (for fd_msg_source_setrr) * * DESCRIPTION: * Store or retrieve the diameted id of the peer from which this message was received. @@ -2511,7 +2510,8 @@ * 0 : Operation complete. * !0 : an error occurred. */ -int fd_msg_source_set( struct msg * msg, DiamId_t diamid, size_t diamidlen, int add_rr, struct dictionary * dict ); +int fd_msg_source_set( struct msg * msg, DiamId_t diamid, size_t diamidlen ); +int fd_msg_source_setrr( struct msg * msg, DiamId_t diamid, size_t diamidlen, struct dictionary * dict ); int fd_msg_source_get( struct msg * msg, DiamId_t *diamid, size_t * diamidlen ); /*
--- a/libfdcore/core.c Tue May 14 11:04:20 2013 +0800 +++ b/libfdcore/core.c Tue May 14 12:32:28 2013 +0800 @@ -256,6 +256,10 @@ b = fd_conf_dump(&buf, &len, NULL); LOG_N("%s", b ?: "Error during configuration dump..."); + /* Display extensions status */ + b = fd_ext_dump(&buf, &len, NULL, 19); + LOG_N("Loaded extensions: %s", b ?: "Error during extensions dump..."); + /* Display registered triggers for FDEV_TRIGGER */ b = fd_event_trig_dump(&buf, &len, &offset); if (!b || offset) {
--- a/libfdcore/extensions.c Tue May 14 11:04:20 2013 +0800 +++ b/libfdcore/extensions.c Tue May 14 12:32:28 2013 +0800 @@ -77,7 +77,7 @@ } /* Dump the list */ -DECLARE_FD_DUMP_PROTOTYPE(fd_ext_dump) +DECLARE_FD_DUMP_PROTOTYPE(fd_ext_dump, int indent_next) { struct fd_list * li; FD_DUMP_HANDLE_OFFSET(); @@ -85,7 +85,10 @@ for (li = ext_list.next; li != &ext_list; li = li->next) { struct fd_ext_info * ext = (struct fd_ext_info *)li; - CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{extension}(@%p): '%s'[%s], %sloaded%s", ext, ext->filename, ext->conffile?:"no conf", ext->handler ? "" : "not ", (li->next == &ext_list) ? "":"\n"), return NULL); + CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%*s'%s'[%s], %sloaded%s", (li == ext_list.next) ? 0 : indent_next,"", + ext->filename, + ext->conffile?:"no conf", + ext->handler ? "" : "not ", (li->next == &ext_list) ? "":"\n"), return NULL); } return *buf; }
--- a/libfdcore/hooks.c Tue May 14 11:04:20 2013 +0800 +++ b/libfdcore/hooks.c Tue May 14 12:32:28 2013 +0800 @@ -332,8 +332,7 @@ case HOOK_MESSAGE_PARSING_ERROR: { if (msg) { DiamId_t id = NULL; - size_t idlen; - if (!fd_msg_source_get( msg, &id, &idlen )) + if (!fd_msg_source_get( msg, &id, NULL )) id = (DiamId_t)"<error getting source>"; if (!id) @@ -352,8 +351,7 @@ case HOOK_MESSAGE_ROUTING_ERROR: { DiamId_t id = NULL; - size_t idlen; - if (!fd_msg_source_get( msg, &id, &idlen )) + if (!fd_msg_source_get( msg, &id, NULL )) id = (DiamId_t)"<error getting source>"; if (!id) @@ -396,6 +394,10 @@ } case HOOK_PEER_CONNECT_SUCCESS: { + DiamId_t id = NULL; + if ((!fd_msg_source_get( msg, &id, NULL )) && (id == NULL)) { /* The CEA is locally issued */ + fd_msg_answ_getq(msg, &msg); /* We dump the CER in that case */ + } CHECK_MALLOC_DO(fd_msg_dump_treeview(&buf, &len, NULL, msg, NULL, 0, 1), break); LOG_N("Connected to '%s', remote capabilities: %s", peer ? peer->p_hdr.info.pi_diamid : "<unknown>", buf); break;
--- a/libfdcore/messages.c Tue May 14 11:04:20 2013 +0800 +++ b/libfdcore/messages.c Tue May 14 12:32:28 2013 +0800 @@ -317,7 +317,6 @@ { struct msg_hdr *hdr; DiamId_t diamid; - size_t diamidlen; /* Save the callback in the message, with the timeout */ CHECK_FCT( fd_msg_anscb_associate( *pmsg, anscb, data, expirecb, timeout ) ); @@ -325,7 +324,7 @@ /* If this is a new request, call the HOOK_MESSAGE_LOCAL hook */ if ( (fd_msg_hdr(*pmsg, &hdr) == 0) && (hdr->msg_flags & CMD_FLAG_REQUEST) - && (fd_msg_source_get(*pmsg, &diamid, &diamidlen) == 0) + && (fd_msg_source_get(*pmsg, &diamid, NULL) == 0) && (diamid == NULL)) { fd_hook_call(HOOK_MESSAGE_LOCAL, *pmsg, NULL, NULL, fd_msg_pmdl_get(*pmsg)); }
--- a/libfdcore/p_psm.c Tue May 14 11:04:20 2013 +0800 +++ b/libfdcore/p_psm.c Tue May 14 12:32:28 2013 +0800 @@ -281,7 +281,7 @@ if (old == new_state) return 0; - TRACE_DEBUG(((old == STATE_OPEN) || (new_state == STATE_OPEN)) ? INFO : FULL, "'%s'\t-> '%s'\t'%s'", + LOG(((old == STATE_OPEN) || (new_state == STATE_OPEN)) ? FD_LOG_NOTICE : FD_LOG_DEBUG, "'%s'\t-> '%s'\t'%s'", STATE_STR(old), STATE_STR(new_state), peer->p_hdr.info.pi_diamid); @@ -499,6 +499,7 @@ } ); fd_hook_associate(msg, pmdl); + CHECK_FCT_DO( fd_msg_source_set( msg, peer->p_hdr.info.pi_diamid, peer->p_hdr.info.pi_diamidlen), goto psm_end); /* If the current state does not allow receiving messages, just drop it */ if (cur_state == STATE_CLOSED) { @@ -556,7 +557,7 @@ CHECK_FCT_DO( fd_p_expi_update(peer), goto psm_end ); /* Set the message source and add the Route-Record */ - CHECK_FCT_DO( fd_msg_source_set( msg, peer->p_hdr.info.pi_diamid, peer->p_hdr.info.pi_diamidlen, 1, fd_g_config->cnf_dict ), goto psm_end); + CHECK_FCT_DO( fd_msg_source_setrr( msg, peer->p_hdr.info.pi_diamid, peer->p_hdr.info.pi_diamidlen, fd_g_config->cnf_dict ), goto psm_end); /* Requeue to the global incoming queue */ CHECK_FCT_DO(fd_fifo_post(fd_g_incoming, &msg), goto psm_end ); @@ -741,7 +742,7 @@ { char * buf = NULL; size_t len = 0; - LOG_D("New remote endpoint(s): %s", fd_ep_dump(&buf, &len, NULL, 0, 0, &peer->p_hdr.info.pi_endpoints) ?: "error"); + LOG_D("Got low layer notification (IGNORED): remote endpoint(s) changed: %s", fd_ep_dump(&buf, &len, NULL, 0, 0, &peer->p_hdr.info.pi_endpoints) ?: "error"); free(buf); }
--- a/libfdcore/routing_dispatch.c Tue May 14 11:04:20 2013 +0800 +++ b/libfdcore/routing_dispatch.c Tue May 14 12:32:28 2013 +0800 @@ -550,7 +550,6 @@ int is_req = 0; int is_err = 0; DiamId_t qry_src = NULL; - size_t qry_src_len = 0; struct msg *msgptr = msg; /* Read the message header */ @@ -750,7 +749,7 @@ /* Retrieve the corresponding query and its origin */ CHECK_FCT( fd_msg_answ_getq( msgptr, &qry ) ); - CHECK_FCT( fd_msg_source_get( qry, &qry_src, &qry_src_len ) ); + CHECK_FCT( fd_msg_source_get( qry, &qry_src, NULL ) ); if ((!qry_src) && (!is_err)) { /* The message is a normal answer to a request issued localy, we do not call the callbacks chain on it. */
--- a/libfdproto/messages.c Tue May 14 11:04:20 2013 +0800 +++ b/libfdproto/messages.c Tue May 14 12:32:28 2013 +0800 @@ -803,8 +803,8 @@ CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Flags: 0x%02hhX (" DUMP_CMDFL_str ")\n", msg->msg_public.msg_flags, DUMP_CMDFL_val(msg->msg_public.msg_flags)), return NULL); CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Command Code: %u\n", msg->msg_public.msg_code), return NULL); CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " ApplicationId: %d\n", msg->msg_public.msg_appl), return NULL); - CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Hop-by-Hop Identifier: 0x%8X\n", msg->msg_public.msg_hbhid), return NULL); - CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " End-to-End Identifier: 0x%8X\n", msg->msg_public.msg_eteid), return NULL); + CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " Hop-by-Hop Identifier: 0x%08X\n", msg->msg_public.msg_hbhid), return NULL); + CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " End-to-End Identifier: 0x%08X\n", msg->msg_public.msg_eteid), return NULL); CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " {debug data}: src:%s(%zd) rwb:%p rt:%d cb:%p,%p(%p) qry:%p asso:%d sess:%p", msg->msg_src_id?:"(nil)", msg->msg_src_id_len, msg->msg_rawbuffer, msg->msg_routable, msg->msg_cb.anscb, msg->msg_cb.expirecb, msg->msg_cb.data, msg->msg_query, msg->msg_associated, msg->msg_sess), return NULL); return *buf; @@ -1070,7 +1070,7 @@ if (first) { CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " {"), return NULL); } else { - CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "+"), return NULL); + CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, ","), return NULL); } } @@ -1130,9 +1130,9 @@ } else { /* For embedded AVPs, we only display (vendor,) code & length */ if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) { - CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "V=%u,", avp->avp_public.avp_vendor), return NULL); + CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "V:%u/", avp->avp_public.avp_vendor), return NULL); } - CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "C=%u,L=%d", avp->avp_public.avp_code, avp->avp_public.avp_len), return NULL); + CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "C:%u/l:%d", avp->avp_public.avp_code, avp->avp_public.avp_len), return NULL); } end: @@ -1341,12 +1341,12 @@ static pthread_mutex_t cached_avp_rr_lock = PTHREAD_MUTEX_INITIALIZER; /* Associate source peer */ -int fd_msg_source_set( struct msg * msg, DiamId_t diamid, size_t diamidlen, int add_rr, struct dictionary * dict ) +int fd_msg_source_set( struct msg * msg, DiamId_t diamid, size_t diamidlen ) { - TRACE_ENTRY( "%p %p %zd %d %p", msg, diamid, diamidlen, add_rr, dict); + TRACE_ENTRY( "%p %p %zd", msg, diamid, diamidlen); /* Check we received a valid message */ - CHECK_PARAMS( CHECK_MSG(msg) && ( (! add_rr) || dict ) ); + CHECK_PARAMS( CHECK_MSG(msg) ); /* Cleanup any previous source */ free(msg->msg_src_id); msg->msg_src_id = NULL; msg->msg_src_id_len = 0; @@ -1359,45 +1359,53 @@ /* Otherwise save the new informations */ CHECK_MALLOC( msg->msg_src_id = os0dup(diamid, diamidlen) ); msg->msg_src_id_len = diamidlen; + /* done */ + return 0; +} + +/* Associate source peer */ +int fd_msg_source_setrr( struct msg * msg, DiamId_t diamid, size_t diamidlen, struct dictionary * dict ) +{ + struct dict_object *avp_rr_model = NULL; + avp_code_t code = AC_ROUTE_RECORD; + struct avp *avp; + union avp_value val; + + TRACE_ENTRY( "%p %p %zd %p", msg, diamid, diamidlen, dict); + /* Check we received a valid message */ + CHECK_PARAMS( CHECK_MSG(msg) && dict ); - if (add_rr) { - struct dict_object *avp_rr_model = NULL; - avp_code_t code = AC_ROUTE_RECORD; - struct avp *avp; - union avp_value val; - - /* Lock the cached values */ + /* Lock the cached values */ + CHECK_POSIX( pthread_mutex_lock(&cached_avp_rr_lock) ); + if (cached_avp_rr_dict == dict) { + avp_rr_model = cached_avp_rr_model; + } + CHECK_POSIX( pthread_mutex_unlock(&cached_avp_rr_lock) ); + + /* If it was not cached */ + if (!avp_rr_model) { + /* Find the model for Route-Record in the dictionary */ + CHECK_FCT( fd_dict_search ( dict, DICT_AVP, AVP_BY_CODE, &code, &avp_rr_model, ENOENT) ); + + /* Now cache this result */ CHECK_POSIX( pthread_mutex_lock(&cached_avp_rr_lock) ); - if (cached_avp_rr_dict == dict) { - avp_rr_model = cached_avp_rr_model; - } + cached_avp_rr_dict = dict; + cached_avp_rr_model = avp_rr_model; CHECK_POSIX( pthread_mutex_unlock(&cached_avp_rr_lock) ); - - /* If it was not cached */ - if (!avp_rr_model) { - /* Find the model for Route-Record in the dictionary */ - CHECK_FCT( fd_dict_search ( dict, DICT_AVP, AVP_BY_CODE, &code, &avp_rr_model, ENOENT) ); - - /* Now cache this result */ - CHECK_POSIX( pthread_mutex_lock(&cached_avp_rr_lock) ); - cached_avp_rr_dict = dict; - cached_avp_rr_model = avp_rr_model; - CHECK_POSIX( pthread_mutex_unlock(&cached_avp_rr_lock) ); - } - - /* Create the AVP with this model */ - CHECK_FCT( fd_msg_avp_new ( avp_rr_model, 0, &avp ) ); - - /* Set the AVP value with the diameter id */ - memset(&val, 0, sizeof(val)); - val.os.data = (uint8_t *)diamid; - val.os.len = diamidlen; - CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) ); + } + + /* Create the AVP with this model */ + CHECK_FCT( fd_msg_avp_new ( avp_rr_model, 0, &avp ) ); - /* Add the AVP in the message */ - CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp ) ); - } + /* Set the AVP value with the diameter id */ + memset(&val, 0, sizeof(val)); + val.os.data = (uint8_t *)diamid; + val.os.len = diamidlen; + CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) ); + + /* Add the AVP in the message */ + CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_LAST_CHILD, avp ) ); /* done */ return 0;
--- a/tests/testappacct.c Tue May 14 11:04:20 2013 +0800 +++ b/tests/testappacct.c Tue May 14 12:32:28 2013 +0800 @@ -238,7 +238,8 @@ } /* Source */ - CHECK( 0, fd_msg_source_set( msg, "peer3", CONSTSTRLEN("peer3"), 1, fd_g_config->cnf_dict ) ); + CHECK( 0, fd_msg_source_set( msg, "peer3", CONSTSTRLEN("peer3") ) ); + CHECK( 0, fd_msg_source_setrr( msg, "peer3", CONSTSTRLEN("peer3"), fd_g_config->cnf_dict ) ); } /* Now, have the daemon handle this */