Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (11.5 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, REFEED)
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 export_or_preexport
62
%type <t> proto_patt
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
 | IMPORT imexport { this_proto->in_filter = $2; }
142
 | EXPORT imexport { this_proto->out_filter = $2; }
143
 | TABLE rtable { this_proto->table = $2; }
144
 | ROUTER ID idval { this_proto->router_id = $3; }
145
 | DESCRIPTION TEXT { this_proto->dsc = $2; }
146
 ;
147

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

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

    
162
CF_ADDTO(conf, debug_default)
163

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

    
169
/* Interface patterns */
170

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

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

    
185
iface_negate:
186
       { this_ipn->positive = 1; }
187
 | '-' { this_ipn->positive = 0; }
188
 ;
189

    
190
iface_patt_node:
191
   iface_patt_node_init iface_negate iface_patt_node_body 
192
 ;
193

    
194

    
195
iface_patt_list:
196
   iface_patt_node
197
 | iface_patt_list ',' iface_patt_node
198
 ;
199

    
200

    
201
/* Direct device route protocol */
202

    
203
CF_ADDTO(proto, dev_proto '}')
204

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

    
213
dev_proto:
214
   dev_proto_start proto_name '{'
215
 | dev_proto proto_item ';'
216
 | dev_proto dev_iface_patt ';'
217
 ;
218

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

    
228
dev_iface_patt:
229
   INTERFACE dev_iface_init iface_patt_list
230
 ;
231

    
232
/* Debug flags */
233

    
234
debug_mask:
235
   ALL { $$ = ~0; }
236
 | OFF { $$ = 0; }
237
 | '{' debug_list '}' { $$ = $2; }
238
 ;
239

    
240
debug_list:
241
   debug_flag
242
 | debug_list ',' debug_flag { $$ = $1 | $3; }
243
 ;
244

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

    
254
/* Password lists */
255

    
256
password_list:
257
   PASSWORDS '{' password_items '}'
258
 | password_item
259
;
260

    
261
password_items: 
262
    /* empty */
263
  | password_item ';' password_items
264
;
265

    
266
password_item:
267
    password_item_begin '{' password_item_params '}'
268
  | password_item_begin
269
;
270

    
271
password_item_begin:
272
   PASSWORD TEXT {
273
     if (!this_p_list) {
274
     	this_p_list = cfg_alloc(sizeof(list));
275
     	init_list(this_p_list);
276
        password_id = 1;
277
     }
278
     this_p_item = cfg_alloc(sizeof (struct password_item));
279
     this_p_item->password = $2;
280
     this_p_item->genfrom = 0;
281
     this_p_item->gento = TIME_INFINITY;
282
     this_p_item->accfrom = 0;
283
     this_p_item->accto = TIME_INFINITY;
284
     this_p_item->id = password_id++;
285
     add_tail(this_p_list, &this_p_item->n);
286
   }
287
;
288

    
289
password_item_params:
290
   /* empty */ { } 
291
 | GENERATE FROM datetime ';' password_item_params { this_p_item->genfrom = $3; }
292
 | GENERATE TO datetime ';' password_item_params { this_p_item->gento = $3; }
293
 | ACCEPT FROM datetime ';' password_item_params { this_p_item->accfrom = $3; }
294
 | ACCEPT TO datetime ';' password_item_params { this_p_item->accto = $3; }
295
 | ID expr ';' password_item_params { this_p_item->id = $2; if ($2 <= 0) cf_error("Password ID has to be greated than zero."); }
296
 ;
297

    
298

    
299

    
300
/* Core commands */
301
CF_CLI_HELP(SHOW, ..., [[Show status information]])
302

    
303
CF_CLI(SHOW STATUS,,, [[Show router status]])
304
{ cmd_show_status(); } ;
305

    
306
CF_CLI(SHOW PROTOCOLS, optsym, [<name>], [[Show routing protocols]])
307
{ proto_show($3, 0); } ;
308

    
309
CF_CLI(SHOW PROTOCOLS ALL, optsym, [<name>], [[Show routing protocol details]])
310
{ proto_show($4, 1); } ;
311

    
312
optsym:
313
   SYM
314
 | /* empty */ { $$ = NULL; }
315
 ;
316

    
317
CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
318
{ if_show(); } ;
319

    
320
CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
321
{ if_show_summary(); } ;
322

    
323
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]])
324
{ rt_show($3); } ;
325

    
326
r_args:
327
   /* empty */ {
328
     $$ = cfg_allocz(sizeof(struct rt_show_data));
329
     $$->pxlen = 256;
330
     $$->filter = FILTER_ACCEPT;
331
     $$->table = config->master_rtc->table;
332
   }
