mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 09:41:54 +00:00
Line numbers for runtime errors (what's wrong with cvs? I could not
commit this from home)
This commit is contained in:
parent
7581b81bd7
commit
a96a979d5b
@ -19,6 +19,7 @@ f_new_inst(void)
|
|||||||
ret = cfg_alloc(sizeof(struct f_inst));
|
ret = cfg_alloc(sizeof(struct f_inst));
|
||||||
ret->code = ret->aux = 0;
|
ret->code = ret->aux = 0;
|
||||||
ret->arg1 = ret->arg2 = ret->next = NULL;
|
ret->arg1 = ret->arg2 = ret->next = NULL;
|
||||||
|
ret->lineno = conf_lino;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
|
|
||||||
#define P(a,b) ((a<<8) | b)
|
#define P(a,b) ((a<<8) | b)
|
||||||
|
|
||||||
|
struct f_inst *startup_func = NULL, *test1_func, *test2_func;
|
||||||
|
|
||||||
#define CMP_ERROR 999
|
#define CMP_ERROR 999
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -187,7 +189,7 @@ static int f_flags;
|
|||||||
static rta *f_rta_copy;
|
static rta *f_rta_copy;
|
||||||
|
|
||||||
#define runtime(x) do { \
|
#define runtime(x) do { \
|
||||||
log( L_ERR x ); \
|
log( L_ERR "filters, line %d: %s", what->lineno, x); \
|
||||||
res.type = T_RETURN; \
|
res.type = T_RETURN; \
|
||||||
res.val.i = F_ERROR; \
|
res.val.i = F_ERROR; \
|
||||||
return res; \
|
return res; \
|
||||||
@ -230,22 +232,6 @@ interpret(struct f_inst *what)
|
|||||||
default: runtime( "Usage of unknown type" );
|
default: runtime( "Usage of unknown type" );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '-':
|
|
||||||
TWOARGS_C;
|
|
||||||
switch (res.type = v1.type) {
|
|
||||||
case T_VOID: runtime( "Can not operate with values of type void" );
|
|
||||||
case T_INT: res.val.i = v1.val.i - v2.val.i; break;
|
|
||||||
default: runtime( "Usage of unknown type" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '*':
|
|
||||||
TWOARGS_C;
|
|
||||||
switch (res.type = v1.type) {
|
|
||||||
case T_VOID: runtime( "Can not operate with values of type void" );
|
|
||||||
case T_INT: res.val.i = v1.val.i * v2.val.i; break;
|
|
||||||
default: runtime( "Usage of unknown type" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '/':
|
case '/':
|
||||||
TWOARGS_C;
|
TWOARGS_C;
|
||||||
switch (res.type = v1.type) {
|
switch (res.type = v1.type) {
|
||||||
@ -598,8 +584,6 @@ i_same(struct f_inst *f1, struct f_inst *f2)
|
|||||||
switch(f1->code) {
|
switch(f1->code) {
|
||||||
case ',': /* fall through */
|
case ',': /* fall through */
|
||||||
case '+':
|
case '+':
|
||||||
case '-':
|
|
||||||
case '*':
|
|
||||||
case '/':
|
case '/':
|
||||||
case P('!','='):
|
case P('!','='):
|
||||||
case P('=','='):
|
case P('=','='):
|
||||||
@ -681,21 +665,23 @@ f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struc
|
|||||||
return res.val.i;
|
return res.val.i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
f_eval_int(struct f_inst *expr)
|
filters_postconfig(void)
|
||||||
{
|
{
|
||||||
struct f_val res;
|
struct f_val res;
|
||||||
|
|
||||||
f_flags = 0;
|
#if 1
|
||||||
f_tmp_attrs = NULL;
|
if (!i_same(test1_func, test2_func))
|
||||||
f_rte = NULL;
|
bug("i_same does not work");
|
||||||
f_rte_old = NULL;
|
#endif
|
||||||
f_rta_copy = NULL;
|
if (startup_func) {
|
||||||
f_pool = cfg_mem;
|
debug( "Launching startup function...\n" );
|
||||||
res = interpret(expr);
|
f_pool = lp_new(&root_pool, 1024);
|
||||||
if (res.type != T_INT)
|
res = interpret(startup_func);
|
||||||
cf_error("Integer expression expected");
|
if (res.type == F_ERROR)
|
||||||
return res.val.i;
|
die( "Startup function resulted in error." );
|
||||||
|
debug( "done\n" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,12 +25,13 @@ struct f_inst { /* Instruction */
|
|||||||
int i;
|
int i;
|
||||||
void *p;
|
void *p;
|
||||||
} a2;
|
} a2;
|
||||||
|
int lineno;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define arg1 a1.p
|
#define arg1 a1.p
|
||||||
#define arg2 a2.p
|
#define arg2 a2.p
|
||||||
|
|
||||||
struct f_prefix {
|
struct prefix {
|
||||||
ip_addr ip;
|
ip_addr ip;
|
||||||
int len;
|
int len;
|
||||||
#define LEN_MASK 0xff
|
#define LEN_MASK 0xff
|
||||||
@ -45,7 +46,7 @@ struct f_val {
|
|||||||
union {
|
union {
|
||||||
int i;
|
int i;
|
||||||
/* ip_addr ip; Folded into prefix */
|
/* ip_addr ip; Folded into prefix */
|
||||||
struct f_prefix px;
|
struct prefix px;
|
||||||
char *s;
|
char *s;
|
||||||
struct f_tree *t;
|
struct f_tree *t;
|
||||||
struct adata *ad;
|
struct adata *ad;
|
||||||
@ -58,6 +59,7 @@ struct filter {
|
|||||||
struct f_inst *root;
|
struct f_inst *root;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void filters_postconfig(void);
|
||||||
struct f_inst *f_new_inst(void);
|
struct f_inst *f_new_inst(void);
|
||||||
struct f_inst *f_new_dynamic_attr(int type, int f_type, int code); /* Type as core knows it, type as filters know it, and code of dynamic attribute */
|
struct f_inst *f_new_dynamic_attr(int type, int f_type, int code); /* Type as core knows it, type as filters know it, and code of dynamic attribute */
|
||||||
struct f_tree *f_new_tree(void);
|
struct f_tree *f_new_tree(void);
|
||||||
@ -70,7 +72,6 @@ struct ea_list;
|
|||||||
struct rte;
|
struct rte;
|
||||||
|
|
||||||
int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags);
|
int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags);
|
||||||
int f_eval_int(struct f_inst *expr);
|
|
||||||
char *filter_name(struct filter *filter);
|
char *filter_name(struct filter *filter);
|
||||||
int filter_same(struct filter *new, struct filter *old);
|
int filter_same(struct filter *new, struct filter *old);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user