MT#10339 CARRIER: nathelper filter by server_id

Change-Id: Ia5cc3928ef73236f443f391e2eaf460dec064e1d
changes/54/2054/1
Victor Seva 11 years ago
parent e427af0ee3
commit a6e79ec2f2

@ -14,5 +14,9 @@ sipwise/add_pcem_module.patch
sipwise/lcr_rate_module.patch
sipwise/parallel_build.patch
sipwise/tcap.patch
# carrier support
sipwise/usrloc_dbro.patch
#TODO#sipwise/nathelper_socket_filter.patch
sipwise/0001-usrloc-support-filter-by-server_id-at-get_all_uconta.patch
sipwise/0002-usrloc-add-module-option-to-support-preload-using-se.patch
sipwise/0003-nathelper-support-filter-contacts-by-server_id.patch
##

@ -0,0 +1,144 @@
From 039231a3b61c00fe36e868417144daa9f04936ba Mon Sep 17 00:00:00 2001
From: Victor Seva <linuxmaniac@torreviejawireless.org>
Date: Sat, 4 Jul 2015 08:08:08 +0200
Subject: [PATCH] usrloc: support filter by server_id at get_all_ucontacts
---
modules/usrloc/dlist.c | 33 +++++++++++++++++++++++++--------
modules/usrloc/dlist.h | 3 ++-
modules/usrloc/usrloc.h | 4 +++-
3 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/modules/usrloc/dlist.c b/modules/usrloc/dlist.c
index 1a95cc6..1081aad 100644
--- a/modules/usrloc/dlist.c
+++ b/modules/usrloc/dlist.c
@@ -85,10 +85,12 @@ static inline int find_dlist(str* _n, dlist_t** _d)
* \param flags contact flags
* \param part_idx part index
* \param part_max maximal part
+ * \param GAU options
* \return 0 on success, positive if buffer size was not sufficient, negative on failure
*/
static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
- unsigned int part_idx, unsigned int part_max)
+ unsigned int part_idx, unsigned int part_max,
+ int options)
{
struct socket_info *sock;
unsigned int dbflags;
@@ -108,9 +110,9 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
int i;
void *cp;
int shortage, needed;
- db_key_t keys1[3]; /* where */
- db_val_t vals1[3];
- db_op_t ops1[3];
+ db_key_t keys1[4]; /* where */
+ db_val_t vals1[4];
+ db_op_t ops1[4];
db_key_t keys2[6]; /* select */
int n[2] = {2,6}; /* number of dynamic values used on key1/key2 */
@@ -160,6 +162,14 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
vals1[n[0]].val.int_val = 1;
n[0]++;
}
+ if(options&GAU_OPT_SERVER_ID) {
+ keys1[n[0]] = &srv_id_col;
+ ops1[n[0]] = OP_EQ;
+ vals1[n[0]].type = DB1_INT;
+ vals1[n[0]].nul = 0;
+ vals1[n[0]].val.int_val = server_id;
+ n[0]++;
+ }
/* TODO: use part_idx and part_max on keys1 */
@@ -323,10 +333,12 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
* \param flags contact flags
* \param part_idx part index
* \param part_max maximal part
+ * \param GAU options
* \return 0 on success, positive if buffer size was not sufficient, negative on failure
*/
static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
- unsigned int part_idx, unsigned int part_max)
+ unsigned int part_idx, unsigned int part_max,
+ int options)
{
dlist_t *p;
urecord_t *r;
@@ -370,6 +382,9 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
if ((c->cflags & flags) != flags)
continue;
+ if(options&GAU_OPT_SERVER_ID && server_id!=c->server_id)
+ continue;
+
if(ul_keepalive_timeout>0 && c->last_keepalive>0)
{
if(c->sock!=NULL && c->sock->proto==PROTO_UDP)
@@ -468,15 +483,17 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
* \param flags contact flags
* \param part_idx part index
* \param part_max maximal part
+ * \param GAU options
* \return 0 on success, positive if buffer size was not sufficient, negative on failure
*/
int get_all_ucontacts(void *buf, int len, unsigned int flags,
- unsigned int part_idx, unsigned int part_max)
+ unsigned int part_idx, unsigned int part_max,
+ int options)
{
if (db_mode==DB_ONLY)
- return get_all_db_ucontacts( buf, len, flags, part_idx, part_max);
+ return get_all_db_ucontacts( buf, len, flags, part_idx, part_max, options);
else
- return get_all_mem_ucontacts( buf, len, flags, part_idx, part_max);
+ return get_all_mem_ucontacts( buf, len, flags, part_idx, part_max, options);
}
diff --git a/modules/usrloc/dlist.h b/modules/usrloc/dlist.h
index 9b8b84c..a210996 100644
--- a/modules/usrloc/dlist.h
+++ b/modules/usrloc/dlist.h
@@ -109,10 +109,11 @@ int synchronize_all_udomains(int istart, int istep);
* \param flags contact flags
* \param part_idx part index
* \param part_max maximal part
+ * \param GAU options
* \return 0 on success, positive if buffer size was not sufficient, negative on failure
*/
int get_all_ucontacts(void *buf, int len, unsigned int flags,
- unsigned int part_idx, unsigned int part_max);
+ unsigned int part_idx, unsigned int part_max, int options);
/*!
diff --git a/modules/usrloc/usrloc.h b/modules/usrloc/usrloc.h
index 5688e8c..4425a06 100644
--- a/modules/usrloc/usrloc.h
+++ b/modules/usrloc/usrloc.h
@@ -40,6 +40,8 @@
#define DB_ONLY 3
#define DB_READONLY 4
+#define GAU_OPT_SERVER_ID (1<<0) /* filter query by server_id */
+
/*forward declaration necessary for udomain*/
struct udomain;
@@ -181,7 +183,7 @@ typedef void (*unlock_udomain_t)(struct udomain* _d, str *_aor);
typedef int (*register_udomain_t)(const char* _n, struct udomain** _d);
typedef int (*get_all_ucontacts_t) (void* buf, int len, unsigned int flags,
- unsigned int part_idx, unsigned int part_max);
+ unsigned int part_idx, unsigned int part_max, int options);
typedef int (*get_udomain_t)(const char* _n, udomain_t** _d);
--
2.1.4

