Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (10.4 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 list *this_p_list;
22
static struct password_item *this_p_item;
23
static int password_id;
24

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

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

    
39

    
40
CF_DECLS
41

    
42
CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
43
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
44
CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
45
CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREIMPORT, GENERATE)
46

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

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

    
61
CF_GRAMMAR
62

    
63
/* Setting of router ID */
64

    
65
CF_ADDTO(conf, rtrid)
66

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

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

    
84
/* Creation of routing tables */
85

    
86
CF_ADDTO(conf, newtab)
87

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

    
93
/* Definition of protocols */
94

    
95
CF_ADDTO(conf, proto)
96

    
97
proto_start: PROTOCOL
98
 ;
99

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

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

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

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

    
140
CF_ADDTO(conf, debug_default)
141

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

    
147
/* Interface patterns */
148

    
149
iface_patt:
150
   TEXT { this_ipatt->pattern = $1; this_ipatt->prefix = IPA_NONE; this_ipatt->pxlen = 0; }
151
 | prefix { this_ipatt->pattern = NULL; this_ipatt->prefix = $1.addr; this_ipatt->pxlen = $1.len; }
152
 | TEXT prefix { this_ipatt->pattern = $1; this_ipatt->prefix = $2.addr; this_ipatt->pxlen = $2.len; }
153
 ;
154

    
155
/* Direct device route protocol */
156

    
157
CF_ADDTO(proto, dev_proto '}')
158

    
159
dev_proto_start: proto_start DIRECT {
160
     struct rt_dev_config *p = proto_config_new(&proto_device, sizeof(struct rt_dev_config));
161
     this_proto = &p->c;
162
     p->c.preference = DEF_PREF_DIRECT;
163
     init_list(&p->iface_list);
164
   }
165
 ;
166

    
167
dev_proto:
168
   dev_proto_start proto_name '{'
169
 | dev_proto proto_item ';'
170
 | dev_proto dev_iface_list ';'
171
 ;
172

    
173
dev_iface_entry_init:
174
   /* EMPTY */ {
175
     struct rt_dev_config *p = (void *) this_proto;
176
     struct iface_patt *k = cfg_allocz(sizeof(struct iface_patt));
177
     add_tail(&p->iface_list, &k->n);
178
     this_ipatt = k;
179
   }
180
 ;
181

    
182
dev_iface_entry:
183
   dev_iface_entry_init iface_patt
184
 ;
185

    
186
dev_iface_list:
187
   INTERFACE dev_iface_entry
188
 | dev_iface_list ',' dev_iface_entry
189
 ;
190

    
191
/* Debug flags */
192

    
193
debug_mask:
194
   ALL { $$ = ~0; }
195
 | OFF { $$ = 0; }
196
 | '{' debug_list '}' { $$ = $2; }
197
 ;
198

    
199
debug_list:
200
   debug_flag
201
 | debug_list ',' debug_flag { $$ = $1 | $3; }
202
 ;
203

    
204
debug_flag:
205
   STATES	{ $$ = D_STATES; }
206
 | ROUTES	{ $$ = D_ROUTES; }
207
 | FILTERS	{ $$ = D_FILTERS; }
208
 | INTERFACES	{ $$ = D_IFACES; }
209
 | EVENTS	{ $$ = D_EVENTS; }
210
 | PACKETS	{ $$ = D_PACKETS; }
211
 ;
212

    
213
/* Password lists */
214

    
215
password_list:
216
   PASSWORDS '{' password_items '}'
217
 | password_item
218
;
219

    
220
password_items: 
221
    /* empty */
222
  | password_item ';' password_items
223
;
224

    
225
password_item:
226
    password_item_begin '{' password_item_params '}'
227
  | password_item_begin
228
;
229

    
230
password_item_begin:
231
   PASSWORD TEXT {
232
     if (!this_p_list) {
233
     	this_p_list = cfg_alloc(sizeof(list));
234
     	init_list(this_p_list);
235
        password_id = 1;
236
     }
237
     this_p_item = cfg_alloc(sizeof (struct password_item));
238
     this_p_item->password = $2;
239
     this_p_item->genfrom = 0;
240
     this_p_item->gento = TIME_INFINITY;
241
     this_p_item->accfrom = 0;
242
     this_p_item->accto = TIME_INFINITY;
243
     this_p_item->id = password_id++;
244
     add_tail(this_p_list, &this_p_item->n);
245
   }
246
;
247

    
248
password_item_params:
249
   /* empty */ { } 
250
 | GENERATE FROM datetime ';' password_item_params { this_p_item->genfrom = $3; }
251
 | GENERATE TO datetime ';' password_item_params { this_p_item->gento = $3; }
252
 | ACCEPT FROM datetime ';' password_item_params { this_p_item->accfrom = $3; }
253
 | ACCEPT TO datetime ';' password_item_params { this_p_item->accto = $3; }
254
 | ID expr ';' password_item_params { this_p_item->id = $2; if ($2 <= 0) cf_error("Password ID has to be greated than zero."); }
255
 ;
