Browse code

- 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 authored on 01/04/2003 18:20:50
Showing 6 changed files
... ...
@@ -60,10 +60,10 @@ include Makefile.rules
60 60
 
61 61
 $(NAME): static_modules
62 62
 
63
-lex.yy.c: cfg.lex $(ALLDEP)
63
+lex.yy.c: cfg.lex cfg.tab.h $(ALLDEP)
64 64
 	$(LEX) $<
65 65
 
66
-cfg.tab.c: cfg.y  $(ALLDEP)
66
+cfg.tab.c cfg.tab.h: cfg.y  $(ALLDEP)
67 67
 	$(YACC) $(YACC_FLAGS) $<
68 68
 
69 69
 .PHONY: all
... ...
@@ -18,7 +18,7 @@
18 18
 VERSION = 0
19 19
 PATCHLEVEL = 8
20 20
 SUBLEVEL =   11
21
-EXTRAVERSION = pre9-opt_l
21
+EXTRAVERSION = pre9-new_opts
22 22
 
23 23
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
24 24
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -31,6 +31,7 @@
31 31
  *  2003-01-29  src_port added (jiri)
32 32
  *  2003-01-23  mhomed added (jiri)
33 33
  *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
34
+ *  2003-04-01  added dst_port, proto (tcp, udp, tls), af(inet, inet6) (andrei)
34 35
  */
35 36
 
36 37
 
... ...
@@ -41,6 +42,7 @@
41 42
 	#include "mem/mem.h"
42 43
 	#include <string.h>
43 44
 	#include <stdlib.h>
45
+	#include "ip_addr.h"
44 46
 
45 47
 
46 48
 	/* states */
... ...
@@ -108,6 +110,9 @@ URI		uri
108 110
 SRCIP	src_ip
109 111
 SRCPORT	src_port
110 112
 DSTIP	dst_ip
113
+DSTPORT	dst_port
114
+PROTO	proto
115
+AF		af
111 116
 MYSELF	myself
112 117
 /* operators */
113 118
 EQUAL	=
... ...
@@ -147,6 +152,11 @@ MODPARAM        modparam
147 152
 /* values */
148 153
 YES			"yes"|"true"|"on"|"enable"
149 154
 NO			"no"|"false"|"off"|"disable"
155
+UDP			"udp"
156
+TCP			"tcp"
157
+TLS			"tls"
158
+INET		"inet"
159
+INET6		"inet6"
150 160
 
151 161
 LETTER		[a-zA-Z]
152 162
 DIGIT		[0-9]
... ...
@@ -221,6 +231,9 @@ EAT_ABLE	[\ \t\b\r]
221 231
 <INITIAL>{SRCIP}	{ count(); yylval.strval=yytext; return SRCIP; }
222 232
 <INITIAL>{SRCPORT}	{ count(); yylval.strval=yytext; return SRCPORT; }
223 233
 <INITIAL>{DSTIP}	{ count(); yylval.strval=yytext; return DSTIP; }
234
+<INITIAL>{DSTPORT}	{ count(); yylval.strval=yytext; return DSTPORT; }
235
+<INITIAL>{PROTO}	{ count(); yylval.strval=yytext; return PROTO; }
236
+<INITIAL>{AF}	{ count(); yylval.strval=yytext; return AF; }
224 237
 <INITIAL>{MYSELF}	{ count(); yylval.strval=yytext; return MYSELF; }
225 238
 
226 239
 <INITIAL>{DEBUG}	{ count(); yylval.strval=yytext; return DEBUG; }
... ...
@@ -261,6 +274,17 @@ EAT_ABLE	[\ \t\b\r]
261 274
 <INITIAL>{NUMBER}		{ count(); yylval.intval=atoi(yytext);return NUMBER; }
262 275
 <INITIAL>{YES}			{ count(); yylval.intval=1; return NUMBER; }
263 276
 <INITIAL>{NO}			{ count(); yylval.intval=0; return NUMBER; }
