Explorar o código

ported from stable:
- drop messages with 0 src port immediately$
- error message cleanups for udp checksum error (EAGAIN) and tcp$
"dead children"$
- detect ips between quotes in src_ip or dst_ip$

Andrei Pelinescu-Onciul %!s(int64=21) %!d(string=hai) anos
pai
achega
5260ef3287
Modificáronse 4 ficheiros con 58 adicións e 15 borrados
  1. 1 1
      Makefile.defs
  2. 29 2
      cfg.y
  3. 4 4
      tcp_main.c
  4. 24 8
      udp_server.c

+ 1 - 1
Makefile.defs

@@ -45,7 +45,7 @@ export makefile_defs
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   13
-EXTRAVERSION = -dev-32-usrloc
+EXTRAVERSION = -dev-33-usrloc
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 29 - 2
cfg.y

@@ -55,6 +55,8 @@
  * 2004-04-29  added SOCK_MODE, SOCK_USER & SOCK_GROUP (andrei)
  * 2004-05-03  applied multicast support patch (MCAST_LOOPBACK) from janakj
                added MCAST_TTL (andrei)
+ * 2004-07-05  src_ip & dst_ip will detect ip addresses between quotes
+ *              (andrei)
  */
 
 
@@ -75,6 +77,7 @@
 #include "sr_module.h"
 #include "modparam.h"
 #include "ip_addr.h"
+#include "resolve.h"
 #include "socket_info.h"
 #include "name_alias.h"
 #include "usr_avp.h"
@@ -110,6 +113,8 @@ static void* f_tmp;
 static struct id_list* lst_tmp;
 static int rt;  /* Type of route block for find_export */
 static str* str_tmp;
+static str s_tmp;
+static struct ip_addr* ip_tmp;
 
 void warn(char* s);
 static struct id_list* mk_listen_id(char*, int, int);
@@ -889,8 +894,19 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
 		| SRCIP equalop ipnet	{ $$=mk_elem(	$2, NET_ST,
 												SRCIP_O, $3);
 								}
