]>
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>
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"
24 struct f_inst
*last_func
= NULL
;
29 interpret(struct f_inst
*what
)
32 struct f_val v1
, v2
, res
;
40 interpret(what
->arg1
);
41 interpret(what
->arg2
);
44 v1
= interpret(what
->arg1
);
45 v2
= interpret(what
->arg2
);
46 if (v1
.type
!= v2
.type
)
47 runtime( "Can not operate with values of incompatible types" );
49 switch (res
.type
= v1
.type
) {
50 case T_VOID
: runtime( "Can not operate with values of type void" );
51 case T_INT
: res
.val
.i
= v1
.val
.i
+ v2
.val
.i
; break;
52 default: runtime( "Usage of unknown type" );
56 v1
= interpret(what
->arg2
);
58 switch (res
.type
= v1
.type
) {
59 case T_VOID
: runtime( "Can not assign void values" );
61 if (sym
->class != SYM_VARIABLE_INT
)
62 runtime( "Variable of bad type" );
69 res
.val
.i
= (int) what
->arg1
;
73 res
.val
.i
= * ((int *) what
->arg1
);
76 v1
= interpret(what
->arg1
);
77 printf( "Printing: " );
79 case T_VOID
: printf( "(void)" ); break;
80 case T_INT
: printf( "%d", v1
.val
.i
); break;
81 default: runtime( "Print of variable of unknown type" );
86 v1
= interpret(what
->arg1
);
88 runtime( "If requires integer expression" );
90 res
= interpret(what
->arg2
);
93 printf( "DEBUGGING PRINT\n" );
96 printf( "No operation\n" );
99 printf( "Puts: %s\n", what
->arg1
);
102 die( "Filter asked me to die" );
104 die( "Unknown insruction %d(%c)", what
->code
, what
->code
& 0xff);
107 return interpret(what
->next
);
112 filters_postconfig(void)
115 printf( "No function defined\n" );
117 interpret(last_func
);
125 ret
= cfg_alloc(sizeof(struct f_inst
));
127 ret
->arg1
= ret
->arg2
= ret
->next
= NULL
;
132 f_run(struct symbol
*filter
, struct rte
*rtein
, struct rte
**rteout
)
135 debug( "Running filter `%s'...", filter
->name
);