Selaa lähdekoodia

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

Andrei Pelinescu-Onciul 22 vuotta sitten
vanhempi
commit
21e0d5c10f
3 muutettua tiedostoa jossa 33 lisäystä ja 19 poistoa
  1. 1 0
      TODO
  2. 29 19
      forward.c
  3. 3 0
      tcp_read.c

+ 1 - 0
TODO

@@ -18,6 +18,7 @@ x (different way) add request header bitmap field for the modules
 - fix bind_address for tcp (in some  way)
 - add conflict in debs/rpms/etc (conflict w/ older ser-mysql, ser-jabber)
 - new packages ser-radius etc
+- tcp_destroy (called on ser exit)
 
 
 High priority:

+ 29 - 19
forward.c

@@ -35,6 +35,7 @@
  *  2003-02-11  removed calls to upd_send & tcp_send & replaced them with
  *               calls to msg_send (andrei)
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ *  2003-04-02  fixed get_send_socket for tcp fwd to udp (andrei)
  */
 
 
@@ -151,35 +152,44 @@ struct socket_info* get_send_socket(union sockaddr_union* to, int proto)
 	send_sock=0;
 	/* check if we need to change the socket (different address families -
 	 * eg: ipv4 -> ipv6 or ipv6 -> ipv4) */
+	switch(proto){
 #ifdef USE_TCP
-	if (proto==PROTO_TCP){
+		case PROTO_TCP:
 		/* on tcp just use the "main address", we don't really now the
 		 * sending address (we can find it out, but we'll need also to see
 		 * if we listen on it, and if yes on which port -> too complicated*/
-		switch(to->s.sa_family){
-			case AF_INET:	send_sock=sendipv4_tcp;
-							break;
+			switch(to->s.sa_family){
+				/* FIXME */
+				case AF_INET:	send_sock=sendipv4_tcp;
+								break;
 #ifdef USE_IPV6
-			case AF_INET6:	send_sock=sendipv6_tcp;
-							break;
+				case AF_INET6:	send_sock=sendipv6_tcp;
+								break;
 #endif
-			default:		LOG(L_ERR, "get_send_socket: BUG: don't know how"
+				default:	LOG(L_ERR, "get_send_socket: BUG: don't know how"
 									" to forward to af %d\n", to->s.sa_family);
-		}
-	}else
+			}
+			break;
 #endif
-	      if ((bind_address==0) ||(to->s.sa_family!=bind_address->address.af)){
-		switch(to->s.sa_family){
-			case AF_INET:	send_sock=sendipv4;
-							break;
+		case PROTO_UDP:
+			if ((bind_address==0)||(to->s.sa_family!=bind_address->address.af)||
+				  (bind_address->proto!=PROTO_UDP)){
+				switch(to->s.sa_family){
+					case AF_INET:	send_sock=sendipv4;
+									break;
 #ifdef USE_IPV6
-			case AF_INET6:	send_sock=sendipv6;
-							break;
+					case AF_INET6:	send_sock=sendipv6;
+									break;
 #endif
-			default:		LOG(L_ERR, "get_send_socket: BUG: don't know how"
-									" to forward to af %d\n", to->s.sa_family);
-		}
-	}else send_sock=bind_address;
+					default:	LOG(L_ERR, "get_send_socket: BUG: don't know"
+										" how to forward to af %d\n",
+										to->s.sa_family);
+				}
+			}else send_sock=bind_address;
+			break;
+		default:
+			LOG(L_CRIT, "BUG: get_send_socket: unkown proto %d\n", proto);
+	}
 	return send_sock;
 }
 

+ 3 - 0
tcp_read.c

@@ -417,11 +417,14 @@ again:
 			DBG("calling receive_msg(%p, %d, )\n",
 					req->start, (int)(req->parsed-req->start));
 			/* just for debugging use sendipv4 as receiving socket  FIXME*/
+			bind_address=con->rcv.bind_address;
+			/*
 			if (con->rcv.dst_ip.af==AF_INET6){
 				bind_address=sendipv6_tcp;
 			}else{
 				bind_address=sendipv4_tcp;
 			}
+			*/
 			con->rcv.proto_reserved1=con->id; /* copy the id */
 			c=*req->parsed; /* ugly hack: zero term the msg & save the
 							   previous char, req->parsed should be ok