-		| SRCIP strop STRING	{ $$=mk_elem(	$2, STRING_ST,
+		| SRCIP strop STRING	{	s_tmp.s=$3;
+									s_tmp.len=strlen($3);
+									ip_tmp=str2ip(&s_tmp);
+									if (ip_tmp==0)
+										ip_tmp=str2ip6(&s_tmp);
+									if (ip_tmp){
+										$$=mk_elem(	$2, NET_ST, SRCIP_O,
+												mk_net_bitlen(ip_tmp, 
+														ip_tmp->len*8) );
+									}else{
+										$$=mk_elem(	$2, STRING_ST,
 												SRCIP_O, $3);
+									}
 								}
 		| SRCIP strop host	{ $$=mk_elem(	$2, STRING_ST,
 												SRCIP_O, $3);
@@ -905,8 +921,19 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
 		| DSTIP equalop ipnet	{ $$=mk_elem(	$2, NET_ST,
 												DSTIP_O, $3);
 								}
-		| DSTIP strop STRING	{ $$=mk_elem(	$2, STRING_ST,
+		| DSTIP strop STRING	{	s_tmp.s=$3;
+									s_tmp.len=strlen($3);
+									ip_tmp=str2ip(&s_tmp);
+									if (ip_tmp==0)
+										ip_tmp=str2ip6(&s_tmp);
+									if (ip_tmp){
+										$$=mk_elem(	$2, NET_ST, DSTIP_O,
+												mk_net_bitlen(ip_tmp, 
+														ip_tmp->len*8) );
+									}else{
+										$$=mk_elem(	$2, STRING_ST,
 												DSTIP_O, $3);
+									}
 								}
 		| DSTIP strop host	{ $$=mk_elem(	$2, STRING_ST,
 												DSTIP_O, $3);

+ 4 - 4
tcp_main.c

@@ -1163,9 +1163,8 @@ void tcp_main_loop()
 								sizeof(response));
 				if (bytes==0){
 					/* EOF -> bad, child has died */
-#ifdef EXTRA_DEBUG
-					DBG("DBG: tcp_main_loop: dead tcp child %d\n", r);
-#endif
+					DBG("DBG: tcp_main_loop: dead tcp child %d"
+							" (shutting down?)\n", r);
 					/* don't listen on it any more */
 					FD_CLR(tcp_children[r].unix_sock, &master_set);
 					/*exit(-1);*/
@@ -1228,7 +1227,8 @@ void tcp_main_loop()
 				bytes=recv_all(pt[r].unix_sock, response, sizeof(response));
 				if (bytes==0){
 					/* EOF -> bad, child has died */
-					LOG(L_INFO, "INFO: tcp_main_loop: dead child %d\n", r);
+					DBG("DBG: tcp_main_loop: dead child %d"
+							" (shutting down?)\n", r);
 					/* don't listen on it any more */
 					FD_CLR(pt[r].unix_sock, &master_set);
 					/*exit(-1);*/

+ 24 - 8
udp_server.c

@@ -32,6 +32,8 @@
  *  2003-04-14  set sockopts to TOS low delay (andrei)
  *  2004-05-03  applied multicast support patch from janakj
  *              added set multicast ttl support (andrei)
+ *  2004-07-05  udp_rcv_loop: drop packets with 0 src port + error msg.
+ *              cleanups (andrei)
  */
 
 
@@ -373,7 +375,7 @@ int udp_rcv_loop()
 #else
 	static char buf [BUF_SIZE+1];
 #endif
-
+	char *tmp;
 	union sockaddr_union* from;
 	unsigned int fromlen;
 	struct receive_info ri;
@@ -403,23 +405,35 @@ int udp_rcv_loop()
 		len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, &from->s,
 											&fromlen);
 		if (len==-1){
+			if (errno==EAGAIN){
+				DBG("udp_rcv_loop: packet with bad checksum received\n");
+				continue;
+			}
 			LOG(L_ERR, "ERROR: udp_rcv_loop:recvfrom:[%d] %s\n",
 						errno, strerror(errno));
-			if ((errno==EINTR)||(errno==EAGAIN)||(errno==EWOULDBLOCK)||
-					(errno==ECONNREFUSED))
+			if ((errno==EINTR)||(errno==EWOULDBLOCK)|| (errno==ECONNREFUSED))
 				continue; /* goto skip;*/
 			else goto error;
 		}
 		/* we must 0-term the messages, receive_msg expects it */
 		buf[len]=0; /* no need to save the previous char */
 
+		ri.src_su=*from;
+		su2ip_addr(&ri.src_ip, from);
+		ri.src_port=su_getport(from);
+
 #ifndef NO_ZERO_CHECKS
 		if (len<MIN_UDP_PACKET) {
-			DBG("DEBUG: probing packet received\n");
+			tmp=ip_addr2a(&ri.src_ip);
+			DBG("udp_rcv_loop: probing packet received from %s %d\n",
+					tmp, htons(ri.src_port));
 			continue;
 		}
 		if (buf[len-1]==0) {
-			LOG(L_WARN, "WARNING: upstream bug - 0-terminated packet\n");
+			tmp=ip_addr2a(&ri.src_ip);
+			LOG(L_WARN, "WARNING: udp_rcv_loop: "
+					"upstream bug - 0-terminated packet from %s %d\n",
+					tmp, htons(ri.src_port));
 			len--;
 		}
 #endif
@@ -430,9 +444,11 @@ int udp_rcv_loop()
 			continue;
 		}
 #endif
-		ri.src_su=*from;
-		su2ip_addr(&ri.src_ip, from);
-		ri.src_port=su_getport(from);
+		if (ri.src_port==0){
+			tmp=ip_addr2a(&ri.src_ip);
+			LOG(L_INFO, "udp_rcv_loop: dropping 0 port packet from %s\n", tmp);
+			continue;
+		}
 		
 		
 		/* receive_msg must free buf too!*/