confbase.Y 3.7 KB
Newer Older
Martin Mareš's avatar
Martin Mareš committed
1 2 3
/*
 *	BIRD -- Configuration Parser Top
 *
4
 *	(c) 1998--2000 Martin Mares <mj@ucw.cz>
Martin Mareš's avatar
Martin Mareš committed
5 6 7 8 9 10
 *
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

CF_HDR

11 12
#define PARSER 1

Martin Mareš's avatar
Martin Mareš committed
13 14
#include "nest/bird.h"
#include "conf/conf.h"
15 16 17
#include "lib/resource.h"
#include "lib/socket.h"
#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"
Martin Mareš's avatar
Martin Mareš committed
24

25 26
/* FIXME: Turn on YYERROR_VERBOSE and work around lots of bison bugs? */

27 28 29 30 31 32 33 34 35
CF_DEFINES

static void
check_u16(unsigned val)
{
  if (val > 0xFFFF)
    cf_error("Value %d out of range (0-65535)", val);
}

Martin Mareš's avatar
Martin Mareš committed
36 37 38 39
CF_DECLS

%union {
  int i;
40
  u32 i32;
Martin Mareš's avatar
Martin Mareš committed
41 42 43
  ip_addr a;
  struct symbol *s;
  char *t;
44
  struct rtable_config *r;
45 46
  struct f_inst *x;
  struct filter *f;
47
  struct f_tree *e;
48
  struct f_trie *trie;
49
  struct f_val v;
50
  struct f_path_mask *h;
Pavel Machek's avatar
Pavel Machek committed
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;
Martin Mareš's avatar
Martin Mareš committed
63 64
}

65
%token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT
Pavel Machek's avatar
Pavel Machek committed
66
%token GEQ LEQ NEQ AND OR
67
%token PO PC
Martin Mareš's avatar
Martin Mareš committed
68
%token <i> NUM ENUM
69
%token <i32> RTRID
Martin Mareš's avatar
Martin Mareš committed
70 71 72
%token <a> IPA
%token <s> SYM
%token <t> TEXT
73
%type <iface> ipa_scope
Martin Mareš's avatar
Martin Mareš committed
74

75
%type <i> expr bool pxlen
76
%type <i32> expr_us
77
%type <time> datetime
78
%type <a> ipa
Martin Mareš's avatar
Martin Mareš committed
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 PO PC
86
%left '+' '-'
87
%left '*' '/' '%'
88
%left '!'
89
%nonassoc '.'
90

91
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US)
92

Martin Mareš's avatar
Martin Mareš committed
93 94
CF_GRAMMAR

95 96
/* Basic config file structure */

97
config: conf_entries END { return 0; }
98
 | CLI_MARKER cli_cmd { return 0; }
Martin Mareš's avatar
Martin Mareš committed
99 100 101 102
 ;

conf_entries:
   /* EMPTY */
103
 | conf_entries conf
Martin Mareš's avatar
Martin Mareš committed
104 105
 ;

106
CF_ADDTO(conf, ';')
Martin Mareš's avatar
Martin Mareš committed
107

108

109
/* Constant expressions */
110

111 112 113 114 115 116 117 118 119 120
CF_ADDTO(conf, definition)
definition:
   DEFINE SYM '=' term ';' {
     struct f_val *val = cfg_alloc(sizeof(struct f_val));
     *val = f_eval($4, cfg_mem);
     if (val->type == T_RETURN) cf_error("Runtime error");
     cf_define_symbol($2, SYM_CONSTANT | val->type, val);
   }
 ;

121
expr:
122
   NUM
123
 | '(' term ')' { $$ = f_eval_int($2); }
124 125 126
 | SYM {
     if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected");
     $$ = SYM_VAL($1).i; }
127 128
 ;

129 130

expr_us:
131 132 133
   expr S  { $$ = (u32) $1 * 1000000; }
 | expr MS { $$ = (u32) $1 * 1000; }
 | expr US { $$ = (u32) $1 * 1; }
134 135
 ;

136 137
/* expr_u16: expr { check_u16($1); $$ = $1; }; */

138 139 140
/* Switches */

bool:
141
   expr {$$ = !!$1; }
142 143 144 145 146 147 148
 | ON { $$ = 1; }
 | YES { $$ = 1; }
 | OFF { $$ = 0; }
 | NO { $$ = 0; }
 | /* Silence means agreement */ { $$ = 1; }
 ;

149 150 151 152 153
/* Addresses, prefixes and netmasks */

ipa:
   IPA
 | SYM {
154 155
     if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
     $$ = SYM_VAL($1).px.ip;
156 157
   }
 ;
158

159 160 161 162 163
ipa_scope:
   /* empty */ { $$ = NULL; }
 | '%' SYM { $$ = if_get_by_name($2->name); }
 ;

164
prefix:
165
   ipa pxlen {
166 167 168 169 170
     if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
     $$.addr = $1; $$.len = $2;
   }
 ;

Martin Mareš's avatar
Martin Mareš committed
171 172
prefix_or_ipa:
   prefix
173
 | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
Martin Mareš's avatar
Martin Mareš committed
174 175
 ;

176
pxlen:
177
   '/' expr {
178
     if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
179 180
     $$ = $2;
   }
181
 | ':' ipa {
182 183 184 185 186
     $$ = ipa_mklen($2);
     if ($$ < 0) cf_error("Invalid netmask %I", $2);
   }
 ;

Martin Mareš's avatar
Martin Mareš committed
187
datetime:
188
   TEXT {
189
     $$ = tm_parse_datetime($1);
190
     if (!$$)
191
       cf_error("Invalid date and time");
192
   }
Pavel Machek's avatar
Pavel Machek committed
193 194
 ;

195 196 197 198 199 200 201 202
text:
   TEXT
 | SYM {
     if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected");
     $$ = SYM_VAL($1).s;
   }
 ;

203 204 205 206 207
text_or_none:
   TEXT { $$ = $1; }
 |      { $$ = NULL; }
 ;

Martin Mareš's avatar
Martin Mareš committed
208 209 210
CF_CODE

CF_END