Browse code

- fixed get_send_sock for the tcp to udp forwarding with bind_address!=0 (recent change)

Andrei Pelinescu-Onciul authored on 02/04/2003 18:20:34
Showing 3 changed files
... ...
@@ -18,6 +18,7 @@ x (different way) add request header bitmap field for the modules
18 18
 - fix bind_address for tcp (in some  way)
19 19
 - add conflict in debs/rpms/etc (conflict w/ older ser-mysql, ser-jabber)
20 20
 - new packages ser-radius etc
21
+- tcp_destroy (called on ser exit)
21 22
 
22 23
 
23 24
 High priority:
... ...
@@ -35,6 +35,7 @@
35 35
  *  2003-02-11  removed calls to upd_send & tcp_send & replaced them with
36 36
  *               calls to msg_send (andrei)
37 37
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
38
+ *  2003-04-02  fixed get_send_socket for tcp fwd to udp (andrei)
38 39
  */
39 40
 
40 41
 
... ...
@@ -151,35 +152,44 @@ struct socket_info* get_send_socket(union sockaddr_union* to, int proto)
151 152
 	send_sock=0;
152 153
 	/* check if we need to change the socket (different address families -
153 154
 	 * eg: ipv4 -> ipv6 or ipv6 -> ipv4) */
155
+	switch(proto){
154 156
 #ifdef USE_TCP
155
-	if (proto==PROTO_TCP){
157
+		case PROTO_TCP:
156 158
 		/* on tcp just use the "main address", we don't really now the
157 159
 		 * sending address (we can find it out, but we'll need also to see
158 160
 		 * if we listen on it, and if yes on which port -> too complicated*/
159
-		switch(to->s.sa_family){
160
-			case AF_INET:	send_sock=sendipv4_tcp;
161
-							break;
161
+			switch(to->s.sa_family){
162
+				/* FIXME */
163
+				case AF_INET:	send_sock=sendipv4_tcp;
164
+								break;
162 165
 #ifdef USE_IPV6
163
-			case AF_INET6:	send_sock=sendipv6_tcp;
164
-							break;
166
+				case AF_INET6:	send_sock=sendipv6_tcp;
167
+								break;
165 168
 #endif
166
-			default:		LOG(L_ERR, "get_send_socket: BUG: don't know how"
169
+				default:	LOG(L_ERR, "get_send_socket: BUG: don't know how"
167 170
 									" to forward to af %d\n", to->s.sa_family);
168
-		}
169
-	}else
171
+			}
172
+			break;
170 173
 #endif
171
-	      if ((bind_address==0) ||(to->s.sa_family!=bind_address->address.af)){
172
-		switch(to->s.sa_family){
173
-			case AF_INET:	send_sock=sendipv4;
174
-							break;
174
+		case PROTO_UDP:
175
+			if ((bind_address==0)||(to->s.sa_family!=bind_address->address.af)||
176
+				  (bind_address->proto!=PROTO_UDP)){
177
+				switch(to->s.sa_family){
178
+					case AF_INET:	send_sock=sendipv4;
179
+									break;
175 180
 #ifdef USE_IPV6
176
-			case AF_INET6:	send_sock=sendipv6;
177
-							break;
181
+					case AF_INET6:	send_sock=sendipv6;
182
+									break;
178 183
 #endif
179
-			default:		LOG(L_ERR, "get_send_socket: BUG: don't know how"
180
-									" to forward to af %d\n", to->s.sa_family);
181
-		}
182
-	}else send_sock=bind_address;
184
+					default:	LOG(L_ERR, "get_send_socket: BUG: don't know"
185
+										" how to forward to af %d\n",
186
+										to->s.sa_family);
187
+				}
188
+			}else send_sock=bind_address;
189
+			break;
190
+		default:
191
+			LOG(L_CRIT, "BUG: get_send_socket: unkown proto %d\n", proto);
192
+	}
183 193
 	return send_sock;
184 194
 }
185 195
 
... ...
@@ -417,11 +417,14 @@ again:
417 417
 			DBG("calling receive_msg(%p, %d, )\n",
418 418
 					req->start, (int)(req->parsed-req->start));
419 419
 			/* just for debugging use sendipv4 as receiving socket  FIXME*/
420
+			bind_address=con->rcv.bind_address;
421
+			/*
420 422
 			if (con->rcv.dst_ip.af==AF_INET6){
421 423
 				bind_address=sendipv6_tcp;
422 424
 			}else{
423 425
 				bind_address=sendipv4_tcp;
424 426
 			}
427
+			*/
425 428
 			con->rcv.proto_reserved1=con->id; /* copy the id */
426 429
 			c=*req->parsed; /* ugly hack: zero term the msg & save the
427 430
 							   previous char, req->parsed should be ok