Skip to content

Commit

Permalink
usrloc: provide previous hop to UL_CONTACT_UPDATE
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Jan 27, 2023
1 parent c19d793 commit da96566
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 28 deletions.
4 changes: 2 additions & 2 deletions modules/mid_registrar/ulcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static int unregister_record(urecord_t *r)
return send_unregister(from, to, ruri, callid, last_cseq, obp, ct);
}

void mid_reg_ct_event(void *binding, ul_cb_type type)
void mid_reg_ct_event(void *binding, ul_cb_type type, ul_cb_extra *_)
{
ucontact_t *c = (ucontact_t *)binding;
int_str_t *skip_dereg;
Expand All @@ -246,7 +246,7 @@ void mid_reg_ct_event(void *binding, ul_cb_type type)
}
}

void mid_reg_aor_event(void *binding, ul_cb_type type)
void mid_reg_aor_event(void *binding, ul_cb_type type, ul_cb_extra *_)
{
urecord_t *r = (urecord_t *)binding;
int_str_t *skip_dereg;
Expand Down
4 changes: 2 additions & 2 deletions modules/mid_registrar/ulcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#ifndef __MID_REG_ULCB_
#define __MID_REG_ULCB_

void mid_reg_ct_event(void *binding, ul_cb_type type);
void mid_reg_aor_event(void *binding, ul_cb_type type);
void mid_reg_ct_event(void *binding, ul_cb_type type, ul_cb_extra *_);
void mid_reg_aor_event(void *binding, ul_cb_type type, ul_cb_extra *_);

#endif /* __MID_REG_ULCB_ */
2 changes: 1 addition & 1 deletion modules/pua_bla/registrar_cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "pua_bla.h"


void bla_contact_cb(void *binding, ul_cb_type type)
void bla_contact_cb(void *binding, ul_cb_type type, ul_cb_extra *_)
{
ucontact_t *c = (ucontact_t *)binding;
subs_info_t subs;
Expand Down
2 changes: 1 addition & 1 deletion modules/pua_bla/registrar_cb.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
#include "../../dprint.h"
#include "../usrloc/usrloc.h"

void bla_contact_cb(void *binding, ul_cb_type type);
void bla_contact_cb(void *binding, ul_cb_type type, ul_cb_extra *_);
2 changes: 1 addition & 1 deletion modules/pua_usrloc/pua_usrloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

extern send_publish_t pua_send_publish;
extern send_subscribe_t pua_send_subscribe;
void ul_contact_publish(void *binding, ul_cb_type type);
void ul_contact_publish(void *binding, ul_cb_type type, ul_cb_extra *_);
int pua_set_publish(struct sip_msg* , char*, char*);

extern str pres_prefix;
Expand Down
2 changes: 1 addition & 1 deletion modules/pua_usrloc/ul_publish.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ str* build_pidf(ucontact_t* c)
return NULL;
}

void ul_contact_publish(void *binding, ul_cb_type type)
void ul_contact_publish(void *binding, ul_cb_type type, ul_cb_extra *_)
{
ucontact_t *c = (ucontact_t *)binding;
str* body= NULL;
Expand Down
2 changes: 1 addition & 1 deletion modules/snmpstats/interprocess_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int setInterprocessBuffersAlarm(void)
* any race conditions between this function and the consumeInterprocessBuffer()
* function.
*/
void handleContactCallbacks(void *binding, ul_cb_type type)
void handleContactCallbacks(void *binding, ul_cb_type type, ul_cb_extra *_)
{
ucontact_t *contactInfo = (ucontact_t *)binding;
char *p;
Expand Down
2 changes: 1 addition & 1 deletion modules/snmpstats/interprocess_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int setInterprocessBuffersAlarm(void);
* any race conditions between this function and the consumeInterprocessBuffer()
* function.
*/
void handleContactCallbacks(void *binding, ul_cb_type type);
void handleContactCallbacks(void *binding, ul_cb_type type, ul_cb_extra *_);


/* Interprocess Buffer consumption Function. This function will iterate over
Expand Down
2 changes: 1 addition & 1 deletion modules/usrloc/dlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ int delete_ucontact_from_coords(udomain_t *d, ucontact_coords ct_coords,
replicate_ucontact_delete(r, c, NULL);

if (exists_ulcb_type(UL_CONTACT_DELETE)) {
run_ul_callbacks( UL_CONTACT_DELETE, c);
run_ul_callbacks( UL_CONTACT_DELETE, c, NULL);
}

if (st_delete_ucontact(c) > 0) {
Expand Down
15 changes: 14 additions & 1 deletion modules/usrloc/ucontact.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,11 +967,22 @@ int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci,
const struct ct_match *match, char skip_replication)
{
int ret, persist_kv_store = 1;
ul_cb_extra extra;

memset(&extra, 0, sizeof extra);

if (exists_ulcb_type(UL_CONTACT_UPDATE)) {
extra.contact_update.prev_proto = _c->next_hop.proto;
extra.contact_update.prev_port = _c->next_hop.port;
pkg_str_dup(&extra.contact_update.prev_name, &_c->next_hop.name);
}

/* we have to update memory in any case, but database directly
* only in sql_wmode SQL_WRITE_THROUGH */
if (mem_update_ucontact(_c, _ci) < 0) {
LM_ERR("failed to update memory\n");
if (extra.contact_update.prev_name.s)
pkg_free(extra.contact_update.prev_name.s);
return -1;
}

Expand All @@ -991,7 +1002,9 @@ int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci,
if (exists_ulcb_type(UL_CONTACT_UPDATE))
{
LM_DBG("exists callback for type= UL_CONTACT_UPDATE\n");
run_ul_callbacks( UL_CONTACT_UPDATE, _c);
run_ul_callbacks( UL_CONTACT_UPDATE, _c, &extra);
if (extra.contact_update.prev_name.s)
pkg_free(extra.contact_update.prev_name.s);
}

if (have_mem_storage())
Expand Down
4 changes: 2 additions & 2 deletions modules/usrloc/udomain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ int mem_timer_udomain(udomain_t* _d)
if (ptr->no_clear_ref <= 0 && ptr->contacts == NULL)
{
if (exists_ulcb_type(UL_AOR_EXPIRE))
run_ul_callbacks(UL_AOR_EXPIRE, ptr);
run_ul_callbacks(UL_AOR_EXPIRE, ptr, NULL);

if (location_cluster) {
if (cluster_mode == CM_FEDERATION_CACHEDB &&
Expand Down Expand Up @@ -1379,7 +1379,7 @@ int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r,
}

if (exists_ulcb_type(UL_AOR_INSERT))
run_ul_callbacks(UL_AOR_INSERT, *_r);
run_ul_callbacks(UL_AOR_INSERT, *_r, NULL);

return 0;
}
Expand Down
18 changes: 14 additions & 4 deletions modules/usrloc/ul_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ typedef enum ul_cb_types {
ULCB_MAX = ((1<<8)-1),
} ul_cb_type;

typedef union ul_cb_extra {
struct {
unsigned short prev_proto;
unsigned short prev_port;
str prev_name;
} contact_update;
} ul_cb_extra;


#define is_contact_cb(type) \
(type & \
(UL_CONTACT_INSERT|UL_CONTACT_UPDATE|UL_CONTACT_DELETE|UL_CONTACT_EXPIRE))
Expand All @@ -59,8 +68,9 @@ typedef enum ul_cb_types {
* @binding: depending on the registered type,
* it should be casted to either (ucontact_t *) or (urecord_t *)
* @type: type of the callback
* @extra: extra parameters provided for each type of callback
*/
typedef void (ul_cb) (void *binding, ul_cb_type type);
typedef void (ul_cb) (void *binding, ul_cb_type type, ul_cb_extra *extra);


struct ul_callback {
Expand Down Expand Up @@ -103,7 +113,7 @@ int register_ulcb(ul_cb_type types, ul_cb f);
* - an (ucontact_t *) for contact callbacks
* - an (urecord_t *) for AoR callbacks
*/
static inline void run_ul_callbacks(ul_cb_type type, void *binding)
static inline void run_ul_callbacks(ul_cb_type type, void *binding, ul_cb_extra *extra)
{
struct list_head *_;
struct ul_callback *cbp;
Expand All @@ -115,9 +125,9 @@ static inline void run_ul_callbacks(ul_cb_type type, void *binding)
binding, type, cbp->types, cbp->id);

if (is_contact_cb(type)) {
cbp->callback(binding, type);
cbp->callback(binding, type, extra);
} else if (is_aor_cb(type)) {
cbp->callback(binding, type);
cbp->callback(binding, type, extra);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions modules/usrloc/urecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ static inline int nodb_timer(urecord_t* _r)
if (!VALID_CONTACT(ptr, act_time)) {
/* run callbacks for EXPIRE event */
if (exists_ulcb_type(UL_CONTACT_EXPIRE))
run_ul_callbacks( UL_CONTACT_EXPIRE, ptr);
run_ul_callbacks( UL_CONTACT_EXPIRE, ptr, NULL);

LM_DBG("Binding '%.*s','%.*s' has expired\n",
ptr->aor->len, ZSW(ptr->aor->s),
Expand Down Expand Up @@ -284,7 +284,7 @@ static inline int ALLOW_UNUSED wt_timer(urecord_t* _r)
if (!VALID_CONTACT(ptr, act_time)) {
/* run callbacks for EXPIRE event */
if (exists_ulcb_type(UL_CONTACT_EXPIRE)) {
run_ul_callbacks( UL_CONTACT_EXPIRE, ptr);
run_ul_callbacks( UL_CONTACT_EXPIRE, ptr, NULL);
}

LM_DBG("Binding '%.*s','%.*s' has expired\n",
Expand Down Expand Up @@ -327,7 +327,7 @@ static inline int wb_timer(urecord_t* _r,query_list_t **ins_list)
if (!VALID_CONTACT(ptr, act_time)) {
/* run callbacks for EXPIRE event */
if (exists_ulcb_type(UL_CONTACT_EXPIRE)) {
run_ul_callbacks( UL_CONTACT_EXPIRE, ptr);
run_ul_callbacks( UL_CONTACT_EXPIRE, ptr, NULL);
}

LM_DBG("Binding '%.*s','%.*s' has expired\n",
Expand Down Expand Up @@ -619,7 +619,7 @@ int cdb_flush_urecord(urecord_t *_r)
if (!VALID_CONTACT(ct, act_time)) {
/* run callbacks for DELETE event */
if (exists_ulcb_type(UL_CONTACT_DELETE))
run_ul_callbacks(UL_CONTACT_DELETE, ct);
run_ul_callbacks(UL_CONTACT_DELETE, ct, NULL);

LM_DBG("deleting AoR: %.*s, Contact: %.*s.\n",
ct->aor->len, ZSW(ct->aor->s),
Expand Down Expand Up @@ -827,7 +827,7 @@ void release_urecord(urecord_t* _r, char skip_replication)
return;

if (exists_ulcb_type(UL_AOR_DELETE))
run_ul_callbacks(UL_AOR_DELETE, _r);
run_ul_callbacks(UL_AOR_DELETE, _r, NULL);

if (!skip_replication && location_cluster) {
if (cluster_mode == CM_FEDERATION_CACHEDB &&
Expand Down Expand Up @@ -881,10 +881,10 @@ int insert_ucontact(urecord_t* _r, str* _contact, ucontact_info_t* _ci,
replicate_ucontact_insert(_r, _contact, *_c, match);

if (exists_ulcb_type(UL_CONTACT_INSERT))
run_ul_callbacks(UL_CONTACT_INSERT, *_c);
run_ul_callbacks(UL_CONTACT_INSERT, *_c, NULL);

if (!first_contact && exists_ulcb_type(UL_AOR_UPDATE))
run_ul_callbacks(UL_AOR_UPDATE, _r);
run_ul_callbacks(UL_AOR_UPDATE, _r, NULL);

if (sql_wmode == SQL_WRITE_THROUGH) {
if (persist_urecord_kv_store(_r) != 0)
Expand All @@ -911,10 +911,10 @@ int delete_ucontact(urecord_t* _r, struct ucontact* _c,
replicate_ucontact_delete(_r, _c, match);

if (exists_ulcb_type(UL_CONTACT_DELETE))
run_ul_callbacks(UL_CONTACT_DELETE, _c);
run_ul_callbacks(UL_CONTACT_DELETE, _c, NULL);

if (exists_ulcb_type(UL_AOR_UPDATE))
run_ul_callbacks(UL_AOR_UPDATE, _r);
run_ul_callbacks(UL_AOR_UPDATE, _r, NULL);

LM_DBG("deleting contact '%.*s'\n", _c->c.len, _c->c.s);

Expand Down
2 changes: 1 addition & 1 deletion modules/usrloc/usrloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ typedef struct usrloc_api {
* Return: 0 (success), negative otherwise
*/
int (*register_ulcb) (ul_cb_type types,
void (*cb) (void *binding, ul_cb_type type));
void (*cb) (void *binding, ul_cb_type type, ul_cb_extra *extra));
} usrloc_api_t;


Expand Down

0 comments on commit da96566

Please sign in to comment.