Browse code

- 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:18:27
Showing 5 changed files
... ...
@@ -45,7 +45,7 @@ export makefile_defs
45 45
 VERSION = 0
46 46
 PATCHLEVEL = 8
47 47
 SUBLEVEL =   12
48
-EXTRAVERSION = -1rc3
48
+EXTRAVERSION = -1rc4
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]")
... ...
@@ -2,11 +2,9 @@ $Id$
2 2
 
3 3
 ( - todo, x - done)
4 4
 
5
-- error <-> warning for bad checksum and sport==0
6
-- drop sport==0 messages
7
-- check all parse_headers occurences (and fix xlog!)
8 5
 - loose_roote : use parse_orig_uri instead of parse_uri
9 6
 
7
+
10 8
 - grep parse_uri & replace with parse_sip_msg_uri (e.g do_action!)
11 9
 x update AUTHORS, debian/copyright, ser.8, ser.cfg.5 from stable
12 10
 x update Makefile*  from stable
... ...
@@ -47,6 +47,8 @@
47 47
  *             added msg:len (andrei)
48 48
  * 2003-10-11  if(){} doesn't require a ';' after it anymore (andrei)
49 49
  * 2003-11-20  added {tcp_connect, tcp_send, tls_*}_timeout (andrei)
50
+ * 2004-07-05  src_ip & dst_ip will detect ip addresses between quotes
51
+ *              (andrei)
50 52
  */
51 53
 
52 54
 
... ...
@@ -67,9 +69,11 @@
67 69
 #include "sr_module.h"
68 70
 #include "modparam.h"
69 71
 #include "ip_addr.h"
72
+#include "resolve.h"
70 73
 #include "name_alias.h"
71 74
 #include "ut.h"
72 75
 
76
+
73 77
 #include "config.h"
74 78
 #ifdef USE_TLS
75 79
 #include "tls/tls_config.h"
... ...
@@ -96,6 +100,8 @@ static void* f_tmp;
96 100
 static struct id_list* lst_tmp;
97 101
 static int rt;  /* Type of route block for find_export */
98 102
 static str* str_tmp;
103
+static str s_tmp;
104
+static struct ip_addr* ip_tmp;
99 105
 
100 106
 void warn(char* s);
101 107
  
... ...
@@ -809,8 +815,19 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
809 815
 		| SRCIP equalop ipnet	{ $$=mk_elem(	$2, NET_ST,
810 816
 												SRCIP_O, $3);
811 817
 								}
