File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / bird / filter / f-util.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Aug 22 12:33:54 2017 UTC (6 years, 11 months ago) by misho
Branches: bird, MAIN
CVS tags: v1_6_3p0, v1_6_3, HEAD
bird 1.6.3

    1: /*
    2:  *	Filters: utility functions
    3:  *
    4:  *	Copyright 1998 Pavel Machek <pavel@ucw.cz>
    5:  *
    6:  *	Can be freely distributed and used under the terms of the GNU GPL.
    7:  */
    8: 
    9: #include "nest/bird.h"
   10: #include "conf/conf.h"
   11: #include "filter/filter.h"
   12: 
   13: #define P(a,b) ((a<<8) | b)
   14: 
   15: struct f_inst *
   16: f_new_inst(void)
   17: {
   18:   struct f_inst * ret;
   19:   ret = cfg_alloc(sizeof(struct f_inst));
   20:   ret->code = ret->aux = 0;
   21:   ret->arg1 = ret->arg2 = ret->next = NULL;
   22:   ret->lineno = ifs->lino;
   23:   return ret;
   24: }
   25: 
   26: struct f_inst *
   27: f_new_dynamic_attr(int type, int f_type UNUSED, int code)
   28: {
   29:   /* FIXME: Remove the f_type parameter? */
   30:   struct f_inst *f = f_new_inst();
   31:   f->aux = type;
   32:   f->a2.i = code;
   33:   return f;
   34: }
   35: 
   36: /*
   37:  * Generate set_dynamic( operation( get_dynamic(), argument ) )
   38:  */
   39: struct f_inst *
   40: f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument)
   41: {
   42:   struct f_inst *set_dyn = f_new_inst(),
   43:                 *oper = f_new_inst(),
   44:                 *get_dyn = dyn;
   45: 
   46:   *set_dyn = *get_dyn;
   47:   get_dyn->code = P('e','a');
   48:   oper->code = operation;
   49:   oper->aux = operation_aux;
   50:   oper->a1.p = get_dyn;
   51:   oper->a2.p = argument;
   52:   set_dyn->code = P('e','S');
   53:   set_dyn->a1.p = oper;
   54:   return set_dyn;
   55: }
   56: 
   57: 
   58: struct f_inst *
   59: f_generate_roa_check(struct symbol *sym, struct f_inst *prefix, struct f_inst *asn)
   60: {
   61:   struct f_inst_roa_check *ret = cfg_allocz(sizeof(struct f_inst_roa_check));
   62:   ret->i.code = P('R','C');
   63:   ret->i.lineno = ifs->lino;
   64:   ret->i.arg1 = prefix;
   65:   ret->i.arg2 = asn;
   66:   /* prefix == NULL <-> asn == NULL */
   67: 
   68:   if ((sym->class != SYM_ROA) || ! sym->def)
   69:     cf_error("%s is not a ROA table", sym->name);
   70:   ret->rtc = sym->def;
   71: 
   72:   return &ret->i;
   73: }
   74: 
   75: char *
   76: filter_name(struct filter *filter)
   77: {
   78:   if (!filter)
   79:     return "ACCEPT";
   80:   else if (filter == FILTER_REJECT)
   81:     return "REJECT";
   82:   else if (!filter->name)
   83:     return "(unnamed)";
   84:   else
   85:     return filter->name;
   86: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>