Browse code

- sock_lists completely re-organized

Andrei Pelinescu-Onciul authored on 24/10/2003 20:23:58
Showing 15 changed files
... ...
@@ -43,7 +43,7 @@ export makefile_defs
43 43
 VERSION = 0
44 44
 PATCHLEVEL = 8
45 45
 SUBLEVEL =   12
46
-EXTRAVERSION = dev-20-lumps
46
+EXTRAVERSION = dev-21-sock_info
47 47
 
48 48
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
49 49
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -4,7 +4,10 @@ $Id$
4 4
 
5 5
 - fix aliases for tls_port (add_them?)
6 6
 - fix check_sel_op -- add proto for uri proto checks
7
+- add via alias for tcp port & infinite tcp conn life
7 8
 
9
+- fix 2 different fixups for diff. no of parameter
10
+ (add no of params ot struct action?) -- linked to var. no. of params
8 11
 - alias support fot tcp/tls port numbers
9 12
 - warning builder set_advertised address support
10 13
 - grep parse_uri & replace with parse_sip_msg_uri (e.g do_action!)
... ...
@@ -47,6 +47,7 @@
47 47
  *             added msg:len (andrei)
48 48
  * 2003-10-11  if(){} doesn't require a ';' after it anymore (andrei)
49 49
  * 2003-10-13  added FIFO_DIR & proto:host:port listen/alias support (andrei)
50
+ * 2003-10-24  converted to the new socket_info lists (andrei)
50 51
  */
51 52
 
52 53
 
... ...
@@ -67,9 +68,11 @@
67 67
 #include "sr_module.h"
68 68
 #include "modparam.h"
69 69
 #include "ip_addr.h"
70
+#include "socket_info.h"
70 71
 #include "name_alias.h"
71 72
 #include "ut.h"
72 73
 
74
+
73 75
 #include "config.h"
74 76
 #ifdef USE_TLS
75 77
 #include "tls/tls_config.h"
... ...
@@ -84,7 +87,7 @@
84 84
 #undef _ALLOCA_H
85 85
 
86 86
 struct id_list{
87
-	char* s;
87
+	char* name;
88 88
 	int proto;
89 89
 	int port;
90 90
 	struct id_list* next;
... ...
@@ -327,6 +330,7 @@ listen_id:	ip			{	tmp=ip_addr2a($1);
327 327
 proto:	  UDP	{ $$=PROTO_UDP; }
328 328
 		| TCP	{ $$=PROTO_TCP; }
329 329
 		| TLS	{ $$=PROTO_TLS; }
330
+		| STAR	{ $$=0; }
330 331
 		;
331 332
 
332 333
 port:	  NUMBER	{ $$=$1; }
... ...
@@ -355,10 +359,7 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
355 355
 		| DNS EQUAL error { yyerror("boolean value expected"); }
356 356
 		| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
357 357
 		| REV_DNS EQUAL error { yyerror("boolean value expected"); }
358
-		| PORT EQUAL NUMBER   { port_no=$3; 
359
-								if (sock_no>0) 
360
-									sock_info[sock_no-1].port_no=port_no;
361
-							  }
358
+		| PORT EQUAL NUMBER   { port_no=$3; }
362 359
 		| STAT EQUAL STRING {
363 360
 					#ifdef STATS
364 361
 							stat_file=$3;
... ...
@@ -521,27 +522,13 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
521 521
 		| REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); }
522 522
 		| LISTEN EQUAL id_lst {
523 523
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
524
-								if (sock_no < MAX_LISTEN){
525
-									sock_info[sock_no].name.s=(char*)
526
-											pkg_malloc(strlen(lst_tmp->s)+1);
527
-									if (sock_info[sock_no].name.s==0){
528
-										LOG(L_CRIT, "ERROR: cfg. parser:"
529
-													" out of memory.\n");
530
-										break;
531
-									}else{
532
-										strncpy(sock_info[sock_no].name.s,
533
-												lst_tmp->s,
534
-												strlen(lst_tmp->s)+1);
535
-										sock_info[sock_no].name.len=
536
-													strlen(lst_tmp->s);
537
-										sock_info[sock_no].port_no=
538
-													lst_tmp->port;
539
-										sock_no++;
540
-									}
541
-								}else{
542
-									LOG(L_CRIT, "ERROR: cfg. parser: "
543
-												"too many listen addresses"
544
-												"(max. %d).\n", MAX_LISTEN);
524
+								if (add_listen_iface(	lst_tmp->name,
525
+														lst_tmp->port,
526
+														lst_tmp->proto,
527
+														0
528
+													)!=0){
529
+									LOG(L_CRIT,  "ERROR: cfg. parser: failed"
530
+											" to add listen address\n");
545 531
 									break;
546 532
 								}
547 533
 							}
... ...
@@ -550,7 +537,7 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
550 550
 						"expected"); }
