Navigation


Changeset 1103:d8591b1c56cd in freeDiameter for libfdcore/p_ce.c


Ignore:
Timestamp:
May 10, 2013, 7:48:57 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Implemented a few hooks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/p_ce.c

    r1078 r1103  
    671671                        fd_cnx_destroy(initiator);
    672672
     673                        LOG_D("%s: Election lost on outgoing connection, closing and answering CEA on incoming connection.", peer->p_hdr.info.pi_diamid);
     674                       
    673675                        /* Process with the receiver side */
    674676                        CHECK_FCT( fd_p_ce_process_receiver(peer) );
     
    678680                        memset(&pei, 0, sizeof(pei));
    679681                        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);
    680684
    681685                        /* Answer an ELECTION LOST to the receiver side */
     
    720724        if (req || ((st = fd_peer_getstate(peer)) != STATE_WAITCEA)) {
    721725                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
    723731                        CHECK_FCT_DO( fd_msg_free(*msg), /* continue */);
    724732                        *msg = NULL;
     
    731739       
    732740        /* 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                } );
    738746       
    739747        /* Check the Result-Code */
    740748        switch (rc) {
    741749                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                       
    742757                        /* No problem, we can continue */
    743758                        break;
     
    745760                case ER_DIAMETER_TOO_BUSY:
    746761                        /* 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);
    748763                        fd_psm_cleanup(peer, 0);
    749764                        fd_psm_next_timeout(peer, 0, 300);
     
    757772                default:
    758773                        /* 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);
    760775                        return EINVAL;
    761776        }
     777       
    762778       
    763779        /* Handshake if needed, start clear otherwise */
     
    778794                                {
    779795                                        /* 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);
    781797                                        goto cleanup;
    782798                                } );
     
    818834        TRACE_ENTRY("%p", peer);
    819835       
    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                } );
    821841        msg = peer->p_cer;
    822842        peer->p_cer = NULL;
     
    928948        CHECK_FCT( fd_msg_rescode_set(msg, "DIAMETER_SUCCESS", NULL, NULL, 0 ) );
    929949        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       
    930954        CHECK_FCT( fd_out_send(&msg, peer->p_cnxctx, peer, FD_CNX_ORDERED ) );
    931955       
     
    936960                        {
    937961                                /* 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);
    939963                                goto cleanup;
    940964                        } );
    941965               
    942966                /* 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               
    944974               
    945975                /* Call second validation callback if needed */
     
    948978                        CHECK_FCT_DO( (*peer->p_cb2)( &peer->p_hdr.info ),
    949979                                {
    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);
    951981                                        CHECK_FCT( fd_psm_terminate( peer, "DO_NOT_WANT_TO_TALK_TO_YOU" ) );
    952982                                        return 0;
     
    9821012        if (pei.pei_errcode) {
    9831013                /* Send the error */
     1014                fd_hook_call(HOOK_PEER_CONNECT_FAILED, msg, peer, pei.pei_message ?: pei.pei_errcode, NULL);
    9841015                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);
    9851020        }
    9861021       
    9871022cleanup:
    9881023        if (msg) {
    989                 //fd_msg_log(FD_MSG_LOG_DROPPED, msg, "An error occurred while processing a CER.");
    9901024                fd_msg_free(msg);
    9911025        }
     
    10271061                               
    10281062                                /* 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);
    10291064                                fd_p_ce_clear_cnx(peer, NULL);
    10301065                               
     
    10411076                                pei.pei_errcode = "ELECTION_LOST";
    10421077                                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);
    10431079                                receiver_reject(cnx, msg, &pei);
    10441080                        }
     
    10481084                        pei.pei_errcode = "DIAMETER_UNABLE_TO_COMPLY"; /* INVALID COMMAND? in case of Capabilities-Updates? */
    10491085                        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));
    10501087                        receiver_reject(cnx, msg, &pei);
    10511088        }
Note: See TracChangeset for help on using the changeset viewer.