File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / bird / filter / f-util.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 19:50:23 2021 UTC (3 years, 4 months ago) by misho
Branches: bird, MAIN
CVS tags: v1_6_8p3, HEAD
bird 1.6.8

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

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