Ver Fonte

core: - no fork unused sockets fix & cleanups
mysql: - strptime XOPEN define

Andrei Pelinescu-Onciul há 21 anos atrás
pai
commit
7a6d1ee1e2
3 ficheiros alterados com 28 adições e 34 exclusões
  1. 1 1
      Makefile.defs
  2. 26 33
      forward.c
  3. 1 0
      socket_info.c

+ 1 - 1
Makefile.defs

@@ -50,7 +50,7 @@ MAIN_NAME=ser
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   99
-EXTRAVERSION = -dev20
+EXTRAVERSION = -dev21
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 26 - 33
forward.c

@@ -95,6 +95,7 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto)
 	socklen_t len;
 	union sockaddr_union from; 
 	struct socket_info* si;
+	struct ip_addr ip;
 
 	if (proto!=PROTO_UDP) {
 		LOG(L_CRIT, "BUG: get_out_socket can only be called for UDP\n");
@@ -118,39 +119,16 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto)
 				strerror(errno));
 		goto error;
 	}
-	for (si=udp_listen; si; si=si->next) {
-		switch(from.s.sa_family) {
-			case AF_INET:	
-						if (si->address.af!=AF_INET)
-								continue;
-						if (memcmp(&si->address.u,
-								&from.sin.sin_addr, 
-								si->address.len)==0)
-							goto found; /*  success */
-						break;
-#if defined(USE_IPV6)
-			case AF_INET6:	
-						if (si->address.af!=AF_INET6)
-								continue;
-						if (memcmp(&si->address.u,
-								&from.sin6.sin6_addr, len)==0)
-							goto found;
-						continue;
-#endif
-			default:	LOG(L_ERR, "ERROR: get_out_socket: "
-									"unknown family: %d\n",
-									from.s.sa_family);
-						goto error;
-		}
-	}
+	su2ip_addr(&ip, &from);
+	si=find_si(&ip, 0, proto);
+	if (si==0) goto error;
+	close(temp_sock);
+	DBG("DEBUG: get_out_socket: socket determined: %p\n", si );
+	return si;
 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: %p\n", si );
-	return si;
 }
 
 
@@ -174,13 +152,28 @@ struct socket_info* get_send_socket(struct sip_msg *msg,
 											msg->force_send_socket->port_no,
 											proto);
 		}
-		if (msg->force_send_socket) 
+		if (msg->force_send_socket && (msg->force_send_socket->socket!=-1)) 
 			return msg->force_send_socket;
-		else
-			LOG(L_WARN, "WARNING: get_send_socket: protocol/port mismatch\n");
+		else{
+			if (msg->force_send_socket->socket==-1)
+				LOG(L_WARN, "WARNING: get_send_socket: not listening"
+						 " on the requested socket, no fork mode?\n");
+			else
+				LOG(L_WARN, "WARNING: get_send_socket: "
+						"protocol/port mismatch\n");
+		}
 	};
 
-	if (mhomed && proto==PROTO_UDP) return get_out_socket(to, proto);
+	if (mhomed && proto==PROTO_UDP){
+		send_sock=get_out_socket(to, proto);
+		if ((send_sock==0) || (send_sock->socket!=-1))
+			return send_sock; /* found or error*/
+		else if (send_sock->socket==-1){
+			LOG(L_WARN, "WARNING: get_send_socket: not listening on the"
+					" requested socket, no fork mode?\n");
+			/* continue: try to use some socket */
+		}
+	}
 
 	send_sock=0;
 	/* check if we need to change the socket (different address families -

+ 1 - 0
socket_info.c

@@ -112,6 +112,7 @@ static inline struct socket_info* new_sock_info(	char* name,
 	si=(struct socket_info*) pkg_malloc(sizeof(struct socket_info));
 	if (si==0) goto error;
 	memset(si, 0, sizeof(struct socket_info));
+	si->socket=-1;
 	si->name.len=strlen(name);
 	si->name.s=(char*)pkg_malloc(si->name.len+1); /* include \0 */
 	if (si->name.s==0) goto error;