Browse code

- msg_send(), udp_send() and tcp_send() parameter list changed (now they use a struct dest_info to pack several of the old params)

Andrei Pelinescu-Onciul authored on 12/04/2006 18:04:23
Showing 16 changed files
... ...
@@ -66,7 +66,7 @@ MAIN_NAME=ser
66 66
 VERSION = 0
67 67
 PATCHLEVEL = 10
68 68
 SUBLEVEL =   99
69
-EXTRAVERSION = -dev37
69
+EXTRAVERSION = -dev38
70 70
 
71 71
 SER_VER = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
72 72
 			$(SUBLEVEL) )
... ...
@@ -40,6 +40,7 @@
40 40
  *  2004-11-30  added FORCE_SEND_SOCKET_T (andrei)
41 41
  *  2005-12-12  return & drop/exit differentiation (andrei)
42 42
  *  2005-12-19  select framework (mma)
43
+ *  2006-04-12  updated *_send() calls to use a struct dest_info (andrei)
43 44
  */
44 45
 
45 46
 
... ...
@@ -95,8 +96,7 @@ int do_action(struct action* a, struct sip_msg* msg)
95 95
 {
96 96
 	int ret;
97 97
 	int v;
98
-	union sockaddr_union* to;
99
-	struct socket_info* send_sock;
98
+	struct dest_info dst;
100 99
 	struct proxy_l* p;
101 100
 	char* tmp;
102 101
 	char *new_uri, *end, *crt;
... ...
@@ -222,7 +222,8 @@ int do_action(struct action* a, struct sip_msg* msg)
222 222
 			}else if ((a->val[0].type==PROXY_ST) && (a->val[1].type==NUMBER_ST)){
223 223
 				if (proto==PROTO_NONE)
224 224
 					proto=msg->rcv.proto;
225
-				ret=forward_request(msg,(struct proxy_l*)a->val[0].u.data, proto);
225
+				ret=forward_request(msg, (struct proxy_l*)a->val[0].u.data,
226
+										proto);
226 227
 				if (ret>=0) ret=1;
227 228
 			}else{
228 229
 				LOG(L_CRIT, "BUG: do_action: bad forward() types %d, %d\n",
... ...
@@ -238,17 +239,7 @@ int do_action(struct action* a, struct sip_msg* msg)
238 238
 				ret=E_BUG;
239 239
 				break;
240 240
 			}
241
-			to=(union sockaddr_union*)
242
-					pkg_malloc(sizeof(union sockaddr_union));
243
-			if (to==0){
244
-				LOG(L_ERR, "ERROR: do_action: "
245
-							"memory allocation failure\n");
246
-				ret=E_OUT_OF_MEM;
247
-				break;
248
-			}
249
-
250 241
 			p=(struct proxy_l*)a->val[0].u.data;
251
-
252 242
 			if (p->ok==0){
253 243
 				if (p->host.h_addr_list[p->addr_idx+1])
254 244
 					p->addr_idx++;
... ...
@@ -256,7 +247,7 @@ int do_action(struct action* a, struct sip_msg* msg)
256 256
 					p->addr_idx=0;
257 257
 				p->ok=1;
258 258
 			}
259
-			ret=hostent2su(	to, &p->host, p->addr_idx,
259
+			ret=hostent2su(&dst.to, &p->host, p->addr_idx,
260 260
 						(p->port)?p->port:SIP_PORT );
261 261
 			if (ret==0){
262 262
 				if (p_onsend){
... ...
@@ -270,9 +261,10 @@ int do_action(struct action* a, struct sip_msg* msg)
270 270
 				p->tx_bytes+=len;
271 271
 				if (a->type==SEND_T){
272 272
 					/*udp*/
273
-					send_sock=get_send_socket(msg, to, PROTO_UDP);
274
-					if (send_sock!=0){
275
-						ret=udp_send(send_sock, tmp, len, to);
273
+					dst.proto=PROTO_UDP; /* not really needed for udp_send */
274
+					dst.send_sock=get_send_socket(msg, &dst.to, PROTO_UDP);
275
+					if (dst.send_sock!=0){
276
+						ret=udp_send(&dst, tmp, len);
276 277
 					}else{
277 278
 						ret=-1;
278 279
 					}
... ...
@@ -280,11 +272,12 @@ int do_action(struct action* a, struct sip_msg* msg)
280 280
 #ifdef USE_TCP
281 281
 					else{
282 282
 					/*tcp*/
283
-					ret=tcp_send(PROTO_TCP, tmp, len, to, 0);
283
+					dst.proto=PROTO_TCP;
284
+					dst.id=0;
285
+					ret=tcp_send(&dst, tmp, len);
284 286
 				}
285 287
 #endif
286 288
 			}
287
-			pkg_free(to);
288 289
 			if (ret<0){
289 290
 				p->errors++;
290 291
 				p->ok=0;
... ...
@@ -48,6 +48,7 @@
48 48
  *  2004-11-08  added force_send_socket support in get_send_socket (andrei)
49 49
  *  2005-12-11  onsend_router support; forward_request to no longer
50 50
  *              pkg_malloc'ed (andrei)
51
+ *  2006-04-12  forward_{request,reply} use now struct dest_info (andrei)
51 52
  */
52 53
 
53 54
 
... ...
@@ -260,17 +261,19 @@ found:
260 260
 
261 261
 
262 262
 
263
-int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
263
+/* parameters:
264
+ *   msg - sip msg
265
+ *   p   - proxy structure to forward to
266
+ *   proto - protocol used
267
+ */
268
+int forward_request(struct sip_msg* msg, struct proxy_l * p, int proto)
264 269
 {
265 270
 	unsigned int len;
266 271
 	char* buf;
267
-	union sockaddr_union to;
268
-	struct socket_info* send_sock;
269 272
 	char md5[MD5_LEN];
270
-	int id; /* used as branch for tcp! */
273
+	struct dest_info send_info;
271 274
 	
272 275
 	buf=0;
273
-	id=0;
274 276
 	
275 277
 	/* if error try next ip address if possible */
276 278
 	if (p->ok==0){
... ...
@@ -280,16 +283,20 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
280 280
 		p->ok=1;
281 281
 	}
282 282
 	
283
-	hostent2su(&to, &p->host, p->addr_idx, 
283
+	hostent2su(&send_info.to, &p->host, p->addr_idx, 
284 284
 				(p->port)?p->port:SIP_PORT);
285 285
 	p->tx++;
286 286
 	p->tx_bytes+=len;
287 287
 	
288
-
289
-	send_sock=get_send_socket(msg, &to, proto);
290
-	if (send_sock==0){
288
+	
289
+	send_info.proto=proto;
290
+	send_info.id=0;
291
+	send_info.send_sock=get_send_socket(msg, &send_info.to,
292
+											send_info.proto);
293
+	if (send_info.send_sock==0){
291 294
 		LOG(L_ERR, "forward_req: ERROR: cannot forward to af %d, proto %d "
292
-				"no corresponding listening socket\n", to.s.sa_family, proto);
295
+				"no corresponding listening socket\n",
296
+				send_info.to.s.sa_family, send_info.proto);
293 297
 		ser_error=E_NO_SOCKET;
294 298
 		goto error;
295 299
 	}
... ...
@@ -312,28 +319,30 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
312 312
 			goto error;
313 313
 		}
314 314
 		msg->hash_index=hash( msg->callid->body, get_cseq(msg)->number);
315
-		if (!branch_builder( msg->hash_index, 0, md5, id /* 0-th branch */,
315
+		if (!branch_builder( msg->hash_index, 0, md5, 0 /* 0-th branch */,
316 316
 					msg->add_to_branch_s, &msg->add_to_branch_len )) {
317 317
 			LOG(L_ERR, "ERROR: forward_request: branch_builder failed\n");
318 318
 			goto error;
319 319
 		}
320 320
 	}
321 321
 
322
-	buf = build_req_buf_from_sip_req( msg, &len, send_sock,  proto);
322
+	buf = build_req_buf_from_sip_req(msg, &len, send_info.send_sock,
323
+											send_info.proto);
323 324
 	if (!buf){
324 325
 		LOG(L_ERR, "ERROR: forward_request: building failed\n");
325 326
 		goto error;
326 327
 	}
327 328
 	 /* send it! */
328 329
 	DBG("Sending:\n%.*s.\n", (int)len, buf);
329
-	DBG("orig. len=%d, new_len=%d, proto=%d\n", msg->len, len, proto );
330
+	DBG("orig. len=%d, new_len=%d, proto=%d\n",
331
+			msg->len, len, send_info.proto );
330 332
 	
331
-	if (run_onsend(msg, send_sock, proto, &to, buf, len)==0){
333
+	if (run_onsend(msg, &send_info, buf, len)==0){
332 334
 		LOG(L_INFO, "forward_request: request dropped (onsend_route)\n");
333 335
 		STATS_TX_DROPS;
334 336
 		goto error; /* error ? */
335 337
 	}
336
-	if (msg_send(send_sock, proto, &to, 0, buf, len)<0){
338
+	if (msg_send(&send_info, buf, len)<0){
337 339
 		ser_error=E_SEND;
338 340
 		p->errors++;
339 341
 		p->ok=0;
... ...
@@ -424,18 +433,15 @@ int update_sock_struct_from_via( union sockaddr_union* to,
424 424
 int forward_reply(struct sip_msg* msg)
425 425
 {
426 426
 	char* new_buf;
427
-	union sockaddr_union* to;
427
+	struct dest_info dst;
428 428
 	unsigned int new_len;
429 429
 	struct sr_module *mod;
430
-	int proto;
431
-	unsigned int id; /* used only by tcp*/
432 430
 #ifdef USE_TCP
433 431
 	char* s;
434 432
 	int len;
435 433
 #endif
436 434
 	
437
-	to=0;
438
-	id=0;
435
+	dst.id=0;
439 436
 	new_buf=0;
440 437
 	/*check if first via host = us */
441 438
 	if (check_via){
... ...
@@ -467,44 +473,37 @@ int forward_reply(struct sip_msg* msg)
467 467
 		goto error;
468 468
 	}
469 469
 
470
-	to=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
471
-	if (to==0){
472
-		LOG(L_ERR, "ERROR: forward_reply: out of memory\n");
473
-		goto error;
474
-	}
475
-
476 470
 	new_buf = build_res_buf_from_sip_res( msg, &new_len);
477 471
 	if (!new_buf){
478 472
 		LOG(L_ERR, "ERROR: forward_reply: building failed\n");
479 473
 		goto error;
480 474
 	}
481 475
 
482
-	proto=msg->via2->proto;
483
-	if (update_sock_struct_from_via( to, msg, msg->via2 )==-1) goto error;
476
+	dst.proto=msg->via2->proto;
477
+	if (update_sock_struct_from_via( &dst.to, msg, msg->via2 )==-1) goto error;
484 478
 
485 479
 
486 480
 #ifdef USE_TCP
487
-	if (proto==PROTO_TCP
481
+	if (dst.proto==PROTO_TCP
488 482
 #ifdef USE_TLS
489
-			|| proto==PROTO_TLS
483
+			|| dst.proto==PROTO_TLS
490 484
 #endif
491 485
 			){
492 486
 		/* find id in i param if it exists */
493
-		if (msg->via1->i&&msg->via1->i->value.s){
487
+		if (msg->via1->i && msg->via1->i->value.s){
494 488
 			s=msg->via1->i->value.s;
495 489
 			len=msg->via1->i->value.len;
496 490
 			DBG("forward_reply: i=%.*s\n",len, ZSW(s));
497
-			if (reverse_hex2int(s, len, &id)<0){
491
+			if (reverse_hex2int(s, len, (unsigned int*)&dst.id)<0){
498 492
 				LOG(L_ERR, "ERROR: forward_reply: bad via i param \"%.*s\"\n",
499 493
 						len, ZSW(s));
500
-					id=0;
494
+					dst.id=0;
501 495
 			}
502
-			DBG("forward_reply: id= %x\n", id);
503 496
 		}		
504 497
 				
505 498
 	} 
506 499
 #endif
507
-	if (msg_send(0, proto, to, (int)id, new_buf, new_len)<0) goto error;
500
+	if (msg_send(&dst, new_buf, new_len)<0) goto error;
508 501
 #ifdef STATS
509 502
 	STATS_TX_RESPONSE(  (msg->first_line.u.reply.statuscode/100) );
510 503
 #endif
... ...
@@ -514,11 +513,9 @@ int forward_reply(struct sip_msg* msg)
514 514
 			(unsigned short) msg->via2->port);
515 515
 
516 516
 	pkg_free(new_buf);
517
-	pkg_free(to);
518 517
 skip:
519 518
 	return 0;
520 519
 error:
521 520
 	if (new_buf) pkg_free(new_buf);
522
-	if (to) pkg_free(to);
523 521
 	return -1;
524 522
 }
... ...
@@ -33,6 +33,8 @@
33 33
  *  2003-04-07 changed all ports to host byte order (andrei)
34 34
  *  2003-04-12  FORCE_RPORT_T added (andrei)
35 35
  *  2003-04-15  added tcp_disable support (andrei)
36
+ *  2006-04-12  reduced msg_send() parameter list: it uses now a struct 
37
+ *               dest_info param. (andrei)
36 38
  */
37 39
 
38 40
 
... ...
@@ -75,40 +77,41 @@ int forward_reply( struct sip_msg* msg);
75 75
 
76 76
 
77 77
 /* params:
78
- *  send_sock= 0 if already known (e.g. for udp in some cases), non-0 otherwise
79
- *  proto=TCP|UDP
80
- *  to = destination,
81
- *  id - only used on tcp, it will force sending on connection "id" if id!=0 
82
- *       and the connection exists, else it will send to "to" 
83
- *       (useful for sending replies on  the same connection as the request
84
- *       that generated them; use 0 if you don't want this)
78
+ * dst = struct dest_info containing:
79
+ *    send_sock = 0 if not known (e.g. for udp in some cases), non-0 otherwise
80
+ *    proto = TCP|UDP
81
+ *    to = destination (sockaddr_union)
82
+ *    id = only used on tcp, it will force sending on connection "id" if id!=0 
83
+ *         and the connection exists, else it will send to "to" 
84
+ *        (useful for sending replies on  the same connection as the request
85
+ *         that generated them; use 0 if you don't want this)
86
+ * buf, len = buffer
85 87
  * returns: 0 if ok, -1 on error*/
86
-static inline int msg_send(	struct socket_info* send_sock, int proto,
87
-							union sockaddr_union* to, int id,
88
-							char* buf, int len)
88
+static inline int msg_send(struct dest_info* dst, char* buf, int len)
89 89
 {
90 90
 	
91
-	if (proto==PROTO_UDP){
92
-		if (send_sock==0) send_sock=get_send_socket(0, to, proto);
93
-		if (send_sock==0){
91
+	if (dst->proto==PROTO_UDP){
92
+		if (dst->send_sock==0) 
93
+			dst->send_sock=get_send_socket(0, &dst->to, dst->proto);
94
+		if (dst->send_sock==0){
94 95
 			LOG(L_ERR, "msg_send: ERROR: no sending socket found\n");
95 96
 			goto error;
96 97
 		}
97
-		if (udp_send(send_sock, buf, len, to)==-1){
98
+		if (udp_send(dst, buf, len)==-1){
98 99
 			STATS_TX_DROPS;
99 100
 			LOG(L_ERR, "msg_send: ERROR: udp_send failed\n");
100 101
 			goto error;
101 102
 		}
102 103
 	}
103 104
 #ifdef USE_TCP
104
-	else if (proto==PROTO_TCP){
105
+	else if (dst->proto==PROTO_TCP){
105 106
 		if (tcp_disable){
106 107
 			STATS_TX_DROPS;
107 108
 			LOG(L_WARN, "msg_send: WARNING: attempt to send on tcp and tcp"
108 109
 					" support is disabled\n");
109 110
 			goto error;
110 111
 		}else{
111
-			if (tcp_send(proto, buf, len, to, id)<0){
112
+			if (tcp_send(dst, buf, len)<0){
112 113
 				STATS_TX_DROPS;
113 114
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
114 115
 				goto error;
... ...
@@ -116,14 +119,14 @@ static inline int msg_send(	struct socket_info* send_sock, int proto,
116 116
 		}
117 117
 	}
118 118
 #ifdef USE_TLS
119
-	else if (proto==PROTO_TLS){
119
+	else if (dst->proto==PROTO_TLS){
120 120
 		if (tls_disable){
121 121
 			STATS_TX_DROPS;
122 122
 			LOG(L_WARN, "msg_send: WARNING: attempt to send on tls and tls"
123 123
 					" support is disabled\n");
124 124
 			goto error;
125 125
 		}else{
126
-			if (tcp_send(proto, buf, len, to, id)<0){
126
+			if (tcp_send(dst, buf, len)<0){
127 127
 				STATS_TX_DROPS;
128 128
 				LOG(L_ERR, "msg_send: ERROR: tcp_send failed\n");
129 129
 				goto error;
... ...
@@ -133,7 +136,7 @@ static inline int msg_send(	struct socket_info* send_sock, int proto,
133 133
 #endif /* USE_TLS */
134 134
 #endif /* USE_TCP */
135 135
 	else{
136
-			LOG(L_CRIT, "BUG: msg_send: unknown proto %d\n", proto);
136
+			LOG(L_CRIT, "BUG: msg_send: unknown proto %d\n", dst->proto);
137 137
 			goto error;
138 138
 	}
139 139
 	return 0;
... ...
@@ -112,7 +112,7 @@ struct receive_info{
112 112
 
113 113
 struct dest_info{
114 114
 	int proto;
115
-	int proto_reserved1; /* tcp stores the connection id here */ 
115
+	int id; /* tcp stores the connection id here */ 
116 116
 	union sockaddr_union to;
117 117
 	struct socket_info* send_sock;
118 118
 };
... ...
@@ -82,8 +82,7 @@ int send_pr_buffer(	struct retr_buf *rb, void *buf, int len
82 82
 					)
83 83
 {
84 84
 	if (buf && len && rb )
85
-		return msg_send( rb->dst.send_sock, rb->dst.proto, &rb->dst.to,
86
-				         rb->dst.proto_reserved1, buf, len);
85
+		return msg_send( &rb->dst, buf, len);
87 86
 	else {
88 87
 #ifdef EXTRA_DEBUG
89 88
 		LOG(L_CRIT, "ERROR: send_pr_buffer: sending an empty buffer"
... ...
@@ -293,7 +293,7 @@ int add_uac( struct cell *t, struct sip_msg *request, str *uri, str* next_hop,
293 293
 	t->uac[branch].request.dst.to=to;
294 294
 	t->uac[branch].request.dst.send_sock=send_sock;
295 295
 	t->uac[branch].request.dst.proto=proto;
296
-	t->uac[branch].request.dst.proto_reserved1=0;
296
+	t->uac[branch].request.dst.id=0;
297 297
 	t->uac[branch].request.buffer=shbuf;
298 298
 	t->uac[branch].request.buffer_len=len;
299 299
 	t->uac[branch].uri.s=t->uac[branch].request.buffer+
... ...
@@ -571,9 +571,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
571 571
 	success_branch=0;
572 572
 	for (i=first_branch; i<t->nr_of_outgoings; i++) {
573 573
 		if (added_branches & (1<<i)) {
574
-			if (run_onsend(p_msg,	t->uac[i].request.dst.send_sock,
575
-									t->uac[i].request.dst.proto,
576
-									&t->uac[i].request.dst.to,
574
+			if (run_onsend(p_msg,	&t->uac[i].request.dst,
577 575
 									t->uac[i].request.buffer,
578 576
 									t->uac[i].request.buffer_len)==0)
579 577
 				continue; /* if onsend drop, try next branch */
... ...
@@ -1002,7 +1002,7 @@ int init_rb( struct retr_buf *rb, struct sip_msg *msg)
1002 1002
 		proto=via->proto;
1003 1003
 	}
1004 1004
 	rb->dst.proto=proto;
1005
-	rb->dst.proto_reserved1=msg->rcv.proto_reserved1;
1005
+	rb->dst.id=msg->rcv.proto_reserved1;
1006 1006
 	/* turn off mhomed for generating replies -- they are ideally sent to where
1007 1007
 	   request came from to make life with NATs and other beasts easier
1008 1008
 	*/
... ...
@@ -316,21 +316,20 @@ static char *build_local_ack(struct sip_msg* rpl, struct cell *trans, int branch
316 316
 static int send_local_ack(struct sip_msg* msg, str* next_hop,
317 317
 							char* ack, int ack_len)
318 318
 {
319
-	struct socket_info* send_sock;
320
-	union sockaddr_union to_su;
319
+	struct dest_info dst;
321 320
 
322 321
 	if (!next_hop) {
323 322
 		LOG(L_ERR, "send_local_ack: Invalid parameter value\n");
324 323
 		return -1;
325 324
 	}
326 325
 
327
-	send_sock = uri2sock(msg, next_hop, &to_su, PROTO_NONE);
328
-	if (!send_sock) {
326
+	dst.send_sock = uri2sock(msg, next_hop, &dst.to, PROTO_NONE);
327
+	if (!dst.send_sock) {
329 328
 		LOG(L_ERR, "send_local_ack: no socket found\n");
330 329
 		return -1;
331 330
 	}
332
-
333
-	return msg_send(send_sock, send_sock->proto, &to_su, 0, ack, ack_len);
331
+	dst.id=0;
332
+	return msg_send(&dst, ack, ack_len);
334 333
 }
335 334
 
336 335
 
... ...
@@ -235,7 +235,7 @@ int t_uac(str* method, str* headers, str* body, dlg_t* dialog,
235 235
 	request->dst.to = to_su;
236 236
 	request->dst.send_sock = send_sock;
237 237
 	request->dst.proto = send_sock->proto;
238
-	request->dst.proto_reserved1 = 0;
238
+	request->dst.id = 0;
239 239
 
240 240
 	hi=dlg2hash(dialog);
241 241
 	LOCK_HASH(hi);
... ...
@@ -54,17 +54,16 @@ extern struct onsend_info* p_onsend;
54 54
 /*
55 55
  * returns: 0 drop the message, >= ok, <0 error (but forward the message)
56 56
  * WARNING: buf must be 0 terminated (to allow regex matches on it) */
57
-static inline int run_onsend(struct sip_msg* orig_msg,
58
-							struct socket_info* send_sock, int proto,
59
-							union sockaddr_union* to, char* buf, int len)
57
+static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
58
+								char* buf, int len)
60 59
 {
61 60
 	struct onsend_info onsnd_info;
62 61
 	int ret;
63 62
 	
64 63
 	ret=1;
65 64
 	if (onsend_rt.rlist[DEFAULT_RT]){
66
-		onsnd_info.to=to;
67
-		onsnd_info.send_sock=send_sock;
65
+		onsnd_info.to=&dst->to;
66
+		onsnd_info.send_sock=dst->send_sock;
68 67
 		onsnd_info.buf=buf;
69 68
 		onsnd_info.len=len;
70 69
 		p_onsend=&onsnd_info;
... ...
@@ -68,6 +68,7 @@
68 68
  *              EAGAIN; lots of bug fixes (andrei)
69 69
  *  2006-02-06  better tcp_max_connections checks, tcp_connections_no moved to
70 70
  *              shm (andrei)
71
+ *  2006-04-12  tcp_send() changed to use struct dest_info (andrei)
71 72
  */
72 73
 
73 74
 
... ...
@@ -730,10 +731,10 @@ void tcpconn_put(struct tcp_connection* c)
730 730
 
731 731
 
732 732
 /* finds a tcpconn & sends on it
733
+ * uses the dst members to, proto (TCP|TLS) and id
733 734
  * returns: number of bytes written (>=0) on success
734 735
  *          <0 on error */
735
-int tcp_send(int type, char* buf, unsigned len, union sockaddr_union* to,
736
-				int id)
736
+int tcp_send(struct dest_info* dst, char* buf, unsigned len)
737 737
 {
738 738
 	struct tcp_connection *c;
739 739
 	struct tcp_connection *tmp;
... ...
@@ -743,27 +744,26 @@ int tcp_send(int type, char* buf, unsigned len, union sockaddr_union* to,
743 743
 	long response[2];
744 744
 	int n;
745 745
 	
746
-	port=0;
747
-	if (to){
748
-		su2ip_addr(&ip, to);
749
-		port=su_getport(to);
750
-		c=tcpconn_get(id, &ip, port, tcp_con_lifetime); 
751
-	}else if (id){
752
-		c=tcpconn_get(id, 0, 0, tcp_con_lifetime);
746
+	port=su_getport(&dst->to);
747
+	if (port){
748
+		su2ip_addr(&ip, &dst->to);
749
+		c=tcpconn_get(dst->id, &ip, port, tcp_con_lifetime); 
750
+	}else if (dst->id){
751
+		c=tcpconn_get(dst->id, 0, 0, tcp_con_lifetime);
753 752
 	}else{
754 753
 		LOG(L_CRIT, "BUG: tcp_send called with null id & to\n");
755 754
 		return -1;
756 755
 	}
757 756
 	
758
-	if (id){
757
+	if (dst->id){
759 758
 		if (c==0) {
760
-			if (to){
759
+			if (port){
761 760
 				/* try again w/o id */
762 761
 				c=tcpconn_get(0, &ip, port, tcp_con_lifetime);
763 762
 				goto no_id;
764 763
 			}else{
765 764
 				LOG(L_ERR, "ERROR: tcp_send: id %d not found, dropping\n",
766
-						id);
765
+						dst->id);
767 766
 				return -1;
768 767
 			}
769 768
 		}else goto get_fd;
... ...
@@ -772,7 +772,7 @@ no_id:
772 772
 		if (c==0){
773 773
 			DBG("tcp_send: no open tcp connection found, opening new one\n");
774 774
 			/* create tcp connection */
775
-			if ((c=tcpconn_connect(to, type))==0){
775
+			if ((c=tcpconn_connect(&dst->to, dst->proto))==0){
776 776
 				LOG(L_ERR, "ERROR: tcp_send: connect failed\n");
777 777
 				return -1;
778 778
 			}
... ...
@@ -29,6 +29,7 @@
29 29
 #ifndef tcp_server_h
30 30
 #define tcp_server_h
31 31
 
32
+#include "ip_addr.h"
32 33
 
33 34
 
34 35
 /* "public" functions*/
... ...
@@ -36,8 +37,7 @@
36 36
 struct tcp_connection* tcpconn_get(int id, struct ip_addr* ip, int port, 
37 37
 									int timeout);
38 38
 void tcpconn_put(struct tcp_connection* c);
39
-int tcp_send(int type, char* buf, unsigned len, union sockaddr_union* to,
40
-			int id);
39
+int tcp_send(struct dest_info* dst, char* buf, unsigned len);
41 40
 
42 41
 int tcpconn_add_alias(int id, int port, int proto);
43 42
 
... ...
@@ -36,6 +36,7 @@
36 36
  *              cleanups (andrei)
37 37
  *  2005-03-10  multicast options are now set for all the udp sockets (andrei)
38 38
  *  2005-06-26  failure to set mcast options is not an error anymore (andrei)
39
+ *  2006-04-12  udp_send() switched to struct dest_info (andrei)
39 40
  */
40 41
 
41 42
 
... ...
@@ -488,13 +489,15 @@ error:
488 488
 
489 489
 
490 490
 
491
-/* which socket to use? main socket or new one? */
492
-int udp_send(struct socket_info *source, char *buf, unsigned len,
493
-										union sockaddr_union*  to)
491
+/* send buf:len over udp to dst (uses only the to and send_sock dst members)
492
+ * returns the numbers of bytes sent on success (>=0) and -1 on error
493
+ */
494
+int udp_send(struct dest_info* dst, char *buf, unsigned len)
494 495
 {
495 496
 
496 497
 	int n;
497 498
 	int tolen;
499
+	struct ip_addr ip; /* used only on error, for debugging */
498 500
 
499 501
 #ifdef DBG_MSG_QA
500 502
 	/* aborts on error, does nothing otherwise */
... ...
@@ -504,15 +507,16 @@ int udp_send(struct socket_info *source, char *buf, unsigned len,
504 504
 	}
505 505
 #endif
506 506
 
507
-	tolen=sockaddru_len(*to);
507
+	tolen=sockaddru_len(dst->to);
508 508
 again:
509
-	n=sendto(source->socket, buf, len, 0, &to->s, tolen);
509
+	n=sendto(dst->send_sock->socket, buf, len, 0, &dst->to.s, tolen);
510 510
 #ifdef XL_DEBUG
511 511
 	LOG(L_INFO, "INFO: send status: %d\n", n);
512 512
 #endif
513 513
 	if (n==-1){
514
-		LOG(L_ERR, "ERROR: udp_send: sendto(sock,%p,%d,0,%p,%d): %s(%d)\n",
515
-				buf,len,to,tolen,
514
+		su2ip_addr(&ip, &dst->to);
515
+		LOG(L_ERR, "ERROR: udp_send: sendto(sock,%p,%d,0,%s:%d,%d): %s(%d)\n",
516
+				buf,len, ip_addr2a(&ip), su_getport(&dst->to), tolen,
516 517
 				strerror(errno),errno);
517 518
 		if (errno==EINTR) goto again;
518 519
 		if (errno==EINVAL) {
... ...
@@ -38,8 +38,7 @@
38 38
 
39 39
 
40 40
 int udp_init(struct socket_info* si);
41
-int udp_send(struct socket_info* source,char *buf, unsigned len,
42
-				union sockaddr_union*  to);
41
+int udp_send(struct dest_info* dst, char *buf, unsigned len);
43 42
 int udp_rcv_loop();
44 43
 
45 44
 
... ...
@@ -103,7 +103,7 @@ cmd:\n\
103 103
 arg:\n\
104 104
      string or number; to force a number to be interpreted as string \n\
105 105
      prefix it by \"s:\", e.g. s:1\n\
106
-Example:\n\
106
+Examples:\n\
107 107
         " NAME " -s unixs:/tmp/ser_unix system.listMethods\n\
108 108
         " NAME " -f \"pid: %v  desc: %v\\n\" -s udp:localhost:2047 core.ps \n\
109 109
         " NAME " ps  # uses default ctl socket \n\