Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (3.9 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(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
  ip4_addr ip4;
43
  ip6_addr ip6;
44
  struct symbol *s;
45
  char *t;
46
  struct rtable_config *r;
47
  struct f_inst *x;
48
  struct filter *f;
49
  struct f_tree *e;
50
  struct f_trie *trie;
51
  struct f_val v;
52
  struct f_path_mask *h;
53
  struct password_item *p;
54
  struct rt_show_data *ra;
55
  struct roa_show_data *ro;
56
  struct sym_show_data *sd;
57
  struct lsadb_show_data *ld;
58
  struct iface *iface;
59
  struct roa_table *rot;
60
  void *g;
61
  bird_clock_t time;
62
  struct prefix px;
63
  struct proto_spec ps;
64
  struct timeformat *tf;
65
}
66

    
67
%token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT
68
%token GEQ LEQ NEQ AND OR
69
%token PO PC
70
%token <i> NUM ENUM
71
%token <ip4> IP4
72
%token <ip6> IP6
73
%token <s> SYM
74
%token <t> TEXT
75
%type <iface> ipa_scope
76

    
77
%type <i> expr bool pxlen
78
%type <i32> expr_us
79
%type <time> datetime
80
%type <a> ipa ipa_raw
81
%type <px> prefix prefix_or_ipa
82
%type <t> text
83
%type <t> text_or_none
84
%type <t> opttext
85

    
86
%nonassoc PREFIX_DUMMY
87
%left AND OR
88
%nonassoc '=' '<' '>' '~' GEQ LEQ NEQ PO PC
89
%left '+' '-'
90
%left '*' '/' '%'
91
%left '!'
92
%nonassoc '.'
93

    
94
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT)
95

    
96
CF_GRAMMAR
97

    
98
/* Basic config file structure */
99

    
100
config: conf_entries END { return 0; }
101
 | CLI_MARKER cli_cmd { return 0; }
102
 ;
103

    
104
conf_entries:
105
   /* EMPTY */
106
 | conf_entries conf
107
 ;
108

    
109
CF_ADDTO(conf, ';')
110

    
111

    
112
/* Constant expressions */
113

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

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

    
132

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

    
139
/* expr_u16: expr { check_u16($1); $$ = $1; }; */
140

    
141
/* Switches */
142

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

    
152
/* Addresses, prefixes and netmasks */
153

    
154
ipa_raw:
155
   IP4 { $$ = ipa_from_ip4($1); }
156
 | IP6 { $$ = ipa_from_ip6($1); }
157
 ;
158

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

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

    
172
prefix:
173
   ipa pxlen {
174
     if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
175
     $$.addr = $1; $$.len = $2;
176
   }
177
 ;
178

    
179
prefix_or_ipa:
180
   prefix
181
 | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
182
 ;
183

    
184
pxlen:
185
   '/' expr {
186
     if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
187
     $$ = $2;
188
   }
189
 | ':' ipa {
190
     $$ = ipa_masklen($2);
191
     if ($$ < 0) cf_error("Invalid netmask %I", $2);
192
   }
193
 ;
194

    
195
datetime:
196
   TEXT {
197
     $$ = tm_parse_datetime($1);
198
     if (!$$)
199
       cf_error("Invalid date and time");
200
   }
201
 ;
202

    
203
text:
204
   TEXT
205
 | SYM {
206
     if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected");
207
     $$ = SYM_VAL($1).s;
208
   }
209
 ;
210

    
211
text_or_none:
212
   TEXT { $$ = $1; }
213
 |      { $$ = NULL; }
214
 ;
215

    
216
opttext:
217
    TEXT
218
 | /* empty */ { $$ = NULL; }
219
 ;
220

    
221

    
222
CF_CODE
223

    
224
CF_END