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