Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (8.95 KB)

1
/*
2
 *	BIRD -- Core Configuration
3
 *
4
 *	(c) 1998--2000 Martin Mares <mj@ucw.cz>
5
 *
6
 *	Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
CF_HDR
10

    
11
#include "nest/rt-dev.h"
12
#include "nest/password.h"
13
#include "nest/cmds.h"
14

    
15
CF_DEFINES
16

    
17
static struct proto_config *this_proto;
18
static struct iface_patt *this_ipatt;
19

    
20
CF_DECLS
21

    
22
CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
23
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
24
CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
25
CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR)
26

    
27
CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
28
	RIP, OSPF, OSPF_EXT, OSPF_IA, OSPF_BOUNDARY, BGP, PIPE)
29

    
30
%type <i32> idval
31
%type <f> imexport
32
%type <r> rtable
33
%type <p> password_list password_begin
34
%type <s> optsym
35
%type <ra> r_args
36
%type <i> echo_mask echo_size debug_mask debug_list debug_flag import_or_proto
37
%type <t> proto_patt
38

    
39
CF_GRAMMAR
40

    
41
/* Setting of router ID */
42

    
43
CF_ADDTO(conf, rtrid)
44

    
45
rtrid: ROUTER ID idval ';' {
46
   new_config->router_id = $3;
47
   }
48
 ;
49

    
50
idval:
51
   NUM { $$ = $1; }
52
 | RTRID
53
 | IPA {
54
#ifndef IPV6
55
     $$ = ipa_to_u32($1);
56
#else
57
     cf_error("Router IDs must be entered as hexadecimal numbers or IPv4 addresses in IPv6 version");
58
#endif
59
   }
60
 ;
61

    
62
/* Creation of routing tables */
63

    
64
CF_ADDTO(conf, newtab)
65

    
66
newtab: TABLE SYM {
67
   rt_new_table($2);
68
   }
69
 ;
70

    
71
/* Definition of protocols */
72

    
73
CF_ADDTO(conf, proto)
74

    
75
proto_start: PROTOCOL
76

    
77
proto_name:
78
   /* EMPTY */ {
79
     struct symbol *s = cf_default_name(this_proto->protocol->template, &this_proto->protocol->name_counter);
80
     s->class = SYM_PROTO;
81
     s->def = this_proto;
82
     this_proto->name = s->name;
83
     }
84
 | SYM {
85
     cf_define_symbol($1, SYM_PROTO, this_proto);
86
     this_proto->name = $1->name;
87
   }
88
 ;
89

    
90
proto_item:
91
   /* EMPTY */
92
 | PREFERENCE expr {
93
     if ($2 < 0 || $2 > 255) cf_error("Invalid preference");
94
     this_proto->preference = $2;
95
   }
96
 | DISABLED { this_proto->disabled = 1; }
97
 | DEBUG debug_mask { this_proto->debug = $2; }
98
 | IMPORT imexport { this_proto->in_filter = $2; }
99
 | EXPORT imexport { this_proto->out_filter = $2; }
100
 | TABLE rtable { this_proto->table = $2; }
101
 ;
102

    
103
imexport:
104
   FILTER filter { $$ = $2; }
105
 | where_filter
106
 | ALL { $$ = FILTER_ACCEPT; }
107
 | NONE { $$ = FILTER_REJECT; }
108
 ;
109

    
110
rtable:
111
   SYM {
112
     if ($1->class != SYM_TABLE) cf_error("Table name expected");
113
     $$ = $1->def;
114
   }
115
 ;
116

    
117
CF_ADDTO(conf, debug_default)
118

    
119
debug_default:
120
   DEBUG PROTOCOLS debug_mask { new_config->proto_default_debug = $3; }
121
 ;
122

    
123
/* Interface patterns */
124

    
125
iface_patt:
126
   TEXT { this_ipatt->pattern = $1; this_ipatt->prefix = IPA_NONE; this_ipatt->pxlen = 0; }
127
 | prefix { this_ipatt->pattern = NULL; this_ipatt->prefix = $1.addr; this_ipatt->pxlen = $1.len; }