333
 | r_args prefix {
334
     $$ = $1;
335
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
336
     $$->prefix = $2.addr;
337
     $$->pxlen = $2.len;
338
   }
339
 | r_args FOR prefix_or_ipa {
340
     $$ = $1;
341
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
342
     $$->prefix = $3.addr;
343
     $$->pxlen = $3.len;
344
     $$->show_for = 1;
345
   }
346
 | r_args TABLE SYM {
347
     $$ = $1;
348
     if ($3->class != SYM_TABLE) cf_error("%s is not a table", $3->name);
349
     $$->table = ((struct rtable_config *)$3->def)->table;
350
   }
351
 | r_args FILTER filter {
352
     $$ = $1;
353
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
354
     $$->filter = $3;
355
   }
356
 | r_args where_filter {
357
     $$ = $1;
358
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
359
     $$->filter = $2;
360
   }
361
 | r_args ALL {
362
     $$ = $1;
363
     $$->verbose = 1;
364
   }
365
 | r_args PRIMARY {
366
     $$ = $1;
367
     $$->primary_only = 1;
368
   }
369
 | r_args export_or_preexport SYM {
370
     struct proto_config *c = (struct proto_config *) $3->def;
371
     $$ = $1;
372
     if ($$->export_mode) cf_error("Protocol specified twice");
373
     if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
374
     $$->export_mode = $2;
375
     $$->primary_only = 1;
376
     $$->export_protocol = c->proto;
377
     $$->running_on_config = c->proto->cf->global;
378
   }
379
 | r_args PROTOCOL SYM {
380
     struct proto_config *c = (struct proto_config *) $3->def;
381
     $$ = $1;
382
     if ($$->show_protocol) cf_error("Protocol specified twice");
383
     if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
384
     $$->show_protocol = c->proto;
385
     $$->running_on_config = c->proto->cf->global;
386
   }
387
 | r_args STATS {
388
     $$ = $1;
389
     $$->stats = 1;
390
   }
391
 | r_args COUNT {
392
     $$ = $1;
393
     $$->stats = 2;
394
   }
395
 ;
396

    
397
export_or_preexport:
398
   PREEXPORT { $$ = 1; }
399
 | EXPORT { $$ = 2; }
400
 ;
401

    
402
CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
403
{ cmd_show_symbols($3); } ;
404

    
405
CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
406
CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
407
{ rdump(&root_pool); cli_msg(0, ""); } ;
408
CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
409
{ sk_dump_all(); cli_msg(0, ""); } ;
410
CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
411
{ if_dump_all(); cli_msg(0, ""); } ;
412
CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
413
{ neigh_dump_all(); cli_msg(0, ""); } ;
414
CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
415
{ rta_dump_all(); cli_msg(0, ""); } ;
416
CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
417
{ rt_dump_all(); cli_msg(0, ""); } ;
418
CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
419
{ protos_dump_all(); cli_msg(0, ""); } ;
420

    
421
CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
422
  cli_set_log_echo(this_cli, $2, $3);
423
  cli_msg(0, "");
424
} ;
425

    
426
echo_mask:
427
   ALL { $$ = ~0; }
428
 | OFF { $$ = 0; }
429
 | NUM
430
 ;
431

    
432
echo_size:
433
   /* empty */ { $$ = 4096; }
434
 | NUM {
435
     if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
436
     $$ = $1;
437
   }
438
 ;
439

    
440
CF_CLI(DISABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Disable protocol]])
441
{ proto_xxable($2, 0); } ;
442
CF_CLI(ENABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Enable protocol]])
443
{ proto_xxable($2, 1); } ;
444
CF_CLI(RESTART, proto_patt, <protocol> | \"<pattern>\" | all, [[Restart protocol]])
445
{ proto_xxable($2, 2); } ;
446
CF_CLI(RELOAD, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol]])
447
{ proto_xxable($2, 3); } ;
448
CF_CLI(REFEED, proto_patt, <protocol> | \"<pattern>\" | all, [[Refeed protocol BROKEN]])
449
{ proto_xxable($2, 4); } ;
450

    
451

    
452

    
453
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging]])
454
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging]])
455
{ proto_debug($2, $3); }
456
 ;
457

    
458
proto_patt:
459
   SYM { $$ = $1->name; }
460
 | ALL { $$ = "*"; }
461
 | TEXT
462
 ;
463

    
464
CF_CODE
465

    
466
CF_END