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 75
 #include "sr_module.h"
76 76
 #include "modparam.h"
77 77
 #include "ip_addr.h"
78
+#include "resolve.h"
78 79
 #include "socket_info.h"
79 80
 #include "name_alias.h"
80 81
 #include "usr_avp.h"
... ...
@@ -110,6 +113,8 @@ static void* f_tmp;
110 110
 static struct id_list* lst_tmp;
111 111
 static int rt;  /* Type of route block for find_export */
112 112
 static str* str_tmp;
113
+static str s_tmp;
114
+static struct ip_addr* ip_tmp;
113 115
 
114 116
 void warn(char* s);
115 117
 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 889
 		| SRCIP equalop ipnet	{ $$=mk_elem(	$2, NET_ST,
890 890
 												SRCIP_O, $3);
891 891
 								}
892
-		| SRCIP strop STRING	{ $$=mk_elem(	$2, STRING_ST,
892
+		| SRCIP strop STRING	{	s_tmp.s=$3;
893
+									s_tmp.len=strlen($3);
894
+									ip_tmp=str2ip(&s_tmp);
895
+									if (ip_tmp==0)
896
+										ip_tmp=str2ip6(&s_tmp);
897
+									if (ip_tmp){
898
+										$$=mk_elem(	$2, NET_ST, SRCIP_O,
899
+												mk_net_bitlen(ip_tmp, 
900
+														ip_tmp->len*8) );
901
+									}else{
902
+										$$=mk_elem(	$2, STRING_ST,
893 903
 												SRCIP_O, $3);
904
+									}
894 905
 								}
895 906
 		| SRCIP strop host	{ $$=mk_elem(	$2, STRING_ST,
896 907
 												SRCIP_O, $3);
... ...
@@ -905,8 +921,19 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
905 905
 		| DSTIP equalop ipnet	{ $$=mk_elem(	$2, NET_ST,
906 906
 												DSTIP_O, $3);
907 907
 								}
908
-		| DSTIP strop STRING	{ $$=mk_elem(	$2, STRING_ST,
908
+		| DSTIP strop STRING	{	s_tmp.s=$3;
909
+									s_tmp.len=strlen($3);
910
+									ip_tmp=str2ip(&s_tmp);
911
+									if (ip_tmp==0)
912
+										ip_tmp=str2ip6(&s_tmp);
913
+									if (ip_tmp){
914
+										$$=mk_elem(	$2, NET_ST, DSTIP_O,
915
+												mk_net_bitlen(ip_tmp, 
916
+														ip_tmp->len*8) );
917
+									}else{
918
+										$$=mk_elem(	$2, STRING_ST,
909 919
 												DSTIP_O, $3);
920
+									}
910 921
 								}
911 922
 		| DSTIP strop host	{ $$=mk_elem(	$2, STRING_ST,
912 923
 												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 1228
 				bytes=recv_all(pt[r].unix_sock, response, sizeof(response));
1229 1229
 				if (bytes==0){
1230 1230
 					/* EOF -> bad, child has died */
1231
-					LOG(L_INFO, "INFO: tcp_main_loop: dead child %d\n", r);
1231
+					DBG("DBG: tcp_main_loop: dead child %d"
1232
+							" (shutting down?)\n", r);
1232 1233
 					/* don't listen on it any more */
1233 1234
 					FD_CLR(pt[r].unix_sock, &master_set);
1234 1235
 					/*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 373
 #else
374 374
 	static char buf [BUF_SIZE+1];
375 375
 #endif
376
-
376
+	char *tmp;
377 377
 	union sockaddr_union* from;
378 378
 	unsigned int fromlen;
379 379
 	struct receive_info ri;
... ...
@@ -403,23 +405,35 @@ int udp_rcv_loop()
403 403
 		len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, &from->s,
404 404
 											&fromlen);
405 405
 		if (len==-1){
406
+			if (errno==EAGAIN){
407
+				DBG("udp_rcv_loop: packet with bad checksum received\n");
408
+				continue;
409
+			}
406 410
 			LOG(L_ERR, "ERROR: udp_rcv_loop:recvfrom:[%d] %s\n",
407 411
 						errno, strerror(errno));
408
-			if ((errno==EINTR)||(errno==EAGAIN)||(errno==EWOULDBLOCK)||
409
-					(errno==ECONNREFUSED))
412
+			if ((errno==EINTR)||(errno==EWOULDBLOCK)|| (errno==ECONNREFUSED))
410 413
 				continue; /* goto skip;*/
411 414
 			else goto error;
412 415
 		}
413 416
 		/* we must 0-term the messages, receive_msg expects it */
414 417
 		buf[len]=0; /* no need to save the previous char */
415 418
 
419
+		ri.src_su=*from;
420
+		su2ip_addr(&ri.src_ip, from);
421
+		ri.src_port=su_getport(from);
422
+
416 423
 #ifndef NO_ZERO_CHECKS
417 424
 		if (len<MIN_UDP_PACKET) {
418
-			DBG("DEBUG: probing packet received\n");
425
+			tmp=ip_addr2a(&ri.src_ip);
426
+			DBG("udp_rcv_loop: probing packet received from %s %d\n",
427
+					tmp, htons(ri.src_port));
419 428
 			continue;
420 429
 		}
421 430
 		if (buf[len-1]==0) {
422
-			LOG(L_WARN, "WARNING: upstream bug - 0-terminated packet\n");
431
+			tmp=ip_addr2a(&ri.src_ip);
432
+			LOG(L_WARN, "WARNING: udp_rcv_loop: "
433
+					"upstream bug - 0-terminated packet from %s %d\n",
434
+					tmp, htons(ri.src_port));
423 435
 			len--;
424 436
 		}
425 437
 #endif
... ...
@@ -430,9 +444,11 @@ int udp_rcv_loop()
430 430
 			continue;
431 431
 		}
432 432
 #endif
433
-		ri.src_su=*from;
434
-		su2ip_addr(&ri.src_ip, from);
435
-		ri.src_port=su_getport(from);
433
+		if (ri.src_port==0){
434
+			tmp=ip_addr2a(&ri.src_ip);
435
+			LOG(L_INFO, "udp_rcv_loop: dropping 0 port packet from %s\n", tmp);
436
+			continue;
437
+		}
436 438
 		
437 439
 		
438 440
 		/* receive_msg must free buf too!*/