config.Y 10.1 KB
Newer Older
1
2
3
/*
 *	BIRD -- Core Configuration
 *
4
 *	(c) 1998--2000 Martin Mares <mj@ucw.cz>
5
 *      (c) 2004       Ondrej Filip <feela@network.cz>
6
7
8
9
10
11
 *
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

CF_HDR

12
#include "nest/rt-dev.h"
13
#include "nest/password.h"
14
#include "nest/cmds.h"
15
#include "lib/lists.h"
16

17
18
19
20
CF_DEFINES

static struct proto_config *this_proto;
static struct iface_patt *this_ipatt;
21
22
static list *this_p_list;
static struct password_item *this_p_item;
23
24
static int password_id;

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

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

39

40
41
CF_DECLS

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,
Ondřej Filip's avatar
Ondřej Filip committed
48
	RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE)
49
50
51
CF_ENUM(T_ENUM_SCOPE, SCOPE_, HOST, LINK, SITE, ORGANIZATION, UNIVERSE)
CF_ENUM(T_ENUM_RTC, RTC_, UNICAST, BROADCAST, MULTICAST, ANYCAST)
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
Ondrej Filip's avatar
Ondrej Filip committed
58
%type <i> echo_mask echo_size debug_mask debug_list debug_flag import_or_preimport
59
%type <t> proto_patt
60
61
62

CF_GRAMMAR

63
64
/* Setting of router ID */

65
CF_ADDTO(conf, rtrid)
66

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

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

84
85
86
87
88
/* Creation of routing tables */

CF_ADDTO(conf, newtab)

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

93
94
95
96
97
/* Definition of protocols */

CF_ADDTO(conf, proto)

proto_start: PROTOCOL
Martin Mareš's avatar
Martin Mareš committed
98
 ;
99
100
101

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

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

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

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

140
141
142
143
CF_ADDTO(conf, debug_default)

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

147
148
149
150
/* Interface patterns */

iface_patt:
   TEXT { this_ipatt->pattern = $1; this_ipatt->prefix = IPA_NONE; this_ipatt->pxlen = 0; }
Martin Mareš's avatar
Martin Mareš committed
151
152
 | prefix { this_ipatt->pattern = NULL; this_ipatt->prefix = $1.addr; this_ipatt->pxlen = $1.len; }
 | 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
158

CF_ADDTO(proto, dev_proto '}')

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

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

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

182
183
184
185
186
187
188
189
190
dev_iface_entry:
   dev_iface_entry_init iface_patt
 ;

dev_iface_list:
   INTERFACE dev_iface_entry
 | dev_iface_list ',' dev_iface_entry
 ;

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* Debug flags */

debug_mask:
   ALL { $$ = ~0; }
 | OFF { $$ = 0; }
 | '{' debug_list '}' { $$ = $2; }
 ;

debug_list:
   debug_flag
 | debug_list ',' debug_flag { $$ = $1 | $3; }
 ;

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

213
214
/* Password lists */

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

220
221
222
223
224
225
226
227
228
229
230
password_items: 
    /* empty */
  | password_item ';' password_items
;

password_item:
    password_item_begin '{' password_item_params '}'
  | password_item_begin
;

password_item_begin:
231
   PASSWORD TEXT {
232
233
234
235
236
     if (!this_p_list) {
     	this_p_list = cfg_alloc(sizeof(list));
     	init_list(this_p_list);
        password_id = 1;
     }
237
238
239
240
241
242
     this_p_item = cfg_alloc(sizeof (struct password_item));
     this_p_item->password = $2;
     this_p_item->genfrom = 0;
     this_p_item->gento = TIME_INFINITY;
     this_p_item->accfrom = 0;
     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
251
252
253
 | GENERATE FROM datetime ';' password_item_params { this_p_item->genfrom = $3; }
 | GENERATE TO datetime ';' password_item_params { this_p_item->gento = $3; }
 | ACCEPT FROM datetime ';' password_item_params { this_p_item->accfrom = $3; }
 | 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]])
Martin Mareš's avatar
Martin Mareš committed
262
{ cmd_show_status(); } ;
263
264

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

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

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

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

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

Ondrej Filip's avatar
Ondrej Filip committed
281
CF_CLI(SHOW ROUTE, r_args, [[[<prefix>|for <prefix>|for <ip>] [table <t>] [filter <f>|where <cond>] [all] [primary] [(import|preimport) <p>] [stats|count]]], [[Show routing table]])
282
283
284
285
286
287
288
289
290
{ rt_show($3); } ;

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

Ondrej Filip's avatar
Ondrej Filip committed
347
import_or_preimport:
348
349
   PREIMPORT { $$ = 1; }
 | IMPORT { $$ = 2; }
350
351
 ;

352
353
354
CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
{ cmd_show_symbols($3); } ;

355
356
CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
357
{ rdump(&root_pool); cli_msg(0, ""); } ;
358
CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
359
{ sk_dump_all(); cli_msg(0, ""); } ;
360
CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
361
{ if_dump_all(); cli_msg(0, ""); } ;
362
CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
363
{ neigh_dump_all(); cli_msg(0, ""); } ;
364
CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
365
{ rta_dump_all(); cli_msg(0, ""); } ;
366
CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
367
{ rt_dump_all(); cli_msg(0, ""); } ;
368
CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
{ protos_dump_all(); cli_msg(0, ""); } ;

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

echo_mask:
   ALL { $$ = ~0; }
 | OFF { $$ = 0; }
 | NUM
 ;

echo_size:
   /* empty */ { $$ = 4096; }
 | NUM {
     if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
     $$ = $1;
   }
 ;
389

390
CF_CLI(DISABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Disable protocol]])
391
{ proto_xxable($2, 0); } ;
392
CF_CLI(ENABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Enable protocol]])
393
{ proto_xxable($2, 1); } ;
394
CF_CLI(RESTART, proto_patt, <protocol> | \"<pattern>\" | all, [[Restart protocol]])
395
396
{ proto_xxable($2, 2); } ;

397
398
399
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging]])
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging]])
{ proto_debug($2, $3); }
Martin Mareš's avatar
Martin Mareš committed
400
 ;
401

402
403
404
405
406
407
proto_patt:
   SYM { $$ = $1->name; }
 | ALL { $$ = "*"; }
 | TEXT
 ;

408
409
410
CF_CODE

CF_END