Statistics
| Branch: | Revision:

iof-bird-daemon / nest / config.Y @ e0a45fb4

History | View | Annotate | Download (13.1 KB)

1
/*
2
 *	BIRD -- Core Configuration
3
 *
4
 *	(c) 1998--2000 Martin Mares <mj@ucw.cz>
5
 *      (c) 2004       Ondrej Filip <feela@network.cz>
6
 *
7
 *	Can be freely distributed and used under the terms of the GNU GPL.
8
 */
9

    
10
CF_HDR
11

    
12
#include "nest/rt-dev.h"
13
#include "nest/password.h"
14
#include "nest/cmds.h"
15
#include "lib/lists.h"
16

    
17
CF_DEFINES
18

    
19
static struct proto_config *this_proto;
20
static struct iface_patt *this_ipatt;
21
static struct iface_patt_node *this_ipn;
22
static list *this_p_list;
23
static struct password_item *this_p_item;
24
static int password_id;
25

    
26
static inline void
27
reset_passwords(void)
28
{
29
 this_p_list = NULL;
30
}
31

    
32
static inline list *
33
get_passwords(void)
34
{
35
  list *rv = this_p_list;
36
  this_p_list = NULL;
37
  return rv;
38
}
39

    
40

    
41
CF_DECLS
42

    
43
CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
44
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
45
CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
46
CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREEXPORT, GENERATE)
47
CF_KEYWORDS(LISTEN, BGP, V6ONLY, ADDRESS, PORT, PASSWORDS, DESCRIPTION)
48
CF_KEYWORDS(RELOAD, IN, OUT, MRTDUMP, MESSAGES, RESTRICT)
49

    
50
CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
51
	RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE)
52
CF_ENUM(T_ENUM_SCOPE, SCOPE_, HOST, LINK, SITE, ORGANIZATION, UNIVERSE)
53
CF_ENUM(T_ENUM_RTC, RTC_, UNICAST, BROADCAST, MULTICAST, ANYCAST)
54
CF_ENUM(T_ENUM_RTD, RTD_, ROUTER, DEVICE, BLACKHOLE, UNREACHABLE, PROHIBIT)
55

    
56
%type <i32> idval
57
%type <f> imexport
58
%type <r> rtable
59
%type <s> optsym
60
%type <ra> r_args
61
%type <i> echo_mask echo_size debug_mask debug_list debug_flag mrtdump_mask mrtdump_list mrtdump_flag export_or_preexport
62
%type <ps> proto_patt proto_patt2
63

    
64
CF_GRAMMAR
65

    
66
/* Setting of router ID */
67

    
68
CF_ADDTO(conf, rtrid)
69

    
70
rtrid: ROUTER ID idval ';' {
71
   new_config->router_id = $3;
72
   }
73
 ;
74

    
75
idval:
76
   NUM { $$ = $1; }
77
 | RTRID
78
 | IPA {
79
#ifndef IPV6
80
     $$ = ipa_to_u32($1);
81
#else
82
     cf_error("Router IDs must be entered as hexadecimal numbers or IPv4 addresses in IPv6 version");
83
#endif
84
   }
85
 ;
86

    
87

    
88
CF_ADDTO(conf, listen)
89

    
90
listen: LISTEN BGP listen_opts ';' ;
91

    
92
listen_opts:
93
   /* Nothing */
94
 | listen_opts listen_opt
95
 ;
96

    
97
listen_opt: 
98
   ADDRESS ipa { new_config->listen_bgp_addr = $2; }
99
 | PORT expr { new_config->listen_bgp_port = $2; }
100
 | V6ONLY { new_config->listen_bgp_flags |= SKF_V6ONLY; }
101
 ;
102

    
103

    
104
/* Creation of routing tables */
105

    
106
CF_ADDTO(conf, newtab)
107

    
108
newtab: TABLE SYM {
109
   rt_new_table($2);
110
   }
111
 ;
112

    
113
/* Definition of protocols */
114

    
115
CF_ADDTO(conf, proto)
116

    
117
proto_start: PROTOCOL
118
 ;
119

    
120
proto_name:
121
   /* EMPTY */ {
122
     struct symbol *s = cf_default_name(this_proto->protocol->template, &this_proto->protocol->name_counter);
123
     s->class = SYM_PROTO;
124
     s->def = this_proto;
125
     this_proto->name = s->name;
126
     }
127
 | SYM {
128
     cf_define_symbol($1, SYM_PROTO, this_proto);
129
     this_proto->name = $1->name;
130
   }
131
 ;
132

    
133
proto_item:
134
   /* EMPTY */
135
 | PREFERENCE expr {
136
     if ($2 < 0 || $2 > 0xFFFF) cf_error("Invalid preference");
137
     this_proto->preference = $2;
138
   }
