]>
git.ipfire.org Git - thirdparty/bird.git/blob - filter/f-util.c
2 * Filters: utility functions
4 * Copyright 1998 Pavel Machek <pavel@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
12 #include <sys/signal.h>
15 #include "nest/bird.h"
16 #include "lib/lists.h"
17 #include "lib/resource.h"
18 #include "lib/socket.h"
19 #include "nest/route.h"
20 #include "nest/protocol.h"
21 #include "nest/iface.h"
22 #include "conf/conf.h"
23 #include "filter/filter.h"
25 struct f_inst
*autoexec_func
= NULL
;
27 #define runtime(x) do { \
29 res.type = T_RETURN; \
30 res.val.i = F_ERROR; \
35 x = interpret(what->y); \
36 if (x.type == T_RETURN) \
39 #define ONEARG ARG(v1, arg1)
40 #define TWOARGS ARG(v1, arg1) \
44 interpret(struct f_inst
*what
)
47 struct f_val v1
, v2
, res
;
59 if (v1
.type
!= v2
.type
)
60 runtime( "Can not operate with values of incompatible types" );
62 switch (res
.type
= v1
.type
) {
63 case T_VOID
: runtime( "Can not operate with values of type void" );
64 case T_INT
: res
.val
.i
= v1
.val
.i
+ v2
.val
.i
; break;
65 default: runtime( "Usage of unknown type" );
71 switch (res
.type
= v2
.type
) {
72 case T_VOID
: runtime( "Can not assign void values" );
74 if (sym
->class != SYM_VARIABLE_INT
)
75 runtime( "Variable of bad type" );
82 res
.val
.i
= (int) what
->arg1
;
86 res
.val
.i
= * ((int *) what
->arg1
);
90 printf( "Printing: " );
92 case T_VOID
: printf( "(void)" ); break;
93 case T_INT
: printf( "%d", v1
.val
.i
); break;
94 default: runtime( "Print of variable of unknown type" );
100 if (v1
.type
!= T_INT
)
101 runtime( "If requires integer expression" );
107 printf( "DEBUGGING PRINT\n" );
110 printf( "No operation\n" );
113 printf( "Puts: %s\n", (char *) what
->arg1
);
116 switch ((int) what
->arg1
) {
118 die( "Filter asked me to die" );
120 /* Should take care about turning ACCEPT into MODIFY */
124 res
.val
.i
= (int) what
->arg1
;
127 bug( "unknown return type: can not happen");
131 bug( "Unknown instruction %d (%c)", what
->code
, what
->code
& 0xff);
134 return interpret(what
->next
);
142 ret
= cfg_alloc(sizeof(struct f_inst
));
144 ret
->arg1
= ret
->arg2
= ret
->next
= NULL
;
149 f_run(struct filter
*filter
, struct rte
*rtein
, struct rte
**rteout
)
153 debug( "Running filter `%s'...", filter
->name
);
156 res
= interpret(inst
);
157 if (res
.type
!= T_RETURN
)
159 debug( "done (%d)\n", res
.val
.i
);
164 filters_postconfig(void)
167 interpret(autoexec_func
);