Statistics
| Branch: | Revision:

iof-bird-daemon / conf / confbase.Y @ d14f8c3c

History | View | Annotate | Download (6.06 KB)

1 f142750d Martin Mares
/*
2
 *	BIRD -- Configuration Parser Top
3
 *
4 aee539f2 Martin Mares
 *	(c) 1998--2000 Martin Mares <mj@ucw.cz>
5 f142750d Martin Mares
 *
6
 *	Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8
9
CF_HDR
10
11 93e868c7 Ondrej Zajicek
#define PARSER 1
12
13 f142750d Martin Mares
#include "nest/bird.h"
14
#include "conf/conf.h"
15 c74c0e3c Martin Mares
#include "lib/resource.h"
16
#include "lib/socket.h"
17 7152e5ef Jan Moskyto Matejka
#include "sysdep/unix/timer.h"
18 221135d6 Martin Mares
#include "lib/string.h"
19 c74c0e3c Martin Mares
#include "nest/protocol.h"
20 50d8424a Martin Mares
#include "nest/iface.h"
21 166b9c49 Martin Mares
#include "nest/route.h"
22 bc2fb680 Martin Mares
#include "nest/cli.h"
23 b9d70dc8 Pavel Machek
#include "filter/filter.h"
24 f142750d Martin Mares
25 f2c6c80a Martin Mares
/* FIXME: Turn on YYERROR_VERBOSE and work around lots of bison bugs? */
26
27 b8cc390e Ondrej Zajicek
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 f142750d Martin Mares
CF_DECLS
37
38
%union {
39
  int i;
40 dce26783 Martin Mares
  u32 i32;
41 f142750d Martin Mares
  ip_addr a;
42 fe9f1a6d Ondrej Zajicek (work)
  ip4_addr ip4;
43
  ip6_addr ip6;
44 04632fd7 Ondrej Zajicek (work)
  net_addr net;
45 d44e686e Ondrej Zajicek (work)
  net_addr *net_ptr;
46 f142750d Martin Mares
  struct symbol *s;
47
  char *t;
48 0e02abfd Martin Mares
  struct rtable_config *r;
49 f4a60a9b Ondrej Zajicek (work)
  struct channel_config *cc;
50 e0f2e42f Martin Mares
  struct f_inst *x;
51
  struct filter *f;
52 38506f71 Pavel Machek
  struct f_tree *e;
53 b1a597e0 Ondrej Zajicek
  struct f_trie *trie;
54 38506f71 Pavel Machek
  struct f_val v;
55 dcab7890 Pavel Machek
  struct f_path_mask *h;
56 9d79fec8 Pavel Machek
  struct password_item *p;
57 730f2e2c Martin Mares
  struct rt_show_data *ra;
58 0f808c06 Ondrej Zajicek
  struct sym_show_data *sd;
59 20ab192b Ondrej Zajicek
  struct lsadb_show_data *ld;
60 69a8259c Ondrej Zajicek
  struct iface *iface;
61 4ab5331c Martin Mares
  void *g;
62 aee539f2 Martin Mares
  bird_clock_t time;
63 5e173e9f Jan Moskyto Matejka
  struct f_prefix px;
64 e304fd4b Ondrej Zajicek
  struct proto_spec ps;
65 f4a60a9b Ondrej Zajicek (work)
  struct channel_limit cl;
66 c37e7851 Ondrej Zajicek
  struct timeformat *tf;
67 f2010f9c Jan Moskyto Matejka
  u32 *lbl;
68 f142750d Martin Mares
}
69
70 b8cc390e Ondrej Zajicek
%token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT
71 5f4aee76 Pavel Machek
%token GEQ LEQ NEQ AND OR
72 cf186034 Ondrej Zajicek
%token PO PC
73 944f008a Martin Mares
%token <i> NUM ENUM
74 fe9f1a6d Ondrej Zajicek (work)
%token <ip4> IP4
75
%token <ip6> IP6
76 f142750d Martin Mares
%token <s> SYM
77
%token <t> TEXT
78 69a8259c Ondrej Zajicek
%type <iface> ipa_scope
79 f142750d Martin Mares
80 04632fd7 Ondrej Zajicek (work)
%type <i> expr bool pxlen4
81 6a8d3f1c Ondrej Zajicek
%type <i32> expr_us
82 aee539f2 Martin Mares
%type <time> datetime
83 04632fd7 Ondrej Zajicek (work)
%type <a> ipa
84 a4caa1c0 Pavel Tvrdík
%type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa
85
%type <net_ptr> net_ net_any net_roa4_ net_roa6_ net_roa_
86 f2010f9c Jan Moskyto Matejka
%type <lbl> label_stack_start label_stack
87 d44e686e Ondrej Zajicek (work)
88
%type <t> text opttext
89 0b62c3a7 Martin Mares
90 60de3356 Pavel Machek
%nonassoc PREFIX_DUMMY
91 1960d203 Ondrej Filip
%left AND OR
92 768d5e10 Pavel Tvrdik
%nonassoc '=' '<' '>' '~' GEQ LEQ NEQ NMA PO PC
93 1960d203 Ondrej Filip
%left '+' '-'
94 0b62c3a7 Martin Mares
%left '*' '/' '%'
95 23b1539b Pavel Machek
%left '!'
96 112d71a7 Ondrej Zajicek
%nonassoc '.'
97 0b62c3a7 Martin Mares
98 dcde7ae5 Ondrej Zajicek
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT)
99 0b62c3a7 Martin Mares
100 f142750d Martin Mares
CF_GRAMMAR
101
102 0b62c3a7 Martin Mares
/* Basic config file structure */
103
104 bc2fb680 Martin Mares
config: conf_entries END { return 0; }
105 ffb59d24 Martin Mares
 | CLI_MARKER cli_cmd { return 0; }
