Changeset 29:5ba91682f0bc in freeDiameter for freeDiameter/cnxctx.c
- Timestamp:
- Oct 28, 2009, 3:19:50 PM (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/cnxctx.c
r27 r29 397 397 } 398 398 399 /* Return the protocol of a connection */ 400 int 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 */ 407 int fd_cnx_getTLS(struct cnxctx * conn) 408 { 409 CHECK_PARAMS_DO( conn, return 0 ); 410 return conn->cc_tls; 411 } 412 399 413 /* Get the list of endpoints (IP addresses) of the local and remote peers on this connection */ 400 414 int fd_cnx_getendpoints(struct cnxctx * conn, struct fd_list * local, struct fd_list * remote) … … 474 488 475 489 TRACE_ENTRY("%p", arg); 476 477 490 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 478 499 ASSERT( conn->cc_proto == IPPROTO_TCP ); 479 500 ASSERT( conn->cc_tls == 0 ); … … 548 569 549 570 TRACE_ENTRY("%p", arg); 550 551 571 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 552 580 ASSERT( conn->cc_proto == IPPROTO_SCTP ); 553 581 ASSERT( conn->cc_tls == 0 ); … … 607 635 int fd_tls_rcvthr_core(struct cnxctx * conn, gnutls_session_t session) 608 636 { 609 /* No guarant ythat 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 */ 610 638 do { 611 639 uint8_t header[4]; … … 616 644 617 645 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); 619 647 if (ret == 0) { 620 648 /* The connection is closed */ … … 640 668 while (received < length) { 641 669 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); 643 671 pthread_cleanup_pop(0); 644 672 … … 664 692 665 693 TRACE_ENTRY("%p", arg); 666 667 694 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 668 703 ASSERT( conn->cc_tls == 1 ); 669 704 ASSERT( Target_Queue(conn) ); … … 709 744 710 745 /* Prepare a gnutls session object for handshake */ 711 int fd_tls_prepare(gnutls_session_t * session, int mode, char * priority )746 int fd_tls_prepare(gnutls_session_t * session, int mode, char * priority, void * alt_creds) 712 747 { 713 748 /* Create the master session context */ … … 724 759 725 760 /* 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 ); 727 762 728 763 /* Request the remote credentials as well */ … … 735 770 736 771 /* 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 )772 int fd_cnx_handshake(struct cnxctx * conn, int mode, char * priority, void * alt_creds) 738 773 { 739 774 TRACE_ENTRY( "%p %d", conn, mode); … … 750 785 751 786 /* 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) ); 753 788 754 789 /* Special case: multi-stream TLS is not natively managed in GNU TLS, we use a wrapper library */ … … 801 836 #ifndef DISABLE_SCTP 802 837 /* 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 805 843 /* Start decrypting the messages from all threads and queuing them in target queue */ 806 844 CHECK_FCT(fd_sctps_startthreads(conn)); 807 845 #endif /* DISABLE_SCTP */ 808 846 } else { 847 /* Mark the connection as protected from here */ 848 conn->cc_tls = 1; 849 809 850 /* Start decrypting the data */ 810 851 CHECK_POSIX( pthread_create( &conn->cc_rcvthr, NULL, rcvthr_tls_single, conn ) ); 811 852 } 812 853 813 854 return 0; 814 855 }
Note: See TracChangeset
for help on using the changeset viewer.