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 151
 	send_sock=0;
152 152
 	/* check if we need to change the socket (different address families -
153 153
 	 * eg: ipv4 -> ipv6 or ipv6 -> ipv4) */
154
+	switch(proto){
154 155
 #ifdef USE_TCP
155
-	if (proto==PROTO_TCP){
156
+		case PROTO_TCP:
156 157
 		/* on tcp just use the "main address", we don't really now the
157 158
 		 * sending address (we can find it out, but we'll need also to see
158 159
 		 * 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;
160
+			switch(to->s.sa_family){
161
+				/* FIXME */
162
+				case AF_INET:	send_sock=sendipv4_tcp;
163
+								break;
162 164
 #ifdef USE_IPV6
163
-			case AF_INET6:	send_sock=sendipv6_tcp;
164
-							break;
165
+				case AF_INET6:	send_sock=sendipv6_tcp;
166
+								break;
165 167
 #endif
166
-			default:		LOG(L_ERR, "get_send_socket: BUG: don't know how"
168
+				default:	LOG(L_ERR, "get_send_socket: BUG: don't know how"
167 169
 									" to forward to af %d\n", to->s.sa_family);
168
-		}
169
-	}else
170
+			}
171
+			break;
170 172
 #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;
173
+		case PROTO_UDP:
174
+			if ((bind_address==0)||(to->s.sa_family!=bind_address->address.af)||
175
+				  (bind_address->proto!=PROTO_UDP)){
176
+				switch(to->s.sa_family){
177
+					case AF_INET:	send_sock=sendipv4;
178
+									break;
175 179
 #ifdef USE_IPV6
176
-			case AF_INET6:	send_sock=sendipv6;
177
-							break;
180
+					case AF_INET6:	send_sock=sendipv6;
181
+									break;
178 182
 #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;
183
+					default:	LOG(L_ERR, "get_send_socket: BUG: don't know"
184
+										" how to forward to af %d\n",
185
+										to->s.sa_family);
186
+				}
187
+			}else send_sock=bind_address;
188
+			break;
189
+		default:
190
+			LOG(L_CRIT, "BUG: get_send_socket: unkown proto %d\n", proto);
191
+	}
183 192
 	return send_sock;
184 193
 }
185 194
 
... ...
@@ -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