Statistics
| Branch: | Revision:

iof-bird-daemon / nest / config.Y @ 258d0ad4

History | View | Annotate | Download (9.98 KB)

1 da877822 Martin Mares
/*
2
 *	BIRD -- Core Configuration
3
 *
4 4b87e256 Martin Mares
 *	(c) 1998--2000 Martin Mares <mj@ucw.cz>
5 bc956fca Ondrej Filip
 *      (c) 2004       Ondrej Filip <feela@network.cz>
6 da877822 Martin Mares
 *
7
 *	Can be freely distributed and used under the terms of the GNU GPL.
8
 */
9
10
CF_HDR
11
12 50d8424a Martin Mares
#include "nest/rt-dev.h"
13 1a2ded45 Pavel Machek
#include "nest/password.h"
14 4b87e256 Martin Mares
#include "nest/cmds.h"
15 5236fb03 Ondrej Filip
#include "lib/lists.h"
16 50d8424a Martin Mares
17 2edb31b0 Martin Mares
CF_DEFINES
18
19
static struct proto_config *this_proto;
20
static struct iface_patt *this_ipatt;
21 5236fb03 Ondrej Filip
static list *this_p_list;
22
static struct password_item *this_p_item;
23 b21f68b4 Ondrej Zajicek
static int password_id;
24
25
static list *
26
get_passwords(void)
27
{
28
  list *rv = this_p_list;
29
  this_p_list = NULL;
30
  return rv;
31
}
32
33 2edb31b0 Martin Mares
34 da877822 Martin Mares
CF_DECLS
35
36 7e5f5ffd Martin Mares
CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
37 96d8e3bf Martin Mares
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
38 6a9f28b0 Martin Mares
CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
39 5236fb03 Ondrej Filip
CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREIMPORT, GENERATE)
40 da877822 Martin Mares
41 7d509304 Martin Mares
CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
42 98ac6176 Ondrej Filip
	RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE)
43 26c09e1d Pavel Machek
CF_ENUM(T_ENUM_SCOPE, SCOPE_, HOST, LINK, SITE, ORGANIZATION, UNIVERSE)
44
CF_ENUM(T_ENUM_RTC, RTC_, UNICAST, BROADCAST, MULTICAST, ANYCAST)
45
CF_ENUM(T_ENUM_RTD, RTD_, ROUTER, DEVICE, BLACKHOLE, UNREACHABLE, PROHIBIT)
46 7d509304 Martin Mares
47 dce26783 Martin Mares
%type <i32> idval
48 5056c559 Martin Mares
%type <f> imexport
49 0e02abfd Martin Mares
%type <r> rtable
50 ae97b946 Martin Mares
%type <s> optsym
51 730f2e2c Martin Mares
%type <ra> r_args
52 ce1da96e Martin Mares
%type <i> echo_mask echo_size debug_mask debug_list debug_flag import_or_proto
53 f14a4bec Martin Mares
%type <t> proto_patt
54 da877822 Martin Mares
55
CF_GRAMMAR
56
57 c74c0e3c Martin Mares
/* Setting of router ID */
58
59 da877822 Martin Mares
CF_ADDTO(conf, rtrid)
60 0e02abfd Martin Mares
61 7f400d1c Martin Mares
rtrid: ROUTER ID idval ';' {
62 31b3e1bb Martin Mares
   new_config->router_id = $3;
63 c74c0e3c Martin Mares
   }
64 da877822 Martin Mares
 ;
65
66
idval:
67 dce26783 Martin Mares
   NUM { $$ = $1; }
68
 | RTRID
69
 | IPA {
70
#ifndef IPV6
71
     $$ = ipa_to_u32($1);
72
#else
73 e79671a7 Martin Mares
     cf_error("Router IDs must be entered as hexadecimal numbers or IPv4 addresses in IPv6 version");
74 dce26783 Martin Mares
#endif
75
   }
76 da877822 Martin Mares
 ;
77
78 0e02abfd Martin Mares
/* Creation of routing tables */
79
80
CF_ADDTO(conf, newtab)
81
82
newtab: TABLE SYM {
83 b9626ec6 Martin Mares
   rt_new_table($2);
84 0e02abfd Martin Mares
   }
85
 ;
86
87 c74c0e3c Martin Mares
/* Definition of protocols */
88
89
CF_ADDTO(conf, proto)
90
91
proto_start: PROTOCOL
92 de10a974 Martin Mares
 ;
93 c74c0e3c Martin Mares
94
proto_name:
95
   /* EMPTY */ {
96 d272fe22 Martin Mares
     struct symbol *s = cf_default_name(this_proto->protocol->template, &this_proto->protocol->name_counter);
97 c74c0e3c Martin Mares
     s->class = SYM_PROTO;
98
     s->def = this_proto;
99
     this_proto->name = s->name;
100
     }
