Browse code

- tcp conn id fix (sipit bug)

Andrei Pelinescu-Onciul authored on 19/08/2003 14:32:55
Showing 2 changed files
... ...
@@ -40,7 +40,7 @@ export makefile_defs
40 40
 VERSION = 0
41 41
 PATCHLEVEL = 8
42 42
 SUBLEVEL =   12
43
-EXTRAVERSION = dev-t12
43
+EXTRAVERSION = dev-t13
44 44
 
45 45
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
46 46
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -112,7 +112,7 @@ struct tcp_connection** tcpconn_id_hash=0;
112 112
 gen_lock_t* tcpconn_lock=0;
113 113
 
114 114
 struct tcp_child tcp_children[MAX_TCP_CHILDREN];
115
-static int connection_id=1; /*  unique for each connection, used for 
115
+static int* connection_id=0; /*  unique for each connection, used for 
116 116
 								quickly finding the corresponding connection
117 117
 								for a reply */
118 118
 int unix_tcp_sock;
... ...
@@ -151,7 +151,7 @@ struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
151 151
 	print_ip("tcpconn_new: new tcp connection: ", &c->rcv.src_ip, "\n");
152 152
 	DBG(     "tcpconn_new: on port %d, type %d\n", c->rcv.src_port, type);
153 153
 	init_tcp_req(&c->req);
154
-	c->id=connection_id++;
154
+	c->id=(*connection_id)++;
155 155
 	c->rcv.proto_reserved1=0; /* this will be filled before receive_message*/
156 156
 	c->rcv.proto_reserved2=0;
157 157
 	c->state=state;
... ...
@@ -941,12 +941,24 @@ int init_tcp()
941 941
 		tcpconn_lock=0;
942 942
 		goto error;
943 943
 	}
944
+	/* init globals */
945
+	connection_id=(int*)shm_malloc(sizeof(int));
946
+	if (connection_id==0){
947
+		LOG(L_CRIT, "ERROR: init_tcp: could not alloc globals\n");
948
+		lock_destroy(tcpconn_lock);
949
+		lock_dealloc((void*)tcpconn_lock);
950
+		tcpconn_lock=0;
951
+		goto error;
952
+	}
953
+	*connection_id=1;
944 954
 	/* alloc hashtables*/
945 955
 	tcpconn_addr_hash=(struct tcp_connection**)shm_malloc(TCP_ADDR_HASH_SIZE*
946 956
 								sizeof(struct tcp_connection*));
947 957
 
948 958
 	if (tcpconn_addr_hash==0){
949 959
 		LOG(L_CRIT, "ERROR: init_tcp: could not alloc address hashtable\n");
960
+		shm_free(connection_id);
961
+		connection_id=0;
950 962
 		lock_destroy(tcpconn_lock);
951 963
 		lock_dealloc((void*)tcpconn_lock);
952 964
 		tcpconn_lock=0;
... ...
@@ -957,6 +969,8 @@ int init_tcp()
957 957
 								sizeof(struct tcp_connection*));
958 958
 	if (tcpconn_id_hash==0){
959 959
 		LOG(L_CRIT, "ERROR: init_tcp: could not alloc id hashtable\n");
960
+		shm_free(connection_id);
961
+		connection_id=0;
960 962
 		shm_free(tcpconn_addr_hash);
961 963
 		tcpconn_addr_hash=0;
962 964
 		lock_destroy(tcpconn_lock);