Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/rr/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef int (*is_direction_t)(struct sip_msg*, int);
typedef int (*get_route_param_t)(struct sip_msg*, str*, str*);
typedef str* (*get_remote_target_t)(struct sip_msg*);
typedef str* (*get_route_set_t)(struct sip_msg*,int *nr_routes);
typedef int (*loose_route_t)(struct sip_msg*);
typedef int (*loose_route_t)(struct sip_msg*, void*);
typedef int (*record_route_t)(struct sip_msg*, str*);

struct rr_binds {
Expand Down
44 changes: 11 additions & 33 deletions modules/rr/loose.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,7 @@ static inline int is_2rr(str* _params)
/*
* Check if URI is myself
*/
#ifdef ENABLE_USER_CHECK
static inline int is_myself(str *_user, struct sip_uri* _uri)
#else
static inline int is_myself(struct sip_uri* _uri)
#endif
{
int ret;
unsigned short port;
Expand All @@ -243,6 +239,7 @@ static inline int is_myself(struct sip_uri* _uri)
if (ret < 0) return 0;

#ifdef ENABLE_USER_CHECK
str *_user = _uri->user;
if(i_user.len && i_user.len==_user->len
&& !strncmp(i_user.s, _user->s, _user->len))
{
Expand Down Expand Up @@ -515,13 +512,7 @@ static inline int after_strict(struct sip_msg* _m)
return RR_ERROR;
}

if ( enable_double_rr && is_2rr(&puri.params) &&
#ifdef ENABLE_USER_CHECK
is_myself(&puri.user, &puri)
#else
is_myself(&puri)
#endif
) {
if (enable_double_rr && is_2rr(&puri.params) && is_myself(&puri)) {
/* double route may occure due different IP and port, so force as
* send interface the one advertise in second Route */
set_sip_defaults( puri.port_no, puri.proto);
Expand Down Expand Up @@ -710,9 +701,7 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
rr_t* rt;
int res;
int status;
#ifdef ENABLE_USER_CHECK
int ret;
#endif
str uri;
struct socket_info *si;
int force_ss = 0;
Expand All @@ -727,13 +716,8 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
}

/* IF the URI was added by me, remove it */
#ifdef ENABLE_USER_CHECK
ret=is_myself(&puri.user, &puri);
if (ret>0)
#else
if (is_myself(&puri))
#endif
{
ret = is_myself(&puri);
if (ret > 0) {
LM_DBG("Topmost route URI: '%.*s' is me\n",
uri.len, ZSW(uri.s));
/* set the hooks for the params -bogdan */
Expand Down Expand Up @@ -882,13 +866,13 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
return status;
}


/*
* Do loose routing as defined in RFC3261
*/
int loose_route(struct sip_msg* _m)
int loose_route(struct sip_msg* _m, void *func_flags)
{
int ret;
int preloaded;
int flags = (long) func_flags;

ctx_routing_set(0);

Expand All @@ -902,20 +886,14 @@ int loose_route(struct sip_msg* _m)
return -1;
}

ret = is_preloaded(_m);
if (ret < 0) {
preloaded = is_preloaded(_m);
if (preloaded < 0) {
return -1;
} else if (ret == 1) {
return after_loose(_m, 1);
} else {
#ifdef ENABLE_USER_CHECK
if (is_myself(&_m->parsed_uri.user, &_m->parsed_uri) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
#else
if (is_myself(&_m->parsed_uri) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
#endif
if (!(flags & LR_ON_SELF) && is_myself(&_m->parsed_uri) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
return after_strict(_m);
} else {
return after_loose(_m, 0);
return after_loose(_m, preloaded);
}
}
}
Expand Down
28 changes: 27 additions & 1 deletion modules/rr/loose.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@
#define RR_FLOW_DOWNSTREAM (1<<0)
#define RR_FLOW_UPSTREAM (1<<1)

#define LR_NO_FLAGS 0
#define LR_ON_SELF 1

extern int ctx_rrparam_idx;
extern int ctx_routing_idx;


/*! \brief
* Do loose routing as per RFC3261
*/
int loose_route(struct sip_msg* _m);
int loose_route(struct sip_msg* _m, void* func_flags);


/*! \brief
Expand Down Expand Up @@ -159,5 +162,28 @@ static inline int is_strict(str* _params)
else return 1;
}

static inline int fixup_lr_flags(void** param)
{
int index, ret = LR_NO_FLAGS;
str *flags = (str *)*param;

for (index=0; index < flags->len; index++) {
switch (flags->s[index]) {
case ' ':
break;
case 'l':
case 'L':
ret |= LR_ON_SELF;
break;
default:
LM_ERR("Invalid flag\n");
return -1;
}
}

*param = (void *)(long)ret;
return 0;
}


#endif /* LOOSE_H */
4 changes: 2 additions & 2 deletions modules/rr/rr_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ static int w_is_direction(struct sip_msg *,void *);
static int pv_get_rr_params(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);


/*! \brief
* Exported functions
*/
static const cmd_export_t cmds[] = {
{"loose_route", (cmd_function)loose_route, {{0,0,0}},
{"loose_route", (cmd_function)loose_route, {
{CMD_PARAM_STR | CMD_PARAM_OPT,fixup_lr_flags,0}},
REQUEST_ROUTE},
{"record_route", (cmd_function)w_record_route, {
{CMD_PARAM_STR | CMD_PARAM_OPT ,0, 0}, {0,0,0}},
Expand Down
2 changes: 1 addition & 1 deletion modules/script_helper/script_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ int run_helper_logic(struct sip_msg *msg, void *param)
rr_api.record_route(msg, NULL);

/* if not RR_DRIVEN */
if (rr_api.loose_route(msg) < 0) {
if (rr_api.loose_route(msg, (void *)0) < 0) {

/* attempt a full dialog search (not the usual quick did lookup) */
if (use_dialog && dlg_api.match_dialog(msg, SEQ_MATCH_DEFAULT) < 0)
Expand Down
Loading