Browse Source

- sock_lists completely re-organized

Andrei Pelinescu-Onciul 22 years ago
parent
commit
9f4c52ce6c
15 changed files with 274 additions and 559 deletions
  1. 1 1
      Makefile.defs
  2. 3 0
      TODO
  3. 15 28
      cfg.y
  4. 84 78
      forward.c
  5. 0 9
      globals.h
  6. 6 2
      ip_addr.h
  7. 57 386
      main.c
  8. 2 2
      mem/mem.h
  9. 14 3
      modules/tm/callid.c
  10. 12 2
      modules/tm/uac.c
  11. 6 1
      pt.h
  12. 4 0
      resolve.h
  13. 9 5
      tags.h
  14. 25 18
      tcp_main.c
  15. 36 24
      test/test.cfg

+ 1 - 1
Makefile.defs

@@ -43,7 +43,7 @@ export makefile_defs
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   12
-EXTRAVERSION = dev-20-lumps
+EXTRAVERSION = dev-21-sock_info
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 3 - 0
TODO

@@ -4,7 +4,10 @@ $Id$
 
 - fix aliases for tls_port (add_them?)
 - fix check_sel_op -- add proto for uri proto checks
+- add via alias for tcp port & infinite tcp conn life
 
+- fix 2 different fixups for diff. no of parameter
+ (add no of params ot struct action?) -- linked to var. no. of params
 - alias support fot tcp/tls port numbers
 - warning builder set_advertised address support
 - grep parse_uri & replace with parse_sip_msg_uri (e.g do_action!)

+ 15 - 28
cfg.y

@@ -47,6 +47,7 @@
  *             added msg:len (andrei)
  * 2003-10-11  if(){} doesn't require a ';' after it anymore (andrei)
  * 2003-10-13  added FIFO_DIR & proto:host:port listen/alias support (andrei)
+ * 2003-10-24  converted to the new socket_info lists (andrei)
  */
 
 
@@ -67,9 +68,11 @@
 #include "sr_module.h"
 #include "modparam.h"
 #include "ip_addr.h"
+#include "socket_info.h"
 #include "name_alias.h"
 #include "ut.h"
 
+
 #include "config.h"
 #ifdef USE_TLS
 #include "tls/tls_config.h"
@@ -84,7 +87,7 @@
 #undef _ALLOCA_H
 
 struct id_list{
-	char* s;
+	char* name;
 	int proto;
 	int port;
 	struct id_list* next;
@@ -327,6 +330,7 @@ listen_id:	ip			{	tmp=ip_addr2a($1);
 proto:	  UDP	{ $$=PROTO_UDP; }
 		| TCP	{ $$=PROTO_TCP; }
 		| TLS	{ $$=PROTO_TLS; }
+		| STAR	{ $$=0; }
 		;
 
 port:	  NUMBER	{ $$=$1; }
@@ -355,10 +359,7 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 		| DNS EQUAL error { yyerror("boolean value expected"); }
 		| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
 		| REV_DNS EQUAL error { yyerror("boolean value expected"); }
-		| PORT EQUAL NUMBER   { port_no=$3; 
-								if (sock_no>0) 
-									sock_info[sock_no-1].port_no=port_no;
-							  }
+		| PORT EQUAL NUMBER   { port_no=$3; }
 		| STAT EQUAL STRING {
 					#ifdef STATS
 							stat_file=$3;
@@ -521,27 +522,13 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 		| REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); }
 		| LISTEN EQUAL id_lst {
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
-								if (sock_no < MAX_LISTEN){
-									sock_info[sock_no].name.s=(char*)
-											pkg_malloc(strlen(lst_tmp->s)+1);
-									if (sock_info[sock_no].name.s==0){
-										LOG(L_CRIT, "ERROR: cfg. parser:"
-													" out of memory.\n");
-										break;
-									}else{
-										strncpy(sock_info[sock_no].name.s,
-												lst_tmp->s,
-												strlen(lst_tmp->s)+1);
-										sock_info[sock_no].name.len=
-													strlen(lst_tmp->s);
-										sock_info[sock_no].port_no=
-													lst_tmp->port;
-										sock_no++;
-									}
-								}else{
-									LOG(L_CRIT, "ERROR: cfg. parser: "
-												"too many listen addresses"
-												"(max. %d).\n", MAX_LISTEN);
+								if (add_listen_iface(	lst_tmp->name,
+														lst_tmp->port,
+														lst_tmp->proto,
+														0
+													)!=0){
+									LOG(L_CRIT,  "ERROR: cfg. parser: failed"
+											" to add listen address\n");
 									break;
 								}
 							}
@@ -550,7 +537,7 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 						"expected"); }
 		| ALIAS EQUAL  id_lst { 
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
-								add_alias(lst_tmp->s, strlen(lst_tmp->s), 
+								add_alias(lst_tmp->name, strlen(lst_tmp->name),
 											lst_tmp->port, lst_tmp->proto);
 							  }
 		| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
@@ -1509,7 +1496,7 @@ static struct id_list* mk_listen_id(char* host, int proto, int port)
 	if (l==0){
 		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
 	}else{
-		l->s=host;
+		l->name=host;
 		l->port=port;
 		l->proto=proto;
 		l->next=0;

+ 84 - 78
forward.c

@@ -43,6 +43,7 @@
  *               local replies (andrei)
  *  2003-08-21  check_self properly handles ipv6 addresses & refs   (andrei)
  *  2003-10-21  check_self updated to handle proto (andrei)
+ *  2003-10-24  converted to the new socket_info lists (andrei)
  */
 
 
@@ -71,6 +72,7 @@
 #include "ip_addr.h"
 #include "resolve.h"
 #include "name_alias.h"
+#include "socket_info.h"
 
 #ifdef DEBUG_DMALLOC
 #include <dmalloc.h>
@@ -87,15 +89,14 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto)
 {
 	int temp_sock;
 	socklen_t len;
-	int r;
 	union sockaddr_union from; 
+	struct socket_info* si;
 
 	if (proto!=PROTO_UDP) {
 		LOG(L_CRIT, "BUG: get_out_socket can only be called for UDP\n");
 		return 0;
 	}
-
-	r=-1;
+	
 	temp_sock=socket(to->s.sa_family, SOCK_DGRAM, 0 );
 	if (temp_sock==-1) {
 		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)
 				strerror(errno));
 		goto error;
 	}
