Skip to content

Commit a8ed644

Browse files
davidtrihy-genesysbenceszigeti
authored andcommitted
TELECOM-12357: Check if socket is null before checking tag, remove req RRs
1 parent dcc20ac commit a8ed644

File tree

3 files changed

+120
-12
lines changed

3 files changed

+120
-12
lines changed

modules/topology_hiding/topo_hiding_logic.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void topo_dlg_initial_reply (struct dlg_cell* dlg, int type,
6464
static void th_down_onreply(struct cell* t, int type,struct tmcb_params *param);
6565
static void th_up_onreply(struct cell* t, int type, struct tmcb_params *param);
6666
static void th_no_dlg_onreply(struct cell* t, int type, struct tmcb_params *param);
67-
static int topo_no_dlg_encode_contact(struct sip_msg *req, unsigned int flags, str *routes, str *ct_user);
67+
static int topo_no_dlg_encode_contact(struct sip_msg *req, unsigned int flags, str *routes, str *rrs_to_ignore, str *ct_user);
6868
static int topo_no_dlg_seq_handling(struct sip_msg *msg,str *info);
6969
static inline int th_no_dlg_one_way_hiding(struct sip_msg *msg, struct socket_info *socket);
7070
static int dlg_th_onreply(struct dlg_cell *dlg, struct sip_msg *rpl, struct sip_msg *req,
@@ -934,7 +934,7 @@ static void th_no_dlg_onreply(struct cell* t, int type, struct tmcb_params *para
934934
int do_rr = 0;
935935
int one_way_hiding = th_no_dlg_one_way_hiding(rpl, t->uas.response.dst.send_sock);
936936

937-
LM_DBG("Response callback with flags %u", flags);
937+
LM_DBG("Response callback with flags %u\n", flags);
938938

939939
/* parse all headers to be sure that all RR and Contact hdrs are found */
940940
if (parse_headers(rpl, HDR_EOH_F, 0)< 0) {
@@ -958,6 +958,7 @@ static void th_no_dlg_onreply(struct cell* t, int type, struct tmcb_params *para
958958
}
959959

960960
route_sets[route_size++] = &rpl_rr_set;
961+
LM_DBG("Reply Record-Routes %.*s\n", rpl_rr_set.len, rpl_rr_set.s);
961962
}
962963

963964
if (do_rr && req->record_route) {
@@ -967,6 +968,7 @@ static void th_no_dlg_onreply(struct cell* t, int type, struct tmcb_params *para
967968
}
968969

969970
route_sets[route_size++] = &req_rr_set;
971+
LM_DBG("Request Record-Routes %.*s\n", req_rr_set.len, req_rr_set.s);
970972
}
971973

972974
if (topo_delete_record_routes(rpl) < 0) {
@@ -980,11 +982,9 @@ static void th_no_dlg_onreply(struct cell* t, int type, struct tmcb_params *para
980982
}
981983

982984
if (!one_way_hiding) {
983-
LM_DBG("No topology hiding on response for this socket\n");
984-
985985
if (!(rpl->REPLY_STATUS >= 300 && rpl->REPLY_STATUS < 400) ) {
986986
if (topo_no_dlg_encode_contact(rpl, flags,
987-
(p ? &p->routes : NULL), (p ? &p->username : NULL)) < 0) {
987+
(p ? &p->routes : NULL), &req_rr_set, (p ? &p->username : NULL)) < 0) {
988988
LM_ERR("Failed to encode contact header \n");
989989
return;
990990
}
@@ -1030,7 +1030,7 @@ static inline int _th_no_dlg_onrequest(struct sip_msg *req, union sockaddr_union
10301030
return -1;
10311031
}
10321032

1033-
if (topo_no_dlg_encode_contact(req, flags, NULL, ct_user) < 0) {
1033+
if (topo_no_dlg_encode_contact(req, flags, NULL, NULL, ct_user) < 0) {
10341034
LM_ERR("Failed to encode contact header \n");
10351035
return -1;
10361036
}
@@ -1774,7 +1774,7 @@ int topo_callid_post_raw(str *data, struct sip_msg* foo)
17741774

17751775
/* We encode the RR headers, the actual Contact and the socket str for this leg */
17761776
/* Via headers will be restored using the TM module, no need to save anything for them */
1777-
static char* build_encoded_contact_suffix(struct sip_msg* msg, str *routes, int *suffix_len, int flags)
1777+
static char* build_encoded_contact_suffix(struct sip_msg* msg, str *routes, str* rrs_to_ignore, int *suffix_len, int flags)
17781778
{
17791779
short rr_len,ct_len,addr_len,flags_len,enc_len;
17801780
char *suffix_plain,*suffix_enc,*p,*s;
@@ -1785,6 +1785,7 @@ static char* build_encoded_contact_suffix(struct sip_msg* msg, str *routes, int
17851785
struct sip_uri ctu;
17861786
struct th_ct_params* el;
17871787
param_t *it;
1788+
rr_t *head = NULL;
17881789
int is_req = (msg->first_line.type==SIP_REQUEST)?1:0;
17891790
int local_len = sizeof(short) /* RR length */ +
17901791
sizeof(short) /* Contact length */ +
@@ -1802,7 +1803,7 @@ static char* build_encoded_contact_suffix(struct sip_msg* msg, str *routes, int
18021803
rr_set = *routes;
18031804
rr_len = (short)routes->len;
18041805
} else if(msg->record_route){
1805-
if(print_rr_body(msg->record_route, &rr_set, !is_req, 0, NULL) != 0){
1806+
if (print_rr_body_ignore(msg->record_route, &rr_set, !is_req, 0, rrs_to_ignore) != 0){
18061807
LM_ERR("failed to print route records \n");
18071808
return NULL;
18081809
}
@@ -1953,7 +1954,7 @@ static char* build_encoded_contact_suffix(struct sip_msg* msg, str *routes, int
19531954
}
19541955

19551956
static int topo_no_dlg_encode_contact(struct sip_msg *msg, unsigned int flags,
1956-
str *routes, str *ct_user)
1957+
str *routes, str *rrs_to_ignore, str *ct_user)
19571958
{
19581959
struct lump* lump;
19591960
char *prefix=NULL,*suffix=NULL,*ct_username=NULL;
@@ -2020,7 +2021,7 @@ static int topo_no_dlg_encode_contact(struct sip_msg *msg, unsigned int flags,
20202021
/* make sure we do not free this string in case of a further error */
20212022
prefix = NULL;
20222023

2023-
if (!(suffix = build_encoded_contact_suffix(msg, routes, &suffix_len, flags))) {
2024+
if (!(suffix = build_encoded_contact_suffix(msg, routes, rrs_to_ignore, &suffix_len, flags))) {
20242025
LM_ERR("Failed to build suffix \n");
20252026
goto error;
20262027
}
@@ -2058,7 +2059,7 @@ static inline void topo_no_dlg_seq_free(void *p)
20582059
static inline int th_no_dlg_one_way_hiding(struct sip_msg *msg, struct socket_info *socket) {
20592060
int one_way_hiding = 0;
20602061

2061-
if (socket->tag.len > 0) {
2062+
if (socket != NULL && socket->tag.len > 0) {
20622063
one_way_hiding = socket->tag.len == th_internal_trusted_tag.len
20632064
&& strncmp(socket->tag.s, th_internal_trusted_tag.s, th_internal_trusted_tag.len) == 0;
20642065

@@ -2367,7 +2368,7 @@ static int topo_no_dlg_seq_handling(struct sip_msg *msg, str *info)
23672368
pkg_free(dec_buf);
23682369

23692370
if (sock && !th_no_dlg_one_way_hiding(msg, sock) &&
2370-
topo_no_dlg_encode_contact(msg, flags, NULL, NULL) < 0) {
2371+
topo_no_dlg_encode_contact(msg, flags, NULL, NULL, NULL) < 0) {
23712372
LM_ERR("Failed to encode contact header \n");
23722373
return -1;
23732374
}

parser/parse_rr.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,110 @@ int shm_duplicate_rr(rr_t** _new, rr_t* _r, int first)
351351
}
352352

353353

354+
int print_rr_body_ignore(struct hdr_field *iroute, str *oroute, int order,
355+
int no_change, str *rrs_to_ignore)
356+
{
357+
rr_t *p, *ignored = NULL;
358+
int n = 0;
359+
int i = 0;
360+
int route_len;
361+
#define MAX_RR_HDRS 64
362+
static str route[MAX_RR_HDRS];
363+
char *cp, *start;
364+
struct hdr_field tmp, *hdr;
365+
str s_rr = STR_NULL;
366+
367+
if(iroute==NULL)
368+
return 0;
369+
370+
route_len= 0;
371+
memset(route, 0, MAX_RR_HDRS*sizeof(str));
372+
373+
while (iroute!=NULL)
374+
{
375+
if (no_change) {
376+
memcpy( &tmp, iroute, sizeof(tmp));
377+
tmp.parsed = NULL;
378+
hdr=&tmp;
379+
}else{
380+
hdr=iroute;
381+
}
382+
if (parse_rr(hdr) < 0)
383+
{
384+
LM_ERR("failed to parse RR\n");
385+
goto error;
386+
}
387+
388+
p =(rr_t*)hdr->parsed;
389+
while (p)
390+
{
391+
s_rr.s = p->nameaddr.name.s;
392+
s_rr.len = p->len;
393+
if (str_strstr(rrs_to_ignore, &s_rr) == NULL) {
394+
route[n].s = s_rr.s;
395+
route[n].len = s_rr.len;
396+
LM_DBG("current rr is %.*s\n", route[n].len, route[n].s);
397+
398+
n++;
399+
route_len += route[i].len;
400+
if (n==MAX_RR_HDRS)
401+
{
402+
LM_ERR("too many RR\n");
403+
goto error;
404+
}
405+
s_rr = STR_NULL;
406+
}
407+
p = p->next;
408+
}
409+
if (no_change)
410+
free_rr( (rr_t**)&tmp.parsed );
411+
iroute = iroute->sibling;
412+
}
413+
414+
route_len += (n - 1); /* for commas */
415+
416+
oroute->s = (char*)pkg_malloc(route_len);
417+
418+
if(oroute->s==0)
419+
{
420+
LM_ERR("no more pkg mem\n");
421+
goto error;
422+
}
423+
cp = start = oroute->s;
424+
if(order==0)
425+
{
426+
i = 0;
427+
428+
while (i<n)
429+
{
430+
memcpy(cp, route[i].s, route[i].len);
431+
cp += route[i].len;
432+
if (++i<n)
433+
*(cp++) = ',';
434+
}
435+
} else {
436+
437+
i = n - 1;
438+
439+
while (i>=0)
440+
{
441+
memcpy(cp, route[i].s, route[i].len);
442+
cp += route[i].len;
443+
if (i-->0)
444+
*(cp++) = ',';
445+
}
446+
}
447+
oroute->len=cp - start;
448+
449+
LM_DBG("out rr [%.*s]\n", oroute->len, oroute->s);
450+
LM_DBG("we have %i records\n", n);
451+
452+
return 0;
453+
454+
error:
455+
return -1;
456+
}
457+
354458
/**
355459
* get first RR header and print comma separated bodies in oroute
356460
* - order = 0 normal; order = 1 reverse

parser/parse_rr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ int shm_duplicate_rr(rr_t** _new, rr_t* _r, int _first);
9494
int print_rr_body(struct hdr_field *iroute, str *oroute, int order,
9595
int no_change, unsigned int * nb_recs);
9696

97+
int print_rr_body_ignore(struct hdr_field *iroute, str *oroute, int order,
98+
int no_change, str *rrs_to_ignore);
99+
97100
/*
98101
* Function returns the first uri
99102
* from Path without any duplication.

0 commit comments

Comments
 (0)