128
 | TEXT prefix { this_ipatt->pattern = $1; this_ipatt->prefix = $2.addr; this_ipatt->pxlen = $2.len; }
129
 ;
130

    
131
/* Direct device route protocol */
132

    
133
CF_ADDTO(proto, dev_proto '}')
134

    
135
dev_proto_start: proto_start DIRECT {
136
     struct rt_dev_config *p = proto_config_new(&proto_device, sizeof(struct rt_dev_config));
137
     this_proto = &p->c;
138
     p->c.preference = DEF_PREF_DIRECT;
139
     init_list(&p->iface_list);
140
   }
141
 ;
142

    
143
dev_proto:
144
   dev_proto_start proto_name '{'
145
 | dev_proto proto_item ';'
146
 | dev_proto dev_iface_list ';'
147
 ;
148

    
149
dev_iface_entry_init:
150
   /* EMPTY */ {
151
     struct rt_dev_config *p = (void *) this_proto;
152
     struct iface_patt *k = cfg_allocz(sizeof(struct iface_patt));
153
     add_tail(&p->iface_list, &k->n);
154
     this_ipatt = k;
155
   }
156
 ;
157

    
158
dev_iface_entry:
159
   dev_iface_entry_init iface_patt
160
 ;
161

    
162
dev_iface_list:
163
   INTERFACE dev_iface_entry
164
 | dev_iface_list ',' dev_iface_entry
165
 ;
166

    
167
/* Debug flags */
168

    
169
debug_mask:
170
   ALL { $$ = ~0; }
171
 | OFF { $$ = 0; }
172
 | '{' debug_list '}' { $$ = $2; }
173
 ;
174

    
175
debug_list:
176
   debug_flag
177
 | debug_list ',' debug_flag { $$ = $1 | $3; }
178
 ;
179

    
180
debug_flag:
181
   STATES	{ $$ = D_STATES; }
182
 | ROUTES	{ $$ = D_ROUTES; }
183
 | FILTERS	{ $$ = D_FILTERS; }
184
 | INTERFACES	{ $$ = D_IFACES; }
185
 | EVENTS	{ $$ = D_EVENTS; }
186
 | PACKETS	{ $$ = D_PACKETS; }
187
 ;
188

    
189
/* Password lists */
190

    
191
password_begin: 
192
   PASSWORD TEXT {
193
     last_password_item = cfg_alloc(sizeof (struct password_item));
194
     last_password_item->password = $2;
195
     last_password_item->from = 0;
196
     last_password_item->to = TIME_INFINITY;
197
     last_password_item->id = 0;
198
     last_password_item->next = NULL;
199
     $$=last_password_item;
200
   }
201
 ;
202

    
203
password_items:
204
   /* empty */ { } 
205
 | FROM datetime password_items { last_password_item->from = $2; }
206
 | TO datetime password_items { last_password_item->to = $2; }
207
 | PASSIVE datetime password_items { last_password_item->passive = $2; }
208
 | ID expr password_items { last_password_item->id = $2; }
209
 ;
210

    
211
password_list: 
212
   /* empty */ { $$ = NULL; } 
213
 | password_begin password_items ';' password_list {
214
     $1->next = $4;
215
     $$ = $1;
216
   }
217
 ;
218

    
219
/* Core commands */
220

    
221
CF_CLI_HELP(SHOW, ..., [[Show status information]])
222

    
223
CF_CLI(SHOW STATUS,,, [[Show router status]])
224
{ cmd_show_status(); }
225

    
226
CF_CLI(SHOW PROTOCOLS, optsym, [<name>], [[Show routing protocols]])
227
{ proto_show($3, 0); } ;
228

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

    
232
optsym:
233
   SYM
234
 | /* empty */ { $$ = NULL; }
235
 ;
236

    
237
CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
238
{ if_show(); } ;
239

    
240
CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
241
{ if_show_summary(); } ;
242

    
243
CF_CLI(SHOW ROUTE, r_args, [<prefix>] [table <t>] [filter <f>] [all] [primary] [(import|protocol) <p>] [stats], [[Show routing table]])
244
{ rt_show($3); } ;
245

    
246
r_args:
247
   /* empty */ {
248
     $$ = cfg_allocz(sizeof(struct rt_show_data));
249
     $$->pxlen = 256;
250
     $$->filter = FILTER_ACCEPT;
251
     $$->table = config->master_rtc->table;
252
   }
