Statistics
| Branch: | Revision:

iof-bird / bird-2.0.1 / conf / confbase.Y @ 6b3f1a54

History | View | Annotate | Download (6.71 KB)

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(uint val)
31
{
32
  if (val > 0xFFFF)
33
    cf_error("Value %u out of range (0-65535)", val);
34
}
35

    
36
CF_DECLS
37

    
38
%union {
39
  uint i;
40
  u32 i32;
41
  u64 i64;
42
  ip_addr a;
43
  ip4_addr ip4;
44
  ip6_addr ip6;
45
  net_addr net;
46
  net_addr *net_ptr;
47
  struct symbol *s;
48
  char *t;
49
  struct rtable_config *r;
50
  struct channel_config *cc;
51
  struct f_inst *x;
52
  struct filter *f;
53
  struct f_tree *e;
54
  struct f_trie *trie;
55
  struct f_val v;
56
  struct f_path_mask *h;
57
  struct password_item *p;
58
  struct rt_show_data *ra;
59
  struct sym_show_data *sd;
60
  struct lsadb_show_data *ld;
61
  struct iface *iface;
62
  void *g;
63
  btime time;
64
  struct f_prefix px;
65
  struct proto_spec ps;
66
  struct channel_limit cl;
67
  struct timeformat *tf;
68
  mpls_label_stack *mls;
69
}
70

    
71
%token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT
72
%token GEQ LEQ NEQ AND OR
73
%token PO PC
74
%token <i> NUM ENUM
75
%token <ip4> IP4
76
%token <ip6> IP6
77
%token <i64> VPN_RD
78
%token <s> SYM
79
%token <t> TEXT
80
%type <iface> ipa_scope
81

    
82
%type <i> expr bool pxlen4
83
%type <time> expr_us time
84
%type <a> ipa
85
%type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa
86
%type <net_ptr> net_ net_any net_vpn4_ net_vpn6_ net_vpn_ net_roa4_ net_roa6_ net_roa_ net_mpls_
87
%type <mls> label_stack_start label_stack
88

    
89
%type <t> text opttext
90

    
91
%nonassoc PREFIX_DUMMY
92
%left AND OR
93
%nonassoc '=' '<' '>' '~' GEQ LEQ NEQ NMA PO PC
94
%left '+' '-'
95
%left '*' '/' '%'
96
%left '!'
97
%nonassoc '.'
98

    
99
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN, MPLS)
100

    
101
CF_GRAMMAR
102

    
103
/* Basic config file structure */
104

    
105
config: conf_entries END { return 0; }
106
 | CLI_MARKER cli_cmd { return 0; }
107
 ;
108

    
109
conf_entries:
110
   /* EMPTY */
111
 | conf_entries conf
112
 ;
113

    
114
CF_ADDTO(conf, ';')
115

    
116

    
117
/* Constant expressions */
118

    
119
CF_ADDTO(conf, definition)
120
definition:
121
   DEFINE SYM '=' term ';' {
122
     struct f_val *val = cfg_alloc(sizeof(struct f_val));
123
     *val = f_eval($4, cfg_mem);
124
     if (val->type == T_RETURN) cf_error("Runtime error");
125
     cf_define_symbol($2, SYM_CONSTANT | val->type, val);
126
   }
127
 ;
128

    
129
expr:
130
   NUM
131
 | '(' term ')' { $$ = f_eval_int($2); }
132
 | SYM {
133
     if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected");
134
     $$ = SYM_VAL($1).i; }
135
 ;
136

    
137

    
138
expr_us:
139
   expr S  { $$ = $1 S_; }
140
 | expr MS { $$ = $1 MS_; }
141
 | expr US { $$ = $1 US_; }
142
 ;
143

    
144
/* Switches */
145

    
146
bool:
147
   expr { $$ = !!$1; }
148
 | ON { $$ = 1; }
149
 | YES { $$ = 1; }
150
 | OFF { $$ = 0; }
151
 | NO { $$ = 0; }
152
 | /* Silence means agreement */ { $$ = 1; }
153
 ;
154

    
155

    
156
/* Addresses */
157

    
158
ipa:
159
   IP4 { $$ = ipa_from_ip4($1); }
160
 | IP6 { $$ = ipa_from_ip6($1); }
161
 | SYM {
162
     if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
163
     $$ = SYM_VAL($1).ip;
164
   }
165
 ;
166

    
167
ipa_scope:
168
   /* empty */ { $$ = NULL; }
169
 | '%' SYM { $$ = if_get_by_name($2->name); }
170
 ;
