int siptrace_net_data_recv(void *data) { sr_net_info_t *nd; struct _siptrace_data sto; if(data==0) return -1; nd = (sr_net_info_t*)data; if(nd->rcv==NULL || nd->data.s==NULL || nd->data.len<=0) return -1; memset(&sto, 0, sizeof(struct _siptrace_data)); sto.body.s = nd->data.s; sto.body.len = nd->data.len; siptrace_copy_proto(nd->rcv->proto, sto.fromip_buff); strcat(sto.fromip_buff, ip_addr2a(&nd->rcv->src_ip)); strcat(sto.fromip_buff,":"); strcat(sto.fromip_buff, int2str(nd->rcv->src_port, NULL)); sto.fromip.s = sto.fromip_buff; sto.fromip.len = strlen(sto.fromip_buff); siptrace_copy_proto(nd->rcv->proto, sto.toip_buff); strcat(sto.toip_buff, ip_addr2a(&nd->rcv->dst_ip)); strcat(sto.toip_buff,":"); strcat(sto.toip_buff, int2str(nd->rcv->dst_port, NULL)); sto.toip.s = sto.toip_buff; sto.toip.len = strlen(sto.toip_buff); sto.dir = "in"; trace_send_hep_duplicate(&sto.body, &sto.fromip, &sto.toip, NULL); return 0; }
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 void trace_onreply_out(struct cell* t, int type, struct tmcb_params *ps) { db_key_t db_keys[NR_KEYS]; db_val_t db_vals[NR_KEYS]; int faked = 0; static char fromip_buff[IP_ADDR_MAX_STR_SIZE+12]; static char toip_buff[IP_ADDR_MAX_STR_SIZE+12]; struct sip_msg* msg; struct sip_msg* req; int_str avp_value; struct usr_avp *avp; struct ip_addr to_ip; int len; char statusbuf[8]; str *sbuf; struct dest_info *dst; if (t==NULL || t->uas.request==0 || ps==NULL) { LM_DBG("no uas request, local transaction\n"); return; } avp = NULL; if(traced_user_avp.n!=0) avp=search_first_avp(traced_user_avp_type, traced_user_avp, &avp_value, 0); if((avp==NULL) && trace_is_off(t->uas.request)) { LM_DBG("trace off...\n"); return; } req = ps->req; msg = ps->rpl; if(msg==NULL || msg==FAKED_REPLY) { msg = t->uas.request; faked = 1; } if(parse_from_header(msg)==-1 || msg->from==NULL || get_from(msg)==NULL) { LM_ERR("cannot parse FROM header\n"); goto error; } if(parse_headers(msg, HDR_CALLID_F, 0)!=0) { LM_ERR("cannot parse call-id\n"); return; } db_keys[0] = msg_column; db_vals[0].type = DB_BLOB; db_vals[0].nul = 0; sbuf = (str*)ps->extra1; if(faked==0) { if(sbuf!=0 && sbuf->len>0) { db_vals[0].val.blob_val.s = sbuf->s; db_vals[0].val.blob_val.len = sbuf->len; } else if(t->uas.response.buffer.s!=NULL) { db_vals[0].val.blob_val.s = t->uas.response.buffer.s; db_vals[0].val.blob_val.len = t->uas.response.buffer.len; } else if(msg->len>0) { db_vals[0].val.blob_val.s = msg->buf; db_vals[0].val.blob_val.len = msg->len; } else { db_vals[0].val.blob_val.s = "No reply buffer"; db_vals[0].val.blob_val.len = sizeof("No reply buffer")-1; } } else { if(sbuf!=0 && sbuf->len>0) { db_vals[0].val.blob_val.s = sbuf->s; db_vals[0].val.blob_val.len = sbuf->len; } else if(t->uas.response.buffer.s==NULL) { db_vals[0].val.blob_val.s = "No reply buffer"; db_vals[0].val.blob_val.len = sizeof("No reply buffer")-1; } else { db_vals[0].val.blob_val.s = t->uas.response.buffer.s; db_vals[0].val.blob_val.len = t->uas.response.buffer.len; } } /* check Call-ID header */ if(msg->callid==NULL || msg->callid->body.s==NULL) { LM_ERR("cannot find Call-ID header!\n"); goto error; } db_keys[1] = callid_column; db_vals[1].type = DB_STR; db_vals[1].nul = 0; db_vals[1].val.str_val.s = msg->callid->body.s; db_vals[1].val.str_val.len = msg->callid->body.len; db_keys[2] = method_column; db_vals[2].type = DB_STR; db_vals[2].nul = 0; db_vals[2].val.str_val.s = t->method.s; db_vals[2].val.str_val.len = t->method.len; db_keys[4] = fromip_column; db_vals[4].type = DB_STRING; db_vals[4].nul = 0; if(trace_local_ip) db_vals[4].val.string_val = trace_local_ip; else { siptrace_copy_proto(msg->rcv.proto, fromip_buff); strcat(fromip_buff, ip_addr2a(&req->rcv.dst_ip)); strcat(fromip_buff,":"); strcat(fromip_buff, int2str(req->rcv.dst_port, NULL)); db_vals[4].val.string_val = fromip_buff; } db_keys[3] = status_column; db_vals[3].type = DB_STRING; db_vals[3].nul = 0; strcpy(statusbuf, int2str(ps->code, NULL)); db_vals[3].val.string_val = statusbuf; db_keys[5] = toip_column; db_vals[5].type = DB_STRING; db_vals[5].nul = 0; memset(&to_ip, 0, sizeof(struct ip_addr)); dst = (struct dest_info*)ps->extra2; if(dst==0) { db_vals[5].val.string_val = "any:255.255.255.255"; } else { su2ip_addr(&to_ip, &dst->to); siptrace_copy_proto(dst->proto, toip_buff); strcat(toip_buff, ip_addr2a(&to_ip)); strcat(toip_buff, ":"); strcat(toip_buff, int2str((unsigned long)su_getport(&dst->to), &len)); LM_DBG("dest [%s]\n", toip_buff); db_vals[5].val.string_val = toip_buff; } db_keys[6] = date_column; db_vals[6].type = DB_DATETIME; db_vals[6].nul = 0; db_vals[6].val.time_val = time(NULL); db_keys[7] = direction_column; db_vals[7].type = DB_STRING; db_vals[7].nul = 0; db_vals[7].val.string_val = "out"; db_keys[8] = fromtag_column; db_vals[8].type = DB_STR; db_vals[8].nul = 0; db_vals[8].val.str_val.s = get_from(msg)->tag_value.s; db_vals[8].val.str_val.len = get_from(msg)->tag_value.len; db_funcs.use_table(db_con, siptrace_get_table()); db_keys[9] = traced_user_column; db_vals[9].type = DB_STR; db_vals[9].nul = 0; if( !trace_is_off(req) ) { db_vals[9].val.str_val.s = ""; db_vals[9].val.str_val.len = 0; LM_DBG("storing info...\n"); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } #ifdef STATISTICS update_stat(siptrace_rpl, 1); #endif } if(avp==NULL) goto done; trace_send_duplicate(db_vals[0].val.blob_val.s, db_vals[0].val.blob_val.len); db_vals[9].val.str_val.s = avp_value.s.s; db_vals[9].val.str_val.len = avp_value.s.len; LM_DBG("storing info...\n"); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } avp = search_next_avp( avp, &avp_value); while(avp!=NULL) { db_vals[9].val.str_val.s = avp_value.s.s; db_vals[9].val.str_val.len = avp_value.s.len; LM_DBG("### - storing info (%d) ...\n", faked); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } avp = search_next_avp( avp, &avp_value); } done: return; error: return; }
static void trace_onreply_in(struct cell* t, int type, struct tmcb_params *ps) { db_key_t db_keys[NR_KEYS]; db_val_t db_vals[NR_KEYS]; static char fromip_buff[IP_ADDR_MAX_STR_SIZE+12]; static char toip_buff[IP_ADDR_MAX_STR_SIZE+12]; struct sip_msg* msg; struct sip_msg* req; int_str avp_value; struct usr_avp *avp; char statusbuf[8]; if(t==NULL || t->uas.request==0 || ps==NULL) { LM_DBG("no uas request, local transaction\n"); return; } req = ps->req; msg = ps->rpl; if(msg==NULL || req==NULL) { LM_DBG("no reply\n"); return; } avp = NULL; if(traced_user_avp.n!=0) avp=search_first_avp(traced_user_avp_type, traced_user_avp, &avp_value, 0); if((avp==NULL) && trace_is_off(req)) { LM_DBG("trace off...\n"); return; } if(parse_from_header(msg)==-1 || msg->from==NULL || get_from(msg)==NULL) { LM_ERR("cannot parse FROM header\n"); goto error; } if(parse_headers(msg, HDR_CALLID_F, 0)!=0) { LM_ERR("cannot parse call-id\n"); return; } db_keys[0] = msg_column; db_vals[0].type = DB_BLOB; db_vals[0].nul = 0; if(msg->len>0) { db_vals[0].val.blob_val.s = msg->buf; db_vals[0].val.blob_val.len = msg->len; } else { db_vals[0].val.blob_val.s = "No reply buffer"; db_vals[0].val.blob_val.len = sizeof("No reply buffer")-1; } /* check Call-ID header */ if(msg->callid==NULL || msg->callid->body.s==NULL) { LM_ERR("cannot find Call-ID header!\n"); goto error; } db_keys[1] = callid_column; db_vals[1].type = DB_STR; db_vals[1].nul = 0; db_vals[1].val.str_val.s = msg->callid->body.s; db_vals[1].val.str_val.len = msg->callid->body.len; db_keys[2] = method_column; db_vals[2].type = DB_STR; db_vals[2].nul = 0; db_vals[2].val.str_val.s = t->method.s; db_vals[2].val.str_val.len = t->method.len; db_keys[3] = status_column; db_vals[3].type = DB_STRING; db_vals[3].nul = 0; strcpy(statusbuf, int2str(ps->code, NULL)); db_vals[3].val.string_val = statusbuf; db_keys[4] = fromip_column; db_vals[4].type = DB_STRING; db_vals[4].nul = 0; siptrace_copy_proto(msg->rcv.proto, fromip_buff); strcat(fromip_buff, ip_addr2a(&msg->rcv.src_ip)); strcat(fromip_buff,":"); strcat(fromip_buff, int2str(msg->rcv.src_port, NULL)); db_vals[4].val.string_val = fromip_buff; db_keys[5] = toip_column; db_vals[5].type = DB_STRING; db_vals[5].nul = 0; // db_vals[5].val.string_val = ip_addr2a(&msg->rcv.dst_ip);; if(trace_local_ip) db_vals[5].val.string_val = trace_local_ip; else { siptrace_copy_proto(msg->rcv.proto, toip_buff); strcat(toip_buff, ip_addr2a(&msg->rcv.dst_ip)); strcat(toip_buff,":"); strcat(toip_buff, int2str(msg->rcv.dst_port, NULL)); db_vals[5].val.string_val = toip_buff; } db_keys[6] = date_column; db_vals[6].type = DB_DATETIME; db_vals[6].nul = 0; db_vals[6].val.time_val = time(NULL); db_keys[7] = direction_column; db_vals[7].type = DB_STRING; db_vals[7].nul = 0; db_vals[7].val.string_val = "in"; db_keys[8] = fromtag_column; db_vals[8].type = DB_STR; db_vals[8].nul = 0; db_vals[8].val.str_val.s = get_from(msg)->tag_value.s; db_vals[8].val.str_val.len = get_from(msg)->tag_value.len; db_funcs.use_table(db_con, siptrace_get_table()); db_keys[9] = traced_user_column; db_vals[9].type = DB_STR; db_vals[9].nul = 0; if( !trace_is_off(req) ) { db_vals[9].val.str_val.s = ""; db_vals[9].val.str_val.len = 0; LM_DBG("storing info...\n"); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } #ifdef STATISTICS update_stat(siptrace_rpl, 1); #endif } if(avp==NULL) goto done; trace_send_duplicate(db_vals[0].val.blob_val.s, db_vals[0].val.blob_val.len); db_vals[9].val.str_val.s = avp_value.s.s; db_vals[9].val.str_val.len = avp_value.s.len; LM_DBG("storing info...\n"); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } avp = search_next_avp( avp, &avp_value); while(avp!=NULL) { db_vals[9].val.str_val.s = avp_value.s.s; db_vals[9].val.str_val.len = avp_value.s.len; LM_DBG("storing info ...\n"); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } avp = search_next_avp( avp, &avp_value); } done: return; error: return; }
static int sip_trace(struct sip_msg *msg, char *s1, char *s2) { db_key_t db_keys[NR_KEYS]; db_val_t db_vals[NR_KEYS]; static char toip_buff[IP_ADDR_MAX_STR_SIZE+6]; static char fromip_buff[IP_ADDR_MAX_STR_SIZE+6]; int_str avp_value; struct usr_avp *avp; if(msg==NULL) { LM_DBG("no uas request, local transaction\n"); return -1; } avp = NULL; if(traced_user_avp.n!=0) avp=search_first_avp(traced_user_avp_type, traced_user_avp, &avp_value, 0); if((avp==NULL) && (trace_on_flag==NULL || *trace_on_flag==0)) { LM_DBG("trace off...\n"); return -1; } if(parse_from_header(msg)==-1 || msg->from==NULL || get_from(msg)==NULL) { LM_ERR("cannot parse FROM header\n"); goto error; } if(parse_headers(msg, HDR_CALLID_F, 0)!=0 || msg->callid==NULL || msg->callid->body.s==NULL) { LM_ERR("cannot parse call-id\n"); goto error; } db_keys[0] = msg_column; db_vals[0].type = DB_BLOB; db_vals[0].nul = 0; db_vals[0].val.blob_val.s = msg->buf; db_vals[0].val.blob_val.len = msg->len; db_keys[1] = callid_column; db_vals[1].type = DB_STR; db_vals[1].nul = 0; db_vals[1].val.str_val.s = msg->callid->body.s; db_vals[1].val.str_val.len = msg->callid->body.len; db_keys[2] = method_column; db_vals[2].type = DB_STR; db_vals[2].nul = 0; if(msg->first_line.type==SIP_REQUEST) { db_vals[2].val.str_val.s = msg->first_line.u.request.method.s; db_vals[2].val.str_val.len = msg->first_line.u.request.method.len; } else { db_vals[2].val.str_val.s = ""; db_vals[2].val.str_val.len = 0; } db_keys[3] = status_column; db_vals[3].type = DB_STR; db_vals[3].nul = 0; if(msg->first_line.type==SIP_REPLY) { db_vals[3].val.str_val.s = msg->first_line.u.reply.status.s; db_vals[3].val.str_val.len = msg->first_line.u.reply.status.len; } else { db_vals[3].val.str_val.s = ""; db_vals[3].val.str_val.len = 0; } db_keys[4] = fromip_column; db_vals[4].type = DB_STRING; db_vals[4].nul = 0; siptrace_copy_proto(msg->rcv.proto, fromip_buff); strcat(fromip_buff, ip_addr2a(&msg->rcv.src_ip)); strcat(fromip_buff,":"); strcat(fromip_buff, int2str(msg->rcv.src_port, NULL)); db_vals[4].val.string_val = fromip_buff; db_keys[5] = toip_column; db_vals[5].type = DB_STRING; db_vals[5].nul = 0; // db_vals[5].val.string_val = ip_addr2a(&msg->rcv.dst_ip);; siptrace_copy_proto(msg->rcv.proto, toip_buff); strcat(toip_buff, ip_addr2a(&msg->rcv.dst_ip)); strcat(toip_buff,":"); strcat(toip_buff, int2str(msg->rcv.dst_port, NULL)); db_vals[5].val.string_val = toip_buff; db_keys[6] = date_column; db_vals[6].type = DB_DATETIME; db_vals[6].nul = 0; db_vals[6].val.time_val = time(NULL); db_keys[7] = direction_column; db_vals[7].type = DB_STRING; db_vals[7].nul = 0; db_vals[7].val.string_val = "in"; db_keys[8] = fromtag_column; db_vals[8].type = DB_STR; db_vals[8].nul = 0; db_vals[8].val.str_val.s = get_from(msg)->tag_value.s; db_vals[8].val.str_val.len = get_from(msg)->tag_value.len; db_funcs.use_table(db_con, siptrace_get_table()); db_keys[9] = traced_user_column; db_vals[9].type = DB_STR; db_vals[9].nul = 0; if(trace_on_flag!=NULL && *trace_on_flag!=0) { db_vals[9].val.str_val.s = ""; db_vals[9].val.str_val.len = 0; LM_DBG("storing info...\n"); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } #ifdef STATISTICS if(msg->first_line.type==SIP_REPLY) { update_stat(siptrace_rpl, 1); } else { update_stat(siptrace_req, 1); } #endif } if(avp==NULL) goto done; trace_send_duplicate(db_vals[0].val.blob_val.s, db_vals[0].val.blob_val.len); db_vals[9].val.str_val.s = avp_value.s.s; db_vals[9].val.str_val.len = avp_value.s.len; LM_DBG("storing info...\n"); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } avp = search_next_avp( avp, &avp_value); while(avp!=NULL) { db_vals[9].val.str_val.s = avp_value.s.s; db_vals[9].val.str_val.len = avp_value.s.len; LM_DBG("storing info...\n"); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } avp = search_next_avp( avp, &avp_value); } done: return 1; error: return -1; }
static void trace_sl_onreply_out( unsigned int types, struct sip_msg* req, struct sl_cb_param *sl_param) { db_key_t db_keys[NR_KEYS]; db_val_t db_vals[NR_KEYS]; static char fromip_buff[IP_ADDR_MAX_STR_SIZE+12]; static char toip_buff[IP_ADDR_MAX_STR_SIZE+12]; int faked = 0; struct sip_msg* msg; int_str avp_value; struct usr_avp *avp; struct ip_addr to_ip; int len; char statusbuf[5]; if(req==NULL || sl_param==NULL) { LM_ERR("bad parameters\n"); goto error; } avp = NULL; if(traced_user_avp.n!=0) avp=search_first_avp(traced_user_avp_type, traced_user_avp, &avp_value, 0); if((avp==NULL) && trace_is_off(req)) { LM_DBG("trace off...\n"); return; } msg = req; faked = 1; if(parse_from_header(msg)==-1 || msg->from==NULL || get_from(msg)==NULL) { LM_ERR("cannot parse FROM header\n"); goto error; } if(parse_headers(msg, HDR_CALLID_F, 0)!=0) { LM_ERR("cannot parse call-id\n"); return; } db_keys[0] = msg_column; db_vals[0].type = DB_BLOB; db_vals[0].nul = 0; db_vals[0].val.blob_val.s = (sl_param->buffer)?sl_param->buffer->s:""; db_vals[0].val.blob_val.len = (sl_param->buffer)?sl_param->buffer->len:0; /* check Call-ID header */ if(msg->callid==NULL || msg->callid->body.s==NULL) { LM_ERR("cannot find Call-ID header!\n"); goto error; } db_keys[1] = callid_column; db_vals[1].type = DB_STR; db_vals[1].nul = 0; db_vals[1].val.str_val.s = msg->callid->body.s; db_vals[1].val.str_val.len = msg->callid->body.len; db_keys[2] = method_column; db_vals[2].type = DB_STR; db_vals[2].nul = 0; db_vals[2].val.str_val.s = msg->first_line.u.request.method.s; db_vals[2].val.str_val.len = msg->first_line.u.request.method.len; db_keys[4] = fromip_column; db_vals[4].type = DB_STRING; db_vals[4].nul = 0; if(trace_local_ip) db_vals[4].val.string_val = trace_local_ip; else { siptrace_copy_proto(msg->rcv.proto, fromip_buff); strcat(fromip_buff, ip_addr2a(&req->rcv.dst_ip)); strcat(fromip_buff,":"); strcat(fromip_buff, int2str(req->rcv.dst_port, NULL)); db_vals[4].val.string_val = fromip_buff; } db_keys[3] = status_column; db_vals[3].type = DB_STRING; db_vals[3].nul = 0; strcpy(statusbuf, int2str(sl_param->code, NULL)); db_vals[3].val.string_val = statusbuf; db_keys[5] = toip_column; db_vals[5].type = DB_STRING; db_vals[5].nul = 0; memset(&to_ip, 0, sizeof(struct ip_addr)); if(sl_param->dst==0) { db_vals[5].val.string_val = "any:255.255.255.255"; } else { su2ip_addr(&to_ip, sl_param->dst); siptrace_copy_proto(req->rcv.proto, toip_buff); strcat(toip_buff, ip_addr2a(&to_ip)); strcat(toip_buff, ":"); strcat(toip_buff, int2str((unsigned long)su_getport(sl_param->dst), &len)); LM_DBG("dest [%s]\n", toip_buff); db_vals[5].val.string_val = toip_buff; } db_keys[6] = date_column; db_vals[6].type = DB_DATETIME; db_vals[6].nul = 0; db_vals[6].val.time_val = time(NULL); db_keys[7] = direction_column; db_vals[7].type = DB_STRING; db_vals[7].nul = 0; db_vals[7].val.string_val = "out"; db_keys[8] = fromtag_column; db_vals[8].type = DB_STR; db_vals[8].nul = 0; db_vals[8].val.str_val.s = get_from(msg)->tag_value.s; db_vals[8].val.str_val.len = get_from(msg)->tag_value.len; db_funcs.use_table(db_con, siptrace_get_table()); db_keys[9] = traced_user_column; db_vals[9].type = DB_STR; db_vals[9].nul = 0; if( !trace_is_off(msg) ) { db_vals[9].val.str_val.s = ""; db_vals[9].val.str_val.len = 0; LM_DBG("storing info...\n"); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } #ifdef STATISTICS update_stat(siptrace_rpl, 1); #endif } if(avp==NULL) goto done; trace_send_duplicate(db_vals[0].val.blob_val.s, db_vals[0].val.blob_val.len); db_vals[9].val.str_val.s = avp_value.s.s; db_vals[9].val.str_val.len = avp_value.s.len; LM_DBG("storing info...\n"); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } avp = search_next_avp( avp, &avp_value); while(avp!=NULL) { db_vals[9].val.str_val.s = avp_value.s.s; db_vals[9].val.str_val.len = avp_value.s.len; LM_DBG("### - storing info (%d) ...\n", faked); if(db_funcs.insert(db_con, db_keys, db_vals, NR_KEYS) < 0) { LM_ERR("error storing trace\n"); goto error; } avp = search_next_avp( avp, &avp_value); } done: return; error: return; }
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); }
static void trace_sl_onreply_out(sl_cbp_t *slcbp) { sip_msg_t *req; struct _siptrace_data sto; struct sip_msg* msg; struct ip_addr to_ip; int len; char statusbuf[5]; if(slcbp==NULL || slcbp->req==NULL) { LM_ERR("bad parameters\n"); return; } req = slcbp->req; 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_is_off(req)) { LM_DBG("trace off...\n"); return; } msg = req; if(sip_trace_prepare(msg)<0) return; sto.body.s = (slcbp->reply)?slcbp->reply->s:""; sto.body.len = (slcbp->reply)?slcbp->reply->len:0; sto.callid = msg->callid->body; sto.method = msg->first_line.u.request.method; if(trace_local_ip.len > 0) { sto.fromip = trace_local_ip; } else { siptrace_copy_proto(msg->rcv.proto, sto.fromip_buff); strcat(sto.fromip_buff, ip_addr2a(&req->rcv.dst_ip)); strcat(sto.fromip_buff,":"); strcat(sto.fromip_buff, int2str(req->rcv.dst_port, NULL)); sto.fromip.s = sto.fromip_buff; sto.fromip.len = strlen(sto.fromip_buff); } strcpy(statusbuf, int2str(slcbp->code, &sto.status.len)); sto.status.s = statusbuf; memset(&to_ip, 0, sizeof(struct ip_addr)); if(slcbp->dst==0) { sto.toip.s = "any:255.255.255.255"; sto.toip.len = 19; } else { su2ip_addr(&to_ip, &slcbp->dst->to); siptrace_copy_proto(req->rcv.proto, sto.toip_buff); strcat(sto.toip_buff, ip_addr2a(&to_ip)); strcat(sto.toip_buff, ":"); strcat(sto.toip_buff, int2str((unsigned long)su_getport(&slcbp->dst->to), &len)); 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 sto.stat = siptrace_rpl; #endif sip_trace_store(&sto, NULL); return; }
static void trace_onreply_out(struct cell* t, int type, struct tmcb_params *ps) { struct _siptrace_data sto; int faked = 0; struct sip_msg* msg; struct sip_msg* req; struct ip_addr to_ip; int len; char statusbuf[8]; struct dest_info *dst; if (t==NULL || t->uas.request==0 || ps==NULL) { LM_DBG("no uas request, local transaction\n"); return; } if(ps->flags&TMCB_RETR_F) { LM_DBG("retransmission\n"); return; } 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_is_off(t->uas.request)) { LM_DBG("trace off...\n"); return; } req = ps->req; msg = ps->rpl; if(msg==NULL || msg==FAKED_REPLY) { msg = t->uas.request; faked = 1; } if(sip_trace_prepare(msg)<0) return; if(faked==0) { if(ps->send_buf.len>0) { sto.body = ps->send_buf; } else if(t->uas.response.buffer!=NULL) { sto.body.s = t->uas.response.buffer; sto.body.len = t->uas.response.buffer_len; } else if(msg->len>0) { sto.body.s = msg->buf; sto.body.len = msg->len; } else { sto.body.s = "No reply buffer"; sto.body.len = sizeof("No reply buffer")-1; } } else { if(ps->send_buf.len>0) { sto.body = ps->send_buf; } else if(t->uas.response.buffer!=NULL) { sto.body.s = t->uas.response.buffer; sto.body.len = t->uas.response.buffer_len; } else { sto.body.s = "No reply buffer"; sto.body.len = sizeof("No reply buffer")-1; } } sto.callid = msg->callid->body; sto.method = get_cseq(msg)->method; if(trace_local_ip.s && trace_local_ip.len > 0) { sto.fromip = trace_local_ip; } else { siptrace_copy_proto(msg->rcv.proto, sto.fromip_buff); strcat(sto.fromip_buff, ip_addr2a(&req->rcv.dst_ip)); strcat(sto.fromip_buff,":"); strcat(sto.fromip_buff, int2str(req->rcv.dst_port, NULL)); sto.fromip.s = sto.fromip_buff; sto.fromip.len = strlen(sto.fromip_buff); } strcpy(statusbuf, int2str(ps->code, &sto.status.len)); sto.status.s = statusbuf; memset(&to_ip, 0, sizeof(struct ip_addr)); dst = ps->dst; if(dst==0) { sto.toip.s = "any:255.255.255.255"; sto.toip.len = 19; } else { su2ip_addr(&to_ip, &dst->to); siptrace_copy_proto(dst->proto, sto.toip_buff); strcat(sto.toip_buff, ip_addr2a(&to_ip)); strcat(sto.toip_buff, ":"); strcat(sto.toip_buff, int2str((unsigned long)su_getport(&dst->to), &len)); 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 sto.stat = siptrace_rpl; #endif sip_trace_store(&sto, NULL); return; }
static void trace_onreply_in(struct cell* t, int type, struct tmcb_params *ps) { struct _siptrace_data sto; sip_msg_t *msg; sip_msg_t *req; char statusbuf[8]; if(t==NULL || t->uas.request==0 || ps==NULL) { LM_DBG("no uas request, local transaction\n"); return; } req = ps->req; msg = ps->rpl; if(msg==NULL || req==NULL) { LM_DBG("no reply\n"); return; } 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_is_off(req)) { LM_DBG("trace off...\n"); return; } if(sip_trace_prepare(msg)<0) return; sto.body.s = msg->buf; sto.body.len = msg->len; sto.callid = msg->callid->body; sto.method = get_cseq(msg)->method; strcpy(statusbuf, int2str(ps->code, &sto.status.len)); sto.status.s = statusbuf; 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); if(trace_local_ip.s && trace_local_ip.len > 0) { sto.toip = trace_local_ip; } else { 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 = "in"; sto.fromtag = get_from(msg)->tag_value; sto.totag = get_to(msg)->tag_value; #ifdef STATISTICS sto.stat = siptrace_rpl; #endif sip_trace_store(&sto, NULL); return; }
static void trace_onreq_out(struct cell* t, int type, struct tmcb_params *ps) { struct _siptrace_data sto; sip_msg_t *msg; struct ip_addr to_ip; int len; struct dest_info *dst; if(t==NULL || ps==NULL) { LM_DBG("very weird\n"); return; } if(ps->flags&TMCB_RETR_F) { LM_DBG("retransmission\n"); return; } msg=ps->req; if(msg==NULL) { /* check if it is outgoing cancel, t is INVITE * and send_buf starts with CANCEL */ if(is_invite(t) && ps->send_buf.len>7 && strncmp(ps->send_buf.s, "CANCEL ", 7)==0) { msg = t->uas.request; if(msg==NULL) { LM_DBG("no uas msg for INVITE transaction\n"); return; } else { LM_DBG("recording CANCEL based on INVITE transaction\n"); } } else { LM_DBG("no uas msg, local transaction\n"); return; } } 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_is_off(msg) ) { LM_DBG("trace off...\n"); return; } if(sip_trace_prepare(msg)<0) return; if(ps->send_buf.len>0) { sto.body = ps->send_buf; } else { sto.body.s = "No request buffer"; sto.body.len = sizeof("No request buffer")-1; } sto.callid = msg->callid->body; if(ps->send_buf.len>10) { sto.method.s = ps->send_buf.s; sto.method.len = 0; while(sto.method.len<ps->send_buf.len) { if(ps->send_buf.s[sto.method.len]==' ') break; sto.method.len++; } if(sto.method.len==ps->send_buf.len) sto.method.len = 10; } else { sto.method = t->method; } sto.status.s = ""; sto.status.len = 0; memset(&to_ip, 0, sizeof(struct ip_addr)); dst = ps->dst; if (trace_local_ip.s && trace_local_ip.len > 0) { sto.fromip = trace_local_ip; } else { if(dst==0 || dst->send_sock==0 || dst->send_sock->sock_str.s==0) { siptrace_copy_proto(msg->rcv.proto, sto.fromip_buff); strcat(sto.fromip_buff, ip_addr2a(&msg->rcv.dst_ip)); strcat(sto.fromip_buff,":"); strcat(sto.fromip_buff, int2str(msg->rcv.dst_port, NULL)); sto.fromip.s = sto.fromip_buff; sto.fromip.len = strlen(sto.fromip_buff); } else { sto.fromip = dst->send_sock->sock_str; } } if(dst==0) { sto.toip.s = "any:255.255.255.255"; sto.toip.len = 19; } else { su2ip_addr(&to_ip, &dst->to); siptrace_copy_proto(dst->proto, sto.toip_buff); strcat(sto.toip_buff, ip_addr2a(&to_ip)); strcat(sto.toip_buff, ":"); strcat(sto.toip_buff, int2str((unsigned long)su_getport(&dst->to), &len)); 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 sto.stat = siptrace_req; #endif sip_trace_store(&sto, NULL); return; }