Statistics
| Branch: | Revision:

iof-bird-daemon / nest / config.Y @ 49569a8b

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

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

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

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

    
120
CF_ADDTO(conf, debug_default)
121

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

    
127
/* Interface patterns */
128

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

    
135
/* Direct device route protocol */
136

    
137
CF_ADDTO(proto, dev_proto '}')
138

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

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

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

    
162
dev_iface_entry:
163
   dev_iface_entry_init iface_patt
164
 ;
165

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

    
171
/* Debug flags */
172

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

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

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

    
193
/* Password lists */
194

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

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

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

    
223
/* Core commands */
224

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

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

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

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

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

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

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

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

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

    
313
import_or_proto:
314
   IMPORT { $$ = 1; }
315
 | PROTOCOL { $$ = 2; }
316
 ;
317

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

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

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

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

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

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

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

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

    
373
CF_CODE
374

    
375
CF_END