HASH_INSERT2(new_config->sym_hash, SYM, new_config->pool, s);
+ add_tail(&(new_config->symbols), &(s->n));
+
return s;
}
* signify no match.
*/
struct symbol *
-cf_find_symbol(struct config *cfg, const byte *c)
+cf_find_symbol(const struct config *cfg, const byte *c)
{
struct symbol *s;
memcpy(ndup, name, nlen);
init_list(&c->tests);
+ init_list(&c->symbols);
c->mrtdump_file = -1; /* Hack, this should be sysdep-specific */
c->pool = p;
c->mem = l;
if (old_config)
old_config->obstacle_count++;
+ DBG("filter_commit\n");
+ filter_commit(c, old_config);
DBG("sysdep_commit\n");
int force_restart = sysdep_commit(c, old_config);
DBG("global_commit\n");
list tables; /* Configured routing tables (struct rtable_config) */
list logfiles; /* Configured log files (sysdep) */
list tests; /* Configured unit tests (f_bt_test_suite) */
+ list symbols; /* Configured symbols in config order */
int mrtdump_file; /* Configured MRTDump file (sysdep, fd in unix) */
char *syslog_name; /* Name used for syslog (NULL -> no syslog) */
extern int (*cf_read_hook)(byte *buf, uint max, int fd);
struct symbol {
+ node n; /* In list of symbols in config */
struct symbol *next;
struct sym_scope *scope;
int class; /* SYM_* */
void cf_lex_init(int is_cli, struct config *c);
void cf_lex_unwind(void);
-struct symbol *cf_find_symbol(struct config *cfg, const byte *c);
+struct symbol *cf_find_symbol(const struct config *cfg, const byte *c);
struct symbol *cf_get_symbol(const byte *c);
struct symbol *cf_default_name(char *template, int *counter);
FILTER CF_SYM_VOID { $2 = cf_define_symbol($2, SYM_FILTER, filter, NULL); cf_push_scope( $2 ); }
filter_body {
struct filter *f = cfg_alloc(sizeof(struct filter));
- *f = (struct filter) { .name = $2->name, .root = $4 };
+ *f = (struct filter) { .sym = $2, .root = $4 };
$2->filter = f;
cf_pop_scope();
struct f_inst *f_clear_local_vars(struct f_inst *decls);
/* Filter structures for execution */
-struct f_line;
-
/* Line of instructions to be unconditionally executed one after another */
struct f_line {
uint len; /* Line length */
- u16 args; /* Function: Args required */
+ u8 args; /* Function: Args required */
struct f_line_item items[0]; /* The items themselves */
};
return "ACCEPT";
else if (filter == FILTER_REJECT)
return "REJECT";
- else if (!filter->name)
+ else if (!filter->sym)
return "(unnamed)";
else
- return filter->name;
+ return filter->sym->name;
}
void f_inst_next(struct f_inst *first, const struct f_inst *append)
struct f_inst i = {
.fi_code = FI_CONDITION,
.lineno = ifs->lino,
- .size = 3,
+ .size = 3 + where->size,
.i_FI_CONDITION = {
.f1 = where,
.f2 = &acc,
},
};
- struct filter *f = cfg_alloc(sizeof(struct filter));
- f->name = NULL;
+ struct filter *f = cfg_allocz(sizeof(struct filter));
f->root = f_postfixify(&i);
return f;
}
if (fret < F_ACCEPT) {
if (!(fs.flags & FF_SILENT))
- log_rl(&rl_runtime_err, L_ERR "Filter %s did not return accept nor reject. Make up your mind", filter->name);
+ log_rl(&rl_runtime_err, L_ERR "Filter %s did not return accept nor reject. Make up your mind", filter_name(filter));
return F_ERROR;
}
DBG( "done (%u)\n", res.val.i );
if (old == FILTER_ACCEPT || old == FILTER_REJECT ||
new == FILTER_ACCEPT || new == FILTER_REJECT)
return 0;
- return f_same(new->root, old->root);
+
+ if ((!old->sym) && (!new->sym))
+ return f_same(new->root, old->root);
+
+ if ((!old->sym) || (!new->sym))
+ return 0;
+
+ if (strcmp(old->sym->name, new->sym->name))
+ return 0;
+
+ return new->sym->flags & SYM_FLAG_SAME;
+}
+
+/**
+ * filter_commit - do filter comparisons on all the named functions and filters
+ */
+void
+filter_commit(const struct config *new, const struct config *old)
+{
+ if (!old)
+ return;
+
+ struct symbol *sym, *osym;
+ WALK_LIST(sym, new->symbols)
+ switch (sym->class) {
+ case SYM_FUNCTION:
+ if ((osym = cf_find_symbol(old, sym->name)) &&
+ (osym->class == SYM_FUNCTION) &&
+ f_same(sym->function, osym->function))
+ sym->flags |= SYM_FLAG_SAME;
+ else
+ sym->flags &= ~SYM_FLAG_SAME;
+ break;
+
+ case SYM_FILTER:
+ if ((osym = cf_find_symbol(old, sym->name)) &&
+ (osym->class == SYM_FILTER) &&
+ f_same(sym->filter->root, osym->filter->root))
+ sym->flags |= SYM_FLAG_SAME;
+ else
+ sym->flags &= ~SYM_FLAG_SAME;
+ break;
+ }
}
/* The filter encapsulating structure to be pointed-to from outside */
struct f_line;
struct filter {
- char *name;
+ struct symbol *sym;
const struct f_line *root;
};
int filter_same(const struct filter *new, const struct filter *old);
int f_same(const struct f_line *f1, const struct f_line *f2);
+void filter_commit(const struct config *new, const struct config *old);
+
#define FILTER_ACCEPT NULL
#define FILTER_REJECT ((void *) 1)
#define FILTER_UNDEF ((void *) 2) /* Used in BGP */
--- /dev/null
+router id 1.1.1.1;
+protocol device {}
+
+function a() {
+ return true;
+}
+
+function b() {
+ return a();
+}
+
+function c() {
+ return b();
+}
+
+filter d {
+ if c() then accept; else reject;
+}
+
+protocol static {
+ ipv4 { import filter d; };
+ route 10.0.0.0/24 unreachable;
+}
--- /dev/null
+router id 1.1.1.1;
+protocol device {}
+
+function a() {
+ return false;
+}
+
+function b() {
+ return a();
+}
+
+function c() {
+ return b();
+}
+
+filter d {
+ if c() then accept; else reject;
+}
+
+protocol static {
+ ipv4 { import filter d; };
+ route 10.0.0.0/24 unreachable;
+}