253
 | r_args prefix {
254
     $$ = $1;
255
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
256
     $$->prefix = $2.addr;
257
     $$->pxlen = $2.len;
258
   }
259
 | r_args FOR prefix_or_ipa {
260
     $$ = $1;
261
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
262
     $$->prefix = $3.addr;
263
     $$->pxlen = $3.len;
264
     $$->show_for = 1;
265
   }
266
 | r_args TABLE SYM {
267
     $$ = $1;
268
     if ($3->class != SYM_TABLE) cf_error("%s is not a table", $3->name);
269
     $$->table = ((struct rtable_config *)$3->def)->table;
270
   }
271
 | r_args FILTER filter {
272
     $$ = $1;
273
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
274
     $$->filter = $3;
275
   }
276
 | r_args where_filter {
277
     $$ = $1;
278
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
279
     $$->filter = $2;
280
   }
281
 | r_args ALL {
282
     $$ = $1;
283
     $$->verbose = 1;
284
   }
285
 | r_args PRIMARY {
286
     $$ = $1;
287
     $$->primary_only = 1;
288
   }
289
 | r_args import_or_proto SYM {
290
     struct proto_config *c = (struct proto_config *) $3->def;
291
     $$ = $1;
292
     if ($$->import_mode) cf_error("Protocol specified twice");
293
     if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
294
     $$->import_mode = $2;
295
     $$->primary_only = 1;
296
     $$->import_protocol = c->proto;
297
     $$->running_on_config = c->proto->cf->global;
298
   }
299
 | r_args STATS {
300
     $$ = $1;
301
     $$->stats = 1;
302
   }
303
 | r_args COUNT {
304
     $$ = $1;
305
     $$->stats = 2;
306
   }
307
 ;
308

    
309
import_or_proto:
310
   IMPORT { $$ = 1; }
311
 | PROTOCOL { $$ = 2; }
312
 ;
313

    
314
CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
315
{ cmd_show_symbols($3); } ;
316

    
317
CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
318
CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
319
{ rdump(&root_pool); cli_msg(0, ""); } ;
320
CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
321
{ sk_dump_all(); cli_msg(0, ""); } ;
322
CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
323
{ if_dump_all(); cli_msg(0, ""); } ;
324
CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
325
{ neigh_dump_all(); cli_msg(0, ""); } ;
326
CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
327
{ rta_dump_all(); cli_msg(0, ""); } ;
328
CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
329
{ rt_dump_all(); cli_msg(0, ""); } ;
330
CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
331
{ protos_dump_all(); cli_msg(0, ""); } ;
332

    
333
CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
334
  cli_set_log_echo(this_cli, $2, $3);
335
  cli_msg(0, "");
336
} ;
337

    
338
echo_mask:
339
   ALL { $$ = ~0; }
340
 | OFF { $$ = 0; }
341
 | NUM
342
 ;
343

    
344
echo_size:
345
   /* empty */ { $$ = 4096; }
346
 | NUM {
347
     if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
348
     $$ = $1;
349
   }
350
 ;
351

    
352
CF_CLI(DISABLE, proto_patt, <protocol> | <pattern> | all, [[Disable protocol]])
353
{ proto_xxable($2, 0); } ;
354
CF_CLI(ENABLE, proto_patt, <protocol> | <pattern> | all, [[Enable protocol]])
355
{ proto_xxable($2, 1); } ;
356
CF_CLI(RESTART, proto_patt, <protocol> | <pattern> | all, [[Restart protocol]])
357
{ proto_xxable($2, 2); } ;
358

    
359
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging]])
360
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging]])
361
{ proto_debug($2, $3); }
362

    
363
proto_patt:
364
   SYM { $$ = $1->name; }
365
 | ALL { $$ = "*"; }
366
 | TEXT
367
 ;
368

    
369
CF_CODE
370

    
371
CF_END