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 41
 	#include "mem/mem.h"
42 42
 	#include <string.h>
43 43
 	#include <stdlib.h>
44
+	#include "ip_addr.h"
44 45
 
45 46
 
46 47
 	/* states */
... ...
@@ -108,6 +110,9 @@ URI		uri
108 108
 SRCIP	src_ip
109 109
 SRCPORT	src_port
110 110
 DSTIP	dst_ip
111
+DSTPORT	dst_port
112
+PROTO	proto
113
+AF		af
111 114
 MYSELF	myself
112 115
 /* operators */
113 116
 EQUAL	=
... ...
@@ -147,6 +152,11 @@ MODPARAM        modparam
147 147
 /* values */
148 148
 YES			"yes"|"true"|"on"|"enable"
149 149
 NO			"no"|"false"|"off"|"disable"
150
+UDP			"udp"
151
+TCP			"tcp"
152
+TLS			"tls"
153
+INET		"inet"
154
+INET6		"inet6"
150 155
 
151 156
 LETTER		[a-zA-Z]
152 157
 DIGIT		[0-9]
... ...
@@ -221,6 +231,9 @@ EAT_ABLE	[\ \t\b\r]
221 221
 <INITIAL>{SRCIP}	{ count(); yylval.strval=yytext; return SRCIP; }
222 222
 <INITIAL>{SRCPORT}	{ count(); yylval.strval=yytext; return SRCPORT; }
223 223
 <INITIAL>{DSTIP}	{ count(); yylval.strval=yytext; return DSTIP; }
224
+<INITIAL>{DSTPORT}	{ count(); yylval.strval=yytext; return DSTPORT; }
225
+<INITIAL>{PROTO}	{ count(); yylval.strval=yytext; return PROTO; }
226
+<INITIAL>{AF}	{ count(); yylval.strval=yytext; return AF; }
224 227
 <INITIAL>{MYSELF}	{ count(); yylval.strval=yytext; return MYSELF; }
225 228
 
226 229
 <INITIAL>{DEBUG}	{ count(); yylval.strval=yytext; return DEBUG; }
... ...
@@ -261,6 +274,17 @@ EAT_ABLE	[\ \t\b\r]
261 261
 <INITIAL>{NUMBER}		{ count(); yylval.intval=atoi(yytext);return NUMBER; }
262 262
 <INITIAL>{YES}			{ count(); yylval.intval=1; return NUMBER; }
263 263
 <INITIAL>{NO}			{ count(); yylval.intval=0; return NUMBER; }
264
+<INITIAL>{TCP}			{ count(); yylval.intval=PROTO_TCP; return NUMBER; }
265
+<INITIAL>{UDP}			{ count(); yylval.intval=PROTO_UDP; return NUMBER; }
266
+<INITIAL>{TLS}			{ count(); yylval.intval=PROTO_TLS; return NUMBER; }
267
+<INITIAL>{INET}			{ count(); yylval.intval=AF_INET; return NUMBER; }
268
+<INITIAL>{INET6}		{ count();
269
+						#ifdef USE_IPV6
270
+						  yylval.intval=AF_INET6;
271
+						#else
272
+						  yylval.intval=-1; /* no match*/
273
+						#endif
274
+						  return NUMBER; }
264 275
 
265 276
 <INITIAL>{COMMA}		{ count(); return COMMA; }
266 277
 <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 33
  * 2003-03-19  replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
34 34
  * 2003-03-19  Added support for route type in find_export (janakj)
35 35
  * 2003-03-20  Regex support in modparam (janakj)
36
+ * 2003-04-01  added dst_port, proto , af (andrei)
36 37
  */
37 38
 
38 39
 
... ...
@@ -130,6 +132,9 @@ int rt;  /* Type of route block for find_export */
130 130
 %token SRCIP
131 131
 %token SRCPORT
132 132
 %token DSTIP
133
+%token DSTPORT
134
+%token PROTO
135
+%token AF
133 136
 %token MYSELF
134 137
 
135 138
 /* config vars. */
... ...
@@ -535,7 +540,19 @@ exp_elem:	METHOD EQUAL_T STRING	{$$= mk_elem(	EQUAL_OP, STRING_ST,
535 535
 		| SRCPORT EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
536 536
 												SRCPORT_O, (void *) $3 ); }
