Navigation


Changeset 29:5ba91682f0bc in freeDiameter for freeDiameter/sctps.c


Ignore:
Timestamp:
Oct 28, 2009, 3:19:50 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added a test for cnxctx (tbc) and fixed some bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/sctps.c

    r27 r29  
    7373       
    7474        TRACE_ENTRY("%p", arg);
    75        
    7675        CHECK_PARAMS_DO(conn && (conn->cc_socket > 0), goto out);
     76       
     77        /* Set the thread name */
     78        {
     79                char buf[48];
     80                snprintf(buf, sizeof(buf), "Demuxer (%d)", conn->cc_socket);
     81                fd_log_threadname ( buf );
     82        }
     83       
    7784        ASSERT( conn->cc_proto == IPPROTO_SCTP );
    78         ASSERT( conn->cc_tls == 1 );
    7985        ASSERT( Target_Queue(conn) );
    8086        ASSERT( conn->cc_sctps_data.array );
     
    115121       
    116122        TRACE_ENTRY("%p", arg);
    117        
    118123        CHECK_PARAMS_DO(ctx && ctx->raw_recv && ctx->parent, goto error);
    119124        cnx = ctx->parent;
    120125        ASSERT( Target_Queue(cnx) );
     126       
     127        /* Set the thread name */
     128        {
     129                char buf[48];
     130                snprintf(buf, sizeof(buf), "Decipher (%hu@%d)", ctx->strid, cnx->cc_socket);
     131                fd_log_threadname ( buf );
     132        }
    121133       
    122134        CHECK_FCT_DO(fd_tls_rcvthr_core(cnx, ctx->strid ? ctx->session : cnx->cc_tls_para.session), /* continue */);
     
    209221        pthread_rwlock_t lock;
    210222        struct cnxctx   *parent;
     223        /* Add another list to chain in a global list to implement a garbage collector on sessions */
    211224};
    212225
     
    219232
    220233/* The level at which we debug session resuming */
    221 #define SR_LEVEL FULL
     234#define SR_LEVEL (FULL + 1)
    222235
    223236/* Initialize the store area for a connection */
     
    303316       
    304317        CHECK_PARAMS_DO( sto && key.data && data.data, return -1 );
    305         TRACE_DEBUG_BUFFER(SR_LEVEL, "Session store [key ", key.data, key.size < 16 ? key.size : 16, "]");
    306318       
    307319        CHECK_POSIX_DO( pthread_rwlock_wrlock(&sto->lock), return -1 );
     320        TRACE_DEBUG_BUFFER(SR_LEVEL, "Session store [key ", key.data, key.size, "]");
    308321       
    309322        li = find_or_next(sto, key, &match);
     
    313326                /* Check the data is the same */
    314327                if ((data.size != sr->data.size) || memcmp(data.data, sr->data.data, data.size)) {
    315                         TRACE_DEBUG(INFO, "GnuTLS tried to store a session with same key and different data!");
     328                        TRACE_DEBUG(SR_LEVEL, "GnuTLS tried to store a session with same key and different data!");
    316329                        ret = -1;
     330                } else {
     331                        TRACE_DEBUG(SR_LEVEL, "GnuTLS tried to store a session with same key and same data, skipped.");
    317332                }
    318333                goto out;
     
    350365       
    351366        CHECK_PARAMS_DO( sto && key.data, return -1 );
    352         TRACE_DEBUG_BUFFER(SR_LEVEL, "Session delete [key ", key.data, key.size < 16 ? key.size : 16, "]");
    353367       
    354368        CHECK_POSIX_DO( pthread_rwlock_wrlock(&sto->lock), return -1 );
     369        TRACE_DEBUG_BUFFER(SR_LEVEL, "Session delete [key ", key.data, key.size, "]");
    355370       
    356371        li = find_or_next(sto, key, &match);
     
    382397
    383398        CHECK_PARAMS_DO( sto && key.data, return error );
    384         TRACE_DEBUG_BUFFER(SR_LEVEL, "Session fetch [key ", key.data, key.size < 16 ? key.size : 16, "]");
    385399
    386400        CHECK_POSIX_DO( pthread_rwlock_rdlock(&sto->lock), return error );
     401        TRACE_DEBUG_BUFFER(SR_LEVEL, "Session fetch [key ", key.data, key.size, "]");
    387402       
    388403        li = find_or_next(sto, key, &match);
     
    394409        }
    395410out:   
     411        TRACE_DEBUG(SR_LEVEL, "Fetched (%p, %d) from store %p", res.data, res.size, sto);
    396412        CHECK_POSIX_DO( pthread_rwlock_unlock(&sto->lock), return error);
    397413        return res;
     
    417433        TRACE_ENTRY("%p", arg);
    418434       
     435        /* Set the thread name */
     436        {
     437                char buf[48];
     438                snprintf(buf, sizeof(buf), "Handshake resume (%hu@%d)", ctx->strid, ctx->parent->cc_socket);
     439                fd_log_threadname ( buf );
     440        }
     441       
    419442        TRACE_DEBUG(FULL, "Starting TLS resumed handshake on stream %hu", ctx->strid);
    420443        CHECK_GNUTLS_DO( gnutls_handshake( ctx->session ), return NULL);
    421444                       
    422         /* We can trace success of resuming handshake by using gnutls_session_is_resumed */
     445        if (TRACE_BOOL(FULL)) {
     446                int resumed = gnutls_session_is_resumed(ctx->session);
     447                if (resumed) {
     448                        fd_log_debug("Session was resumed successfully on stream %hu (conn: '%s')\n", ctx->strid, fd_cnx_getid(ctx->parent));
     449                } else {
     450                        fd_log_debug("Session was NOT resumed (full handshake) on stream %hu (conn: '%s')\n", ctx->strid, fd_cnx_getid(ctx->parent));
     451                }
     452        }
    423453                       
    424454        /* Finish */
     
    467497
    468498/* Handshake other streams, after full handshake on the master session */
    469 int fd_sctps_handshake_others(struct cnxctx * conn, char * priority)
     499int fd_sctps_handshake_others(struct cnxctx * conn, char * priority, void * alt_creds)
    470500{
    471501        uint16_t i;
     
    487517        for (i = 1; i < conn->cc_sctp_para.pairs; i++) {
    488518                /* Set credentials and priority */
    489                 CHECK_FCT( fd_tls_prepare(&conn->cc_sctps_data.array[i].session, conn->cc_tls_para.mode, priority) );
     519                CHECK_FCT( fd_tls_prepare(&conn->cc_sctps_data.array[i].session, conn->cc_tls_para.mode, priority, alt_creds) );
    490520               
    491521                /* For the client, copy data from master session; for the server, set session resuming pointers */
     
    550580}
    551581
     582static void * bye_th(void * arg)
     583{
     584        struct sctps_ctx * ctx = (struct sctps_ctx *) arg;
     585        TRACE_ENTRY("%p", arg);
     586       
     587        /* Set the thread name */
     588        {
     589                char buf[48];
     590                snprintf(buf, sizeof(buf), "gnutls_bye (%hu@%d)", ctx->strid, ctx->parent->cc_socket);
     591                fd_log_threadname ( buf );
     592        }
     593       
     594        CHECK_GNUTLS_DO( gnutls_bye(ctx->session, GNUTLS_SHUT_RDWR), /* Continue */ );
     595                       
     596        /* Finish */
     597        return arg;
     598}
     599
     600
     601
    552602/* Destroy a wrapper context */
    553603void fd_sctps_destroy(struct cnxctx * conn)
     
    560610        fd_sctps_stopthreads(conn);
    561611       
    562         /* End all TLS sessions -- maybe we should do it in parallel ? */
    563         for (i = 0; i < conn->cc_sctp_para.pairs; i++) {
    564                 CHECK_GNUTLS_DO( gnutls_bye(conn->cc_sctps_data.array[i].session, GNUTLS_SHUT_RDWR), /* Continue */ );
    565         }
    566        
     612        /* End all TLS sessions, in parallel */
     613        for (i = 1; i < conn->cc_sctp_para.pairs; i++) {
     614                CHECK_POSIX_DO( pthread_create( &conn->cc_sctps_data.array[i].thr, NULL, bye_th, &conn->cc_sctps_data.array[i] ), break );
     615        }
     616        for (--i; i > 0; --i) {
     617                CHECK_POSIX_DO( pthread_join( conn->cc_sctps_data.array[i].thr, NULL ), continue );
     618        }
     619skip:   
    567620        /* Now, stop the demux thread */
    568621        CHECK_FCT_DO( fd_thr_term(&conn->cc_rcvthr), /* continue */ );
     
    572625                fd_event_destroy( &conn->cc_sctps_data.array[i].raw_recv, free );
    573626                free(conn->cc_sctps_data.array[i].partial.buf);
    574                 gnutls_deinit(conn->cc_sctps_data.array[i].session);
     627                if (i > 0)
     628                        gnutls_deinit(conn->cc_sctps_data.array[i].session);
    575629        }
    576630       
Note: See TracChangeset for help on using the changeset viewer.