106 f142750d Martin Mares
 ;
107
108
conf_entries:
109
   /* EMPTY */
110 7f400d1c Martin Mares
 | conf_entries conf
111 f142750d Martin Mares
 ;
112
113 7f400d1c Martin Mares
CF_ADDTO(conf, ';')
114 f142750d Martin Mares
115 1103b32e Ondrej Zajicek
116 72380a34 Pavel Machek
/* Constant expressions */
117 0b62c3a7 Martin Mares
118 1103b32e Ondrej Zajicek
CF_ADDTO(conf, definition)
119
definition:
120
   DEFINE SYM '=' term ';' {
121
     struct f_val *val = cfg_alloc(sizeof(struct f_val));
122
     *val = f_eval($4, cfg_mem);
123
     if (val->type == T_RETURN) cf_error("Runtime error");
124
     cf_define_symbol($2, SYM_CONSTANT | val->type, val);
125
   }
126
 ;
127
128 c9b66706 Martin Mares
expr:
129 0b62c3a7 Martin Mares
   NUM
130 cc590a11 Martin Mares
 | '(' term ')' { $$ = f_eval_int($2); }
131 1103b32e Ondrej Zajicek
 | SYM {
132
     if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected");
133
     $$ = SYM_VAL($1).i; }
134 0b62c3a7 Martin Mares
 ;
135
136 6a8d3f1c Ondrej Zajicek
137
expr_us:
138 0e175f9f Ondrej Zajicek
   expr S  { $$ = (u32) $1 * 1000000; }
139
 | expr MS { $$ = (u32) $1 * 1000; }
140
 | expr US { $$ = (u32) $1 * 1; }
141 6a8d3f1c Ondrej Zajicek
 ;
142
143 166b9c49 Martin Mares
/* Switches */
144
145
bool:
146 c8cafc8e Ondrej Zajicek (work)
   expr { $$ = !!$1; }
147 166b9c49 Martin Mares
 | ON { $$ = 1; }
148
 | YES { $$ = 1; }
149
 | OFF { $$ = 0; }
150
 | NO { $$ = 0; }
151
 | /* Silence means agreement */ { $$ = 1; }
152
 ;
