-
Notifications
You must be signed in to change notification settings - Fork 564
/
routing.c
802 lines (706 loc) · 17.9 KB
/
routing.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
/*
* Copyright (C) 2005-2008 Voice Sistem SRL
*
* This file is part of Open SIP Server (OpenSIPS).
*
* DROUTING OpenSIPS-module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* DROUTING OpenSIPS-module is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* For any questions about this software and its license, please contact
* Voice Sistem at following e-mail address:
* office@voice-system.ro
*
* History:
* ---------
* 2005-02-20 first version (cristian)
* 2005-02-27 ported to 0.9.0 (bogdan)
*/
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <ctype.h>
#include "dr_partitions.h"
#include "../../str.h"
#include "../../resolve.h"
#include "../../mem/mem.h"
#include "../../mem/shm_mem.h"
#include "../../mem/rpm_mem.h"
#include "../../parser/parse_uri.h"
#include "../../time_rec.h"
#include "prefix_tree.h"
#include "parse.h"
#include "dr_cb.h"
#define is_valid_gw_char(_c) \
(isalpha(_c) || isdigit(_c) || (_c)=='_' || (_c)=='-' || (_c)=='.')
extern int dr_force_dns;
rt_data_t*
build_rt_data(struct head_db *part)
{
rt_data_t *rdata=NULL;
int flags;
if( NULL==(rdata=func_malloc(part->malloc, sizeof(rt_data_t)))) {
LM_ERR("no more shm mem\n");
goto err_exit;
}
memset(rdata, 0, sizeof(rt_data_t));
INIT_PTREE_NODE(part->malloc, NULL, rdata->pt);
flags = (part->cache? AVLMAP_PERSISTENT: AVLMAP_SHARED);
rdata->pgw_tree = map_create(flags);
rdata->carriers_tree = map_create(flags);
if (rdata->pgw_tree == NULL || rdata->carriers_tree == NULL) {
LM_ERR("Initializing avl failed!\n");
if (rdata->pgw_tree)
map_destroy(rdata->pgw_tree, 0);
goto err_exit;
}
return rdata;
err_exit:
if (rdata)
func_free(part->free, rdata);
return 0;
}
int parse_destination_list(rt_data_t* rd, char *dstlist, pgw_list_t** pgwl_ret,
unsigned short *len, int no_resize, osips_malloc_f mf)
{
#define PGWL_SIZE 32
pgw_list_t *pgwl=NULL, *p = NULL;
unsigned int size, pgwl_size;
long int t;
char *tmp, *ep;
int i;
str id;
/* temporary list of gw while parsing */
pgwl_size = PGWL_SIZE;
pgwl = (pgw_list_t*)pkg_malloc(pgwl_size*sizeof(pgw_list_t));
if (pgwl==NULL) {
LM_ERR("no more shm mem\n");
goto error;
}
memset(pgwl, 0, pgwl_size*sizeof(pgw_list_t));
/* parset the destination list */
tmp = dstlist;
size = 0;
/* parse the dstlst */
while(tmp && (*tmp!=0)) {
/* need a larger array ? */
if(size>=pgwl_size){
p=(pgw_list_t*)pkg_malloc((pgwl_size*2)*sizeof(pgw_list_t));
if (p==NULL) {
LM_ERR("not enough shm mem to resize\n");
goto error;
}
memset( p+pgwl_size, 0, pgwl_size*sizeof(pgw_list_t));
memcpy( p, pgwl, pgwl_size*sizeof(pgw_list_t));
pkg_free(pgwl);
pgwl_size*=2;
pgwl=p;
}
/* go over spaces */
EAT_SPACE(tmp);
/* carrier id or GW id ? */
if (*tmp==CARRIER_MARKER) {
pgwl[size].is_carrier = 1;
tmp++;
}
/* eat the destination ID (alphanumerical) */
id.s = tmp;
while( *tmp && is_valid_gw_char(*tmp))
tmp++;
if (id.s == tmp) {
LM_ERR("bad id '%c' (%d)[%s]\n",
*tmp, (int)(tmp-dstlist), dstlist);
goto error;
}
id.len = tmp - id.s ;
/* look for the destination */
if (pgwl[size].is_carrier) {
pgwl[size].dst.carrier = get_carrier_by_id(rd->carriers_tree, &id);
} else {
pgwl[size].dst.gw = get_gw_by_id(rd->pgw_tree, &id);
}
if (pgwl[size].dst.gw==NULL)
LM_WARN("destination ID <%.*s> was not found\n",id.len,id.s);
/* consume spaces */
EAT_SPACE(tmp);
/* any weight? */
if (*tmp=='=') {
tmp++;
/* expect the weight value (int) */
errno = 0;
t = strtol(tmp, &ep, 10);
if (ep == tmp) {
LM_ERR("bad weight value '%c' (%d)[%s]\n",
*ep, (int)(ep-dstlist), dstlist);
goto error;
}
if (errno == ERANGE && (t== LONG_MAX || t== LONG_MIN)) {
LM_ERR("weight value out of bounds\n");
goto error;
}
tmp = ep;
pgwl[size].weight = t;
/* consume spaces */
EAT_SPACE(tmp);
}
/* valid record ? */
if (pgwl[size].dst.gw==NULL) {
/* reset current record and do not count */
memset( pgwl+size, 0, sizeof(pgw_list_t));
} else {
/* count record */
size++;
}
/* separator */
if ( (*tmp==SEP) || (*tmp==SEP1) ) {
tmp++;
} else if (*tmp!=0) {
LM_ERR("bad char %c (%d) [%s]\n",
*tmp, (int)(tmp-dstlist), dstlist);
goto error;
}
}
if (size==0) {
LM_DBG("empty destination list\n");
pkg_free(pgwl);
*len = 0;
*pgwl_ret = NULL;
return 0;
}
/* done with parsing, build the final array and return */
if (no_resize) {
*len = size;
*pgwl_ret = pgwl;
return 0;
}
p=(pgw_list_t*)func_malloc(mf, size*sizeof(pgw_list_t));
if (p==NULL) {
LM_ERR("not enough shm mem for final build\n");
goto error;
}
memcpy( p, pgwl, size*sizeof(pgw_list_t));
pkg_free(pgwl);
*len = size;
*pgwl_ret = p;
return 0;
error:
if (pgwl)
pkg_free(pgwl);
*len = 0;
*pgwl_ret = NULL;
return -1;
}
int add_carrier(char *id, int flags, char *gwlist, char *attrs,
int state, rt_data_t *rd,
osips_malloc_f mf, osips_free_f ff)
{
pcr_t *cr = NULL;
unsigned int i;
str key;
/* allocate a new carrier structure */
cr = (pcr_t*)func_malloc(mf, sizeof(pcr_t)+strlen(id)+(attrs?strlen(attrs):0));
if (cr==NULL) {
LM_ERR("no more shm mem for a new carrier\n");
goto error;
}
memset(cr, 0, sizeof(pcr_t));
if (gwlist && gwlist[0]!=0 ) {
/* parse the list of gateways */
if (parse_destination_list( rd, gwlist, &cr->pgwl,&cr->pgwa_len,0, mf)!=0){
LM_ERR("failed to parse the destinations\n");
goto error;
}
/* check that all dest to be GW! */
for( i=0 ; i<cr->pgwa_len ; i++ ) {
if (cr->pgwl[i].is_carrier) {
LM_ERR("invalid carrier <%s> definition as points to other "
"carrier (%.*s) in destination list\n",id,
cr->pgwl[i].dst.carrier->id.len,
cr->pgwl[i].dst.carrier->id.s);
goto error;
}
}
}
/* copy integer fields */
cr->flags = flags;
/* set state */
if (state!=0)
/* disabled */
cr->flags |= DR_CR_FLAG_IS_OFF;
else
/* enabled */
cr->flags &= ~DR_CR_FLAG_IS_OFF;
/* copy id */
cr->id.s = (char*)(cr+1);
cr->id.len = strlen(id);
memcpy(cr->id.s,id,cr->id.len);
/* copy attributes */
if (attrs && strlen(attrs)) {
cr->attrs.s = cr->id.s + cr->id.len;
cr->attrs.len = strlen(attrs);
memcpy(cr->attrs.s,attrs,cr->attrs.len);
}
/* link it */
key.s = id;
key.len = strlen(id);
map_put(rd->carriers_tree, key, cr);
return 0;
error:
if (cr) {
if (cr->pgwl)
func_free(ff, cr->pgwl);
func_free(ff, cr);
}
return -1;
}
rt_info_t*
build_rt_info(
int id,
int priority,
tmrec_t *trec,
/* script route name */
char* route_idx,
/* list of destinations indexes */
char* dstlst,
char* attrs,
rt_data_t* rd,
osips_malloc_f mf,
osips_free_f ff
)
{
rt_info_t* rt = NULL;
/* callback parameters for the QR module */
int i;
void * qr_rule = NULL;
struct dr_callback *dr_cb_it;
struct dr_cb_params *cb_params;
struct dr_reg_init_rule_params *init_rule_params;
struct dr_reg_param *reg_dst_param;
pgw_list_t *p = NULL;
rt = (rt_info_t*)func_malloc(mf, sizeof(rt_info_t) +
(attrs?strlen(attrs):0) + (route_idx?strlen(route_idx)+1:0) );
if (rt==NULL) {
LM_ERR("no more mem(1)\n");
goto err_exit;
}
memset(rt, 0, sizeof(rt_info_t));
rt->id = id;
rt->priority = priority;
rt->time_rec = trec;
if (attrs && strlen(attrs)) {
rt->attrs.s = (char*)(rt+1);
rt->attrs.len = strlen(attrs);
memcpy(rt->attrs.s,attrs,rt->attrs.len);
}
if (route_idx && strlen(route_idx)) {
rt->route_idx = ((char*)(rt+1)) + rt->attrs.len;
strcpy(rt->route_idx, route_idx);
}
if ( dstlst && dstlst[0]!=0 ) {
if (parse_destination_list(rd, dstlst, &rt->pgwl,&rt->pgwa_len,0,mf)!=0){
LM_ERR("failed to parse the destinations\n");
goto err_exit;
}
}
/* call the create rule callbacks */
init_rule_params = (struct dr_reg_init_rule_params *) shm_malloc(
sizeof(struct dr_reg_init_rule_params));
cb_params = (struct dr_cb_params *) shm_malloc(sizeof(struct dr_cb_params));
if(init_rule_params != NULL && cb_params != NULL) {
memset(init_rule_params, 0, sizeof(struct dr_reg_init_rule_params));
init_rule_params->n_dst = rt->pgwa_len;
init_rule_params->r_id = id; /* name of the rule */
cb_params->param = (void*)&init_rule_params;
if(dr_reg_cbs != NULL && (dr_reg_cbs->types & DRCB_REG_INIT_RULE)) {
dr_cb_it = dr_reg_cbs->first;
while(dr_cb_it) {
if(dr_cb_it->types & DRCB_REG_INIT_RULE) {
dr_cb_it->callback(dr_cb_it->types, cb_params);
break; /* execute just the first callback */
}
dr_cb_it = dr_cb_it->next;
}
} else {
LM_ERR("No callback list to match the given type\n");
}
qr_rule = (void*)((struct dr_reg_init_rule_params*)*cb_params->param)->rule;
p = rt->pgwl;
/* TODO: should check if qr loaded */
for(i = 0; i < rt->pgwa_len; i++) {
if(p[i].is_carrier) {
reg_dst_param = (struct dr_reg_param *) shm_malloc(
sizeof(struct dr_reg_param));
if(reg_dst_param == NULL) {
LM_ERR("no more shm memory\n");
} else {
reg_dst_param->rule = qr_rule;
reg_dst_param->n_dst = i;
reg_dst_param->cr_or_gw = p[i].dst.carrier;
run_callbacks(dr_reg_cbs, DRCB_REG_CR, (void*)reg_dst_param);
}
} else {
reg_dst_param = (struct dr_reg_param *) shm_malloc(sizeof(struct
dr_reg_param));
if(reg_dst_param == NULL) {
LM_ERR("no more shm memory\n");
/* TODO: should we crash all together? */
} else {
reg_dst_param->rule = qr_rule;
reg_dst_param->n_dst = i;
reg_dst_param->cr_or_gw = p[i].dst.gw;
run_callbacks(dr_reg_cbs, DRCB_REG_GW, (void*)reg_dst_param);
}
}
}
}
run_callbacks(dr_reg_cbs, DRCB_REG_ADD_RULE, (void*)qr_rule);
return rt;
err_exit:
if ((NULL != rt) ) {
if (NULL!=rt->pgwl)
func_free(ff, rt->pgwl);
func_free(ff, rt);
}
return NULL;
}
int add_rt_info(
ptree_node_t *pn,
rt_info_t* r,
unsigned int rgid,
osips_malloc_f malloc_f,
osips_free_f free_f
)
{
rg_entry_t *trg=NULL;
rt_info_wrp_t *rtl_wrp=NULL;
rt_info_wrp_t *rtlw=NULL;
int i=0;
if((NULL == pn) || (NULL == r))
goto err_exit;
if (NULL == (rtl_wrp = (rt_info_wrp_t*)
func_malloc(malloc_f, sizeof(rt_info_wrp_t)))) {
LM_ERR("no more shm mem\n");
goto err_exit;
}
memset( rtl_wrp, 0, sizeof(rt_info_wrp_t));
rtl_wrp->rtl = r;
if(NULL==pn->rg) {
/* allocate the routing groups array */
pn->rg_len = RG_INIT_LEN;
if(NULL == (pn->rg = (rg_entry_t*)func_malloc(malloc_f,
pn->rg_len*sizeof(rg_entry_t)))) {
/* recover the old pointer to be able to shm_free mem */
goto err_exit;
}
memset( pn->rg, 0, pn->rg_len*sizeof(rg_entry_t));
pn->rg_pos=0;
}
/* search for the rgid up to the rg_pos */
for(i=0; (i<pn->rg_pos) && (pn->rg[i].rgid!=rgid); i++);
if(i==pn->rg_len) {
/* realloc & copy the old rg */
trg = pn->rg;
if(NULL == (pn->rg = (rg_entry_t*)func_malloc(malloc_f,
(pn->rg_len + RG_INIT_LEN)*sizeof(rg_entry_t)))) {
/* recover the old pointer to be able to shm_free mem */
pn->rg = trg;
goto err_exit;
}
memset(pn->rg+pn->rg_len, 0, RG_INIT_LEN*sizeof(rg_entry_t));
memcpy(pn->rg, trg, pn->rg_len*sizeof(rg_entry_t));
pn->rg_len+=RG_INIT_LEN;
func_free(free_f, trg);
}
/* insert into list */
r->ref_cnt++;
if(NULL==pn->rg[i].rtlw){
pn->rg[i].rtlw = rtl_wrp;
pn->rg[i].rgid = rgid;
pn->rg_pos++;
goto ok_exit;
}
if( r->priority > pn->rg[i].rtlw->rtl->priority) {
/* change the head of the list */
rtl_wrp->next = pn->rg[i].rtlw;
pn->rg[i].rtlw = rtl_wrp;
goto ok_exit;
}
rtlw = pn->rg[i].rtlw;
while( rtlw->next !=NULL) {
if(r->priority > rtlw->next->rtl->priority) {
rtl_wrp->next = rtlw->next;
rtlw->next = rtl_wrp;
goto ok_exit;
}
rtlw = rtlw->next;
}
/* the smallest priority is linked at the end */
rtl_wrp->next=NULL;
rtlw->next=rtl_wrp;
ok_exit:
return 0;
err_exit:
if (rtl_wrp) func_free(free_f, rtl_wrp);
return -1;
}
int
add_dst(
rt_data_t *r,
/* id */
char *id,
/* ip address */
char* ip,
/* strip len */
int strip,
/* pri prefix */
char* pri,
/* dst type*/
int type,
/* dst attrs*/
char* attrs,
/* probe_mode */
int probing,
/* socket */
struct socket_info *sock,
/* state */
int state,
osips_malloc_f mf,
osips_free_f ff
)
{
static unsigned id_counter = 0;
pgw_t *pgw=NULL;
struct sip_uri uri;
int l_ip,l_pri,l_attrs,l_id;
#define GWABUF_MAX_SIZE 512
char gwabuf[GWABUF_MAX_SIZE];
char *p;
union sockaddr_union sau;
struct proxy_l *proxy;
unsigned int sip_prefix;
str gwas;
str key;
if (NULL==r || NULL==ip) {
LM_ERR("invalid parametres\n");
goto err_exit;
}
l_id = strlen(id);
l_ip = strlen(ip);
l_pri = pri?strlen(pri):0;
l_attrs = attrs?strlen(attrs):0;
/* check the ID of the gateway */
for (p = id + l_id - 1; p >= id; p--)
if (!is_valid_gw_char(*p)) {
LM_ERR("invalid char in gateway's name [%c]\n", *p);
goto err_exit;
}
/* check if GW address starts with 'sip' or 'sips' */
if (l_ip>5) {
if ( strncasecmp("sip:", ip, 4)==0)
sip_prefix = 4;
else if ( strncasecmp("sips:", ip, 5)==0)
sip_prefix = 5;
else sip_prefix = 0;
} else
sip_prefix = 0;
if( sip_prefix==0 ) {
if(l_ip+4>=GWABUF_MAX_SIZE) {
LM_ERR("GW address (%d) longer "
"than %d\n",l_ip+4,GWABUF_MAX_SIZE);
goto err_exit;
}
memcpy(gwabuf, "sip:", 4);
memcpy(gwabuf+4, ip, l_ip);
gwas.s = gwabuf;
gwas.len = 4+l_ip;
} else {
gwas.s = ip;
gwas.len = l_ip;
}
/* parse the normalized address as a SIP URI */
memset(&uri, 0, sizeof(struct sip_uri));
if(parse_uri(gwas.s, gwas.len, &uri)!=0) {
LM_ERR("invalid uri <%.*s>\n",
gwas.len, gwas.s);
goto err_exit;
}
/* update the sip_prefix to skip to domain part */
if (uri.user.len)
sip_prefix += uri.host.s - uri.user.s;
/* allocate new structure */
pgw = (pgw_t*)func_malloc(mf, sizeof(pgw_t) + l_id + (l_ip-sip_prefix) +
l_pri + l_attrs);
if (NULL==pgw) {
LM_ERR("no more shm mem (%u)\n",
(unsigned int)(sizeof(pgw_t)+l_id+l_ip-sip_prefix+l_pri +l_attrs));
goto err_exit;
}
memset(pgw,0,sizeof(pgw_t));
/* set probing related flags */
switch(probing) {
case 0:
break;
case 1:
pgw->flags |= DR_DST_PING_DSBL_FLAG;
break;
case 2:
pgw->flags |= DR_DST_PING_PERM_FLAG;
break;
default:
goto err_exit;
}
/* set state related flags */
switch(state) {
case 0:
break;
case 1:
pgw->flags |= DR_DST_STAT_DSBL_FLAG|DR_DST_STAT_NOEN_FLAG;
break;
case 2:
pgw->flags |= DR_DST_STAT_DSBL_FLAG;
break;
default:
goto err_exit;
}
/* set outbound socket */
pgw->sock = sock;
pgw->_id = ++id_counter;
pgw->id.len= l_id;
pgw->id.s = (char*)(pgw+1);
memcpy(pgw->id.s, id, l_id);
pgw->ip_str.len= l_ip-sip_prefix;
pgw->ip_str.s = (char*)(pgw+1)+l_id;
memcpy(pgw->ip_str.s, ip+sip_prefix, l_ip-sip_prefix);
if (pri) {
pgw->pri.len = l_pri;
pgw->pri.s = ((char*)(pgw+1))+l_id+l_ip-sip_prefix;
memcpy(pgw->pri.s, pri, l_pri);
}
if (attrs) {
pgw->attrs.len = l_attrs;
pgw->attrs.s = ((char*)(pgw+1))+l_id+l_ip-sip_prefix+l_pri;
memcpy(pgw->attrs.s, attrs, l_attrs);
}
pgw->strip = strip;
pgw->type = type;
/* add address in the global list of destinations/GWs */
proxy = mk_proxy(&uri.host,uri.port_no,uri.proto,(uri.type==SIPS_URI_T));
if (proxy==NULL) {
if(dr_force_dns) {
LM_ERR("cannot resolve <%.*s>\n",
uri.host.len, uri.host.s);
goto err_exit;
} else {
LM_DBG("cannot resolve <%.*s> - won't be used"
" by is_from_gw()\n", uri.host.len, uri.host.s);
goto done;
}
}
hostent2ip_addr( &pgw->ips[0], &proxy->host, proxy->addr_idx);
pgw->ports[0] = proxy->port;
pgw->protos[0] = proxy->proto;
LM_DBG("first gw ip addr [%s]\n", ip_addr2a(&pgw->ips[0]));
pgw->ips_no = 1;
while (pgw->ips_no<DR_MAX_IPS && (get_next_su( proxy, &sau, 0)==0) ) {
su2ip_addr( &pgw->ips[pgw->ips_no], &sau);
pgw->ports[pgw->ips_no] = proxy->port;
pgw->protos[pgw->ips_no] = proxy->proto;
LM_DBG("additional gw ip addr [%s]\n",
ip_addr2a( &pgw->ips[pgw->ips_no] ) );
pgw->ips_no++;
}
free_proxy(proxy);
pkg_free(proxy);
done:
key.s = id;
key.len = strlen(id);
if (map_put(r->pgw_tree, key, pgw)) {
LM_ERR("Duplicate gateway!\n");
return -1;
}
return 0;
err_exit:
if(NULL!=pgw)
func_free(ff, pgw);
return -1;
}
void destroy_pcr_shm_w(void *pcr_p)
{
pcr_t* pcr = pcr_p;
if (pcr->pgwl) shm_free(pcr->pgwl);
shm_free(pcr);
}
void destroy_pcr_rpm_w(void *pcr_p)
{
pcr_t* pcr = pcr_p;
if (pcr->pgwl) rpm_free(pcr->pgwl);
rpm_free(pcr);
}
static void shm_free_w(void *p)
{
shm_free(p);
}
static void rpm_free_w(void *p)
{
rpm_free(p);
}
/* FIXME FREE AVL HERE */
void
del_pgw_list(
map_t pgw_tree
)
{
map_destroy(pgw_tree,
(pgw_tree->flags & AVLMAP_PERSISTENT?rpm_free_w:shm_free_w));
}
/* FIXME FREE AVL HERE */
void del_carriers_list(
map_t carriers_tree
)
{
map_destroy(carriers_tree,
(carriers_tree->flags & AVLMAP_PERSISTENT?
destroy_pcr_rpm_w:destroy_pcr_shm_w));
}
void
free_rt_data(
rt_data_t* rt_data,
osips_free_f free_f
)
{
int j;
if(NULL!=rt_data) {
/* del GW list */
del_pgw_list(rt_data->pgw_tree);
rt_data->pgw_tree = 0 ;
/* del prefix tree */
del_tree(rt_data->pt, free_f);
rt_data->pt = 0 ;
/* del prefixless rules */
if(NULL!=rt_data->noprefix.rg) {
for(j=0;j<rt_data->noprefix.rg_pos;j++) {
if(rt_data->noprefix.rg[j].rtlw !=NULL) {
del_rt_list(rt_data->noprefix.rg[j].rtlw, free_f);
rt_data->noprefix.rg[j].rtlw = 0;
}
}
func_free(free_f, rt_data->noprefix.rg);
rt_data->noprefix.rg = 0;
}
/* del carriers */
del_carriers_list(rt_data->carriers_tree);
rt_data->carriers_tree=0;
/* del top level */
func_free(free_f, rt_data);
}
}