From b746032e5eb146e8ac445d5f890cb1dc378983be Mon Sep 17 00:00:00 2001 From: Andrei Datcu Date: Thu, 19 Jun 2014 15:21:37 +0300 Subject: [PATCH 1/3] Split fromip and toip columns --- db/schema/sip_trace.xml | 36 ++- modules/siptrace/README | 24 +- modules/siptrace/doc/siptrace_admin.xml | 63 ++-- modules/siptrace/siptrace.c | 374 ++++++++++++++++-------- scripts/db_berkeley/opensips/sip_trace | 4 +- scripts/dbtext/opensips/sip_trace | 2 +- scripts/mysql/siptrace-create.sql | 10 +- scripts/opensipsctlrc | 12 +- scripts/opensipsdbctl | 2 +- scripts/oracle/siptrace-create.sql | 10 +- scripts/pi_http/pi_framework.xml | 32 +- scripts/pi_http/siptrace-mod | 24 +- scripts/pi_http/siptrace-table | 8 +- scripts/postgres/siptrace-create.sql | 10 +- 14 files changed, 417 insertions(+), 194 deletions(-) diff --git a/db/schema/sip_trace.xml b/db/schema/sip_trace.xml index 8b4585553e8..5b06e44950f 100644 --- a/db/schema/sip_trace.xml +++ b/db/schema/sip_trace.xml @@ -1,5 +1,5 @@ - @@ -9,7 +9,7 @@ sip_trace - 3 + 4&MYSQL_TABLE_TYPE; This table is used to store incoming/outgoing SIP messages in database. More informations can be found in the siptrace module documentation at: &OPENSIPS_MOD_DOC;siptrace.html. @@ -75,8 +75,15 @@ SIP reply status + + from_proto + string + 5 + Source protocol + + - fromip + from_ip string &ip_add_len; @@ -84,13 +91,34 @@ - toip + from_port + unsigned int + 5 + Source port + + + + to_proto + string + 5 + Destination protocol + + + + to_ip string &ip_add_len; Destination IP address + + to_port + unsigned int + 5 + Destination port + + fromtag string diff --git a/modules/siptrace/README b/modules/siptrace/README index 3476ab368e1..bf67e943e05 100644 --- a/modules/siptrace/README +++ b/modules/siptrace/README @@ -206,17 +206,35 @@ modparam("siptrace", "duplicate_uri", "sip:10.1.1.1:5888") 1.3.8. trace_local_ip (str) - The address to be used in fromip field for local generated - messages. If not set, the module sets it to the address of the - socket that will be used to send the message. + The address to be used in fromip fields (protocol, ip and port) + for local generated messages. If not set, the module sets it to + the address of the socket that will be used to send the + message. Protocol and/or port ar optional and if ommited will + take the default values: udp and 5060. Default value is "NULL". Example 1.8. Set trace_local_ip parameter ... +#Resulting address: udp:10.1.1.1:5064 modparam("siptrace", "trace_local_ip", "10.1.1.1:5064") ... +... +#Resulting address: tcp:10.1.1.1:5060 +modparam("siptrace, "trace_local_ip", "tcp:10.1.1.1") +... + +... +#Resulting address: tcp:10.1.1.1:5064 +modparam("siptrace", "trace_local_ip", "tcp:10.1.1.1:5064") +... + +... +#Resulting address: udp:10.1.1.1:5060 +modparam("siptrace", "trace_local_ip", "10.1.1.1") +... + 1.3.9. table (str) Name of the table where to store the SIP messages. diff --git a/modules/siptrace/doc/siptrace_admin.xml b/modules/siptrace/doc/siptrace_admin.xml index 86f850b4c83..716fed931c5 100644 --- a/modules/siptrace/doc/siptrace_admin.xml +++ b/modules/siptrace/doc/siptrace_admin.xml @@ -1,9 +1,9 @@ - + &adminguide; - +
Overview @@ -231,9 +231,10 @@ modparam("siptrace", "duplicate_uri", "sip:10.1.1.1:5888")
<varname>trace_local_ip</varname> (str) - The address to be used in fromip field for local generated - messages. If not set, the module sets it to the address - of the socket that will be used to send the message. + The address to be used in fromip fields (protocol, ip and port) + for local generated messages. If not set, the module sets it to the address + of the socket that will be used to send the message. Protocol and/or port + ar optional and if ommited will take the default values: udp and 5060. @@ -244,8 +245,24 @@ modparam("siptrace", "duplicate_uri", "sip:10.1.1.1:5888") Set <varname>trace_local_ip</varname> parameter ... +#Resulting address: udp:10.1.1.1:5064 modparam("siptrace", "trace_local_ip", "10.1.1.1:5064") ... + +... +#Resulting address: tcp:10.1.1.1:5060 +modparam("siptrace, "trace_local_ip", "tcp:10.1.1.1") +... + +... +#Resulting address: tcp:10.1.1.1:5064 +modparam("siptrace", "trace_local_ip", "tcp:10.1.1.1:5064") +... + +... +#Resulting address: udp:10.1.1.1:5060 +modparam("siptrace", "trace_local_ip", "10.1.1.1") +...
@@ -269,7 +286,7 @@ modparam("siptrace", "table", "strace")
- +
Exported Functions
@@ -298,7 +315,7 @@ sip_trace(); The function triggers the tracing of all messages belonging to a - dialog. The function must be called for the initial request (that + dialog. The function must be called for the initial request (that starts the dialog) and it will automatically take care of tracing evertyhing related to that dialog. @@ -368,7 +385,7 @@ modparam("siptrace", "duplicate_with_hep", 1)
<varname>hep_version</varname> (integer) - The parameter indicate the version of HEP protocol. + The parameter indicate the version of HEP protocol. Can be 1 or 2. In HEPv2 the timestamp and capture agent ID will be included to HEP header. @@ -385,11 +402,11 @@ modparam("siptrace", "hep_version", 2) ... -
+
<varname>hep_capture_id</varname> (integer) - The parameter indicate the capture agent ID for HEPv2 protocol. + The parameter indicate the capture agent ID for HEPv2 protocol. Limitation: 16-bit integer. @@ -407,7 +424,7 @@ modparam("siptrace", "hep_capture_id", 234)
- +
@@ -427,11 +444,11 @@ modparam("siptrace", "hep_capture_id", 234) trace_mode : turns on/off SIP message tracing. Possible values are: - on + on off The parameter is optional - if missing, the command will - return the status of the SIP message tracing (as string + return the status of the SIP message tracing (as string on or off ) without changing anything. @@ -461,13 +478,13 @@ modparam("siptrace", "hep_capture_id", 234) trace_to_db_mode : turns on/off SIP message tracing into DB. Possible values are: - on + on off The parameter is optional - if missing, the command will - return the status of the SIP message tracing (as string + return the status of the SIP message tracing (as string on or off ) without changing - anything. The parameter can be switched from off to on, + anything. The parameter can be switched from off to on, if db connection was before inizialized @@ -482,18 +499,18 @@ modparam("siptrace", "hep_capture_id", 234)
- + - +
Database setup - Before running &osips; with siptrace, you have to setup the database - tables where the module will store the data. For that, if the + Before running &osips; with siptrace, you have to setup the database + tables where the module will store the data. For that, if the table were not created by the installation script or you choose to install everything by yourself you can use the siptrace-create.sql - SQL script in the database directories in the - opensips/scripts folder as template. + SQL script in the database directories in the + opensips/scripts folder as template. You can also find the complete database documentation on the project webpage, &osipsdbdocslink;. @@ -506,6 +523,6 @@ modparam("siptrace", "hep_capture_id", 234) flag, use sip_trace().
- +
diff --git a/modules/siptrace/siptrace.c b/modules/siptrace/siptrace.c index 3ec5b3e391b..716c688750c 100644 --- a/modules/siptrace/siptrace.c +++ b/modules/siptrace/siptrace.c @@ -48,7 +48,7 @@ #include "../sipcapture/sipcapture.h" -#define NR_KEYS 10 +#define NR_KEYS 14 /* trace is completly disabled */ #define trace_is_off() \ @@ -98,8 +98,10 @@ static void trace_msg_out_w(struct sip_msg* req, str *buffer, static struct mi_root* sip_trace_mi(struct mi_root* cmd, void* param ); static struct mi_root* trace_to_database_mi(struct mi_root* cmd, void* param ); -static int trace_send_hep_duplicate(str *body, str *fromip, str *toip); -static int pipport2su (str *pipport, union sockaddr_union *tmp_su, unsigned int *proto); +static int trace_send_hep_duplicate(str *body, str *fromproto, str *fromip, + unsigned short fromport, str *toproto, str *toip, unsigned short toport); +static int pipport2su (str *sproto, str *ip, unsigned short port, + union sockaddr_union *tmp_su, unsigned int *proto); static int do_dlg_siptrace = 0; static void siptrace_dlg_created(struct dlg_cell *did, int type,struct dlg_cb_params * params); @@ -114,10 +116,14 @@ static str traced_user_column = str_init("traced_user"); /* 02 */ static str msg_column = str_init("msg"); /* 03 */ static str method_column = str_init("method"); /* 04 */ static str status_column = str_init("status"); /* 05 */ -static str fromip_column = str_init("fromip"); /* 06 */ -static str toip_column = str_init("toip"); /* 07 */ -static str fromtag_column = str_init("fromtag"); /* 08 */ -static str direction_column = str_init("direction"); /* 09 */ +static str fromproto_column = str_init("from_proto"); /* 06 */ +static str fromip_column = str_init("from_ip"); /* 07 */ +static str fromport_column = str_init("from_port"); /* 08 */ +static str toproto_column = str_init("to_proto"); /* 09 */ +static str toip_column = str_init("to_ip"); /* 10 */ +static str toport_column = str_init("to_port"); /* 11 */ +static str fromtag_column = str_init("fromtag"); /* 12 */ +static str direction_column = str_init("direction"); /* 13 */ static char *trace_flag_str = 0; int trace_flag = -1; @@ -141,7 +147,9 @@ static unsigned short trace_table_avp_type = 0; static int trace_table_avp; static str trace_table_avp_str = {NULL, 0}; +static str trace_local_proto = {NULL, 0}; static str trace_local_ip = {NULL, 0}; +static unsigned short trace_local_port = 0; static unsigned int enable_ack_trace = 0; @@ -177,8 +185,12 @@ static param_export_t params[] = { {"msg_column", STR_PARAM, &msg_column.s }, {"method_column", STR_PARAM, &method_column.s }, {"status_column", STR_PARAM, &status_column.s }, + {"fromproto_column", STR_PARAM, &fromproto_column.s }, {"fromip_column", STR_PARAM, &fromip_column.s }, + {"fromport_column", STR_PARAM, &fromport_column.s }, + {"toproto_column", STR_PARAM, &toproto_column.s }, {"toip_column", STR_PARAM, &toip_column.s }, + {"toport_column", STR_PARAM, &toport_column.s }, {"fromtag_column", STR_PARAM, &fromtag_column.s }, {"direction_column", STR_PARAM, &direction_column.s }, {"trace_flag", STR_PARAM, &trace_flag_str }, @@ -260,6 +272,89 @@ static int fixup_trace_dialog(void** param, int param_no) } +static int parse_trace_local_ip(void){ + /* We tokenize the trace_local_ip from proto:ip:port to three fields */ + + trace_local_ip.len = strlen(trace_local_ip.s); + unsigned int port_no; + char *c = strchr(trace_local_ip.s, ':'); + if (c == NULL) { + /* Only ip is specified */ + trace_local_port = SIP_PORT; + trace_local_proto.s = "udp"; + trace_local_proto.len = sizeof("udp") -1; + } + else { + str first_token = {c + 1, + trace_local_ip.len - (c - trace_local_ip.s) - 1}; + + if (str2int(&first_token, &port_no) == 0){ + + /* The first token is the port, so no proto */ + if (port_no > 65535 || port_no == 0){ + LM_WARN("trace local_ip: port is out of range (%d). " + "Will consider it to be %d\n", port_no, SIP_PORT); + trace_local_port = SIP_PORT; + } + else + trace_local_port = (unsigned short) port_no; + + trace_local_proto.s = "udp"; + trace_local_proto.len = sizeof("udp") - 1; + trace_local_ip.len = c - trace_local_ip.s; + } + else { + + /* The first token is the protocol */ + trace_local_proto.s = trace_local_ip.s; + trace_local_proto.len = c - trace_local_ip.s; + + if (trace_local_proto.len > 4){ + /* Too many letters for the protocol. Avoiding overflow */ + LM_ERR("trace_local_ip : wrong protocol\n"); + return -1; + } else if (trace_local_proto.len == 0){ + trace_local_proto.s = "udp"; + trace_local_proto.len = sizeof("udp") - 1; + } + + char *c2 = strchr(c + 1, ':'); + + if (c2 != NULL){ + + /* We have a second token */ + str second_token; + second_token.s = c2 + 1; + second_token.len = trace_local_ip.len - + (c2 - trace_local_ip.s) - 1; + + if (str2int(&second_token, &port_no) != 0) { + trace_local_port = SIP_PORT; + LM_WARN("trace_local_ip: port is wrongly defined. " + "Will consider it as %hd\n", trace_local_port); + } + else if (port_no > 65535 || port_no == 0){ + LM_WARN("trace local_ip: port is out of range (%d). " + "Will consider it to be %d\n", + port_no, SIP_PORT); + trace_local_port = SIP_PORT; + } + else + trace_local_port = (unsigned short) port_no; + trace_local_ip.s = c + 1; + trace_local_ip.len = c2 - c - 1; + } + else { + trace_local_port = SIP_PORT; + trace_local_ip.len -= c - trace_local_ip.s + 1; + trace_local_ip.s = c + 1; + } + } + } + + return 0; +} + static int mod_init(void) { pv_spec_t avp_spec; @@ -273,8 +368,12 @@ static int mod_init(void) msg_column.len = strlen(msg_column.s); method_column.len = strlen(method_column.s); status_column.len = strlen(status_column.s); + fromproto_column.len = strlen(fromproto_column.s); fromip_column.len = strlen(fromip_column.s); + fromport_column.len = strlen(fromport_column.s); + toproto_column.len = strlen(toproto_column.s); toip_column.len = strlen(toip_column.s); + toport_column.len = strlen(toport_column.s); fromtag_column.len = strlen(fromtag_column.s); direction_column.len = strlen(direction_column.s); if (traced_user_avp_str.s) @@ -283,8 +382,9 @@ static int mod_init(void) trace_table_avp_str.len = strlen(trace_table_avp_str.s); if (dup_uri_str.s) dup_uri_str.len = strlen(dup_uri_str.s); + if (trace_local_ip.s) - trace_local_ip.len = strlen(trace_local_ip.s); + parse_trace_local_ip(); LM_INFO("initializing...\n"); @@ -430,12 +530,16 @@ static int mod_init(void) db_keys[1] = &callid_column; db_keys[2] = &method_column; db_keys[3] = &status_column; - db_keys[4] = &fromip_column; - db_keys[5] = &toip_column; - db_keys[6] = &date_column; - db_keys[7] = &direction_column; - db_keys[8] = &fromtag_column; - db_keys[9] = &traced_user_column; + db_keys[4] = &fromproto_column; + db_keys[5] = &fromip_column; + db_keys[6] = &fromport_column; + db_keys[7] = &toproto_column; + db_keys[8] = &toip_column; + db_keys[9] = &toport_column; + db_keys[10] = &date_column; + db_keys[11] = &direction_column; + db_keys[12] = &fromtag_column; + db_keys[13] = &traced_user_column; /* init DB values info which is constant ( type, null ) */ db_vals[0].type = DB_BLOB; @@ -444,10 +548,14 @@ static int mod_init(void) db_vals[3].type = DB_STR; db_vals[4].type = DB_STR; db_vals[5].type = DB_STR; - db_vals[6].type = DB_DATETIME; - db_vals[7].type = DB_STRING; + db_vals[6].type = DB_INT; + db_vals[7].type = DB_STR; db_vals[8].type = DB_STR; - db_vals[9].type = DB_STR; + db_vals[9].type = DB_INT; + db_vals[10].type = DB_DATETIME; + db_vals[11].type = DB_STRING; + db_vals[12].type = DB_STR; + db_vals[13].type = DB_STR; /* no field can be null */ for (i=0;ircv.src_ip, - msg->rcv.src_port, msg->rcv.proto); + set_sock_columns( db_vals[4], db_vals[5], db_vals[6], fromip_buff, + &msg->rcv.src_ip, msg->rcv.src_port, msg->rcv.proto); - set_sock_column( db_vals[5], toip_buff, &msg->rcv.dst_ip, - msg->rcv.dst_port, msg->rcv.proto); + set_sock_columns( db_vals[7], db_vals[8], db_vals[9], toip_buff, + &msg->rcv.dst_ip, msg->rcv.dst_port, msg->rcv.proto); - db_vals[6].val.time_val = time(NULL); + db_vals[10].val.time_val = time(NULL); - db_vals[7].val.string_val = "in"; + db_vals[11].val.string_val = "in"; - 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_vals[12].val.str_val.s = get_from(msg)->tag_value.s; + db_vals[12].val.str_val.len = get_from(msg)->tag_value.len; if (save_siptrace(msg,avp,&avp_value,db_keys,db_vals) < 0) { LM_ERR("failed to save siptrace\n"); @@ -1080,34 +1202,37 @@ static void trace_msg_out(struct sip_msg* msg, str *sbuf, memset(&to_ip, 0, sizeof(struct ip_addr)); - if (trace_local_ip.s && trace_local_ip.len > 0) - db_vals[4].val.str_val = trace_local_ip; + if (trace_local_ip.s && trace_local_ip.len > 0){ + set_columns_to_trace_local_ip( db_vals[4], db_vals[5], db_vals[6]); + } else { if(send_sock==0 || send_sock->sock_str.s==0) { - set_sock_column( db_vals[4], fromip_buff, &msg->rcv.dst_ip, - msg->rcv.dst_port, msg->rcv.proto); + set_sock_columns( db_vals[4], db_vals[5], db_vals[6], fromip_buff, + &msg->rcv.dst_ip, msg->rcv.dst_port, msg->rcv.proto); } else { - db_vals[4].val.str_val = send_sock->sock_str; + db_vals[4].val.str_val.s = proto2str(send_sock->proto,fromip_buff); + db_vals[4].val.str_val.len = strlen(db_vals[4].val.str_val.s); + db_vals[5].val.str_val = send_sock->sock_str; + db_vals[6].val.int_val = send_sock->port_no; } } if(to==0) { - db_vals[5].val.str_val.s = "any:255.255.255.255:9"; - db_vals[5].val.str_val.len = sizeof("any:255.255.255.255:9")-1; + set_columns_to_any(db_vals[7], db_vals[8], db_vals[9]); } else { su2ip_addr(&to_ip, to); - set_sock_column( db_vals[5], toip_buff, &to_ip, - (unsigned long)su_getport(to), proto); + set_sock_columns( db_vals[7], db_vals[8], db_vals[9], toip_buff, + &to_ip, (unsigned short)su_getport(to), proto); } - db_vals[6].val.time_val = time(NULL); + db_vals[10].val.time_val = time(NULL); - db_vals[7].val.string_val = "out"; + db_vals[11].val.string_val = "out"; - 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_vals[12].val.str_val.s = get_from(msg)->tag_value.s; + db_vals[12].val.str_val.len = get_from(msg)->tag_value.len; if (save_siptrace(msg,avp,&avp_value,db_keys,db_vals) < 0) { LM_ERR("failed to save siptrace\n"); @@ -1192,22 +1317,23 @@ static void trace_onreply_in(struct cell* t, int type, struct tmcb_params *ps) db_vals[3].val.str_val.s = statusbuf; db_vals[3].val.str_val.len = len; - set_sock_column( db_vals[4], fromip_buff, &msg->rcv.src_ip, - msg->rcv.src_port, msg->rcv.proto); + set_sock_columns( db_vals[4], db_vals[5], db_vals[6], fromip_buff, + &msg->rcv.src_ip, msg->rcv.src_port, msg->rcv.proto); - if(trace_local_ip.s && trace_local_ip.len > 0) - db_vals[5].val.str_val = trace_local_ip; + if(trace_local_ip.s && trace_local_ip.len > 0){ + set_columns_to_trace_local_ip(db_vals[7], db_vals[8], db_vals[9]); + } else { - set_sock_column( db_vals[5], toip_buff, &msg->rcv.dst_ip, - msg->rcv.dst_port, msg->rcv.proto); + set_sock_columns( db_vals[7], db_vals[8], db_vals[9], toip_buff, + &msg->rcv.dst_ip, msg->rcv.dst_port, msg->rcv.proto); } - db_vals[6].val.time_val = time(NULL); + db_vals[10].val.time_val = time(NULL); - db_vals[7].val.string_val = "in"; + db_vals[11].val.string_val = "in"; - 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_vals[12].val.str_val.s = get_from(msg)->tag_value.s; + db_vals[12].val.str_val.len = get_from(msg)->tag_value.len; if (save_siptrace(req,avp,&avp_value,db_keys,db_vals) < 0) { LM_ERR("failed to save siptrace\n"); @@ -1313,11 +1439,12 @@ static void trace_onreply_out(struct cell* t, int type, struct tmcb_params *ps) db_vals[2].val.str_val.len = t->method.len; - if(trace_local_ip.s && trace_local_ip.len > 0) - db_vals[4].val.str_val = trace_local_ip; + if(trace_local_ip.s && trace_local_ip.len > 0){ + set_columns_to_trace_local_ip(db_vals[4], db_vals[5], db_vals[6]); + } else { - set_sock_column( db_vals[4], fromip_buff, &msg->rcv.dst_ip, - msg->rcv.dst_port, msg->rcv.proto); + set_sock_columns( db_vals[4], db_vals[5], db_vals[6], fromip_buff, + &msg->rcv.dst_ip, msg->rcv.dst_port, msg->rcv.proto); } strcpy(statusbuf, int2str(ps->code, &len)); @@ -1328,20 +1455,19 @@ static void trace_onreply_out(struct cell* t, int type, struct tmcb_params *ps) dst = (struct dest_info*)ps->extra2; if(dst==0) { - db_vals[5].val.str_val.s = "any:255.255.255.255:9"; - db_vals[5].val.str_val.len = sizeof("any:255.255.255.255:9")-1; + set_columns_to_any( db_vals[7], db_vals[8], db_vals[9]); } else { su2ip_addr(&to_ip, &dst->to); - set_sock_column( db_vals[5], toip_buff, &to_ip, - (unsigned long)su_getport(&dst->to), dst->proto); + set_sock_columns( db_vals[7], db_vals[8], db_vals[9], toip_buff, + &to_ip, (unsigned long)su_getport(&dst->to), dst->proto); } - db_vals[6].val.time_val = time(NULL); + db_vals[10].val.time_val = time(NULL); - db_vals[7].val.string_val = "out"; + db_vals[11].val.string_val = "out"; - 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_vals[12].val.str_val.s = get_from(msg)->tag_value.s; + db_vals[12].val.str_val.len = get_from(msg)->tag_value.len; if (save_siptrace(req,avp,&avp_value,db_keys,db_vals) < 0) { LM_ERR("failed to save siptrace\n"); @@ -1430,11 +1556,12 @@ static void trace_sl_onreply_out( unsigned int types, struct sip_msg* req, 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; - if(trace_local_ip.s && trace_local_ip.len > 0) - db_vals[4].val.str_val = trace_local_ip; + if(trace_local_ip.s && trace_local_ip.len > 0){ + set_columns_to_trace_local_ip( db_vals[4], db_vals[5], db_vals[6]); + } else { - set_sock_column( db_vals[4], fromip_buff, &msg->rcv.dst_ip, - msg->rcv.dst_port, msg->rcv.proto); + set_sock_columns( db_vals[4], db_vals[5], db_vals[6], fromip_buff, + &msg->rcv.dst_ip, msg->rcv.dst_port, msg->rcv.proto); } strcpy(statusbuf, int2str(sl_param->code, &len)); @@ -1444,20 +1571,19 @@ static void trace_sl_onreply_out( unsigned int types, struct sip_msg* req, memset(&to_ip, 0, sizeof(struct ip_addr)); if(sl_param->dst==0) { - db_vals[5].val.str_val.s = "any:255.255.255.255"; - db_vals[5].val.str_val.len = sizeof("any:255.255.255.255")-1; + set_columns_to_any(db_vals[7], db_vals[8], db_vals[9]); } else { su2ip_addr(&to_ip, sl_param->dst); - set_sock_column( db_vals[5], toip_buff, &to_ip, - (unsigned long)su_getport(sl_param->dst), req->rcv.proto); + set_sock_columns( db_vals[7], db_vals[8],db_vals[9], toip_buff, &to_ip, + (unsigned short)su_getport(sl_param->dst), req->rcv.proto); } - db_vals[6].val.time_val = time(NULL); + db_vals[10].val.time_val = time(NULL); - db_vals[7].val.string_val = "out"; + db_vals[11].val.string_val = "out"; - 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_vals[12].val.str_val.s = get_from(msg)->tag_value.s; + db_vals[12].val.str_val.len = get_from(msg)->tag_value.len; if (save_siptrace(msg,avp,&avp_value,db_keys,db_vals) < 0) { LM_ERR("failed to save siptrace\n"); @@ -1632,7 +1758,8 @@ static int trace_send_duplicate(char *buf, int len) return ret; } -static int trace_send_hep_duplicate(str *body, str *fromip, str *toip) +static int trace_send_hep_duplicate(str *body, str *fromproto, str *fromip, + unsigned short fromport, str *toproto, str *toip, unsigned short toport) { struct proxy_l * p=NULL /* make gcc happy */; void* buffer = NULL; @@ -1675,8 +1802,8 @@ static int trace_send_hep_duplicate(str *body, str *fromip, str *toip) } /* Convert proto:ip:port to sockaddress union SRC IP */ - if (pipport2su(fromip, &from_su, &proto)==-1 || - (pipport2su(toip, &to_su, &proto)==-1)) + if (pipport2su(fromproto, fromip, fromport, &from_su, &proto)==-1 || + (pipport2su(toproto, toip, toport, &to_su, &proto)==-1)) goto error; /* check if from and to are in the same family*/ @@ -1824,57 +1951,46 @@ static int trace_send_hep_duplicate(str *body, str *fromip, str *toip) * \param proto uint protocol type * \return success / unsuccess */ -static int pipport2su (str *pipport, union sockaddr_union *tmp_su, - unsigned int *proto) +static int pipport2su (str *sproto, str *ip, unsigned short port, + union sockaddr_union *tmp_su, unsigned int *proto) { - unsigned int port_no, cutlen = 4; - struct ip_addr *ip; - char *p; - str port_str, host_uri; + struct ip_addr *ip_a; + str host_uri; /*parse protocol */ - if(strncmp(pipport->s, "udp:",4) == 0) *proto = IPPROTO_UDP; - else if(strncmp(pipport->s, "tcp:",4) == 0) *proto = IPPROTO_TCP; - else if(strncmp(pipport->s, "tls:",4) == 0) *proto = IPPROTO_IDP; /* fake proto type */ + if(strncmp(sproto->s, "udp:",4) == 0) *proto = IPPROTO_UDP; + else if(strncmp(sproto->s, "tcp:",4) == 0) *proto = IPPROTO_TCP; + else if(strncmp(sproto->s, "tls:",4) == 0) *proto = IPPROTO_IDP; /* fake proto type */ #ifdef USE_SCTP - else if(strncmp(pipport->s, "sctp:",5) == 0) cutlen = 5, *proto = IPPROTO_SCTP; + else if(strncmp(sproto->s, "sctp:",5) == 0) cutlen = 5, *proto = IPPROTO_SCTP; #endif - else if(strncmp(pipport->s, "any:",4) == 0) *proto = IPPROTO_UDP; + else if(strncmp(sproto->s, "any:",4) == 0) *proto = IPPROTO_UDP; else { - LM_ERR("bad protocol %.*s\n", pipport->len,pipport->s); + LM_ERR("bad protocol %.*s\n", sproto->len, sproto->s); return -1; } - /*separate proto and host */ - p = pipport->s + cutlen; - if( (*(p)) == '\0') { + /*check if ip is not null*/ + if (ip->len == 0) { LM_ERR("malformed ip address\n"); return -1; } - host_uri.s = p; - for (p=pipport->s+pipport->len ; p>=host_uri.s && *p!=':' ; p--); - if (*p!=':') { - LM_ERR("no port specified\n"); - return -1; + if (port == 0) { + port = SIP_PORT; } + else{ /*the address contains a port number*/ - port_str.s = p + 1; - port_str.len = pipport->len+pipport->s - port_str.s; - LM_DBG("the port string is %.*s\n", port_str.len, port_str.s); - if(str2int(&port_str, &port_no) != 0 ) { - LM_ERR("there is not a valid number port\n"); - return -1; - } - if (port_no<1024 || port_no>65536) - { - LM_ERR("invalid port number; must be in [1024,65536]\n"); - return -1; + if (port_no<1024 || port_no>65536) + { + LM_ERR("invalid port number; must be in [1024,65536]\n"); + return -1; + } } - host_uri.len = p - host_uri.s; - LM_DBG("proto %d, host %.*s , port %d \n",*proto,host_uri.len,host_uri.s,port_no ); + LM_DBG("proto %d, host %.*s , port %d \n",*proto, ip->len, ip->s, port); /* now IPv6 address has no brakets. It should be fixed! */ + host_uri = *ip; if (host_uri.s[0] == '[') { if(host_uri.s[host_uri.len-1] != ']') { LM_ERR("bracket not closed\n"); @@ -1885,12 +2001,12 @@ static int pipport2su (str *pipport, union sockaddr_union *tmp_su, } /* check if it's an ip address */ - if (((ip=str2ip(&host_uri))!=0) + if (((ip_a = str2ip(&host_uri)) != 0) #ifdef USE_IPV6 - || ((ip=str2ip6(&host_uri))!=0) + || ((ip_a = str2ip6 (&host_uri)) != 0) #endif ) { - ip_addr2su(tmp_su, ip, ntohs(port_no)); + ip_addr2su(tmp_su, ip_a, ntohs(port)); return 0; } diff --git a/scripts/db_berkeley/opensips/sip_trace b/scripts/db_berkeley/opensips/sip_trace index e51f4e182d7..4866a15e161 100644 --- a/scripts/db_berkeley/opensips/sip_trace +++ b/scripts/db_berkeley/opensips/sip_trace @@ -1,5 +1,5 @@ METADATA_COLUMNS -id(int) time_stamp(datetime) callid(str) traced_user(str) msg(str) method(str) status(str) fromip(str) toip(str) fromtag(str) direction(str) +id(int) time_stamp(datetime) callid(str) traced_user(str) msg(str) method(str) status(str) from_proto(str) from_ip(str) from_port(int) to_proto(str) to_ip(str) to_port(int) fromtag(str) direction(str) METADATA_KEY 2 METADATA_READONLY @@ -7,4 +7,4 @@ METADATA_READONLY METADATA_LOGFLAGS 0 METADATA_DEFAULTS -NIL|'1900-01-01 00:00:01'|''|NULL|NIL|''|NULL|''|''|''|'' +NIL|'1900-01-01 00:00:01'|''|NULL|NIL|''|NULL|NIL|''|NIL|NIL|''|NIL|''|'' diff --git a/scripts/dbtext/opensips/sip_trace b/scripts/dbtext/opensips/sip_trace index 7d8d9539fa9..98ed25c6e5f 100644 --- a/scripts/dbtext/opensips/sip_trace +++ b/scripts/dbtext/opensips/sip_trace @@ -1 +1 @@ -id(int,auto) time_stamp(int) callid(string) traced_user(string,null) msg(string) method(string) status(string,null) fromip(string) toip(string) fromtag(string) direction(string) +id(int,auto) time_stamp(int) callid(string) traced_user(string,null) msg(string) method(string) status(string,null) from_proto(string) from_ip(string) from_port(int) to_proto(string) to_ip(string) to_port(int) fromtag(string) direction(string) diff --git a/scripts/mysql/siptrace-create.sql b/scripts/mysql/siptrace-create.sql index 47a06ef624d..ed37a2238f5 100644 --- a/scripts/mysql/siptrace-create.sql +++ b/scripts/mysql/siptrace-create.sql @@ -7,14 +7,18 @@ CREATE TABLE sip_trace ( msg TEXT NOT NULL, method CHAR(32) DEFAULT '' NOT NULL, status CHAR(128) DEFAULT NULL, - fromip CHAR(50) DEFAULT '' NOT NULL, - toip CHAR(50) DEFAULT '' NOT NULL, + from_proto CHAR(5) NOT NULL, + from_ip CHAR(50) DEFAULT '' NOT NULL, + from_port INT(5) UNSIGNED NOT NULL, + to_proto CHAR(5) NOT NULL, + to_ip CHAR(50) DEFAULT '' NOT NULL, + to_port INT(5) UNSIGNED NOT NULL, fromtag CHAR(64) DEFAULT '' NOT NULL, direction CHAR(4) DEFAULT '' NOT NULL ) ENGINE=MyISAM; CREATE INDEX traced_user_idx ON sip_trace (traced_user); CREATE INDEX date_idx ON sip_trace (time_stamp); -CREATE INDEX fromip_idx ON sip_trace (fromip); +CREATE INDEX fromip_idx ON sip_trace (from_ip); CREATE INDEX callid_idx ON sip_trace (callid); diff --git a/scripts/opensipsctlrc b/scripts/opensipsctlrc index aeef5eaf8f2..b220574cdcc 100644 --- a/scripts/opensipsctlrc +++ b/scripts/opensipsctlrc @@ -16,25 +16,25 @@ ## by default none is loaded # If you want to setup a database with opensipsdbctl, you must at least specify # this parameter. -# DBENGINE=MYSQL +DBENGINE=MYSQL ## database host -# DBHOST=localhost +DBHOST=localhost ## database name (for ORACLE this is TNS name) -# DBNAME=opensips +DBNAME=opensips # database path used by dbtext or db_berkeley # DB_PATH="/usr/local/etc/opensips/dbtext" ## database read/write user -# DBRWUSER=opensips +DBRWUSER=opensips ## password for database read/write user -# DBRWPW="opensipsrw" +DBRWPW="opensipsrw" ## database super user (for ORACLE this is 'scheme-creator' user) -# DBROOTUSER="root" +DBROOTUSER="root" # user name column # USERCOL="username" diff --git a/scripts/opensipsdbctl b/scripts/opensipsdbctl index a231d2bc00f..4f9bff251d7 100755 --- a/scripts/opensipsdbctl +++ b/scripts/opensipsdbctl @@ -10,7 +10,7 @@ PATH=$PATH:/usr/local/sbin/ # for testing only, please don't enable this in production environments # as this introduce security risks -TEST="false" +TEST="true" ### include resource files, if any if [ -f /etc/opensips/opensipsctlrc ]; then diff --git a/scripts/oracle/siptrace-create.sql b/scripts/oracle/siptrace-create.sql index d083e2d9627..c3a8ec5d8b6 100644 --- a/scripts/oracle/siptrace-create.sql +++ b/scripts/oracle/siptrace-create.sql @@ -7,8 +7,12 @@ CREATE TABLE sip_trace ( msg CLOB, method VARCHAR2(32) DEFAULT '', status VARCHAR2(128) DEFAULT NULL, - fromip VARCHAR2(50) DEFAULT '', - toip VARCHAR2(50) DEFAULT '', + from_proto VARCHAR2(5), + from_ip VARCHAR2(50) DEFAULT '', + from_port NUMBER(10), + to_proto VARCHAR2(5), + to_ip VARCHAR2(50) DEFAULT '', + to_port NUMBER(10), fromtag VARCHAR2(64) DEFAULT '', direction VARCHAR2(4) DEFAULT '' ); @@ -23,6 +27,6 @@ BEGIN map2users('sip_trace'); END; / CREATE INDEX sip_trace_traced_user_idx ON sip_trace (traced_user); CREATE INDEX sip_trace_date_idx ON sip_trace (time_stamp); -CREATE INDEX sip_trace_fromip_idx ON sip_trace (fromip); +CREATE INDEX sip_trace_fromip_idx ON sip_trace (from_ip); CREATE INDEX sip_trace_callid_idx ON sip_trace (callid); diff --git a/scripts/pi_http/pi_framework.xml b/scripts/pi_http/pi_framework.xml index 381864e7909..a5ea0688660 100644 --- a/scripts/pi_http/pi_framework.xml +++ b/scripts/pi_http/pi_framework.xml @@ -749,8 +749,12 @@ msgDB_BLOB methodDB_STR statusDB_STR - fromipDB_STR - toipDB_STR + from_protoDB_STR + from_ipDB_STR + from_portDB_INT + to_protoDB_STR + to_ipDB_STR + to_portDB_INT fromtagDB_STR directionDB_STR @@ -3639,8 +3643,12 @@
msgmethodstatus - fromip - toip + from_proto + from_ip + from_port + to_proto + to_ip + to_portfromtagdirection @@ -3655,8 +3663,12 @@ msgmethodstatus - fromip - toip + from_proto + from_ip + from_port + to_proto + to_ip + to_portfromtagdirection @@ -3674,8 +3686,12 @@ msgmethodstatus - fromip - toip + from_proto + from_ip + from_port + to_proto + to_ip + to_portfromtagdirection diff --git a/scripts/pi_http/siptrace-mod b/scripts/pi_http/siptrace-mod index f58a03be046..336087b8a33 100644 --- a/scripts/pi_http/siptrace-mod +++ b/scripts/pi_http/siptrace-mod @@ -11,8 +11,12 @@ msgmethodstatus - fromip - toip + from_proto + from_ip + from_port + to_proto + to_ip + to_portfromtagdirection @@ -27,8 +31,12 @@ msgmethodstatus - fromip - toip + from_proto + from_ip + from_port + to_proto + to_ip + to_portfromtagdirection @@ -46,8 +54,12 @@ msgmethodstatus - fromip - toip + from_proto + from_ip + from_port + to_proto + to_ip + to_portfromtagdirection diff --git a/scripts/pi_http/siptrace-table b/scripts/pi_http/siptrace-table index ae535bd6568..996e54c3db6 100644 --- a/scripts/pi_http/siptrace-table +++ b/scripts/pi_http/siptrace-table @@ -9,8 +9,12 @@ msgDB_BLOBmethodDB_STRstatusDB_STR - fromipDB_STR - toipDB_STR + from_protoDB_STR + from_ipDB_STR + from_portDB_INT + to_protoDB_STR + to_ipDB_STR + to_portDB_INTfromtagDB_STRdirectionDB_STR diff --git a/scripts/postgres/siptrace-create.sql b/scripts/postgres/siptrace-create.sql index 6ac01e470aa..9f4391fb75d 100644 --- a/scripts/postgres/siptrace-create.sql +++ b/scripts/postgres/siptrace-create.sql @@ -7,8 +7,12 @@ CREATE TABLE sip_trace ( msg TEXT NOT NULL, method VARCHAR(32) DEFAULT '' NOT NULL, status VARCHAR(128) DEFAULT NULL, - fromip VARCHAR(50) DEFAULT '' NOT NULL, - toip VARCHAR(50) DEFAULT '' NOT NULL, + from_proto VARCHAR(5) NOT NULL, + from_ip VARCHAR(50) DEFAULT '' NOT NULL, + from_port INTEGER NOT NULL, + to_proto VARCHAR(5) NOT NULL, + to_ip VARCHAR(50) DEFAULT '' NOT NULL, + to_port INTEGER NOT NULL, fromtag VARCHAR(64) DEFAULT '' NOT NULL, direction VARCHAR(4) DEFAULT '' NOT NULL ); @@ -16,6 +20,6 @@ CREATE TABLE sip_trace ( ALTER SEQUENCE sip_trace_id_seq MAXVALUE 2147483647 CYCLE; CREATE INDEX sip_trace_traced_user_idx ON sip_trace (traced_user); CREATE INDEX sip_trace_date_idx ON sip_trace (time_stamp); -CREATE INDEX sip_trace_fromip_idx ON sip_trace (fromip); +CREATE INDEX sip_trace_fromip_idx ON sip_trace (from_ip); CREATE INDEX sip_trace_callid_idx ON sip_trace (callid); From 534884d4ea7989b69e17fed250170f9be805d760 Mon Sep 17 00:00:00 2001 From: Andrei Datcu Date: Thu, 19 Jun 2014 16:11:57 +0300 Subject: [PATCH 2/3] Fixed typo in siptrace's readme --- modules/dispatcher/dispatcher.c | 1 + modules/siptrace/README | 2 +- modules/siptrace/doc/siptrace_admin.xml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/dispatcher/dispatcher.c b/modules/dispatcher/dispatcher.c index ac3ad957667..f85b60ae272 100644 --- a/modules/dispatcher/dispatcher.c +++ b/modules/dispatcher/dispatcher.c @@ -67,6 +67,7 @@ #define DS_DEST_PRIO_COL "priority" #define DS_DEST_ATTRS_COL "attrs" #define DS_TABLE_NAME "dispatcher" +#define DS_PARTITION_DELIM ':' /** parameters */ int ds_force_dst = 0; diff --git a/modules/siptrace/README b/modules/siptrace/README index bf67e943e05..e04f1744645 100644 --- a/modules/siptrace/README +++ b/modules/siptrace/README @@ -209,7 +209,7 @@ modparam("siptrace", "duplicate_uri", "sip:10.1.1.1:5888") The address to be used in fromip fields (protocol, ip and port) for local generated messages. If not set, the module sets it to the address of the socket that will be used to send the - message. Protocol and/or port ar optional and if ommited will + message. Protocol and/or port are optional and if omitted will take the default values: udp and 5060. Default value is "NULL". diff --git a/modules/siptrace/doc/siptrace_admin.xml b/modules/siptrace/doc/siptrace_admin.xml index 716fed931c5..e40417bc8f8 100644 --- a/modules/siptrace/doc/siptrace_admin.xml +++ b/modules/siptrace/doc/siptrace_admin.xml @@ -234,7 +234,7 @@ modparam("siptrace", "duplicate_uri", "sip:10.1.1.1:5888") The address to be used in fromip fields (protocol, ip and port) for local generated messages. If not set, the module sets it to the address of the socket that will be used to send the message. Protocol and/or port - ar optional and if ommited will take the default values: udp and 5060. + are optional and if omitted will take the default values: udp and 5060. From 58e6b4c9aaf9be3c770f7327dd2e180c2d0a56ef Mon Sep 17 00:00:00 2001 From: Andrei Datcu Date: Thu, 19 Jun 2014 16:21:49 +0300 Subject: [PATCH 3/3] Fixed formulation in siptrace's readme --- modules/siptrace/README | 11 ++++++----- modules/siptrace/doc/siptrace_admin.xml | 9 +++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/siptrace/README b/modules/siptrace/README index e04f1744645..0ac8f7cf50b 100644 --- a/modules/siptrace/README +++ b/modules/siptrace/README @@ -206,11 +206,12 @@ modparam("siptrace", "duplicate_uri", "sip:10.1.1.1:5888") 1.3.8. trace_local_ip (str) - The address to be used in fromip fields (protocol, ip and port) - for local generated messages. If not set, the module sets it to - the address of the socket that will be used to send the - message. Protocol and/or port are optional and if omitted will - take the default values: udp and 5060. + The address to be used in the fields that specifiy the source + address (protocol, ip and port) for local generated messages. + If not set, the module sets it to the address of the socket + that will be used to send the message. Protocol and/or port are + optional and if omitted will take the default values: udp and + 5060. Default value is "NULL". diff --git a/modules/siptrace/doc/siptrace_admin.xml b/modules/siptrace/doc/siptrace_admin.xml index e40417bc8f8..751bdc3e277 100644 --- a/modules/siptrace/doc/siptrace_admin.xml +++ b/modules/siptrace/doc/siptrace_admin.xml @@ -231,10 +231,11 @@ modparam("siptrace", "duplicate_uri", "sip:10.1.1.1:5888")
<varname>trace_local_ip</varname> (str) - The address to be used in fromip fields (protocol, ip and port) - for local generated messages. If not set, the module sets it to the address - of the socket that will be used to send the message. Protocol and/or port - are optional and if omitted will take the default values: udp and 5060. + The address to be used in the fields that specifiy the source address + (protocol, ip and port) for local generated messages. If not set, + the module sets it to the address of the socket that will be used to send + the message. Protocol and/or port are optional and if omitted will take + the default values: udp and 5060.