Browse code

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 authored on 05/07/2004 15:19:14
Showing 4 changed files
... ...
@@ -45,7 +45,7 @@ export makefile_defs
45 45
 VERSION = 0
46 46
 PATCHLEVEL = 8
47 47
 SUBLEVEL =   13
48
-EXTRAVERSION = -dev-32-usrloc
48
+EXTRAVERSION = -dev-33-usrloc
49 49
 
50 50
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
51 51
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -55,6 +55,8 @@
55 55
  * 2004-04-29  added SOCK_MODE, SOCK_USER & SOCK_GROUP (andrei)
56 56
  * 2004-05-03  applied multicast support patch (MCAST_LOOPBACK) from janakj
57 57
                added MCAST_TTL (andrei)
58
+ * 2004-07-05  src_ip & dst_ip will detect ip addresses between quotes
59
+ *              (andrei)
58 60
  */
59 61
 
60 62
 
... ...
@@ -75,6 +77,7 @@
75 77
 #include "sr_module.h"
76 78
 #include "modparam.h"
77 79
 #include "ip_addr.h"
80
+#include "resolve.h"
78 81
 #include "socket_info.h"
79 82
 #include "name_alias.h"
80 83
 #include "usr_avp.h"
... ...
@@ -110,6 +113,8 @@ static void* f_tmp;
110 113
 static struct id_list* lst_tmp;
111 114
 static int rt;  /* Type of route block for find_export */
112 115
 static str* str_tmp;
116
+static str s_tmp;
117
+static struct ip_addr* ip_tmp;
113 118
 
114 119
 void warn(char* s);
115 120
 static struct id_list* mk_listen_id(char*, int, int);
... ...
@@ -889,8 +894,19 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
889 894
 		| SRCIP equalop ipnet	{ $$=mk_elem(	$2, NET_ST,
890 895
 												SRCIP_O, $3);
891 896
 								}