537 537
 		| SRCPORT EQUAL_T error { $$=0; yyerror("number expected"); }
538
-		| SRCPORT error { $$=0; yyerror("equation operator expected"); }
538
+		| SRCPORT error { $$=0; yyerror("equal operator expected"); }
539
+		| DSTPORT EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
540
+												DSTPORT_O, (void *) $3 ); }
541
+		| DSTPORT EQUAL_T error { $$=0; yyerror("number expected"); }
542
+		| DSTPORT error { $$=0; yyerror("equal operator expected"); }
543
+		| PROTO EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
544
+												PROTO_O, (void *) $3 ); }
545
+		| PROTO EQUAL_T error { $$=0; yyerror("number expected"); }
546
+		| PROTO error { $$=0; yyerror("equal operator expected"); }
547
+		| AF EQUAL_T NUMBER	{ $$=mk_elem(	EQUAL_OP, NUMBER_ST,
548
+												AF_O, (void *) $3 ); }
549
+		| AF EQUAL_T error { $$=0; yyerror("number expected"); }
550
+		| AF error { $$=0; yyerror("equal operator expected"); }
539 551
 		| SRCIP EQUAL_T ipnet	{ $$=mk_elem(	EQUAL_OP, NET_ST,
540 552
 												SRCIP_O, $3);
541 553
 								}
... ...
@@ -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 238
 }
239 239
 
240 240
 
241
-static int comp_port( int port, void *param, int op, int subtype )
241
+inline static int comp_no( int port, void *param, int op, int subtype )
242 242
 {
243 243
 	if (op!=EQUAL_OP) {
244
-		LOG(L_CRIT, "BUG: comp_port: '=' expected: %d\n", op );
244
+		LOG(L_CRIT, "BUG: comp_no: '=' expected: %d\n", op );
245 245
 		return E_BUG;
246 246
 	}
247 247
 	if (subtype!=NUMBER_ST) {
248
-		LOG(L_CRIT, "BUG: comp_port: number expected: %d\n", subtype );
248
+		LOG(L_CRIT, "BUG: comp_no: number expected: %d\n", subtype );
249 249
 		return E_BUG;
250 250
 	}
251 251
 	return port==(long)param;
252 252
 }
253 253
 
254 254
 /* eval_elem helping function, returns str op param */
255
-static int comp_strstr(str* str, void* param, int op, int subtype)
255
+inline static int comp_strstr(str* str, void* param, int op, int subtype)
256 256
 {
257 257
 	int ret;
258 258
 	char backup;
... ...
@@ -298,7 +300,7 @@ error:
298 298
 }
299 299
 
300 300
 /* eval_elem helping function, returns str op param */
301
-static int comp_str(char* str, void* param, int op, int subtype)
301
+inline static int comp_str(char* str, void* param, int op, int subtype)
302 302
 {
303 303
 	int ret;
304 304
 	
... ...
@@ -330,7 +332,7 @@ error:
330 330
 
331 331
 
332 332
 /* eval_elem helping function, returns an op param */
333
-static int comp_ip(struct ip_addr* ip, void* param, int op, int subtype)
333
+inline static int comp_ip(struct ip_addr* ip, void* param, int op, int subtype)
334 334
 {
335 335
 	struct hostent* he;
336 336
 	char ** h;
... ...
@@ -439,11 +441,21 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
439 439
 				else ret=1;
440 440
 				break;
441 441
 		case SRCPORT_O:
442
-				ret=comp_port(ntohs(msg->rcv.src_port), 
442
+				ret=comp_no(ntohs(msg->rcv.src_port), 
443 443
 					e->r.param, /* e.g., 5060 */
444 444
 					e->op, /* e.g. == */
445 445
 					e->subtype /* 5060 is number */);
446 446
 				break;
447
+		case DSTPORT_O:
448
+				ret=comp_no(ntohs(msg->rcv.dst_port), e->r.param, e->op, 
449
+							e->subtype);
450
+				break;
451
+		case PROTO_O:
452
+				ret=comp_no(msg->rcv.proto, e->r.param, e->op, e->subtype);
453
+				break;
454
+		case AF_O:
455
+				ret=comp_no(msg->rcv.src_ip.af, e->r.param, e->op, e->subtype);
456
+				break;
447 457
 		default:
448 458
 				LOG(L_CRIT, "BUG: eval_elem: invalid operand %d\n",
449 459
 							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,