add 12583_nathelper.contact_only.patch

pull/1/head
Richard Fuchs 14 years ago
parent d08c94d0ac
commit 791ee39096

@ -0,0 +1,204 @@
diff --git a/modules_k/nathelper/nathelper.c b/modules_k/nathelper/nathelper.c
index 7195054..f0f2598 100644
--- a/modules_k/nathelper/nathelper.c
+++ b/modules_k/nathelper/nathelper.c
@@ -333,6 +333,7 @@ static char *force_socket_str = 0;
static pid_t mypid;
static int sipping_flag = -1;
static int natping_processes = 1;
+static int contact_only = 0;
static str nortpproxy_str = str_init("a=nortpproxy:yes");
@@ -402,6 +403,7 @@ static param_export_t params[] = {
{"sipping_bflag", INT_PARAM, &sipping_flag },
{"natping_processes", INT_PARAM, &natping_processes },
{"natping_socket", STR_PARAM, &natping_socket },
+ {"contact_only", INT_PARAM, &contact_only },
{0, 0, 0}
};
@@ -1684,9 +1686,10 @@ nh_timer(unsigned int ticks, void *timer_idx)
goto done;
}
}
- rval = ul.get_all_ucontacts(buf, cblen, (ping_nated_only?ul.nat_flag:0),
+ 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);
+ natping_processes*natping_interval,
+ contact_only ? GAU_OPT_ONLY_CONTACT : 0);
if (rval<0) {
LM_ERR("failed to fetch contacts\n");
goto done;
@@ -1700,9 +1703,10 @@ nh_timer(unsigned int ticks, void *timer_idx)
LM_ERR("out of pkg memory\n");
goto done;
}
- rval = ul.get_all_ucontacts(buf,cblen,(ping_nated_only?ul.nat_flag:0),
+ 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);
+ natping_processes*natping_interval,
+ contact_only ? GAU_OPT_ONLY_CONTACT : 0);
if (rval != 0) {
pkg_free(buf);
goto done;
diff --git a/modules_k/usrloc/dlist.c b/modules_k/usrloc/dlist.c
index 2d10283..d5d6640 100644
--- a/modules_k/usrloc/dlist.c
+++ b/modules_k/usrloc/dlist.c
@@ -88,10 +88,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 options GAU_OPT_* bit field
* \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,
+ unsigned int options)
{
static char query_buf[512];
static str query_str;
@@ -167,7 +169,7 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
/* received */
p = (char*)VAL_STRING(ROW_VALUES(row));
- if ( VAL_NULL(ROW_VALUES(row)) || p==0 || p[0]==0 ) {
+ if ( VAL_NULL(ROW_VALUES(row)) || p==0 || p[0]==0 || (options & GAU_OPT_ONLY_CONTACT) ) {
/* contact */
p = (char*)VAL_STRING(ROW_VALUES(row)+1);
if (VAL_NULL(ROW_VALUES(row)+1) || p==0 || p[0]==0) {
@@ -263,10 +265,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 options GAU_OPT_* bit field
* \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,
+ unsigned int options)
{
dlist_t *p;
urecord_t *r;
@@ -303,7 +307,7 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
*/
if ((c->cflags & flags) != flags)
continue;
- if (c->received.s) {
+ if (c->received.s && !(options & GAU_OPT_ONLY_CONTACT)) {
needed = (int)(sizeof(c->received.len)
+ c->received.len + sizeof(c->sock)
+ sizeof(c->cflags) + sizeof(c->path.len)
@@ -398,15 +402,34 @@ 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 options GAU_OPT_* bit field
* \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)
+int get_all_ucontacts_opt(void *buf, int len, unsigned int flags,
+ unsigned int part_idx, unsigned int part_max,
+ unsigned 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);
+}
+
+
+/*!
+ * \brief Same asget_all_ucontacts_opt() but without options
+ * \param buf target buffer
+ * \param len length of buffer
+ * \param flags contact flags
+ * \param part_idx part index
+ * \param part_max maximal part
+ * \param options GAU_OPT_* bit field
+ * \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)
+{
+ return get_all_ucontacts_opt(buf, len, flags, part_idx, part_max, 0);
}
diff --git a/modules_k/usrloc/dlist.h b/modules_k/usrloc/dlist.h
index 149b84c..01c91e5 100644
--- a/modules_k/usrloc/dlist.h
+++ b/modules_k/usrloc/dlist.h
@@ -123,6 +123,21 @@ int get_all_ucontacts(void *buf, int len, unsigned int flags,
/*!
+ * \brief Same as get_all_ucontacts() with options
+ * \param buf target buffer
+ * \param len length of buffer
+ * \param flags contact flags
+ * \param part_idx part index
+ * \param part_max maximal part
+ * \param options GAU_OPT_* bit field
+ * \return 0 on success, positive if buffer size was not sufficient, negative on failure
+ */
+int get_all_ucontacts_opt(void *buf, int len, unsigned int flags,
+ unsigned int part_idx, unsigned int part_max,
+ unsigned int options);
+
+
+/*!
* \brief Find and return usrloc domain
*
* \param _n domain name
diff --git a/modules_k/usrloc/usrloc.c b/modules_k/usrloc/usrloc.c
index 8c3408f..1ce0c36 100644
--- a/modules_k/usrloc/usrloc.c
+++ b/modules_k/usrloc/usrloc.c
@@ -67,6 +67,7 @@ int bind_usrloc(usrloc_api_t* api)
api->register_udomain = register_udomain;
api->get_udomain = get_udomain;
api->get_all_ucontacts = get_all_ucontacts;
+ api->get_all_ucontacts_opt = get_all_ucontacts_opt;
api->insert_urecord = insert_urecord;
api->delete_urecord = delete_urecord;
api->get_urecord = get_urecord;
diff --git a/modules_k/usrloc/usrloc.h b/modules_k/usrloc/usrloc.h
index bfd225a..ea0ec52 100644
--- a/modules_k/usrloc/usrloc.h
+++ b/modules_k/usrloc/usrloc.h
@@ -38,6 +38,8 @@
#define WRITE_BACK 2
#define DB_ONLY 3
+#define GAU_OPT_ONLY_CONTACT (1<<0) /* ignore "received" address and always return contact */
+
/*forward declaration necessary for udomain*/
struct udomain;
@@ -162,6 +164,9 @@ 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_opt_t) (void* buf, int len, unsigned int flags,
+ unsigned int part_idx, unsigned int part_max, unsigned int options);
+
typedef int (*get_all_ucontacts_t) (void* buf, int len, unsigned int flags,
unsigned int part_idx, unsigned int part_max);
@@ -179,6 +184,7 @@ typedef struct usrloc_api {
register_udomain_t register_udomain;
get_udomain_t get_udomain;
get_all_ucontacts_t get_all_ucontacts;
+ get_all_ucontacts_opt_t get_all_ucontacts_opt;
insert_urecord_t insert_urecord;
delete_urecord_t delete_urecord;
Loading…
Cancel
Save