]> git.ipfire.org Git - thirdparty/bird.git/blob - filter/f-util.c
Add interface for running filters (please comment!), avoid bison warnings
[thirdparty/bird.git] / filter / f-util.c
1 /*
2 * Filters: utility functions
3 *
4 * Copyright 1998 Pavel Machek <pavel@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 #include <stdio.h>
10 #include <fcntl.h>
11 #include <unistd.h>
12 #include <sys/signal.h>
13
14 #include "nest/bird.h"
15 #include "lib/lists.h"
16 #include "lib/resource.h"
17 #include "lib/socket.h"
18 #include "nest/route.h"
19 #include "nest/protocol.h"
20 #include "nest/iface.h"
21 #include "conf/conf.h"
22 #include "filter/filter.h"
23
24 struct f_instruction *last_func = NULL;
25
26 static void
27 interpret(struct f_instruction *what)
28 {
29 struct symbol *sym;
30 if (!what)
31 return;
32 switch(what->code) {
33 case ',':
34 interpret(what->arg1);
35 interpret(what->arg2);
36 break;
37 case '=':
38 sym = what->arg1;
39 sym->aux = (int) what->arg2;
40 break;
41 case 'p':
42 sym = what->arg1;
43 switch(sym->class) {
44 case SYM_VARIABLE_INT:
45 printf( "Printing: %d\n", sym->aux );
46 break;
47 default:
48 printf( "Unknown type passed to print\n" );
49 break;
50 }
51 break;
52 case 'D':
53 printf( "DEBUGGING PRINT\n" );
54 break;
55 case '0':
56 printf( "No operation\n" );
57 break;
58 }
59 interpret(what->next);
60 }
61
62 void
63 filters_postconfig(void)
64 {
65 if (!last_func)
66 printf( "No function defined\n" );
67 else {
68 interpret(last_func);
69 }
70 }
71
72 struct f_instruction *
73 f_new_inst(void)
74 {
75 struct f_instruction * ret;
76 ret = cfg_alloc(sizeof(struct f_instruction));
77 ret->code = 0;
78 ret->arg1 = ret->arg2 = ret->next = NULL;
79 return ret;
80 }
81
82 int
83 f_run(struct symbol *filter, struct rte *rtein, struct rte **rteout)
84 {
85 struct f_instruction *inst;
86 debug( "Running filter `%s'...", filter->name );
87
88 inst = filter->def;
89 interpret(inst);
90 debug( "done\n" );
91 return F_ACCEPT;
92 }