Navigation


Changeset 29:5ba91682f0bc in freeDiameter for freeDiameter/cnxctx.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/cnxctx.c

    r27 r29  
    397397}
    398398
     399/* Return the protocol of a connection */
     400int fd_cnx_getproto(struct cnxctx * conn)
     401{
     402        CHECK_PARAMS_DO( conn, return 0 );
     403        return conn->cc_proto;
     404}
     405
     406/* Return the TLS state of a connection */
     407int fd_cnx_getTLS(struct cnxctx * conn)
     408{
     409        CHECK_PARAMS_DO( conn, return 0 );
     410        return conn->cc_tls;
     411}
     412
    399413/* Get the list of endpoints (IP addresses) of the local and remote peers on this connection */
    400414int fd_cnx_getendpoints(struct cnxctx * conn, struct fd_list * local, struct fd_list * remote)
     
    474488       
    475489        TRACE_ENTRY("%p", arg);
    476        
    477490        CHECK_PARAMS_DO(conn && (conn->cc_socket > 0), goto out);
     491       
     492        /* Set the thread name */
     493        {
     494                char buf[48];
     495                snprintf(buf, sizeof(buf), "Receiver (%d) TCP/noTLS)", conn->cc_socket);
     496                fd_log_threadname ( buf );
     497        }
     498       
    478499        ASSERT( conn->cc_proto == IPPROTO_TCP );
    479500        ASSERT( conn->cc_tls == 0 );
     
    548569       
    549570        TRACE_ENTRY("%p", arg);
    550        
    551571        CHECK_PARAMS_DO(conn && (conn->cc_socket > 0), goto out);
     572       
     573        /* Set the thread name */
     574        {
     575                char buf[48];
     576                snprintf(buf, sizeof(buf), "Receiver (%d) SCTP/noTLS)", conn->cc_socket);
     577                fd_log_threadname ( buf );
     578        }
     579       
    552580        ASSERT( conn->cc_proto == IPPROTO_SCTP );
    553581        ASSERT( conn->cc_tls == 0 );
     
    607635int fd_tls_rcvthr_core(struct cnxctx * conn, gnutls_session_t session)
    608636{
    609         /* No guaranty that GnuTLS preserves the message boundaries, so we re-build it as in TCP */
     637        /* No guarantee that GnuTLS preserves the message boundaries, so we re-build it as in TCP */
    610638        do {
    611639                uint8_t header[4];
     
    616644
    617645                do {
    618                         ret = fd_tls_recv_handle_error(conn, conn->cc_tls_para.session, &header[received], sizeof(header) - received);
     646                        ret = fd_tls_recv_handle_error(conn, session, &header[received], sizeof(header) - received);
    619647                        if (ret == 0) {
    620648                                /* The connection is closed */
     
    640668                while (received < length) {
    641669                        pthread_cleanup_push(free, newmsg); /* In case we are canceled, clean the partialy built buffer */
    642                         ret = fd_tls_recv_handle_error(conn, conn->cc_tls_para.session, newmsg + received, length - received);
     670                        ret = fd_tls_recv_handle_error(conn, session, newmsg + received, length - received);
    643671                        pthread_cleanup_pop(0);
    644672
     
    664692       
    665693        TRACE_ENTRY("%p", arg);
    666        
    667694        CHECK_PARAMS_DO(conn && (conn->cc_socket > 0), goto error);
     695       
     696        /* Set the thread name */
     697        {
     698                char buf[48];
     699                snprintf(buf, sizeof(buf), "Receiver (%d) TLS/ single stream)", conn->cc_socket);
     700                fd_log_threadname ( buf );
     701        }
     702       
    668703        ASSERT( conn->cc_tls == 1 );
    669704        ASSERT( Target_Queue(conn) );
     
    709744
    710745/* Prepare a gnutls session object for handshake */
    711 int fd_tls_prepare(gnutls_session_t * session, int mode, char * priority)
     746int fd_tls_prepare(gnutls_session_t * session, int mode, char * priority, void * alt_creds)
    712747{
    713748        /* Create the master session context */
     
    724759
    725760        /* Set the credentials of this side of the connection */
    726         CHECK_GNUTLS_DO( gnutls_credentials_set (*session, GNUTLS_CRD_CERTIFICATE, fd_g_config->cnf_sec_data.credentials), return EINVAL );
     761        CHECK_GNUTLS_DO( gnutls_credentials_set (*session, GNUTLS_CRD_CERTIFICATE, alt_creds ?: fd_g_config->cnf_sec_data.credentials), return EINVAL );
    727762
    728763        /* Request the remote credentials as well */
     
    735770
    736771/* TLS handshake a connection; no need to have called start_clear before. Reception is active if handhsake is successful */
    737 int fd_cnx_handshake(struct cnxctx * conn, int mode, char * priority)
     772int fd_cnx_handshake(struct cnxctx * conn, int mode, char * priority, void * alt_creds)
    738773{
    739774        TRACE_ENTRY( "%p %d", conn, mode);
     
    750785       
    751786        /* Prepare the master session credentials and priority */
    752         CHECK_FCT( fd_tls_prepare(&conn->cc_tls_para.session, mode, priority) );
     787        CHECK_FCT( fd_tls_prepare(&conn->cc_tls_para.session, mode, priority, alt_creds) );
    753788
    754789        /* Special case: multi-stream TLS is not natively managed in GNU TLS, we use a wrapper library */
     
    801836#ifndef DISABLE_SCTP
    802837                /* Resume all additional sessions from the master one. */
    803                 CHECK_FCT(fd_sctps_handshake_others(conn, priority));
    804                
     838                CHECK_FCT(fd_sctps_handshake_others(conn, priority, alt_creds));
     839               
     840                /* Mark the connection as protected from here */
     841                conn->cc_tls = 1;
     842
    805843                /* Start decrypting the messages from all threads and queuing them in target queue */
    806844                CHECK_FCT(fd_sctps_startthreads(conn));
    807845#endif /* DISABLE_SCTP */
    808846        } else {
     847                /* Mark the connection as protected from here */
     848                conn->cc_tls = 1;
     849
    809850                /* Start decrypting the data */
    810851                CHECK_POSIX( pthread_create( &conn->cc_rcvthr, NULL, rcvthr_tls_single, conn ) );
    811852        }
    812 
     853       
    813854        return 0;
    814855}
Note: See TracChangeset for help on using the changeset viewer.