Selaa lähdekoodia

- sockaddr_union len fixes (needed for bind/sun)
- new macro sockaddru_len(su) -> returns the len of a sockaddr_union
(sizeof(sockaddr) or sizeof(sockaddr_in6))
- removed the len parameter in udp_send (not needed) and updated the modules
using it (im, msilo, sl, tm)

Andrei Pelinescu-Onciul 23 vuotta sitten
vanhempi
commit
741db91318
8 muutettua tiedostoa jossa 32 lisäystä ja 33 poistoa
  1. 1 2
      action.c
  2. 2 4
      forward.c
  3. 14 1
      ip_addr.h
  4. 1 2
      modules/tm/t_funcs.c
  5. 1 0
      test/ser.cfg
  6. 0 1
      test/stateless.cfg
  7. 12 22
      udp_server.c
  8. 1 1
      udp_server.h

+ 1 - 2
action.c

@@ -152,8 +152,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 				p->tx_bytes+=msg->len;
 				p->tx_bytes+=msg->len;
 				send_sock=get_send_socket(to);
 				send_sock=get_send_socket(to);
 				if (send_sock!=0){
 				if (send_sock!=0){
-					ret=udp_send(send_sock, msg->orig, msg->len, to,
-									sizeof(union sockaddr_union));
+					ret=udp_send(send_sock, msg->orig, msg->len, to);
 				}else{
 				}else{
 					ret=-1;
 					ret=-1;
 				}
 				}

+ 2 - 4
forward.c

@@ -189,8 +189,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
 	DBG("Sending:\n%s.\n", buf);
 	DBG("Sending:\n%s.\n", buf);
 	DBG("orig. len=%d, new_len=%d\n", msg->len, len );
 	DBG("orig. len=%d, new_len=%d\n", msg->len, len );
 	
 	
-	if (udp_send(send_sock, buf, len,  to,
-							sizeof(union sockaddr_union))==-1){
+	if (udp_send(send_sock, buf, len,  to)==-1){
 			ser_error=E_SEND;
 			ser_error=E_SEND;
 			p->errors++;
 			p->errors++;
 			p->ok=0;
 			p->ok=0;
@@ -335,8 +334,7 @@ int forward_reply(struct sip_msg* msg)
 		goto error;
 		goto error;
 	}
 	}
 
 