277
+<INITIAL>{TCP}			{ count(); yylval.intval=PROTO_TCP; return NUMBER; }
278
+<INITIAL>{UDP}			{ count(); yylval.intval=PROTO_UDP; return NUMBER; }
279
+<INITIAL>{TLS}			{ count(); yylval.intval=PROTO_TLS; return NUMBER; }
280
+<INITIAL>{INET}			{ count(); yylval.intval=AF_INET; return NUMBER; }
281
+<INITIAL>{INET6}		{ count();
282
+						#ifdef USE_IPV6
283
+						  yylval.intval=AF_INET6;
284
+						#else
285
+						  yylval.intval=-1; /* no match*/
286
+						#endif
287
+						  return NUMBER; }
264 288
 
265 289
 <INITIAL>{COMMA}		{ count(); return COMMA; }
266 290
 <INITIAL>{SEMICOLON}	{ count(); return SEMICOLON; }
... ...
@@ -25,7 +25,8 @@
25 25
  * You should have received a copy of the GNU General Public License 
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
- *
28
+ */
29
+ /*
29 30
  * History:
30 31
  * ---------
31 32
  * 2003-01-29  src_port added (jiri)
... ...
@@ -33,6 +34,7 @@
33 34
  * 2003-03-19  replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
34 35
  * 2003-03-19  Added support for route type in find_export (janakj)
35 36
  * 2003-03-20  Regex support in modparam (janakj)
37
+ * 2003-04-01  added dst_port, proto , af (andrei)
36 38
  */
37 39
 
38 40
 
... ...
@@ -130,6 +132,9 @@ int rt;  /* Type of route block for find_export */
130 132
 %token SRCIP
131 133
 %token SRCPORT
132 134
 %token DSTIP
135
+%token DSTPORT
136
+%token PROTO
137
+%token AF
133 138
 %token MYSELF
134 139
 
135 140
 /* config vars. */
... ...
@@ -535,7 +540,19 @@ exp_elem:	METHOD EQUAL_T STRING	{$$= mk_elem(	EQUAL_OP, STRING_ST,
535 540
 		| SRCPORT EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
536 541
 												SRCPORT_O, (void *) $3 ); }
537 542
 		| SRCPORT EQUAL_T error { $$=0; yyerror("number expected"); }
538
-		| SRCPORT error { $$=0; yyerror("equation operator expected"); }
543
+		| SRCPORT error { $$=0; yyerror("equal operator expected"); }
544
+		| DSTPORT EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
545
+												DSTPORT_O, (void *) $3 ); }
546
+		| DSTPORT EQUAL_T error { $$=0; yyerror("number expected"); }
547
+		| DSTPORT error { $$=0; yyerror("equal operator expected"); }
548
+		| PROTO EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
549
+												PROTO_O, (void *) $3 ); }
550
+		| PROTO EQUAL_T error { $$=0; yyerror("number expected"); }
551
+		| PROTO error { $$=0; yyerror("equal operator expected"); }
552
+		| AF EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
553
+												AF_O, (void *) $3 ); }
554
+		| AF EQUAL_T error { $$=0; yyerror("number expected"); }
555
+		| AF error { $$=0; yyerror("equal operator expected"); }
539 556
 		| SRCIP EQUAL_T ipnet	{ $$=mk_elem(	EQUAL_OP, NET_ST,
540 557
 												SRCIP_O, $3);
541 558
 								}
... ...
@@ -29,10 +29,12 @@
29 29
  *
30 30
  * History:
31 31
  * --------
32
- *  2003-02-28  scratchpad compatibility abandoned (jiri)
33 32
  *  2003-01-28  scratchpad removed, src_port introduced (jiri)
33
+ *  2003-02-28  scratchpad compatibility abandoned (jiri)
34 34
  *  2003-03-10  updated to the new module exports format (andrei)
35 35
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
36
+ *  2003-04-01  added dst_port, proto, af; renamed comp_port to comp_no,
37
+ *               inlined all the comp_* functions (andrei)
36 38
  */
