Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (11.3 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

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

    
55
%type <i32> idval
56
%type <f> imexport
57
%type <r> rtable
58
%type <s> optsym
59
%type <ra> r_args
60
%type <i> echo_mask echo_size debug_mask debug_list debug_flag export_or_preexport
61
%type <t> proto_patt
62

    
63
CF_GRAMMAR
64

    
65
/* Setting of router ID */
66

    
67
CF_ADDTO(conf, rtrid)
68

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

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

    
86

    
87
CF_ADDTO(conf, listen)
88

    
89
listen: LISTEN BGP listen_opts ';' ;
90

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

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

    
102

    
103
/* Creation of routing tables */
104

    
105
CF_ADDTO(conf, newtab)
106

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

    
112
/* Definition of protocols */
113

    
114
CF_ADDTO(conf, proto)
115

    
116
proto_start: PROTOCOL
117
 ;
118

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

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

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

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

    
161
CF_ADDTO(conf, debug_default)
162

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

    
168
/* Interface patterns */
169

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

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

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

    
189
iface_patt_node:
190
   iface_patt_node_init iface_negate iface_patt_node_body 
191
 ;
192

    
193

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

    
199

    
200
/* Direct device route protocol */
201

    
202
CF_ADDTO(proto, dev_proto '}')
203

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

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

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

    
227
dev_iface_patt:
228
   INTERFACE dev_iface_init iface_patt_list
229
 ;
230

    
231
/* Debug flags */
232

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

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

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

    
253
/* Password lists */
254

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

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

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

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

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

    
297

    
298

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
439
CF_CLI(DISABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Disable protocol]])
440
{ proto_xxable($2, 0); } ;
441
CF_CLI(ENABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Enable protocol]])
442
{ proto_xxable($2, 1); } ;
443
CF_CLI(RESTART, proto_patt, <protocol> | \"<pattern>\" | all, [[Restart protocol]])
444
{ proto_xxable($2, 2); } ;
445

    
446
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging]])
447
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging]])
448
{ proto_debug($2, $3); }
449
 ;
450

    
451
proto_patt:
452
   SYM { $$ = $1->name; }
453
 | ALL { $$ = "*"; }
454
 | TEXT
455
 ;
456

    
457
CF_CODE
458

    
459
CF_END