-	if (udp_send(send_sock, new_buf,new_len,  to,
-				sizeof(union sockaddr_union))==-1)
+	if (udp_send(send_sock, new_buf,new_len,  to)==-1)
 	{
 	{
 		STATS_TX_DROPS;
 		STATS_TX_DROPS;
 		goto error;
 		goto error;

+ 14 - 1
ip_addr.h

@@ -54,10 +54,23 @@ struct socket_info{
 	unsigned short port_no;  /* port number */
 	unsigned short port_no;  /* port number */
 	str port_no_str; /* port number converted to string -- optimization*/
 	str port_no_str; /* port number converted to string -- optimization*/
 	int is_ip; /* 1 if name is an ip address, 0 if not  -- optimization*/
 	int is_ip; /* 1 if name is an ip address, 0 if not  -- optimization*/
+	union sockaddr_union su; 
 };
 };
 
 
 
 
-
+/* len of the sockaddr */
+#ifdef __FreeBSD__
+#define sockaddru_len(su)	((su).s.sa_len)
+#else
+#ifdef USE_IPV6
+#define sockaddru_len(su)	\
+			(((su).s.sa_family==AF_INET6)?sizeof(struct sockaddr_in6):\
+					sizeof(struct sockaddr_in))
+#else
+#define sockaddru_len(su)	sizeof(struct sockaddr_in)
+#endif /*USE_IPV6*/
+#endif /*__FreeBSD__*/
+	
 /* inits an ip_addr with the addr. info from a hostent structure
 /* inits an ip_addr with the addr. info from a hostent structure
  * ip = struct ip_addr*
  * ip = struct ip_addr*
  * he= struct hostent*
  * he= struct hostent*

+ 1 - 2
modules/tm/t_funcs.c

@@ -23,8 +23,7 @@ int send_pr_buffer( struct retr_buf *rb,
 	void *buf, int len, char *function, int line )
 	void *buf, int len, char *function, int line )
 {
 {
 	if (buf && len && rb )
 	if (buf && len && rb )
-		return udp_send( rb->send_sock, buf,
-			len, &rb->to,  sizeof(union sockaddr_union) ) ;
+		return udp_send( rb->send_sock, buf, len, &rb->to) ;
 	else {
 	else {
 		LOG(L_CRIT, "ERROR: sending an empty buffer from %s (%d)\n",
 		LOG(L_CRIT, "ERROR: sending an empty buffer from %s (%d)\n",
 			function, line );
 			function, line );

+ 1 - 0
test/ser.cfg

@@ -3,6 +3,7 @@ check_via=1      # (cmd. line: -v)
 dns=on           # (cmd. line: -r)
 dns=on           # (cmd. line: -r)
 rev_dns=yes      # (cmd. line: -R)
 rev_dns=yes      # (cmd. line: -R)
 fork=no          # (cmd. line: -D)
 fork=no          # (cmd. line: -D)
+fork=yes
 log_stderror=yes # (cmd line: -E)
 log_stderror=yes # (cmd line: -E)
 fifo=/tmp/ser_fifo
 fifo=/tmp/ser_fifo
 # for more info: sip_router -h
 # for more info: sip_router -h

+ 0 - 1
test/stateless.cfg

@@ -7,7 +7,6 @@
 
 
 debug=9          # debug level (cmd line: -dddddddddd)
 debug=9          # debug level (cmd line: -dddddddddd)
 fork=yes          # (cmd. line: -D)
 fork=yes          # (cmd. line: -D)
-fork=no
 log_stderror=yes # (cmd line: -E)
 log_stderror=yes # (cmd line: -E)
 #log_stderror=no	# (cmd line: -E)
 #log_stderror=no	# (cmd line: -E)
 
 

+ 12 - 22
udp_server.c

@@ -113,26 +113,20 @@ int probe_max_receive_buffer( int udp_sock )
 int udp_init(struct socket_info* sock_info)
 int udp_init(struct socket_info* sock_info)
 {
 {
 	union sockaddr_union* addr;
 	union sockaddr_union* addr;
-	int sock_len;
 	int optval;
 	int optval;
 
 
-
+	addr=&sock_info->su;
+/*
 	addr=(union sockaddr_union*)malloc(sizeof(union sockaddr_union));
 	addr=(union sockaddr_union*)malloc(sizeof(union sockaddr_union));
 	if (addr==0){
 	if (addr==0){
 		LOG(L_ERR, "ERROR: udp_init: out of memory\n");
 		LOG(L_ERR, "ERROR: udp_init: out of memory\n");
 		goto error;
 		goto error;
 	}
 	}
-	
+*/
 	if (init_su(addr, &sock_info->address, htons(sock_info->port_no))<0){
 	if (init_su(addr, &sock_info->address, htons(sock_info->port_no))<0){
 		LOG(L_ERR, "ERROR: udp_init: could not init sockaddr_union\n");
 		LOG(L_ERR, "ERROR: udp_init: could not init sockaddr_union\n");
 		goto error;
 		goto error;
 	}
 	}
-	/*
-	addr->sin_family=AF_INET;
-	addr->sin_port=htons(port);
-	addr->sin_addr.s_addr=ip;
-	*/
-
 	
 	
 	sock_info->socket = socket(AF2PF(addr->s.sa_family), SOCK_DGRAM, 0);
 	sock_info->socket = socket(AF2PF(addr->s.sa_family), SOCK_DGRAM, 0);
 	if (sock_info->socket==-1){
 	if (sock_info->socket==-1){
@@ -158,17 +152,11 @@ int udp_init(struct socket_info* sock_info)
 
 
 
 
 	if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error;
 	if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error;
-#ifdef __FreeBSD__
-	sock_len=addr->s.sa_len;
-#else
-	sock_len=sizeof(union sockaddr_union);
-#endif
 	
 	
-
-	if (bind(sock_info->socket,  &addr->s, sock_len)==-1){
+	if (bind(sock_info->socket,  &addr->s, sockaddru_len(*addr))==-1){
 		LOG(L_ERR, "ERROR: udp_init: bind(%x, %p, %d) on %s: %s\n",
 		LOG(L_ERR, "ERROR: udp_init: bind(%x, %p, %d) on %s: %s\n",
 				sock_info->socket, &addr->s, 
 				sock_info->socket, &addr->s, 
-				sock_len,
+				sockaddru_len(*addr),
 				sock_info->address_str.s,
 				sock_info->address_str.s,
 				strerror(errno));
 				strerror(errno));
 	#ifdef USE_IPV6
 	#ifdef USE_IPV6
@@ -179,11 +167,11 @@ int udp_init(struct socket_info* sock_info)
 		goto error;
 		goto error;
 	}
 	}
 
 
-	free(addr);
+/*	free(addr);*/
 	return 0;
 	return 0;
 
 
 error:
 error:
-	if (addr) free(addr);
+/*	if (addr) free(addr);*/
 	return -1;
 	return -1;
 }
 }
 
 
@@ -207,6 +195,7 @@ int udp_rcv_loop()
 		LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n");
 		LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n");
 		goto error;
 		goto error;
 	}
 	}
