Statistics
| Branch: | Revision:

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

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

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

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

    
62
CF_GRAMMAR
63

    
64
/* Setting of router ID */
65

    
66
CF_ADDTO(conf, rtrid)
67

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

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

    
85
/* Creation of routing tables */
86

    
87
CF_ADDTO(conf, newtab)
88

    
89
newtab: TABLE SYM {
90
   rt_new_table($2);
91
   }
92
 ;
93

    
94
/* Definition of protocols */
95

    
96
CF_ADDTO(conf, proto)
97

    
98
proto_start: PROTOCOL
99
 ;
100

    
101
proto_name:
102
   /* EMPTY */ {
103
     struct symbol *s = cf_default_name(this_proto->protocol->template, &this_proto->protocol->name_counter);
104
     s->class = SYM_PROTO;
105
     s->def = this_proto;
106
     this_proto->name = s->name;
107
     }
108
 | SYM {
109
     cf_define_symbol($1, SYM_PROTO, this_proto);
110
     this_proto->name = $1->name;
111
   }
112
 ;
113

    
114
proto_item:
115
   /* EMPTY */
116
 | PREFERENCE expr {
117
     if ($2 < 0 || $2 > 255) cf_error("Invalid preference");
118
     this_proto->preference = $2;
119
   }
120
 | DISABLED bool { this_proto->disabled = $2; }
121
 | DEBUG debug_mask { this_proto->debug = $2; }
122
 | IMPORT imexport { this_proto->in_filter = $2; }
123
 | EXPORT imexport { this_proto->out_filter = $2; }
124
 | TABLE rtable { this_proto->table = $2; }
125
 ;
126

    
127
imexport:
128
   FILTER filter { $$ = $2; }
129
 | where_filter
130
 | ALL { $$ = FILTER_ACCEPT; }
131
 | NONE { $$ = FILTER_REJECT; }
132
 ;
133

    
134
rtable:
135
   SYM {
136
     if ($1->class != SYM_TABLE) cf_error("Table name expected");
137
     $$ = $1->def;
138
   }
139
 ;
140

    
141
CF_ADDTO(conf, debug_default)
142

    
143
debug_default:
144
   DEBUG PROTOCOLS debug_mask { new_config->proto_default_debug = $3; }
145
 | DEBUG COMMANDS expr { new_config->cli_debug = $3; }
146
 ;
147

    
148
/* Interface patterns */
149

    
150
iface_patt_node_init:
151
   /* EMPTY */ {
152
     struct iface_patt_node *ipn = cfg_allocz(sizeof(struct iface_patt_node));
153
     add_tail(&this_ipatt->ipn_list, NODE ipn);
154
     this_ipn = ipn;
155
   }
156
 ;
157

    
158
iface_patt_node_body:
159
   TEXT { this_ipn->pattern = $1; this_ipn->prefix = IPA_NONE; this_ipn->pxlen = 0; }
160
 | prefix { this_ipn->pattern = NULL; this_ipn->prefix = $1.addr; this_ipn->pxlen = $1.len; }
161
 | TEXT prefix { this_ipn->pattern = $1; this_ipn->prefix = $2.addr; this_ipn->pxlen = $2.len; }
162
 ;
163

    
164
iface_negate:
165
       { this_ipn->positive = 1; }
166
 | '-' { this_ipn->positive = 0; }
167
 ;
168

    
169
iface_patt_node:
170
   iface_patt_node_init iface_negate iface_patt_node_body 
171
 ;
172

    
173

    
174
iface_patt_list:
175
   iface_patt_node
176
 | iface_patt_list ',' iface_patt_node
177
 ;
178

    
179

    
180
/* Direct device route protocol */
181

    
182
CF_ADDTO(proto, dev_proto '}')
183

    
184
dev_proto_start: proto_start DIRECT {
185
     struct rt_dev_config *p = proto_config_new(&proto_device, sizeof(struct rt_dev_config));
186
     this_proto = &p->c;
187
     p->c.preference = DEF_PREF_DIRECT;
188
     init_list(&p->iface_list);
189
   }
190
 ;