892
-		| SRCIP strop STRING	{ $$=mk_elem(	$2, STRING_ST,
897
+		| SRCIP strop STRING	{	s_tmp.s=$3;
898
+									s_tmp.len=strlen($3);
899
+									ip_tmp=str2ip(&s_tmp);
900
+									if (ip_tmp==0)
901
+										ip_tmp=str2ip6(&s_tmp);
902
+									if (ip_tmp){
903
+										$$=mk_elem(	$2, NET_ST, SRCIP_O,
904
+												mk_net_bitlen(ip_tmp, 
905
+														ip_tmp->len*8) );
906
+									}else{
907
+										$$=mk_elem(	$2, STRING_ST,
893 908
 												SRCIP_O, $3);
909
+									}
894 910
 								}
895 911
 		| SRCIP strop host	{ $$=mk_elem(	$2, STRING_ST,
896 912
 												SRCIP_O, $3);
... ...
@@ -905,8 +921,19 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
905 921
 		| DSTIP equalop ipnet	{ $$=mk_elem(	$2, NET_ST,
906 922
 												DSTIP_O, $3);
907 923
 								}
908
-		| DSTIP strop STRING	{ $$=mk_elem(	$2, STRING_ST,
924
+		| DSTIP strop STRING	{	s_tmp.s=$3;
925
+									s_tmp.len=strlen($3);
926
+									ip_tmp=str2ip(&s_tmp);
927
+									if (ip_tmp==0)
928
+										ip_tmp=str2ip6(&s_tmp);
929
+									if (ip_tmp){
930
+										$$=mk_elem(	$2, NET_ST, DSTIP_O,
931
+												mk_net_bitlen(ip_tmp, 
932
+														ip_tmp->len*8) );
933
+									}else{
934
+										$$=mk_elem(	$2, STRING_ST,
909 935
 												DSTIP_O, $3);
936
+									}
910 937
 								}
911 938
 		| DSTIP strop host	{ $$=mk_elem(	$2, STRING_ST,
912 939
 												DSTIP_O, $3);
... ...
@@ -1163,9 +1163,8 @@ void tcp_main_loop()
1163 1163
 								sizeof(response));
1164 1164
 				if (bytes==0){
1165 1165
 					/* EOF -> bad, child has died */
1166
-#ifdef EXTRA_DEBUG
1167
-					DBG("DBG: tcp_main_loop: dead tcp child %d\n", r);
1168
-#endif
1166
+					DBG("DBG: tcp_main_loop: dead tcp child %d"
1167
+							" (shutting down?)\n", r);
1169 1168
 					/* don't listen on it any more */
1170 1169
 					FD_CLR(tcp_children[r].unix_sock, &master_set);
1171 1170
 					/*exit(-1);*/
... ...
@@ -1228,7 +1227,8 @@ void tcp_main_loop()
1228 1227
 				bytes=recv_all(pt[r].unix_sock, response, sizeof(response));
1229 1228
 				if (bytes==0){
1230 1229
 					/* EOF -> bad, child has died */
1231
-					LOG(L_INFO, "INFO: tcp_main_loop: dead child %d\n", r);
1230
+					DBG("DBG: tcp_main_loop: dead child %d"
1231
+							" (shutting down?)\n", r);
1232 1232
 					/* don't listen on it any more */
1233 1233
 					FD_CLR(pt[r].unix_sock, &master_set);
1234 1234
 					/*exit(-1);*/
... ...
@@ -32,6 +32,8 @@
32 32
  *  2003-04-14  set sockopts to TOS low delay (andrei)
33 33
  *  2004-05-03  applied multicast support patch from janakj
34 34
  *              added set multicast ttl support (andrei)
35
+ *  2004-07-05  udp_rcv_loop: drop packets with 0 src port + error msg.
36
+ *              cleanups (andrei)
35 37
  */
36 38
 
37 39
 
... ...
@@ -373,7 +375,7 @@ int udp_rcv_loop()
373 375
 #else
374 376
 	static char buf [BUF_SIZE+1];
375 377
 #endif
376
-
378
+	char *tmp;
377 379
 	union sockaddr_union* from;
378 380
 	unsigned int fromlen;
379 381
 	struct receive_info ri;
... ...
@@ -403,23 +405,35 @@ int udp_rcv_loop()
403 405
 		len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, &from->s,
404 406
 											&fromlen);
405 407
 		if (len==-1){
408
+			if (errno==EAGAIN){
409
+				DBG("udp_rcv_loop: packet with bad checksum received\n");
410
+				continue;
411
+			}
406 412
 			LOG(L_ERR, "ERROR: udp_rcv_loop:recvfrom:[%d] %s\n",
407 413
 						errno, strerror(errno));
408
-			if ((errno==EINTR)||(errno==EAGAIN)||(errno==EWOULDBLOCK)||
409
-					(errno==ECONNREFUSED))
414
+			if ((errno==EINTR)||(errno==EWOULDBLOCK)|| (errno==ECONNREFUSED))
410 415
 				continue; /* goto skip;*/
411 416
 			else goto error;
412 417
 		}
413 418
 		/* we must 0-term the messages, receive_msg expects it */
414 419
 		buf[len]=0; /* no need to save the previous char */
415 420
 
421
+		ri.src_su=*from;
422
+		su2ip_addr(&ri.src_ip, from);
423
+		ri.src_port=su_getport(from);
424
+
416 425
 #ifndef NO_ZERO_CHECKS
417 426
 		if (len<MIN_UDP_PACKET) {
418
-			DBG("DEBUG: probing packet received\n");
427
+			tmp=ip_addr2a(&ri.src_ip);
428
+			DBG("udp_rcv_loop: probing packet received from %s %d\n",
429
+					tmp, htons(ri.src_port));
419 430
 			continue;
420 431
 		}
421 432
 		if (buf[len-1]==0) {
422
-			LOG(L_WARN, "WARNING: upstream bug - 0-terminated packet\n");
433
+			tmp=ip_addr2a(&ri.src_ip);
434
+			LOG(L_WARN, "WARNING: udp_rcv_loop: "
435
+					"upstream bug - 0-terminated packet from %s %d\n",
436
+					tmp, htons(ri.src_port));
423 437
 			len--;
424 438
 		}
425 439
 #endif
... ...
@@ -430,9 +444,11 @@ int udp_rcv_loop()
430 444
 			continue;
431 445
 		}
432 446
 #endif
433
-		ri.src_su=*from;
434
-		su2ip_addr(&ri.src_ip, from);
435
-		ri.src_port=su_getport(from);
447
+		if (ri.src_port==0){
448
+			tmp=ip_addr2a(&ri.src_ip);
449
+			LOG(L_INFO, "udp_rcv_loop: dropping 0 port packet from %s\n", tmp);
450
+			continue;
451
+		}
436 452
 		
437 453
 		
438 454
 		/* receive_msg must free buf too!*/