@ -0,0 +1,92 @@
From aedd970a97fef3e00c9e490e458f6f9af19df4d2 Mon Sep 17 00:00:00 2001
From: Victor Seva <linuxmaniac@torreviejawireless.org>
Date: Sat, 4 Jul 2015 09:43:41 +0200
Subject: [PATCH] usrloc: add module option to support preload using server_id
as filter
---
modules/usrloc/udomain.c | 26 ++++++++++++++++++++++----
modules/usrloc/ul_mod.c | 4 +++-
modules/usrloc/ul_mod.h | 2 ++
3 files changed, 27 insertions(+), 5 deletions(-)
--- a/modules/usrloc/udomain.c
+++ b/modules/usrloc/udomain.c
@@ -379,6 +379,9 @@
db_row_t *row;
db_key_t columns[21];
db1_res_t* res = NULL;
+ db_key_t keys[1]; /* where */
+ db_val_t vals[1];
+ db_op_t ops[1];
str user, contact;
char* domain;
int i;
@@ -418,9 +421,21 @@
LM_NOTICE("load start time [%d]\n", (int)time(NULL));
#endif
+ if (ul_db_srvid) {
+ LM_NOTICE("filtered by server_id[%d]\n", server_id);
+ keys[0] = &srv_id_col;
+ ops[0] = OP_EQ;
+ vals[0].type = DB1_INT;
+ vals[0].nul = 0;
+ vals[0].val.int_val = server_id;
+ }
+
if (DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) {
- if (ul_dbf.query(_c, 0, 0, 0, columns, 0, (use_domain)?(21):(20), 0,
- 0) < 0) {
+ if (ul_dbf.query(_c, (ul_db_srvid)?(keys):(0),
+ (ul_db_srvid)?(ops):(0), (ul_db_srvid)?(vals):(0),
+ columns, (ul_db_srvid)?(1):(0),
+ (use_domain)?(21):(20), 0, 0) < 0)
+ {
LM_ERR("db_query (1) failed\n");
return -1;
}
@@ -429,8 +444,11 @@
return -1;
}
} else {
- if (ul_dbf.query(_c, 0, 0, 0, columns, 0, (use_domain)?(21):(20), 0,
- &res) < 0) {
+ if (ul_dbf.query(_c, (ul_db_srvid)?(keys):(0),
+ (ul_db_srvid)?(ops):(0), (ul_db_srvid)?(vals):(0),
+ columns, (ul_db_srvid)?(1):(0),
+ (use_domain)?(21):(20), 0, &res) < 0)
+ {
LM_ERR("db_query failed\n");
return -1;
}
--- a/modules/usrloc/ul_mod.c
+++ b/modules/usrloc/ul_mod.c
@@ -177,6 +177,8 @@
db1_con_t* ul_dbh_ro = 0; /* Read-Only Database connection handle */
db_func_t ul_dbf_ro;
+/* filter on load by server id */
+unsigned int ul_db_srvid = 0;
/*! \brief
* Exported functions
@@ -233,6 +235,7 @@
{"expires_type", PARAM_INT, &ul_expires_type},
{"db_raw_fetch_type", PARAM_INT, &ul_db_raw_fetch_type},
{"db_insert_null", PARAM_INT, &ul_db_insert_null},
+ {"server_id_filter", PARAM_INT, &ul_db_srvid},
{0, 0, 0}
};
--- a/modules/usrloc/ul_mod.h
+++ b/modules/usrloc/ul_mod.h
@@ -87,6 +87,8 @@
extern int handle_lost_tcp;
extern int close_expired_tcp;
+/* filter on load by server id */
+extern unsigned int ul_db_srvid;
/*! nat branch flag */
extern unsigned int nat_bflag;

@ -0,0 +1,63 @@
From 894796f6f1fa2d2778ace5c56f58d204ea06efc2 Mon Sep 17 00:00:00 2001
From: Victor Seva <linuxmaniac@torreviejawireless.org>
Date: Thu, 2 Apr 2015 16:27:23 +0200
Subject: [PATCH] nathelper: support filter contacts by server_id
---
modules/nathelper/nathelper.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/modules/nathelper/nathelper.c b/modules/nathelper/nathelper.c
index f6791db..5f20a5f 100644
--- a/modules/nathelper/nathelper.c
+++ b/modules/nathelper/nathelper.c
@@ -358,7 +358,8 @@ static unsigned int raw_ip = 0;
static unsigned short raw_port = 0;
static int nh_keepalive_timeout = 0;
static request_method_t sipping_method_id = 0;
-
+/* filter contacts by server_id */
+static int nh_filter_srvid = 0;
/*0-> disabled, 1 ->enabled*/
unsigned int *natping_state=0;
@@ -426,6 +427,7 @@ static param_export_t params[] = {
{"keepalive_timeout", INT_PARAM, &nh_keepalive_timeout },
{"udpping_from_path", INT_PARAM, &udpping_from_path },
{"append_sdp_oldmediaip", INT_PARAM, &sdp_oldmediaip },
+ {"filter_server_id", INT_PARAM, &nh_filter_srvid },
{0, 0, 0}
};
@@ -2067,6 +2069,7 @@ nh_timer(unsigned int ticks, void *timer_idx)
char *path_ip_str = NULL;
unsigned int path_ip = 0;
unsigned short path_port = 0;
+ int options = 0;
if((*natping_state) == 0)
goto done;
@@ -2079,9 +2082,10 @@ nh_timer(unsigned int ticks, void *timer_idx)
goto done;
}
}
+ if(nh_filter_srvid) options |= GAU_OPT_SERVER_ID;
rval = ul.get_all_ucontacts(buf, cblen, (ping_nated_only?ul.nat_flag:0),
((unsigned int)(unsigned long)timer_idx)*natping_interval+iteration,
- natping_processes*natping_interval);
+ natping_processes*natping_interval, options);
if (rval<0) {
LM_ERR("failed to fetch contacts\n");
goto done;
@@ -2097,7 +2101,7 @@ nh_timer(unsigned int ticks, void *timer_idx)
}
rval = ul.get_all_ucontacts(buf,cblen,(ping_nated_only?ul.nat_flag:0),
((unsigned int)(unsigned long)timer_idx)*natping_interval+iteration,
- natping_processes*natping_interval);
+ natping_processes*natping_interval, options);
if (rval != 0) {
pkg_free(buf);
goto done;
--
2.1.4
Loading…
Cancel
Save