191

    
192
dev_proto:
193
   dev_proto_start proto_name '{'
194
 | dev_proto proto_item ';'
195
 | dev_proto dev_iface_patt ';'
196
 ;
197

    
198
dev_iface_init:
199
   /* EMPTY */ {
200
     struct rt_dev_config *p = (void *) this_proto;
201
     this_ipatt = cfg_allocz(sizeof(struct iface_patt));
202
     add_tail(&p->iface_list, NODE this_ipatt);
203
     init_list(&this_ipatt->ipn_list);
204
   }
205
 ;
206

    
207
dev_iface_patt:
208
   INTERFACE dev_iface_init iface_patt_list
209
 ;
210

    
211
/* Debug flags */
212

    
213
debug_mask:
214
   ALL { $$ = ~0; }
215
 | OFF { $$ = 0; }
216
 | '{' debug_list '}' { $$ = $2; }
217
 ;
218

    
219
debug_list:
220
   debug_flag
221
 | debug_list ',' debug_flag { $$ = $1 | $3; }
222
 ;
223

    
224
debug_flag:
225
   STATES	{ $$ = D_STATES; }
226
 | ROUTES	{ $$ = D_ROUTES; }
227
 | FILTERS	{ $$ = D_FILTERS; }
228
 | INTERFACES	{ $$ = D_IFACES; }
229
 | EVENTS	{ $$ = D_EVENTS; }
230
 | PACKETS	{ $$ = D_PACKETS; }
231
 ;
232

    
233
/* Password lists */
234

    
235
password_list:
236
   PASSWORDS '{' password_items '}'
237
 | password_item
238
;
239

    
240
password_items: 
241
    /* empty */
242
  | password_item ';' password_items
243
;
244

    
245
password_item:
246
    password_item_begin '{' password_item_params '}'
247
  | password_item_begin
248
;
249

    
250
password_item_begin:
251
   PASSWORD TEXT {
252
     if (!this_p_list) {
253
     	this_p_list = cfg_alloc(sizeof(list));
254
     	init_list(this_p_list);
255
        password_id = 1;
256
     }
257
     this_p_item = cfg_alloc(sizeof (struct password_item));
258
     this_p_item->password = $2;
259
     this_p_item->genfrom = 0;
260
     this_p_item->gento = TIME_INFINITY;
261
     this_p_item->accfrom = 0;
262
     this_p_item->accto = TIME_INFINITY;
263
     this_p_item->id = password_id++;
264
     add_tail(this_p_list, &this_p_item->n);
265
   }
266
;
267

    
268
password_item_params:
269
   /* empty */ { } 
270
 | GENERATE FROM datetime ';' password_item_params { this_p_item->genfrom = $3; }
271
 | GENERATE TO datetime ';' password_item_params { this_p_item->gento = $3; }
272
 | ACCEPT FROM datetime ';' password_item_params { this_p_item->accfrom = $3; }
273
 | ACCEPT TO datetime ';' password_item_params { this_p_item->accto = $3; }
274
 | ID expr ';' password_item_params { this_p_item->id = $2; if ($2 <= 0) cf_error("Password ID has to be greated than zero."); }
275
 ;
276

    
277

    
278
/* Core commands */
279
CF_CLI_HELP(SHOW, ..., [[Show status information]])
280

    
281
CF_CLI(SHOW STATUS,,, [[Show router status]])
282
{ cmd_show_status(); } ;
283

    
284
CF_CLI(SHOW PROTOCOLS, optsym, [<name>], [[Show routing protocols]])
285
{ proto_show($3, 0); } ;
286

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

    
290
optsym:
291
   SYM
292
 | /* empty */ { $$ = NULL; }
293
 ;
294

    
295
CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
296
{ if_show(); } ;
297

    
298
CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
299
{ if_show_summary(); } ;
300

    
301
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]])
302
{ rt_show($3); } ;
303

    
304
r_args:
305
   /* empty */ {
306
     $$ = cfg_allocz(sizeof(struct rt_show_data));
307
     $$->pxlen = 256;
308
     $$->filter = FILTER_ACCEPT;
309
     $$->table = config->master_rtc->table;
310
   }
