Statistics
| Branch: | Revision:

iof-bird-daemon / nest / config.Y @ 8bf684ec

History | View | Annotate | Download (9.29 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, COMMANDS, PREIMPORT)
26

    
27
CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
28
	RIP, OSPF, OSPF_EXT, OSPF_IA, BGP, PIPE)
29
CF_ENUM(T_ENUM_SCOPE, SCOPE_, HOST, LINK, SITE, ORGANIZATION, UNIVERSE)
30
CF_ENUM(T_ENUM_RTC, RTC_, UNICAST, BROADCAST, MULTICAST, ANYCAST)
31
CF_ENUM(T_ENUM_RTD, RTD_, ROUTER, DEVICE, BLACKHOLE, UNREACHABLE, PROHIBIT)
32

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

    
42
CF_GRAMMAR
43

    
44
/* Setting of router ID */
45

    
46
CF_ADDTO(conf, rtrid)
47

    
48
rtrid: ROUTER ID idval ';' {
49
   new_config->router_id = $3;
50
   }
51
 ;
52

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

    
65
/* Creation of routing tables */
66

    
67
CF_ADDTO(conf, newtab)
68

    
69
newtab: TABLE SYM {
70
   rt_new_table($2);
71
   }
72
 ;
73

    
74
/* Definition of protocols */
75

    
76
CF_ADDTO(conf, proto)
77

    
78
proto_start: PROTOCOL
79
 ;
80

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

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

    
107
imexport:
108
   FILTER filter { $$ = $2; }
109
 | where_filter
110
 | ALL { $$ = FILTER_ACCEPT; }
111
 | NONE { $$ = FILTER_REJECT; }
112
 ;
113

    
114
rtable:
115
   SYM {
116
     if ($1->class != SYM_TABLE) cf_error("Table name expected");
117
     $$ = $1->def;
118
   }
119
 ;
120

    
121
CF_ADDTO(conf, debug_default)
122

    
123
debug_default:
124
   DEBUG PROTOCOLS debug_mask { new_config->proto_default_debug = $3; }
125
 | DEBUG COMMANDS expr { new_config->cli_debug = $3; }
126
 ;
127

    
128
/* Interface patterns */
129

    
130
iface_patt:
131
   TEXT { this_ipatt->pattern = $1; this_ipatt->prefix = IPA_NONE; this_ipatt->pxlen = 0; }
132
 | prefix { this_ipatt->pattern = NULL; this_ipatt->prefix = $1.addr; this_ipatt->pxlen = $1.len; }
133
 | TEXT prefix { this_ipatt->pattern = $1; this_ipatt->prefix = $2.addr; this_ipatt->pxlen = $2.len; }
134
 ;
135

    
136
/* Direct device route protocol */
137

    
138
CF_ADDTO(proto, dev_proto '}')
139

    
140
dev_proto_start: proto_start DIRECT {
141
     struct rt_dev_config *p = proto_config_new(&proto_device, sizeof(struct rt_dev_config));
142
     this_proto = &p->c;
143
     p->c.preference = DEF_PREF_DIRECT;
144
     init_list(&p->iface_list);
145
   }
146
 ;
147

    
148
dev_proto:
149
   dev_proto_start proto_name '{'
150
 | dev_proto proto_item ';'
151
 | dev_proto dev_iface_list ';'
152
 ;
153

    
154
dev_iface_entry_init:
155
   /* EMPTY */ {
156
     struct rt_dev_config *p = (void *) this_proto;
157
     struct iface_patt *k = cfg_allocz(sizeof(struct iface_patt));
158
     add_tail(&p->iface_list, &k->n);
159
     this_ipatt = k;
160
   }
161
 ;
162

    
163
dev_iface_entry:
164
   dev_iface_entry_init iface_patt
165
 ;
166

    
167
dev_iface_list:
168
   INTERFACE dev_iface_entry
169
 | dev_iface_list ',' dev_iface_entry
170
 ;
