Skip to content

Commit df742a0

Browse files
davidtrihy-genesysbenceszigeti
authored andcommitted
Revert "GCVCALLP-2234: Checking maddr before overwriting ruri during loose route"
This reverts commit a6d07e0.
1 parent c7b28c4 commit df742a0

File tree

5 files changed

+55
-58
lines changed

5 files changed

+55
-58
lines changed

modules/rr/api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ typedef int (*is_direction_t)(struct sip_msg*, int);
4949
typedef int (*get_route_param_t)(struct sip_msg*, str*, str*);
5050
typedef str* (*get_remote_target_t)(struct sip_msg*);
5151
typedef str* (*get_route_set_t)(struct sip_msg*,int *nr_routes);
52-
typedef int (*loose_route_t)(struct sip_msg*);
52+
typedef int (*loose_route_t)(struct sip_msg*, void*);
5353
typedef int (*record_route_t)(struct sip_msg*, str*);
5454

5555
struct rr_binds {

modules/rr/loose.c

Lines changed: 24 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@
6262
#define RR_DRIVEN 1 /* The next hop is determined from the route set */
6363
#define NOT_RR_DRIVEN -1 /* The next hop is not determined from the route set */
6464

65-
#define MADDR_ERROR -1
66-
#define MADDR_FOUND 0
67-
#define MADDR_NOT_FOUND 1
68-
6965
#define ROUTE_PREFIX "Route: <"
7066
#define ROUTE_PREFIX_LEN (sizeof(ROUTE_PREFIX)-1)
7167

@@ -228,11 +224,7 @@ static inline int is_2rr(str* _params)
228224
/*
229225
* Check if URI is myself
230226
*/
231-
#ifdef ENABLE_USER_CHECK
232-
static inline int is_myself(str *_user, struct sip_uri* _uri)
233-
#else
234227
static inline int is_myself(struct sip_uri* _uri)
235-
#endif
236228
{
237229
int ret;
238230
unsigned short port;
@@ -247,6 +239,7 @@ static inline int is_myself(struct sip_uri* _uri)
247239
if (ret < 0) return 0;
248240

249241
#ifdef ENABLE_USER_CHECK
242+
str *_user = _uri->user;
250243
if(i_user.len && i_user.len==_user->len
251244
&& !strncmp(i_user.s, _user->s, _user->len))
252245
{
@@ -352,6 +345,7 @@ static inline int save_ruri(struct sip_msg* _m)
352345
return 0;
353346
}
354347

348+
355349
/*
356350
* input: uri - uri to be checked if has maddr
357351
* input: puri - parsed uri
@@ -364,25 +358,25 @@ static inline int get_maddr_uri(str *uri, struct sip_uri *puri)
364358
struct sip_uri turi;
365359

366360
if(uri==NULL || uri->s==NULL)
367-
return MADDR_ERROR;
361+
return RR_ERROR;
368362
if(puri==NULL)
369363
{
370364
if (parse_uri(uri->s, uri->len, &turi) < 0)
371365
{
372366
LM_ERR("failed to parse the URI\n");
373-
return MADDR_ERROR;
367+
return RR_ERROR;
374368
}
375369
puri = &turi;
376370
}
377371

378372
if(puri->maddr.s==NULL)
379-
return MADDR_NOT_FOUND;
373+
return 0;
380374

381375
/* sip: + maddr + : + port */
382376
if( (puri->maddr_val.len) > ( RH_MADDR_PARAM_MAX_LEN - 10 ) )
383377
{
384378
LM_ERR( "Too long maddr parameter\n");
385-
return MADDR_ERROR;
379+
return RR_ERROR;
386380
}
387381
memcpy( builturi, "sip:", 4 );
388382
memcpy( builturi+4, puri->maddr_val.s, puri->maddr_val.len );
@@ -400,7 +394,7 @@ static inline int get_maddr_uri(str *uri, struct sip_uri *puri)
400394
uri->s = builturi;
401395

402396
LM_DBG("uri is %s\n", builturi );
403-
return MADDR_FOUND;
397+
return 0;
404398
}
405399

406400

@@ -424,7 +418,7 @@ static inline int handle_sr(struct sip_msg* _m, struct hdr_field* _hdr, rr_t* _r
424418
/* Put the first Route in Request-URI */
425419

426420
uri = _r->nameaddr.uri;
427-
if (get_maddr_uri(&uri, 0) < 0) {
421+
if(get_maddr_uri(&uri, 0)!=0) {
428422
LM_ERR("failed to check maddr\n");
429423
return RR_ERROR;
430424
}
@@ -499,7 +493,7 @@ static inline int find_rem_target(struct sip_msg* _m, struct hdr_field** _h, rr_
499493
*/
500494
static inline int after_strict(struct sip_msg* _m)
501495
{
502-
int res, rem_len, maddr_found;
496+
int res, rem_len;
503497
struct hdr_field* hdr;
504498
struct sip_uri puri;
505499
rr_t* rt, *prev, *del_rt;
@@ -518,13 +512,7 @@ static inline int after_strict(struct sip_msg* _m)
518512
return RR_ERROR;
519513
}
520514

521-
if ( enable_double_rr && is_2rr(&puri.params) &&
522-
#ifdef ENABLE_USER_CHECK
523-
is_myself(&puri.user, &puri)
524-
#else
525-
is_myself(&puri)
526-
#endif
527-
) {
515+
if (enable_double_rr && is_2rr(&puri.params) && is_myself(&puri)) {
528516
/* double route may occure due different IP and port, so force as
529517
* send interface the one advertise in second Route */
530518
set_sip_defaults( puri.port_no, puri.proto);
@@ -593,7 +581,7 @@ static inline int after_strict(struct sip_msg* _m)
593581
* always be a strict router because endpoints don't use ;lr parameter
594582
* In this case we will simply put the URI in R-URI and forward it,
595583
* which will work perfectly */
596-
if (get_maddr_uri(&uri, &puri) < 0) {
584+
if(get_maddr_uri(&uri, &puri)!=0) {
597585
LM_ERR("failed to check maddr\n");
598586
return RR_ERROR;
599587
}
@@ -659,17 +647,13 @@ static inline int after_strict(struct sip_msg* _m)
659647
}
660648

661649
uri = rt->nameaddr.uri;
662-
maddr_found = get_maddr_uri(&uri, &puri);
663-
if (maddr_found == MADDR_ERROR) {
650+
if(get_maddr_uri(&uri, 0)!=0) {
664651
LM_ERR("checking maddr failed\n");
665652
return RR_ERROR;
666653
}
667-
668-
if (maddr_found == MADDR_FOUND) {
669-
if (set_ruri(_m, &uri) < 0) {
670-
LM_ERR("failed to rewrite R-URI\n");
671-
return RR_ERROR;
672-
}
654+
if (set_ruri(_m, &uri) < 0) {
655+
LM_ERR("failed to rewrite R-URI\n");
656+
return RR_ERROR;
673657
}
674658

675659
/* mark remote contact route as deleted */
@@ -717,9 +701,7 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
717701
rr_t* rt;
718702
int res;
719703
int status;
720-
#ifdef ENABLE_USER_CHECK
721704
int ret;
722-
#endif
723705
str uri;
724706
const struct socket_info *si;
725707
int force_ss = 0;
@@ -734,13 +716,8 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
734716
}
735717

736718
/* IF the URI was added by me, remove it */
737-
#ifdef ENABLE_USER_CHECK
738-
ret=is_myself(&puri.user, &puri);
739-
if (ret>0)
740-
#else
741-
if (is_myself(&puri))
742-
#endif
743-
{
719+
ret = is_myself(&puri);
720+
if (ret > 0) {
744721
LM_DBG("Topmost route URI: '%.*s' is me\n",
745722
uri.len, ZSW(uri.s));
746723
/* set the hooks for the params -bogdan */
@@ -889,13 +866,13 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
889866
return status;
890867
}
891868

892-
893869
/*
894870
* Do loose routing as defined in RFC3261
895871
*/
896-
int loose_route(struct sip_msg* _m)
872+
int loose_route(struct sip_msg* _m, void *func_flags)
897873
{
898-
int ret;
874+
int preloaded;
875+
int flags = (long) func_flags;
899876

900877
ctx_routing_set(0);
901878

@@ -909,20 +886,14 @@ int loose_route(struct sip_msg* _m)
909886
return -1;
910887
}
911888

912-
ret = is_preloaded(_m);
913-
if (ret < 0) {
889+
preloaded = is_preloaded(_m);
890+
if (preloaded < 0) {
914891
return -1;
915-
} else if (ret == 1) {
916-
return after_loose(_m, 1);
917892
} else {
918-
#ifdef ENABLE_USER_CHECK
919-
if (is_myself(&_m->parsed_uri.user, &_m->parsed_uri) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
920-
#else
921-
if (is_myself(&_m->parsed_uri) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
922-
#endif
893+
if (!(flags & LR_ON_SELF) && is_myself(&_m->parsed_uri) && !(_m->parsed_uri.gr.s && _m->parsed_uri.gr.len)) {
923894
return after_strict(_m);
924895
} else {
925-
return after_loose(_m, 0);
896+
return after_loose(_m, preloaded);
926897
}
927898
}
928899
}

modules/rr/loose.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@
3838
#define RR_FLOW_DOWNSTREAM (1<<0)
3939
#define RR_FLOW_UPSTREAM (1<<1)
4040

41+
#define LR_NO_FLAGS 0
42+
#define LR_ON_SELF 1
43+
4144
extern int ctx_rrparam_idx;
4245
extern int ctx_routing_idx;
4346

4447

4548
/*! \brief
4649
* Do loose routing as per RFC3261
4750
*/
48-
int loose_route(struct sip_msg* _m);
51+
int loose_route(struct sip_msg* _m, void* func_flags);
4952

5053

5154
/*! \brief
@@ -159,5 +162,28 @@ static inline int is_strict(str* _params)
159162
else return 1;
160163
}
161164

165+
static inline int fixup_lr_flags(void** param)
166+
{
167+
int index, ret = LR_NO_FLAGS;
168+
str *flags = (str *)*param;
169+
170+
for (index=0; index < flags->len; index++) {
171+
switch (flags->s[index]) {
172+
case ' ':
173+
break;
174+
case 'l':
175+
case 'L':
176+
ret |= LR_ON_SELF;
177+
break;
178+
default:
179+
LM_ERR("Invalid flag\n");
180+
return -1;
181+
}
182+
}
183+
184+
*param = (void *)(long)ret;
185+
return 0;
186+
}
187+
162188

163189
#endif /* LOOSE_H */

modules/rr/rr_mod.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ static int w_is_direction(struct sip_msg *,void *);
8989
static int pv_get_rr_params(struct sip_msg *msg, pv_param_t *param,
9090
pv_value_t *res);
9191

92-
9392
/*! \brief
9493
* Exported functions
9594
*/
9695
static const cmd_export_t cmds[] = {
97-
{"loose_route", (cmd_function)loose_route, {{0,0,0}},
96+
{"loose_route", (cmd_function)loose_route, {
97+
{CMD_PARAM_STR | CMD_PARAM_OPT,fixup_lr_flags,0}},
9898
REQUEST_ROUTE},
9999
{"record_route", (cmd_function)w_record_route, {
100100
{CMD_PARAM_STR | CMD_PARAM_OPT ,0, 0}, {0,0,0}},

modules/script_helper/script_helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ int run_helper_logic(struct sip_msg *msg, void *param)
172172
rr_api.record_route(msg, NULL);
173173

174174
/* if not RR_DRIVEN */
175-
if (rr_api.loose_route(msg) < 0) {
175+
if (rr_api.loose_route(msg, (void *)0) < 0) {
176176

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

0 commit comments

Comments
 (0)