From c2a3bbb0d2d185b8d657d188bafc88f1f8b5b497 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 18 Jan 2013 16:15:33 +0000 Subject: [PATCH] implement nathelper.contact_only [bool] option --- modules_k/nathelper/nathelper.c | 12 ++++++---- modules_k/usrloc/dlist.c | 39 ++++++++++++++++++++++++++------- modules_k/usrloc/dlist.h | 15 +++++++++++++ modules_k/usrloc/usrloc.c | 1 + modules_k/usrloc/usrloc.h | 6 +++++ 5 files changed, 61 insertions(+), 12 deletions(-) diff --git a/modules_k/nathelper/nathelper.c b/modules_k/nathelper/nathelper.c index 719505412..f0f25981b 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 2d102831c..d5d664099 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 149b84cf4..01c91e547 100644 --- a/modules_k/usrloc/dlist.h +++ b/modules_k/usrloc/dlist.h @@ -122,6 +122,21 @@ int get_all_ucontacts(void *buf, int len, unsigned int flags, unsigned int part_idx, unsigned int part_max); +/*! + * \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 * diff --git a/modules_k/usrloc/usrloc.c b/modules_k/usrloc/usrloc.c index 8c3408f4e..1ce0c36f8 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 bfd225aa7..ea0ec522f 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;