551 551
 		| ALIAS EQUAL  id_lst { 
552 552
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
553
-								add_alias(lst_tmp->s, strlen(lst_tmp->s), 
553
+								add_alias(lst_tmp->name, strlen(lst_tmp->name),
554 554
 											lst_tmp->port, lst_tmp->proto);
555 555
 							  }
556 556
 		| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
... ...
@@ -1509,7 +1496,7 @@ static struct id_list* mk_listen_id(char* host, int proto, int port)
1509 1509
 	if (l==0){
1510 1510
 		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
1511 1511
 	}else{
1512
-		l->s=host;
1512
+		l->name=host;
1513 1513
 		l->port=port;
1514 1514
 		l->proto=proto;
1515 1515
 		l->next=0;
... ...
@@ -43,6 +43,7 @@
43 43
  *               local replies (andrei)
44 44
  *  2003-08-21  check_self properly handles ipv6 addresses & refs   (andrei)
45 45
  *  2003-10-21  check_self updated to handle proto (andrei)
46
+ *  2003-10-24  converted to the new socket_info lists (andrei)
46 47
  */
47 48
 
48 49
 
... ...
@@ -71,6 +72,7 @@
71 71
 #include "ip_addr.h"
72 72
 #include "resolve.h"
73 73
 #include "name_alias.h"
74
+#include "socket_info.h"
74 75
 
75 76
 #ifdef DEBUG_DMALLOC
76 77
 #include <dmalloc.h>
... ...
@@ -87,15 +89,14 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto)
87 87
 {
88 88
 	int temp_sock;
89 89
 	socklen_t len;
90
-	int r;
91 90
 	union sockaddr_union from; 
91
+	struct socket_info* si;
92 92
 
93 93
 	if (proto!=PROTO_UDP) {
94 94
 		LOG(L_CRIT, "BUG: get_out_socket can only be called for UDP\n");
95 95
 		return 0;
96 96
 	}
97
-
98
-	r=-1;
97
+	
99 98
 	temp_sock=socket(to->s.sa_family, SOCK_DGRAM, 0 );
100 99
 	if (temp_sock==-1) {
101 100
 		LOG(L_ERR, "ERROR: get_out_socket: socket() failed: %s\n",
... ...
@@ -113,38 +114,39 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto)
113 113
 				strerror(errno));
114 114
 		goto error;
115 115
 	}
116
-	for (r=0; r<sock_no; r++) {
116
+	for (si=udp_listen; si; si=si->next) {
117 117
 		switch(from.s.sa_family) {
118 118
 			case AF_INET:	
119
-						if (sock_info[r].address.af!=AF_INET)
119
+						if (si->address.af!=AF_INET)
120 120
 								continue;
121
-						if (memcmp(&sock_info[r].address.u,
121
+						if (memcmp(&si->address.u,
122 122
 								&from.sin.sin_addr, 
123
-								sock_info[r].address.len)==0)
124
-							goto error; /* it is actually success */
123
+								si->address.len)==0)
124
+							goto found; /*  success */
125 125
 						break;
126 126
 #if defined(USE_IPV6)
127 127
 			case AF_INET6:	
128
-						if (sock_info[r].address.af!=AF_INET6)
128
+						if (si->address.af!=AF_INET6)
129 129
 								continue;
130
-						if (memcmp(&sock_info[r].address.u,
130
+						if (memcmp(&si->address.u,
131 131
 								&from.sin6.sin6_addr, len)==0)
132
-							goto error;
132
+							goto found;
133 133
 						continue;
134 134
 #endif
135 135
 			default:	LOG(L_ERR, "ERROR: get_out_socket: "
136 136
 									"unknown family: %d\n",
137 137
 									from.s.sa_family);
138
-						r=-1;
139 138
 						goto error;
140 139
 		}
141 140
 	}
142
-	LOG(L_ERR, "ERROR: get_out_socket: no socket found\n");
143
-	r=-1;
144 141
 error:
142
+	LOG(L_ERR, "ERROR: get_out_socket: no socket found\n");
143
+	close(temp_sock);
144
+	return 0;
145
+found:
145 146
 	close(temp_sock);
146
-	DBG("DEBUG: get_out_socket: socket determined: %d\n", r );
147
-	return r==-1? 0: &sock_info[r];
147
+	DBG("DEBUG: get_out_socket: socket determined: %p\n", si );
148
+	return si;
148 149
 }
149 150
 
150 151
 
... ...
@@ -228,10 +230,10 @@ struct socket_info* get_send_socket(union sockaddr_union* to, int proto)
228 228
  */
229 229
 int check_self(str* host, unsigned short port, unsigned short proto)
230 230
 {
231
-	int r;
232 231
 	char* hname;
233 232
 	int h_len;
234 233
 	struct socket_info* si;
234
+	unsigned short c_proto;
235 235
 #ifdef USE_IPV6
236 236
 	struct ip_addr* ip6;
237 237
 #endif
... ...
@@ -245,76 +247,80 @@ int check_self(str* host, unsigned short port, unsigned short proto)
245 245
 		h_len-=2;
246 246
 	}
247 247
 #endif
248
-	/* get teh proper sock list */
249
-	switch(proto){
250
-		case PROTO_NONE: /* we'll use udp and not all the lists FIXME: */
251
-		case PROTO_UDP:
252
-			si=sock_info;
253
-			break;
248
+	c_proto=proto?proto:PROTO_UDP;
249
+	do{
250
+		/* get the proper sock list */
251
+		switch(c_proto){
252
+			case PROTO_NONE: /* we'll use udp and not all the lists FIXME: */
253
+			case PROTO_UDP:
254
+				si=udp_listen;
255
+				break;
254 256
 #ifdef USE_TCP
255
-		case PROTO_TCP:
256
-			si=tcp_info;
257
-			break;
257
+			case PROTO_TCP:
258
+				si=tcp_listen;
259
+				break;
258 260
 #endif
259 261
 #ifdef USE_TLS
260
-		case PROTO_TLS:
261
-			si=tls_info;
262
-			break;
262
+			case PROTO_TLS:
263
+				si=tls_listen;
264
+				break;
263 265
 #endif
264
-		default:
265
-			/* unknown proto */
266
-			LOG(L_WARN, "WARNING: check_self: unknown proto %d\n", proto);
267
-			return 0; /* false */
268
-	}
269
-	for (r=0; r<sock_no; r++){
270
-		DBG("check_self - checking if host==us: %d==%d && "
271
-				" [%.*s] == [%.*s]\n", 
272
-					h_len,
273
-					si[r].name.len,
274
-					h_len, hname,
275
-					si[r].name.len, si[r].name.s
276
-			);
277
-		if (port) {
278
-			DBG("check_self - checking if port %d matches port %d\n", 
279
-					si[r].port_no, port);
280
-			if (si[r].port_no!=port) {
281
-				continue;
282
-			}
266
+			default:
267
+				/* unknown proto */
268
+				LOG(L_WARN, "WARNING: check_self: "
269
+							"unknown proto %d\n", c_proto);
270
+				return 0; /* false */
283 271
 		}
284
-		if ( (h_len==sock_info[r].name.len) && 
285
-			(strncasecmp(hname, sock_info[r].name.s,
286
-				     sock_info[r].name.len)==0) /*slower*/)
287
-			/* comp. must be case insensitive, host names
288
-			 * can be written in mixed case, it will also match
289
-			 * ipv6 addresses if we are lucky*/
290
-			break;
291
-	/* check if host == ip address */
272
+		for (; si; si=si->next){
273
+			DBG("check_self - checking if host==us: %d==%d && "
274
+					" [%.*s] == [%.*s]\n", 
275
+						h_len,
276
+						si->name.len,
277
+						h_len, hname,
278
+						si->name.len, si->name.s
279
+				);
280
+			if (port) {
281
+				DBG("check_self - checking if port %d matches port %d\n", 
282
+						si->port_no, port);
283
+				if (si->port_no!=port) {
284
+					continue;
285
+				}
286
+			}
287
+			if ( (h_len==si->name.len) && 
288
+				(strncasecmp(hname, si->name.s,
289
+						 si->name.len)==0) /*slower*/)
290
+				/* comp. must be case insensitive, host names
291
+				 * can be written in mixed case, it will also match
292
+				 * ipv6 addresses if we are lucky*/
293
+				goto found;
294
+		/* check if host == ip address */
292 295
 #ifdef USE_IPV6
293
-		/* ipv6 case is uglier, host can be [3ffe::1] */
294
-		ip6=str2ip6(host);
295
-		if (ip6){
296
-			if (ip_addr_cmp(ip6, &sock_info[r].address))
297
-				break; /* match */
298
-			else
299
-				continue; /* no match, but this is an ipv6 address
300
-							 so no point in trying ipv4 */
301
-		}
296
+			/* ipv6 case is uglier, host can be [3ffe::1] */
297
+			ip6=str2ip6(host);
298
+			if (ip6){
299
+				if (ip_addr_cmp(ip6, &si->address))
300
+					goto found; /* match */
301
+				else
302
+					continue; /* no match, but this is an ipv6 address
303
+								 so no point in trying ipv4 */
304
+			}
302 305
 #endif
303
-		/* ipv4 */
304
-		if ( 	(!sock_info[r].is_ip) &&
305
-				(h_len==sock_info[r].address_str.len) && 
306
-			(memcmp(hname, sock_info[r].address_str.s, 
307
-								sock_info[r].address_str.len)==0)
308
-			)
309
-			break;
310
-	}
311
-	if (r==sock_no){
312
-		/* try to look into the aliases*/
313
-		if (grep_aliases(hname, h_len, port, proto)==0){
314
-			DBG("check_self: host != me\n");
315
-			return 0;
306
+			/* ipv4 */
307
+			if ( 	(!(si->flags&SI_IS_IP)) &&
308
+					(h_len==si->address_str.len) && 
309
+				(memcmp(hname, si->address_str.s, 
310
+									si->address_str.len)==0)
311
+				)
312
+				goto found;
316 313
 		}
314
+	}while( (proto==0) && (c_proto=next_proto(c_proto)) );
315
+	
316
+	/* try to look into the aliases*/
317
+	if (grep_aliases(hname, h_len, port, proto)==0){
318
+		DBG("check_self: host != me\n");
319
+		return 0;
317 320
 	}
321
+found:
318 322
 	return 1;
319 323
 }
320 324
 
... ...
@@ -46,19 +46,10 @@
46 46
 extern char * cfg_file;
47 47
 extern int config_check;
48 48
 extern char *stat_file;
49
-extern struct socket_info sock_info[]; /* all addresses we listen/send from*/
50
-#ifdef USE_TCP
51
-extern struct socket_info tcp_info[]; /* all tcp sockets we listen on*/
52
-#endif
53
-#ifdef USE_TLS
54
-extern struct socket_info tls_info[]; /* tcp-tls sockets */
55
-#endif
56
-extern int sock_no; /* number of addresses/open sockets*/
57 49
 extern unsigned short port_no;
58 50
 
59 51
 extern struct socket_info* bind_address; /* pointer to the crt. proc.
60 52
 											listening address */
61
-extern int bind_idx; /* same as above but index in the bound[] array */
62 53
 extern struct socket_info* sendipv4; /* ipv4 socket to use when msg.
63 54
 										comes from ipv6*/
64 55
 extern struct socket_info* sendipv6; /* same as above for ipv6 */
... ...
@@ -77,6 +77,9 @@ union sockaddr_union{
77 77
 };
78 78
 
79 79
 
80
+
81
+enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2 };
82
+
80 83
 struct socket_info{
81 84
 	int socket;
82 85
 	str name; /* name - eg.: foo.bar or 10.0.0.1 */
... ...
@@ -84,10 +87,11 @@ struct socket_info{
84 84
 	str address_str;        /* ip address converted to string -- optimization*/
85 85
 	unsigned short port_no;  /* port number */
86 86
 	str port_no_str; /* port number converted to string -- optimization*/
87
-	int is_ip; /* 1 if name is an ip address, 0 if not  -- optimization*/
88
-	int is_lo; /* 1 if is a loopback, 0 if not */
87
+	enum si_flags flags; /* SI_IS_IP | SI_IS_LO */
89 88
 	union sockaddr_union su; 
90 89
 	int proto; /* tcp or udp*/
90
+	struct socket_info* next;
91
+	struct socket_info* prev;
91 92
 };
92 93
 
93 94
 
... ...
@@ -44,6 +44,7 @@
44 44
  *                see comment above it for explanations. (andrei)
45 45
  *  2003-06-29  replaced port_no_str snprintf w/ int2str (andrei)
46 46
  *  2003-10-10  added switch for config check (-c) (andrei)
47
+ *  2003-10-24  converted to the new socket_info lists (andrei)
47 48
  *
48 49
  */
49 50
 
... ...
@@ -330,17 +331,15 @@ int names_len[MAX_LISTEN];            /* lengths of the names*/
330 330
 struct ip_addr addresses[MAX_LISTEN]; /* our ips */
331 331
 int addresses_no=0;                   /* number of names/ips */
332 332
 #endif
333
-struct socket_info sock_info[MAX_LISTEN];/*all addresses we listen/send from*/
333
+struct socket_info* udp_listen=0;
334 334
 #ifdef USE_TCP
335
-struct socket_info tcp_info[MAX_LISTEN];/*all tcp addresses we listen on*/
335
+struct socket_info* tcp_listen=0;
336 336
 #endif
337 337
 #ifdef USE_TLS
338
-struct socket_info tls_info[MAX_LISTEN]; /* all tls addresses we listen on*/
338
+struct socket_info* tls_listen=0;
339 339
 #endif
340
-int sock_no=0; /* number of addresses/open sockets*/
341 340
 struct socket_info* bind_address=0; /* pointer to the crt. proc.
342 341
 									 listening address*/
343
-int bind_idx; /* same as above but index in the bound[] array */
344 342
 struct socket_info* sendipv4; /* ipv4 socket to use when msg. comes from ipv6*/
345 343
 struct socket_info* sendipv6; /* same as above for ipv6 */
346 344
 #ifdef USE_TCP
... ...
@@ -754,8 +753,9 @@ error:
754 754
 /* main loop */
755 755
 int main_loop()
756 756
 {
757
-	int r, i;
757
+	int  i;
758 758
 	pid_t pid;
759
+	struct socket_info* si;
759 760
 #ifdef USE_TCP
760 761
 	int sockfd[2];
761 762
 #endif
... ...
@@ -773,12 +773,11 @@ int main_loop()
773 773
 		setstats( 0 );
774 774
 #endif
775 775
 		/* only one address, we ignore all the others */
776
-		if (udp_init(&sock_info[0])==-1) goto error;
777
-		bind_address=&sock_info[0];
776
+		if (udp_init(udp_listen)==-1) goto error;
777
+		bind_address=udp_listen;
778 778
 		sendipv4=bind_address;
779 779
 		sendipv6=bind_address; /*FIXME*/
780
-		bind_idx=0;
781
-		if (sock_no>1){
780
+		if (udp_listen->next){
782 781
 			LOG(L_WARN, "WARNING: using only the first listen address"
783 782
 						" (no fork)\n");
784 783
 		}
... ...
@@ -853,66 +852,55 @@ int main_loop()
853 853
 		/* process_no now initialized to zero -- increase from now on
854 854
 		   as new processes are forked (while skipping 0 reserved for main )
855 855
 		*/
856
-		for(r=0;r<sock_no;r++){
856
+		for(si=udp_listen;si;si=si->next){
857 857
 			/* create the listening socket (for each address)*/
858 858
 			/* udp */
859
-			if (udp_init(&sock_info[r])==-1) goto error;
859
+			if (udp_init(si)==-1) goto error;
860 860
 			/* get first ipv4/ipv6 socket*/
861
-			if ((sock_info[r].address.af==AF_INET)&&
862
-					((sendipv4==0)||(sendipv4->is_lo)))
863
-				sendipv4=&sock_info[r];
861
+			if ((si->address.af==AF_INET)&&
862
+					((sendipv4==0)||(sendipv4->flags&SI_IS_LO)))
863
+				sendipv4=si;
864 864
 	#ifdef USE_IPV6
865
-			if((sendipv6==0)&&(sock_info[r].address.af==AF_INET6))
866
-				sendipv6=&sock_info[r];
865
+			if((sendipv6==0)&&(si->address.af==AF_INET6))
866
+				sendipv6=si;
867 867
 	#endif
868
+		}
868 869
 #ifdef USE_TCP
869
-			if (!tcp_disable){
870
-				tcp_info[r]=sock_info[r]; /* copy the sockets */
870
+		if (!tcp_disable){
871
+			for(si=tcp_listen; si; si=si->next){
871 872
 				/* same thing for tcp */
872
-				if (tcp_init(&tcp_info[r])==-1)  goto error;
873
+				if (tcp_init(si)==-1)  goto error;
873 874
 				/* get first ipv4/ipv6 socket*/
874
-				if ((tcp_info[r].address.af==AF_INET)&&
875
-						((sendipv4_tcp==0)||(sendipv4_tcp->is_lo)))
876
-					sendipv4_tcp=&tcp_info[r];
875
+				if ((si->address.af==AF_INET)&&
876
+						((sendipv4_tcp==0)||(sendipv4_tcp->flags&SI_IS_LO)))
877
+					sendipv4_tcp=si;
877 878
 		#ifdef USE_IPV6
878
-				if((sendipv6_tcp==0)&&(tcp_info[r].address.af==AF_INET6))
879
-					sendipv6_tcp=&tcp_info[r];
879
+				if((sendipv6_tcp==0)&&(si->address.af==AF_INET6))
880
+					sendipv6_tcp=si;
880 881
 		#endif
881 882
 			}
883
+		}
882 884
 #ifdef USE_TLS
883
-			if (!tls_disable){
884
-				tls_info[r]=sock_info[r]; /* copy the sockets */
885
-				/* fix the port number -- there is no way so far to set-up
886
-				 * individual tls port numbers */
887
-				tls_info[r].port_no=tls_port_no; /* FIXME: */
888
-				tmp=int2str(tls_info[r].port_no, &len);
889
-				/* we don't need to free the previous content, is uesd
890
-				 * by tcp & udp! */
891
-				tls_info[r].port_no_str.s=(char*)pkg_malloc(len+1);
892
-				if (tls_info[r].port_no_str.s==0){
893
-					LOG(L_CRIT, "memory allocation failure\n");
894
-					goto error;
895
-				}
896
-				strncpy(tls_info[r].port_no_str.s, tmp, len+1);
897
-				tls_info[r].port_no_str.len=len;
898
-				
885
+		if (!tls_disable){
886
+			for(si=tls_listen; si; si=si->next){
899 887
 				/* same as for tcp*/
900
-				if (tls_init(&tls_info[r])==-1)  goto error;
888
+				if (tls_init(si)==-1)  goto error;
901 889
 				/* get first ipv4/ipv6 socket*/
902
-				if ((tls_info[r].address.af==AF_INET)&&
903
-						((sendipv4_tls==0)||(sendipv4_tls->is_lo)))
904
-					sendipv4_tls=&tls_info[r];
890
+				if ((si->address.af==AF_INET)&&
891
+						((sendipv4_tls==0)||(sendipv4_tls->flags&SI_IS_LO)))
892
+					sendipv4_tls=si;
905 893
 		#ifdef USE_IPV6
906
-				if((sendipv6_tls==0)&&(tls_info[r].address.af==AF_INET6))
907
-					sendipv6_tls=&tls_info[r];
894
+				if((sendipv6_tls==0)&&(si->address.af==AF_INET6))
895
+					sendipv6_tls=si;
908 896
 		#endif
909 897
 			}
898
+		}
910 899
 #endif /* USE_TLS */
911 900
 #endif /* USE_TCP */
912 901
 			/* all procs should have access to all the sockets (for sending)
913 902
 			 * so we open all first*/
914
-		}
915
-		for(r=0; r<sock_no;r++){
903
+		/* udp processes */
904
+		for(si=udp_listen; si; si=si->next){
916 905
 			for(i=0;i<children_no;i++){
917 906
 				process_no++;
918 907
 #ifdef USE_TCP
... ...
@@ -935,8 +923,7 @@ int main_loop()
935 935
 						unix_tcp_sock=sockfd[1];
936 936
 					}
937 937
 #endif
938
-					bind_address=&sock_info[r]; /* shortcut */
939
-					bind_idx=r;
938
+					bind_address=si; /* shortcut */
940 939
 					if (init_child(i + 1) < 0) {
941 940
 						LOG(L_ERR, "init_child failed\n");
942 941
 						goto error;
... ...
@@ -948,8 +935,8 @@ int main_loop()
948 948
 				}else{
949 949
 						pt[process_no].pid=pid; /*should be in shared mem.*/
950 950
 						snprintf(pt[process_no].desc, MAX_PT_DESC,
951
-							"receiver child=%d sock=%d @ %s:%s", i, r, 	
952
-							sock_info[r].name.s, sock_info[r].port_no_str.s );
951
+							"receiver child=%d sock= %s:%s", i, 	
952
+							si->name.s, si->port_no_str.s );
953 953
 #ifdef USE_TCP
954 954
 						if (!tcp_disable){
955 955
 							close(sockfd[1]);
... ...
@@ -967,8 +954,6 @@ int main_loop()
967 967
 
968 968
 	/*this is the main process*/
969 969
 	bind_address=0;				/* main proc -> it shouldn't send anything, */
970
-	bind_idx=0;					/* if it does get_send_sock should return
971
-	                               a good socket */
972 970
 	
973 971
 	/* if configured to do so, start a server for accepting FIFO commands */
974 972
 	if (open_fifo_server()<0) {
... ...
@@ -1068,8 +1053,9 @@ int main_loop()
1068 1068
 #endif
1069 1069
 	/*DEBUG- remove it*/
1070 1070
 #ifdef DEBUG
1071
-	fprintf(stderr, "\n% 3d processes (%3d), % 3d children * % 3d listening addresses"
1072
-			"+ main + fifo %s\n", process_no+1, process_count(), children_no, sock_no,
1071
+	fprintf(stderr, "\n% 3d processes (%3d), % 3d children * "
1072
+			"listening addresses + tcp listeners + tls listeners"
1073
+			"+ main + fifo %s\n", process_no+1, process_count(), children_no,
1073 1074
 			(timer_list)?"+ timer":"");
1074 1075
 	for (r=0; r<=process_no; r++){
1075 1076
 		fprintf(stderr, "% 3d   % 5d - %s\n", r, pt[r].pid, pt[r].desc);
... ...
@@ -1095,134 +1081,6 @@ int main_loop()
1095 1095
 
1096 1096
 }
1097 1097
 
1098
-/* add all family type addresses of interface if_name to the socket_info array
1099
- * if if_name==0, adds all addresses on all interfaces
1100
- * WARNING: it only works with ipv6 addresses on FreeBSD
1101
- * return: -1 on error, 0 on success
1102
- */
1103
-int add_interfaces(char* if_name, int family, unsigned short port)
1104
-{
1105
-	struct ifconf ifc;
1106
-	struct ifreq ifr;
1107
-	struct ifreq ifrcopy;
1108
-	char*  last;
1109
-	char* p;
1110
-	int size;
1111
-	int lastlen;
1112
-	int s;
1113
-	char* tmp;
1114
-	struct ip_addr addr;
1115
-	int ret;
1116
-
1117
-#ifdef HAVE_SOCKADDR_SA_LEN
1118
-	#ifndef MAX
1119
-		#define MAX(a,b) ( ((a)>(b))?(a):(b))
1120
-	#endif
1121
-#endif
1122
-	/* ipv4 or ipv6 only*/
1123
-	s=socket(family, SOCK_DGRAM, 0);
1124
-	ret=-1;
1125
-	lastlen=0;
1126
-	ifc.ifc_req=0;
1127
-	for (size=10; ; size*=2){
1128
-		ifc.ifc_len=size*sizeof(struct ifreq);
1129
-		ifc.ifc_req=(struct ifreq*) pkg_malloc(size*sizeof(struct ifreq));
1130
-		if (ifc.ifc_req==0){
1131
-			fprintf(stderr, "memory allocation failure\n");
1132
-			goto error;
1133
-		}
1134
-		if (ioctl(s, SIOCGIFCONF, &ifc)==-1){
1135
-			if(errno==EBADF) return 0; /* invalid descriptor => no such ifs*/
1136
-			fprintf(stderr, "ioctl failed: %s\n", strerror(errno));
1137
-			goto error;
1138
-		}
1139
-		if  ((lastlen) && (ifc.ifc_len==lastlen)) break; /*success,
1140
-														   len not changed*/
1141
-		lastlen=ifc.ifc_len;
1142
-		/* try a bigger array*/
1143
-		pkg_free(ifc.ifc_req);
1144
-	}
1145
-	
1146
-	last=(char*)ifc.ifc_req+ifc.ifc_len;
1147
-	for(p=(char*)ifc.ifc_req; p<last;
1148
-			p+=(sizeof(ifr.ifr_name)+
1149
-			#ifdef  HAVE_SOCKADDR_SA_LEN
1150
-				MAX(ifr.ifr_addr.sa_len, sizeof(struct sockaddr))
1151
-			#else
1152
-				( (ifr.ifr_addr.sa_family==AF_INET)?
1153
-					sizeof(struct sockaddr_in):
1154
-					((ifr.ifr_addr.sa_family==AF_INET6)?
1155
-						sizeof(struct sockaddr_in6):sizeof(struct sockaddr)) )
1156
-			#endif
1157
-				)
1158
-		)
1159
-	{
1160
-		/* copy contents into ifr structure
1161
-		 * warning: it might be longer (e.g. ipv6 address) */
1162
-		memcpy(&ifr, p, sizeof(ifr));
1163
-		if (ifr.ifr_addr.sa_family!=family){
1164
-			/*printf("strange family %d skipping...\n",
1165
-					ifr->ifr_addr.sa_family);*/
1166
-			continue;
1167
-		}
1168
-		
1169
-		/*get flags*/
1170
-		ifrcopy=ifr;
1171
-		if (ioctl(s, SIOCGIFFLAGS,  &ifrcopy)!=-1){ /* ignore errors */
1172
-			/* ignore down ifs only if listening on all of them*/
1173
-			if (if_name==0){ 
1174
-				/* if if not up, skip it*/
1175
-				if (!(ifrcopy.ifr_flags & IFF_UP)) continue;
1176
-			}
1177
-		}
1178
-		
1179
-		
1180
-		
1181
-		if ((if_name==0)||
1182
-			(strncmp(if_name, ifr.ifr_name, sizeof(ifr.ifr_name))==0)){
1183
-			
1184
-				/*add address*/
1185
-			if (sock_no<MAX_LISTEN){
1186
-				sockaddr2ip_addr(&addr, 
1187
-					(struct sockaddr*)(p+(long)&((struct ifreq*)0)->ifr_addr));
1188
-				if ((tmp=ip_addr2a(&addr))==0) goto error;
1189
-				/* fill the strings*/
1190
-				sock_info[sock_no].name.s=(char*)pkg_malloc(strlen(tmp)+1);
1191
-				if(sock_info[sock_no].name.s==0){
1192
-					fprintf(stderr, "Out of memory.\n");
1193
-					goto error;
1194
-				}
1195
-				/* fill in the new name and port */
1196
-				sock_info[sock_no].name.len=strlen(tmp);
1197
-				strncpy(sock_info[sock_no].name.s, tmp, 
1198
-							sock_info[sock_no].name.len+1);
1199
-				sock_info[sock_no].port_no=port;
1200
-				/* mark if loopback */
1201
-				if (ifrcopy.ifr_flags & IFF_LOOPBACK) 
1202
-					sock_info[sock_no].is_lo=1;
1203
-				sock_no++;
1204
-				ret=0;
1205
-			}else{
1206
-				fprintf(stderr, "Too many addresses (max %d)\n", MAX_LISTEN);
1207
-				goto error;
1208
-			}
1209
-		}
1210
-			/*
1211
-			printf("%s:\n", ifr->ifr_name);
1212
-			printf("        ");
1213
-			print_sockaddr(&(ifr->ifr_addr));
1214
-			printf("        ");
1215
-			ls_ifflags(ifr->ifr_name, family, options);
1216
-			printf("\n");*/
1217
-	}
1218
-	pkg_free(ifc.ifc_req); /*clean up*/
1219
-	close(s);
1220
-	return  ret;
1221
-error:
1222
-	if (ifc.ifc_req) pkg_free(ifc.ifc_req);
1223
-	close(s);
1224
-	return -1;
1225
-}
1226 1098
 
1227 1099
 
1228 1100
 
... ...
@@ -1230,14 +1088,9 @@ int main(int argc, char** argv)
1230 1230
 {
1231 1231
 
1232 1232
 	FILE* cfg_stream;
1233
-	struct hostent* he;
1234
-	int c,r,t;
1233
+	int c,r;
1235 1234
 	char *tmp;
1236
-	char** h;
1237
-	struct host_alias* a;
1238
-	struct utsname myname;
1239 1235
 	char *options;
1240
-	int len;
1241 1236
 	int ret;
1242 1237
 	struct passwd *pw_entry;
1243 1238
 	struct group  *gr_entry;
... ...
@@ -1287,9 +1140,7 @@ int main(int argc, char** argv)
1287 1287
 						fprintf(stderr, "bad port number: -p %s\n", optarg);
1288 1288
 						goto error;
1289 1289
 					}
1290
-					if (sock_no>0) sock_info[sock_no-1].port_no=port_no;
1291 1290
 					break;
1292
-
1293 1291
 			case 'm':
1294 1292
 					shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;
1295 1293
 					if (tmp &&(*tmp)){
... ...
@@ -1311,23 +1162,8 @@ int main(int argc, char** argv)
1311 1311
 					break;
1312 1312
 			case 'l':
1313 1313
 					/* add a new addr. to our address list */
1314
-					if (sock_no < MAX_LISTEN){
1315
-						sock_info[sock_no].name.s=
1316
-										(char*)pkg_malloc(strlen(optarg)+1);
1317
-						if (sock_info[sock_no].name.s==0){
1318
-							fprintf(stderr, "Out of memory.\n");
1319
-							goto error;
1320
-						}
1321
-						strncpy(sock_info[sock_no].name.s, optarg,
1322
-												strlen(optarg)+1);
1323
-						sock_info[sock_no].name.len=strlen(optarg);
1324
-						/* set default port */
1325
-						sock_info[sock_no].port_no=port_no;
1326
-						sock_no++;
1327
-					}else{
1328
-						fprintf(stderr, 
1329
-									"Too many addresses (max. %d).\n",
1330
-									MAX_LISTEN);
1314
+					if (add_listen_iface(optarg, 0, 0, 0)!=0){
1315
+						fprintf(stderr, "failed to add new listen address\n");
1331 1316
 						goto error;
1332 1317
 					}
1333 1318
 					break;
... ...
@@ -1534,188 +1370,23 @@ try_again:
1534 1534
 			gid=gr_entry->gr_gid;
1535 1535
 		}
1536 1536
 	}
1537
-
1538
-	if (sock_no==0) {
1539
-		/* try to get all listening ipv4 interfaces */
1540
-		if (add_interfaces(0, AF_INET, 0)==-1){
1541
-			/* if error fall back to get hostname*/
1542
-			/* get our address, only the first one */
1543
-			if (uname (&myname) <0){
1544
-				fprintf(stderr, "cannot determine hostname, try -l address\n");
1545
-				goto error;
1546
-			}
1547
-			sock_info[sock_no].name.s=
1548
-								(char*)pkg_malloc(strlen(myname.nodename)+1);
1549
-			if (sock_info[sock_no].name.s==0){
1550
-				fprintf(stderr, "Out of memory.\n");
1551
-				goto error;
1552
-			}
1553
-			sock_info[sock_no].name.len=strlen(myname.nodename);
1554
-			strncpy(sock_info[sock_no].name.s, myname.nodename,
1555
-					sock_info[sock_no].name.len+1);
1556
-			sock_no++;
1557
-		}
1558
-	}
1559
-
1560
-	/* try to change all the interface names into addresses
1561
-	 *  --ugly hack */
1562
-	for (r=0; r<sock_no;){
1563
-		if (add_interfaces(sock_info[r].name.s, AF_INET,
1564
-					sock_info[r].port_no)!=-1){
1565
-			/* success => remove current entry (shift the entire array)*/
1566
-			pkg_free(sock_info[r].name.s);
1567
-			memmove(&sock_info[r], &sock_info[r+1], 
1568
-						(sock_no-r)*sizeof(struct socket_info));
1569
-			sock_no--;
1570
-			continue;
1571
-		}
1572
-		r++;
1573
-	}
1574
-	/* get ips & fill the port numbers*/
1575
-#ifdef EXTRA_DEBUG
1576
-	printf("Listening on \n");
1577
-#endif
1578
-	for (r=0; r<sock_no;r++){
1579
-		/* fix port number, port_no should be !=0 here */
1580
-		if (sock_info[r].port_no==0) sock_info[r].port_no=port_no;
1581
-		tmp=int2str(sock_info[r].port_no, &len);
1582
-		if (len>=MAX_PORT_LEN){
1583
-			fprintf(stderr, "ERROR: bad port number: %d\n", 
1584
-						sock_info[r].port_no);
1585
-			goto error;
1586
-		}
1587
-		sock_info[r].port_no_str.s=(char*)pkg_malloc(len+1);
1588
-		if (sock_info[r].port_no_str.s==0){
1589
-			fprintf(stderr, "Out of memory.\n");
1590
-			goto error;
1591
-		}
1592
-		strncpy(sock_info[r].port_no_str.s, tmp, len+1);
1593
-		sock_info[r].port_no_str.len=len;
1594
-		
1595
-		/* get "official hostnames", all the aliases etc. */
1596
-		he=resolvehost(sock_info[r].name.s);
1597
-		if (he==0){
1598
-			DPrint("ERROR: could not resolve %s\n", sock_info[r].name.s);
1599
-			goto error;
1600
-		}
1601
-		/* check if we got the official name */
1602
-		if (strcasecmp(he->h_name, sock_info[r].name.s)!=0){
1603
-			if (add_alias(sock_info[r].name.s, sock_info[r].name.len,
1604
-							sock_info[r].port_no, 0)<0){
1605
-				LOG(L_ERR, "ERROR: main: add_alias failed\n");
1606
-			}
1607
-			/* change the oficial name */
1608
-			pkg_free(sock_info[r].name.s);
1609
-			sock_info[r].name.s=(char*)pkg_malloc(strlen(he->h_name)+1);
1610
-			if (sock_info[r].name.s==0){
1611
-				fprintf(stderr, "Out of memory.\n");
1612
-				goto error;
1613
-			}
1614
-			sock_info[r].name.len=strlen(he->h_name);
1615
-			strncpy(sock_info[r].name.s, he->h_name, sock_info[r].name.len+1);
1616
-		}
1617
-		/* add the aliases*/
1618
-		for(h=he->h_aliases; h && *h; h++)
1619
-			if (add_alias(*h, strlen(*h), sock_info[r].port_no, 0)<0){
1620
-				LOG(L_ERR, "ERROR: main: add_alias failed\n");
1621
-			}
1622
-		hostent2ip_addr(&sock_info[r].address, he, 0); /*convert to ip_addr 
1623
-														 format*/
1624
-		if ((tmp=ip_addr2a(&sock_info[r].address))==0) goto error;
1625
-		sock_info[r].address_str.s=(char*)pkg_malloc(strlen(tmp)+1);
1626
-		if (sock_info[r].address_str.s==0){
1627
-			fprintf(stderr, "Out of memory.\n");
1628
-			goto error;
1629
-		}
1630
-		strncpy(sock_info[r].address_str.s, tmp, strlen(tmp)+1);
1631
-		/* set is_ip (1 if name is an ip address, 0 otherwise) */
1632
-		sock_info[r].address_str.len=strlen(tmp);
1633
-		if 	(	(sock_info[r].address_str.len==sock_info[r].name.len)&&
1634
-				(strncasecmp(sock_info[r].address_str.s, sock_info[r].name.s,
1635
-						 sock_info[r].address_str.len)==0)
1636
-			){
1637
-				sock_info[r].is_ip=1;
1638
-				/* do rev. dns on it (for aliases)*/
1639
-				he=rev_resolvehost(&sock_info[r].address);
1640
-				if (he==0){
1641
-					DPrint("WARNING: could not rev. resolve %s\n",
1642
-							sock_info[r].name.s);
1643
-				}else{
1644
-					/* add the aliases*/
1645
-					if (add_alias(he->h_name, strlen(he->h_name),
1646
-									sock_info[r].port_no, 0)<0){
1647
-						LOG(L_ERR, "ERROR: main: add_alias failed\n");
1648
-					}
1649
-					for(h=he->h_aliases; h && *h; h++)
1650
-						if (add_alias(*h,strlen(*h),sock_info[r].port_no,0)<0){
1651
-							LOG(L_ERR, "ERROR: main: add_alias failed\n");
1652
-						}
1653
-				}
1654
-		}else{ sock_info[r].is_ip=0; };
1655
-			
1656
-#ifdef EXTRA_DEBUG
1657
-		printf("              %.*s [%s]:%s\n", sock_info[r].name.len, 
1658
-				sock_info[r].name.s,
1659
-				sock_info[r].address_str.s, sock_info[r].port_no_str.s);
1660
-#endif
1661
-	}
1662
-	/* removing duplicate addresses*/
1663
-	for (r=0; r<sock_no; r++){
1664
-		for (t=r+1; t<sock_no;){
1665
-			if ((sock_info[r].port_no==sock_info[t].port_no) &&
1666
-				(sock_info[r].address.af==sock_info[t].address.af) &&
1667
-				(memcmp(sock_info[r].address.u.addr, 
1668
-						sock_info[t].address.u.addr,
1669
-						sock_info[r].address.len)  == 0)
1670
-				){
1671
-#ifdef EXTRA_DEBUG
1672
-				printf("removing duplicate (%d) %s [%s] == (%d) %s [%s]\n",
1673
-						r, sock_info[r].name.s, sock_info[r].address_str.s,
1674
-						t, sock_info[t].name.s, sock_info[t].address_str.s);
1675
-#endif
1676
-				/* add the name to the alias list*/
1677
-				if ((!sock_info[t].is_ip) && (
1678
-						(sock_info[t].name.len!=sock_info[r].name.len)||
1679
-						(strncmp(sock_info[t].name.s, sock_info[r].name.s,
1680
-								 sock_info[r].name.len)!=0))
1681
-					)
1682
-					add_alias(sock_info[t].name.s, sock_info[t].name.len,
1683
-								sock_info[t].port_no, 0);
1684
-						
1685
-				/* free space*/
1686
-				pkg_free(sock_info[t].name.s);
1687
-				pkg_free(sock_info[t].address_str.s);
1688
-				pkg_free(sock_info[t].port_no_str.s);
1689
-				/* shift the array*/
1690
-				memmove(&sock_info[t], &sock_info[t+1], 
1691
-							(sock_no-t)*sizeof(struct socket_info));
1692
-				sock_no--;
1693
-				continue;
1694
-			}
1695
-			t++;
1696
-		}
1537
+	
1538
+	if (fix_all_socket_lists()!=0){
1539
+		fprintf(stderr,  "failed to initialize liste addresses\n");
1540
+		goto error;
1697 1541
 	}
1698 1542
 	/* print all the listen addresses */
1699 1543
 	printf("Listening on \n");
1700
-	for (r=0; r<sock_no; r++)
1701
-		printf("              %s [%s]:%s\n",sock_info[r].name.s,
1702
-				sock_info[r].address_str.s, sock_info[r].port_no_str.s);
1703
-
1704
-	printf("Aliases: ");
1705
-	for(a=aliases; a; a=a->next) 
1706
-		if (a->port)
1707
-			printf("%.*s:%d ", a->alias.len, a->alias.s, a->port);
1708
-		else
1709
-			printf("%.*s:* ", a->alias.len, a->alias.s);
1544
+	print_all_socket_lists();
1545
+	printf("Aliases: \n");
1546
+	/*print_aliases();*/
1547
+	print_aliases();
1710 1548
 	printf("\n");
1711
-	if (sock_no==0){
1712
-		fprintf(stderr, "ERROR: no listening sockets");
1713
-		goto error;
1714
-	}
1549
+	
1715 1550
 	if (dont_fork){
1716 1551
 		fprintf(stderr, "WARNING: no fork mode %s\n", 
1717
-				(sock_no>1)?" and more than one listen address found (will"
1718
-							" use only the the first one)":"");
1552
+				(udp_listen->next)?" and more than one listen address found"
1553
+				"(will use only the the first one)":"");
1719 1554
 	}
1720 1555
 	if (config_check){
1721 1556
 		fprintf(stderr, "config file ok, exiting...\n");
... ...
@@ -123,9 +123,9 @@
123 123
 #	include <stdlib.h>
124 124
 #	define pkg_malloc(s) \
125 125
 	(  { void *v; v=malloc((s)); \
126
-	   DBG("malloc %x size %d end %x\n", v, s, (unsigned int)v+(s));\
126
+	   DBG("malloc %p size %d end %p\n", v, s, (char*)v+(s));\
127 127
 	   v; } )
128
-#	define pkg_free(p)  do{ DBG("free %x\n", (p)); free((p)); }while(0);
128
+#	define pkg_free(p)  do{ DBG("free %p\n", (p)); free((p)); }while(0);
129 129
 #	define pkg_status()
130 130
 #endif
131 131
 
... ...
@@ -28,13 +28,15 @@
28 28
  *
29 29
  * History:
30 30
  * ----------
31
- * 2003-04-09 Created by janakj
31
+ *  2003-04-09  Created by janakj
32
+ *  2003-10-24  updated to the new socket_info lists (andrei)
32 33
  */
33 34
 
34 35
 #include <stdio.h>
35 36
 #include <stdlib.h>
36 37
 #include "../../dprint.h"
37 38
 #include "../../pt.h"
39
+#include "../../socket_info.h"
38 40
 #include "callid.h"
39 41
 
40 42
 #define CALLID_NR_LEN 20
... ...
@@ -106,12 +108,21 @@ int init_callid(void)
106 106
  */
107 107
 int child_init_callid(int rank) 
108 108
 {
109
+	struct socket_info *si;
110
+	
111
+	/* on tcp/tls bind_address is 0 so try to get the first address we listen
112
+	 * on no matter the protocol */
113
+	si=bind_address?bind_address:get_first_socket();
114
+	if (si==0){
115
+		LOG(L_CRIT, "BUG: child_init_callid: null socket list\n");
116
+		return -1;
117
+	}
109 118
 	callid_suffix.s = callid_buf + callid_prefix.len;
110 119
 
111 120
 	callid_suffix.len = snprintf(callid_suffix.s, CALLID_SUFFIX_LEN,
112 121
 				     "%c%d@%.*s", CID_SEP, my_pid(), 
113
-				     sock_info[bind_idx].address_str.len,
114
-				     sock_info[bind_idx].address_str.s);
122
+				     si->address_str.len,
123
+				     si->address_str.s);
115 124
 	if ((callid_suffix.len == -1) || (callid_suffix.len > CALLID_SUFFIX_LEN)) {
116 125
 		LOG(L_ERR, "ERROR: child_init_callid: buffer too small\n");
117 126
 		return -1;
... ...
@@ -44,6 +44,7 @@
44 44
  *  2003-04-02  port_no_str does not contain a leading ':' anymore (andrei)
45 45
  *  2003-07-08  appropriate log messages in check_params(...), 
46 46
  *               call calculate_hooks if next_hop==NULL in t_uac (dcm) 
47
+ *  2003-10-24  updated to the new socket_info lists (andrei)
47 48
  */
48 49
 
49 50
 #include <string.h>
... ...
@@ -53,6 +54,7 @@
53 53
 #include "../../md5.h"
54 54
 #include "../../crc.h"
55 55
 #include "../../ip_addr.h"
56
+#include "../../socket_info.h"
56 57
 #include "ut.h"
57 58
 #include "h_table.h"
58 59
 #include "t_hooks.h"
... ...
@@ -75,18 +77,26 @@ char* uac_from = "sip:foo@foo.bar"; /* Module parameter */
75 75
 int uac_init(void) 
76 76
 {
77 77
 	str src[3];
78
+	struct socket_info *si;
78 79
 
79 80
 	if (RAND_MAX < TABLE_ENTRIES) {
80 81
 		LOG(L_WARN, "Warning: uac does not spread "
81 82
 		    "accross the whole hash table\n");
82 83
 	}
84
+	/* on tcp/tls bind_address is 0 so try to get the first address we listen
85
+	 * on no matter the protocol */
86
+	si=bind_address?bind_address:get_first_socket();
87
+	if (si==0){
88
+		LOG(L_CRIT, "BUG: child_init_callid: null socket list\n");
89
+		return -1;
90
+	}
83 91
 
84 92
 	/* calculate the initial From tag */
85 93
 	src[0].s = "Long live SER server";
86 94
 	src[0].len = strlen(src[0].s);
87
-	src[1].s = sock_info[bind_idx].address_str.s;
95
+	src[1].s = si->address_str.s;
88 96
 	src[1].len = strlen(src[1].s);
89
-	src[2].s = sock_info[bind_idx].port_no_str.s;
97
+	src[2].s = si->port_no_str.s;
90 98
 	src[2].len = strlen(src[2].s);
91 99
 
92 100
 	MDStringArray(from_tag, src, 3);
... ...
@@ -43,6 +43,7 @@
43 43
 
44 44
 #include "globals.h"
45 45
 #include "timer.h"
46
+#include "socket_info.h"
46 47
 
47 48
 #define MAX_PT_DESC	128
48 49
 
... ...
@@ -63,9 +64,13 @@ extern int process_no;
63 63
 */
64 64
 inline static int process_count()
65 65
 {
66
+	int udp_listeners;
67
+	struct socket_info* si;
68
+	
69
+	for (si=udp_listen, udp_listeners=0; si; si=si->next, udp_listeners++);
66 70
     return 
67 71
 		/* receivers and attendant */
68
-		(dont_fork ? 1 : children_no*sock_no + 1)
72
+		(dont_fork ? 1 : children_no*udp_listeners + 1)
69 73
 		/* timer process */
70 74
 		+ (timer_list ? 1 : 0 )
71 75
 		/* fifo server */
... ...
@@ -284,8 +284,10 @@ static inline struct hostent* resolvehost(char* name)
284 284
 	static struct hostent* he2=0;
285 285
 #endif
286 286
 #ifndef DNS_IP_HACK
287
+#ifdef USE_IPV6
287 288
 	int len;
288 289
 #endif
290
+#endif
289 291
 #ifdef DNS_IP_HACK
290 292
 	struct ip_addr* ip;
291 293
 	str s;
... ...
@@ -304,6 +306,7 @@ static inline struct hostent* resolvehost(char* name)
304 304
 	}
305 305
 	
306 306
 #else /* DNS_IP_HACK */
307
+#ifdef USE_IPV6
307 308
 	len=0;
308 309
 	if (*name=='['){
309 310
 		len=strlen(name);
... ...
@@ -314,6 +317,7 @@ static inline struct hostent* resolvehost(char* name)
314 314
 		}
315 315
 	}
316 316
 #endif
317
+#endif
317 318
 	/* ipv4 */
318 319
 	he=gethostbyname(name);
319 320
 #ifdef USE_IPV6
... ...
@@ -48,6 +48,7 @@
48 48
 #include "globals.h"
49 49
 #include "crc.h"
50 50
 #include "str.h"
51
+#include "socket_info.h"
51 52
 
52 53
 #define TOTAG_VALUE_LEN (MD5_LEN+CRC16_LEN+1)
53 54
 
... ...
@@ -71,12 +72,15 @@ static void inline init_tags( char *tag, char **suffix,
71 71
 		char *signature, char separator )
72 72
 {
73 73
 	str src[3];
74
-
74
+	struct socket_info* si;
75
+	
76
+	si=get_first_socket();
75 77
 	src[0].s=signature; src[0].len=strlen(signature);
76
-	src[1].s=sock_info[0].address_str.s;
77
-	src[1].len=sock_info[0].address_str.len;
78
-	src[2].s=sock_info[0].port_no_str.s;
79
-	src[2].len=sock_info[0].port_no_str.len;
78
+	/* if we are not listening on anything we shouldn't be here */
79
+	src[1].s=si?si->address_str.s:"";
80
+	src[1].len=si?si->address_str.len:0;
81
+	src[2].s=si?si->port_no_str.s:"";
82
+	src[2].len=si?si->port_no_str.len:0;
80 83
 
81 84
 	MDStringArray( tag, src, 3 );
82 85
 
... ...
@@ -42,6 +42,7 @@
42 42
  *  2003-06-30  moved tcp new connect checking & handling to
43 43
  *               handle_new_connect (andrei)
44 44
  *  2003-07-09  tls_close called before closing the tcp connection (andrei)
45
+ *  2003-10-24  converted to the new socket_info lists (andrei)
45 46
  */
46 47
 
47 48
 
... ...
@@ -181,14 +182,14 @@ error:
181 181
 
182 182
 struct socket_info* find_tcp_si(union sockaddr_union* s)
183 183
 {
184
-	int r;
185 184
 	struct ip_addr ip;
185
+	struct socket_info* si;
186 186
 	
187 187
 	su2ip_addr(&ip, s);
188
-	for (r=0; r<sock_no; r++)
189
-		if (ip_addr_cmp(&ip, &tcp_info[r].address)){
188
+	for (si=tcp_listen; si; si=si->next)
189
+		if (ip_addr_cmp(&ip, &si->address)){
190 190
 			/* found it, we use first match */
191
-			return &tcp_info[r];
191
+			return si;
192 192
 		}
193 193
 	return 0; /* no match */
194 194
 }
... ...
@@ -728,24 +729,31 @@ void tcp_main_loop()
728 728
 	int bytes;
729 729
 	struct timeval timeout;
730 730
 	int fd;
731
+	struct socket_info* si;
731 732
 
732 733
 	/*init */
733 734
 	maxfd=0;
734 735
 	FD_ZERO(&master_set);
735 736
 	/* set all the listen addresses */
736
-	for (r=0; r<sock_no; r++){
737
-		if ((tcp_info[r].proto==PROTO_TCP) &&(tcp_info[r].socket!=-1)){
738
-			FD_SET(tcp_info[r].socket, &master_set);
739
-			if (tcp_info[r].socket>maxfd) maxfd=tcp_info[r].socket;
737
+	for (si=tcp_listen; si; si=si->next){
738
+		if ((si->proto==PROTO_TCP) &&(si->socket!=-1)){
739
+			FD_SET(si->socket, &master_set);
740
+			if (si->socket>maxfd) maxfd=si->socket;
741
+		}else{
742
+			LOG(L_CRIT, "BUG: tcp_main_loop: non tcp address in tcp_listen\n");
740 743
 		}
744
+	}
741 745
 #ifdef USE_TLS
742
-		if ((!tls_disable)&&(tls_info[r].proto==PROTO_TLS) &&
743
-				(tls_info[r].socket!=-1)){
744
-			FD_SET(tls_info[r].socket, &master_set);
745
-			if (tls_info[r].socket>maxfd) maxfd=tls_info[r].socket;
746
+	if (!tls_disable){
747
+		for (si=tls_listen; si; si=si->next){
748
+			if ((si->proto==PROTO_TLS) && (si->socket!=-1)){
749
+				FD_SET(si->socket, &master_set);
750
+				if (si->socket>maxfd) maxfd=si->socket;
751
+			}else{
752
+			LOG(L_CRIT, "BUG: tcp_main_loop: non tls address in tls_listen\n");
746 753
 		}
747
-#endif
748 754
 	}
755
+#endif
749 756
 	/* set all the unix sockets used for child comm */
750 757
 	for (r=1; r<process_no; r++){
751 758
 		if (pt[r].unix_sock>0){ /* we can't have 0, we never close it!*/
... ...
@@ -770,13 +778,13 @@ void tcp_main_loop()
770 770
 			n=0;
771 771
 		}
772 772
 		
773
-		for (r=0; r<sock_no && n; r++){
774
-			handle_new_connect(&tcp_info[r], &sel_set, &n);
773
+		for (si=tcp_listen; si && n; si=si->next)
774
+			handle_new_connect(si, &sel_set, &n);
775 775
 #ifdef USE_TLS
776 776
 			if (!tls_disable)
777
-				handle_new_connect(&tls_info[r], &sel_set, &n);
777
+				for (si=tls_listen; si && n; si=si->next)
778
+					handle_new_connect(si, &sel_set, &n);
778 779
 #endif
779
-		}
780 780
 		
781 781
 		/* check all the read fds (from the tcpconn_addr_hash ) */
782 782
 		for (h=0; h<TCP_ADDR_HASH_SIZE; h++){
... ...
@@ -1063,7 +1071,6 @@ int tcp_init_children()
1063 1063
 			unix_tcp_sock=sockfd[1];
1064 1064
 			bind_address=0; /* force a SEGFAULT if someone uses a non-init.
1065 1065
 							   bind address on tcp */
1066
-			bind_idx=0;
1067 1066
 			if (init_child(r+children_no+1) < 0) {
1068 1067
 				LOG(L_ERR, "init_children failed\n");
1069 1068
 				goto error;
... ...
@@ -1,29 +1,41 @@
1
-debug=9          # debug level (cmd line: -dddddddddd)
2
-check_via=1      # (cmd. line: -v)
3
-dns=on           # (cmd. line: -r)
4
-rev_dns=yes      # (cmd. line: -R)
5
-fork=no          # (cmd. line: -D)
6
-log_stderror=yes # (cmd line: -E)
7
-# for more info: sip_router -h
1
+#
2
+# configuration for stress testing
3
+#
4
+# $ID: $
5
+#
8 6
 
9
-route{
10 7
 
11
-	(src_ip=~'(dorian)|(ekina)|(terix)' & method=~'^inv') \
12
-				forward(centauri.fokus.gmd.de);
13
-	src_ip=~"^192\.168\.[0-9]{1,3}\.[0-9]{1,3}$"  \
14
-				log(1,"msg. from a private network\n"); route(1);
15
-	src_ip==0.0.0.0/0   setuserpass("andrei:test"); log(1, " test msg\n"); forward(192.168.46.55);setuser("foo");sethostport("bar.com:6000");forward(192.168.46.69);drop;
16
-}
8
+#debug=9          # debug level (cmd line: -dddddddddd)
9
+#fork=yes          # (cmd. line: -D)
10
+#log_stderror=yes # (cmd line: -E)
11
+#log_stderror=no	# (cmd line: -E)
17 12
 
18
-route[1]{
19
-	src_ip==192.168.46.61  log("possible loop, dropping\n"); drop;
20
-	(src_ip==192.168.46.0/24) log("routing with rt2\n");route(2); log("we're back\n");
21
-	src_ip==0.0.0.0/0 log(1, "we'll drop this one too\n"); drop;
22
-}
23 13
 
24
-route[2]{
25
-	(method=~'^ACK' and uri=~'.*fokus') forward("fox.iptel.org");
26
-	! method=~'^INV' forward(193.175.135.179); /* dorian */
27
-	method=~'.' log("spying...\n"); send(dorian,8000); \
28
-						forward("fox.iptel.org");
14
+#children=2
15
+check_via=no     # (cmd. line: -v)
16
+dns=off           # (cmd. line: -r)
17
+rev_dns=off      # (cmd. line: -R)
18
+#port=5070
19
+#listen=10.0.0.179 lo	dorian
20
+#listen=eth0
21
+#listen=127.0.0.1
22
+#listen=192.168.57.33
23
+#listen=192.168.57.72
24
+#loop_checks=0
25
+# for more info: sip_router -h
26
+alias=iptel.org
27
+alias="foo.bar"
28
+fifo="/tmp/ser_fifo"
29
+listen= tcp:10.0.0.179:5065
30
+alias=  tcp:all:5065
31
+
32
+#modules
33
+
34
+
35
+route{
36
+	if (myself==uri){
37
+		log("\n\nfrom myself\n\n");
38
+	};
39
+	log(" continue \n\n");
40
+	forward(uri:host, uri:port);
29 41
 }