101
 | SYM {
102 0e02abfd Martin Mares
     cf_define_symbol($1, SYM_PROTO, this_proto);
103 c74c0e3c Martin Mares
     this_proto->name = $1->name;
104
   }
105
 ;
106
107
proto_item:
108
   /* EMPTY */
109 0b62c3a7 Martin Mares
 | PREFERENCE expr {
110 c74c0e3c Martin Mares
     if ($2 < 0 || $2 > 255) cf_error("Invalid preference");
111
     this_proto->preference = $2;
112
   }
113 ca77641d Pavel Machek
 | DISABLED bool { this_proto->disabled = $2; }
114 96d8e3bf Martin Mares
 | DEBUG debug_mask { this_proto->debug = $2; }
115 5056c559 Martin Mares
 | IMPORT imexport { this_proto->in_filter = $2; }
116
 | EXPORT imexport { this_proto->out_filter = $2; }
117 0e02abfd Martin Mares
 | TABLE rtable { this_proto->table = $2; }
118 5056c559 Martin Mares
 ;
119
120
imexport:
121
   FILTER filter { $$ = $2; }
122 f8809249 Martin Mares
 | where_filter
123 5056c559 Martin Mares
 | ALL { $$ = FILTER_ACCEPT; }
124
 | NONE { $$ = FILTER_REJECT; }
125 c74c0e3c Martin Mares
 ;
126
127 0e02abfd Martin Mares
rtable:
128
   SYM {
129
     if ($1->class != SYM_TABLE) cf_error("Table name expected");
130
     $$ = $1->def;
131
   }
132
 ;
133
134 f30b86f9 Martin Mares
CF_ADDTO(conf, debug_default)
135
136
debug_default:
137
   DEBUG PROTOCOLS debug_mask { new_config->proto_default_debug = $3; }
138 4761efdb Martin Mares
 | DEBUG COMMANDS expr { new_config->cli_debug = $3; }
139 f30b86f9 Martin Mares
 ;
140
141 8edf2361 Martin Mares
/* Interface patterns */
142
143
iface_patt:
144
   TEXT { this_ipatt->pattern = $1; this_ipatt->prefix = IPA_NONE; this_ipatt->pxlen = 0; }
145 758458be Martin Mares
 | prefix { this_ipatt->pattern = NULL; this_ipatt->prefix = $1.addr; this_ipatt->pxlen = $1.len; }
146
 | TEXT prefix { this_ipatt->pattern = $1; this_ipatt->prefix = $2.addr; this_ipatt->pxlen = $2.len; }
147 8edf2361 Martin Mares
 ;
148
149 7e5f5ffd Martin Mares
/* Direct device route protocol */
150 50d8424a Martin Mares
151
CF_ADDTO(proto, dev_proto '}')
152
153 7e5f5ffd Martin Mares
dev_proto_start: proto_start DIRECT {
154
     struct rt_dev_config *p = proto_config_new(&proto_device, sizeof(struct rt_dev_config));
155
     this_proto = &p->c;
156
     p->c.preference = DEF_PREF_DIRECT;
157
     init_list(&p->iface_list);
158 50d8424a Martin Mares
   }
159
 ;
160
161
dev_proto:
162 7e5f5ffd Martin Mares
   dev_proto_start proto_name '{'
163 50d8424a Martin Mares
 | dev_proto proto_item ';'
164
 | dev_proto dev_iface_list ';'
165
 ;
166
167 8edf2361 Martin Mares
dev_iface_entry_init:
168
   /* EMPTY */ {
169
     struct rt_dev_config *p = (void *) this_proto;
170
     struct iface_patt *k = cfg_allocz(sizeof(struct iface_patt));
171
     add_tail(&p->iface_list, &k->n);
172
     this_ipatt = k;
173 50d8424a Martin Mares
   }
174
 ;
175
176 8edf2361 Martin Mares
dev_iface_entry:
177
   dev_iface_entry_init iface_patt
178
 ;
179
180
dev_iface_list:
181
   INTERFACE dev_iface_entry
182
 | dev_iface_list ',' dev_iface_entry
183
 ;
184
185 96d8e3bf Martin Mares
/* Debug flags */
186
187
debug_mask:
188
   ALL { $$ = ~0; }
189
 | OFF { $$ = 0; }
190
 | '{' debug_list '}' { $$ = $2; }
191
 ;
192
193
debug_list:
194
   debug_flag
195
 | debug_list ',' debug_flag { $$ = $1 | $3; }
196
 ;
197
198
debug_flag:
199
   STATES	{ $$ = D_STATES; }
200
 | ROUTES	{ $$ = D_ROUTES; }
