int siptrace_net_data_send(void *data) { sr_net_info_t *nd; struct dest_info new_dst; struct _siptrace_data sto; if(data==0) return -1; nd = (sr_net_info_t*)data; if(nd->dst==NULL || nd->data.s==NULL || nd->data.len<=0) return -1; new_dst=*nd->dst; new_dst.send_sock=get_send_socket(0, &nd->dst->to, nd->dst->proto); memset(&sto, 0, sizeof(struct _siptrace_data)); sto.body.s = nd->data.s; sto.body.len = nd->data.len; if (unlikely(new_dst.send_sock==0)) { LM_WARN("no sending socket found\n"); strcpy(sto.fromip_buff, "any:255.255.255.255:5060"); } else { strncpy(sto.fromip_buff, new_dst.send_sock->sock_str.s, new_dst.send_sock->sock_str.len); } sto.fromip.s = sto.fromip_buff; sto.fromip.len = strlen(sto.fromip_buff); siptrace_copy_proto(new_dst.send_sock->proto, sto.toip_buff); strcat(sto.toip_buff, suip2a(&new_dst.to, sizeof(new_dst.to))); strcat(sto.toip_buff,":"); strcat(sto.toip_buff, int2str((int)su_getport(&new_dst.to), NULL)); sto.toip.s = sto.toip_buff; sto.toip.len = strlen(sto.toip_buff); sto.dir = "out"; trace_send_hep_duplicate(&sto.body, &sto.fromip, &sto.toip, NULL); return 0; }
static int sip_trace(struct sip_msg *msg, struct dest_info * dst, char *dir) { struct _siptrace_data sto; struct onsend_info *snd_inf = NULL; if (dst){ if (dst->send_sock == 0){ dst->send_sock=get_send_socket(0, &dst->to, dst->proto); if (dst->send_sock==0){ LM_ERR("can't forward to af %d, proto %d no corresponding" " listening socket\n", dst->to.s.sa_family, dst->proto); return -1; } } } if(msg==NULL) { LM_DBG("nothing to trace\n"); return -1; } memset(&sto, 0, sizeof(struct _siptrace_data)); if(traced_user_avp.n!=0) sto.avp=search_first_avp(traced_user_avp_type, traced_user_avp, &sto.avp_value, &sto.state); if((sto.avp==NULL) && (trace_on_flag==NULL || *trace_on_flag==0)) { LM_DBG("trace off...\n"); return -1; } if(sip_trace_prepare(msg)<0) return -1; sto.callid = msg->callid->body; if(msg->first_line.type==SIP_REQUEST) { sto.method = msg->first_line.u.request.method; } else { if(parse_headers(msg, HDR_CSEQ_F, 0) != 0 || msg->cseq==NULL || msg->cseq->parsed==NULL) { LM_ERR("cannot parse cseq header\n"); return -1; } sto.method = get_cseq(msg)->method; } if(msg->first_line.type==SIP_REPLY) { sto.status = msg->first_line.u.reply.status; } else { sto.status.s = ""; sto.status.len = 0; } snd_inf=get_onsend_info(); if(snd_inf==NULL) { sto.body.s = msg->buf; sto.body.len = msg->len; siptrace_copy_proto(msg->rcv.proto, sto.fromip_buff); strcat(sto.fromip_buff, ip_addr2a(&msg->rcv.src_ip)); strcat(sto.fromip_buff,":"); strcat(sto.fromip_buff, int2str(msg->rcv.src_port, NULL)); sto.fromip.s = sto.fromip_buff; sto.fromip.len = strlen(sto.fromip_buff); siptrace_copy_proto(msg->rcv.proto, sto.toip_buff); strcat(sto.toip_buff, ip_addr2a(&msg->rcv.dst_ip)); strcat(sto.toip_buff,":"); strcat(sto.toip_buff, int2str(msg->rcv.dst_port, NULL)); sto.toip.s = sto.toip_buff; sto.toip.len = strlen(sto.toip_buff); sto.dir = (dir)?dir:"in"; } else { sto.body.s = snd_inf->buf; sto.body.len = snd_inf->len; strncpy(sto.fromip_buff, snd_inf->send_sock->sock_str.s, snd_inf->send_sock->sock_str.len); sto.fromip.s = sto.fromip_buff; sto.fromip.len = strlen(sto.fromip_buff); siptrace_copy_proto(snd_inf->send_sock->proto, sto.toip_buff); strcat(sto.toip_buff, suip2a(snd_inf->to, sizeof(*snd_inf->to))); strcat(sto.toip_buff,":"); strcat(sto.toip_buff, int2str((int)su_getport(snd_inf->to), NULL)); sto.toip.s = sto.toip_buff; sto.toip.len = strlen(sto.toip_buff); sto.dir = "out"; } sto.fromtag = get_from(msg)->tag_value; sto.totag = get_to(msg)->tag_value; #ifdef STATISTICS if(msg->first_line.type==SIP_REPLY) { sto.stat = siptrace_rpl; } else { sto.stat = siptrace_req; } #endif return sip_trace_store(&sto, dst); }