153
154 e3f2d5fc Martin Mares
155 04632fd7 Ondrej Zajicek (work)
/* Addresses */
156 fe9f1a6d Ondrej Zajicek (work)
157 e3f2d5fc Martin Mares
ipa:
158 04632fd7 Ondrej Zajicek (work)
   IP4 { $$ = ipa_from_ip4($1); }
159
 | IP6 { $$ = ipa_from_ip6($1); }
160 e3f2d5fc Martin Mares
 | SYM {
161 1103b32e Ondrej Zajicek
     if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
162 5e173e9f Jan Moskyto Matejka
     $$ = SYM_VAL($1).ip;
163 e3f2d5fc Martin Mares
   }
164
 ;
165 89d2355d Martin Mares
166 69a8259c Ondrej Zajicek
ipa_scope:
167
   /* empty */ { $$ = NULL; }
168
 | '%' SYM { $$ = if_get_by_name($2->name); }
169
 ;
170
171 d44e686e Ondrej Zajicek (work)
172 04632fd7 Ondrej Zajicek (work)
/* Networks - internal */
173 d44e686e Ondrej Zajicek (work)
174 04632fd7 Ondrej Zajicek (work)
pxlen4:
175
   '/' NUM {
176
     if ($2 < 0 || $2 > IP4_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $2);
177
     $$ = $2;
178
   }
179
 | ':' IP4 {
180
     $$ = ip4_masklen($2);
181 e691d16a Ondrej Zajicek (work)
     if ($$ == 255) cf_error("Invalid netmask %I4", $2);
182 04632fd7 Ondrej Zajicek (work)
   }
183
 ;
184 d44e686e Ondrej Zajicek (work)
185 04632fd7 Ondrej Zajicek (work)
net_ip4_: IP4 pxlen4
186
{
187
  net_fill_ip4(&($$), $1, $2);
188
  if (!net_validate_ip4((net_addr_ip4 *) &($$)))
189
    cf_error("Invalid IPv4 prefix");
190
};
191 d44e686e Ondrej Zajicek (work)
192 04632fd7 Ondrej Zajicek (work)
net_ip6_: IP6 '/' NUM
193
{
194
  net_fill_ip6(&($$), $1, $3);
195
  if ($3 < 0 || $3 > IP6_MAX_PREFIX_LENGTH)
196
    cf_error("Invalid prefix length %d", $3);
197
  if (!net_validate_ip6((net_addr_ip6 *) &($$)))
198
    cf_error("Invalid IPv6 prefix");
199
};
200 d44e686e Ondrej Zajicek (work)
201 513ad0a8 Pavel Tvrdík
net_roa4_: net_ip4_ MAX NUM AS NUM
202
{
203 a4caa1c0 Pavel Tvrdík
  $$ = cfg_alloc(sizeof(net_addr_roa4));
204 286e2011 Ondrej Zajicek (work)
  net_fill_roa4($$, net4_prefix(&$1), net4_pxlen(&$1), $3, $5);
205 8860e991 Ondrej Zajicek (work)
  if ($3 < (int) net4_pxlen(&$1) || $3 > IP4_MAX_PREFIX_LENGTH)
206 513ad0a8 Pavel Tvrdík
    cf_error("Invalid max prefix length %d", $3);
207
};
208
209
net_roa6_: net_ip6_ MAX NUM AS NUM
210
{
211 a4caa1c0 Pavel Tvrdík
  $$ = cfg_alloc(sizeof(net_addr_roa6));
212 286e2011 Ondrej Zajicek (work)
  net_fill_roa6($$, net6_prefix(&$1), net6_pxlen(&$1), $3, $5);
213 8860e991 Ondrej Zajicek (work)
  if ($3 < (int) net6_pxlen(&$1) || $3 > IP6_MAX_PREFIX_LENGTH)
214 513ad0a8 Pavel Tvrdík
    cf_error("Invalid max prefix length %d", $3);
215
};
216
217 04632fd7 Ondrej Zajicek (work)
net_ip_: net_ip4_ | net_ip6_ ;
218 513ad0a8 Pavel Tvrdík
net_roa_: net_roa4_ | net_roa6_ ;
219
220 a4caa1c0 Pavel Tvrdík
net_:
221
   net_ip_ { $$ = cfg_alloc($1.length); net_copy($$, &($1)); }