201
 | FILTERS	{ $$ = D_FILTERS; }
202 6a9f28b0 Martin Mares
 | INTERFACES	{ $$ = D_IFACES; }
203 96d8e3bf Martin Mares
 | EVENTS	{ $$ = D_EVENTS; }
204
 | PACKETS	{ $$ = D_PACKETS; }
205
 ;
206
207 8edf2361 Martin Mares
/* Password lists */
208
209 b21f68b4 Ondrej Zajicek
password_list:
210
   PASSWORDS '{' password_items '}'
211
 | password_item
212
;
213
214 5236fb03 Ondrej Filip
password_items: 
215
    /* empty */
216
  | password_item ';' password_items
217
;
218
219
password_item:
220
    password_item_begin '{' password_item_params '}'
221
  | password_item_begin
222
;
223
224
password_item_begin:
225 1a2ded45 Pavel Machek
   PASSWORD TEXT {
226 b21f68b4 Ondrej Zajicek
     if (!this_p_list) {
227
     	this_p_list = cfg_alloc(sizeof(list));
228
     	init_list(this_p_list);
229
        password_id = 1;
230
     }
231 5236fb03 Ondrej Filip
     this_p_item = cfg_alloc(sizeof (struct password_item));
232
     this_p_item->password = $2;
233
     this_p_item->genfrom = 0;
234
     this_p_item->gento = TIME_INFINITY;
235
     this_p_item->accfrom = 0;
236
     this_p_item->accto = TIME_INFINITY;
237 b21f68b4 Ondrej Zajicek
     this_p_item->id = password_id++;
238 5236fb03 Ondrej Filip
     add_tail(this_p_list, &this_p_item->n);
239 1a2ded45 Pavel Machek
   }
240 5236fb03 Ondrej Filip
;
241 1a2ded45 Pavel Machek
242 5236fb03 Ondrej Filip
password_item_params:
243 1a2ded45 Pavel Machek
   /* empty */ { } 
244 5236fb03 Ondrej Filip
 | GENERATE FROM datetime ';' password_item_params { this_p_item->genfrom = $3; }
245
 | GENERATE TO datetime ';' password_item_params { this_p_item->gento = $3; }
246
 | ACCEPT FROM datetime ';' password_item_params { this_p_item->accfrom = $3; }
247
 | ACCEPT TO datetime ';' password_item_params { this_p_item->accto = $3; }
248 bc956fca Ondrej Filip
 | ID expr ';' password_item_params { this_p_item->id = $2; if ($2 <= 0) cf_error("Password ID has to be greated than zero."); }
249 1a2ded45 Pavel Machek
 ;
250
251
252 bc2fb680 Martin Mares
/* Core commands */
253 fae0396e Martin Mares
CF_CLI_HELP(SHOW, ..., [[Show status information]])
254 ae97b946 Martin Mares
255 4b87e256 Martin Mares
CF_CLI(SHOW STATUS,,, [[Show router status]])
256 de10a974 Martin Mares
{ cmd_show_status(); } ;
257 ae97b946 Martin Mares
258
CF_CLI(SHOW PROTOCOLS, optsym, [<name>], [[Show routing protocols]])
259 0d3e6bce Martin Mares
{ proto_show($3, 0); } ;
260
261 28e01f85 Martin Mares
CF_CLI(SHOW PROTOCOLS ALL, optsym, [<name>], [[Show routing protocol details]])
262 0d3e6bce Martin Mares
{ proto_show($4, 1); } ;
263 ae97b946 Martin Mares
264 730f2e2c Martin Mares
optsym:
265
   SYM
266
 | /* empty */ { $$ = NULL; }
267
 ;
268
269 ae97b946 Martin Mares
CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
270
{ if_show(); } ;
271
272
CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
273
{ if_show_summary(); } ;
274
275 49569a8b Martin Mares
CF_CLI(SHOW ROUTE, r_args, [[[<prefix>|for <prefix>|for <ip>] [table <t>] [filter <f>|where <cond>] [all] [primary] [(import|protocol) <p>] [stats|count]]], [[Show routing table]])
276 730f2e2c Martin Mares
{ rt_show($3); } ;
277
278
r_args:
279
   /* empty */ {
280
     $$ = cfg_allocz(sizeof(struct rt_show_data));
281
     $$->pxlen = 256;
282
     $$->filter = FILTER_ACCEPT;
283
     $$->table = config->master_rtc->table;
284
   }
285 758458be Martin Mares
 | r_args prefix {
286 730f2e2c Martin Mares
     $$ = $1;
287
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
288 758458be Martin Mares
     $$->prefix = $2.addr;
289
     $$->pxlen = $2.len;
290 730f2e2c Martin Mares
   }
