0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-15 07:38:43 +00:00
bird/filter/f-inst.h

122 lines
3.7 KiB
C
Raw Normal View History

/*
* BIRD Internet Routing Daemon -- Filter instructions
*
* (c) 1999 Pavel Machek <pavel@ucw.cz>
* (c) 2018--2019 Maria Matejka <mq@jmq.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*
* Filter interpreter data structures and internal API.
2019-07-15 11:19:01 +00:00
* See filter/f-inst.c for documentation.
*/
#ifndef _BIRD_F_INST_H_
#define _BIRD_F_INST_H_
#include "nest/bird.h"
#include "conf/conf.h"
#include "filter/filter.h"
#include "filter/data.h"
#include "lib/buffer.h"
#include "lib/flowspec.h"
/* Flags for instructions */
enum f_instruction_flags {
FIF_RECURSIVE = 1, /* FI_CALL: function is directly recursive */
} PACKED;
/* Include generated filter instruction declarations */
#include "filter/inst-gen.h"
#define f_new_inst(...) MACRO_CONCAT_AFTER(f_new_inst_, MACRO_FIRST(__VA_ARGS__))(__VA_ARGS__)
/* Convert the instruction back to the enum name */
const char *f_instruction_name_(enum f_instruction_code fi);
static inline const char *f_instruction_name(enum f_instruction_code fi)
{ return f_instruction_name_(fi) + 3; }
struct f_arg {
struct symbol *arg;
struct f_arg *next;
};
/* Filter structures for execution */
/* Line of instructions to be unconditionally executed one after another */
struct f_line {
uint len; /* Line length */
u8 args; /* Function: Args required */
u8 vars;
u8 results; /* Results left on stack: cmd -> 0, term -> 1 */
struct f_arg *arg_list;
struct f_line_item items[0]; /* The items themselves */
};
/* Convert the f_inst infix tree to the f_line structures */
struct f_line *f_linearize_concat(const struct f_inst * const inst[], uint count, uint results);
static inline struct f_line *f_linearize(const struct f_inst *root, uint results)
{ return f_linearize_concat(&root, 1, results); }
void f_dump_line(const struct f_line *, uint indent);
/* Recursive iteration over filter instructions */
struct filter_iterator {
BUFFER_(const struct f_line *) lines;
};
void f_add_lines(const struct f_line_item *what, struct filter_iterator *fit);
#define FILTER_ITERATE_INIT(fit, filter, pool) \
({ \
BUFFER_INIT((fit)->lines, (pool), 32); \
BUFFER_PUSH((fit)->lines) = (filter)->root; \
})
#define FILTER_ITERATE(fit, fi) ({ \
const struct f_line *fl_; \
while (!BUFFER_EMPTY((fit)->lines)) \
{ \
BUFFER_POP((fit)->lines); \
fl_ = (fit)->lines.data[(fit)->lines.used]; \
for (uint i_ = 0; i_ < fl_->len; i_++) \
{ \
const struct f_line_item *fi = &fl_->items[i_]; \
f_add_lines(fi, (fit));
#define FILTER_ITERATE_END } } })
#define FILTER_ITERATE_CLEANUP(fit) \
({ \
mb_free((fit)->lines.data); \
memset((fit), 0, sizeof(struct filter_iterator)); \
})
struct filter *f_new_where(struct f_inst *);
static inline struct f_static_attr f_new_static_attr(btype type, int code, int readonly)
{ return (struct f_static_attr) { .type = type, .sa_code = code, .readonly = readonly }; }
struct f_inst *f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn);
struct f_attr_bit {
const struct ea_class *class;
uint bit;
};
#define f_new_dynamic_attr_bit(_bit, _name) ((struct f_attr_bit) { .bit = _bit, .class = ea_class_find(_name) })
/* Hook for call bt_assert() function in configuration */
extern void (*bt_assert_hook)(int result, const struct f_line_item *assert);
/* Bird Tests */
struct f_bt_test_suite {
node n; /* Node in config->tests */
const struct f_line *fn; /* Root of function */
const struct f_line *cmp; /* Compare to this function */
const char *fn_name; /* Name of test */
const char *dsc; /* Description */
int result; /* Desired result */
};
#endif