37 39
 
38 40
  
... ...
@@ -238,21 +240,21 @@ static int fix_actions(struct action* a)
238 240
 }
239 241
 
240 242
 
241
-static int comp_port( int port, void *param, int op, int subtype )
243
+inline static int comp_no( int port, void *param, int op, int subtype )
242 244
 {
243 245
 	if (op!=EQUAL_OP) {
244
-		LOG(L_CRIT, "BUG: comp_port: '=' expected: %d\n", op );
246
+		LOG(L_CRIT, "BUG: comp_no: '=' expected: %d\n", op );
245 247
 		return E_BUG;
246 248
 	}
247 249
 	if (subtype!=NUMBER_ST) {
248
-		LOG(L_CRIT, "BUG: comp_port: number expected: %d\n", subtype );
250
+		LOG(L_CRIT, "BUG: comp_no: number expected: %d\n", subtype );
249 251
 		return E_BUG;
250 252
 	}
251 253
 	return port==(long)param;
252 254
 }
253 255
 
254 256
 /* eval_elem helping function, returns str op param */
255
-static int comp_strstr(str* str, void* param, int op, int subtype)
257
+inline static int comp_strstr(str* str, void* param, int op, int subtype)
256 258
 {
257 259
 	int ret;
258 260
 	char backup;
... ...
@@ -298,7 +300,7 @@ error:
298 300
 }
299 301
 
300 302
 /* eval_elem helping function, returns str op param */
301
-static int comp_str(char* str, void* param, int op, int subtype)
303
+inline static int comp_str(char* str, void* param, int op, int subtype)
302 304
 {
303 305
 	int ret;
304 306
 	
... ...
@@ -330,7 +332,7 @@ error:
330 332
 
331 333
 
332 334
 /* eval_elem helping function, returns an op param */
333
-static int comp_ip(struct ip_addr* ip, void* param, int op, int subtype)
335
+inline static int comp_ip(struct ip_addr* ip, void* param, int op, int subtype)
334 336
 {
335 337
 	struct hostent* he;
336 338
 	char ** h;
... ...
@@ -439,11 +441,21 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
439 441
 				else ret=1;
440 442
 				break;
441 443
 		case SRCPORT_O:
442
-				ret=comp_port(ntohs(msg->rcv.src_port), 
444
+				ret=comp_no(ntohs(msg->rcv.src_port), 
443 445
 					e->r.param, /* e.g., 5060 */
444 446
 					e->op, /* e.g. == */
445 447
 					e->subtype /* 5060 is number */);
446 448
 				break;
449
+		case DSTPORT_O:
450
+				ret=comp_no(ntohs(msg->rcv.dst_port), e->r.param, e->op, 
451
+							e->subtype);
452
+				break;
453
+		case PROTO_O:
454
+				ret=comp_no(msg->rcv.proto, e->r.param, e->op, e->subtype);
455
+				break;
456
+		case AF_O:
457
+				ret=comp_no(msg->rcv.src_ip.af, e->r.param, e->op, e->subtype);
458
+				break;
447 459
 		default:
448 460
 				LOG(L_CRIT, "BUG: eval_elem: invalid operand %d\n",
449 461
 							e->l.operand);
... ...
@@ -47,7 +47,7 @@ enum { EXP_T=1, ELEM_T };
47 47
 enum { AND_OP=1, OR_OP, NOT_OP };
48 48
 enum { EQUAL_OP=10, MATCH_OP, NO_OP };
49 49
 enum { METHOD_O=1, URI_O, SRCIP_O, SRCPORT_O,
50
-	DSTIP_O, DEFAULT_O, ACTION_O, NUMBER_O};
50
+	   DSTIP_O, DSTPORT_O, PROTO_O, AF_O, DEFAULT_O, ACTION_O, NUMBER_O};
51 51
 
52 52
 enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
53 53
 		SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T,