Statistics
| Branch: | Revision:

iof-bird-daemon / nest / config.Y @ 258d0ad4

History | View | Annotate | Download (9.98 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 list *
26
get_passwords(void)
27
{
28
  list *rv = this_p_list;
29
  this_p_list = NULL;
30
  return rv;
31
}
32

    
33

    
34
CF_DECLS
35

    
36
CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
37
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
38
CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
39
CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREIMPORT, GENERATE)
40

    
41
CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
42
	RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE)
43
CF_ENUM(T_ENUM_SCOPE, SCOPE_, HOST, LINK, SITE, ORGANIZATION, UNIVERSE)
44
CF_ENUM(T_ENUM_RTC, RTC_, UNICAST, BROADCAST, MULTICAST, ANYCAST)
45
CF_ENUM(T_ENUM_RTD, RTD_, ROUTER, DEVICE, BLACKHOLE, UNREACHABLE, PROHIBIT)
46

    
47
%type <i32> idval
48
%type <f> imexport
49
%type <r> rtable
50
%type <s> optsym
51
%type <ra> r_args
52
%type <i> echo_mask echo_size debug_mask debug_list debug_flag import_or_proto
53
%type <t> proto_patt
54

    
55
CF_GRAMMAR
56

    
57
/* Setting of router ID */
58

    
59
CF_ADDTO(conf, rtrid)
60

    
61
rtrid: ROUTER ID idval ';' {
62
   new_config->router_id = $3;
63
   }
64
 ;
65

    
66
idval:
67
   NUM { $$ = $1; }
68
 | RTRID
69
 | IPA {
70
#ifndef IPV6
71
     $$ = ipa_to_u32($1);
72
#else
73
     cf_error("Router IDs must be entered as hexadecimal numbers or IPv4 addresses in IPv6 version");
74
#endif
75
   }
76
 ;
77

    
78
/* Creation of routing tables */
79

    
80
CF_ADDTO(conf, newtab)
81

    
82
newtab: TABLE SYM {
83
   rt_new_table($2);
84
   }
85
 ;
86

    
87
/* Definition of protocols */
88

    
89
CF_ADDTO(conf, proto)
90

    
91
proto_start: PROTOCOL
92
 ;
93

    
94
proto_name:
95
   /* EMPTY */ {
96
     struct symbol *s = cf_default_name(this_proto->protocol->template, &this_proto->protocol->name_counter);
97
     s->class = SYM_PROTO;
98
     s->def = this_proto;
99
     this_proto->name = s->name;
100
     }
101
 | SYM {
102
     cf_define_symbol($1, SYM_PROTO, this_proto);
103
     this_proto->name = $1->name;
104
   }
105
 ;
106

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

    
120
imexport:
121
   FILTER filter { $$ = $2; }
122
 | where_filter
123
 | ALL { $$ = FILTER_ACCEPT; }
124
 | NONE { $$ = FILTER_REJECT; }
125
 ;
126

    
127
rtable:
128
   SYM {
129
     if ($1->class != SYM_TABLE) cf_error("Table name expected");
130
     $$ = $1->def;
131
   }
132
 ;
133

    
134
CF_ADDTO(conf, debug_default)
135

    
136
debug_default:
137
   DEBUG PROTOCOLS debug_mask { new_config->proto_default_debug = $3; }
138
 | DEBUG COMMANDS expr { new_config->cli_debug = $3; }
139
 ;
140

    
141
/* Interface patterns */
142

    
143
iface_patt:
144
   TEXT { this_ipatt->pattern = $1; this_ipatt->prefix = IPA_NONE; this_ipatt->pxlen = 0; }
145
 | prefix { this_ipatt->pattern = NULL; this_ipatt->prefix = $1.addr; this_ipatt->pxlen = $1.len; }
146
 | TEXT prefix { this_ipatt->pattern = $1; this_ipatt->prefix = $2.addr; this_ipatt->pxlen = $2.len; }
147
 ;
148

    
149
/* Direct device route protocol */
150

    
151
CF_ADDTO(proto, dev_proto '}')
152

    
153
dev_proto_start: proto_start DIRECT {
154
     struct rt_dev_config *p = proto_config_new(&proto_device, sizeof(struct rt_dev_config));
155
     this_proto = &p->c;
156
     p->c.preference = DEF_PREF_DIRECT;
157
     init_list(&p->iface_list);
158
   }
159
 ;
160

    
161
dev_proto:
162
   dev_proto_start proto_name '{'
163
 | dev_proto proto_item ';'
164
 | dev_proto dev_iface_list ';'
165
 ;
166

    
167
dev_iface_entry_init:
168
   /* EMPTY */ {
169
     struct rt_dev_config *p = (void *) this_proto;
170
     struct iface_patt *k = cfg_allocz(sizeof(struct iface_patt));
171
     add_tail(&p->iface_list, &k->n);
172
     this_ipatt = k;
173
   }
