소스 검색

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

Andrei Pelinescu-Onciul 24 년 전
부모
커밋
63fa628f5a
7개의 변경된 파일23개의 추가작업 그리고 10개의 파일을 삭제
  1. 3 0
      action.c
  2. 4 2
      cfg.y
  3. 1 0
      globals.h
  4. 4 2
      main.c
  5. 1 0
      route_struct.c
  6. 5 1
      sip_router.cfg
  7. 5 5
      test/mobile61.cfg

+ 3 - 0
action.c

@@ -17,6 +17,9 @@
 #include <sys/socket.h>
 #include <netdb.h>
 #include <stdlib.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
 
 /* ret= 0 if action -> end of lis t(e.g DROP), >0
    and >0 on error */

+ 4 - 2
cfg.y

@@ -7,6 +7,7 @@
 %{
 
 #include <stdlib.h>
+#include <stdio.h>
 #include "route_struct.h"
 #include "globals.h"
 #include "route.h"
@@ -154,7 +155,7 @@ route_stm:	ROUTE LBRACE rules RBRACE { push($3, &rlist[DEFAULT_RT]); }
 
 rules:	rules rule { push($2, &$1); $$=$1; 
 						printf(": rules->rules(%x) rule(%x)\n", $1,$2);}
-	| rule {$$=$1; printf(": rules->rule (%x)\n",$1) }
+	| rule {$$=$1; printf(": rules->rule (%x)\n",$1); }
 	| rules error { $$=0; yyerror("invalid rule"); }
 	 ;
 
@@ -266,7 +267,7 @@ net4:	ipv4 SLASH ipv4	{ $$=mk_net($1, $3); }
 								yyerror("invalid bit number in netmask");
 								$$=0;
 							}else{
-								$$=mk_net($1, htonl((1<<$3)-1));
+								$$=mk_net($1, ((1<<$3)-1));
 							}
 						}
 	| ipv4				{ $$=mk_net($1, 0xffffffff); }
@@ -424,6 +425,7 @@ void yyerror(char* s)
 {
 	fprintf(stderr, "parse error (%d,%d-%d): %s\n", line, startcolumn, 
 			column, s);
+	cfg_errors++;
 }
 
 /*

+ 1 - 0
globals.h

@@ -26,5 +26,6 @@ extern int log_stderr;
 extern int check_via;
 extern int received_dns;
 
+extern int cfg_errors;
 
 #endif

+ 4 - 2
main.c

@@ -87,6 +87,8 @@ int process_no = 0;
 #ifdef ROUTE_SRV
 #endif
 
+/* cfg parsing */
+int cfg_errors=0;
 
 
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
@@ -330,8 +332,8 @@ int main(int argc, char** argv)
 	}
 	
 	yyin=cfg_stream;
-	if (yyparse()!=0){
-		fprintf(stderr, "ERROR: config parser failure\n");
+	if ((yyparse()!=0)||(cfg_errors)){
+		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
 		goto error;
 	}
 	

+ 1 - 0
route_struct.c

@@ -9,6 +9,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 
 struct expr* mk_exp(int op, struct expr* left, struct expr* right)

+ 5 - 1
sip_router.cfg

@@ -4,11 +4,15 @@
 #  method_re   sip_uri_re      dest_host
 # (warning: re cannot contain space)
 
+<<<<<<< sip_router.cfg
+.			.				  centauri 
+=======
 #.			.				   centauri
 .*			.*				   mobile50 
 .			.				   fox.iptel.org
+>>>>>>> 1.6
 ^R.*        ^sip:.*@dorian.*   ekina.fokus.gmd.de        
-^INVITE     .*                 ape:5061             # my laptop
+#^INVITE     .*                 ape:5061             # my laptop
 .           .                  192.168.46.55
 .*			.*andrei		   helios.fokus.gmd.de
 

+ 5 - 5
test/mobile61.cfg

@@ -10,14 +10,14 @@ route{
 }
 
 route[1]{
-	src_ip=192.168.46.61  log("possible loop, dropping\n"); drop;
-	src_ip==192.168.46.0/24 route(2);
-	src_ip=0.0.0.0/0 log(1, "we'll drop this one too\n"); drop
+	src_ip==192.168.46.61  log("possible loop, dropping\n"); drop;
+	(src_ip==192.168.46.0/24) log("routing with rt2\n");route(2); log("we're back\n");
+	src_ip==0.0.0.0/0 log(1, "we'll drop this one too\n"); drop;
 }
 
 route[2]{
 	(method~='^ACK' and uri~='.*fokus') forward("fox.iptel.org");
-	method~='^INV' forward(193.175.135.179); /* dorian */
+	! method~='^INV' forward(193.175.135.179); /* dorian */
 	method~='.' log("spying...\n"); send(dorian,8000); \
-						forward("fox.iptel.org);
+						forward("fox.iptel.org");
 }