Преглед изворни кода

- added dst_port, proto (== tcp, udp, tls), af (==inet, inet6) to the config
script
- fixed a makefile dep. problem (lex.yy.c : cfg.tab.h & cfg.tab.h: cfg.y)

Andrei Pelinescu-Onciul пре 22 година
родитељ
комит
aeb805d516
6 измењених фајлова са 67 додато и 14 уклоњено
  1. 2 2
      Makefile
  2. 1 1
      Makefile.defs
  3. 24 0
      cfg.lex
  4. 19 2
      cfg.y
  5. 20 8
      route.c
  6. 1 1
      route_struct.h

+ 2 - 2
Makefile

@@ -60,10 +60,10 @@ include Makefile.rules
 
 $(NAME): static_modules
 
-lex.yy.c: cfg.lex $(ALLDEP)
+lex.yy.c: cfg.lex cfg.tab.h $(ALLDEP)
 	$(LEX) $<
 
-cfg.tab.c: cfg.y  $(ALLDEP)
+cfg.tab.c cfg.tab.h: cfg.y  $(ALLDEP)
 	$(YACC) $(YACC_FLAGS) $<
 
 .PHONY: all

+ 1 - 1
Makefile.defs

@@ -18,7 +18,7 @@
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   11
-EXTRAVERSION = pre9-opt_l
+EXTRAVERSION = pre9-new_opts
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 24 - 0
cfg.lex

@@ -31,6 +31,7 @@
  *  2003-01-29  src_port added (jiri)
  *  2003-01-23  mhomed added (jiri)
  *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ *  2003-04-01  added dst_port, proto (tcp, udp, tls), af(inet, inet6) (andrei)
  */
 
 
@@ -41,6 +42,7 @@
 	#include "mem/mem.h"
 	#include <string.h>
 	#include <stdlib.h>
+	#include "ip_addr.h"
 
 
 	/* states */
@@ -108,6 +110,9 @@ URI		uri
 SRCIP	src_ip
 SRCPORT	src_port
 DSTIP	dst_ip
+DSTPORT	dst_port
+PROTO	proto
+AF		af
 MYSELF	myself
 /* operators */
 EQUAL	=
@@ -147,6 +152,11 @@ MODPARAM        modparam
 /* values */
 YES			"yes"|"true"|"on"|"enable"
 NO			"no"|"false"|"off"|"disable"
+UDP			"udp"
+TCP			"tcp"
+TLS			"tls"
+INET		"inet"
+INET6		"inet6"
 
 LETTER		[a-zA-Z]
 DIGIT		[0-9]
@@ -221,6 +231,9 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{SRCIP}	{ count(); yylval.strval=yytext; return SRCIP; }
 <INITIAL>{SRCPORT}	{ count(); yylval.strval=yytext; return SRCPORT; }
 <INITIAL>{DSTIP}	{ count(); yylval.strval=yytext; return DSTIP; }
+<INITIAL>{DSTPORT}	{ count(); yylval.strval=yytext; return DSTPORT; }
+<INITIAL>{PROTO}	{ count(); yylval.strval=yytext; return PROTO; }
+<INITIAL>{AF}	{ count(); yylval.strval=yytext; return AF; }
 <INITIAL>{MYSELF}	{ count(); yylval.strval=yytext; return MYSELF; }
 
 <INITIAL>{DEBUG}	{ count(); yylval.strval=yytext; return DEBUG; }
@@ -261,6 +274,17 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{NUMBER}		{ count(); yylval.intval=atoi(yytext);return NUMBER; }
 <INITIAL>{YES}			{ count(); yylval.intval=1; return NUMBER; }
 <INITIAL>{NO}			{ count(); yylval.intval=0; return NUMBER; }
+<INITIAL>{TCP}			{ count(); yylval.intval=PROTO_TCP; return NUMBER; }
+<INITIAL>{UDP}			{ count(); yylval.intval=PROTO_UDP; return NUMBER; }
+<INITIAL>{TLS}			{ count(); yylval.intval=PROTO_TLS; return NUMBER; }
+<INITIAL>{INET}			{ count(); yylval.intval=AF_INET; return NUMBER; }
+<INITIAL>{INET6}		{ count();
+						#ifdef USE_IPV6
+						  yylval.intval=AF_INET6;
+						#else
+						  yylval.intval=-1; /* no match*/
+						#endif
+						  return NUMBER; }
 
 <INITIAL>{COMMA}		{ count(); return COMMA; }
 <INITIAL>{SEMICOLON}	{ count(); return SEMICOLON; }

+ 19 - 2
cfg.y

@@ -25,7 +25,8 @@
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
+ */
+ /*
  * History:
  * ---------
  * 2003-01-29  src_port added (jiri)
@@ -33,6 +34,7 @@
  * 2003-03-19  replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
  * 2003-03-19  Added support for route type in find_export (janakj)
  * 2003-03-20  Regex support in modparam (janakj)
+ * 2003-04-01  added dst_port, proto , af (andrei)
  */
 
 
@@ -130,6 +132,9 @@ int rt;  /* Type of route block for find_export */
 %token SRCIP
 %token SRCPORT
 %token DSTIP
