]> git.ipfire.org Git - thirdparty/bird.git/blobdiff - filter/f-util.c
Doc: Update prefix set comment
[thirdparty/bird.git] / filter / f-util.c
index e94331b66f76eed01961dedb73a6a1bd9de62e8c..410999a640ce009895edf47e684bb9f26e9ad20d 100644 (file)
 #include "nest/bird.h"
 #include "conf/conf.h"
 #include "filter/filter.h"
-#include "filter/f-inst-struct.h"
+#include "filter/f-inst.h"
 #include "lib/idm.h"
 #include "nest/protocol.h"
 #include "nest/route.h"
 
 #define P(a,b) ((a<<8) | b)
 
-static const char * const f_instruction_name_str[] = {
-#define F(c,...) \
-  [c] = #c,
-FI__LIST
-#undef F
-};
-
 const char *
-f_instruction_name(enum f_instruction_code fi)
-{
-  if (fi < FI__MAX)
-    return f_instruction_name_str[fi];
-  else
-    bug("Got unknown instruction code: %d", fi);
-}
-
-char *
-filter_name(struct filter *filter)
+filter_name(const struct filter *filter)
 {
   if (!filter)
     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 filter *f_new_where(struct f_inst *where)
 {
-  first->next = append;
-}
+  struct f_inst *cond = f_new_inst(FI_CONDITION, where,
+                                  f_new_inst(FI_DIE, F_ACCEPT),
+                                  f_new_inst(FI_DIE, F_REJECT));
 
-struct filter *f_new_where(const struct f_inst *where)
-{
-  struct f_inst acc = {
-    .fi_code = FI_PRINT_AND_DIE,
-    .lineno = ifs->lino,
-    .i_FI_PRINT_AND_DIE = { .fret = F_ACCEPT, },
-  };
-
-  struct f_inst rej = {
-    .fi_code = FI_PRINT_AND_DIE,
-    .lineno = ifs->lino,
-    .i_FI_PRINT_AND_DIE = { .fret = F_REJECT, },
-  };
-
-  struct f_inst i = {
-    .fi_code = FI_CONDITION,
-    .lineno = ifs->lino,
-    .i_FI_CONDITION = {
-      .f1 = where,
-      .f2 = &acc,
-      .f3 = &rej,
-    },
-  };
-
-  struct filter *f = cfg_alloc(sizeof(struct filter));
-  f->name = NULL;
-  f->root = f_postfixify(&i);
+  struct filter *f = cfg_allocz(sizeof(struct filter));
+  f->root = f_linearize(cond);
   return f;
 }
 
-struct f_inst *f_clear_local_vars(struct f_inst *decls)
-{
-  /* Prepend instructions to clear local variables */
-  struct f_inst *head = NULL;
-
-  for (const struct f_inst *si = decls; si; si = si->next) {
-    struct f_inst *cur = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_VOID });
-    if (head)
-      f_inst_next(cur, head);
-    else
-      f_inst_next(cur, si);
-    head = cur;        /* The first FI_CONSTANT put there */
-  }
-
-  return head;
-}
-
 #define CA_KEY(n)      n->name, n->fda.type
 #define CA_NEXT(n)     n->next
 #define CA_EQ(na,ta,nb,tb)     (!strcmp(na,nb) && (ta == tb))
@@ -210,7 +153,7 @@ ca_lookup(pool *p, const char *name, int f_type)
     }
 
     cas = mb_allocz(&root_pool, sizeof(struct ca_storage) + strlen(name) + 1);
-    cas->fda = f_new_dynamic_attr(ea_type, 0, f_type, EA_CUSTOM(id));
+    cas->fda = f_new_dynamic_attr(ea_type, f_type, EA_CUSTOM(id));
     cas->uc = 1;
 
     strcpy(cas->name, name);