Browse code

- config parser + expression builder seem to be working

Andrei Pelinescu-Onciul authored on 19/09/2001 21:45:25
Showing 4 changed files
... ...
@@ -19,8 +19,9 @@
19 19
 	static int comment_nest=0;
20 20
 	static int state=0;
21 21
 	static char* str=0;
22
-	int line=0;
23
-	int column=0;
22
+	int line=1;
23
+	int column=1;
24
+	int startcolumn=1;
24 25
 
25 26
 	static char* addstr(char*, char**);
26 27
 	static void count();
... ...
@@ -38,6 +39,7 @@ SEND	send
38 39
 LOG		log
39 40
 ERROR	error
40 41
 ROUTE	route
42
+EXEC	exec
41 43
 /* condition keywords */
42 44
 METHOD	method
43 45
 URI		uri
... ...
@@ -47,7 +49,7 @@ DSTIP	dst_ip
47 49
 EQUAL	=
48 50
 EQUAL_T	==
49 51
 MATCH	~=
50
-NOT		!
52
+NOT		!|"not"
51 53
 AND		"and"|"&&"|"&"
52 54
 OR		"or"|"||"|"|"
53 55
 
... ...
@@ -101,6 +103,7 @@ EAT_ABLE	[\ \t\b\r]
101 103
 <INITIAL>{LOG}	{ count(); yylval.strval=yytext; return LOG; }
102 104
 <INITIAL>{ERROR}	{ count(); yylval.strval=yytext; return ERROR; }
103 105
 <INITIAL>{ROUTE}	{ count(); yylval.strval=yytext; return ROUTE; }
106
+<INITIAL>{EXEC}	{ count(); yylval.strval=yytext; return EXEC; }
104 107
 
105 108
 <INITIAL>{METHOD}	{ count(); yylval.strval=yytext; return METHOD; }
106 109
 <INITIAL>{URI}	{ count(); yylval.strval=yytext; return URI; }
... ...
@@ -186,7 +189,8 @@ EAT_ABLE	[\ \t\b\r]
186 189
 
187 190
 <INITIAL>{COM_LINE}.*{CR}	{ count(); } 
188 191
 
189
-<INITIAL>{ID}			{ count(); yylval.strval=yytext; return ID; }
192
+<INITIAL>{ID}			{ count(); addstr(yytext, &str);
193
+						  yylval.strval=str; str=0; return ID; }
190 194
 
191 195
 
