core: if nosip msg hooks skip handling the packet, stop sip routing processing
[sip-router] / src / core / receive.c
index 2b8b2c7..b14ebf8 100644 (file)
@@ -169,6 +169,7 @@ int receive_msg(char *buf, unsigned int len, struct receive_info *rcv_info)
        sr_event_param_t evp = {0};
        unsigned int cidlockidx = 0;
        unsigned int cidlockset = 0;
+       int errsipmsg = 0;
 
        if(sr_event_enabled(SREV_NET_DATA_RECV)) {
                if(sip_check_fline(buf, len) == 0) {
@@ -214,15 +215,22 @@ int receive_msg(char *buf, unsigned int len, struct receive_info *rcv_info)
                msg_set_time(msg);
 
        if(parse_msg(buf, len, msg) != 0) {
+               errsipmsg = 1;
                evp.data = (void *)msg;
                if((ret = sr_event_exec(SREV_RCV_NOSIP, &evp)) < NONSIP_MSG_DROP) {
-                       LOG(cfg_get(core, core_cfg, corelog),
-                                       "core parsing of SIP message failed (%s:%d/%d)\n",
-                                       ip_addr2a(&msg->rcv.src_ip), (int)msg->rcv.src_port,
-                                       (int)msg->rcv.proto);
-                       sr_core_ert_run(msg, SR_CORE_ERT_RECEIVE_PARSE_ERROR);
-               } else if(ret == NONSIP_MSG_DROP)
+                       LM_DBG("attempt of nonsip message processing failed\n");
+               } else if(ret == NONSIP_MSG_DROP) {
+                       LM_DBG("nonsip message processing completed\n");
                        goto error02;
+               }
+       }
+       if(errsipmsg==1) {
+               LOG(cfg_get(core, core_cfg, corelog),
+                               "core parsing of SIP message failed (%s:%d/%d)\n",
+                               ip_addr2a(&msg->rcv.src_ip), (int)msg->rcv.src_port,
+                               (int)msg->rcv.proto);
+               sr_core_ert_run(msg, SR_CORE_ERT_RECEIVE_PARSE_ERROR);
+               goto error02;
        }
 
        if(unlikely(parse_headers(msg, HDR_FROM_F | HDR_TO_F | HDR_CALLID_F | HDR_CSEQ_F, 0)
@@ -306,7 +314,8 @@ int receive_msg(char *buf, unsigned int len, struct receive_info *rcv_info)
                if(unlikely(main_rt.rlist[DEFAULT_RT] == NULL)) {
                        keng = sr_kemi_eng_get();
                        if(keng == NULL) {
-                               LM_ERR("no config routing engine registered\n");
+                               LM_ERR("no request_route {...} and no other config routing"
+                                               " engine registered\n");
                                goto error_req;
                        }
                        if(unlikely(cidlockset)) {
@@ -414,10 +423,11 @@ int receive_msg(char *buf, unsigned int len, struct receive_info *rcv_info)
                                goto error_rpl;
                        } else
 #endif /* NO_ONREPLY_ROUTE_ERROR */
-                                       if(unlikely(ret == 0 || (ctx.run_flags & DROP_R_F))) {
-                               STATS_RPL_FWD_DROP();
-                               goto skip_send_reply; /* drop the message, no error */
-                       }
+                               if(unlikely(ret == 0 || (ctx.run_flags & DROP_R_F))) {
+                                       STATS_RPL_FWD_DROP();
+                                       LM_DBG("drop flag set - skip forwarding the reply\n");
+                                       goto skip_send_reply; /* drop the message, no error */
+                               }
                }
                /* send the msg */
                forward_reply(msg);