File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / bird / conf / confbase.Y
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, 10 months ago) by misho
Branches: bird, MAIN
CVS tags: v1_6_3p0, v1_6_3, HEAD
bird 1.6.3

    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 filter *f;
   47:   struct f_tree *e;
   48:   struct f_trie *trie;
   49:   struct f_val v;
   50:   struct f_path_mask *h;
   51:   struct password_item *p;
   52:   struct rt_show_data *ra;
   53:   struct roa_show_data *ro;
   54:   struct sym_show_data *sd;
   55:   struct lsadb_show_data *ld;
   56:   struct iface *iface;
   57:   struct roa_table *rot;
   58:   void *g;
   59:   bird_clock_t time;
   60:   struct prefix px;
   61:   struct proto_spec ps;
   62:   struct timeformat *tf;
   63: }
   64: 
   65: %token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT
   66: %token GEQ LEQ NEQ AND OR
   67: %token PO PC
   68: %token <i> NUM ENUM
   69: %token <i32> RTRID
   70: %token <a> IPA
   71: %token <s> SYM
   72: %token <t> TEXT
   73: %type <iface> ipa_scope
   74: 
   75: %type <i> expr bool pxlen
   76: %type <i32> expr_us
   77: %type <time> datetime
   78: %type <a> ipa
   79: %type <px> prefix prefix_or_ipa
   80: %type <t> text
   81: %type <t> text_or_none
   82: 
   83: %nonassoc PREFIX_DUMMY
   84: %left AND OR
   85: %nonassoc '=' '<' '>' '~' GEQ LEQ NEQ NMA PO PC
   86: %left '+' '-'
   87: %left '*' '/' '%'
   88: %left '!'
   89: %nonassoc '.'
   90: 
   91: CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT)
   92: 
   93: CF_GRAMMAR
   94: 
   95: /* Basic config file structure */
   96: 
   97: config: conf_entries END { return 0; }
   98:  | CLI_MARKER cli_cmd { return 0; }
   99:  ;
  100: 
  101: conf_entries:
  102:    /* EMPTY */
  103:  | conf_entries conf
  104:  ;
  105: 
  106: CF_ADDTO(conf, ';')
  107: 
  108: 
  109: /* Constant expressions */
  110: 
  111: CF_ADDTO(conf, definition)
  112: definition:
  113:    DEFINE SYM '=' term ';' {
  114:      struct f_val *val = cfg_alloc(sizeof(struct f_val));
  115:      *val = f_eval($4, cfg_mem);
  116:      if (val->type == T_RETURN) cf_error("Runtime error");
  117:      cf_define_symbol($2, SYM_CONSTANT | val->type, val);
  118:    }
  119:  ;
  120: 
  121: expr:
  122:    NUM
  123:  | '(' term ')' { $$ = f_eval_int($2); }
  124:  | SYM {
  125:      if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected");
  126:      $$ = SYM_VAL($1).i; }
  127:  ;
  128: 
  129: 
  130: expr_us:
  131:    expr S  { $$ = (u32) $1 * 1000000; }
  132:  | expr MS { $$ = (u32) $1 * 1000; }
  133:  | expr US { $$ = (u32) $1 * 1; }
  134:  ;
  135: 
  136: /* expr_u16: expr { check_u16($1); $$ = $1; }; */
  137: 
  138: /* Switches */
  139: 
  140: bool:
  141:    expr { $$ = !!$1; }
  142:  | ON { $$ = 1; }
  143:  | YES { $$ = 1; }
  144:  | OFF { $$ = 0; }
  145:  | NO { $$ = 0; }
  146:  | /* Silence means agreement */ { $$ = 1; }
  147:  ;
  148: 
  149: /* Addresses, prefixes and netmasks */
  150: 
  151: ipa:
  152:    IPA
  153:  | SYM {
  154:      if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
  155:      $$ = SYM_VAL($1).px.ip;
  156:    }
  157:  ;
  158: 
  159: ipa_scope:
  160:    /* empty */ { $$ = NULL; }
  161:  | '%' SYM { $$ = if_get_by_name($2->name); }
  162:  ;
  163: 
  164: prefix:
  165:    ipa pxlen {
  166:      if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
  167:      $$.addr = $1; $$.len = $2;
  168:    }
  169:  ;
  170: 
  171: prefix_or_ipa:
  172:    prefix
  173:  | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
  174:  ;
  175: 
  176: pxlen:
  177:    '/' expr {
  178:      if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
  179:      $$ = $2;
  180:    }
  181:  | ':' ipa {
  182:      $$ = ipa_masklen($2);
  183:      if ($$ < 0) cf_error("Invalid netmask %I", $2);
  184:    }
  185:  ;
  186: 
  187: datetime:
  188:    TEXT {
  189:      $$ = tm_parse_datetime($1);
  190:      if (!$$)
  191:        cf_error("Invalid date and time");
  192:    }
  193:  ;
  194: 
  195: text:
  196:    TEXT
  197:  | SYM {
  198:      if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected");
  199:      $$ = SYM_VAL($1).s;
  200:    }
  201:  ;
  202: 
  203: text_or_none:
  204:    TEXT { $$ = $1; }
  205:  |      { $$ = NULL; }
  206:  ;
  207: 
  208: CF_CODE
  209: 
  210: CF_END

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