+	memset(from, 0 , sizeof(union sockaddr_union));
 
 
 	for(;;){
 	for(;;){
 #ifdef DYN_BUF
 #ifdef DYN_BUF
@@ -217,7 +206,7 @@ int udp_rcv_loop()
 			goto error;
 			goto error;
 		}
 		}
 #endif
 #endif
-		fromlen=sizeof(union sockaddr_union);
+		fromlen=sockaddru_len(bind_address->su);
 		len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, &from->s,
 		len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, &from->s,
 											&fromlen);
 											&fromlen);
 		if (len==-1){
 		if (len==-1){
@@ -335,10 +324,11 @@ qa_passed:
 
 
 /* which socket to use? main socket or new one? */
 /* which socket to use? main socket or new one? */
 int udp_send(struct socket_info *source, char *buf, unsigned len,
 int udp_send(struct socket_info *source, char *buf, unsigned len,
-				union sockaddr_union*  to, unsigned tolen)
+				union sockaddr_union*  to)
 {
 {
 
 
 	int n;
 	int n;
+	int tolen;
 
 
 #ifdef DBG_MSG_QA
 #ifdef DBG_MSG_QA
 	/* aborts on error, does nothing otherwise */
 	/* aborts on error, does nothing otherwise */
@@ -348,7 +338,7 @@ int udp_send(struct socket_info *source, char *buf, unsigned len,
 	}
 	}
 #endif
 #endif
 
 
-
+	tolen=sockaddru_len(*to);
 again:
 again:
 	n=sendto(source->socket, buf, len, 0, &to->s, tolen);
 	n=sendto(source->socket, buf, len, 0, &to->s, tolen);
 #ifdef XL_DEBUG
 #ifdef XL_DEBUG

+ 1 - 1
udp_server.h

@@ -15,7 +15,7 @@
 
 
 int udp_init(struct socket_info* si);
 int udp_init(struct socket_info* si);
 int udp_send(struct socket_info* source,char *buf, unsigned len,
 int udp_send(struct socket_info* source,char *buf, unsigned len,
-				union sockaddr_union*  to, unsigned tolen);
+				union sockaddr_union*  to);
 int udp_rcv_loop();
 int udp_rcv_loop();