311
 | r_args prefix {
312
     $$ = $1;
313
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
314
     $$->prefix = $2.addr;
315
     $$->pxlen = $2.len;
316
   }
317
 | r_args FOR prefix_or_ipa {
318
     $$ = $1;
319
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
320
     $$->prefix = $3.addr;
321
     $$->pxlen = $3.len;
322
     $$->show_for = 1;
323
   }
324
 | r_args TABLE SYM {
325
     $$ = $1;
326
     if ($3->class != SYM_TABLE) cf_error("%s is not a table", $3->name);
327
     $$->table = ((struct rtable_config *)$3->def)->table;
328
   }
329
 | r_args FILTER filter {
330
     $$ = $1;
331
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
332
     $$->filter = $3;
333
   }
334
 | r_args where_filter {
335
     $$ = $1;
336
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
337
     $$->filter = $2;
338
   }
339
 | r_args ALL {
340
     $$ = $1;
341
     $$->verbose = 1;
342
   }
343
 | r_args PRIMARY {
344
     $$ = $1;
345
     $$->primary_only = 1;
346
   }
347
 | r_args export_or_preexport SYM {
348
     struct proto_config *c = (struct proto_config *) $3->def;
349
     $$ = $1;
350
     if ($$->export_mode) cf_error("Protocol specified twice");
351
     if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
352
     $$->export_mode = $2;
353
     $$->primary_only = 1;
354
     $$->export_protocol = c->proto;
355
     $$->running_on_config = c->proto->cf->global;
356
   }
357
 | r_args PROTOCOL SYM {
358
     struct proto_config *c = (struct proto_config *) $3->def;
359
     $$ = $1;
360
     if ($$->show_protocol) cf_error("Protocol specified twice");
361
     if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
362
     $$->show_protocol = c->proto;
363
     $$->running_on_config = c->proto->cf->global;
364
   }
365
 | r_args STATS {
366
     $$ = $1;
367
     $$->stats = 1;
368
   }
369
 | r_args COUNT {
370
     $$ = $1;
371
     $$->stats = 2;
372
   }
373
 ;
374

    
375
export_or_preexport:
376
   PREEXPORT { $$ = 1; }
377
 | EXPORT { $$ = 2; }
378
 ;
379

    
380
CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
381
{ cmd_show_symbols($3); } ;
382

    
383
CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
384
CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
385
{ rdump(&root_pool); cli_msg(0, ""); } ;
386
CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
387
{ sk_dump_all(); cli_msg(0, ""); } ;
388
CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
389
{ if_dump_all(); cli_msg(0, ""); } ;
390
CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
391
{ neigh_dump_all(); cli_msg(0, ""); } ;
392
CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
393
{ rta_dump_all(); cli_msg(0, ""); } ;
394
CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
395
{ rt_dump_all(); cli_msg(0, ""); } ;
396
CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
397
{ protos_dump_all(); cli_msg(0, ""); } ;
398

    
399
CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
400
  cli_set_log_echo(this_cli, $2, $3);
401
  cli_msg(0, "");
402
} ;
403

    
404
echo_mask:
405
   ALL { $$ = ~0; }
406
 | OFF { $$ = 0; }
407
 | NUM
408
 ;
409

    
410
echo_size:
411
   /* empty */ { $$ = 4096; }
412
 | NUM {
413
     if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
414
     $$ = $1;
415
   }
416
 ;
417

    
418
CF_CLI(DISABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Disable protocol]])
419
{ proto_xxable($2, 0); } ;
420
CF_CLI(ENABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Enable protocol]])
421
{ proto_xxable($2, 1); } ;
422
CF_CLI(RESTART, proto_patt, <protocol> | \"<pattern>\" | all, [[Restart protocol]])
423
{ proto_xxable($2, 2); } ;
424

    
425
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging]])
426
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging]])
427
{ proto_debug($2, $3); }
428
 ;
429

    
430
proto_patt:
431
   SYM { $$ = $1->name; }
432
 | ALL { $$ = "*"; }
433
 | TEXT
434
 ;
435

    
436
CF_CODE
437

    
438
CF_END