192 196
 <<EOF>>							{
... ...
@@ -237,12 +241,14 @@ static void count()
237 241
 {
238 242
 	int i;
239 243
 	
244
+	startcolumn=column;
240 245
 	for (i=0; i<yyleng;i++){
241 246
 		if (yytext[i]=='\n'){
242 247
 			line++;
243
-			column=0;
248
+			column=startcolumn=1;
244 249
 		}else if (yytext[i]=='\t'){
245
-			column+=8 -(column%8);
250
+			column++;
251
+			/*column+=8 -(column%8);*/
246 252
 		}else{
247 253
 			column++;
248 254
 		}
... ...
@@ -12,9 +12,11 @@
12 12
 
13 13
 %union {
14 14
 	int intval;
15
+	unsigned uval;
15 16
 	char* strval;
16 17
 	struct expr* expr;
17 18
 	struct action* action;
19
+	struct net* net;
18 20
 }
19 21
 
20 22
 /* terminals */
... ...
@@ -27,6 +29,8 @@
27 29
 %token LOG
28 30
 %token ERROR
29 31
 %token ROUTE
32
+%token EXEC
33
+
30 34
 %token METHOD
31 35
 %token URI
32 36
 %token SRCIP
... ...
@@ -45,9 +49,9 @@
45 49
 %nonassoc EQUAL
46 50
 %nonassoc EQUAL_T
47 51
 %nonassoc MATCH
48
-%left NOT
49
-%left AND
50 52
 %left OR
53
+%left AND
54
+%left NOT
51 55
 
52 56
 /* values */
53 57
 %token <intval> NUMBER
... ...
@@ -71,6 +75,9 @@
71 75
 /*non-terminals */
72 76
 %type <expr> exp, condition,  exp_elem
73 77
 %type <action> action, actions, cmd
78
+%type <uval> ipv4
79
+%type <net> net4
80
+%type <strval> host
74 81
 
75 82
 
76 83
 
... ...
@@ -109,7 +116,19 @@ assign_stm:	DEBUG EQUAL NUMBER
109 116
 	;
110 117
 
111 118
 
112
-ipv4:	NUMBER DOT NUMBER DOT NUMBER DOT NUMBER
119
+ipv4:	NUMBER DOT NUMBER DOT NUMBER DOT NUMBER { 
120
+											if (($1>255) || ($1<0) ||
121
+												($3>255) || ($3<0) ||
122
+												($5>255) || ($5<0) ||
123
+												($7>255) || ($7<0)){
124
+												yyerror("invalid ipv4"
125
+														"address");
126
+												$$=0;
127
+											}else{
128
+												$$=($1<<24)|($3<<16)|
129
+													($5<<8)|$7;
130
+											}
131
+												}
113 132
 	;
114 133
 
115 134
 route_stm:	ROUTE LBRACE rules RBRACE 
... ...
@@ -122,140 +141,253 @@ rules:	rules rule
122 141
 	| rules error { yyerror("invalid rule"); }
123 142
 	 ;
124 143
 
125
-rule:	condition	actions CR
144
+rule:	condition	actions CR {
145
+								printf("Got a new rule!\n");
146
+								printf("expr: "); print_expr($1);
147
+								printf("\n  -> actions: ");
148
+								print_action($2); printf("\n");
149
+							   }
126 150
 	| CR  /* null rule */
127 151
 	| condition error { yyerror("bad actions in rule"); }
128 152
 	;
129 153
 
130
-condition:	exp
154
+condition:	exp {$$=$1;}
131 155
 	;
132 156
 
133
-exp:	exp AND exp 
134
-	| exp OR  exp 
135
-	| NOT exp 
136
-	| LPAREN exp RPAREN
137
-	| exp_elem
157
+exp:	exp AND exp 	{ $$=mk_exp(AND_OP, $1, $3); }
158
+	| exp OR  exp		{ $$=mk_exp(OR_OP, $1, $3);  }
159
+	| NOT exp 			{ $$=mk_exp(NOT_OP, $2, 0);  }
160
+	| LPAREN exp RPAREN	{ $$=$2; }
161
+	| exp_elem			{ $$=$1; }
138 162
 	;
139 163
 
140
-exp_elem:	METHOD EQUAL_T STRING	{$$= mk_elem(	EQUAL_OP,
141
-							STRING_ST, 
142
-							METHOD_O,
143
-							$3);
144
-					}
145
-		| METHOD EQUAL_T ID	{$$ = mk_elem(	EQUAL_OP,
146
-							STRING_ST,
147
-							METHOD_O,
148
-							$3); 
149
-				 	}
164
+exp_elem:	METHOD EQUAL_T STRING	{$$= mk_elem(	EQUAL_OP, STRING_ST, 
165
+													METHOD_O, $3);
166
+									}
167
+		| METHOD EQUAL_T ID	{$$ = mk_elem(	EQUAL_OP, STRING_ST,
168
+											METHOD_O, $3); 
169
+				 			}
150 170
 		| METHOD EQUAL_T error { $$=0; yyerror("string expected"); }
151
-		| METHOD MATCH STRING 	{$$ = mk_elem(	MATCH_OP,
152
-							STRING_ST,
153
-							METHOD_O,
154
-							$3); 
155
-				 	}
156
-		| METHOD MATCH ID	{$$ = mk_elem(	MATCH_OP,
157
-							STRING_ST,
158
-							METHOD_O,
159
-							$3); 
160
-				 	}
171
+		| METHOD MATCH STRING	{$$ = mk_elem(	MATCH_OP, STRING_ST,
172
+												METHOD_O, $3); 
173
+				 				}
174
+		| METHOD MATCH ID	{$$ = mk_elem(	MATCH_OP, STRING_ST,
175
+											METHOD_O, $3); 
176
+				 			}
161 177
 		| METHOD MATCH error { $$=0; yyerror("string expected"); }
162
-		| METHOD error	{ $$=0; 
163
-				  yyerror("invalid operator,"
164
-				  		"== or ~= expected");
165
-				}
166
-		| URI EQUAL_T STRING 	{$$ = mk_elem(	EQUAL_OP,
167
-							STRING_ST,
168
-							URI_O,
169
-							$3); 
170
-				 	}
171
-		| URI EQUAL_T ID 	{$$ = mk_elem(	EQUAL_OP,
172
-							STRING_ST,
173
-							URI_O,
174
-							$3); 
175
-				 	}
178
+		| METHOD error	{ $$=0; yyerror("invalid operator,"
179
+										"== or ~= expected");
180
+						}
181
+		| URI EQUAL_T STRING 	{$$ = mk_elem(	EQUAL_OP, STRING_ST,
182
+												URI_O, $3); 
183
+				 				}
184
+		| URI EQUAL_T ID 	{$$ = mk_elem(	EQUAL_OP, STRING_ST,
185
+											URI_O, $3); 
186
+				 			}
176 187
 		| URI EQUAL_T error { $$=0; yyerror("string expected"); }
177
-		| URI MATCH STRING 
178
-		| URI MATCH ID
188
+		| URI MATCH STRING	{ $$=mk_elem(	MATCH_OP, STRING_ST,
189
+											URI_O, $3);
190
+							}
191
+		| URI MATCH ID		{ $$=mk_elem(	MATCH_OP, STRING_ST,
192
+											URI_O, $3);
193
+							}
179 194
 		| URI MATCH error {  $$=0; yyerror("string expected"); }
180
-		| URI error	{ $$=0; 
181
-				  yyerror("invalid operator,"
182
-				  		" == or ~= expected");
183
-				}
184
-		| SRCIP EQUAL_T net4 
185
-		| SRCIP EQUAL_T STRING 
186
-		| SRCIP EQUAL_T host
187
-		| SRCIP EQUAL_T error { yyerror( "ip address or hostname"
188
-						 "expected" ); }
189
-		| SRCIP MATCH STRING
190
-		| SRCIP MATCH ID
191
-		| SRCIP MATCH error  { yyerror( "hostname expected"); }
192
-		| SRCIP error  {yyerror("invalid operator, == or ~= expected");}
193
-		| DSTIP EQUAL_T net4 
194
-		| DSTIP EQUAL_T STRING
195
-		| DSTIP EQUAL_T host
196
-		| DSTIP EQUAL_T error { yyerror( "ip address or hostname"
195
+		| URI error	{ $$=0; yyerror("invalid operator,"
196
+				  					" == or ~= expected");
197
+					}
198
+		| SRCIP EQUAL_T net4	{ $$=mk_elem(	EQUAL_OP, NET_ST,
199
+												SRCIP_O, $3);
200
+								}
201
+		| SRCIP EQUAL_T STRING	{ $$=mk_elem(	EQUAL_OP, STRING_ST,
202
+												SRCIP_O, $3);
203
+								}
204
+		| SRCIP EQUAL_T host	{ $$=mk_elem(	EQUAL_OP, STRING_ST,
205
+												SRCIP_O, $3);
206
+								}
207
+		| SRCIP EQUAL_T error { $$=0; yyerror( "ip address or hostname"
197 208
 						 "expected" ); }
198
-		| DSTIP MATCH STRING
199
-		| DSTIP MATCH ID
200
-		| DSTIP MATCH error  { yyerror ( "hostname  expected" ); }
201
-		| DSTIP error {yyerror("invalid operator, == or ~= expected");}
209
+		| SRCIP MATCH STRING	{ $$=mk_elem(	MATCH_OP, STRING_ST,
210
+												SRCIP_O, $3);
211
+								}
212
+		| SRCIP MATCH ID		{ $$=mk_elem(	MATCH_OP, STRING_ST,
213
+												SRCIP_O, $3);
214
+								}
215
+		| SRCIP MATCH error  { $$=0; yyerror( "hostname expected"); }
216
+		| SRCIP error  { $$=0; 
217
+						 yyerror("invalid operator, == or ~= expected");}
218
+		| DSTIP EQUAL_T net4	{ $$=mk_elem(	EQUAL_OP, NET_ST,
219
+												DSTIP_O, $3);
220
+								}
221
+		| DSTIP EQUAL_T STRING	{ $$=mk_elem(	EQUAL_OP, STRING_ST,
222
+												DSTIP_O, $3);
223
+								}
224
+		| DSTIP EQUAL_T host	{ $$=mk_elem(	EQUAL_OP, STRING_ST,
225
+												DSTIP_O, $3);
226
+								}
227
+		| DSTIP EQUAL_T error { $$=0; yyerror( "ip address or hostname"
228
+						 			"expected" ); }
229
+		| DSTIP MATCH STRING	{ $$=mk_elem(	MATCH_OP, STRING_ST,
230
+												DSTIP_O, $3);
231
+								}
232
+		| DSTIP MATCH ID	{ $$=mk_elem(	MATCH_OP, STRING_ST,
233
+											DSTIP_O, $3);
234
+							}
235
+		| DSTIP MATCH error  { $$=0; yyerror ( "hostname  expected" ); }
236
+		| DSTIP error { $$=0; 
237
+						yyerror("invalid operator, == or ~= expected");}
202 238
 	;
203 239
 
204
-net4:	ipv4 SLASH ipv4 
205
-	| ipv4 SLASH NUMBER 
206
-	| ipv4
207
-	| ipv4 SLASH error {yyerror("netmask (eg:255.0.0.0 or 8) expected");}
240
+net4:	ipv4 SLASH ipv4	{ $$=mk_net($1, $3); } 
241
+	| ipv4 SLASH NUMBER {	if (($3>32)|($3<1)){
242
+								yyerror("invalid bit number in netmask");
243
+								$$=0;
244
+							}else{
245
+								$$=mk_net($1, (1<<$3)-1);
246
+							}
247
+						}
248
+	| ipv4				{ $$=mk_net($1, 0xffffffff); }
249
+	| ipv4 SLASH error { $$=0;
250
+						 yyerror("netmask (eg:255.0.0.0 or 8) expected");}
208 251
 	;
209 252
 
210
-host:	ID
211
-	| host DOT ID
212
-	| host DOT error { yyerror("invalid hostname"); }
253
+host:	ID				{ $$=$1; }
254
+	| host DOT ID		{ $$=(char*)malloc(strlen($1)+1+strlen($3)+1);
255
+						  if ($$==0){
256
+						  	fprintf(stderr, "memory allocation failure"
257
+						 				" while parsing host\n");
258
+						  }else{
259
+						  	memcpy($$, $1, strlen($1));
260
+						  	$$[strlen($1)]='.';
261
+						  	memcpy($$+strlen($1)+1, $3, strlen($3));
262
+						  	$$[strlen($1)+1+strlen($3)]=0;
263
+						  }
264
+						  free($1); free($3);
265
+						};
266
+	| host DOT error { $$=0; free($1); yyerror("invalid hostname"); }
213 267
 	;
214 268
 
215 269
 
216
-actions:	actions action 
217
-		| action
218
-		| actions error { yyerror("bad command"); }
270
+actions:	actions action	{$$=append_action($1, $2); }
271
+		| action			{$$=$1;}
272
+		| actions error { $$=0; yyerror("bad command"); }
219 273
 	;
220 274
 
221
-action:		cmd SEMICOLON
222
-		| SEMICOLON /* null action */
223
-		| cmd error { yyerror("bad command: missing ';'?"); }
275
+action:		cmd SEMICOLON {$$=$1;}
276
+		| SEMICOLON /* null action */ {$$=0;}
277
+		| cmd error { $$=0; yyerror("bad command: missing ';'?"); }
224 278
 	;
225 279
 
226
-cmd:		FORWARD LPAREN host RPAREN 
227
-		| FORWARD LPAREN STRING RPAREN 
228
-		| FORWARD LPAREN ipv4 RPAREN 
229
-		| FORWARD LPAREN host COMMA NUMBER RPAREN
230
-		| FORWARD LPAREN STRING COMMA NUMBER RPAREN
231
-		| FORWARD LPAREN ipv4 COMMA NUMBER RPAREN
232
-		| FORWARD error { yyerror("missing '(' or ')' ?"); }
233
-		| FORWARD LPAREN error RPAREN { yyerror("bad forward"
234
-						"argument"); }
235
-		| SEND LPAREN host RPAREN 
236
-		| SEND LPAREN STRING RPAREN 
237
-		| SEND LPAREN ipv4 RPAREN
238
-		| SEND LPAREN host COMMA NUMBER RPAREN
239
-		| SEND LPAREN STRING COMMA NUMBER RPAREN
240
-		| SEND LPAREN ipv4 COMMA NUMBER RPAREN
241
-		| SEND error { yyerror("missing '(' or ')' ?"); }
242
-		| SEND LPAREN error RPAREN { yyerror("bad send"
243
-						"argument"); }
244
-		| DROP LPAREN RPAREN 
245
-		| DROP 
246
-		| LOG LPAREN STRING RPAREN
247
-		| LOG LPAREN NUMBER COMMA STRING RPAREN
248
-		| LOG error { yyerror("missing '(' or ')' ?"); }
249
-		| LOG LPAREN error RPAREN { yyerror("bad log"
250
-						"argument"); }
251
-		| ERROR LPAREN STRING COMMA STRING RPAREN 
252
-		| ERROR error { yyerror("missing '(' or ')' ?"); }
253
-		| ERROR LPAREN error RPAREN { yyerror("bad error"
254
-						"argument"); }
255
-		| ROUTE LPAREN NUMBER RPAREN
256
-		| ROUTE error { yyerror("missing '(' or ')' ?"); }
257
-		| ROUTE LPAREN error RPAREN { yyerror("bad route"
280
+cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
281
+														STRING_ST,
282
+														NUMBER_ST,
283
+														$3,
284
+														0);
285
+										}
286
+		| FORWARD LPAREN STRING RPAREN	{ $$=mk_action(	FORWARD_T,
287
+														STRING_ST,
288
+														NUMBER_ST,
289
+														$3,
290
+														0);
291
+										}
292
+		| FORWARD LPAREN ipv4 RPAREN	{ $$=mk_action(	FORWARD_T,
293
+														IP_ST,
294
+														NUMBER_ST,
295
+														(void*)$3,
296
+														0);
297
+										}
298
+		| FORWARD LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T,
299
+																 STRING_ST,
300
+																 NUMBER_ST,
301
+																$3,
302
+																(void*)$5);
303
+												 }
304
+		| FORWARD LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T,
305
+																 STRING_ST,
306
+																 NUMBER_ST,
307
+																$3,
308
+																(void*)$5);
309
+													}
310
+		| FORWARD LPAREN ipv4 COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T,
311
+																 IP_ST,
312
+																 NUMBER_ST,
313
+																 (void*)$3,
314
+																(void*)$5);
315
+												  }
316
+		| FORWARD error { $$=0; yyerror("missing '(' or ')' ?"); }
317
+		| FORWARD LPAREN error RPAREN { $$=0; yyerror("bad forward"
318
+										"argument"); }
319
+		| SEND LPAREN host RPAREN	{ $$=mk_action(	SEND_T,
320
+													STRING_ST,
321
+													NUMBER_ST,
322
+													$3,
323
+													0);
324
+									}
325
+		| SEND LPAREN STRING RPAREN { $$=mk_action(	SEND_T,
326
+													STRING_ST,
327
+													NUMBER_ST,
328
+													$3,
329
+													0);
330
+									}
331
+		| SEND LPAREN ipv4 RPAREN	{ $$=mk_action(	SEND_T,
332
+													IP_ST,
333
+													NUMBER_ST,
334
+													(void*)$3,
335
+													0);
336
+									}
337
+		| SEND LPAREN host COMMA NUMBER RPAREN	{ $$=mk_action(	SEND_T,
338
+																STRING_ST,
339
+																NUMBER_ST,
340
+																$3,
341
+																(void*)$5);
342
+												}
343
+		| SEND LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(	SEND_T,
344
+																STRING_ST,
345
+																NUMBER_ST,
346
+																$3,
347
+																(void*)$5);
348
+												}
349
+		| SEND LPAREN ipv4 COMMA NUMBER RPAREN { $$=mk_action(	SEND_T,
350
+																IP_ST,
351
+																NUMBER_ST,
352
+																(void*)$3,
353
+																(void*)$5);
354
+											   }
355
+		| SEND error { $$=0; yyerror("missing '(' or ')' ?"); }
356
+		| SEND LPAREN error RPAREN { $$=0; yyerror("bad send"
357
+													"argument"); }
358
+		| DROP LPAREN RPAREN	{$$=mk_action(DROP_T,0, 0, 0, 0); }
359
+		| DROP					{$$=mk_action(DROP_T,0, 0, 0, 0); }
360
+		| LOG LPAREN STRING RPAREN	{$$=mk_action(	LOG_T, NUMBER_ST, 
361
+													STRING_ST,(void*)4,$3);
362
+									}
363
+		| LOG LPAREN NUMBER COMMA STRING RPAREN	{$$=mk_action(	LOG_T,
364
+																NUMBER_ST, 
365
+																STRING_ST,
366
+																(void*)$3,
367
+																$5);
368
+												}
369
+		| LOG error { $$=0; yyerror("missing '(' or ')' ?"); }
370
+		| LOG LPAREN error RPAREN { $$=0; yyerror("bad log"
371
+									"argument"); }
372
+		| ERROR LPAREN STRING COMMA STRING RPAREN {$$=mk_action(ERROR_T,
373
+																STRING_ST, 
374
+																STRING_ST,
375
+																$3,
376
+																$5);
377
+												  }
378
+												
379
+		| ERROR error { $$=0; yyerror("missing '(' or ')' ?"); }
380
+		| ERROR LPAREN error RPAREN { $$=0; yyerror("bad error"
381
+														"argument"); }
382
+		| ROUTE LPAREN NUMBER RPAREN	{ $$=mk_action(ROUTE_T, NUMBER_ST,
383
+														0, (void*)$3, 0);
384
+										}
385
+		| ROUTE error { $$=0; yyerror("missing '(' or ')' ?"); }
386
+		| ROUTE LPAREN error RPAREN { $$=0; yyerror("bad route"
258 387
 						"argument"); }
