]> git.ipfire.org Git - thirdparty/bird.git/blame - nest/config.Y
Documentation update.
[thirdparty/bird.git] / nest / config.Y
CommitLineData
da877822
MM
1/*
2 * BIRD -- Core Configuration
3 *
4b87e256 4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
bc956fca 5 * (c) 2004 Ondrej Filip <feela@network.cz>
da877822
MM
6 *
7 * Can be freely distributed and used under the terms of the GNU GPL.
8 */
9
10CF_HDR
11
50d8424a 12#include "nest/rt-dev.h"
1a2ded45 13#include "nest/password.h"
4b87e256 14#include "nest/cmds.h"
5236fb03 15#include "lib/lists.h"
50d8424a 16
2edb31b0
MM
17CF_DEFINES
18
19static struct proto_config *this_proto;
20static struct iface_patt *this_ipatt;
20e94fb8 21static struct iface_patt_node *this_ipn;
5236fb03
OF
22static list *this_p_list;
23static struct password_item *this_p_item;
b21f68b4
OZ
24static int password_id;
25
024c310b
OZ
26static inline void
27reset_passwords(void)
28{
29 this_p_list = NULL;
30}
31
32static inline list *
b21f68b4
OZ
33get_passwords(void)
34{
35 list *rv = this_p_list;
36 this_p_list = NULL;
37 return rv;
38}
39
2edb31b0 40
da877822
MM
41CF_DECLS
42
7e5f5ffd 43CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
96d8e3bf 44CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
6a9f28b0 45CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
ea2ae6dd 46CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREEXPORT, GENERATE)
e04555c0 47CF_KEYWORDS(LISTEN, BGP, V6ONLY, ADDRESS, PORT, PASSWORDS, DESCRIPTION)
ba5e5940 48CF_KEYWORDS(RELOAD, IN, OUT, MRTDUMP, MESSAGES, RESTRICT, MEMORY, IGP_METRIC)
da877822 49
7d509304 50CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
98ac6176 51 RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE)
26c09e1d
PM
52CF_ENUM(T_ENUM_SCOPE, SCOPE_, HOST, LINK, SITE, ORGANIZATION, UNIVERSE)
53CF_ENUM(T_ENUM_RTC, RTC_, UNICAST, BROADCAST, MULTICAST, ANYCAST)
54CF_ENUM(T_ENUM_RTD, RTD_, ROUTER, DEVICE, BLACKHOLE, UNREACHABLE, PROHIBIT)
7d509304 55
dce26783 56%type <i32> idval
5056c559 57%type <f> imexport
0e02abfd 58%type <r> rtable
ae97b946 59%type <s> optsym
730f2e2c 60%type <ra> r_args
cf31112f 61%type <i> echo_mask echo_size debug_mask debug_list debug_flag mrtdump_mask mrtdump_list mrtdump_flag export_or_preexport
e304fd4b 62%type <ps> proto_patt proto_patt2
da877822
MM
63
64CF_GRAMMAR
65
c74c0e3c
MM
66/* Setting of router ID */
67
da877822 68CF_ADDTO(conf, rtrid)
0e02abfd 69
7f400d1c 70rtrid: ROUTER ID idval ';' {
31b3e1bb 71 new_config->router_id = $3;
c74c0e3c 72 }
da877822
MM
73 ;
74
75idval:
dce26783
MM
76 NUM { $$ = $1; }
77 | RTRID
78 | IPA {
79#ifndef IPV6
80 $$ = ipa_to_u32($1);
81#else
e79671a7 82 cf_error("Router IDs must be entered as hexadecimal numbers or IPv4 addresses in IPv6 version");
dce26783
MM
83#endif
84 }
da877822
MM
85 ;
86
789772ed 87
d72cdff4 88CF_ADDTO(conf, listen)
789772ed 89
d72cdff4 90listen: LISTEN BGP listen_opts ';' ;
789772ed 91
d72cdff4 92listen_opts:
789772ed 93 /* Nothing */
d72cdff4 94 | listen_opts listen_opt
789772ed
OZ
95 ;
96
d72cdff4
OZ
97listen_opt:
98 ADDRESS ipa { new_config->listen_bgp_addr = $2; }
99 | PORT expr { new_config->listen_bgp_port = $2; }
100 | V6ONLY { new_config->listen_bgp_flags |= SKF_V6ONLY; }
789772ed
OZ
101 ;
102
103
0e02abfd
MM
104/* Creation of routing tables */
105
106CF_ADDTO(conf, newtab)
107
108newtab: TABLE SYM {
b9626ec6 109 rt_new_table($2);
0e02abfd
MM
110 }
111 ;
112
c74c0e3c
MM
113/* Definition of protocols */
114
115CF_ADDTO(conf, proto)
116
117proto_start: PROTOCOL
de10a974 118 ;
c74c0e3c
MM
119
120proto_name:
121 /* EMPTY */ {
d272fe22 122 struct symbol *s = cf_default_name(this_proto->protocol->template, &this_proto->protocol->name_counter);
c74c0e3c
MM
123 s->class = SYM_PROTO;
124 s->def = this_proto;
125 this_proto->name = s->name;
126 }
127 | SYM {
0e02abfd 128 cf_define_symbol($1, SYM_PROTO, this_proto);
c74c0e3c
MM
129 this_proto->name = $1->name;
130 }
131 ;
132
133proto_item:
134 /* EMPTY */
0b62c3a7 135 | PREFERENCE expr {
f4c6ca8c 136 if ($2 < 0 || $2 > 0xFFFF) cf_error("Invalid preference");
c74c0e3c
MM
137 this_proto->preference = $2;
138 }
ca77641d 139 | DISABLED bool { this_proto->disabled = $2; }
96d8e3bf 140 | DEBUG debug_mask { this_proto->debug = $2; }
cf31112f 141 | MRTDUMP mrtdump_mask { this_proto->mrtdump = $2; }
5056c559
MM
142 | IMPORT imexport { this_proto->in_filter = $2; }
143 | EXPORT imexport { this_proto->out_filter = $2; }
0e02abfd 144 | TABLE rtable { this_proto->table = $2; }
4cdd0784 145 | ROUTER ID idval { this_proto->router_id = $3; }
3f9b7bfe 146 | DESCRIPTION TEXT { this_proto->dsc = $2; }
5056c559
MM
147 ;
148
149imexport:
150 FILTER filter { $$ = $2; }
f8809249 151 | where_filter
5056c559
MM
152 | ALL { $$ = FILTER_ACCEPT; }
153 | NONE { $$ = FILTER_REJECT; }
c74c0e3c
MM
154 ;
155
0e02abfd
MM
156rtable:
157 SYM {
158 if ($1->class != SYM_TABLE) cf_error("Table name expected");
159 $$ = $1->def;
160 }
161 ;
162
f30b86f9
MM
163CF_ADDTO(conf, debug_default)
164
165debug_default:
166 DEBUG PROTOCOLS debug_mask { new_config->proto_default_debug = $3; }
4761efdb 167 | DEBUG COMMANDS expr { new_config->cli_debug = $3; }
f30b86f9
MM
168 ;
169
cf31112f
OZ
170/* MRTDUMP PROTOCOLS is in systep/unix/config.Y */
171
8edf2361
MM
172/* Interface patterns */
173
20e94fb8
OZ
174iface_patt_node_init:
175 /* EMPTY */ {
176 struct iface_patt_node *ipn = cfg_allocz(sizeof(struct iface_patt_node));
177 add_tail(&this_ipatt->ipn_list, NODE ipn);
178 this_ipn = ipn;
179 }
180 ;
181
182iface_patt_node_body:
183 TEXT { this_ipn->pattern = $1; this_ipn->prefix = IPA_NONE; this_ipn->pxlen = 0; }
5d53b807
OZ
184 | prefix_or_ipa { this_ipn->pattern = NULL; this_ipn->prefix = $1.addr; this_ipn->pxlen = $1.len; }
185 | TEXT prefix_or_ipa { this_ipn->pattern = $1; this_ipn->prefix = $2.addr; this_ipn->pxlen = $2.len; }
20e94fb8
OZ
186 ;
187
188iface_negate:
189 { this_ipn->positive = 1; }
190 | '-' { this_ipn->positive = 0; }
191 ;
192
193iface_patt_node:
194 iface_patt_node_init iface_negate iface_patt_node_body
195 ;
196
197
198iface_patt_list:
199 iface_patt_node
200 | iface_patt_list ',' iface_patt_node
8edf2361
MM
201 ;
202
20e94fb8 203
7e5f5ffd 204/* Direct device route protocol */
50d8424a
MM
205
206CF_ADDTO(proto, dev_proto '}')
207
7e5f5ffd
MM
208dev_proto_start: proto_start DIRECT {
209 struct rt_dev_config *p = proto_config_new(&proto_device, sizeof(struct rt_dev_config));
7e5f5ffd
MM
210 this_proto = &p->c;
211 p->c.preference = DEF_PREF_DIRECT;
212 init_list(&p->iface_list);
50d8424a
MM
213 }
214 ;
215
216dev_proto:
7e5f5ffd 217 dev_proto_start proto_name '{'
50d8424a 218 | dev_proto proto_item ';'
20e94fb8 219 | dev_proto dev_iface_patt ';'
50d8424a
MM
220 ;
221
20e94fb8 222dev_iface_init:
8edf2361
MM
223 /* EMPTY */ {
224 struct rt_dev_config *p = (void *) this_proto;
20e94fb8
OZ
225 this_ipatt = cfg_allocz(sizeof(struct iface_patt));
226 add_tail(&p->iface_list, NODE this_ipatt);
227 init_list(&this_ipatt->ipn_list);
50d8424a 228 }
50d8424a
MM
229 ;
230
20e94fb8
OZ
231dev_iface_patt:
232 INTERFACE dev_iface_init iface_patt_list
8edf2361
MM
233 ;
234
96d8e3bf
MM
235/* Debug flags */
236
237debug_mask:
238 ALL { $$ = ~0; }
239 | OFF { $$ = 0; }
240 | '{' debug_list '}' { $$ = $2; }
241 ;
242
243debug_list:
244 debug_flag
245 | debug_list ',' debug_flag { $$ = $1 | $3; }
246 ;
247
248debug_flag:
249 STATES { $$ = D_STATES; }
250 | ROUTES { $$ = D_ROUTES; }
251 | FILTERS { $$ = D_FILTERS; }
6a9f28b0 252 | INTERFACES { $$ = D_IFACES; }
96d8e3bf
MM
253 | EVENTS { $$ = D_EVENTS; }
254 | PACKETS { $$ = D_PACKETS; }
255 ;
256
cf31112f
OZ
257/* MRTDump flags */
258
259mrtdump_mask:
260 ALL { $$ = ~0; }
261 | OFF { $$ = 0; }
262 | '{' mrtdump_list '}' { $$ = $2; }
263 ;
264
265mrtdump_list:
266 mrtdump_flag
267 | mrtdump_list ',' mrtdump_flag { $$ = $1 | $3; }
268 ;
269
270mrtdump_flag:
271 STATES { $$ = MD_STATES; }
272 | MESSAGES { $$ = MD_MESSAGES; }
273 ;
274
8edf2361
MM
275/* Password lists */
276
b21f68b4
OZ
277password_list:
278 PASSWORDS '{' password_items '}'
279 | password_item
280;
281
5236fb03
OF
282password_items:
283 /* empty */
284 | password_item ';' password_items
285;
286
287password_item:
288 password_item_begin '{' password_item_params '}'
289 | password_item_begin
290;
291
292password_item_begin:
1a2ded45 293 PASSWORD TEXT {
b21f68b4
OZ
294 if (!this_p_list) {
295 this_p_list = cfg_alloc(sizeof(list));
296 init_list(this_p_list);
297 password_id = 1;
298 }
5236fb03
OF
299 this_p_item = cfg_alloc(sizeof (struct password_item));
300 this_p_item->password = $2;
301 this_p_item->genfrom = 0;
302 this_p_item->gento = TIME_INFINITY;
303 this_p_item->accfrom = 0;
304 this_p_item->accto = TIME_INFINITY;
b21f68b4 305 this_p_item->id = password_id++;
5236fb03 306 add_tail(this_p_list, &this_p_item->n);
1a2ded45 307 }
5236fb03 308;
1a2ded45 309
5236fb03 310password_item_params:
1a2ded45 311 /* empty */ { }
5236fb03
OF
312 | GENERATE FROM datetime ';' password_item_params { this_p_item->genfrom = $3; }
313 | GENERATE TO datetime ';' password_item_params { this_p_item->gento = $3; }
314 | ACCEPT FROM datetime ';' password_item_params { this_p_item->accfrom = $3; }
315 | ACCEPT TO datetime ';' password_item_params { this_p_item->accto = $3; }
bc956fca 316 | ID expr ';' password_item_params { this_p_item->id = $2; if ($2 <= 0) cf_error("Password ID has to be greated than zero."); }
1a2ded45
PM
317 ;
318
1a2ded45 319
87d7fd97 320
bc2fb680 321/* Core commands */
fae0396e 322CF_CLI_HELP(SHOW, ..., [[Show status information]])
ae97b946 323
4b87e256 324CF_CLI(SHOW STATUS,,, [[Show router status]])
de10a974 325{ cmd_show_status(); } ;
ae97b946 326
acb60628
OZ
327CF_CLI(SHOW MEMORY,,, [[Show memory usage]])
328{ cmd_show_memory(); } ;
329
e304fd4b 330CF_CLI(SHOW PROTOCOLS, proto_patt2, [<protocol> | \"<pattern>\"], [[Show routing protocols]])
e0a45fb4 331{ proto_apply_cmd($3, proto_cmd_show, 0, 0); } ;
0d3e6bce 332
e304fd4b 333CF_CLI(SHOW PROTOCOLS ALL, proto_patt2, [<protocol> | \"<pattern>\"], [[Show routing protocol details]])
e0a45fb4 334{ proto_apply_cmd($4, proto_cmd_show, 0, 1); } ;
ae97b946 335
730f2e2c
MM
336optsym:
337 SYM
338 | /* empty */ { $$ = NULL; }
339 ;
340
ae97b946
MM
341CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
342{ if_show(); } ;
343
344CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
345{ if_show_summary(); } ;
346
ea2ae6dd 347CF_CLI(SHOW ROUTE, r_args, [[[<prefix>|for <prefix>|for <ip>] [table <t>] [filter <f>|where <cond>] [all] [primary] [(export|preexport) <p>] [protocol <p>] [stats|count]]], [[Show routing table]])
730f2e2c
MM
348{ rt_show($3); } ;
349
350r_args:
351 /* empty */ {
352 $$ = cfg_allocz(sizeof(struct rt_show_data));
353 $$->pxlen = 256;
354 $$->filter = FILTER_ACCEPT;
355 $$->table = config->master_rtc->table;
356 }
758458be 357 | r_args prefix {
730f2e2c
MM
358 $$ = $1;
359 if ($$->pxlen != 256) cf_error("Only one prefix expected");
758458be
MM
360 $$->prefix = $2.addr;
361 $$->pxlen = $2.len;
730f2e2c 362 }
9449c91a
MM
363 | r_args FOR prefix_or_ipa {
364 $$ = $1;
365 if ($$->pxlen != 256) cf_error("Only one prefix expected");
366 $$->prefix = $3.addr;
367 $$->pxlen = $3.len;
368 $$->show_for = 1;
369 }
730f2e2c
MM
370 | r_args TABLE SYM {
371 $$ = $1;
372 if ($3->class != SYM_TABLE) cf_error("%s is not a table", $3->name);
373 $$->table = ((struct rtable_config *)$3->def)->table;
374 }
375 | r_args FILTER filter {
376 $$ = $1;
430da60f 377 if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
730f2e2c
MM
378 $$->filter = $3;
379 }
430da60f
MM
380 | r_args where_filter {
381 $$ = $1;
382 if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
383 $$->filter = $2;
384 }
730f2e2c
MM
385 | r_args ALL {
386 $$ = $1;
387 $$->verbose = 1;
388 }
ce1da96e
MM
389 | r_args PRIMARY {
390 $$ = $1;
391 $$->primary_only = 1;
392 }
ea2ae6dd 393 | r_args export_or_preexport SYM {
ce1da96e
MM
394 struct proto_config *c = (struct proto_config *) $3->def;
395 $$ = $1;
ea2ae6dd 396 if ($$->export_mode) cf_error("Protocol specified twice");
ce1da96e 397 if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
ea2ae6dd 398 $$->export_mode = $2;
ce1da96e 399 $$->primary_only = 1;
ea2ae6dd 400 $$->export_protocol = c->proto;
ce1da96e
MM
401 $$->running_on_config = c->proto->cf->global;
402 }
4d176e14
OF
403 | r_args PROTOCOL SYM {
404 struct proto_config *c = (struct proto_config *) $3->def;
405 $$ = $1;
406 if ($$->show_protocol) cf_error("Protocol specified twice");
407 if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
408 $$->show_protocol = c->proto;
409 $$->running_on_config = c->proto->cf->global;
ce1da96e 410 }
23693958
MM
411 | r_args STATS {
412 $$ = $1;
413 $$->stats = 1;
414 }
33a368ad
MM
415 | r_args COUNT {
416 $$ = $1;
417 $$->stats = 2;
418 }
ce1da96e
MM
419 ;
420
ea2ae6dd
OZ
421export_or_preexport:
422 PREEXPORT { $$ = 1; }
423 | EXPORT { $$ = 2; }
730f2e2c
MM
424 ;
425
4b87e256
MM
426CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
427{ cmd_show_symbols($3); } ;
428
96d8e3bf
MM
429CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
430CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
34350a52 431{ rdump(&root_pool); cli_msg(0, ""); } ;
96d8e3bf 432CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
34350a52 433{ sk_dump_all(); cli_msg(0, ""); } ;
96d8e3bf 434CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
34350a52 435{ if_dump_all(); cli_msg(0, ""); } ;
96d8e3bf 436CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
34350a52 437{ neigh_dump_all(); cli_msg(0, ""); } ;
96d8e3bf 438CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
34350a52 439{ rta_dump_all(); cli_msg(0, ""); } ;
96d8e3bf 440CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
34350a52 441{ rt_dump_all(); cli_msg(0, ""); } ;
96d8e3bf 442CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
34350a52
MM
443{ protos_dump_all(); cli_msg(0, ""); } ;
444
445CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
446 cli_set_log_echo(this_cli, $2, $3);
447 cli_msg(0, "");
448} ;
449
450echo_mask:
451 ALL { $$ = ~0; }
452 | OFF { $$ = 0; }
453 | NUM
454 ;
455
456echo_size:
457 /* empty */ { $$ = 4096; }
458 | NUM {
459 if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
460 $$ = $1;
461 }
462 ;
bc2fb680 463
49569a8b 464CF_CLI(DISABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Disable protocol]])
e0a45fb4 465{ proto_apply_cmd($2, proto_cmd_disable, 1, 0); } ;
49569a8b 466CF_CLI(ENABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Enable protocol]])
e0a45fb4 467{ proto_apply_cmd($2, proto_cmd_enable, 1, 0); } ;
49569a8b 468CF_CLI(RESTART, proto_patt, <protocol> | \"<pattern>\" | all, [[Restart protocol]])
e0a45fb4 469{ proto_apply_cmd($2, proto_cmd_restart, 1, 0); } ;
bf47fe4b 470CF_CLI(RELOAD, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol]])
e0a45fb4 471{ proto_apply_cmd($2, proto_cmd_reload, 1, CMD_RELOAD); } ;
8a7fb885 472CF_CLI(RELOAD IN, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol (just imported routes)]])
e0a45fb4 473{ proto_apply_cmd($3, proto_cmd_reload, 1, CMD_RELOAD_IN); } ;
8a7fb885 474CF_CLI(RELOAD OUT, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol (just exported routes)]])
e0a45fb4 475{ proto_apply_cmd($3, proto_cmd_reload, 1, CMD_RELOAD_OUT); } ;
f14a4bec 476
cf31112f 477CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging via BIRD logs]])
353729f5 478CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | interfaces | events | packets }), [[Control protocol debugging via BIRD logs]])
e0a45fb4 479{ proto_apply_cmd($2, proto_cmd_debug, 1, $3); } ;
cf31112f
OZ
480
481CF_CLI_HELP(MRTDUMP, ..., [[Control protocol debugging via MRTdump files]])
482CF_CLI(MRTDUMP, proto_patt mrtdump_mask, (<protocol> | <pattern> | all) (all | off | { states | messages }), [[Control protocol debugging via MRTdump format]])
e0a45fb4
OZ
483{ proto_apply_cmd($2, proto_cmd_mrtdump, 1, $3); } ;
484
485CF_CLI(RESTRICT,,,[[Restrict current CLI session to safe commands]])
486{ this_cli->restricted = 1; cli_msg(16, "Access restricted"); } ;
96d8e3bf 487
f14a4bec 488proto_patt:
e304fd4b
OZ
489 SYM { $$.ptr = $1; $$.patt = 0; }
490 | ALL { $$.ptr = NULL; $$.patt = 1; }
491 | TEXT { $$.ptr = $1; $$.patt = 1; }
f14a4bec
MM
492 ;
493
e304fd4b
OZ
494proto_patt2:
495 SYM { $$.ptr = $1; $$.patt = 0; }
496 | { $$.ptr = NULL; $$.patt = 1; }
497 | TEXT { $$.ptr = $1; $$.patt = 1; }
498 ;
499
ba5e5940
OZ
500CF_ADDTO(dynamic_attr, IGP_METRIC
501 { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_GEN_IGP_METRIC); })
502
e304fd4b 503
da877822
MM
504CF_CODE
505
506CF_END