mirror of https://github.com/sipwise/kamailio.git
This filters the query on DB_ONLY mode when retriving contacts for nat ping to the list of sockets we are listen into. Each server now manages its own nat contacts.changes/98/298/1
parent
81596a116d
commit
16f9b2cba3
@ -0,0 +1,200 @@
|
||||
--- a/modules/nathelper/nathelper.c
|
||||
+++ b/modules/nathelper/nathelper.c
|
||||
@@ -344,6 +344,7 @@
|
||||
static int natping_disable_flag = -1;
|
||||
static int natping_processes = 1;
|
||||
static int contact_only = 0;
|
||||
+static int filter_socket = 0;
|
||||
|
||||
static str nortpproxy_str = str_init("a=nortpproxy:yes");
|
||||
|
||||
@@ -426,6 +427,7 @@
|
||||
{"keepalive_timeout", INT_PARAM, &nh_keepalive_timeout },
|
||||
{"udpping_from_path", INT_PARAM, &udpping_from_path },
|
||||
{"contact_only", INT_PARAM, &contact_only },
|
||||
+ {"filter_socket", INT_PARAM, &filter_socket },
|
||||
|
||||
{0, 0, 0}
|
||||
};
|
||||
@@ -2061,6 +2063,7 @@
|
||||
char *path_ip_str = NULL;
|
||||
unsigned int path_ip = 0;
|
||||
unsigned short path_port = 0;
|
||||
+ unsigned int options = 0;
|
||||
|
||||
if((*natping_state) == 0)
|
||||
goto done;
|
||||
@@ -2073,10 +2076,13 @@
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
+
|
||||
+ if(contact_only) options |= GAU_OPT_ONLY_CONTACT;
|
||||
+ if(filter_socket) options |= GAU_OPT_FILTER_SOCKET;
|
||||
+
|
||||
rval = ul.get_all_ucontacts_opt(buf, cblen, (ping_nated_only?ul.nat_flag:0),
|
||||
((unsigned int)(unsigned long)timer_idx)*natping_interval+iteration,
|
||||
- natping_processes*natping_interval,
|
||||
- contact_only ? GAU_OPT_ONLY_CONTACT : 0);
|
||||
+ natping_processes*natping_interval, options);
|
||||
if (rval<0) {
|
||||
LM_ERR("failed to fetch contacts\n");
|
||||
goto done;
|
||||
@@ -2092,8 +2098,7 @@
|
||||
}
|
||||
rval = ul.get_all_ucontacts_opt(buf,cblen,(ping_nated_only?ul.nat_flag:0),
|
||||
((unsigned int)(unsigned long)timer_idx)*natping_interval+iteration,
|
||||
- natping_processes*natping_interval,
|
||||
- contact_only ? GAU_OPT_ONLY_CONTACT : 0);
|
||||
+ natping_processes*natping_interval, options);
|
||||
if (rval != 0) {
|
||||
pkg_free(buf);
|
||||
goto done;
|
||||
--- a/modules/usrloc/dlist.c
|
||||
+++ b/modules/usrloc/dlist.c
|
||||
@@ -79,6 +79,57 @@
|
||||
return 1;
|
||||
}
|
||||
|
||||
+int sprint_all_socket_lists(char **buf, int len)
|
||||
+{
|
||||
+ struct socket_info *si;
|
||||
+ struct socket_info** list;
|
||||
+ struct addr_info* ai;
|
||||
+ unsigned short proto;
|
||||
+ unsigned int pos = 0;
|
||||
+ size_t size = 0;
|
||||
+ str s_proto = STR_NULL;
|
||||
+ char *s = *buf;
|
||||
+
|
||||
+ proto=PROTO_UDP;
|
||||
+ do{
|
||||
+ list=get_sock_info_list(proto);
|
||||
+ s_proto.s = get_valid_proto_name(proto);
|
||||
+ s_proto.len = strlen(s_proto.s);
|
||||
+ LM_DBG("s_proto[%d]:%.s\n", s_proto.len, s_proto.len, s_proto.s);
|
||||
+ for(si=list?*list:0; si; si=si->next){
|
||||
+ if (si->addr_info_lst)
|
||||
+ {
|
||||
+ for (ai=si->addr_info_lst; ai; ai=ai->next)
|
||||
+ {
|
||||
+ size = 5 + s_proto.len + ai->address_str.len + si->port_no_str.len;
|
||||
+ if (pos + size + 1>len) goto error;
|
||||
+ snprintf(s + pos, size, ",'%s:%s:%s'",
|
||||
+ s_proto.s, ai->address_str.s, si->port_no_str.s);
|
||||
+ pos = pos + size;
|
||||
+ LM_DBG("ip[%d]:%.s\n", ai->address_str.len, ai->address_str.len, ai->address_str.s);
|
||||
+ LM_DBG("port[%d]:%.s\n", si->port_no_str.len, si->port_no_str.len, si->port_no_str.s);
|
||||
+ LM_DBG("pos:%d size:%d [%.s]\n", pos, size, pos, s);
|
||||
+ }
|
||||
+ }else{
|
||||
+ size = 5 + s_proto.len + si->name.len + si->port_no_str.len;
|
||||
+ if (pos + size + 1>len) goto error;
|
||||
+ snprintf(s + pos, size, ",'%s:%s:%s'",
|
||||
+ s_proto.s, si->name.s, si->port_no_str.s);
|
||||
+ pos = pos + size;
|
||||
+ LM_DBG("ip[%d]:%.s\n", si->name.len, si->name.len, si->name.s);
|
||||
+ LM_DBG("port[%d]:%.s\n", si->port_no_str.len, si->port_no_str.len, si->port_no_str.s);
|
||||
+ LM_DBG("pos:%d size:%d [%.s]\n", pos, size, pos, s);
|
||||
+ }
|
||||
+ }
|
||||
+ }while((proto=next_proto(proto)));
|
||||
+ s[0] = '('; s[pos] = ')';
|
||||
+ LM_DBG("pos:%d [%.s]\n", pos+1, len, s);
|
||||
+ return pos + 1;
|
||||
+
|
||||
+error:
|
||||
+ s[0] = '('; s[pos] = ')';
|
||||
+ return -1;
|
||||
+}
|
||||
|
||||
/*!
|
||||
* \brief Get all contacts from the database, in partitions if wanted
|
||||
@@ -96,6 +147,8 @@
|
||||
unsigned int options)
|
||||
{
|
||||
static char query_buf[512];
|
||||
+ static char socket_list[256];
|
||||
+ static str socket_str;
|
||||
static str query_str;
|
||||
|
||||
struct socket_info *sock;
|
||||
@@ -115,12 +168,41 @@
|
||||
int i;
|
||||
void *cp;
|
||||
int shortage, needed;
|
||||
+ char *query_format = NULL;
|
||||
|
||||
if(ul_dbf.raw_query==NULL) {
|
||||
LM_WARN("DB raw query support is required, but not implemented\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
+ if (options & GAU_OPT_FILTER_SOCKET)
|
||||
+ {
|
||||
+ socket_str.s = socket_list;
|
||||
+ socket_str.len = sprint_all_socket_lists(&socket_str.s, 256);
|
||||
+ if(socket_str.len<0) {
|
||||
+ LM_ERR("error generating socket_list parameter\n");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ LM_DBG("socket_str[%d]:[%.s]\n", socket_str.len, socket_str.len, socket_str.s);
|
||||
+ query_format = "select %.*s, %.*s, %.*s,"
|
||||
+ " %.*s, %.*s, %.*s from %s where %.*s > %.*s and"
|
||||
+#ifdef ORACLE_USRLOC
|
||||
+ " bitand(%.*s, %d) = %d and mod(id, %u) = %u and %.*s in %.*s";
|
||||
+#else
|
||||
+ " %.*s & %d = %d and id %% %u = %u and %.*s in %.*s";
|
||||
+#endif
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ query_format = "select %.*s, %.*s, %.*s,"
|
||||
+ " %.*s, %.*s, %.*s from %s where %.*s > %.*s and"
|
||||
+#ifdef ORACLE_USRLOC
|
||||
+ " bitand(%.*s, %d) = %d and mod(id, %u) = %u";
|
||||
+#else
|
||||
+ " %.*s & %d = %d and id %% %u = %u";
|
||||
+#endif
|
||||
+ }
|
||||
+
|
||||
cp = buf;
|
||||
shortage = 0;
|
||||
/* Reserve space for terminating 0000 */
|
||||
@@ -136,13 +218,8 @@
|
||||
|
||||
for (dom = root; dom!=NULL ; dom=dom->next) {
|
||||
/* build query */
|
||||
- i = snprintf( query_buf, sizeof(query_buf), "select %.*s, %.*s, %.*s,"
|
||||
- " %.*s, %.*s, %.*s from %s where %.*s > %.*s and"
|
||||
-#ifdef ORACLE_USRLOC
|
||||
- " bitand(%.*s, %d) = %d and mod(id, %u) = %u",
|
||||
-#else
|
||||
- " %.*s & %d = %d and id %% %u = %u",
|
||||
-#endif
|
||||
+ i = snprintf( query_buf, sizeof(query_buf),
|
||||
+ query_format,
|
||||
received_col.len, received_col.s,
|
||||
contact_col.len, contact_col.s,
|
||||
sock_col.len, sock_col.s,
|
||||
@@ -153,7 +230,9 @@
|
||||
expires_col.len, expires_col.s,
|
||||
now_len, now_s,
|
||||
cflags_col.len, cflags_col.s,
|
||||
- flags, flags, part_max, part_idx);
|
||||
+ flags, flags, part_max, part_idx,
|
||||
+ sock_col.len, sock_col.s,
|
||||
+ socket_str.len, socket_str.s);
|
||||
if ( i>=sizeof(query_buf) ) {
|
||||
LM_ERR("DB query too long\n");
|
||||
return -1;
|
||||
--- a/modules/usrloc/usrloc.h
|
||||
+++ b/modules/usrloc/usrloc.h
|
||||
@@ -43,6 +43,7 @@
|
||||
#define DB_READONLY 4
|
||||
|
||||
#define GAU_OPT_ONLY_CONTACT (1<<0) /* ignore "received" address and always return contact */
|
||||
+#define GAU_OPT_FILTER_SOCKET (1<<1) /* filter query by socket field */
|
||||
|
||||
/*forward declaration necessary for udomain*/
|
||||
|
||||
Loading…
Reference in new issue