-	for (r=0; r<sock_no; r++) {
+	for (si=udp_listen; si; si=si->next) {
 		switch(from.s.sa_family) {
 			case AF_INET:	
-						if (sock_info[r].address.af!=AF_INET)
+						if (si->address.af!=AF_INET)
 								continue;
-						if (memcmp(&sock_info[r].address.u,
+						if (memcmp(&si->address.u,
 								&from.sin.sin_addr, 
-								sock_info[r].address.len)==0)
-							goto error; /* it is actually success */
+								si->address.len)==0)
+							goto found; /*  success */
 						break;
 #if defined(USE_IPV6)
 			case AF_INET6:	
-						if (sock_info[r].address.af!=AF_INET6)
+						if (si->address.af!=AF_INET6)
 								continue;
-						if (memcmp(&sock_info[r].address.u,
+						if (memcmp(&si->address.u,
 								&from.sin6.sin6_addr, len)==0)
-							goto error;
+							goto found;
 						continue;
 #endif
 			default:	LOG(L_ERR, "ERROR: get_out_socket: "
 									"unknown family: %d\n",
 									from.s.sa_family);
-						r=-1;
 						goto error;
 		}
 	}
-	LOG(L_ERR, "ERROR: get_out_socket: no socket found\n");
-	r=-1;
 error:
+	LOG(L_ERR, "ERROR: get_out_socket: no socket found\n");
+	close(temp_sock);
+	return 0;
+found:
 	close(temp_sock);
-	DBG("DEBUG: get_out_socket: socket determined: %d\n", r );
-	return r==-1? 0: &sock_info[r];
+	DBG("DEBUG: get_out_socket: socket determined: %p\n", si );
+	return si;
 }
 
 
@@ -228,10 +230,10 @@ struct socket_info* get_send_socket(union sockaddr_union* to, int proto)
  */
 int check_self(str* host, unsigned short port, unsigned short proto)
 {
-	int r;
 	char* hname;
 	int h_len;
 	struct socket_info* si;
+	unsigned short c_proto;
 #ifdef USE_IPV6
 	struct ip_addr* ip6;
 #endif
@@ -245,76 +247,80 @@ int check_self(str* host, unsigned short port, unsigned short proto)
 		h_len-=2;
 	}
 #endif
-	/* get teh proper sock list */
-	switch(proto){
-		case PROTO_NONE: /* we'll use udp and not all the lists FIXME: */
-		case PROTO_UDP:
-			si=sock_info;
-			break;
+	c_proto=proto?proto:PROTO_UDP;
+	do{
+		/* get the proper sock list */
+		switch(c_proto){
+			case PROTO_NONE: /* we'll use udp and not all the lists FIXME: */
+			case PROTO_UDP:
+				si=udp_listen;
+				break;
 #ifdef USE_TCP
-		case PROTO_TCP:
-			si=tcp_info;
-			break;
+			case PROTO_TCP:
+				si=tcp_listen;
+				break;
 #endif
 #ifdef USE_TLS
-		case PROTO_TLS:
-			si=tls_info;
-			break;
+			case PROTO_TLS:
+				si=tls_listen;
+				break;
 #endif
-		default:
-			/* unknown proto */
-			LOG(L_WARN, "WARNING: check_self: unknown proto %d\n", proto);
-			return 0; /* false */
-	}
-	for (r=0; r<sock_no; r++){
-		DBG("check_self - checking if host==us: %d==%d && "
-				" [%.*s] == [%.*s]\n", 
-					h_len,
-					si[r].name.len,
-					h_len, hname,
-					si[r].name.len, si[r].name.s
-			);
-		if (port) {
-			DBG("check_self - checking if port %d matches port %d\n", 
-					si[r].port_no, port);
-			if (si[r].port_no!=port) {
-				continue;
-			}
+			default:
+				/* unknown proto */
+				LOG(L_WARN, "WARNING: check_self: "
+							"unknown proto %d\n", c_proto);
+				return 0; /* false */
 		}
-		if ( (h_len==sock_info[r].name.len) && 
-			(strncasecmp(hname, sock_info[r].name.s,
-				     sock_info[r].name.len)==0) /*slower*/)
-			/* comp. must be case insensitive, host names
-			 * can be written in mixed case, it will also match
-			 * ipv6 addresses if we are lucky*/
-			break;
-	/* check if host == ip address */
+		for (; si; si=si->next){
+			DBG("check_self - checking if host==us: %d==%d && "
+					" [%.*s] == [%.*s]\n", 
+						h_len,
+						si->name.len,
+						h_len, hname,
+						si->name.len, si->name.s
+				);
+			if (port) {
+				DBG("check_self - checking if port %d matches port %d\n", 
+						si->port_no, port);
+				if (si->port_no!=port) {
+					continue;
+				}
+			}
+			if ( (h_len==si->name.len) && 
+				(strncasecmp(hname, si->name.s,
+						 si->name.len)==0) /*slower*/)
+				/* comp. must be case insensitive, host names
+				 * can be written in mixed case, it will also match
+				 * ipv6 addresses if we are lucky*/
+				goto found;
+		/* check if host == ip address */
 #ifdef USE_IPV6
-		/* ipv6 case is uglier, host can be [3ffe::1] */
-		ip6=str2ip6(host);
-		if (ip6){
-			if (ip_addr_cmp(ip6, &sock_info[r].address))
-				break; /* match */
-			else
-				continue; /* no match, but this is an ipv6 address
-							 so no point in trying ipv4 */
-		}
+			/* ipv6 case is uglier, host can be [3ffe::1] */
+			ip6=str2ip6(host);
+			if (ip6){
+				if (ip_addr_cmp(ip6, &si->address))
+					goto found; /* match */
+				else
+					continue; /* no match, but this is an ipv6 address
+								 so no point in trying ipv4 */
+			}
 #endif
-		/* ipv4 */
-		if ( 	(!sock_info[r].is_ip) &&
-				(h_len==sock_info[r].address_str.len) && 
-			(memcmp(hname, sock_info[r].address_str.s, 
-								sock_info[r].address_str.len)==0)
-			)
-			break;
-	}
-	if (r==sock_no){
-		/* try to look into the aliases*/
-		if (grep_aliases(hname, h_len, port, proto)==0){
-			DBG("check_self: host != me\n");
-			return 0;
+			/* ipv4 */
+			if ( 	(!(si->flags&SI_IS_IP)) &&
+					(h_len==si->address_str.len) && 
+				(memcmp(hname, si->address_str.s, 
+									si->address_str.len)==0)
+				)
+				goto found;
 		}
+	}while( (proto==0) && (c_proto=next_proto(c_proto)) );
+	
+	/* try to look into the aliases*/
+	if (grep_aliases(hname, h_len, port, proto)==0){
+		DBG("check_self: host != me\n");
+		return 0;
 	}
+found:
 	return 1;
 }
 

+ 0 - 9
globals.h

@@ -46,19 +46,10 @@
 extern char * cfg_file;
 extern int config_check;
 extern char *stat_file;
-extern struct socket_info sock_info[]; /* all addresses we listen/send from*/
-#ifdef USE_TCP
-extern struct socket_info tcp_info[]; /* all tcp sockets we listen on*/
-#endif
-#ifdef USE_TLS
-extern struct socket_info tls_info[]; /* tcp-tls sockets */
-#endif
-extern int sock_no; /* number of addresses/open sockets*/
 extern unsigned short port_no;
 
 extern struct socket_info* bind_address; /* pointer to the crt. proc.
 											listening address */
-extern int bind_idx; /* same as above but index in the bound[] array */
 extern struct socket_info* sendipv4; /* ipv4 socket to use when msg.
 										comes from ipv6*/
 extern struct socket_info* sendipv6; /* same as above for ipv6 */

+ 6 - 2
ip_addr.h

@@ -77,6 +77,9 @@ union sockaddr_union{
 };
 
 
+
+enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2 };
+
 struct socket_info{
 	int socket;
 	str name; /* name - eg.: foo.bar or 10.0.0.1 */
@@ -84,10 +87,11 @@ struct socket_info{
 	str address_str;        /* ip address converted to string -- optimization*/
 	unsigned short port_no;  /* port number */
 	str port_no_str; /* port number converted to string -- optimization*/
-	int is_ip; /* 1 if name is an ip address, 0 if not  -- optimization*/
-	int is_lo; /* 1 if is a loopback, 0 if not */
+	enum si_flags flags; /* SI_IS_IP | SI_IS_LO */
 	union sockaddr_union su; 
 	int proto; /* tcp or udp*/
+	struct socket_info* next;
+	struct socket_info* prev;
 };
 
 

+ 57 - 386
main.c

@@ -44,6 +44,7 @@
  *                see comment above it for explanations. (andrei)
  *  2003-06-29  replaced port_no_str snprintf w/ int2str (andrei)
  *  2003-10-10  added switch for config check (-c) (andrei)
+ *  2003-10-24  converted to the new socket_info lists (andrei)
  *
  */
 
@@ -330,17 +331,15 @@ int names_len[MAX_LISTEN];            /* lengths of the names*/
 struct ip_addr addresses[MAX_LISTEN]; /* our ips */
 int addresses_no=0;                   /* number of names/ips */
 #endif
-struct socket_info sock_info[MAX_LISTEN];/*all addresses we listen/send from*/
+struct socket_info* udp_listen=0;
 #ifdef USE_TCP
-struct socket_info tcp_info[MAX_LISTEN];/*all tcp addresses we listen on*/
+struct socket_info* tcp_listen=0;
 #endif
 #ifdef USE_TLS
-struct socket_info tls_info[MAX_LISTEN]; /* all tls addresses we listen on*/
+struct socket_info* tls_listen=0;
 #endif
-int sock_no=0; /* number of addresses/open sockets*/
 struct socket_info* bind_address=0; /* pointer to the crt. proc.
 									 listening address*/
-int bind_idx; /* same as above but index in the bound[] array */
 struct socket_info* sendipv4; /* ipv4 socket to use when msg. comes from ipv6*/
 struct socket_info* sendipv6; /* same as above for ipv6 */
 #ifdef USE_TCP
@@ -754,8 +753,9 @@ error:
 /* main loop */
 int main_loop()
 {
-	int r, i;
+	int  i;
 	pid_t pid;
+	struct socket_info* si;
 #ifdef USE_TCP
 	int sockfd[2];
 #endif
@@ -773,12 +773,11 @@ int main_loop()
 		setstats( 0 );
 #endif
 		/* only one address, we ignore all the others */
-		if (udp_init(&sock_info[0])==-1) goto error;
-		bind_address=&sock_info[0];
+		if (udp_init(udp_listen)==-1) goto error;
+		bind_address=udp_listen;
 		sendipv4=bind_address;
 		sendipv6=bind_address; /*FIXME*/
-		bind_idx=0;
-		if (sock_no>1){
+		if (udp_listen->next){
 			LOG(L_WARN, "WARNING: using only the first listen address"
 						" (no fork)\n");
 		}
@@ -853,66 +852,55 @@ int main_loop()
 		/* process_no now initialized to zero -- increase from now on
 		   as new processes are forked (while skipping 0 reserved for main )
 		*/
-		for(r=0;r<sock_no;r++){
+		for(si=udp_listen;si;si=si->next){
 			/* create the listening socket (for each address)*/
 			/* udp */
-			if (udp_init(&sock_info[r])==-1) goto error;
+			if (udp_init(si)==-1) goto error;
 			/* get first ipv4/ipv6 socket*/
-			if ((sock_info[r].address.af==AF_INET)&&
-					((sendipv4==0)||(sendipv4->is_lo)))
-				sendipv4=&sock_info[r];
+			if ((si->address.af==AF_INET)&&
+					((sendipv4==0)||(sendipv4->flags&SI_IS_LO)))
+				sendipv4=si;
 	#ifdef USE_IPV6
-			if((sendipv6==0)&&(sock_info[r].address.af==AF_INET6))
-				sendipv6=&sock_info[r];
+			if((sendipv6==0)&&(si->address.af==AF_INET6))
+				sendipv6=si;
 	#endif
+		}
 #ifdef USE_TCP
-			if (!tcp_disable){
-				tcp_info[r]=sock_info[r]; /* copy the sockets */
+		if (!tcp_disable){
+			for(si=tcp_listen; si; si=si->next){
 				/* same thing for tcp */
-				if (tcp_init(&tcp_info[r])==-1)  goto error;
+				if (tcp_init(si)==-1)  goto error;
 				/* get first ipv4/ipv6 socket*/
-				if ((tcp_info[r].address.af==AF_INET)&&
-						((sendipv4_tcp==0)||(sendipv4_tcp->is_lo)))
-					sendipv4_tcp=&tcp_info[r];
+				if ((si->address.af==AF_INET)&&
+						((sendipv4_tcp==0)||(sendipv4_tcp->flags&SI_IS_LO)))
+					sendipv4_tcp=si;
 		#ifdef USE_IPV6
-				if((sendipv6_tcp==0)&&(tcp_info[r].address.af==AF_INET6))
-					sendipv6_tcp=&tcp_info[r];
+				if((sendipv6_tcp==0)&&(si->address.af==AF_INET6))
+					sendipv6_tcp=si;
 		#endif
 			}
+		}
 #ifdef USE_TLS
-			if (!tls_disable){
-				tls_info[r]=sock_info[r]; /* copy the sockets */
-				/* fix the port number -- there is no way so far to set-up
-				 * individual tls port numbers */
-				tls_info[r].port_no=tls_port_no; /* FIXME: */
-				tmp=int2str(tls_info[r].port_no, &len);
-				/* we don't need to free the previous content, is uesd
-				 * by tcp & udp! */
-				tls_info[r].port_no_str.s=(char*)pkg_malloc(len+1);
-				if (tls_info[r].port_no_str.s==0){
-					LOG(L_CRIT, "memory allocation failure\n");
-					goto error;
-				}
-				strncpy(tls_info[r].port_no_str.s, tmp, len+1);
-				tls_info[r].port_no_str.len=len;
-				
+		if (!tls_disable){
+			for(si=tls_listen; si; si=si->next){
 				/* same as for tcp*/
-				if (tls_init(&tls_info[r])==-1)  goto error;
+				if (tls_init(si)==-1)  goto error;
 				/* get first ipv4/ipv6 socket*/
-				if ((tls_info[r].address.af==AF_INET)&&
-						((sendipv4_tls==0)||(sendipv4_tls->is_lo)))
-					sendipv4_tls=&tls_info[r];
+				if ((si->address.af==AF_INET)&&
+						((sendipv4_tls==0)||(sendipv4_tls->flags&SI_IS_LO)))
+					sendipv4_tls=si;
 		#ifdef USE_IPV6
-				if((sendipv6_tls==0)&&(tls_info[r].address.af==AF_INET6))
-					sendipv6_tls=&tls_info[r];
+				if((sendipv6_tls==0)&&(si->address.af==AF_INET6))
+					sendipv6_tls=si;
 		#endif
 			}
+		}
 #endif /* USE_TLS */
 #endif /* USE_TCP */
 			/* all procs should have access to all the sockets (for sending)
 			 * so we open all first*/
-		}
-		for(r=0; r<sock_no;r++){
+		/* udp processes */
+		for(si=udp_listen; si; si=si->next){
 			for(i=0;i<children_no;i++){
 				process_no++;
 #ifdef USE_TCP
@@ -935,8 +923,7 @@ int main_loop()
 						unix_tcp_sock=sockfd[1];
 					}
 #endif
-					bind_address=&sock_info[r]; /* shortcut */
-					bind_idx=r;
+					bind_address=si; /* shortcut */
 					if (init_child(i + 1) < 0) {
 						LOG(L_ERR, "init_child failed\n");
 						goto error;
@@ -948,8 +935,8 @@ int main_loop()
 				}else{
 						pt[process_no].pid=pid; /*should be in shared mem.*/
 						snprintf(pt[process_no].desc, MAX_PT_DESC,
-							"receiver child=%d sock=%d @ %s:%s", i, r, 	
-							sock_info[r].name.s, sock_info[r].port_no_str.s );
+							"receiver child=%d sock= %s:%s", i, 	
+							si->name.s, si->port_no_str.s );
 #ifdef USE_TCP
 						if (!tcp_disable){
 							close(sockfd[1]);
@@ -967,8 +954,6 @@ int main_loop()
 
 	/*this is the main process*/
 	bind_address=0;				/* main proc -> it shouldn't send anything, */
-	bind_idx=0;					/* if it does get_send_sock should return
-	                               a good socket */
 	
 	/* if configured to do so, start a server for accepting FIFO commands */
 	if (open_fifo_server()<0) {
@@ -1068,8 +1053,9 @@ int main_loop()
 #endif
 	/*DEBUG- remove it*/
 #ifdef DEBUG
-	fprintf(stderr, "\n% 3d processes (%3d), % 3d children * % 3d listening addresses"
-			"+ main + fifo %s\n", process_no+1, process_count(), children_no, sock_no,
+	fprintf(stderr, "\n% 3d processes (%3d), % 3d children * "
+			"listening addresses + tcp listeners + tls listeners"
+			"+ main + fifo %s\n", process_no+1, process_count(), children_no,
 			(timer_list)?"+ timer":"");
 	for (r=0; r<=process_no; r++){
 		fprintf(stderr, "% 3d   % 5d - %s\n", r, pt[r].pid, pt[r].desc);
@@ -1095,134 +1081,6 @@ int main_loop()
 
 }
 
-/* add all family type addresses of interface if_name to the socket_info array
- * if if_name==0, adds all addresses on all interfaces
- * WARNING: it only works with ipv6 addresses on FreeBSD
- * return: -1 on error, 0 on success
- */
-int add_interfaces(char* if_name, int family, unsigned short port)
-{
-	struct ifconf ifc;
-	struct ifreq ifr;
-	struct ifreq ifrcopy;
-	char*  last;
-	char* p;
-	int size;
-	int lastlen;
-	int s;
-	char* tmp;
-	struct ip_addr addr;
-	int ret;
-
-#ifdef HAVE_SOCKADDR_SA_LEN
-	#ifndef MAX
-		#define MAX(a,b) ( ((a)>(b))?(a):(b))
-	#endif
-#endif
-	/* ipv4 or ipv6 only*/
-	s=socket(family, SOCK_DGRAM, 0);
-	ret=-1;
-	lastlen=0;
-	ifc.ifc_req=0;
-	for (size=10; ; size*=2){
-		ifc.ifc_len=size*sizeof(struct ifreq);
-		ifc.ifc_req=(struct ifreq*) pkg_malloc(size*sizeof(struct ifreq));
-		if (ifc.ifc_req==0){
-			fprintf(stderr, "memory allocation failure\n");
-			goto error;
-		}
-		if (ioctl(s, SIOCGIFCONF, &ifc)==-1){
-			if(errno==EBADF) return 0; /* invalid descriptor => no such ifs*/
-			fprintf(stderr, "ioctl failed: %s\n", strerror(errno));
-			goto error;
-		}
-		if  ((lastlen) && (ifc.ifc_len==lastlen)) break; /*success,
-														   len not changed*/
-		lastlen=ifc.ifc_len;
-		/* try a bigger array*/
-		pkg_free(ifc.ifc_req);
-	}
-	
-	last=(char*)ifc.ifc_req+ifc.ifc_len;
-	for(p=(char*)ifc.ifc_req; p<last;
-			p+=(sizeof(ifr.ifr_name)+
-			#ifdef  HAVE_SOCKADDR_SA_LEN
-				MAX(ifr.ifr_addr.sa_len, sizeof(struct sockaddr))
-			#else
-				( (ifr.ifr_addr.sa_family==AF_INET)?
-					sizeof(struct sockaddr_in):
-					((ifr.ifr_addr.sa_family==AF_INET6)?
-						sizeof(struct sockaddr_in6):sizeof(struct sockaddr)) )
-			#endif
-				)
-		)
-	{
-		/* copy contents into ifr structure
-		 * warning: it might be longer (e.g. ipv6 address) */
-		memcpy(&ifr, p, sizeof(ifr));
-		if (ifr.ifr_addr.sa_family!=family){
-			/*printf("strange family %d skipping...\n",
-					ifr->ifr_addr.sa_family);*/
-			continue;
-		}
-		
-		/*get flags*/
-		ifrcopy=ifr;
-		if (ioctl(s, SIOCGIFFLAGS,  &ifrcopy)!=-1){ /* ignore errors */
-			/* ignore down ifs only if listening on all of them*/
-			if (if_name==0){ 
-				/* if if not up, skip it*/
-				if (!(ifrcopy.ifr_flags & IFF_UP)) continue;
-			}
-		}
-		
-		
-		
-		if ((if_name==0)||
-			(strncmp(if_name, ifr.ifr_name, sizeof(ifr.ifr_name))==0)){
-			
-				/*add address*/
-			if (sock_no<MAX_LISTEN){
-				sockaddr2ip_addr(&addr, 
-					(struct sockaddr*)(p+(long)&((struct ifreq*)0)->ifr_addr));
-				if ((tmp=ip_addr2a(&addr))==0) goto error;
-				/* fill the strings*/
-				sock_info[sock_no].name.s=(char*)pkg_malloc(strlen(tmp)+1);
-				if(sock_info[sock_no].name.s==0){
-					fprintf(stderr, "Out of memory.\n");
-					goto error;
-				}
-				/* fill in the new name and port */
-				sock_info[sock_no].name.len=strlen(tmp);
-				strncpy(sock_info[sock_no].name.s, tmp, 
-							sock_info[sock_no].name.len+1);
-				sock_info[sock_no].port_no=port;
-				/* mark if loopback */
-				if (ifrcopy.ifr_flags & IFF_LOOPBACK) 
-					sock_info[sock_no].is_lo=1;
-				sock_no++;
-				ret=0;
-			}else{
-				fprintf(stderr, "Too many addresses (max %d)\n", MAX_LISTEN);
-				goto error;
-			}
-		}
-			/*
-			printf("%s:\n", ifr->ifr_name);
-			printf("        ");
-			print_sockaddr(&(ifr->ifr_addr));
-			printf("        ");
-			ls_ifflags(ifr->ifr_name, family, options);
-			printf("\n");*/
-	}
-	pkg_free(ifc.ifc_req); /*clean up*/
-	close(s);
-	return  ret;
-error:
-	if (ifc.ifc_req) pkg_free(ifc.ifc_req);
-	close(s);
-	return -1;
-}
 
 
 
@@ -1230,14 +1088,9 @@ int main(int argc, char** argv)
 {
 
 	FILE* cfg_stream;
-	struct hostent* he;
-	int c,r,t;
+	int c,r;
 	char *tmp;
-	char** h;
-	struct host_alias* a;
-	struct utsname myname;
 	char *options;
-	int len;
 	int ret;
 	struct passwd *pw_entry;
 	struct group  *gr_entry;
@@ -1287,9 +1140,7 @@ int main(int argc, char** argv)
 						fprintf(stderr, "bad port number: -p %s\n", optarg);
 						goto error;
 					}
-					if (sock_no>0) sock_info[sock_no-1].port_no=port_no;
 					break;
-
 			case 'm':
 					shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;
 					if (tmp &&(*tmp)){
@@ -1311,23 +1162,8 @@ int main(int argc, char** argv)
 					break;
 			case 'l':
 					/* add a new addr. to our address list */
-					if (sock_no < MAX_LISTEN){
-						sock_info[sock_no].name.s=
-										(char*)pkg_malloc(strlen(optarg)+1);
-						if (sock_info[sock_no].name.s==0){
-							fprintf(stderr, "Out of memory.\n");
-							goto error;
-						}
-						strncpy(sock_info[sock_no].name.s, optarg,
-												strlen(optarg)+1);
-						sock_info[sock_no].name.len=strlen(optarg);
-						/* set default port */
-						sock_info[sock_no].port_no=port_no;
-						sock_no++;
-					}else{
-						fprintf(stderr, 
-									"Too many addresses (max. %d).\n",
-									MAX_LISTEN);
+					if (add_listen_iface(optarg, 0, 0, 0)!=0){
+						fprintf(stderr, "failed to add new listen address\n");
 						goto error;
 					}
 					break;
@@ -1534,188 +1370,23 @@ try_again:
 			gid=gr_entry->gr_gid;
 		}
 	}
-
-	if (sock_no==0) {
-		/* try to get all listening ipv4 interfaces */
-		if (add_interfaces(0, AF_INET, 0)==-1){
-			/* if error fall back to get hostname*/
-			/* get our address, only the first one */
-			if (uname (&myname) <0){
-				fprintf(stderr, "cannot determine hostname, try -l address\n");
-				goto error;
-			}
-			sock_info[sock_no].name.s=
-								(char*)pkg_malloc(strlen(myname.nodename)+1);
-			if (sock_info[sock_no].name.s==0){
-				fprintf(stderr, "Out of memory.\n");
-				goto error;
-			}
-			sock_info[sock_no].name.len=strlen(myname.nodename);
-			strncpy(sock_info[sock_no].name.s, myname.nodename,
-					sock_info[sock_no].name.len+1);
-			sock_no++;
-		}
-	}
-
-	/* try to change all the interface names into addresses
-	 *  --ugly hack */
-	for (r=0; r<sock_no;){
-		if (add_interfaces(sock_info[r].name.s, AF_INET,
-					sock_info[r].port_no)!=-1){
-			/* success => remove current entry (shift the entire array)*/
-			pkg_free(sock_info[r].name.s);
-			memmove(&sock_info[r], &sock_info[r+1], 
-						(sock_no-r)*sizeof(struct socket_info));
-			sock_no--;
-			continue;
-		}
-		r++;
-	}
-	/* get ips & fill the port numbers*/
-#ifdef EXTRA_DEBUG
-	printf("Listening on \n");
-#endif
-	for (r=0; r<sock_no;r++){
-		/* fix port number, port_no should be !=0 here */
-		if (sock_info[r].port_no==0) sock_info[r].port_no=port_no;
-		tmp=int2str(sock_info[r].port_no, &len);
-		if (len>=MAX_PORT_LEN){
-			fprintf(stderr, "ERROR: bad port number: %d\n", 
-						sock_info[r].port_no);
-			goto error;
-		}
-		sock_info[r].port_no_str.s=(char*)pkg_malloc(len+1);
-		if (sock_info[r].port_no_str.s==0){
-			fprintf(stderr, "Out of memory.\n");
-			goto error;
-		}
-		strncpy(sock_info[r].port_no_str.s, tmp, len+1);
-		sock_info[r].port_no_str.len=len;
-		
-		/* get "official hostnames", all the aliases etc. */
-		he=resolvehost(sock_info[r].name.s);
-		if (he==0){
-			DPrint("ERROR: could not resolve %s\n", sock_info[r].name.s);
-			goto error;
-		}
-		/* check if we got the official name */
-		if (strcasecmp(he->h_name, sock_info[r].name.s)!=0){
-			if (add_alias(sock_info[r].name.s, sock_info[r].name.len,
-							sock_info[r].port_no, 0)<0){
-				LOG(L_ERR, "ERROR: main: add_alias failed\n");
-			}
-			/* change the oficial name */
-			pkg_free(sock_info[r].name.s);
-			sock_info[r].name.s=(char*)pkg_malloc(strlen(he->h_name)+1);
-			if (sock_info[r].name.s==0){
-				fprintf(stderr, "Out of memory.\n");
-				goto error;
-			}
-			sock_info[r].name.len=strlen(he->h_name);
-			strncpy(sock_info[r].name.s, he->h_name, sock_info[r].name.len+1);
-		}
-		/* add the aliases*/
-		for(h=he->h_aliases; h && *h; h++)
-			if (add_alias(*h, strlen(*h), sock_info[r].port_no, 0)<0){
-				LOG(L_ERR, "ERROR: main: add_alias failed\n");
-			}
-		hostent2ip_addr(&sock_info[r].address, he, 0); /*convert to ip_addr 
-														 format*/
-		if ((tmp=ip_addr2a(&sock_info[r].address))==0) goto error;
-		sock_info[r].address_str.s=(char*)pkg_malloc(strlen(tmp)+1);
-		if (sock_info[r].address_str.s==0){
-			fprintf(stderr, "Out of memory.\n");
-			goto error;
-		}
-		strncpy(sock_info[r].address_str.s, tmp, strlen(tmp)+1);
-		/* set is_ip (1 if name is an ip address, 0 otherwise) */
-		sock_info[r].address_str.len=strlen(tmp);
-		if 	(	(sock_info[r].address_str.len==sock_info[r].name.len)&&
-				(strncasecmp(sock_info[r].address_str.s, sock_info[r].name.s,
-						 sock_info[r].address_str.len)==0)
-			){
-				sock_info[r].is_ip=1;
-				/* do rev. dns on it (for aliases)*/
-				he=rev_resolvehost(&sock_info[r].address);
-				if (he==0){
-					DPrint("WARNING: could not rev. resolve %s\n",
-							sock_info[r].name.s);
-				}else{
-					/* add the aliases*/
-					if (add_alias(he->h_name, strlen(he->h_name),
-									sock_info[r].port_no, 0)<0){
-						LOG(L_ERR, "ERROR: main: add_alias failed\n");
-					}
-					for(h=he->h_aliases; h && *h; h++)
-						if (add_alias(*h,strlen(*h),sock_info[r].port_no,0)<0){
-							LOG(L_ERR, "ERROR: main: add_alias failed\n");
-						}
-				}
-		}else{ sock_info[r].is_ip=0; };
-			
-#ifdef EXTRA_DEBUG
-		printf("              %.*s [%s]:%s\n", sock_info[r].name.len, 
-				sock_info[r].name.s,
-				sock_info[r].address_str.s, sock_info[r].port_no_str.s);
-#endif
-	}
-	/* removing duplicate addresses*/
-	for (r=0; r<sock_no; r++){
-		for (t=r+1; t<sock_no;){
-			if ((sock_info[r].port_no==sock_info[t].port_no) &&
-				(sock_info[r].address.af==sock_info[t].address.af) &&
-				(memcmp(sock_info[r].address.u.addr, 
-						sock_info[t].address.u.addr,
-						sock_info[r].address.len)  == 0)
-				){
-#ifdef EXTRA_DEBUG
-				printf("removing duplicate (%d) %s [%s] == (%d) %s [%s]\n",
-						r, sock_info[r].name.s, sock_info[r].address_str.s,
-						t, sock_info[t].name.s, sock_info[t].address_str.s);
-#endif
-				/* add the name to the alias list*/
-				if ((!sock_info[t].is_ip) && (
-						(sock_info[t].name.len!=sock_info[r].name.len)||
-						(strncmp(sock_info[t].name.s, sock_info[r].name.s,
-								 sock_info[r].name.len)!=0))
-					)
-					add_alias(sock_info[t].name.s, sock_info[t].name.len,
-								sock_info[t].port_no, 0);
-						
-				/* free space*/
-				pkg_free(sock_info[t].name.s);
-				pkg_free(sock_info[t].address_str.s);
-				pkg_free(sock_info[t].port_no_str.s);
-				/* shift the array*/
-				memmove(&sock_info[t], &sock_info[t+1], 
-							(sock_no-t)*sizeof(struct socket_info));
-				sock_no--;
-				continue;
-			}
-			t++;
-		}
+	
+	if (fix_all_socket_lists()!=0){
+		fprintf(stderr,  "failed to initialize liste addresses\n");
+		goto error;
 	}
 	/* print all the listen addresses */
 	printf("Listening on \n");
-	for (r=0; r<sock_no; r++)
-		printf("              %s [%s]:%s\n",sock_info[r].name.s,
-				sock_info[r].address_str.s, sock_info[r].port_no_str.s);
-
-	printf("Aliases: ");
-	for(a=aliases; a; a=a->next) 
-		if (a->port)
-			printf("%.*s:%d ", a->alias.len, a->alias.s, a->port);
-		else
-			printf("%.*s:* ", a->alias.len, a->alias.s);
+	print_all_socket_lists();
+	printf("Aliases: \n");
+	/*print_aliases();*/
+	print_aliases();
 	printf("\n");
-	if (sock_no==0){
-		fprintf(stderr, "ERROR: no listening sockets");
-		goto error;
-	}
+	
 	if (dont_fork){
 		fprintf(stderr, "WARNING: no fork mode %s\n", 
-				(sock_no>1)?" and more than one listen address found (will"
-							" use only the the first one)":"");
+				(udp_listen->next)?" and more than one listen address found"
+				"(will use only the the first one)":"");
 	}
 	if (config_check){
 		fprintf(stderr, "config file ok, exiting...\n");

+ 2 - 2
mem/mem.h

@@ -123,9 +123,9 @@
 #	include <stdlib.h>
 #	define pkg_malloc(s) \
 	(  { void *v; v=malloc((s)); \
-	   DBG("malloc %x size %d end %x\n", v, s, (unsigned int)v+(s));\
+	   DBG("malloc %p size %d end %p\n", v, s, (char*)v+(s));\
 	   v; } )
-#	define pkg_free(p)  do{ DBG("free %x\n", (p)); free((p)); }while(0);
+#	define pkg_free(p)  do{ DBG("free %p\n", (p)); free((p)); }while(0);
 #	define pkg_status()
 #endif
 

+ 14 - 3
modules/tm/callid.c

@@ -28,13 +28,15 @@
  *
  * History:
  * ----------
- * 2003-04-09 Created by janakj
+ *  2003-04-09  Created by janakj
+ *  2003-10-24  updated to the new socket_info lists (andrei)
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include "../../dprint.h"
 #include "../../pt.h"
+#include "../../socket_info.h"
 #include "callid.h"
 
 #define CALLID_NR_LEN 20
@@ -106,12 +108,21 @@ int init_callid(void)
  */
 int child_init_callid(int rank) 
 {
+	struct socket_info *si;
+	
+	/* on tcp/tls bind_address is 0 so try to get the first address we listen
+	 * on no matter the protocol */
+	si=bind_address?bind_address:get_first_socket();
+	if (si==0){
+		LOG(L_CRIT, "BUG: child_init_callid: null socket list\n");
+		return -1;
+	}
 	callid_suffix.s = callid_buf + callid_prefix.len;
 
 	callid_suffix.len = snprintf(callid_suffix.s, CALLID_SUFFIX_LEN,
 				     "%c%d@%.*s", CID_SEP, my_pid(), 
-				     sock_info[bind_idx].address_str.len,
-				     sock_info[bind_idx].address_str.s);
+				     si->address_str.len,
+				     si->address_str.s);
 	if ((callid_suffix.len == -1) || (callid_suffix.len > CALLID_SUFFIX_LEN)) {
 		LOG(L_ERR, "ERROR: child_init_callid: buffer too small\n");
 		return -1;

+ 12 - 2
modules/tm/uac.c

@@ -44,6 +44,7 @@
  *  2003-04-02  port_no_str does not contain a leading ':' anymore (andrei)
  *  2003-07-08  appropriate log messages in check_params(...), 
  *               call calculate_hooks if next_hop==NULL in t_uac (dcm) 
+ *  2003-10-24  updated to the new socket_info lists (andrei)
  */
 
 #include <string.h>
@@ -53,6 +54,7 @@
 #include "../../md5.h"
 #include "../../crc.h"
 #include "../../ip_addr.h"
+#include "../../socket_info.h"
 #include "ut.h"
 #include "h_table.h"
 #include "t_hooks.h"
@@ -75,18 +77,26 @@ char* uac_from = "sip:[email protected]"; /* Module parameter */
 int uac_init(void) 
 {
 	str src[3];
+	struct socket_info *si;
 
 	if (RAND_MAX < TABLE_ENTRIES) {
 		LOG(L_WARN, "Warning: uac does not spread "
 		    "accross the whole hash table\n");
 	}
+	/* on tcp/tls bind_address is 0 so try to get the first address we listen
+	 * on no matter the protocol */
+	si=bind_address?bind_address:get_first_socket();
+	if (si==0){
+		LOG(L_CRIT, "BUG: child_init_callid: null socket list\n");
+		return -1;
+	}
 
 	/* calculate the initial From tag */
 	src[0].s = "Long live SER server";
 	src[0].len = strlen(src[0].s);
-	src[1].s = sock_info[bind_idx].address_str.s;
+	src[1].s = si->address_str.s;
 	src[1].len = strlen(src[1].s);
-	src[2].s = sock_info[bind_idx].port_no_str.s;
+	src[2].s = si->port_no_str.s;
 	src[2].len = strlen(src[2].s);
 
 	MDStringArray(from_tag, src, 3);

+ 6 - 1
pt.h

@@ -43,6 +43,7 @@
 
 #include "globals.h"
 #include "timer.h"
+#include "socket_info.h"
 
 #define MAX_PT_DESC	128
 
@@ -63,9 +64,13 @@ extern int process_no;
 */
 inline static int process_count()
 {
+	int udp_listeners;
+	struct socket_info* si;
+	
+	for (si=udp_listen, udp_listeners=0; si; si=si->next, udp_listeners++);
     return 
 		/* receivers and attendant */
-		(dont_fork ? 1 : children_no*sock_no + 1)
+		(dont_fork ? 1 : children_no*udp_listeners + 1)
 		/* timer process */
 		+ (timer_list ? 1 : 0 )
 		/* fifo server */

+ 4 - 0
resolve.h

@@ -284,8 +284,10 @@ static inline struct hostent* resolvehost(char* name)
 	static struct hostent* he2=0;
 #endif
 #ifndef DNS_IP_HACK
+#ifdef USE_IPV6
 	int len;
 #endif
+#endif
 #ifdef DNS_IP_HACK
 	struct ip_addr* ip;
 	str s;
@@ -304,6 +306,7 @@ static inline struct hostent* resolvehost(char* name)
 	}
 	
 #else /* DNS_IP_HACK */
+#ifdef USE_IPV6
 	len=0;
 	if (*name=='['){
 		len=strlen(name);
@@ -313,6 +316,7 @@ static inline struct hostent* resolvehost(char* name)
 			goto skip_ipv4;
 		}
 	}
+#endif
 #endif
 	/* ipv4 */
 	he=gethostbyname(name);

+ 9 - 5
tags.h

@@ -48,6 +48,7 @@
 #include "globals.h"
 #include "crc.h"
 #include "str.h"
+#include "socket_info.h"
 
 #define TOTAG_VALUE_LEN (MD5_LEN+CRC16_LEN+1)
 
@@ -71,12 +72,15 @@ static void inline init_tags( char *tag, char **suffix,
 		char *signature, char separator )
 {
 	str src[3];
-
+	struct socket_info* si;
+	
+	si=get_first_socket();
 	src[0].s=signature; src[0].len=strlen(signature);
-	src[1].s=sock_info[0].address_str.s;
-	src[1].len=sock_info[0].address_str.len;
-	src[2].s=sock_info[0].port_no_str.s;
-	src[2].len=sock_info[0].port_no_str.len;
+	/* if we are not listening on anything we shouldn't be here */
+	src[1].s=si?si->address_str.s:"";
+	src[1].len=si?si->address_str.len:0;
+	src[2].s=si?si->port_no_str.s:"";
+	src[2].len=si?si->port_no_str.len:0;
 
 	MDStringArray( tag, src, 3 );
 

+ 25 - 18
tcp_main.c

@@ -42,6 +42,7 @@
  *  2003-06-30  moved tcp new connect checking & handling to
  *               handle_new_connect (andrei)
  *  2003-07-09  tls_close called before closing the tcp connection (andrei)
+ *  2003-10-24  converted to the new socket_info lists (andrei)
  */
 
 
@@ -181,14 +182,14 @@ error:
 
 struct socket_info* find_tcp_si(union sockaddr_union* s)
 {
-	int r;
 	struct ip_addr ip;
+	struct socket_info* si;
 	
 	su2ip_addr(&ip, s);
-	for (r=0; r<sock_no; r++)
-		if (ip_addr_cmp(&ip, &tcp_info[r].address)){
+	for (si=tcp_listen; si; si=si->next)
+		if (ip_addr_cmp(&ip, &si->address)){
 			/* found it, we use first match */
-			return &tcp_info[r];
+			return si;
 		}
 	return 0; /* no match */
 }
@@ -728,24 +729,31 @@ void tcp_main_loop()
 	int bytes;
 	struct timeval timeout;
 	int fd;
+	struct socket_info* si;
 
 	/*init */
 	maxfd=0;
 	FD_ZERO(&master_set);
 	/* set all the listen addresses */
-	for (r=0; r<sock_no; r++){
-		if ((tcp_info[r].proto==PROTO_TCP) &&(tcp_info[r].socket!=-1)){
-			FD_SET(tcp_info[r].socket, &master_set);
-			if (tcp_info[r].socket>maxfd) maxfd=tcp_info[r].socket;
+	for (si=tcp_listen; si; si=si->next){
+		if ((si->proto==PROTO_TCP) &&(si->socket!=-1)){
+			FD_SET(si->socket, &master_set);
+			if (si->socket>maxfd) maxfd=si->socket;
+		}else{
+			LOG(L_CRIT, "BUG: tcp_main_loop: non tcp address in tcp_listen\n");
 		}
+	}
 #ifdef USE_TLS
-		if ((!tls_disable)&&(tls_info[r].proto==PROTO_TLS) &&
-				(tls_info[r].socket!=-1)){
-			FD_SET(tls_info[r].socket, &master_set);
-			if (tls_info[r].socket>maxfd) maxfd=tls_info[r].socket;
+	if (!tls_disable){
+		for (si=tls_listen; si; si=si->next){
+			if ((si->proto==PROTO_TLS) && (si->socket!=-1)){
+				FD_SET(si->socket, &master_set);
+				if (si->socket>maxfd) maxfd=si->socket;
+			}else{
+			LOG(L_CRIT, "BUG: tcp_main_loop: non tls address in tls_listen\n");
 		}
-#endif
 	}
+#endif
 	/* set all the unix sockets used for child comm */
 	for (r=1; r<process_no; r++){
 		if (pt[r].unix_sock>0){ /* we can't have 0, we never close it!*/
@@ -770,13 +778,13 @@ void tcp_main_loop()
 			n=0;
 		}
 		
-		for (r=0; r<sock_no && n; r++){
-			handle_new_connect(&tcp_info[r], &sel_set, &n);
+		for (si=tcp_listen; si && n; si=si->next)
+			handle_new_connect(si, &sel_set, &n);
 #ifdef USE_TLS
 			if (!tls_disable)
-				handle_new_connect(&tls_info[r], &sel_set, &n);
+				for (si=tls_listen; si && n; si=si->next)
+					handle_new_connect(si, &sel_set, &n);
 #endif
-		}
 		
 		/* check all the read fds (from the tcpconn_addr_hash ) */
 		for (h=0; h<TCP_ADDR_HASH_SIZE; h++){
@@ -1063,7 +1071,6 @@ int tcp_init_children()
 			unix_tcp_sock=sockfd[1];
 			bind_address=0; /* force a SEGFAULT if someone uses a non-init.
 							   bind address on tcp */
-			bind_idx=0;
 			if (init_child(r+children_no+1) < 0) {
 				LOG(L_ERR, "init_children failed\n");
 				goto error;

+ 36 - 24
test/test.cfg

@@ -1,29 +1,41 @@
-debug=9          # debug level (cmd line: -dddddddddd)
-check_via=1      # (cmd. line: -v)
-dns=on           # (cmd. line: -r)
-rev_dns=yes      # (cmd. line: -R)
-fork=no          # (cmd. line: -D)
-log_stderror=yes # (cmd line: -E)
-# for more info: sip_router -h
+#
+# configuration for stress testing
+#
+# $ID: $
+#
 
-route{
 
-	(src_ip=~'(dorian)|(ekina)|(terix)' & method=~'^inv') \
-				forward(centauri.fokus.gmd.de);
-	src_ip=~"^192\.168\.[0-9]{1,3}\.[0-9]{1,3}$"  \
-				log(1,"msg. from a private network\n"); route(1);
-	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;
-}
+#debug=9          # debug level (cmd line: -dddddddddd)
+#fork=yes          # (cmd. line: -D)
+#log_stderror=yes # (cmd line: -E)
+#log_stderror=no	# (cmd line: -E)
 
-route[1]{
-	src_ip==192.168.46.61  log("possible loop, dropping\n"); drop;
-	(src_ip==192.168.46.0/24) log("routing with rt2\n");route(2); log("we're back\n");
-	src_ip==0.0.0.0/0 log(1, "we'll drop this one too\n"); drop;
-}
 
-route[2]{
-	(method=~'^ACK' and uri=~'.*fokus') forward("fox.iptel.org");
-	! method=~'^INV' forward(193.175.135.179); /* dorian */
-	method=~'.' log("spying...\n"); send(dorian,8000); \
-						forward("fox.iptel.org");
+#children=2
+check_via=no     # (cmd. line: -v)
+dns=off           # (cmd. line: -r)
+rev_dns=off      # (cmd. line: -R)
+#port=5070
+#listen=10.0.0.179 lo	dorian
+#listen=eth0
+#listen=127.0.0.1
+#listen=192.168.57.33
+#listen=192.168.57.72
+#loop_checks=0
+# for more info: sip_router -h
+alias=iptel.org
+alias="foo.bar"
+fifo="/tmp/ser_fifo"
+listen= tcp:10.0.0.179:5065
+alias=  tcp:all:5065
+
+#modules
+
+
+route{
+	if (myself==uri){
+		log("\n\nfrom myself\n\n");
+	};
+	log(" continue \n\n");
+	forward(uri:host, uri:port);
 }