+%token DSTPORT
+%token PROTO
+%token AF
 %token MYSELF
 
 /* config vars. */
@@ -535,7 +540,19 @@ exp_elem:	METHOD EQUAL_T STRING	{$$= mk_elem(	EQUAL_OP, STRING_ST,
 		| SRCPORT EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
 												SRCPORT_O, (void *) $3 ); }
 		| SRCPORT EQUAL_T error { $$=0; yyerror("number expected"); }
-		| SRCPORT error { $$=0; yyerror("equation operator expected"); }
+		| SRCPORT error { $$=0; yyerror("equal operator expected"); }
+		| DSTPORT EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
+												DSTPORT_O, (void *) $3 ); }
+		| DSTPORT EQUAL_T error { $$=0; yyerror("number expected"); }
+		| DSTPORT error { $$=0; yyerror("equal operator expected"); }
+		| PROTO EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
+												PROTO_O, (void *) $3 ); }
+		| PROTO EQUAL_T error { $$=0; yyerror("number expected"); }
+		| PROTO error { $$=0; yyerror("equal operator expected"); }
+		| AF EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
+												AF_O, (void *) $3 ); }
+		| AF EQUAL_T error { $$=0; yyerror("number expected"); }
+		| AF error { $$=0; yyerror("equal operator expected"); }
 		| SRCIP EQUAL_T ipnet	{ $$=mk_elem(	EQUAL_OP, NET_ST,
 												SRCIP_O, $3);
 								}

+ 20 - 8
route.c

@@ -29,10 +29,12 @@
  *
  * History:
  * --------
- *  2003-02-28  scratchpad compatibility abandoned (jiri)
  *  2003-01-28  scratchpad removed, src_port introduced (jiri)
+ *  2003-02-28  scratchpad compatibility abandoned (jiri)
  *  2003-03-10  updated to the new module exports format (andrei)
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ *  2003-04-01  added dst_port, proto, af; renamed comp_port to comp_no,
+ *               inlined all the comp_* functions (andrei)
  */
 
  
@@ -238,21 +240,21 @@ static int fix_actions(struct action* a)
 }
 
 
-static int comp_port( int port, void *param, int op, int subtype )
+inline static int comp_no( int port, void *param, int op, int subtype )
 {
 	if (op!=EQUAL_OP) {
-		LOG(L_CRIT, "BUG: comp_port: '=' expected: %d\n", op );
+		LOG(L_CRIT, "BUG: comp_no: '=' expected: %d\n", op );
 		return E_BUG;
 	}
 	if (subtype!=NUMBER_ST) {
-		LOG(L_CRIT, "BUG: comp_port: number expected: %d\n", subtype );
+		LOG(L_CRIT, "BUG: comp_no: number expected: %d\n", subtype );
 		return E_BUG;
 	}
 	return port==(long)param;
 }
 
 /* eval_elem helping function, returns str op param */
-static int comp_strstr(str* str, void* param, int op, int subtype)
+inline static int comp_strstr(str* str, void* param, int op, int subtype)
 {
 	int ret;
 	char backup;
@@ -298,7 +300,7 @@ error:
 }
 
 /* eval_elem helping function, returns str op param */
-static int comp_str(char* str, void* param, int op, int subtype)
+inline static int comp_str(char* str, void* param, int op, int subtype)
 {
 	int ret;
 	
@@ -330,7 +332,7 @@ error:
 
 
 /* eval_elem helping function, returns an op param */
-static int comp_ip(struct ip_addr* ip, void* param, int op, int subtype)
+inline static int comp_ip(struct ip_addr* ip, void* param, int op, int subtype)
 {
 	struct hostent* he;
 	char ** h;
@@ -439,11 +441,21 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
 				else ret=1;
 				break;
 		case SRCPORT_O:
-				ret=comp_port(ntohs(msg->rcv.src_port), 
+				ret=comp_no(ntohs(msg->rcv.src_port), 
 					e->r.param, /* e.g., 5060 */
 					e->op, /* e.g. == */
 					e->subtype /* 5060 is number */);
 				break;
+		case DSTPORT_O:
+				ret=comp_no(ntohs(msg->rcv.dst_port), e->r.param, e->op, 
+							e->subtype);
+				break;
+		case PROTO_O:
+				ret=comp_no(msg->rcv.proto, e->r.param, e->op, e->subtype);
+				break;
+		case AF_O:
+				ret=comp_no(msg->rcv.src_ip.af, e->r.param, e->op, e->subtype);
+				break;
 		default:
 				LOG(L_CRIT, "BUG: eval_elem: invalid operand %d\n",
 							e->l.operand);

+ 1 - 1
route_struct.h

@@ -47,7 +47,7 @@ enum { EXP_T=1, ELEM_T };
 enum { AND_OP=1, OR_OP, NOT_OP };
 enum { EQUAL_OP=10, MATCH_OP, NO_OP };
 enum { METHOD_O=1, URI_O, SRCIP_O, SRCPORT_O,
-	DSTIP_O, DEFAULT_O, ACTION_O, NUMBER_O};
+	   DSTIP_O, DSTPORT_O, PROTO_O, AF_O, DEFAULT_O, ACTION_O, NUMBER_O};
 
 enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
 		SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T,