174
 ;
175

    
176
dev_iface_entry:
177
   dev_iface_entry_init iface_patt
178
 ;
179

    
180
dev_iface_list:
181
   INTERFACE dev_iface_entry
182
 | dev_iface_list ',' dev_iface_entry
183
 ;
184

    
185
/* Debug flags */
186

    
187
debug_mask:
188
   ALL { $$ = ~0; }
189
 | OFF { $$ = 0; }
190
 | '{' debug_list '}' { $$ = $2; }
191
 ;
192

    
193
debug_list:
194
   debug_flag
195
 | debug_list ',' debug_flag { $$ = $1 | $3; }
196
 ;
197

    
198
debug_flag:
199
   STATES	{ $$ = D_STATES; }
200
 | ROUTES	{ $$ = D_ROUTES; }
201
 | FILTERS	{ $$ = D_FILTERS; }
202
 | INTERFACES	{ $$ = D_IFACES; }
203
 | EVENTS	{ $$ = D_EVENTS; }
204
 | PACKETS	{ $$ = D_PACKETS; }
205
 ;
206

    
207
/* Password lists */
208

    
209
password_list:
210
   PASSWORDS '{' password_items '}'
211
 | password_item
212
;
213

    
214
password_items: 
215
    /* empty */
216
  | password_item ';' password_items
217
;
218

    
219
password_item:
220
    password_item_begin '{' password_item_params '}'
221
  | password_item_begin
222
;
223

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

    
242
password_item_params:
243
   /* empty */ { } 
244
 | GENERATE FROM datetime ';' password_item_params { this_p_item->genfrom = $3; }
245
 | GENERATE TO datetime ';' password_item_params { this_p_item->gento = $3; }
246
 | ACCEPT FROM datetime ';' password_item_params { this_p_item->accfrom = $3; }
247
 | ACCEPT TO datetime ';' password_item_params { this_p_item->accto = $3; }
248
 | ID expr ';' password_item_params { this_p_item->id = $2; if ($2 <= 0) cf_error("Password ID has to be greated than zero."); }
249
 ;
250

    
251

    
252
/* Core commands */
253
CF_CLI_HELP(SHOW, ..., [[Show status information]])
254

    
255
CF_CLI(SHOW STATUS,,, [[Show router status]])
256
{ cmd_show_status(); } ;
257

    
258
CF_CLI(SHOW PROTOCOLS, optsym, [<name>], [[Show routing protocols]])
259
{ proto_show($3, 0); } ;
260

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

    
264
optsym:
265
   SYM
266
 | /* empty */ { $$ = NULL; }
267
 ;
268

    
269
CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
270
{ if_show(); } ;
271

    
272
CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
273
{ if_show_summary(); } ;
274

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

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

    
341
import_or_proto:
342
   PREIMPORT { $$ = 1; }
343
 | IMPORT { $$ = 2; }
344
 ;
345

    
346
CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
347
{ cmd_show_symbols($3); } ;
348

    
349
CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
350
CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
351
{ rdump(&root_pool); cli_msg(0, ""); } ;
352
CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
353
{ sk_dump_all(); cli_msg(0, ""); } ;
354
CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
355
{ if_dump_all(); cli_msg(0, ""); } ;
356
CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
357
{ neigh_dump_all(); cli_msg(0, ""); } ;
358
CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
359
{ rta_dump_all(); cli_msg(0, ""); } ;
360
CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
361
{ rt_dump_all(); cli_msg(0, ""); } ;
362
CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
363
{ protos_dump_all(); cli_msg(0, ""); } ;
364

    
365
CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
366
  cli_set_log_echo(this_cli, $2, $3);
367
  cli_msg(0, "");
368
} ;
369

    
370
echo_mask:
371
   ALL { $$ = ~0; }
372
 | OFF { $$ = 0; }
373
 | NUM
374
 ;
375

    
376
echo_size:
377
   /* empty */ { $$ = 4096; }
378
 | NUM {
379
     if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
380
     $$ = $1;
381
   }
382
 ;
383

    
384
CF_CLI(DISABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Disable protocol]])
385
{ proto_xxable($2, 0); } ;
386
CF_CLI(ENABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Enable protocol]])
387
{ proto_xxable($2, 1); } ;
388
CF_CLI(RESTART, proto_patt, <protocol> | \"<pattern>\" | all, [[Restart protocol]])
389
{ proto_xxable($2, 2); } ;
390

    
391
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging]])
392
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging]])
393
{ proto_debug($2, $3); }
394
 ;
395

    
396
proto_patt:
397
   SYM { $$ = $1->name; }
398
 | ALL { $$ = "*"; }
399
 | TEXT
400
 ;
401

    
402
CF_CODE
403

    
404
CF_END