Statistics
| Branch: | Revision:

iof-bird-daemon / nest / config.Y @ 4cdd0784

History | View | Annotate | Download (11.2 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)
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
 ;
145

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

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

    
160
CF_ADDTO(conf, debug_default)
161

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

    
167
/* Interface patterns */
168

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

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

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

    
188
iface_patt_node:
189
   iface_patt_node_init iface_negate iface_patt_node_body 
190
 ;
191

    
192

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

    
198

    
199
/* Direct device route protocol */
200

    
201
CF_ADDTO(proto, dev_proto '}')
202

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

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

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

    
226
dev_iface_patt:
227
   INTERFACE dev_iface_init iface_patt_list
228
 ;
229

    
230
/* Debug flags */
231

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

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

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

    
252
/* Password lists */
253

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

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

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

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

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

    
296

    
297

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
456
CF_CODE
457

    
458
CF_END