171

    
172

    
173
/* Networks - internal */
174

    
175
pxlen4:
176
   '/' NUM {
177
     if ($2 > IP4_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %u", $2);
178
     $$ = $2;
179
   }
180
 | ':' IP4 {
181
     $$ = ip4_masklen($2);
182
     if ($$ == 255) cf_error("Invalid netmask %I4", $2);
183
   }
184
 ;
185

    
186
net_ip4_: IP4 pxlen4
187
{
188
  net_fill_ip4(&($$), $1, $2);
189

    
190
  net_addr_ip4 *n = (void *) &($$);
191
  if (!net_validate_ip4(n))
192
    cf_error("Invalid IPv4 prefix %I4/%d, maybe you wanted %I4/%d",
193
	     n->prefix, n->pxlen, ip4_and(n->prefix, ip4_mkmask(n->pxlen)), n->pxlen);
194
};
195

    
196
net_ip6_: IP6 '/' NUM
197
{
198
  if ($3 > IP6_MAX_PREFIX_LENGTH)
199
    cf_error("Invalid prefix length %u", $3);
200

    
201
  net_fill_ip6(&($$), $1, $3);
202

    
203
  net_addr_ip6 *n = (void *) &($$);
204
  if (!net_validate_ip6(n))
205
    cf_error("Invalid IPv6 prefix %I6/%d, maybe you wanted %I6/%d",
206
	     n->prefix, n->pxlen, ip6_and(n->prefix, ip6_mkmask(n->pxlen)), n->pxlen);
207
};
208

    
209
net_vpn4_: VPN_RD net_ip4_
210
{
211
  $$ = cfg_alloc(sizeof(net_addr_vpn4));
212
  net_fill_vpn4($$, net4_prefix(&$2), net4_pxlen(&$2), $1);
213
}
214

    
215
net_vpn6_: VPN_RD net_ip6_
216
{
217
  $$ = cfg_alloc(sizeof(net_addr_vpn6));
218
  net_fill_vpn6($$, net6_prefix(&$2), net6_pxlen(&$2), $1);
219
}
220

    
221
net_roa4_: net_ip4_ MAX NUM AS NUM
222
{
223
  $$ = cfg_alloc(sizeof(net_addr_roa4));
224
  net_fill_roa4($$, net4_prefix(&$1), net4_pxlen(&$1), $3, $5);
225
  if ($3 < net4_pxlen(&$1) || $3 > IP4_MAX_PREFIX_LENGTH)
226
    cf_error("Invalid max prefix length %u", $3);
227
};
228

    
229
net_roa6_: net_ip6_ MAX NUM AS NUM
230
{
231
  $$ = cfg_alloc(sizeof(net_addr_roa6));
232
  net_fill_roa6($$, net6_prefix(&$1), net6_pxlen(&$1), $3, $5);
233
  if ($3 < net6_pxlen(&$1) || $3 > IP6_MAX_PREFIX_LENGTH)
234
    cf_error("Invalid max prefix length %u", $3);
235
};
236

    
237
net_mpls_: MPLS NUM
238
{
239
  $$ = cfg_alloc(sizeof(net_addr_roa6));
240
  net_fill_mpls($$, $2);
241
}
242

    
243
net_ip_: net_ip4_ | net_ip6_ ;
244
net_vpn_: net_vpn4_ | net_vpn6_ ;
245
net_roa_: net_roa4_ | net_roa6_ ;
246

    
247
net_:
248
   net_ip_ { $$ = cfg_alloc($1.length); net_copy($$, &($1)); }
249
 | net_vpn_
250
 | net_roa_
251
 | net_flow_
252
 | net_mpls_
253
 ;
254

    
255

    
256
/* Networks - regular */
257

    
258
net_ip6:
259
   net_ip6_
260
 | SYM {
261
     if (($1->class != (SYM_CONSTANT | T_NET)) || (SYM_VAL($1).net->type != NET_IP6))
262
       cf_error("IPv6 network expected");
263
     $$ = * SYM_VAL($1).net;
264
   }
265
 ;
266

    
267
net_ip:
268
   net_ip_
269
 | SYM {
270
     if (($1->class != (SYM_CONSTANT | T_NET)) || !net_is_ip(SYM_VAL($1).net))
271
       cf_error("IP network expected");
272
     $$ = * SYM_VAL($1).net;
273
   }
274
 ;
275

    
276
net_any:
277
   net_
278
 | SYM {
279
     if ($1->class != (SYM_CONSTANT | T_NET))
280
       cf_error("Network expected");
281
     $$ = (net_addr *) SYM_VAL($1).net; /* Avoid const warning */
282
   }
283
 ;
284

    
285
net_or_ipa:
286
   net_ip4_
287
 | net_ip6_
288
 | IP4 { net_fill_ip4(&($$), $1, IP4_MAX_PREFIX_LENGTH); }
289
 | IP6 { net_fill_ip6(&($$), $1, IP6_MAX_PREFIX_LENGTH); }
290
 | SYM {
291
     if ($1->class == (SYM_CONSTANT | T_IP))
292
       net_fill_ip_host(&($$), SYM_VAL($1).ip);
293
     else if (($1->class == (SYM_CONSTANT | T_NET)) && net_is_ip(SYM_VAL($1).net))
294
       $$ = * SYM_VAL($1).net;
295
     else
296
       cf_error("IP address or network expected");
297
   }
298
 ;
299

    
300
label_stack_start: NUM
301
{
302
  $$ = cfg_allocz(sizeof(mpls_label_stack));
303
  $$->len = 1;
304
  $$->stack[0] = $1;
305
};
306

    
307
label_stack:
308
    label_stack_start
309
  | label_stack '/' NUM {
310
    if ($1->len >= MPLS_MAX_LABEL_STACK)
311
      cf_error("Too many labels in stack");
312
    $1->stack[$1->len++] = $3;
313
    $$ = $1;
314
  }
315
;
316

    
317
time:
318
   TEXT {
319
     $$ = tm_parse_time($1);
320
     if (!$$)
321
       cf_error("Invalid date/time");
322
   }
323
 ;
324

    
325
text:
326
   TEXT
327
 | SYM {
328
     if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected");
329
     $$ = SYM_VAL($1).s;
330
   }
331
 ;
332

    
333
opttext:
334
    TEXT
335
 | /* empty */ { $$ = NULL; }
336
 ;
337

    
338

    
339
CF_CODE
340

    
341
CF_END