388
+		| EXEC LPAREN STRING RPAREN	{ $$=mk_action(	EXEC_T, STRING_ST, 0,
389
+													$3, 0);
390
+									}
259 391
 	;
260 392
 
261 393
 
... ...
@@ -263,9 +395,11 @@ cmd:		FORWARD LPAREN host RPAREN
263 395
 
264 396
 extern int line;
265 397
 extern int column;
398
+extern int startcolumn;
266 399
 yyerror(char* s)
267 400
 {
268
-	fprintf(stderr, "parse error (%d,%d): %s\n", line, column, s);
401
+	fprintf(stderr, "parse error (%d,%d-%d): %s\n", line, startcolumn, 
402
+			column, s);
269 403
 }
270 404
 
271 405
 int main(int argc, char ** argv)
... ...
@@ -8,6 +8,7 @@
8 8
 #include  "route_struct.h"
9 9
 
10 10
 #include <stdio.h>
11
+#include <netinet/in.h>
11 12
 
12 13
 struct expr* mk_exp(int op, struct expr* left, struct expr* right)
13 14
 {
... ...
@@ -74,8 +75,46 @@ struct action* append_action(struct action* a, struct action* b)
74 75
 	return a;
75 76
 }
76 77
 
78
+
79
+
80
+struct net* mk_net(unsigned long ip, unsigned long mask)
81
+{
82
+	struct net* n;
83
+
84
+	n=(struct net*)malloc(sizeof(struct net));
85
+	if (n==0) goto error;
86
+	n->ip=ip;
87
+	n->mask=mask;
88
+	return n;
89
+error:
90
+	fprintf(stderr, "ERROR: mk_net_mask: memory allocation failure\n");
91
+	return 0;
92
+}
93
+
77 94
 	
