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

    1: /*
    2:  *	BIRD -- Configuration Parser Top
    3:  *
    4:  *	(c) 1998--2000 Martin Mares <mj@ucw.cz>
    5:  *
    6:  *	Can be freely distributed and used under the terms of the GNU GPL.
    7:  */
    8: 
    9: CF_HDR
   10: 
   11: #define PARSER 1
   12: 
   13: #include "nest/bird.h"
   14: #include "conf/conf.h"
   15: #include "lib/resource.h"
   16: #include "lib/socket.h"
   17: #include "lib/timer.h"
   18: #include "lib/string.h"
   19: #include "nest/protocol.h"
   20: #include "nest/iface.h"
   21: #include "nest/route.h"
   22: #include "nest/cli.h"
   23: #include "filter/filter.h"
   24: 
   25: /* FIXME: Turn on YYERROR_VERBOSE and work around lots of bison bugs? */
   26: 
   27: CF_DEFINES
   28: 
   29: static void
   30: check_u16(unsigned val)
   31: {
   32:   if (val > 0xFFFF)
   33:     cf_error("Value %d out of range (0-65535)", val);
   34: }
   35: 
   36: CF_DECLS
   37: 
   38: %union {
   39:   int i;
   40:   u32 i32;
   41:   ip_addr a;
   42:   struct symbol *s;
   43:   char *t;
   44:   struct rtable_config *r;
   45:   struct f_inst *x;
   46:   struct f_dynamic_attr fda;
   47:   struct f_static_attr fsa;
   48:   struct filter *f;
   49:   struct f_tree *e;
   50:   struct f_trie *trie;
   51:   struct f_val v;
   52:   struct f_path_mask *h;
   53:   struct password_item *p;
   54:   struct rt_show_data *ra;
   55:   struct roa_show_data *ro;
   56:   struct sym_show_data *sd;
   57:   struct lsadb_show_data *ld;
   58:   struct mrt_dump_data *md;
   59:   struct iface *iface;
   60:   struct roa_table *rot;
   61:   void *g;
   62:   bird_clock_t time;
   63:   struct prefix px;
   64:   struct proto_spec ps;
   65:   struct timeformat *tf;
   66: }
   67: 
   68: %token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT
   69: %token GEQ LEQ NEQ AND OR
   70: %token PO PC
   71: %token <i> NUM ENUM
   72: %token <i32> RTRID
   73: %token <a> IPA
   74: %token <s> SYM
   75: %token <t> TEXT
   76: %type <iface> ipa_scope
   77: 
   78: %type <i> expr bool pxlen
   79: %type <i32> expr_us
   80: %type <time> datetime
   81: %type <a> ipa
   82: %type <px> prefix prefix_or_ipa
   83: %type <t> text opttext
   84: %type <t> text_or_none
   85: 
   86: %nonassoc PREFIX_DUMMY
   87: %left AND OR
   88: %nonassoc '=' '<' '>' '~' GEQ LEQ NEQ NMA PO PC
   89: %left '+' '-'
   90: %left '*' '/' '%'
   91: %left '!'
   92: %nonassoc '.'
   93: 
   94: CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT)
   95: 
   96: CF_GRAMMAR
   97: 
   98: /* Basic config file structure */
   99: 
  100: config: conf_entries END { return 0; }
  101:  | CLI_MARKER cli_cmd { return 0; }
  102:  ;
  103: 
  104: conf_entries:
  105:    /* EMPTY */
  106:  | conf_entries conf
  107:  ;
  108: 
  109: CF_ADDTO(conf, ';')
  110: 
  111: 
  112: /* Constant expressions */
  113: 
  114: CF_ADDTO(conf, definition)
  115: definition:
  116:    DEFINE SYM '=' term ';' {
  117:      struct f_val *val = cfg_alloc(sizeof(struct f_val));
  118:      *val = f_eval($4, cfg_mem);
  119:      if (val->type == T_RETURN) cf_error("Runtime error");
  120:      cf_define_symbol($2, SYM_CONSTANT | val->type, val);
  121:    }
  122:  ;
  123: 
  124: expr:
  125:    NUM
  126:  | '(' term ')' { $$ = f_eval_int($2); }
  127:  | SYM {
  128:      if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected");
  129:      $$ = SYM_VAL($1).i; }
  130:  ;
  131: 
  132: 
  133: expr_us:
  134:    expr S  { $$ = (u32) $1 * 1000000; }
  135:  | expr MS { $$ = (u32) $1 * 1000; }
  136:  | expr US { $$ = (u32) $1 * 1; }
  137:  ;
  138: 
  139: /* expr_u16: expr { check_u16($1); $$ = $1; }; */
  140: 
  141: /* Switches */
  142: 
  143: bool:
  144:    expr { $$ = !!$1; }
  145:  | ON { $$ = 1; }
  146:  | YES { $$ = 1; }
  147:  | OFF { $$ = 0; }
  148:  | NO { $$ = 0; }
  149:  | /* Silence means agreement */ { $$ = 1; }
  150:  ;
  151: 
  152: /* Addresses, prefixes and netmasks */
  153: 
  154: ipa:
  155:    IPA
  156:  | SYM {
  157:      if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
  158:      $$ = SYM_VAL($1).px.ip;
  159:    }
  160:  ;
  161: 
  162: ipa_scope:
  163:    /* empty */ { $$ = NULL; }
  164:  | '%' SYM { $$ = if_get_by_name($2->name); }
  165:  ;
  166: 
  167: prefix:
  168:    ipa pxlen {
  169:      if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
  170:      $$.addr = $1; $$.len = $2;
  171:    }
  172:  ;
  173: 
  174: prefix_or_ipa:
  175:    prefix
  176:  | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
  177:  ;
  178: 
  179: pxlen:
  180:    '/' expr {
  181:      if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
  182:      $$ = $2;
  183:    }
  184:  | ':' ipa {
  185:      $$ = ipa_masklen($2);
  186:      if ($$ < 0) cf_error("Invalid netmask %I", $2);
  187:    }
  188:  ;
  189: 
  190: datetime:
  191:    TEXT {
  192:      $$ = tm_parse_datetime($1);
  193:      if (!$$)
  194:        cf_error("Invalid date and time");
  195:    }
  196:  ;
  197: 
  198: text:
  199:    TEXT
  200:  | SYM {
  201:      if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected");
  202:      $$ = SYM_VAL($1).s;
  203:    }
  204:  ;
  205: 
  206: opttext:
  207:     TEXT
  208:  | /* empty */ { $$ = NULL; }
  209:  ;
  210: 
  211: text_or_none:
  212:    TEXT { $$ = $1; }
  213:  |      { $$ = NULL; }
  214:  ;
  215: 
  216: CF_CODE
  217: 
  218: CF_END

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