Browse code

- minor parsing bug fixes - bsd fixes - added cfg_errors, a global inc'ed from yyerror

Andrei Pelinescu-Onciul authored on 21/09/2001 23:47:10
Showing 7 changed files
... ...
@@ -17,6 +17,9 @@
17 17
 #include <sys/socket.h>
18 18
 #include <netdb.h>
19 19
 #include <stdlib.h>
20
+#include <netinet/in.h>
21
+#include <arpa/inet.h>
22
+
20 23
 
21 24
 /* ret= 0 if action -> end of lis t(e.g DROP), >0
22 25
    and >0 on error */
... ...
@@ -7,6 +7,7 @@
7 7
 %{
8 8
 
9 9
 #include <stdlib.h>
10
+#include <stdio.h>
10 11
 #include "route_struct.h"
11 12
 #include "globals.h"
12 13
 #include "route.h"
... ...
@@ -154,7 +155,7 @@ route_stm:	ROUTE LBRACE rules RBRACE { push($3, &rlist[DEFAULT_RT]); }
154 154
 
155 155
 rules:	rules rule { push($2, &$1); $$=$1; 
156 156
 						printf(": rules->rules(%x) rule(%x)\n", $1,$2);}
157
-	| rule {$$=$1; printf(": rules->rule (%x)\n",$1) }
157
+	| rule {$$=$1; printf(": rules->rule (%x)\n",$1); }
158 158
 	| rules error { $$=0; yyerror("invalid rule"); }
159 159
 	 ;
160 160
 
... ...
@@ -266,7 +267,7 @@ net4:	ipv4 SLASH ipv4	{ $$=mk_net($1, $3); }
266 266
 								yyerror("invalid bit number in netmask");
267 267
 								$$=0;
268 268
 							}else{
269
-								$$=mk_net($1, htonl((1<<$3)-1));
269
+								$$=mk_net($1, ((1<<$3)-1));
270 270
 							}
271 271
 						}
272 272
 	| ipv4				{ $$=mk_net($1, 0xffffffff); }
... ...
@@ -424,6 +425,7 @@ void yyerror(char* s)
424 424
 {
425 425
 	fprintf(stderr, "parse error (%d,%d-%d): %s\n", line, startcolumn, 
426 426
 			column, s);
427
+	cfg_errors++;
427 428
 }
428 429
 
429 430
 /*
... ...
@@ -26,5 +26,6 @@ extern int log_stderr;
26 26
 extern int check_via;
27 27
 extern int received_dns;
28 28
 
29
+extern int cfg_errors;
29 30
 
30 31
 #endif
... ...
@@ -87,6 +87,8 @@ int process_no = 0;
87 87
 #ifdef ROUTE_SRV
88 88
 #endif
89 89
 
90
+/* cfg parsing */
91
+int cfg_errors=0;
90 92
 
91 93
 
92 94
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
... ...
@@ -330,8 +332,8 @@ int main(int argc, char** argv)
330 330
 	}
331 331
 	
332 332
 	yyin=cfg_stream;
333
-	if (yyparse()!=0){
334
-		fprintf(stderr, "ERROR: config parser failure\n");
333
+	if ((yyparse()!=0)||(cfg_errors)){
334
+		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
335 335
 		goto error;
336 336
 	}
337 337
 	
... ...
@@ -9,6 +9,7 @@
9 9
 
10 10
 #include <stdio.h>
11 11
 #include <stdlib.h>
12
+#include <sys/types.h>
12 13
 #include <netinet/in.h>
13 14
 
14 15
 struct expr* mk_exp(int op, struct expr* left, struct expr* right)
... ...
@@ -4,11 +4,15 @@
4 4
 #  method_re   sip_uri_re      dest_host
5 5
 # (warning: re cannot contain space)
6 6
 
7
+<<<<<<< sip_router.cfg
8
+.			.				  centauri 
9
+=======
7 10
 #.			.				   centauri
8 11
 .*			.*				   mobile50 
9 12
 .			.				   fox.iptel.org
13
+>>>>>>> 1.6
10 14
 ^R.*        ^sip:.*@dorian.*   ekina.fokus.gmd.de        
11
-^INVITE     .*                 ape:5061             # my laptop
15
+#^INVITE     .*                 ape:5061             # my laptop
12 16
 .           .                  192.168.46.55
13 17
 .*			.*andrei		   helios.fokus.gmd.de
14 18
 
... ...
@@ -10,14 +10,14 @@ route{
10 10
 }
11 11
 
12 12
 route[1]{
13
-	src_ip=192.168.46.61  log("possible loop, dropping\n"); drop;
14
-	src_ip==192.168.46.0/24 route(2);
15
-	src_ip=0.0.0.0/0 log(1, "we'll drop this one too\n"); drop
13
+	src_ip==192.168.46.61  log("possible loop, dropping\n"); drop;
14
+	(src_ip==192.168.46.0/24) log("routing with rt2\n");route(2); log("we're back\n");
15
+	src_ip==0.0.0.0/0 log(1, "we'll drop this one too\n"); drop;
16 16
 }
17 17
 
18 18
 route[2]{
19 19
 	(method~='^ACK' and uri~='.*fokus') forward("fox.iptel.org");
20
-	method~='^INV' forward(193.175.135.179); /* dorian */
20
+	! method~='^INV' forward(193.175.135.179); /* dorian */
21 21
 	method~='.' log("spying...\n"); send(dorian,8000); \
22
-						forward("fox.iptel.org);
22
+						forward("fox.iptel.org");
23 23
 }