Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (3.71 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
#include "lib/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
  struct symbol *s;
43
  char *t;
44 0e02abfd Martin Mares
  struct rtable_config *r;
45 e0f2e42f Martin Mares
  struct f_inst *x;
46
  struct filter *f;
47 38506f71 Pavel Machek
  struct f_tree *e;
48 b1a597e0 Ondrej Zajicek
  struct f_trie *trie;
49 38506f71 Pavel Machek
  struct f_val v;
50 dcab7890 Pavel Machek
  struct f_path_mask *h;
51 9d79fec8 Pavel Machek
  struct password_item *p;
52 730f2e2c Martin Mares
  struct rt_show_data *ra;
53 af582c48 Ondrej Zajicek
  struct roa_show_data *ro;
54 0f808c06 Ondrej Zajicek
  struct sym_show_data *sd;
55 20ab192b Ondrej Zajicek
  struct lsadb_show_data *ld;
56 69a8259c Ondrej Zajicek
  struct iface *iface;
57 af582c48 Ondrej Zajicek
  struct roa_table *rot;
58 4ab5331c Martin Mares
  void *g;
59 aee539f2 Martin Mares
  bird_clock_t time;
60 758458be Martin Mares
  struct prefix px;
61 e304fd4b Ondrej Zajicek
  struct proto_spec ps;
62 c37e7851 Ondrej Zajicek
  struct timeformat *tf;
63 f142750d Martin Mares
}
64
65 b8cc390e Ondrej Zajicek
%token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT
66 5f4aee76 Pavel Machek
%token GEQ LEQ NEQ AND OR
67 cf186034 Ondrej Zajicek
%token PO PC
68 944f008a Martin Mares
%token <i> NUM ENUM
69 dce26783 Martin Mares
%token <i32> RTRID
70 f142750d Martin Mares
%token <a> IPA
71
%token <s> SYM
72
%token <t> TEXT
73 69a8259c Ondrej Zajicek
%type <iface> ipa_scope
74 f142750d Martin Mares
75 a1beb8f3 Ondrej Zajicek
%type <i> expr bool pxlen
76 6a8d3f1c Ondrej Zajicek
%type <i32> expr_us
77 aee539f2 Martin Mares
%type <time> datetime
78 e3f2d5fc Martin Mares
%type <a> ipa
79 d3abfbc6 Martin Mares
%type <px> prefix prefix_or_ipa
80 9eceab33 Ondrej Zajicek
%type <t> text
81 874b8685 Ondrej Zajicek
%type <t> text_or_none
82 0b62c3a7 Martin Mares
83 60de3356 Pavel Machek
%nonassoc PREFIX_DUMMY
84 1960d203 Ondrej Filip
%left AND OR
85 768d5e10 Pavel Tvrdik
%nonassoc '=' '<' '>' '~' GEQ LEQ NEQ NMA PO PC
86 1960d203 Ondrej Filip
%left '+' '-'
87 0b62c3a7 Martin Mares
%left '*' '/' '%'
88 23b1539b Pavel Machek
%left '!'
89 112d71a7 Ondrej Zajicek
%nonassoc '.'
90 0b62c3a7 Martin Mares
91 dcde7ae5 Ondrej Zajicek
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT)
92 0b62c3a7 Martin Mares
93 f142750d Martin Mares
CF_GRAMMAR
94
95 0b62c3a7 Martin Mares
/* Basic config file structure */
96
97 bc2fb680 Martin Mares
config: conf_entries END { return 0; }
98 ffb59d24 Martin Mares
 | CLI_MARKER cli_cmd { return 0; }
99 f142750d Martin Mares
 ;
100
101
conf_entries:
102
   /* EMPTY */
103 7f400d1c Martin Mares
 | conf_entries conf
104 f142750d Martin Mares
 ;
105
106 7f400d1c Martin Mares
CF_ADDTO(conf, ';')
107 f142750d Martin Mares
108 1103b32e Ondrej Zajicek
109 72380a34 Pavel Machek
/* Constant expressions */
110 0b62c3a7 Martin Mares
111 1103b32e Ondrej Zajicek
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 c9b66706 Martin Mares
expr:
122 0b62c3a7 Martin Mares
   NUM
123 cc590a11 Martin Mares
 | '(' term ')' { $$ = f_eval_int($2); }
124 1103b32e Ondrej Zajicek
 | SYM {
125
     if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected");
126
     $$ = SYM_VAL($1).i; }
127 0b62c3a7 Martin Mares
 ;
128
129 6a8d3f1c Ondrej Zajicek
130
expr_us:
131 0e175f9f Ondrej Zajicek
   expr S  { $$ = (u32) $1 * 1000000; }
132
 | expr MS { $$ = (u32) $1 * 1000; }
133
 | expr US { $$ = (u32) $1 * 1; }
134 6a8d3f1c Ondrej Zajicek
 ;
135
136 b8cc390e Ondrej Zajicek
/* expr_u16: expr { check_u16($1); $$ = $1; }; */
137
138 166b9c49 Martin Mares
/* Switches */
139
140
bool:
141 c8cafc8e Ondrej Zajicek (work)
   expr { $$ = !!$1; }
142 166b9c49 Martin Mares
 | ON { $$ = 1; }
143
 | YES { $$ = 1; }
144
 | OFF { $$ = 0; }
145
 | NO { $$ = 0; }
146
 | /* Silence means agreement */ { $$ = 1; }
147
 ;
148
149 e3f2d5fc Martin Mares
/* Addresses, prefixes and netmasks */
150
151
ipa:
152
   IPA
153
 | SYM {
154 1103b32e Ondrej Zajicek
     if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
155
     $$ = SYM_VAL($1).px.ip;
156 e3f2d5fc Martin Mares
   }
157
 ;
158 89d2355d Martin Mares
159 69a8259c Ondrej Zajicek
ipa_scope:
160
   /* empty */ { $$ = NULL; }
161
 | '%' SYM { $$ = if_get_by_name($2->name); }
162
 ;
163
164 758458be Martin Mares
prefix:
165 e3f2d5fc Martin Mares
   ipa pxlen {
166 758458be Martin Mares
     if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
167
     $$.addr = $1; $$.len = $2;
168
   }
169
 ;
170
171 d3abfbc6 Martin Mares
prefix_or_ipa:
172
   prefix
173 e3f2d5fc Martin Mares
 | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
174 d3abfbc6 Martin Mares
 ;
175
176 89d2355d Martin Mares
pxlen:
177 e3f2d5fc Martin Mares
   '/' expr {
178 6db8c5a6 Martin Mares
     if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
179 89d2355d Martin Mares
     $$ = $2;
180
   }
181 e3f2d5fc Martin Mares
 | ':' ipa {
182 88a183c6 Ondrej Zajicek
     $$ = ipa_masklen($2);
183 89d2355d Martin Mares
     if ($$ < 0) cf_error("Invalid netmask %I", $2);
184
   }
185
 ;
186
187 16c07e3d Martin Mares
datetime:
188 aee539f2 Martin Mares
   TEXT {
189 0d3effcf Ondrej Filip
     $$ = tm_parse_datetime($1);
190 aee539f2 Martin Mares
     if (!$$)
191 0d3effcf Ondrej Filip
       cf_error("Invalid date and time");
192 aee539f2 Martin Mares
   }
193 9d79fec8 Pavel Machek
 ;
194
195 9eceab33 Ondrej Zajicek
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 874b8685 Ondrej Zajicek
text_or_none:
204
   TEXT { $$ = $1; }
205
 |      { $$ = NULL; }
206
 ;
207
208 f142750d Martin Mares
CF_CODE
209
210
CF_END