Navigation


Changeset 706:4ffbc9f1e922 in freeDiameter for libfdproto/messages.c


Ignore:
Timestamp:
Feb 9, 2011, 3:26:58 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Large UNTESTED commit with the following changes:

  • Improved DiameterIdentity? handling (esp. interationalization issues), and improve efficiency of some string operations in peers, sessions, and dictionary modules (closes #7)
  • Cleanup in the session module to free only unreferenced sessions (#16)
  • Removed fd_cpu_flush_cache(), replaced by more robust alternatives.
  • Improved peer state machine algorithm to counter SCTP multistream race condition.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/messages.c

    r704 r706  
    126126                        struct timespec timeout;
    127127                }                msg_cb;                /* Callback to be called when an answer is received, if not NULL */
    128         char *                   msg_src_id;            /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */
     128        DiamId_t                 msg_src_id;            /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */
     129        size_t                   msg_src_id_len;        /* cached length of this string */
    129130};
    130131
     
    332333        if (sess && dict) {
    333334                struct dict_object * sess_id_avp;
    334                 char * sid;
     335                os0_t sid;
     336                size_t sidlen;
    335337                struct avp * avp;
    336338                union avp_value val;
    337339               
    338340                CHECK_FCT( fd_dict_search( dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sess_id_avp, ENOENT) );
    339                 CHECK_FCT( fd_sess_getsid ( sess, &sid ) );
     341                CHECK_FCT( fd_sess_getsid ( sess, &sid, &sidlen ) );
    340342                CHECK_FCT( fd_msg_avp_new ( sess_id_avp, 0, &avp ) );
    341                 val.os.data = (unsigned char *)sid;
    342                 val.os.len  = strlen(sid);
     343                val.os.data = sid;
     344                val.os.len  = sidlen;
    343345                CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) );
    344346                CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ) );
     
    703705                msg->msg_public.msg_eteid
    704706                );
    705         fd_log_debug_fstr(fstr, INOBJHDR "intern: rwb:%p rt:%d cb:%p(%p) qry:%p asso:%d sess:%p src:%s\n",
    706                         INOBJHDRVAL, msg->msg_rawbuffer, msg->msg_routable, msg->msg_cb.fct, msg->msg_cb.data, msg->msg_query, msg->msg_associated, msg->msg_sess, msg->msg_src_id?:"(nil)");
     707        fd_log_debug_fstr(fstr, INOBJHDR "intern: rwb:%p rt:%d cb:%p(%p) qry:%p asso:%d sess:%p src:%s(%zd)\n",
     708                        INOBJHDRVAL, msg->msg_rawbuffer, msg->msg_routable, msg->msg_cb.fct, msg->msg_cb.data, msg->msg_query, msg->msg_associated, msg->msg_sess, msg->msg_src_id?:"(nil)", msg->msg_src_id_len);
    707709}
    708710
     
    10121014}
    10131015
     1016/* cache the dictionary model for next function to avoid re-searching at every incoming message */
     1017static struct dict_object *cached_avp_rr_model = NULL;
     1018static struct dictionary  *cached_avp_rr_dict  = NULL;
     1019static pthread_mutex_t     cached_avp_rr_lock = PTHREAD_MUTEX_INITIALIZER;
     1020
    10141021/* Associate source peer */
    1015 int fd_msg_source_set( struct msg * msg, char * diamid, int add_rr, struct dictionary * dict )
    1016 {
    1017         TRACE_ENTRY( "%p %p %d %p", msg, diamid, add_rr, dict);
     1022int fd_msg_source_set( struct msg * msg, DiamId_t diamid, size_t diamidlen, int add_rr, struct dictionary * dict )
     1023{
     1024        TRACE_ENTRY( "%p %p %zd %d %p", msg, diamid, diamidlen, add_rr, dict);
    10181025       
    10191026        /* Check we received a valid message */
     
    10211028       
    10221029        /* Cleanup any previous source */
    1023         free(msg->msg_src_id); msg->msg_src_id = NULL;
     1030        free(msg->msg_src_id); msg->msg_src_id = NULL; msg->msg_src_id_len = 0;
    10241031       
    10251032        /* If the request is to cleanup the source, we are done */
     
    10291036       
    10301037        /* Otherwise save the new informations */
    1031         CHECK_MALLOC( msg->msg_src_id = strdup(diamid) );
     1038        CHECK_MALLOC( msg->msg_src_id = os0dup(diamid, diamidlen) );
     1039        msg->msg_src_id_len = diamidlen;
     1040       
    10321041       
    10331042        if (add_rr) {
    1034                 struct dict_object      *avp_rr_model;
     1043                struct dict_object      *avp_rr_model = NULL;
    10351044                avp_code_t               code = AC_ROUTE_RECORD;
    10361045                struct avp              *avp;
    10371046                union avp_value          val;
    10381047               
    1039                 /* Find the model for Route-Record in the dictionary */
    1040                 CHECK_FCT( fd_dict_search ( dict, DICT_AVP, AVP_BY_CODE, &code, &avp_rr_model, ENOENT) );
     1048                /* Lock the cached values */
     1049                CHECK_POSIX( pthread_mutex_lock(&cached_avp_rr_lock) );
     1050                if (cached_avp_rr_dict == dict) {
     1051                        avp_rr_model = cached_avp_rr_model;
     1052                }
     1053                CHECK_POSIX( pthread_mutex_unlock(&cached_avp_rr_lock) );
     1054               
     1055                /* If it was not cached */
     1056                if (!avp_rr_model) {
     1057                        /* Find the model for Route-Record in the dictionary */
     1058                        CHECK_FCT( fd_dict_search ( dict, DICT_AVP, AVP_BY_CODE, &code, &avp_rr_model, ENOENT) );
     1059                       
     1060                        /* Now cache this result */
     1061                        CHECK_POSIX( pthread_mutex_lock(&cached_avp_rr_lock) );
     1062                        cached_avp_rr_dict  = dict;
     1063                        cached_avp_rr_model = avp_rr_model;
     1064                        CHECK_POSIX( pthread_mutex_unlock(&cached_avp_rr_lock) );
     1065                }
    10411066               
    10421067                /* Create the AVP with this model */
     
    10451070                /* Set the AVP value with the diameter id */
    10461071                memset(&val, 0, sizeof(val));
    1047                 val.os.data = (unsigned char *)diamid;
    1048                 val.os.len  = strlen(diamid);
     1072                val.os.data = (uint8_t *)diamid;
     1073                val.os.len  = diamidlen;
    10491074                CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) );
    10501075
     
    10571082}
    10581083
    1059 int fd_msg_source_get( struct msg * msg, char ** diamid )
    1060 {
    1061         TRACE_ENTRY( "%p %p", msg, diamid);
     1084int fd_msg_source_get( struct msg * msg, DiamId_t* diamid, size_t * diamidlen )
     1085{
     1086        TRACE_ENTRY( "%p %p %p", msg, diamid, diamidlen);
    10621087       
    10631088        /* Check we received valid parameters */
     
    10671092        /* Copy the informations */
    10681093        *diamid = msg->msg_src_id;
     1094       
     1095        if (diamidlen)
     1096                *diamidlen = msg->msg_src_id_len;
    10691097       
    10701098        /* done */
     
    22252253
    22262254/* Call all dispatch callbacks for a given message */
    2227 int fd_msg_dispatch ( struct msg ** msg, struct session * session, enum disp_action *action, const char ** error_code)
     2255int fd_msg_dispatch ( struct msg ** msg, struct session * session, enum disp_action *action, char ** error_code)
    22282256{
    22292257        struct dictionary  * dict;
Note: See TracChangeset for help on using the changeset viewer.