Changeset 1103:d8591b1c56cd in freeDiameter for libfdcore/p_ce.c
- Timestamp:
- May 10, 2013, 7:48:57 PM (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdcore/p_ce.c
r1078 r1103 671 671 fd_cnx_destroy(initiator); 672 672 673 LOG_D("%s: Election lost on outgoing connection, closing and answering CEA on incoming connection.", peer->p_hdr.info.pi_diamid); 674 673 675 /* Process with the receiver side */ 674 676 CHECK_FCT( fd_p_ce_process_receiver(peer) ); … … 678 680 memset(&pei, 0, sizeof(pei)); 679 681 pei.pei_errcode = "ELECTION_LOST"; 682 pei.pei_message = "Please answer my CER instead, you won the election."; 683 LOG_D("%s: Election lost on incoming connection, closing and waiting for CEA on outgoing connection.", peer->p_hdr.info.pi_diamid); 680 684 681 685 /* Answer an ELECTION LOST to the receiver side */ … … 720 724 if (req || ((st = fd_peer_getstate(peer)) != STATE_WAITCEA)) { 721 725 if (*msg) { 722 //fd_msg_log( FD_MSG_LOG_DROPPED, *msg, "Received CER/CEA while in '%s' state.", STATE_STR(st)); 726 /* In such case, just discard the message */ 727 char buf[128]; 728 snprintf(buf, sizeof(buf), "Received while peer state machine was in state %s.", STATE_STR(st)); 729 fd_hook_call(HOOK_MESSAGE_DROPPED, *msg, peer, buf, fd_msg_pmdl_get(*msg)); 730 723 731 CHECK_FCT_DO( fd_msg_free(*msg), /* continue */); 724 732 *msg = NULL; … … 731 739 732 740 /* Save info from the CEA into the peer */ 733 CHECK_FCT_DO( save_remote_CE_info(*msg, peer, &pei, &rc), goto cleanup );734 735 /* Dispose of the message, we don't need it anymore */736 CHECK_FCT_DO( fd_msg_free(*msg), /* continue */ );737 *msg = NULL;741 CHECK_FCT_DO( save_remote_CE_info(*msg, peer, &pei, &rc), 742 { 743 fd_hook_call(HOOK_PEER_CONNECT_FAILED, *msg, peer, "An error occurred while processing incoming CEA.", NULL); 744 goto cleanup; 745 } ); 738 746 739 747 /* Check the Result-Code */ 740 748 switch (rc) { 741 749 case ER_DIAMETER_SUCCESS: 750 /* Log success */ 751 fd_hook_call(HOOK_PEER_CONNECT_SUCCESS, *msg, peer, NULL, NULL); 752 753 /* Dispose of the message, we don't need it anymore */ 754 CHECK_FCT_DO( fd_msg_free(*msg), /* continue */ ); 755 *msg = NULL; 756 742 757 /* No problem, we can continue */ 743 758 break; … … 745 760 case ER_DIAMETER_TOO_BUSY: 746 761 /* Retry later */ 747 TRACE_DEBUG(INFO, "Peer %s replied a CEA with Result-Code AVP DIAMETER_TOO_BUSY, will retry later.", peer->p_hdr.info.pi_diamid);762 fd_hook_call(HOOK_PEER_CONNECT_FAILED, *msg, peer, "Remote peer is too busy", NULL); 748 763 fd_psm_cleanup(peer, 0); 749 764 fd_psm_next_timeout(peer, 0, 300); … … 757 772 default: 758 773 /* In any other case, we abort all attempts to connect to this peer */ 759 TRACE_DEBUG(INFO, "Peer %s replied a CEA with Result-Code %d, aborting connection attempts.", peer->p_hdr.info.pi_diamid, rc);774 fd_hook_call(HOOK_PEER_CONNECT_FAILED, *msg, peer, "CEA with unexpected error code", NULL); 760 775 return EINVAL; 761 776 } 777 762 778 763 779 /* Handshake if needed, start clear otherwise */ … … 778 794 { 779 795 /* Handshake failed ... */ 780 fd_ log_debug("TLS Handshake failed with peer '%s', resetting the connection", peer->p_hdr.info.pi_diamid);796 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, peer, "TLS handshake failed after CER/CEA exchange", NULL); 781 797 goto cleanup; 782 798 } ); … … 818 834 TRACE_ENTRY("%p", peer); 819 835 820 CHECK_FCT( set_peer_cnx(peer, &peer->p_receiver) ); 836 CHECK_FCT_DO( set_peer_cnx(peer, &peer->p_receiver), 837 { 838 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, peer, "Error saving the incoming connection in the peer structure", NULL); 839 return __ret__; 840 } ); 821 841 msg = peer->p_cer; 822 842 peer->p_cer = NULL; … … 928 948 CHECK_FCT( fd_msg_rescode_set(msg, "DIAMETER_SUCCESS", NULL, NULL, 0 ) ); 929 949 CHECK_FCT( add_CE_info(msg, peer->p_cnxctx, isi & PI_SEC_TLS_OLD, isi & PI_SEC_NONE) ); 950 951 /* The connection is complete, but we may still need TLS handshake */ 952 fd_hook_call(HOOK_PEER_CONNECT_SUCCESS, msg, peer, NULL, NULL); 953 930 954 CHECK_FCT( fd_out_send(&msg, peer->p_cnxctx, peer, FD_CNX_ORDERED ) ); 931 955 … … 936 960 { 937 961 /* Handshake failed ... */ 938 fd_ log_debug("TLS Handshake failed with peer '%s', resetting the connection", peer->p_hdr.info.pi_diamid);962 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, peer, "TLS handshake failed after CER/CEA exchange", NULL); 939 963 goto cleanup; 940 964 } ); 941 965 942 966 /* Retrieve the credentials */ 943 CHECK_FCT( fd_cnx_getcred(peer->p_cnxctx, &peer->p_hdr.info.runtime.pir_cert_list, &peer->p_hdr.info.runtime.pir_cert_list_size) ); 967 CHECK_FCT_DO( fd_cnx_getcred(peer->p_cnxctx, &peer->p_hdr.info.runtime.pir_cert_list, &peer->p_hdr.info.runtime.pir_cert_list_size), 968 { 969 /* Error ... */ 970 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, peer, "Unable to retrieve remote credentials after TLS handshake", NULL); 971 goto cleanup; 972 } ); 973 944 974 945 975 /* Call second validation callback if needed */ … … 948 978 CHECK_FCT_DO( (*peer->p_cb2)( &peer->p_hdr.info ), 949 979 { 950 TRACE_DEBUG(INFO, "Validation callback rejected the peer %s after handshake", peer->p_hdr.info.pi_diamid);980 fd_hook_call(HOOK_PEER_CONNECT_FAILED, NULL, peer, "Validation callback rejected the peer after handshake", NULL); 951 981 CHECK_FCT( fd_psm_terminate( peer, "DO_NOT_WANT_TO_TALK_TO_YOU" ) ); 952 982 return 0; … … 982 1012 if (pei.pei_errcode) { 983 1013 /* Send the error */ 1014 fd_hook_call(HOOK_PEER_CONNECT_FAILED, msg, peer, pei.pei_message ?: pei.pei_errcode, NULL); 984 1015 receiver_reject(&peer->p_cnxctx, &msg, &pei); 1016 } else { 1017 char buf[1024]; 1018 snprintf(buf, sizeof(buf), "Unexpected error occurred while processing incoming connection from '%s'.", peer->p_hdr.info.pi_diamid); 1019 fd_hook_call(HOOK_PEER_CONNECT_FAILED, msg, peer, buf, NULL); 985 1020 } 986 1021 987 1022 cleanup: 988 1023 if (msg) { 989 //fd_msg_log(FD_MSG_LOG_DROPPED, msg, "An error occurred while processing a CER.");990 1024 fd_msg_free(msg); 991 1025 } … … 1027 1061 1028 1062 /* Close initiator connection (was already set as principal) */ 1063 LOG_D("%s: Election lost on outgoing connection, closing and answering CEA on incoming connection.", peer->p_hdr.info.pi_diamid); 1029 1064 fd_p_ce_clear_cnx(peer, NULL); 1030 1065 … … 1041 1076 pei.pei_errcode = "ELECTION_LOST"; 1042 1077 pei.pei_message = "Please answer my CER instead, you won the election."; 1078 LOG_D("%s: Election lost on incoming connection, closing and waiting for CEA on outgoing connection.", peer->p_hdr.info.pi_diamid); 1043 1079 receiver_reject(cnx, msg, &pei); 1044 1080 } … … 1048 1084 pei.pei_errcode = "DIAMETER_UNABLE_TO_COMPLY"; /* INVALID COMMAND? in case of Capabilities-Updates? */ 1049 1085 pei.pei_message = "Invalid state to receive a new connection attempt."; 1086 LOG_E("%s: Rejecting new connection attempt while our state machine is in state '%s'", peer->p_hdr.info.pi_diamid, STATE_STR(cur_state)); 1050 1087 receiver_reject(cnx, msg, &pei); 1051 1088 }
Note: See TracChangeset
for help on using the changeset viewer.