139
 | DISABLED bool { this_proto->disabled = $2; }
140
 | DEBUG debug_mask { this_proto->debug = $2; }
141
 | MRTDUMP mrtdump_mask { this_proto->mrtdump = $2; }
142
 | IMPORT imexport { this_proto->in_filter = $2; }
143
 | EXPORT imexport { this_proto->out_filter = $2; }
144
 | TABLE rtable { this_proto->table = $2; }
145
 | ROUTER ID idval { this_proto->router_id = $3; }
146
 | DESCRIPTION TEXT { this_proto->dsc = $2; }
147
 ;
148

    
149
imexport:
150
   FILTER filter { $$ = $2; }
151
 | where_filter
152
 | ALL { $$ = FILTER_ACCEPT; }
153
 | NONE { $$ = FILTER_REJECT; }
154
 ;
155

    
156
rtable:
157
   SYM {
158
     if ($1->class != SYM_TABLE) cf_error("Table name expected");
159
     $$ = $1->def;
160
   }
161
 ;
162

    
163
CF_ADDTO(conf, debug_default)
164

    
165
debug_default:
166
   DEBUG PROTOCOLS debug_mask { new_config->proto_default_debug = $3; }
167
 | DEBUG COMMANDS expr { new_config->cli_debug = $3; }
168
 ;
169

    
170
/* MRTDUMP PROTOCOLS is in systep/unix/config.Y */
171

    
172
/* Interface patterns */
173

    
174
iface_patt_node_init:
175
   /* EMPTY */ {
176
     struct iface_patt_node *ipn = cfg_allocz(sizeof(struct iface_patt_node));
177
     add_tail(&this_ipatt->ipn_list, NODE ipn);
178
     this_ipn = ipn;
179
   }
180
 ;
181

    
182
iface_patt_node_body:
183
   TEXT { this_ipn->pattern = $1; this_ipn->prefix = IPA_NONE; this_ipn->pxlen = 0; }
184
 | prefix { this_ipn->pattern = NULL; this_ipn->prefix = $1.addr; this_ipn->pxlen = $1.len; }
185
 | TEXT prefix { this_ipn->pattern = $1; this_ipn->prefix = $2.addr; this_ipn->pxlen = $2.len; }
186
 ;
187

    
188
iface_negate:
189
       { this_ipn->positive = 1; }
190
 | '-' { this_ipn->positive = 0; }
191
 ;
192

    
193
iface_patt_node:
194
   iface_patt_node_init iface_negate iface_patt_node_body 
195
 ;
196

    
197

    
198
iface_patt_list:
199
   iface_patt_node
200
 | iface_patt_list ',' iface_patt_node
201
 ;
202

    
203

    
204
/* Direct device route protocol */
205

    
206
CF_ADDTO(proto, dev_proto '}')
207

    
208
dev_proto_start: proto_start DIRECT {
209
     struct rt_dev_config *p = proto_config_new(&proto_device, sizeof(struct rt_dev_config));
210
     this_proto = &p->c;
211
     p->c.preference = DEF_PREF_DIRECT;
212
     init_list(&p->iface_list);
213
   }
214
 ;
215

    
216
dev_proto:
217
   dev_proto_start proto_name '{'
218
 | dev_proto proto_item ';'
219
 | dev_proto dev_iface_patt ';'
220
 ;
221

    
222
dev_iface_init:
223
   /* EMPTY */ {
224
     struct rt_dev_config *p = (void *) this_proto;
225
     this_ipatt = cfg_allocz(sizeof(struct iface_patt));
226
     add_tail(&p->iface_list, NODE this_ipatt);
227
     init_list(&this_ipatt->ipn_list);
228
   }
229
 ;
230

    
231
dev_iface_patt:
232
   INTERFACE dev_iface_init iface_patt_list
233
 ;
234

    
235
/* Debug flags */
236

    
237
debug_mask:
238
   ALL { $$ = ~0; }
239
 | OFF { $$ = 0; }
240
 | '{' debug_list '}' { $$ = $2; }
241
 ;
242

    
243
debug_list:
244
   debug_flag
245
 | debug_list ',' debug_flag { $$ = $1 | $3; }
246
 ;
247

    
248
debug_flag:
249
   STATES	{ $$ = D_STATES; }
250
 | ROUTES	{ $$ = D_ROUTES; }
251
 | FILTERS	{ $$ = D_FILTERS; }
252
 | INTERFACES	{ $$ = D_IFACES; }
253
 | EVENTS	{ $$ = D_EVENTS; }
254
 | PACKETS	{ $$ = D_PACKETS; }
255
 ;
256

    
257
/* MRTDump flags */
258

    
259
mrtdump_mask:
260
   ALL { $$ = ~0; }