256

    
257

    
258
/* Core commands */
259
CF_CLI_HELP(SHOW, ..., [[Show status information]])
260

    
261
CF_CLI(SHOW STATUS,,, [[Show router status]])
262
{ cmd_show_status(); } ;
263

    
264
CF_CLI(SHOW PROTOCOLS, optsym, [<name>], [[Show routing protocols]])
265
{ proto_show($3, 0); } ;
266

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

    
270
optsym:
271
   SYM
272
 | /* empty */ { $$ = NULL; }
273
 ;
274

    
275
CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
276
{ if_show(); } ;
277

    
278
CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
279
{ if_show_summary(); } ;
280

    
281
CF_CLI(SHOW ROUTE, r_args, [[[<prefix>|for <prefix>|for <ip>] [table <t>] [filter <f>|where <cond>] [all] [primary] [(import|preimport) <p>] [protocol <p>] [stats|count]]], [[Show routing table]])
282
{ rt_show($3); } ;
283

    
284
r_args:
285
   /* empty */ {
286
     $$ = cfg_allocz(sizeof(struct rt_show_data));
287
     $$->pxlen = 256;
288
     $$->filter = FILTER_ACCEPT;
289
     $$->table = config->master_rtc->table;
290
   }
291
 | r_args prefix {
292
     $$ = $1;
293
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
294
     $$->prefix = $2.addr;
295
     $$->pxlen = $2.len;
296
   }
297
 | r_args FOR prefix_or_ipa {
298
     $$ = $1;
299
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
300
     $$->prefix = $3.addr;
301
     $$->pxlen = $3.len;
302
     $$->show_for = 1;
303
   }
304
 | r_args TABLE SYM {
305
     $$ = $1;
306
     if ($3->class != SYM_TABLE) cf_error("%s is not a table", $3->name);
307
     $$->table = ((struct rtable_config *)$3->def)->table;
308
   }
309
 | r_args FILTER filter {
310
     $$ = $1;
311
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
312
     $$->filter = $3;
313
   }
314
 | r_args where_filter {
315
     $$ = $1;
316
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
317
     $$->filter = $2;
318
   }
319
 | r_args ALL {
320
     $$ = $1;
321
     $$->verbose = 1;
322
   }
323
 | r_args PRIMARY {
324
     $$ = $1;
325
     $$->primary_only = 1;
326
   }
327
 | r_args import_or_preimport SYM {
328
     struct proto_config *c = (struct proto_config *) $3->def;
329
     $$ = $1;
330
     if ($$->import_mode) cf_error("Protocol specified twice");
331
     if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
332
     $$->import_mode = $2;
333
     $$->primary_only = 1;
334
     $$->import_protocol = c->proto;
335
     $$->running_on_config = c->proto->cf->global;
336
   }
337
 | r_args PROTOCOL SYM {
338
     struct proto_config *c = (struct proto_config *) $3->def;
339
     $$ = $1;
340
     if ($$->show_protocol) cf_error("Protocol specified twice");
341
     if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
342
     $$->show_protocol = c->proto;
343
     $$->running_on_config = c->proto->cf->global;
344
   }
345
 | r_args STATS {
346
     $$ = $1;
347
     $$->stats = 1;
348
   }
349
 | r_args COUNT {
350
     $$ = $1;
351
     $$->stats = 2;
352
   }
353
 ;
354

    
355
import_or_preimport:
356
   PREIMPORT { $$ = 1; }
357
 | IMPORT { $$ = 2; }
358
 ;
359

    
360
CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
361
{ cmd_show_symbols($3); } ;
362

    
363
CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
364
CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
365
{ rdump(&root_pool); cli_msg(0, ""); } ;
366
CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
367
{ sk_dump_all(); cli_msg(0, ""); } ;
368
CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
369
{ if_dump_all(); cli_msg(0, ""); } ;
370
CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
371
{ neigh_dump_all(); cli_msg(0, ""); } ;
372
CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
373
{ rta_dump_all(); cli_msg(0, ""); } ;
374
CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
375
{ rt_dump_all(); cli_msg(0, ""); } ;
376
CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
377
{ protos_dump_all(); cli_msg(0, ""); } ;
378

    
379
CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
380
  cli_set_log_echo(this_cli, $2, $3);
381
  cli_msg(0, "");
382
} ;
383

    
384
echo_mask:
385
   ALL { $$ = ~0; }
386
 | OFF { $$ = 0; }
387
 | NUM
388
 ;
389

    
390
echo_size:
391
   /* empty */ { $$ = 4096; }
392
 | NUM {
393
     if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
394
     $$ = $1;
395
   }
396
 ;
397

    
398
CF_CLI(DISABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Disable protocol]])
399
{ proto_xxable($2, 0); } ;
400
CF_CLI(ENABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Enable protocol]])
401
{ proto_xxable($2, 1); } ;
402
CF_CLI(RESTART, proto_patt, <protocol> | \"<pattern>\" | all, [[Restart protocol]])
403
{ proto_xxable($2, 2); } ;
404

    
405
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging]])
406
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging]])
407
{ proto_debug($2, $3); }
408
 ;
409

    
410
proto_patt:
411
   SYM { $$ = $1->name; }
412
 | ALL { $$ = "*"; }
413
 | TEXT
414
 ;
415

    
416
CF_CODE
417

    
418
CF_END