Skip to content

Commit

Permalink
siptrace: send_sock_name - new parameter to specify send socket by name
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Apr 8, 2020
1 parent 1f52406 commit e0109d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/modules/siptrace/siptrace.c
Expand Up @@ -170,6 +170,7 @@ int trace_xheaders_write = 0;
int trace_xheaders_read = 0;

str trace_send_sock_str = {0, 0};
str trace_send_sock_name_str = {0, 0};
sip_uri_t *trace_send_sock_uri = 0;
socket_info_t *trace_send_sock_info = 0;

Expand Down Expand Up @@ -244,6 +245,8 @@ static param_export_t params[] = {
{"xheaders_read", INT_PARAM, &trace_xheaders_read},
{"hep_mode_on", INT_PARAM, &hep_mode_on},
{"force_send_sock", PARAM_STR, &trace_send_sock_str},
{"send_sock_addr", PARAM_STR, &trace_send_sock_str},
{"send_sock_name", PARAM_STR, &trace_send_sock_name_str},
{"hep_version", INT_PARAM, &hep_version},
{"hep_capture_id", INT_PARAM, &hep_capture_id},
{"trace_delayed", INT_PARAM, &trace_delayed},
Expand Down Expand Up @@ -346,7 +349,11 @@ static int mod_init(void)
}
}

if(trace_send_sock_str.s != 0) {
if(trace_send_sock_name_str.s != 0) {
trace_send_sock_info = ksr_get_socket_by_name(&trace_send_sock_name_str);
trace_send_sock_str.s = NULL;
trace_send_sock_str.len = 0;
} else if(trace_send_sock_str.s != 0) {
trace_send_sock_str.len = strlen(trace_send_sock_str.s);
trace_send_sock_uri = (sip_uri_t*)pkg_malloc(sizeof(sip_uri_t));
if(trace_send_sock_uri == 0) {
Expand Down
20 changes: 11 additions & 9 deletions src/modules/siptrace/siptrace_hep.c
Expand Up @@ -43,6 +43,7 @@ extern int hep_vendor_id;
extern str hep_auth_key_str;
extern str trace_send_sock_str;
extern sip_uri_t *trace_send_sock_uri;
extern str trace_send_sock_name_str;
extern socket_info_t *trace_send_sock_info;
extern str trace_dup_uri_str;
extern sip_uri_t *trace_dup_uri;
Expand Down Expand Up @@ -535,7 +536,6 @@ int hlog(struct sip_msg *msg, str *correlationid, str *message)
struct timezone tz;
struct dest_info dst;
struct proxy_l *p = NULL;
struct socket_info *si;

if(!correlationid) {
if(msg->callid == NULL && ((parse_headers(msg, HDR_CALLID_F, 0) == -1)
Expand Down Expand Up @@ -587,22 +587,24 @@ int hlog(struct sip_msg *msg, str *correlationid, str *message)
free_proxy(p); /* frees only p content, not p itself */
pkg_free(p);

if(trace_send_sock_str.s) {
LM_DBG("send sock activated, grep for the sock_info\n");
if(trace_send_sock_name_str.s) {
dst.send_sock = trace_send_sock_info;
} else if(trace_send_sock_str.s) {
LM_DBG("send sock activated - find the sock info\n");
if(trace_send_sock_info) {
si = trace_send_sock_info;
dst.send_sock = trace_send_sock_info;
} else {
si = grep_sock_info(&trace_send_sock_uri->host,
dst.send_sock = grep_sock_info(&trace_send_sock_uri->host,
trace_send_sock_uri->port_no,
trace_send_sock_uri->proto);
}
if(!si) {
if(!dst.send_sock) {
LM_WARN("local socket not found for: [%.*s]\n",
trace_send_sock_str.len, trace_send_sock_str.s);
} else {
LM_DBG("using local send socket: [%.*s] [%.*s]\n", si->name.len,
si->name.s, si->address_str.len, si->address_str.s);
dst.send_sock = si;
LM_DBG("using local send socket: [%.*s] [%.*s]\n",
dst.send_sock->name.len, dst.send_sock->name.s,
dst.send_sock->address_str.len, dst.send_sock->address_str.s);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/modules/siptrace/siptrace_send.c
Expand Up @@ -41,6 +41,7 @@ extern int trace_xheaders_read;
extern str trace_dup_uri_str;
extern sip_uri_t *trace_dup_uri;
extern str trace_send_sock_str;
extern str trace_send_sock_name_str;
extern sip_uri_t *trace_send_sock_uri;
extern socket_info_t *trace_send_sock_info;

Expand Down Expand Up @@ -315,7 +316,9 @@ int trace_send_duplicate(char *buf, int len, dest_info_t *dst2)
}

if(pdst->send_sock == NULL) {
if(trace_send_sock_str.s) {
if(trace_send_sock_name_str.s) {
pdst->send_sock = trace_send_sock_info;
} else if(trace_send_sock_str.s) {
LM_DBG("send sock activated, grep for the sock_info\n");
if(trace_send_sock_info) {
pdst->send_sock = trace_send_sock_info;
Expand Down

0 comments on commit e0109d5

Please sign in to comment.