Navigation


Changeset 1113:eb4ce68b6e5c in freeDiameter for libfdcore/routing_dispatch.c


Ignore:
Timestamp:
May 13, 2013, 8:17:13 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Added calls to remaining hooks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/routing_dispatch.c

    r1103 r1113  
    393393
    394394                        if (!peer) {
    395                                 //fd_msg_log(FD_MSG_LOG_DROPPED, *pmsg, "Unable to send error '%s' to deleted peer '%s' in reply to this message.", error_code, id);
     395                                char buf[256];
     396                                snprintf(buf, sizeof(buf), "Unable to send error '%s' to deleted peer '%s' in reply to this message.", error_code, id);
     397                                fd_hook_call(HOOK_MESSAGE_DROPPED, *pmsg, NULL, buf, fd_msg_pmdl_get(*pmsg));
    396398                                fd_msg_free(*pmsg);
    397399                                *pmsg = NULL;
     
    496498
    497499        /* Now, call any callback registered for the message */
    498         CHECK_FCT( fd_msg_dispatch ( &msgptr, sess, &action, &ec) );
     500        CHECK_FCT( fd_msg_dispatch ( &msgptr, sess, &action, &ec, &em, &error) );
    499501
    500502        /* Now, act depending on msg and action and ec */
     
    505507                                if (!fd_g_config->cnf_flags.no_fwd) {
    506508                                        /* requeue to fd_g_outgoing */
     509                                        fd_hook_call(HOOK_MESSAGE_ROUTING_FORWARD, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr));
    507510                                        CHECK_FCT( fd_fifo_post(fd_g_outgoing, &msgptr) );
    508511                                        break;
     
    519522                               
    520523                                if (!is_req) {
    521                                         //fd_msg_log( FD_MSG_LOG_DROPPED, msgptr,  "Internal error: Answer received to locally issued request, but not handled by any handler.");
     524                                        fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, "Internal error: Answer received to locally issued request, but not handled by any handler.", fd_msg_pmdl_get(msgptr));
    522525                                        fd_msg_free(msgptr);
    523526                                        break;
     
    532535                                CHECK_FCT( fd_fifo_post(fd_g_outgoing, &msgptr) );
    533536                }
     537        } else if (em) {
     538                fd_hook_call(HOOK_MESSAGE_DROPPED, error, NULL, em, fd_msg_pmdl_get(error));
     539                fd_msg_free(error);
    534540        }
    535541       
     
    555561        /* Handle incorrect bits */
    556562        if (is_req && is_err) {
     563                fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "R & E bits were set", fd_msg_pmdl_get(msgptr));
    557564                CHECK_FCT( return_error( &msgptr, "DIAMETER_INVALID_HDR_BITS", "R & E bits were set", NULL) );
    558565                return 0;
     
    573580                /* Check if we have local support for the message application */
    574581                if ( (hdr->msg_appl == 0) || (hdr->msg_appl == AI_RELAY) ) {
    575                         TRACE_DEBUG(INFO, "Received a routable message with application id 0 or " _stringize(AI_RELAY) " (relay),"
    576                                           " returning DIAMETER_APPLICATION_UNSUPPORTED");
     582                        fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Received a routable message with application id 0 or " _stringize(AI_RELAY) " (relay)", fd_msg_pmdl_get(msgptr));
    577583                        CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", "Routable message with application id 0 or relay", NULL) );
    578584                        return 0;
     
    601607                                                        {
    602608                                                                if (error_info.pei_errcode) {
     609                                                                        fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error_info.pei_message ?: error_info.pei_errcode, fd_msg_pmdl_get(msgptr));
    603610                                                                        CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) );
    604611                                                                        return 0;
    605612                                                                } else {
     613                                                                        fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Unspecified error while parsing Destination-Host AVP", fd_msg_pmdl_get(msgptr));
    606614                                                                        return ret;
    607615                                                                }
     
    621629                                                        {
    622630                                                                if (error_info.pei_errcode) {
     631                                                                        fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error_info.pei_message ?: error_info.pei_errcode, fd_msg_pmdl_get(msgptr));
    623632                                                                        CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) );
    624633                                                                        return 0;
    625634                                                                } else {
     635                                                                        fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Unspecified error while parsing Destination-Realm AVP", fd_msg_pmdl_get(msgptr));
    626636                                                                        return ret;
    627637                                                                }
     
    643653                                                        {
    644654                                                                if (error_info.pei_errcode) {
     655                                                                        fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error_info.pei_message ?: error_info.pei_errcode, fd_msg_pmdl_get(msgptr));
    645656                                                                        CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) );
    646657                                                                        return 0;
    647658                                                                } else {
     659                                                                        fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Unspecified error while parsing User-Name AVP", fd_msg_pmdl_get(msgptr));
    648660                                                                        return ret;
    649661                                                                }
     
    668680                /* Handle the missing routing AVPs first */
    669681                if ( is_dest_realm == UNKNOWN ) {
     682                        fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Non-routable message not supported (invalid bit ? missing Destination-Realm ?)", fd_msg_pmdl_get(msgptr));
    670683                        CHECK_FCT( return_error( &msgptr, "DIAMETER_COMMAND_UNSUPPORTED", "Non-routable message not supported (invalid bit ? missing Destination-Realm ?)", NULL) );
    671684                        return 0;
     
    676689                        if (is_local_app == YES) {
    677690                                /* Ok, give the message to the dispatch thread */
     691                                fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr));
    678692                                CHECK_FCT( fd_fifo_post(fd_g_local, &msgptr) );
    679693                        } else {
    680694                                /* We don't support the application, reply an error */
     695                                fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Application unsupported", fd_msg_pmdl_get(msgptr));
    681696                                CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) );
    682697                        }
     
    687702                if ((is_dest_host == NO) || (is_dest_realm == NO)) {
    688703                        if (fd_g_config->cnf_flags.no_fwd) {
     704                                fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, "Message for another realm/host", fd_msg_pmdl_get(msgptr));
    689705                                CHECK_FCT( return_error( &msgptr, "DIAMETER_UNABLE_TO_DELIVER", "I am not a Diameter agent", NULL) );
    690706                                return 0;
     
    700716                                        {
    701717                                                /* If the process failed, we assume it is because of the AVP format */
     718                                                fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Failed to process decorated NAI", fd_msg_pmdl_get(msgptr));
    702719                                                CHECK_FCT( return_error( &msgptr, "DIAMETER_INVALID_AVP_VALUE", "Failed to process decorated NAI", un) );
    703720                                                return 0;
     
    713730                        if (is_local_app == YES) {
    714731                                /* Handle localy since we are able to */
     732                                fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr));
    715733                                CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) );
    716734                                return 0;
     
    719737                        if (fd_g_config->cnf_flags.no_fwd) {
    720738                                /* We return an error */
     739                                fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, "Application unsupported", fd_msg_pmdl_get(msgptr));
    721740                                CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) );
    722741                                return 0;
     
    736755                if ((!qry_src) && (!is_err)) {
    737756                        /* The message is a normal answer to a request issued localy, we do not call the callbacks chain on it. */
     757                        fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr));
    738758                        CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) );
    739759                        return 0;
     
    764784                        CHECK_FCT_DO( ret = (*rh->rt_fwd_cb)(rh->cbdata, &msgptr),
    765785                                {
    766                                         //fd_msg_log( FD_MSG_LOG_DROPPED, msgptr, "Internal error: a FWD routing callback returned an error (%s)", strerror(ret));
     786                                        char buf[256];
     787                                        snprintf(buf, sizeof(buf), "A FWD routing callback returned an error: %s", strerror(ret));
     788                                        fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr));
     789                                        fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr));
    767790                                        fd_msg_free(msgptr);
    768791                                        msgptr = NULL;
     792                                        break;
    769793                                } );
    770794                }
     
    780804        /* Now pass the message to the next step: either forward to another peer, or dispatch to local extensions */
    781805        if (is_req || qry_src) {
     806                fd_hook_call(HOOK_MESSAGE_ROUTING_FORWARD, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr));
    782807                CHECK_FCT(fd_fifo_post(fd_g_outgoing, &msgptr) );
    783808        } else {
     809                fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr));
    784810                CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) );
    785811        }
     
    823849                CHECK_FCT( fd_peer_getbyid( qry_src, qry_src_len, 0, (void *) &peer ) );
    824850                if (fd_peer_getstate(peer) != STATE_OPEN) {
    825                         //fd_msg_log( FD_MSG_LOG_DROPPED, msgptr, "Unable to forward answer to deleted / closed peer '%s'.", qry_src);
     851                        char buf[128];
     852                        snprintf(buf, sizeof(buf), "Unable to forward answer to deleted / closed peer '%s'.", qry_src);
     853                        fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr));
     854                        fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr));
    826855                        fd_msg_free(msgptr);
    827856                        return 0;
     
    908937                        CHECK_FCT_DO( ret = (*rh->rt_out_cb)(rh->cbdata, msgptr, candidates),
    909938                                {
    910                                         //fd_msg_log( FD_MSG_LOG_DROPPED, msgptr, "Internal error: an OUT routing callback returned an error (%s)", strerror(ret));
     939                                        char buf[256];
     940                                        snprintf(buf, sizeof(buf), "An OUT routing callback returned an error: %s", strerror(ret));
     941                                        fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr));
     942                                        fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr));
    911943                                        fd_msg_free(msgptr);
    912944                                        msgptr = NULL;
     
    956988        /* If the message has not been sent, return an error */
    957989        if (msgptr) {
    958                 //fd_msg_log( FD_MSG_LOG_NODELIVER, msgptr, "No suitable candidate to route the message to." );
     990                fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, "No remaining suitable candidate to route the message to", fd_msg_pmdl_get(msgptr));
    959991                return_error( &msgptr, "DIAMETER_UNABLE_TO_DELIVER", "No suitable candidate to route the message to", NULL);
    960992        }
Note: See TracChangeset for help on using the changeset viewer.