78 95
 	
96
+
97
+void print_ip(unsigned ip)
98
+{
99
+	ip=htonl(ip);
100
+	printf("%d.%d.%d.%d", ((unsigned char*)&ip)[0],
101
+						  ((unsigned char*)&ip)[1],
102
+						  ((unsigned char*)&ip)[2],
103
+						  ((unsigned char*)&ip)[3]);
104
+}
105
+
106
+
107
+void print_net(struct net* net)
108
+{
109
+	if (net==0){
110
+		fprintf(stderr, "ERROR: print net: null pointer\n");
111
+		return;
112
+	}
113
+	print_ip(net->ip); printf("/"); print_ip(net->mask);
114
+}
115
+
116
+
117
+
79 118
 void print_expr(struct expr* exp)
80 119
 {
81 120
 	if (exp==0){
... ...
@@ -105,8 +144,9 @@ void print_expr(struct expr* exp)
105 144
 				break;
106 145
 			case MATCH_OP:
107 146
 				printf("~=");
147
+				break;
108 148
 			default:
109
-				priint("<UNKNOWN>");
149
+				printf("<UNKNOWN>");
110 150
 		}
111 151
 		switch(exp->subtype){
112 152
 			case NOSUBTYPE: 
... ...
@@ -116,10 +156,13 @@ void print_expr(struct expr* exp)
116 156
 					printf("\"%s\"", (char*)exp->r.param);
117 157
 					break;
118 158
 			case NET_ST:
119
-					printf("");
159
+					print_net((struct net*)exp->r.param);
160
+					break;
161
+			case IP_ST:
162
+					print_ip(exp->r.intval);
120 163
 					break;
121 164
 			default:
122
-					prinf("UNKNOWN");
165
+					printf("UNKNOWN");
123 166
 		}
124 167
 	}else if (exp->type==EXP_T){
125 168
 		switch(exp->op){
... ...
@@ -11,7 +11,7 @@ enum { AND_OP=1, OR_OP, NOT_OP };
11 11
 enum { EQUAL_OP=10, MATCH_OP };
12 12
 enum { METHOD_O=1, URI_O, SRCIP_O, DSTIP_O };
13 13
 
14
-enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T};
14
+enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T};
15 15
 enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST };
16 16
 
17 17
 	
... ...
@@ -26,6 +26,7 @@ struct expr{
26 26
 	union {
27 27
 		struct expr* expr;
28 28
 		void* param;
29
+		int   intval;
29 30
 	}r;
30 31
 };
31 32
 
... ...
@@ -42,9 +43,19 @@ struct action{
42 43
 	struct action* next;
43 44
 };
44 45
 
46
+
47
+struct net{
48
+	unsigned long ip;
49
+	unsigned long mask;
50
+};
51
+
45 52
 struct expr* mk_exp(int op, struct expr* left, struct expr* right);
46 53
 struct expr* mk_elem(int op, int subtype, int operand, void* param);
47 54
 struct action* mk_action(int type, int p1_type, int p2_type, void* p1, void* p2);
55
+struct action* append_action(struct action* a, struct action* b);
56
+
57
+
58
+struct net* mk_net(unsigned long ip, unsigned long mask);
48 59
 
49 60
 void print_action(struct action* a);
50 61
 void print_expr(struct expr* exp);