261
 | OFF { $$ = 0; }
262
 | '{' mrtdump_list '}' { $$ = $2; }
263
 ;
264

    
265
mrtdump_list:
266
   mrtdump_flag
267
 | mrtdump_list ',' mrtdump_flag { $$ = $1 | $3; }
268
 ;
269

    
270
mrtdump_flag:
271
   STATES	{ $$ = MD_STATES; }
272
 | MESSAGES	{ $$ = MD_MESSAGES; }
273
 ;
274

    
275
/* Password lists */
276

    
277
password_list:
278
   PASSWORDS '{' password_items '}'
279
 | password_item
280
;
281

    
282
password_items: 
283
    /* empty */
284
  | password_item ';' password_items
285
;
286

    
287
password_item:
288
    password_item_begin '{' password_item_params '}'
289
  | password_item_begin
290
;
291

    
292
password_item_begin:
293
   PASSWORD TEXT {
294
     if (!this_p_list) {
295
     	this_p_list = cfg_alloc(sizeof(list));
296
     	init_list(this_p_list);
297
        password_id = 1;
298
     }
299
     this_p_item = cfg_alloc(sizeof (struct password_item));
300
     this_p_item->password = $2;
301
     this_p_item->genfrom = 0;
302
     this_p_item->gento = TIME_INFINITY;
303
     this_p_item->accfrom = 0;
304
     this_p_item->accto = TIME_INFINITY;
305
     this_p_item->id = password_id++;
306
     add_tail(this_p_list, &this_p_item->n);
307
   }
308
;
309

    
310
password_item_params:
311
   /* empty */ { } 
312
 | GENERATE FROM datetime ';' password_item_params { this_p_item->genfrom = $3; }
313
 | GENERATE TO datetime ';' password_item_params { this_p_item->gento = $3; }
314
 | ACCEPT FROM datetime ';' password_item_params { this_p_item->accfrom = $3; }
315
 | ACCEPT TO datetime ';' password_item_params { this_p_item->accto = $3; }
316
 | ID expr ';' password_item_params { this_p_item->id = $2; if ($2 <= 0) cf_error("Password ID has to be greated than zero."); }
317
 ;
