Changeset 29:5ba91682f0bc in freeDiameter for freeDiameter/sctps.c
- Timestamp:
- Oct 28, 2009, 3:19:50 PM (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/sctps.c
r27 r29 73 73 74 74 TRACE_ENTRY("%p", arg); 75 76 75 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 77 84 ASSERT( conn->cc_proto == IPPROTO_SCTP ); 78 ASSERT( conn->cc_tls == 1 );79 85 ASSERT( Target_Queue(conn) ); 80 86 ASSERT( conn->cc_sctps_data.array ); … … 115 121 116 122 TRACE_ENTRY("%p", arg); 117 118 123 CHECK_PARAMS_DO(ctx && ctx->raw_recv && ctx->parent, goto error); 119 124 cnx = ctx->parent; 120 125 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 } 121 133 122 134 CHECK_FCT_DO(fd_tls_rcvthr_core(cnx, ctx->strid ? ctx->session : cnx->cc_tls_para.session), /* continue */); … … 209 221 pthread_rwlock_t lock; 210 222 struct cnxctx *parent; 223 /* Add another list to chain in a global list to implement a garbage collector on sessions */ 211 224 }; 212 225 … … 219 232 220 233 /* The level at which we debug session resuming */ 221 #define SR_LEVEL FULL234 #define SR_LEVEL (FULL + 1) 222 235 223 236 /* Initialize the store area for a connection */ … … 303 316 304 317 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, "]");306 318 307 319 CHECK_POSIX_DO( pthread_rwlock_wrlock(&sto->lock), return -1 ); 320 TRACE_DEBUG_BUFFER(SR_LEVEL, "Session store [key ", key.data, key.size, "]"); 308 321 309 322 li = find_or_next(sto, key, &match); … … 313 326 /* Check the data is the same */ 314 327 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!"); 316 329 ret = -1; 330 } else { 331 TRACE_DEBUG(SR_LEVEL, "GnuTLS tried to store a session with same key and same data, skipped."); 317 332 } 318 333 goto out; … … 350 365 351 366 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, "]");353 367 354 368 CHECK_POSIX_DO( pthread_rwlock_wrlock(&sto->lock), return -1 ); 369 TRACE_DEBUG_BUFFER(SR_LEVEL, "Session delete [key ", key.data, key.size, "]"); 355 370 356 371 li = find_or_next(sto, key, &match); … … 382 397 383 398 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, "]");385 399 386 400 CHECK_POSIX_DO( pthread_rwlock_rdlock(&sto->lock), return error ); 401 TRACE_DEBUG_BUFFER(SR_LEVEL, "Session fetch [key ", key.data, key.size, "]"); 387 402 388 403 li = find_or_next(sto, key, &match); … … 394 409 } 395 410 out: 411 TRACE_DEBUG(SR_LEVEL, "Fetched (%p, %d) from store %p", res.data, res.size, sto); 396 412 CHECK_POSIX_DO( pthread_rwlock_unlock(&sto->lock), return error); 397 413 return res; … … 417 433 TRACE_ENTRY("%p", arg); 418 434 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 419 442 TRACE_DEBUG(FULL, "Starting TLS resumed handshake on stream %hu", ctx->strid); 420 443 CHECK_GNUTLS_DO( gnutls_handshake( ctx->session ), return NULL); 421 444 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 } 423 453 424 454 /* Finish */ … … 467 497 468 498 /* Handshake other streams, after full handshake on the master session */ 469 int fd_sctps_handshake_others(struct cnxctx * conn, char * priority )499 int fd_sctps_handshake_others(struct cnxctx * conn, char * priority, void * alt_creds) 470 500 { 471 501 uint16_t i; … … 487 517 for (i = 1; i < conn->cc_sctp_para.pairs; i++) { 488 518 /* 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) ); 490 520 491 521 /* For the client, copy data from master session; for the server, set session resuming pointers */ … … 550 580 } 551 581 582 static 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 552 602 /* Destroy a wrapper context */ 553 603 void fd_sctps_destroy(struct cnxctx * conn) … … 560 610 fd_sctps_stopthreads(conn); 561 611 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 } 619 skip: 567 620 /* Now, stop the demux thread */ 568 621 CHECK_FCT_DO( fd_thr_term(&conn->cc_rcvthr), /* continue */ ); … … 572 625 fd_event_destroy( &conn->cc_sctps_data.array[i].raw_recv, free ); 573 626 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); 575 629 } 576 630
Note: See TracChangeset
for help on using the changeset viewer.