Browse code

- timer will use first ipv4/ipv6 socket for sending and not the first interface (which can be a loopback) - rport related src_port fixes (all ports are now kept in host byte order)

Andrei Pelinescu-Onciul authored on 06/04/2003 00:21:13
Showing 8 changed files
... ...
@@ -18,7 +18,7 @@
18 18
 VERSION = 0
19 19
 PATCHLEVEL = 8
20 20
 SUBLEVEL =   11
21
-EXTRAVERSION = pre10-allmost-there
21
+EXTRAVERSION = pre11-rport+ba
22 22
 
23 23
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
24 24
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -93,8 +93,8 @@ struct socket_info{
93 93
 struct receive_info{
94 94
 	struct ip_addr src_ip;
95 95
 	struct ip_addr dst_ip;
96
-	unsigned short src_port;
97
-	unsigned short dst_port;
96
+	unsigned short src_port; /* host byte order */
97
+	unsigned short dst_port; /* host byte order */
98 98
 	int proto;
99 99
 	int proto_reserved1; /* tcp stores the connection id here */
100 100
 	int proto_reserved2;
... ...
@@ -240,15 +240,15 @@ static inline int su_cmp(union sockaddr_union* s1, union sockaddr_union* s2)
240 240
 
241 241
 
242 242
 
243
-/* gets the port number */
243
+/* gets the port number (host byte order) */
244 244
 static inline short su_getport(union sockaddr_union* su)
245 245
 {
246 246
 	switch(su->s.sa_family){
247 247
 		case AF_INET:
248
-			return su->sin.sin_port;
248
+			return ntohs(su->sin.sin_port);
249 249
 #ifdef USE_IPV6
250 250
 		case AF_INET6:
251
-			return su->sin6.sin6_port;
251
+			return ntohs(su->sin6.sin6_port);
252 252
 #endif
253 253
 		default:
254 254
 			LOG(L_CRIT,"su_get_port: BUG: unknown address family %d\n",
... ...
@@ -259,16 +259,16 @@ static inline short su_getport(union sockaddr_union* su)
259 259
 
260 260
 
261 261
 
262
-/* sets the port number */
262
+/* sets the port number (host byte order) */
263 263
 static inline void su_setport(union sockaddr_union* su, unsigned short port)
264 264
 {
265 265
 	switch(su->s.sa_family){
266 266
 		case AF_INET:
267
-			su->sin.sin_port=port;
267
+			su->sin.sin_port=htons(port);
268 268
 			break;
269 269
 #ifdef USE_IPV6
270 270
 		case AF_INET6:
271
-			 su->sin6.sin6_port=port;
271
+			 su->sin6.sin6_port=htons(port);
272 272
 			 break;
273 273
 #endif
274 274
 		default:
... ...
@@ -306,7 +306,8 @@ static inline void su2ip_addr(struct ip_addr* ip, union sockaddr_union* su)
306 306
 #define ip_addr2su init_su
307 307
 
308 308
 /* inits a struct sockaddr_union from a struct ip_addr and a port no 
309
- * returns 0 if ok, -1 on error (unknown address family) */
309
+ * returns 0 if ok, -1 on error (unknown address family)
310
+ * the port number is in host byte order */
310 311
 static inline int init_su( union sockaddr_union* su,
311 312
 							struct ip_addr* ip,
312 313
 							unsigned short   port ) 
... ...
@@ -320,7 +321,7 @@ static inline int init_su( union sockaddr_union* su,
320 320
 		#ifdef HAVE_SOCKADDR_SA_LEN
321 321
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
322 322
 		#endif
323
-		su->sin6.sin6_port=port;
323
+		su->sin6.sin6_port=htons(port);
324 324
 		break;
325 325
 #endif
326 326
 	case AF_INET:
... ...
@@ -328,7 +329,7 @@ static inline int init_su( union sockaddr_union* su,
328 328
 		#ifdef HAVE_SOCKADDR_SA_LEN
329 329
 			su->sin.sin_len=sizeof(struct sockaddr_in);
330 330
 		#endif
331
-		su->sin.sin_port=port;
331
+		su->sin.sin_port=htons(port);
332 332
 		break;
333 333
 	default:
334 334
 		LOG(L_CRIT, "init_ss: BUG: unknown address family %d\n", ip->af);
... ...
@@ -340,7 +341,7 @@ static inline int init_su( union sockaddr_union* su,
340 340
 
341 341
 
342 342
 /* inits a struct sockaddr_union from a struct hostent, an address index in
343
- * the hostent structure and a port no.
343
+ * the hostent structure and a port no. (host byte order)
344 344
  * WARNING: no index overflow  checks!
345 345
  * returns 0 if ok, -1 on error (unknown address family) */
346 346
 static inline int hostent2su( union sockaddr_union* su,
... ...
@@ -357,7 +358,7 @@ static inline int hostent2su( union sockaddr_union* su,
357 357
 		#ifdef HAVE_SOCKADDR_SA_LEN
358 358
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
359 359
 		#endif
360
-		su->sin6.sin6_port=port;
360
+		su->sin6.sin6_port=htons(port);
361 361
 		break;
362 362
 #endif
363 363
 	case AF_INET:
... ...
@@ -365,7 +366,7 @@ static inline int hostent2su( union sockaddr_union* su,
365 365
 		#ifdef HAVE_SOCKADDR_SA_LEN
366 366
 			su->sin.sin_len=sizeof(struct sockaddr_in);
367 367
 		#endif
368
-		su->sin.sin_port=port;
368
+		su->sin.sin_port=htons(port);
369 369
 		break;
370 370
 	default:
371 371
 		LOG(L_CRIT, "hostent2su: BUG: unknown address family %d\n", 
... ...
@@ -755,8 +755,9 @@ int main_loop()
755 755
 	}
756 756
 
757 757
 	/*this is the main process*/
758
-	bind_address=&sock_info[0]; /* main proc -> it shoudln't send anything, */
759
-	bind_idx=0;					/* if it does it will use the first address */
758
+	bind_address=0;				/* main proc -> it shouldn't send anything, */
759
+	bind_idx=0;					/* if it does get_send_sock should return
760
+	                               a good socket */
760 761
 	
761 762
 	/* if configured to do so, start a server for accepting FIFO commands */
762 763
 	if (open_fifo_server()<0) {
... ...
@@ -204,7 +204,7 @@ static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
204 204
 		str_int_print("pid=", my_pid());
205 205
 		/* req_src_ip= */
206 206
 		str_ipaddr_print(" req_src_ip=", &msg->rcv.src_ip);
207
-		str_int_print(" req_src_port=", ntohs(msg->rcv.src_port));
207
+		str_int_print(" req_src_port=", msg->rcv.src_port);
208 208
 		str_pair_print(" in_uri=", msg->first_line.u.request.uri.s,
209 209
 									msg->first_line.u.request.uri.len);
210 210
 		str_pair_print(" out_uri=", foo->s, foo->len);
... ...
@@ -272,7 +272,7 @@ char* rport_builder(struct sip_msg *msg, unsigned int *rport_len)
272 272
 	int len;
273 273
 	
274 274
 	tmp_len=0;
275
-	tmp=int2str(ntohs(msg->rcv.src_port), &tmp_len);
275
+	tmp=int2str(msg->rcv.src_port, &tmp_len);
276 276
 	len=RPORT_LEN+tmp_len;
277 277
 	buf=pkg_malloc(sizeof(char)*(len+1));/* space for null term */
278 278
 	if (buf==0){
... ...
@@ -247,6 +247,9 @@ static inline void parse_param_name(str* _s, pclass_t _c, param_hooks_t* _h, par
247 247
 }
248 248
 
249 249
 
250
+
251
+
252
+
250 253
 /*
251 254
  * Parse body of a parameter. It can be quoted string or
252 255
  * a single token.
... ...
@@ -441,13 +441,13 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
441 441
 				else ret=1;
442 442
 				break;
443 443
 		case SRCPORT_O:
444
-				ret=comp_no(ntohs(msg->rcv.src_port), 
444
+				ret=comp_no(msg->rcv.src_port, 
445 445
 					e->r.param, /* e.g., 5060 */
446 446
 					e->op, /* e.g. == */
447 447
 					e->subtype /* 5060 is number */);
448 448
 				break;
449 449
 		case DSTPORT_O:
450
-				ret=comp_no(ntohs(msg->rcv.dst_port), e->r.param, e->op, 
450
+				ret=comp_no(msg->rcv.dst_port, e->r.param, e->op, 
451 451
 							e->subtype);
452 452
 				break;
453 453
 		case PROTO_O:
... ...
@@ -283,7 +283,7 @@ struct tcp_connection* _tcpconn_find(int id, struct ip_addr* ip, int port)
283 283
 		for (c=tcpconn_id_hash[hash]; c; c=c->id_next){
284 284
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
285 285
 			print_ip(&c->rcv.src_ip);
286
-			DBG(" port=%d\n", ntohs(c->rcv.src_port));
286
+			DBG(" port=%d\n", c->rcv.src_port);
287 287
 			if ((id==c->id)&&(!c->bad)) return c;
288 288
 		}
289 289
 	}else if (ip){
... ...
@@ -291,7 +291,7 @@ struct tcp_connection* _tcpconn_find(int id, struct ip_addr* ip, int port)
291 291
 		for (c=tcpconn_addr_hash[hash]; c; c=c->next){
292 292
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
293 293
 			print_ip(&c->rcv.src_ip);
294
-			DBG(" port=%d\n", ntohs(c->rcv.src_port));
294
+			DBG(" port=%d\n", c->rcv.src_port);
295 295
 			if ( (!c->bad) && (port==c->rcv.src_port) &&
296 296
 					(ip_addr_cmp(ip, &c->rcv.src_ip)) )
297 297
 				return c;
... ...
@@ -391,14 +391,14 @@ again:
391 391
 					  "buf:\n%.*s\nparsed:\n%.*s\n", req->state, req->error,
392 392
 					  (int)(req->pos-req->buf), req->buf,
393 393
 					  (int)(req->parsed-req->start), req->start);
394
-			DBG("- received from: port %d, ip -", ntohs(con->rcv.src_port));
394
+			DBG("- received from: port %d, ip -", con->rcv.src_port);
395 395
 			print_ip(&con->rcv.src_ip); DBG("-\n");
396 396
 			resp=CONN_ERROR;
397 397
 			goto end_req;
398 398
 		}
399 399
 		if (req->complete){
400 400
 			DBG("tcp_read_req: end of header part\n");
401
-			DBG("- received from: port %d, ip - ", ntohs(con->rcv.src_port));
401
+			DBG("- received from: port %d, ip - ", con->rcv.src_port);
402 402
 			print_ip(&con->rcv.src_ip); DBG("-\n");
403 403
 			DBG("tcp_read_req: headers:\n%.*s.\n",
404 404
 					(int)(req->body-req->start), req->start);