From 2ed74f6af07e2339f14d4ad9c674703be8ca1c0c Mon Sep 17 00:00:00 2001 From: Alexei Gradinari Date: Thu, 7 Apr 2016 14:45:47 -0400 Subject: [PATCH] res_pjsip: better logging failed request Add custom message instead of "No matching endpoint found". Add method to logging. Do not log OPTIONS/NOTIFY requests which can be used for ping. ASTERISK-25900 Change-Id: I7ac95e9b0a8943b1f2cf899d65972f542daaa1a9 --- res/res_pjsip/pjsip_distributor.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/res/res_pjsip/pjsip_distributor.c b/res/res_pjsip/pjsip_distributor.c index 3e33367215..f9a2856f5a 100644 --- a/res/res_pjsip/pjsip_distributor.c +++ b/res/res_pjsip/pjsip_distributor.c @@ -22,6 +22,8 @@ #include "asterisk/res_pjsip.h" #include "asterisk/acl.h" +/* Needed for SUBSCRIBE, NOTIFY, and PUBLISH method definitions */ +#include #include "include/res_pjsip_private.h" #include "asterisk/taskprocessor.h" #include "asterisk/threadpool.h" @@ -360,14 +362,16 @@ struct ast_sip_endpoint *ast_sip_get_artificial_endpoint(void) return artificial_endpoint; } -static void log_unidentified_request(pjsip_rx_data *rdata) +static void log_failed_request(pjsip_rx_data *rdata, char *msg) { char from_buf[PJSIP_MAX_URL_SIZE]; char callid_buf[PJSIP_MAX_URL_SIZE]; + char method_buf[PJSIP_MAX_URL_SIZE]; pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, rdata->msg_info.from->uri, from_buf, PJSIP_MAX_URL_SIZE); ast_copy_pj_str(callid_buf, &rdata->msg_info.cid->id, PJSIP_MAX_URL_SIZE); - ast_log(LOG_NOTICE, "Request from '%s' failed for '%s:%d' (callid: %s) - No matching endpoint found\n", - from_buf, rdata->pkt_info.src_name, rdata->pkt_info.src_port, callid_buf); + ast_copy_pj_str(method_buf, &rdata->msg_info.msg->line.req.method.name, PJSIP_MAX_URL_SIZE); + ast_log(LOG_NOTICE, "Request '%s' from '%s' failed for '%s:%d' (callid: %s) - %s\n", + method_buf, from_buf, rdata->pkt_info.src_name, rdata->pkt_info.src_port, callid_buf, msg); } static pj_bool_t endpoint_lookup(pjsip_rx_data *rdata) @@ -398,8 +402,11 @@ static pj_bool_t endpoint_lookup(pjsip_rx_data *rdata) ast_copy_pj_str(name, &sip_from->user, sizeof(name)); } - log_unidentified_request(rdata); - ast_sip_report_invalid_endpoint(name, rdata); + if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_options_method) && + pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_notify_method)) { + log_failed_request(rdata, "No matching endpoint found"); + ast_sip_report_invalid_endpoint(name, rdata); + } } rdata->endpt_info.mod_data[endpoint_mod.id] = endpoint; return PJ_FALSE; @@ -508,11 +515,17 @@ static pj_bool_t authenticate(pjsip_rx_data *rdata) pjsip_tx_data_dec_ref(tdata); return PJ_FALSE; case AST_SIP_AUTHENTICATION_FAILED: - ast_sip_report_auth_failed_challenge_response(endpoint, rdata); + if (endpoint!=artificial_endpoint) { + log_failed_request(rdata, "Failed to authenticate"); + ast_sip_report_auth_failed_challenge_response(endpoint, rdata); + } pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL); return PJ_TRUE; case AST_SIP_AUTHENTICATION_ERROR: - ast_sip_report_auth_failed_challenge_response(endpoint, rdata); + if (endpoint!=artificial_endpoint) { + log_failed_request(rdata, "Error to authenticate"); + ast_sip_report_auth_failed_challenge_response(endpoint, rdata); + } pjsip_tx_data_dec_ref(tdata); pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL); return PJ_TRUE;