Changeset 706:4ffbc9f1e922 in freeDiameter for libfdcore/cnxctx.c
- Timestamp:
- Feb 9, 2011, 3:26:58 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdcore/cnxctx.c
r662 r706 51 51 */ 52 52 53 /* Note: this file could be moved to libfreeDiameter instead, but since it uses gnuTLS we prefer to keep it in the daemon */54 55 53 /* Lifetime of a cnxctx object: 56 54 * 1) Creation … … 158 156 TRACE_DEBUG(INFO, "This function should never been called when SCTP is disabled..."); 159 157 ASSERT(0); 160 CHECK_FCT_DO( ENOTSUP, ); 161 return NULL; 158 CHECK_FCT_DO( ENOTSUP, return NULL); 162 159 #else /* DISABLE_SCTP */ 163 160 struct cnxctx * cnx = NULL; … … 249 246 int rc; 250 247 251 /* Numeric values for debug */252 248 rc = getnameinfo((sSA *)&ss, sSAlen(&ss), addrbuf, sizeof(addrbuf), portbuf, sizeof(portbuf), NI_NUMERICHOST | NI_NUMERICSERV); 253 249 if (rc) { … … 256 252 } 257 253 258 snprintf(cli->cc_id, sizeof(cli->cc_id), "{%s} (%d) <- [%s]:%s (%d)", 259 IPPROTO_NAME(cli->cc_proto), serv->cc_socket, 260 addrbuf, portbuf, cli->cc_socket); 261 262 /* Name for log messages */ 254 /* Numeric values for debug... */ 255 snprintf(cli->cc_id, sizeof(cli->cc_id), "%s from [%s]:%s (%d<-%d)", 256 IPPROTO_NAME(cli->cc_proto), addrbuf, portbuf, serv->cc_socket, cli->cc_socket); 257 258 259 /* ...Name for log messages */ 263 260 rc = getnameinfo((sSA *)&ss, sSAlen(&ss), cli->cc_remid, sizeof(cli->cc_remid), NULL, 0, 0); 264 261 if (rc) … … 334 331 int rc; 335 332 336 /* Numeric values for debug */333 /* Numeric values for debug... */ 337 334 rc = getnameinfo(sa, addrlen, addrbuf, sizeof(addrbuf), portbuf, sizeof(portbuf), NI_NUMERICHOST | NI_NUMERICSERV); 338 335 if (rc) { … … 341 338 } 342 339 343 snprintf(cnx->cc_id, sizeof(cnx->cc_id), " {TCP} ->[%s]:%s (%d)", addrbuf, portbuf, cnx->cc_socket);344 345 /* Name for log messages */340 snprintf(cnx->cc_id, sizeof(cnx->cc_id), "TCP to [%s]:%s (%d)", addrbuf, portbuf, cnx->cc_socket); 341 342 /* ...Name for log messages */ 346 343 rc = getnameinfo(sa, addrlen, cnx->cc_remid, sizeof(cnx->cc_remid), NULL, 0, 0); 347 344 if (rc) … … 356 353 { 357 354 #ifdef DISABLE_SCTP 358 TRACE_DEBUG(INFO, "This function should never be encalled when SCTP is disabled...");355 TRACE_DEBUG(INFO, "This function should never be called when SCTP is disabled..."); 359 356 ASSERT(0); 360 CHECK_FCT_DO( ENOTSUP, ); 361 return NULL; 357 CHECK_FCT_DO( ENOTSUP, return NULL); 362 358 #else /* DISABLE_SCTP */ 363 359 int sock = 0; … … 416 412 int rc; 417 413 418 /* Numeric values for debug */414 /* Numeric values for debug... */ 419 415 rc = getnameinfo((sSA *)&primary, sSAlen(&primary), addrbuf, sizeof(addrbuf), portbuf, sizeof(portbuf), NI_NUMERICHOST | NI_NUMERICSERV); 420 416 if (rc) { … … 423 419 } 424 420 425 snprintf(cnx->cc_id, sizeof(cnx->cc_id), " {SCTP} ->[%s]:%s (%d)", addrbuf, portbuf, cnx->cc_socket);426 427 /* Name for log messages */421 snprintf(cnx->cc_id, sizeof(cnx->cc_id), "SCTP to [%s]:%s (%d)", addrbuf, portbuf, cnx->cc_socket); 422 423 /* ...Name for log messages */ 428 424 rc = getnameinfo((sSA *)&primary, sSAlen(&primary), cnx->cc_remid, sizeof(cnx->cc_remid), NULL, 0, 0); 429 425 if (rc) … … 454 450 455 451 /* Set the hostname to check during handshake */ 456 void fd_cnx_sethostname(struct cnxctx * conn, char *hn)452 void fd_cnx_sethostname(struct cnxctx * conn, DiamId_t hn) 457 453 { 458 454 CHECK_PARAMS_DO( conn, return ); … … 460 456 } 461 457 458 /* We share a lock with many threads but we hold it only very short time so it is OK */ 459 static pthread_mutex_t state_lock = PTHREAD_MUTEX_INITIALIZER; 460 uint32_t fd_cnx_getstate(struct cnxctx * conn) 461 { 462 uint32_t st; 463 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); 464 st = conn->cc_state; 465 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); 466 return st; 467 } 468 int fd_cnx_teststate(struct cnxctx * conn, uint32_t flag) 469 { 470 uint32_t st; 471 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); 472 st = conn->cc_state; 473 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); 474 return st & flag; 475 } 476 void fd_cnx_addstate(struct cnxctx * conn, uint32_t orstate) 477 { 478 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); 479 conn->cc_state |= orstate; 480 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); 481 } 482 void fd_cnx_setstate(struct cnxctx * conn, uint32_t abstate) 483 { 484 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); 485 conn->cc_state = abstate; 486 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); 487 } 488 489 462 490 /* Return the TLS state of a connection */ 463 491 int fd_cnx_getTLS(struct cnxctx * conn) 464 492 { 465 493 CHECK_PARAMS_DO( conn, return 0 ); 466 fd_cpu_flush_cache(); 467 return conn->cc_status & CC_STATUS_TLS; 468 } 494 return fd_cnx_teststate(conn, CC_STATUS_TLS); 495 } 496 497 /* Return true if the connection supports unordered delivery of messages */ 498 int fd_cnx_isMultichan(struct cnxctx * conn) 499 { 500 CHECK_PARAMS_DO( conn, return 0 ); 501 #ifdef DISABLE_SCTP 502 if (conn->cc_proto == IPPROTO_SCTP) 503 return (conn->cc_sctp_para.str_in > 1) || (conn->cc_sctp_para.str_out > 1); 504 #endif /* DISABLE_SCTP */ 505 return 0; 506 } 507 469 508 470 509 /* Get the list of endpoints (IP addresses) of the local and remote peers on this connection */ … … 508 547 } 509 548 510 /* Retrieve a list of all IP addresses of the local system from the kernel, using */549 /* Retrieve a list of all IP addresses of the local system from the kernel, using getifaddrs */ 511 550 int fd_cnx_get_local_eps(struct fd_list * list) 512 551 { 513 552 struct ifaddrs *iflist, *cur; 553 514 554 CHECK_SYS(getifaddrs(&iflist)); 515 555 … … 543 583 CHECK_PARAMS_DO( conn, goto fatal ); 544 584 545 TRACE_DEBUG(FULL, "Error flag set for socket %d (%s / %s)", conn->cc_socket, conn->cc_remid, conn->cc_id);585 TRACE_DEBUG(FULL, "Error flag set for socket %d (%s, %s)", conn->cc_socket, conn->cc_id, conn->cc_remid); 546 586 547 587 /* Mark the error */ 548 fd_cpu_flush_cache(); 549 conn->cc_status |= CC_STATUS_ERROR; 588 fd_cnx_addstate(conn, CC_STATUS_ERROR); 550 589 551 590 /* Report the error if not reported yet, and not closing */ 552 if ( (!(conn->cc_status & CC_STATUS_CLOSING )) && (!(conn->cc_status & CC_STATUS_SIGNALED ))) {591 if (!fd_cnx_teststate(conn, CC_STATUS_CLOSING | CC_STATUS_SIGNALED )) { 553 592 TRACE_DEBUG(FULL, "Sending FDEVP_CNX_ERROR event"); 554 CHECK_FCT_DO( fd_event_send( Target_Queue(conn), FDEVP_CNX_ERROR, 0, NULL), goto fatal); 555 conn->cc_status |= CC_STATUS_SIGNALED; 556 } 557 fd_cpu_flush_cache(); 593 CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), FDEVP_CNX_ERROR, 0, NULL), goto fatal); 594 fd_cnx_addstate(conn, CC_STATUS_SIGNALED); 595 } 558 596 return; 559 597 fatal: 560 598 /* An unrecoverable error occurred, stop the daemon */ 599 ASSERT(0); 561 600 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), ); 562 601 } … … 583 622 /* Handle special case of timeout */ 584 623 if ((ret < 0) && (errno == EAGAIN)) { 585 fd_cpu_flush_cache(); 586 if (! (conn->cc_status & CC_STATUS_CLOSING)) 624 if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING )) 587 625 goto again; /* don't care, just ignore */ 588 626 if (!timedout) { … … 592 630 } 593 631 594 CHECK_SYS_DO(ret, /* continue */);595 596 632 /* Mark the error */ 597 if (ret <= 0) 633 if (ret <= 0) { 634 CHECK_SYS_DO(ret, /* continue, this is only used to log the error here */); 598 635 fd_cnx_markerror(conn); 636 } 599 637 600 638 return ret; … … 610 648 /* Handle special case of timeout */ 611 649 if ((ret < 0) && (errno == EAGAIN)) { 612 fd_cpu_flush_cache(); 613 if (! (conn->cc_status & CC_STATUS_CLOSING)) 650 if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING )) 614 651 goto again; /* don't care, just ignore */ 615 652 if (!timedout) { … … 643 680 644 681 ASSERT( conn->cc_proto == IPPROTO_TCP ); 645 ASSERT( ! (conn->cc_status & CC_STATUS_TLS) );646 ASSERT( Target_Queue(conn) );682 ASSERT( ! fd_cnx_teststate(conn, CC_STATUS_TLS ) ); 683 ASSERT( fd_cnx_target_queue(conn) ); 647 684 648 685 /* Receive from a TCP connection: we have to rebuild the message boundaries */ … … 666 703 667 704 /* Check the received word is a valid begining of a Diameter message */ 668 if ((header[0] != DIAMETER_VERSION) /* defined in <libf reeDiameter.h> */705 if ((header[0] != DIAMETER_VERSION) /* defined in <libfdproto.h> */ 669 706 || (length > DIAMETER_MSG_SIZE_MAX)) { /* to avoid too big mallocs */ 670 707 /* The message is suspect */ … … 691 728 692 729 /* We have received a complete message, pass it to the daemon */ 693 fd_cpu_flush_cache(); 694 CHECK_FCT_DO( fd_event_send( Target_Queue(conn), FDEVP_CNX_MSG_RECV, length, newmsg), /* continue or destroy everything? */); 730 CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), FDEVP_CNX_MSG_RECV, length, newmsg), /* continue or destroy everything? */); 695 731 696 732 } while (conn->cc_loop); … … 726 762 727 763 ASSERT( conn->cc_proto == IPPROTO_SCTP ); 728 ASSERT( ! (conn->cc_status & CC_STATUS_TLS) );729 ASSERT( Target_Queue(conn) );764 ASSERT( ! fd_cnx_teststate(conn, CC_STATUS_TLS ) ); 765 ASSERT( fd_cnx_target_queue(conn) ); 730 766 731 767 do { 732 fd_cpu_flush_cache(); 733 CHECK_FCT_DO( fd_sctp_recvmeta(conn->cc_socket, NULL, &buf, &bufsz, &event, &conn->cc_status), goto fatal ); 768 CHECK_FCT_DO( fd_sctp_recvmeta(conn, NULL, &buf, &bufsz, &event), goto fatal ); 734 769 if (event == FDEVP_CNX_ERROR) { 735 770 fd_cnx_markerror(conn); … … 742 777 } 743 778 744 fd_cpu_flush_cache(); 745 CHECK_FCT_DO( fd_event_send( Target_Queue(conn), event, bufsz, buf), goto fatal ); 779 CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), event, bufsz, buf), goto fatal ); 746 780 747 781 } while (conn->cc_loop || (event != FDEVP_CNX_MSG_RECV)); … … 763 797 TRACE_ENTRY("%p %i", conn, loop); 764 798 765 CHECK_PARAMS( conn && Target_Queue(conn) && (!(conn->cc_status &CC_STATUS_TLS)) && (!conn->cc_loop));799 CHECK_PARAMS( conn && fd_cnx_target_queue(conn) && (!fd_cnx_teststate(conn, CC_STATUS_TLS)) && (!conn->cc_loop)); 766 800 767 801 /* Release resources in case of a previous call was already made */ … … 803 837 switch (ret) { 804 838 case GNUTLS_E_REHANDSHAKE: 805 fd_cpu_flush_cache(); 806 if (!(conn->cc_status & CC_STATUS_CLOSING)) 839 if (!fd_cnx_teststate(conn, CC_STATUS_CLOSING)) 807 840 CHECK_GNUTLS_DO( ret = gnutls_handshake(session), 808 841 { … … 815 848 case GNUTLS_E_AGAIN: 816 849 case GNUTLS_E_INTERRUPTED: 817 fd_cpu_flush_cache(); 818 if (!(conn->cc_status & CC_STATUS_CLOSING)) 850 if (!fd_cnx_teststate(conn, CC_STATUS_CLOSING)) 819 851 goto again; 820 852 TRACE_DEBUG(FULL, "Connection is closing, so abord gnutls_record_recv now."); … … 849 881 switch (ret) { 850 882 case GNUTLS_E_REHANDSHAKE: 851 fd_cpu_flush_cache(); 852 if (!(conn->cc_status & CC_STATUS_CLOSING)) 883 if (!fd_cnx_teststate(conn, CC_STATUS_CLOSING)) 853 884 CHECK_GNUTLS_DO( ret = gnutls_handshake(session), 854 885 { … … 861 892 case GNUTLS_E_AGAIN: 862 893 case GNUTLS_E_INTERRUPTED: 863 fd_cpu_flush_cache(); 864 if (!(conn->cc_status & CC_STATUS_CLOSING)) 894 if (!fd_cnx_teststate(conn, CC_STATUS_CLOSING)) 865 895 goto again; 866 896 TRACE_DEBUG(INFO, "Connection is closing, so abord gnutls_record_send now."); … … 927 957 928 958 /* We have received a complete message, pass it to the daemon */ 929 fd_cpu_flush_cache(); 930 CHECK_FCT_DO( ret = fd_event_send( Target_Queue(conn), FDEVP_CNX_MSG_RECV, length, newmsg), 959 CHECK_FCT_DO( ret = fd_event_send( fd_cnx_target_queue(conn), FDEVP_CNX_MSG_RECV, length, newmsg), 931 960 { 932 961 free(newmsg); … … 956 985 } 957 986 958 ASSERT( conn->cc_status & CC_STATUS_TLS);959 ASSERT( Target_Queue(conn) );987 ASSERT( fd_cnx_teststate(conn, CC_STATUS_TLS) ); 988 ASSERT( fd_cnx_target_queue(conn) ); 960 989 961 990 /* The next function only returns when there is an error on the socket */ … … 1215 1244 { 1216 1245 TRACE_ENTRY( "%p %d %p %p", conn, mode, priority, alt_creds); 1217 CHECK_PARAMS( conn && (! (conn->cc_status &CC_STATUS_TLS)) && ( (mode == GNUTLS_CLIENT) || (mode == GNUTLS_SERVER) ) && (!conn->cc_loop) );1246 CHECK_PARAMS( conn && (!fd_cnx_teststate(conn, CC_STATUS_TLS)) && ( (mode == GNUTLS_CLIENT) || (mode == GNUTLS_SERVER) ) && (!conn->cc_loop) ); 1218 1247 1219 1248 /* Save the mode */ … … 1248 1277 1249 1278 /* Mark the connection as protected from here, so that the gnutls credentials will be freed */ 1250 fd_cpu_flush_cache(); 1251 conn->cc_status |= CC_STATUS_TLS; 1252 1279 fd_cnx_addstate(conn, CC_STATUS_TLS); 1280 1253 1281 /* Handshake master session */ 1254 1282 { … … 1299 1327 { 1300 1328 TRACE_ENTRY("%p %p %p", conn, cert_list, cert_list_size); 1301 CHECK_PARAMS( conn && (conn->cc_status &CC_STATUS_TLS) && cert_list && cert_list_size );1329 CHECK_PARAMS( conn && fd_cnx_teststate(conn, CC_STATUS_TLS) && cert_list && cert_list_size ); 1302 1330 1303 1331 /* This function only works for X.509 certificates. */ … … 1360 1388 } 1361 1389 1390 /* Where the events are sent */ 1391 struct fifo * fd_cnx_target_queue(struct cnxctx * conn) 1392 { 1393 struct fifo *q; 1394 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); 1395 q = conn->cc_alt ?: conn->cc_incoming; 1396 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); 1397 return q; 1398 } 1399 1362 1400 /* Set an alternate FIFO list to send FDEVP_CNX_* events to */ 1363 1401 int fd_cnx_recv_setaltfifo(struct cnxctx * conn, struct fifo * alt_fifo) 1364 1402 { 1403 int ret; 1365 1404 TRACE_ENTRY( "%p %p", conn, alt_fifo ); 1366 1405 CHECK_PARAMS( conn && alt_fifo && conn->cc_incoming ); 1367 1406 1368 1407 /* The magic function does it all */ 1369 CHECK_FCT( fd_fifo_move( conn->cc_incoming, alt_fifo, &conn->cc_alt ) ); 1370 1371 return 0; 1408 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); 1409 CHECK_FCT_DO( ret = fd_fifo_move( conn->cc_incoming, alt_fifo, &conn->cc_alt ), ); 1410 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); 1411 1412 return ret; 1372 1413 } 1373 1414 … … 1379 1420 TRACE_ENTRY("%p %p %zd", conn, buf, len); 1380 1421 do { 1381 fd_cpu_flush_cache(); 1382 if (conn->cc_status & CC_STATUS_TLS) { 1422 if (fd_cnx_teststate(conn, CC_STATUS_TLS)) { 1383 1423 CHECK_GNUTLS_DO( ret = fd_tls_send_handle_error(conn, conn->cc_tls_para.session, buf + sent, len - sent), ); 1384 1424 } else { … … 1394 1434 } 1395 1435 1396 /* Send a message -- this is synchronous -- and we assume it's never called by several threads at the same time , so we don't protect. */1436 /* Send a message -- this is synchronous -- and we assume it's never called by several threads at the same time (on the same conn), so we don't protect. */ 1397 1437 int fd_cnx_send(struct cnxctx * conn, unsigned char * buf, size_t len, uint32_t flags) 1398 1438 { 1399 1439 TRACE_ENTRY("%p %p %zd %x", conn, buf, len, flags); 1400 1440 1401 CHECK_PARAMS(conn && (conn->cc_socket > 0) && (! (conn->cc_status &CC_STATUS_ERROR)) && buf && len);1402 1403 TRACE_DEBUG(FULL, "Sending %zdb %sdata on connection %s", len, (conn->cc_status &CC_STATUS_TLS) ? "TLS-protected ":"", conn->cc_id);1441 CHECK_PARAMS(conn && (conn->cc_socket > 0) && (! fd_cnx_teststate(conn, CC_STATUS_ERROR)) && buf && len); 1442 1443 TRACE_DEBUG(FULL, "Sending %zdb %sdata on connection %s", len, fd_cnx_teststate(conn, CC_STATUS_TLS) ? "TLS-protected ":"", conn->cc_id); 1404 1444 1405 1445 switch (conn->cc_proto) { … … 1410 1450 #ifndef DISABLE_SCTP 1411 1451 case IPPROTO_SCTP: { 1412 if (flags & FD_CNX_BROADCAST) {1413 /* Send the buffer over all other streams */1414 uint16_t str;1415 fd_cpu_flush_cache();1416 if (conn->cc_status & CC_STATUS_TLS) {1417 for ( str=1; str < conn->cc_sctp_para.pairs; str++) {1418 ssize_t ret;1419 size_t sent = 0;1420 do {1421 CHECK_GNUTLS_DO( ret = fd_tls_send_handle_error(conn, conn->cc_sctps_data.array[str].session, buf + sent, len - sent), );1422 if (ret <= 0)1423 return ENOTCONN;1424 1425 sent += ret;1426 } while ( sent < len );1427 }1428 } else {1429 for ( str=1; str < conn->cc_sctp_para.str_out; str++) {1430 CHECK_FCT_DO( fd_sctp_sendstr(conn->cc_socket, str, buf, len, &conn->cc_status), { fd_cnx_markerror(conn); return ENOTCONN; } );1431 }1432 }1433 1434 /* Set the ORDERED flag also so that it is sent over stream 0 as well */1435 flags &= FD_CNX_ORDERED;1436 }1437 1438 1452 if (flags & FD_CNX_ORDERED) { 1439 1453 /* We send over stream #0 */ … … 1444 1458 int another_str = 0; /* do we send over stream #0 ? */ 1445 1459 1446 if ((conn->cc_sctp_para.str_out > 1) && ((! (conn->cc_status &CC_STATUS_TLS)) || (conn->cc_sctp_para.pairs > 1))) {1460 if ((conn->cc_sctp_para.str_out > 1) && ((!fd_cnx_teststate(conn, CC_STATUS_TLS)) || (conn->cc_sctp_para.pairs > 1))) { 1447 1461 /* Update the id of the stream we will send this message over */ 1448 1462 conn->cc_sctp_para.next += 1; 1449 conn->cc_sctp_para.next %= ( (conn->cc_status &CC_STATUS_TLS) ? conn->cc_sctp_para.pairs : conn->cc_sctp_para.str_out);1463 conn->cc_sctp_para.next %= (fd_cnx_teststate(conn, CC_STATUS_TLS) ? conn->cc_sctp_para.pairs : conn->cc_sctp_para.str_out); 1450 1464 another_str = (conn->cc_sctp_para.next ? 1 : 0); 1451 1465 } … … 1454 1468 CHECK_FCT( send_simple(conn, buf, len) ); 1455 1469 } else { 1456 if (! (conn->cc_status &CC_STATUS_TLS)) {1457 CHECK_FCT_DO( fd_sctp_sendstr(conn ->cc_socket, conn->cc_sctp_para.next, buf, len, &conn->cc_status), { fd_cnx_markerror(conn); return ENOTCONN; } );1470 if (!fd_cnx_teststate(conn, CC_STATUS_TLS)) { 1471 CHECK_FCT_DO( fd_sctp_sendstr(conn, conn->cc_sctp_para.next, buf, len), { fd_cnx_markerror(conn); return ENOTCONN; } ); 1458 1472 } else { 1459 1473 /* push the record to the appropriate session */ … … 1496 1510 CHECK_PARAMS_DO(conn, return); 1497 1511 1498 fd_cpu_flush_cache(); 1499 conn->cc_status |= CC_STATUS_CLOSING; 1512 fd_cnx_addstate(conn, CC_STATUS_CLOSING); 1500 1513 1501 1514 /* Initiate shutdown of the TLS session(s): call gnutls_bye(WR), then read until error */ 1502 if ( conn->cc_status & CC_STATUS_TLS) {1515 if (fd_cnx_teststate(conn, CC_STATUS_TLS)) { 1503 1516 #ifndef DISABLE_SCTP 1504 1517 if (conn->cc_sctp_para.pairs > 1) { 1505 if (! (conn->cc_status &CC_STATUS_ERROR )) {1518 if (! fd_cnx_teststate(conn, CC_STATUS_ERROR )) { 1506 1519 /* Bye on master session */ 1507 1520 CHECK_GNUTLS_DO( gnutls_bye(conn->cc_tls_para.session, GNUTLS_SHUT_WR), fd_cnx_markerror(conn) ); 1508 1521 } 1509 1522 1510 if (! (conn->cc_status &CC_STATUS_ERROR ) ) {1523 if (! fd_cnx_teststate(conn, CC_STATUS_ERROR ) ) { 1511 1524 /* and other stream pairs */ 1512 1525 fd_sctps_bye(conn); 1513 1526 } 1514 1527 1515 if (! (conn->cc_status &CC_STATUS_ERROR ) ) {1528 if (! fd_cnx_teststate(conn, CC_STATUS_ERROR ) ) { 1516 1529 /* Now wait for all decipher threads to terminate */ 1517 1530 fd_sctps_waitthreadsterm(conn); … … 1533 1546 } else { 1534 1547 #endif /* DISABLE_SCTP */ 1535 /* We are not using the sctps wrapper layer */1536 if (! (conn->cc_status &CC_STATUS_ERROR ) ) {1548 /* We are TLS, but not using the sctps wrapper layer */ 1549 if (! fd_cnx_teststate(conn, CC_STATUS_ERROR ) ) { 1537 1550 /* Master session */ 1538 1551 CHECK_GNUTLS_DO( gnutls_bye(conn->cc_tls_para.session, GNUTLS_SHUT_WR), fd_cnx_markerror(conn) ); 1539 1552 } 1540 1553 1541 if (! (conn->cc_status &CC_STATUS_ERROR ) ) {1554 if (! fd_cnx_teststate(conn, CC_STATUS_ERROR ) ) { 1542 1555 /* In this case, just wait for thread rcvthr_tls_single to terminate */ 1543 1556 if (conn->cc_rcvthr != (pthread_t)NULL) { … … 1555 1568 conn->cc_tls_para.session = NULL; 1556 1569 } 1557 1558 1570 #ifndef DISABLE_SCTP 1559 1571 }
Note: See TracChangeset
for help on using the changeset viewer.