222
 | net_roa_
223 77234bbb Ondrej Zajicek (work)
 | net_flow_
224 a4caa1c0 Pavel Tvrdík
 ;
225 d44e686e Ondrej Zajicek (work)
226
227 04632fd7 Ondrej Zajicek (work)
/* Networks - regular */
228
229
net_ip6:
230
   net_ip6_
231
 | SYM {
232
     if (($1->class != (SYM_CONSTANT | T_NET)) || (SYM_VAL($1).net->type != NET_IP6))
233
       cf_error("IPv6 network expected");
234
     $$ = * SYM_VAL($1).net;
235 d7661fbe Jan Moskyto Matejka
   }
236 04632fd7 Ondrej Zajicek (work)
 ;
237
238
net_ip:
239
   net_ip_
240
 | SYM {
241
     if (($1->class != (SYM_CONSTANT | T_NET)) || !net_is_ip(SYM_VAL($1).net))
242
       cf_error("IP network expected");
243
     $$ = * SYM_VAL($1).net;
244 758458be Martin Mares
   }
245
 ;
246
247 04632fd7 Ondrej Zajicek (work)
net_any:
248
   net_
249
 | SYM {
250
     if ($1->class != (SYM_CONSTANT | T_NET))
251
       cf_error("Network expected");
252
     $$ = (net_addr *) SYM_VAL($1).net; /* Avoid const warning */
253
   }
254
 ;
255
256
net_or_ipa:
257
   net_ip4_
258
 | net_ip6_
259
 | IP4 { net_fill_ip4(&($$), $1, IP4_MAX_PREFIX_LENGTH); }
260
 | IP6 { net_fill_ip6(&($$), $1, IP6_MAX_PREFIX_LENGTH); }
261
 | SYM {
262
     if ($1->class == (SYM_CONSTANT | T_IP))
263
       net_fill_ip_host(&($$), SYM_VAL($1).ip);
264
     else if (($1->class == (SYM_CONSTANT | T_NET)) && net_is_ip(SYM_VAL($1).net))
265
       $$ = * SYM_VAL($1).net;
266
     else
267
       cf_error("IP address or network expected");
268 89d2355d Martin Mares
   }
269
 ;
270
271 f2010f9c Jan Moskyto Matejka
label_stack_start: NUM
272
{
273 d14f8c3c Jan Moskyto Matejka
  $$ = cfg_allocz(sizeof(u32) * (MPLS_MAX_LABEL_STACK+1));
274 f2010f9c Jan Moskyto Matejka
  $$[0] = 1;
275
  $$[1] = $1;
276
};
277
278
label_stack:
279
    label_stack_start
280
  | label_stack '/' NUM {
281 d14f8c3c Jan Moskyto Matejka
    if ($1[0] >= MPLS_MAX_LABEL_STACK)
282 f2010f9c Jan Moskyto Matejka
      cf_error("Too many labels in stack.");
283
    $1[++$1[0]] = $3;
284
    $$ = $1;
285
  }
286
;
287 04632fd7 Ondrej Zajicek (work)
288 16c07e3d Martin Mares
datetime:
289 aee539f2 Martin Mares
   TEXT {
290 0d3effcf Ondrej Filip
     $$ = tm_parse_datetime($1);
291 aee539f2 Martin Mares
     if (!$$)
292 0d3effcf Ondrej Filip
       cf_error("Invalid date and time");
293 aee539f2 Martin Mares
   }
294 9d79fec8 Pavel Machek
 ;
295
296 9eceab33 Ondrej Zajicek
text:
297
   TEXT
298
 | SYM {
299
     if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected");
300
     $$ = SYM_VAL($1).s;
301
   }
302
 ;
303
304 fe9f1a6d Ondrej Zajicek (work)
opttext:
305
    TEXT
306
 | /* empty */ { $$ = NULL; }
307
 ;
308
309
310 f142750d Martin Mares
CF_CODE
311
312
CF_END