... | ... |
@@ -22,6 +22,7 @@ |
22 | 22 |
#include "data_lump.h" |
23 | 23 |
#include "ut.h" |
24 | 24 |
#include "mem.h" |
25 |
+#include "msg_translator.h" |
|
25 | 26 |
|
26 | 27 |
#ifdef DEBUG_DMALLOC |
27 | 28 |
#include <dmalloc.h> |
... | ... |
@@ -35,128 +36,20 @@ |
35 | 36 |
#endif |
36 | 37 |
|
37 | 38 |
|
38 |
-/* faster than inet_ntoa */ |
|
39 |
-static inline char* q_inet_itoa(unsigned long ip) |
|
40 |
-{ |
|
41 |
- static char q_inet_itoa_buf[16]; /* 123.567.901.345\0 */ |
|
42 |
- unsigned char* p; |
|
43 |
- unsigned char a,b,c; /* abc.def.ghi.jkl */ |
|
44 |
- int offset; |
|
45 |
- int r; |
|
46 |
- p=(unsigned char*)&ip; |
|
47 |
- |
|
48 |
- offset=0; |
|
49 |
- /* unrolled loops (faster)*/ |
|
50 |
- for(r=0;r<3;r++){ |
|
51 |
- a=p[r]/100; |
|
52 |
- c=p[r]%10; |
|
53 |
- b=p[r]%100/10; |
|
54 |
- if (a){ |
|
55 |
- q_inet_itoa_buf[offset]=a+'0'; |
|
56 |
- q_inet_itoa_buf[offset+1]=b+'0'; |
|
57 |
- q_inet_itoa_buf[offset+2]=c+'0'; |
|
58 |
- q_inet_itoa_buf[offset+3]='.'; |
|
59 |
- offset+=4; |
|
60 |
- }else if (b){ |
|
61 |
- q_inet_itoa_buf[offset]=b+'0'; |
|
62 |
- q_inet_itoa_buf[offset+1]=c+'0'; |
|
63 |
- q_inet_itoa_buf[offset+2]='.'; |
|
64 |
- offset+=3; |
|
65 |
- }else{ |
|
66 |
- q_inet_itoa_buf[offset]=c+'0'; |
|
67 |
- q_inet_itoa_buf[offset+1]='.'; |
|
68 |
- offset+=2; |
|
69 |
- } |
|
70 |
- } |
|
71 |
- /* last number */ |
|
72 |
- a=p[r]/100; |
|
73 |
- c=p[r]%10; |
|
74 |
- b=p[r]%100/10; |
|
75 |
- if (a){ |
|
76 |
- q_inet_itoa_buf[offset]=a+'0'; |
|
77 |
- q_inet_itoa_buf[offset+1]=b+'0'; |
|
78 |
- q_inet_itoa_buf[offset+2]=c+'0'; |
|
79 |
- q_inet_itoa_buf[offset+3]=0; |
|
80 |
- }else if (b){ |
|
81 |
- q_inet_itoa_buf[offset]=b+'0'; |
|
82 |
- q_inet_itoa_buf[offset+1]=c+'0'; |
|
83 |
- q_inet_itoa_buf[offset+2]=0; |
|
84 |
- }else{ |
|
85 |
- q_inet_itoa_buf[offset]=c+'0'; |
|
86 |
- q_inet_itoa_buf[offset+1]=0; |
|
87 |
- } |
|
88 |
- |
|
89 |
- return q_inet_itoa_buf; |
|
90 |
-} |
|
91 |
- |
|
92 |
- |
|
93 |
- |
|
94 |
- |
|
95 |
- |
|
96 |
- |
|
97 |
- |
|
98 |
-/* checks if ip is in host(name) and ?host(ip)=name? |
|
99 |
- * ip must be in network byte order! |
|
100 |
- * resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made |
|
101 |
- * return 0 if equal */ |
|
102 |
-int check_address(unsigned long ip, char *name, int resolver) |
|
103 |
-{ |
|
104 |
- struct hostent* he; |
|
105 |
- int i; |
|
106 |
- |
|
107 |
- /* maybe we are lucky and name it's an ip */ |
|
108 |
- if (strcmp(name, q_inet_itoa( /* *(struct in_addr *)&*/ip ))==0) |
|
109 |
- return 0; |
|
110 |
- if (resolver&DO_DNS){ |
|
111 |
- DBG("check_address: doing dns lookup\n"); |
|
112 |
- /* try all names ips */ |
|
113 |
- he=gethostbyname(name); |
|
114 |
- for(i=0;he && he->h_addr_list[i];i++){ |
|
115 |
- if (*(unsigned long*)he->h_addr_list[i]==ip) |
|
116 |
- return 0; |
|
117 |
- } |
|
118 |
- } |
|
119 |
- if (resolver&DO_REV_DNS){ |
|
120 |
- DBG("check_address: doing rev. dns lookup\n"); |
|
121 |
- print_ip(ip); |
|
122 |
- /* try reverse dns */ |
|
123 |
- he=gethostbyaddr((char*)&ip, sizeof(ip), AF_INET); |
|
124 |
- if (he && (strcmp(he->h_name, name)==0)) |
|
125 |
- return 0; |
|
126 |
- for (i=0; he && he->h_aliases[i];i++){ |
|
127 |
- if (strcmp(he->h_aliases[i],name)==0) |
|
128 |
- return 0; |
|
129 |
- } |
|
130 |
- } |
|
131 |
- return -1; |
|
132 |
-} |
|
133 |
- |
|
134 |
- |
|
135 | 39 |
|
136 | 40 |
int forward_request( struct sip_msg* msg, struct proxy_l * p) |
137 | 41 |
{ |
138 |
- unsigned int len, new_len, via_len, received_len, uri_len; |
|
139 |
- char* line_buf; |
|
140 |
- char* received_buf; |
|
141 |
- char* tmp; |
|
142 |
- int tmp_len; |
|
143 |
- char* new_buf; |
|
144 |
- char* orig; |
|
42 |
+ unsigned int len; |
|
145 | 43 |
char* buf; |
146 |
- unsigned int offset, s_offset, size; |
|
147 | 44 |
struct sockaddr_in* to; |
148 |
- unsigned long source_ip; |
|
149 |
- struct lump *t,*r; |
|
150 |
- struct lump* anchor; |
|
151 | 45 |
|
152 |
- orig=msg->orig; |
|
153 |
- buf=msg->buf; |
|
154 |
- len=msg->len; |
|
155 |
- source_ip=msg->src_ip; |
|
156 |
- received_len=0; |
|
157 |
- new_buf=0; |
|
158 |
- line_buf=0; |
|
159 |
- received_buf=0; |
|
46 |
+ |
|
47 |
+ buf = build_buf_from_sip_request( msg, &len); |
|
48 |
+ if (!buf){ |
|
49 |
+ LOG(L_ERR, "ERROR: forward_reply: building failed\n"); |
|
50 |
+ goto error; |
|
51 |
+ } |
|
52 |
+ |
|
160 | 53 |
to=0; |
161 | 54 |
to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr)); |
162 | 55 |
if (to==0){ |
... | ... |
@@ -164,261 +57,9 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) |
164 | 57 |
goto error; |
165 | 58 |
} |
166 | 59 |
|
167 |
- line_buf=pkg_malloc(sizeof(char)*MAX_VIA_LINE_SIZE); |
|
168 |
- if (line_buf==0){ |
|
169 |
- LOG(L_ERR, "ERROR: forward_request: out of memory\n"); |
|
170 |
- goto error1; |
|
171 |
- } |
|
172 |
-/* |
|
173 |
- via_len=snprintf(line_buf, MAX_VIA_LINE_SIZE, "Via: SIP/2.0/UDP %s:%d\r\n", |
|
174 |
- names[0], port_no); |
|
175 |
-*/ |
|
176 |
- via_len=MY_VIA_LEN+names_len[0]; /* space included in MY_VIA*/ |
|
177 |
- if ((via_len+port_no_str_len+CRLF_LEN)<MAX_VIA_LINE_SIZE){ |
|
178 |
- memcpy(line_buf, MY_VIA, MY_VIA_LEN); |
|
179 |
- memcpy(line_buf+MY_VIA_LEN, names[0], names_len[0]); |
|
180 |
- if (port_no!=SIP_PORT){ |
|
181 |
- memcpy(line_buf+via_len, port_no_str, port_no_str_len); |
|
182 |
- via_len+=port_no_str_len; |
|
183 |
- } |
|
184 |
- memcpy(line_buf+via_len, CRLF, CRLF_LEN); |
|
185 |
- via_len+=CRLF_LEN; |
|
186 |
- line_buf[via_len]=0; /* null terminate the string*/ |
|
187 |
- }else{ |
|
188 |
- LOG(L_ERR, "forward_request: ERROR: via too long (%d)\n", |
|
189 |
- via_len); |
|
190 |
- goto error1; |
|
191 |
- } |
|
192 |
- |
|
193 |
- |
|
194 |
- |
|
195 |
- /* check if received needs to be added */ |
|
196 |
- if (check_address(source_ip, msg->via1->host.s, received_dns)!=0){ |
|
197 |
- received_buf=pkg_malloc(sizeof(char)*MAX_RECEIVED_SIZE); |
|
198 |
- if (received_buf==0){ |
|
199 |
- LOG(L_ERR, "ERROR: forward_request: out of memory\n"); |
|
200 |
- goto error1; |
|
201 |
- } |
|
202 |
- /* |
|
203 |
- received_len=snprintf(received_buf, MAX_RECEIVED_SIZE, |
|
204 |
- ";received=%s", |
|
205 |
- inet_ntoa(*(struct in_addr *)&source_ip)); |
|
206 |
- */ |
|
207 |
- memcpy(received_buf, RECEIVED, RECEIVED_LEN); |
|
208 |
- tmp=q_inet_itoa( /* *(struct in_addr *)& */source_ip); |
|
209 |
- tmp_len=strlen(tmp); |
|
210 |
- received_len=RECEIVED_LEN+tmp_len; |
|
211 |
- memcpy(received_buf+RECEIVED_LEN, tmp, tmp_len); |
|
212 |
- received_buf[received_len]=0; /*null terminate it */ |
|
213 |
- } |
|
214 |
- |
|
215 |
- /* add via header to the list */ |
|
216 |
- /* try to add it before msg. 1st via */ |
|
217 |
- /*add first via, as an anchor for second via*/ |
|
218 |
- anchor=anchor_lump(&(msg->add_rm), msg->via1->hdr.s-buf, 0, HDR_VIA); |
|
219 |
- if (anchor==0) goto error; |
|
220 |
- if (insert_new_lump_before(anchor, line_buf, via_len, HDR_VIA)==0) |
|
221 |
- goto error; |
|
222 |
- /* if received needs to be added, add anchor after host and add it */ |
|
223 |
- if (received_len){ |
|
224 |
- if (msg->via1->params.s){ |
|
225 |
- size= msg->via1->params.s-msg->via1->hdr.s-1; /*compensate |
|
226 |
- for ';' */ |
|
227 |
- }else{ |
|
228 |
- size= msg->via1->host.s-msg->via1->hdr.s+msg->via1->host.len; |
|
229 |
- if (msg->via1->port!=0){ |
|
230 |
- size+=strlen(msg->via1->hdr.s+size+1)+1; /* +1 for ':'*/ |
|
231 |
- } |
|
232 |
- } |
|
233 |
- anchor=anchor_lump(&(msg->add_rm),msg->via1->hdr.s-buf+size,0, |
|
234 |
- HDR_VIA); |
|
235 |
- if (anchor==0) goto error; |
|
236 |
- if (insert_new_lump_after(anchor, received_buf, received_len, HDR_VIA) |
|
237 |
- ==0 ) goto error; |
|
238 |
- } |
|
239 |
- |
|
240 |
- |
|
241 |
- /* compute new msg len and fix overlapping zones*/ |
|
242 |
- new_len=len; |
|
243 |
- s_offset=0; |
|
244 |
- for(t=msg->add_rm;t;t=t->next){ |
|
245 |
- for(r=t->before;r;r=r->before){ |
|
246 |
- switch(r->op){ |
|
247 |
- case LUMP_ADD: |
|
248 |
- new_len+=r->len; |
|
249 |
- break; |
|
250 |
- default: |
|
251 |
- /* only ADD allowed for before/after */ |
|
252 |
- LOG(L_CRIT, "BUG:forward_request: invalid op for" |
|
253 |
- " data lump (%x)\n", r->op); |
|
254 |
- } |
|
255 |
- } |
|
256 |
- switch(t->op){ |
|
257 |
- case LUMP_ADD: |
|
258 |
- new_len+=t->len; |
|
259 |
- break; |
|
260 |
- case LUMP_DEL: |
|
261 |
- /* fix overlapping deleted zones */ |
|
262 |
- if (t->u.offset < s_offset){ |
|
263 |
- /* change len */ |
|
264 |
- if (t->len>s_offset-t->u.offset) |
|
265 |
- t->len-=s_offset-t->u.offset; |
|
266 |
- else t->len=0; |
|
267 |
- t->u.offset=s_offset; |
|
268 |
- } |
|
269 |
- s_offset=t->u.offset+t->len; |
|
270 |
- new_len-=t->len; |
|
271 |
- break; |
|
272 |
- case LUMP_NOP: |
|
273 |
- /* fix offset if overlapping on a deleted zone */ |
|
274 |
- if (t->u.offset < s_offset){ |
|
275 |
- t->u.offset=s_offset; |
|
276 |
- }else |
|
277 |
- s_offset=t->u.offset; |
|
278 |
- /* do nothing */ |
|
279 |
- break; |
|
280 |
- debug: |
|
281 |
- LOG(L_CRIT,"BUG:forward_request: invalid" |
|
282 |
- " op for data lump (%x)\n", r->op); |
|
283 |
- } |
|
284 |
- for (r=t->after;r;r=r->after){ |
|
285 |
- switch(r->op){ |
|
286 |
- case LUMP_ADD: |
|
287 |
- new_len+=r->len; |
|
288 |
- break; |
|
289 |
- default: |
|
290 |
- /* only ADD allowed for before/after */ |
|
291 |
- LOG(L_CRIT, "BUG:forward_request: invalid" |
|
292 |
- " op for data lump (%x)\n", r->op); |
|
293 |
- } |
|
294 |
- } |
|
295 |
- } |
|
296 |
- |
|
297 |
- |
|
298 |
- if (msg->new_uri.s){ |
|
299 |
- uri_len=msg->new_uri.len; |
|
300 |
- new_len=new_len-msg->first_line.u.request.uri.len+uri_len; |
|
301 |
- } |
|
302 |
- new_buf=(char*)malloc(new_len+1); |
|
303 |
- if (new_buf==0){ |
|
304 |
- LOG(L_ERR, "ERROR: forward_request: out of memory\n"); |
|
305 |
- goto error; |
|
306 |
- } |
|
307 |
- |
|
308 |
- offset=s_offset=0; |
|
309 |
- if (msg->new_uri.s){ |
|
310 |
- /* copy message up to uri */ |
|
311 |
- size=msg->first_line.u.request.uri.s-buf; |
|
312 |
- memcpy(new_buf, orig, size); |
|
313 |
- offset+=size; |
|
314 |
- s_offset+=size; |
|
315 |
- /* add our uri */ |
|
316 |
- memcpy(new_buf+offset, msg->new_uri.s, uri_len); |
|
317 |
- offset+=uri_len; |
|
318 |
- s_offset+=msg->first_line.u.request.uri.len; /* skip original uri */ |
|
319 |
- } |
|
320 |
-/* copy msg adding/removing lumps */ |
|
321 |
- for (t=msg->add_rm;t;t=t->next){ |
|
322 |
- switch(t->op){ |
|
323 |
- case LUMP_ADD: |
|
324 |
- /* just add it here! */ |
|
325 |
- /* process before */ |
|
326 |
- for(r=t->before;r;r=r->before){ |
|
327 |
- switch (r->op){ |
|
328 |
- case LUMP_ADD: |
|
329 |
- /*just add it here*/ |
|
330 |
- memcpy(new_buf+offset, r->u.value, r->len); |
|
331 |
- offset+=r->len; |
|
332 |
- break; |
|
333 |
- default: |
|
334 |
- /* only ADD allowed for before/after */ |
|
335 |
- LOG(L_CRIT, "BUG:forward_request: invalid op for" |
|
336 |
- " data lump (%x)\n", r->op); |
|
337 |
- |
|
338 |
- } |
|
339 |
- } |
|
340 |
- /* copy "main" part */ |
|
341 |
- memcpy(new_buf+offset, t->u.value, t->len); |
|
342 |
- offset+=t->len; |
|
343 |
- /* process after */ |
|
344 |
- for(r=t->after;r;r=r->after){ |
|
345 |
- switch (r->op){ |
|
346 |
- case LUMP_ADD: |
|
347 |
- /*just add it here*/ |
|
348 |
- memcpy(new_buf+offset, r->u.value, r->len); |
|
349 |
- offset+=r->len; |
|
350 |
- break; |
|
351 |
- default: |
|
352 |
- /* only ADD allowed for before/after */ |
|
353 |
- LOG(L_CRIT, "BUG:forward_request: invalid op for" |
|
354 |
- " data lump (%x)\n", r->op); |
|
355 |
- } |
|
356 |
- } |
|
357 |
- break; |
|
358 |
- case LUMP_NOP: |
|
359 |
- case LUMP_DEL: |
|
360 |
- /* copy till offset */ |
|
361 |
- if (s_offset>t->u.offset){ |
|
362 |
- DBG("Warning: (%d) overlapped lumps offsets," |
|
363 |
- " ignoring(%x, %x)\n", t->op, s_offset,t->u.offset); |
|
364 |
- /* this should've been fixed above (when computing len) */ |
|
365 |
- /* just ignore it*/ |
|
366 |
- break; |
|
367 |
- } |
|
368 |
- size=t->u.offset-s_offset; |
|
369 |
- if (size){ |
|
370 |
- memcpy(new_buf+offset, orig+s_offset,size); |
|
371 |
- offset+=size; |
|
372 |
- s_offset+=size; |
|
373 |
- } |
|
374 |
- /* process before */ |
|
375 |
- for(r=t->before;r;r=r->before){ |
|
376 |
- switch (r->op){ |
|
377 |
- case LUMP_ADD: |
|
378 |
- /*just add it here*/ |
|
379 |
- memcpy(new_buf+offset, r->u.value, r->len); |
|
380 |
- offset+=r->len; |
|
381 |
- break; |
|
382 |
- default: |
|
383 |
- /* only ADD allowed for before/after */ |
|
384 |
- LOG(L_CRIT, "BUG:forward_request: invalid op for" |
|
385 |
- " data lump (%x)\n", r->op); |
|
386 |
- |
|
387 |
- } |
|
388 |
- } |
|
389 |
- /* process main (del only) */ |
|
390 |
- if (t->op==LUMP_DEL){ |
|
391 |
- /* skip len bytes from orig msg */ |
|
392 |
- s_offset+=t->len; |
|
393 |
- } |
|
394 |
- /* process after */ |
|
395 |
- for(r=t->after;r;r=r->after){ |
|
396 |
- switch (r->op){ |
|
397 |
- case LUMP_ADD: |
|
398 |
- /*just add it here*/ |
|
399 |
- memcpy(new_buf+offset, r->u.value, r->len); |
|
400 |
- offset+=r->len; |
|
401 |
- break; |
|
402 |
- default: |
|
403 |
- /* only ADD allowed for before/after */ |
|
404 |
- LOG(L_CRIT, "BUG:forward_request: invalid op for" |
|
405 |
- " data lump (%x)\n", r->op); |
|
406 |
- } |
|
407 |
- } |
|
408 |
- break; |
|
409 |
- default: |
|
410 |
- LOG(L_CRIT, "BUG: forward_request: unknown op (%x)\n", |
|
411 |
- t->op); |
|
412 |
- } |
|
413 |
- } |
|
414 |
- /* copy the rest of the message */ |
|
415 |
- memcpy(new_buf+offset, orig+s_offset, len-s_offset); |
|
416 |
- new_buf[new_len]=0; |
|
417 |
- |
|
418 | 60 |
/* send it! */ |
419 |
- DBG("Sending:\n%s.\n", new_buf); |
|
420 |
- DBG("orig. len=%d, new_len=%d, via_len=%d, received_len=%d\n", |
|
421 |
- len, new_len, via_len, received_len); |
|
61 |
+ DBG("Sending:\n%s.\n", buf); |
|
62 |
+ DBG("orig. len=%d, new_len=%d\n", msg->len, len ); |
|
422 | 63 |
|
423 | 64 |
to->sin_family = AF_INET; |
424 | 65 |
to->sin_port = (p->port)?htons(p->port):htons(SIP_PORT); |
... | ... |
@@ -432,9 +73,9 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) |
432 | 73 |
to->sin_addr.s_addr=*((long*)p->host.h_addr_list[p->addr_idx]); |
433 | 74 |
|
434 | 75 |
p->tx++; |
435 |
- p->tx_bytes+=new_len; |
|
76 |
+ p->tx_bytes+=len; |
|
436 | 77 |
|
437 |
- if (udp_send(new_buf, new_len, (struct sockaddr*) to, |
|
78 |
+ if (udp_send( buf, len, (struct sockaddr*) to, |
|
438 | 79 |
sizeof(struct sockaddr_in))==-1){ |
439 | 80 |
p->errors++; |
440 | 81 |
p->ok=0; |
... | ... |
@@ -442,20 +83,17 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) |
442 | 83 |
update_fail_on_send; |
443 | 84 |
#endif |
444 | 85 |
goto error; |
445 |
- } |
|
86 |
+ } |
|
446 | 87 |
#ifdef STATS |
447 | 88 |
/* sent requests stats */ |
448 | 89 |
else update_sent_request( msg->first_line.u.request.method_value ); |
449 | 90 |
#endif |
450 |
- free(new_buf); |
|
91 |
+ free(buf); |
|
451 | 92 |
free(to); |
452 | 93 |
/* received_buf & line_buf will be freed in receiv_msg by free_lump_list*/ |
453 | 94 |
return 0; |
454 |
-error1: |
|
455 |
- if (line_buf) pkg_free(line_buf); |
|
456 |
- if (received_buf) pkg_free(received_buf); |
|
457 | 95 |
error: |
458 |
- if (new_buf) free(new_buf); |
|
96 |
+ if (buf) free(buf); |
|
459 | 97 |
if (to) free(to); |
460 | 98 |
return -1; |
461 | 99 |
} |
... | ... |
@@ -478,7 +116,7 @@ int forward_reply(struct sip_msg* msg) |
478 | 116 |
#ifdef DNS_IP_HACK |
479 | 117 |
int err; |
480 | 118 |
#endif |
481 |
- |
|
119 |
+ |
|
482 | 120 |
|
483 | 121 |
orig=msg->orig; |
484 | 122 |
buf=msg->buf; |
... | ... |
@@ -516,9 +154,9 @@ int forward_reply(struct sip_msg* msg) |
516 | 154 |
via_len+=msg->via1->hdr.len+1; |
517 | 155 |
} |
518 | 156 |
new_len=len-via_len; |
519 |
- |
|
157 |
+ |
|
520 | 158 |
DBG(" old size: %d, new size: %d\n", len, new_len); |
521 |
- new_buf=(char*)malloc(new_len+1);/* +1 is for debugging |
|
159 |
+ new_buf=(char*)malloc(new_len+1);/* +1 is for debugging |
|
522 | 160 |
(\0 to print it )*/ |
523 | 161 |
if (new_buf==0){ |
524 | 162 |
LOG(L_ERR, "ERROR: forward_reply: out of memory\n"); |
... | ... |
@@ -531,10 +169,10 @@ int forward_reply(struct sip_msg* msg) |
531 | 169 |
memcpy(new_buf+offset,orig+s_offset, len-s_offset); |
532 | 170 |
/* send it! */ |
533 | 171 |
DBG(" copied size: orig:%d, new: %d, rest: %d\n", |
534 |
- s_offset, offset, |
|
172 |
+ s_offset, offset, |
|
535 | 173 |
len-s_offset ); |
536 | 174 |
DBG("Sending: to %s:%d, \n%s.\n", |
537 |
- msg->via2->host.s, |
|
175 |
+ msg->via2->host.s, |
|
538 | 176 |
(unsigned short)msg->via2->port, |
539 | 177 |
new_buf); |
540 | 178 |
|
... | ... |
@@ -561,8 +199,8 @@ int forward_reply(struct sip_msg* msg) |
561 | 199 |
#ifdef DNS_IP_HACK |
562 | 200 |
} |
563 | 201 |
#endif |
564 |
- if (udp_send(new_buf,new_len, (struct sockaddr*) to, |
|
565 |
- sizeof(struct sockaddr_in))==-1) |
|
202 |
+ if (udp_send(new_buf,new_len, (struct sockaddr*) to, |
|
203 |
+ sizeof(struct sockaddr_in))==-1) |
|
566 | 204 |
{ |
567 | 205 |
#ifdef STATS |
568 | 206 |
update_fail_on_send; |
... | ... |
@@ -16,7 +16,6 @@ int relay_lowest_reply_upstream( struct cell *Trans , struct sip_msg *p_msg ); |
16 | 16 |
int push_reply_from_uac_to_uas( struct sip_msg * , unsigned int ); |
17 | 17 |
int t_cancel_branch(unsigned int branch); //TO DO |
18 | 18 |
|
19 |
-int send_udp_to( char *buf, unsigned buflen, struct sockaddr_in* to, unsigned tolen ); |
|
20 | 19 |
|
21 | 20 |
void retransmission_handler( void *); |
22 | 21 |
void final_response_handler( void *); |
... | ... |
@@ -40,10 +39,6 @@ int tm_startup() |
40 | 39 |
hash_table->timers[WT_TIMER_LIST].timeout_handler = wait_handler; |
41 | 40 |
hash_table->timers[DELETE_LIST].timeout_handler = delete_handler; |
42 | 41 |
|
43 |
- /* creating socket for forwarding and retransmision*/ |
|
44 |
- if ( (sock_fd=socket(AF_INET, SOCK_DGRAM,0))<0 ) |
|
45 |
- return -1; |
|
46 |
- |
|
47 | 42 |
return 0; |
48 | 43 |
} |
49 | 44 |
|
... | ... |
@@ -270,7 +265,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int |
270 | 265 |
T->outbound_request[0]->max_retrans = (T->inbound_request->first_line.u.request.method_value==METHOD_INVITE) ? MAX_INVITE_RETR : MAX_NON_INVITE_RETR; |
271 | 266 |
T->outbound_request[0]->timeout = RETR_T1; |
272 | 267 |
/* send the request */ |
273 |
- send_udp_to( T->outbound_request[0]->buffer , T->outbound_request[0]->bufflen , &(T->outbound_request[0]->to) , sizeof(struct sockaddr_in) ); |
|
268 |
+ send_udp( T->outbound_request[0]->buffer , T->outbound_request[0]->bufflen , &(T->outbound_request[0]->to) , sizeof(struct sockaddr_in) ); |
|
274 | 269 |
} |
275 | 270 |
|
276 | 271 |
|
... | ... |
@@ -401,7 +396,7 @@ int t_retransmit_reply( struct sip_msg* p_msg ) |
401 | 396 |
/* if no transaction exists or no reply to be resend -> out */ |
402 | 397 |
if ( T && T->inbound_response ) |
403 | 398 |
{ |
404 |
- send_udp_to( T->inbound_response->buffer , T->inbound_response->bufflen , &(T->inbound_response->to) , sizeof(struct sockaddr_in) ); |
|
399 |
+ send_udp( T->inbound_response->buffer , T->inbound_response->bufflen , &(T->inbound_response->to) , sizeof(struct sockaddr_in) ); |
|
405 | 400 |
return 0; |
406 | 401 |
} |
407 | 402 |
|
... | ... |
@@ -760,7 +755,7 @@ int t_build_and_send_ACK( struct cell *Trans, unsigned int branch) |
760 | 755 |
*(p++) = '\n'; |
761 | 756 |
|
762 | 757 |
/* sends the ACK message to the same destination as the INVITE */ |
763 |
- send_udp_to( ack_buf, p-ack_buf, &(T->outbound_request[branch]->to) , sizeof(struct sockaddr_in) ); |
|
758 |
+ send_udp( ack_buf, p-ack_buf, &(T->outbound_request[branch]->to) , sizeof(struct sockaddr_in) ); |
|
764 | 759 |
|
765 | 760 |
/* free mem*/ |
766 | 761 |
free( ack_buf ); |
... | ... |
@@ -771,23 +766,6 @@ int t_build_and_send_ACK( struct cell *Trans, unsigned int branch) |
771 | 766 |
|
772 | 767 |
|
773 | 768 |
|
774 |
-/* sends a buffer as a datagram |
|
775 |
- */ |
|
776 |
-int send_udp_to( char *buf, unsigned buflen, struct sockaddr_in* to, unsigned tolen ) |
|
777 |
-{ |
|
778 |
- int res; |
|
779 |
- |
|
780 |
- do |
|
781 |
- { |
|
782 |
- res = sendto(sock_fd, buf, buflen, 0, to, tolen); |
|
783 |
- }while( res==-1 && errno==EINTR ); |
|
784 |
- |
|
785 |
- return res; |
|
786 |
-} |
|
787 |
- |
|
788 |
- |
|
789 |
- |
|
790 |
- |
|
791 | 769 |
|
792 | 770 |
|
793 | 771 |
|