812
-		| SRCIP strop STRING	{ $$=mk_elem(	$2, STRING_ST,
818
+		| SRCIP strop STRING	{	s_tmp.s=$3;
819
+									s_tmp.len=strlen($3);
820
+									ip_tmp=str2ip(&s_tmp);
821
+									if (ip_tmp==0)
822
+										ip_tmp=str2ip6(&s_tmp);
823
+									if (ip_tmp){
824
+										$$=mk_elem(	$2, NET_ST, SRCIP_O,
825
+												mk_net_bitlen(ip_tmp, 
826
+														ip_tmp->len*8) );
827
+									}else{
828
+										$$=mk_elem(	$2, STRING_ST,
813 829
 												SRCIP_O, $3);
830
+									}
814 831
 								}
815 832
 		| SRCIP strop host	{ $$=mk_elem(	$2, STRING_ST,
816 833
 												SRCIP_O, $3);
... ...
@@ -825,8 +842,19 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
825 842
 		| DSTIP equalop ipnet	{ $$=mk_elem(	$2, NET_ST,
826 843
 												DSTIP_O, $3);
827 844
 								}
828
-		| DSTIP strop STRING	{ $$=mk_elem(	$2, STRING_ST,
845
+		| DSTIP strop STRING	{	s_tmp.s=$3;
846
+									s_tmp.len=strlen($3);
847
+									ip_tmp=str2ip(&s_tmp);
848
+									if (ip_tmp==0)
849
+										ip_tmp=str2ip6(&s_tmp);
850
+									if (ip_tmp){
851
+										$$=mk_elem(	$2, NET_ST, DSTIP_O,
852
+												mk_net_bitlen(ip_tmp, 
853
+														ip_tmp->len*8) );
854
+									}else{
855
+										$$=mk_elem(	$2, STRING_ST,
829 856
 												DSTIP_O, $3);
857
+									}
830 858
 								}
831 859
 		| DSTIP strop host	{ $$=mk_elem(	$2, STRING_ST,
832 860
 												DSTIP_O, $3);
... ...
@@ -1069,9 +1069,8 @@ void tcp_main_loop()
1069 1069
 								sizeof(response));
1070 1070
 				if (bytes==0){
1071 1071
 					/* EOF -> bad, child has died */
1072
-#ifdef EXTRA_DEBUG
1073
-					DBG("DBG: tcp_main_loop: dead tcp child %d\n", r);
1074
-#endif
1072
+					DBG("DBG: tcp_main_loop: dead tcp child %d"
1073
+							" (shutting down?)\n", r);
1075 1074
 					/* don't listen on it any more */
1076 1075
 					FD_CLR(tcp_children[r].unix_sock, &master_set);
1077 1076
 					/*exit(-1);*/
... ...
@@ -1134,7 +1133,8 @@ void tcp_main_loop()
1134 1133
 				bytes=recv_all(pt[r].unix_sock, response, sizeof(response));
1135 1134
 				if (bytes==0){
1136 1135
 					/* EOF -> bad, child has died */
1137
-					LOG(L_CRIT, "BUG: tcp_main_loop: dead child %d\n", r);
1136
+					DBG("DBG: tcp_main_loop: dead child %d"
1137
+							" (shutting down?)\n", r);
1138 1138
 					/* don't listen on it any more */
1139 1139
 					FD_CLR(pt[r].unix_sock, &master_set);
1140 1140
 					/*exit(-1);*/
... ...
@@ -30,6 +30,8 @@
30 30
  *  2003-02-10  undoed the above changes (andrei)
31 31
  *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
32 32
  *  2003-04-14  set sockopts to TOS low delay (andrei)
33
+ *  2004-07-05  udp_rcv_loop: drop packets with 0 src port + error msg.
34
+ *              cleanups (andrei)
33 35
  */
34 36
 
35 37
 
... ...
@@ -289,7 +291,7 @@ int udp_rcv_loop()
289 291
 #else
290 292
 	static char buf [BUF_SIZE+1];
291 293
 #endif
292
-
294
+	char *tmp;
293 295
 	union sockaddr_union* from;
294 296
 	unsigned int fromlen;
295 297
 	struct receive_info ri;
... ...
@@ -319,23 +321,35 @@ int udp_rcv_loop()
319 321
 		len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, &from->s,
320 322
 											&fromlen);
321 323
 		if (len==-1){
324
+			if (errno==EAGAIN){
325
+				DBG("udp_rcv_loop: packet with bad checksum received\n");
326
+				continue;
327
+			}
322 328
 			LOG(L_ERR, "ERROR: udp_rcv_loop:recvfrom:[%d] %s\n",
323 329
 						errno, strerror(errno));
324
-			if ((errno==EINTR)||(errno==EAGAIN)||(errno==EWOULDBLOCK)||
325
-					(errno==ECONNREFUSED))
330
+			if ((errno==EINTR)||(errno==EWOULDBLOCK)|| (errno==ECONNREFUSED))
326 331
 				continue; /* goto skip;*/
327 332
 			else goto error;
328 333
 		}
329 334
 		/* we must 0-term the messages, receive_msg expects it */
330 335
 		buf[len]=0; /* no need to save the previous char */
331 336
 
337
+		ri.src_su=*from;
338
+		su2ip_addr(&ri.src_ip, from);
339
+		ri.src_port=su_getport(from);
340
+
332 341
 #ifndef NO_ZERO_CHECKS
333 342
 		if (len<MIN_UDP_PACKET) {
334
-			DBG("DEBUG: probing packet received\n");
343
+			tmp=ip_addr2a(&ri.src_ip);
344
+			DBG("udp_rcv_loop: probing packet received from %s %d\n",
345
+					tmp, htons(ri.src_port));
335 346
 			continue;
336 347
 		}
337 348
 		if (buf[len-1]==0) {
338
-			LOG(L_WARN, "WARNING: upstream bug - 0-terminated packet\n");
349
+			tmp=ip_addr2a(&ri.src_ip);
350
+			LOG(L_WARN, "WARNING: udp_rcv_loop: "
351
+					"upstream bug - 0-terminated packet from %s %d\n",
352
+					tmp, htons(ri.src_port));
339 353
 			len--;
340 354
 		}
341 355
 #endif
... ...
@@ -346,9 +360,11 @@ int udp_rcv_loop()
346 360
 			continue;
347 361
 		}
348 362
 #endif
349
-		ri.src_su=*from;
350
-		su2ip_addr(&ri.src_ip, from);
351
-		ri.src_port=su_getport(from);
363
+		if (ri.src_port==0){
364
+			tmp=ip_addr2a(&ri.src_ip);
365
+			LOG(L_INFO, "udp_rcv_loop: dropping 0 port packet from %s\n", tmp);
366
+			continue;
367
+		}
352 368
 		
353 369
 		
354 370
 		/* receive_msg must free buf too!*/