291 9449c91a Martin Mares
 | r_args FOR prefix_or_ipa {
292
     $$ = $1;
293
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
294
     $$->prefix = $3.addr;
295
     $$->pxlen = $3.len;
296
     $$->show_for = 1;
297
   }
298 730f2e2c Martin Mares
 | r_args TABLE SYM {
299
     $$ = $1;
300
     if ($3->class != SYM_TABLE) cf_error("%s is not a table", $3->name);
301
     $$->table = ((struct rtable_config *)$3->def)->table;
302
   }
303
 | r_args FILTER filter {
304
     $$ = $1;
305 430da60f Martin Mares
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
306 730f2e2c Martin Mares
     $$->filter = $3;
307
   }
308 430da60f Martin Mares
 | r_args where_filter {
309
     $$ = $1;
310
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
311
     $$->filter = $2;
312
   }
313 730f2e2c Martin Mares
 | r_args ALL {
314
     $$ = $1;
315
     $$->verbose = 1;
316
   }
317 ce1da96e Martin Mares
 | r_args PRIMARY {
318
     $$ = $1;
319
     $$->primary_only = 1;
320
   }
321
 | r_args import_or_proto SYM {
322
     struct proto_config *c = (struct proto_config *) $3->def;
323
     $$ = $1;
324
     if ($$->import_mode) cf_error("Protocol specified twice");
325
     if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
326
     $$->import_mode = $2;
327
     $$->primary_only = 1;
328
     $$->import_protocol = c->proto;
329
     $$->running_on_config = c->proto->cf->global;
330
   }
331 23693958 Martin Mares
 | r_args STATS {
332
     $$ = $1;
333
     $$->stats = 1;
334
   }
335 33a368ad Martin Mares
 | r_args COUNT {
336
     $$ = $1;
337
     $$->stats = 2;
338
   }
339 ce1da96e Martin Mares
 ;
340
341
import_or_proto:
342 c90ac711 Ondrej Filip
   PREIMPORT { $$ = 1; }
343
 | IMPORT { $$ = 2; }
344 730f2e2c Martin Mares
 ;
345
346 4b87e256 Martin Mares
CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
347
{ cmd_show_symbols($3); } ;
348
349 96d8e3bf Martin Mares
CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
350
CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
351 34350a52 Martin Mares
{ rdump(&root_pool); cli_msg(0, ""); } ;
352 96d8e3bf Martin Mares
CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
353 34350a52 Martin Mares
{ sk_dump_all(); cli_msg(0, ""); } ;
354 96d8e3bf Martin Mares
CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
355 34350a52 Martin Mares
{ if_dump_all(); cli_msg(0, ""); } ;
356 96d8e3bf Martin Mares
CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
357 34350a52 Martin Mares
{ neigh_dump_all(); cli_msg(0, ""); } ;
358 96d8e3bf Martin Mares
CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
359 34350a52 Martin Mares
{ rta_dump_all(); cli_msg(0, ""); } ;
360 96d8e3bf Martin Mares
CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
361 34350a52 Martin Mares
{ rt_dump_all(); cli_msg(0, ""); } ;
362 96d8e3bf Martin Mares
CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
363 34350a52 Martin Mares
{ protos_dump_all(); cli_msg(0, ""); } ;
364
365
CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
366
  cli_set_log_echo(this_cli, $2, $3);
367
  cli_msg(0, "");
368
} ;
369
370
echo_mask:
371
   ALL { $$ = ~0; }
372
 | OFF { $$ = 0; }
373
 | NUM
374
 ;
375
376
echo_size:
377
   /* empty */ { $$ = 4096; }
378
 | NUM {
379
     if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
380
     $$ = $1;
381
   }
382
 ;
383 bc2fb680 Martin Mares
384 49569a8b Martin Mares
CF_CLI(DISABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Disable protocol]])
385 f14a4bec Martin Mares
{ proto_xxable($2, 0); } ;
386 49569a8b Martin Mares
CF_CLI(ENABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Enable protocol]])
387 f14a4bec Martin Mares
{ proto_xxable($2, 1); } ;
388 49569a8b Martin Mares
CF_CLI(RESTART, proto_patt, <protocol> | \"<pattern>\" | all, [[Restart protocol]])
389 f14a4bec Martin Mares
{ proto_xxable($2, 2); } ;
390
391 96d8e3bf Martin Mares
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging]])
392
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging]])
393
{ proto_debug($2, $3); }
394 de10a974 Martin Mares
 ;
395 96d8e3bf Martin Mares
396 f14a4bec Martin Mares
proto_patt:
397
   SYM { $$ = $1->name; }
398
 | ALL { $$ = "*"; }
399
 | TEXT
400
 ;
401
402 da877822 Martin Mares
CF_CODE
403
404
CF_END