318

    
319

    
320

    
321
/* Core commands */
322
CF_CLI_HELP(SHOW, ..., [[Show status information]])
323

    
324
CF_CLI(SHOW STATUS,,, [[Show router status]])
325
{ cmd_show_status(); } ;
326

    
327
CF_CLI(SHOW PROTOCOLS, proto_patt2, [<protocol> | \"<pattern>\"], [[Show routing protocols]])
328
{ proto_apply_cmd($3, proto_cmd_show, 0, 0); } ;
329

    
330
CF_CLI(SHOW PROTOCOLS ALL, proto_patt2, [<protocol> | \"<pattern>\"], [[Show routing protocol details]])
331
{ proto_apply_cmd($4, proto_cmd_show, 0, 1); } ;
332

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

    
338
CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
339
{ if_show(); } ;
340

    
341
CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
342
{ if_show_summary(); } ;
343

    
344
CF_CLI(SHOW ROUTE, r_args, [[[<prefix>|for <prefix>|for <ip>] [table <t>] [filter <f>|where <cond>] [all] [primary] [(export|preexport) <p>] [protocol <p>] [stats|count]]], [[Show routing table]])
345
{ rt_show($3); } ;
346

    
347
r_args:
348
   /* empty */ {
349
     $$ = cfg_allocz(sizeof(struct rt_show_data));
350
     $$->pxlen = 256;
351
     $$->filter = FILTER_ACCEPT;
352
     $$->table = config->master_rtc->table;
353
   }
354
 | r_args prefix {
355
     $$ = $1;
356
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
357
     $$->prefix = $2.addr;
358
     $$->pxlen = $2.len;
359
   }
360
 | r_args FOR prefix_or_ipa {
361
     $$ = $1;
362
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
363
     $$->prefix = $3.addr;
364
     $$->pxlen = $3.len;
365
     $$->show_for = 1;
366
   }
367
 | r_args TABLE SYM {
368
     $$ = $1;
369
     if ($3->class != SYM_TABLE) cf_error("%s is not a table", $3->name);
370
     $$->table = ((struct rtable_config *)$3->def)->table;
371
   }
372
 | r_args FILTER filter {
373
     $$ = $1;
374
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
375
     $$->filter = $3;
376
   }
377
 | r_args where_filter {
378
     $$ = $1;
379
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
380
     $$->filter = $2;
381
   }
382
 | r_args ALL {
383
     $$ = $1;
384
     $$->verbose = 1;
385
   }
386
 | r_args PRIMARY {
387
     $$ = $1;
388
     $$->primary_only = 1;
389
   }
390
 | r_args export_or_preexport SYM {
391
     struct proto_config *c = (struct proto_config *) $3->def;
392
     $$ = $1;
393
     if ($$->export_mode) cf_error("Protocol specified twice");
394
     if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
395
     $$->export_mode = $2;
396
     $$->primary_only = 1;
397
     $$->export_protocol = c->proto;
398
     $$->running_on_config = c->proto->cf->global;
399
   }
400
 | r_args PROTOCOL SYM {
401
     struct proto_config *c = (struct proto_config *) $3->def;
402
     $$ = $1;
403
     if ($$->show_protocol) cf_error("Protocol specified twice");
404
     if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
405
     $$->show_protocol = c->proto;
406
     $$->running_on_config = c->proto->cf->global;
407
   }
408
 | r_args STATS {
409
     $$ = $1;
410
     $$->stats = 1;
411
   }
412
 | r_args COUNT {
413
     $$ = $1;
414
     $$->stats = 2;
415
   }
416
 ;
417

    
418
export_or_preexport:
419
   PREEXPORT { $$ = 1; }
420
 | EXPORT { $$ = 2; }
421
 ;
422

    
423
CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
424
{ cmd_show_symbols($3); } ;
425

    
426
CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
427
CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
428
{ rdump(&root_pool); cli_msg(0, ""); } ;
429
CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
430
{ sk_dump_all(); cli_msg(0, ""); } ;
431
CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
432
{ if_dump_all(); cli_msg(0, ""); } ;
433
CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
434
{ neigh_dump_all(); cli_msg(0, ""); } ;
435
CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
436
{ rta_dump_all(); cli_msg(0, ""); } ;
437
CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
438
{ rt_dump_all(); cli_msg(0, ""); } ;
439
CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
440
{ protos_dump_all(); cli_msg(0, ""); } ;
441

    
442
CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
443
  cli_set_log_echo(this_cli, $2, $3);
444
  cli_msg(0, "");
445
} ;
446

    
447
echo_mask:
448
   ALL { $$ = ~0; }
449
 | OFF { $$ = 0; }
450
 | NUM
451
 ;
452

    
453
echo_size:
454
   /* empty */ { $$ = 4096; }
455
 | NUM {
456
     if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
457
     $$ = $1;
458
   }
459
 ;
460

    
461
CF_CLI(DISABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Disable protocol]])
462
{ proto_apply_cmd($2, proto_cmd_disable, 1, 0); } ;
463
CF_CLI(ENABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Enable protocol]])
464
{ proto_apply_cmd($2, proto_cmd_enable, 1, 0); } ;
465
CF_CLI(RESTART, proto_patt, <protocol> | \"<pattern>\" | all, [[Restart protocol]])
466
{ proto_apply_cmd($2, proto_cmd_restart, 1, 0); } ;
467
CF_CLI(RELOAD, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol]])
468
{ proto_apply_cmd($2, proto_cmd_reload, 1, CMD_RELOAD); } ;
469
CF_CLI(RELOAD IN, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol (just imported routes)]])
470
{ proto_apply_cmd($3, proto_cmd_reload, 1, CMD_RELOAD_IN); } ;
471
CF_CLI(RELOAD OUT, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol (just exported routes)]])
472
{ proto_apply_cmd($3, proto_cmd_reload, 1, CMD_RELOAD_OUT); } ;
473

    
474
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging via BIRD logs]])
475
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging via BIRD logs]])
476
{ proto_apply_cmd($2, proto_cmd_debug, 1, $3); } ;
477

    
478
CF_CLI_HELP(MRTDUMP, ..., [[Control protocol debugging via MRTdump files]])
479
CF_CLI(MRTDUMP, proto_patt mrtdump_mask, (<protocol> | <pattern> | all) (all | off | { states | messages }), [[Control protocol debugging via MRTdump format]])
480
{ proto_apply_cmd($2, proto_cmd_mrtdump, 1, $3); } ;
481

    
482
CF_CLI(RESTRICT,,,[[Restrict current CLI session to safe commands]])
483
{ this_cli->restricted = 1; cli_msg(16, "Access restricted"); } ;
484

    
485
proto_patt:
486
   SYM  { $$.ptr = $1; $$.patt = 0; }
487
 | ALL  { $$.ptr = NULL; $$.patt = 1; }
488
 | TEXT { $$.ptr = $1; $$.patt = 1; }
489
 ;
490

    
491
proto_patt2:
492
   SYM  { $$.ptr = $1; $$.patt = 0; }
493
 |      { $$.ptr = NULL; $$.patt = 1; }
494
 | TEXT { $$.ptr = $1; $$.patt = 1; }
495
 ;
496

    
497

    
498
CF_CODE
499

    
500
CF_END