171

    
172
/* Debug flags */
173

    
174
debug_mask:
175
   ALL { $$ = ~0; }
176
 | OFF { $$ = 0; }
177
 | '{' debug_list '}' { $$ = $2; }
178
 ;
179

    
180
debug_list:
181
   debug_flag
182
 | debug_list ',' debug_flag { $$ = $1 | $3; }
183
 ;
184

    
185
debug_flag:
186
   STATES	{ $$ = D_STATES; }
187
 | ROUTES	{ $$ = D_ROUTES; }
188
 | FILTERS	{ $$ = D_FILTERS; }
189
 | INTERFACES	{ $$ = D_IFACES; }
190
 | EVENTS	{ $$ = D_EVENTS; }
191
 | PACKETS	{ $$ = D_PACKETS; }
192
 ;
193

    
194
/* Password lists */
195

    
196
password_begin: 
197
   PASSWORD TEXT {
198
     last_password_item = cfg_alloc(sizeof (struct password_item));
199
     last_password_item->password = $2;
200
     last_password_item->from = 0;
201
     last_password_item->to = TIME_INFINITY;
202
     last_password_item->id = 0;
203
     last_password_item->next = NULL;
204
     $$=last_password_item;
205
   }
206
 ;
207

    
208
password_items:
209
   /* empty */ { } 
210
 | FROM datetime password_items { last_password_item->from = $2; }
211
 | TO datetime password_items { last_password_item->to = $2; }
212
 | PASSIVE datetime password_items { last_password_item->passive = $2; }
213
 | ID expr password_items { last_password_item->id = $2; }
214
 ;
215

    
216
password_list: 
217
   /* empty */ { $$ = NULL; } 
218
 | password_begin password_items ';' password_list {
219
     $1->next = $4;
220
     $$ = $1;
221
   }
222
 ;
223

    
224
/* Core commands */
225

    
226
CF_CLI_HELP(SHOW, ..., [[Show status information]])
227

    
228
CF_CLI(SHOW STATUS,,, [[Show router status]])
229
{ cmd_show_status(); } ;
230

    
231
CF_CLI(SHOW PROTOCOLS, optsym, [<name>], [[Show routing protocols]])
232
{ proto_show($3, 0); } ;
233

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

    
237
optsym:
238
   SYM
239
 | /* empty */ { $$ = NULL; }
240
 ;
241

    
242
CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
243
{ if_show(); } ;
244

    
245
CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
246
{ if_show_summary(); } ;
247

    
248
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]])
249
{ rt_show($3); } ;
250

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

    
314
import_or_proto:
315
   PREIMPORT { $$ = 1; }
316
 | IMPORT { $$ = 2; }
317
 ;
318

    
319
CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
320
{ cmd_show_symbols($3); } ;
321

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

    
338
CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
339
  cli_set_log_echo(this_cli, $2, $3);
340
  cli_msg(0, "");
341
} ;
342

    
343
echo_mask:
344
   ALL { $$ = ~0; }
345
 | OFF { $$ = 0; }
346
 | NUM
347
 ;
348

    
349
echo_size:
350
   /* empty */ { $$ = 4096; }
351
 | NUM {
352
     if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
353
     $$ = $1;
354
   }
355
 ;
356

    
357
CF_CLI(DISABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Disable protocol]])
358
{ proto_xxable($2, 0); } ;
359
CF_CLI(ENABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Enable protocol]])
360
{ proto_xxable($2, 1); } ;
361
CF_CLI(RESTART, proto_patt, <protocol> | \"<pattern>\" | all, [[Restart protocol]])
362
{ proto_xxable($2, 2); } ;
363

    
364
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging]])
365
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging]])
366
{ proto_debug($2, $3); }
367
 ;
368

    
369
proto_patt:
370
   SYM { $$ = $1->name; }
371
 | ALL { $$ = "*"; }
372
 | TEXT
373
 ;
374

    
375
CF_CODE
376

    
377
CF_END