2 * BIRD -- Core Configuration
4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
5 * (c) 2004 Ondrej Filip <feela@network.cz>
7 * Can be freely distributed and used under the terms of the GNU GPL.
12 #include "nest/rt-dev.h"
13 #include "nest/password.h"
14 #include "nest/cmds.h"
15 #include "lib/lists.h"
19 static struct proto_config *this_proto;
20 static struct iface_patt *this_ipatt;
21 static struct iface_patt_node *this_ipn;
22 static struct roa_table_config *this_roa_table;
23 static list *this_p_list;
24 static struct password_item *this_p_item;
25 static int password_id;
36 list *rv = this_p_list;
41 #define DIRECT_CFG ((struct rt_dev_config *) this_proto)
45 CF_KEYWORDS(ROUTER, ID, PROTOCOL, TEMPLATE, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
46 CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
47 CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
48 CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREEXPORT, GENERATE, ROA, MAX, FLUSH)
49 CF_KEYWORDS(LISTEN, BGP, V6ONLY, DUAL, ADDRESS, PORT, PASSWORDS, DESCRIPTION)
50 CF_KEYWORDS(RELOAD, IN, OUT, MRTDUMP, MESSAGES, RESTRICT, MEMORY, IGP_METRIC)
52 CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
53 RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE)
54 CF_ENUM(T_ENUM_SCOPE, SCOPE_, HOST, LINK, SITE, ORGANIZATION, UNIVERSE, UNDEFINED)
55 CF_ENUM(T_ENUM_RTC, RTC_, UNICAST, BROADCAST, MULTICAST, ANYCAST)
56 CF_ENUM(T_ENUM_RTD, RTD_, ROUTER, DEVICE, BLACKHOLE, UNREACHABLE, PROHIBIT, MULTIPATH)
57 CF_ENUM(T_ENUM_ROA, ROA_, UNKNOWN, VALID, INVALID)
65 %type <rot> roa_table_arg
67 %type <i> proto_start echo_mask echo_size debug_mask debug_list debug_flag mrtdump_mask mrtdump_list mrtdump_flag export_or_preexport roa_mode
68 %type <ps> proto_patt proto_patt2
72 /* Setting of router ID */
76 rtrid: ROUTER ID idval ';' {
77 new_config->router_id = $3;
88 cf_error("Router IDs must be entered as hexadecimal numbers or IPv4 addresses in IPv6 version");
94 CF_ADDTO(conf, listen)
96 listen: LISTEN BGP listen_opts ';' ;
100 | listen_opts listen_opt
104 ADDRESS ipa { new_config->listen_bgp_addr = $2; }
105 | PORT expr { new_config->listen_bgp_port = $2; }
106 | V6ONLY { new_config->listen_bgp_flags = 0; }
107 | DUAL { new_config->listen_bgp_flags = 1; }
111 /* Creation of routing tables */
113 CF_ADDTO(conf, newtab)
120 CF_ADDTO(conf, roa_table)
122 roa_table_start: ROA TABLE SYM {
123 this_roa_table = roa_new_table_config($3);
128 | roa_table_opts ROA prefix MAX NUM AS NUM ';' {
129 roa_add_item_config(this_roa_table, $3.addr, $3.len, $5, $7);
135 | roa_table_start '{' roa_table_opts '}'
138 /* Definition of protocols */
140 CF_ADDTO(conf, proto)
143 PROTOCOL { $$ = SYM_PROTO; }
144 | TEMPLATE { $$ = SYM_TEMPLATE; }
149 struct symbol *s = cf_default_name(this_proto->protocol->template, &this_proto->protocol->name_counter);
150 s->class = this_proto->class;
152 this_proto->name = s->name;
155 cf_define_symbol($1, this_proto->class, this_proto);
156 this_proto->name = $1->name;
159 if (($3->class != SYM_TEMPLATE) && ($3->class != SYM_PROTO)) cf_error("Template or protocol name expected");
161 cf_define_symbol($1, this_proto->class, this_proto);
162 this_proto->name = $1->name;
164 proto_copy_config(this_proto, $3->def);
171 if ($2 < 0 || $2 > 0xFFFF) cf_error("Invalid preference");
172 this_proto->preference = $2;
174 | DISABLED bool { this_proto->disabled = $2; }
175 | DEBUG debug_mask { this_proto->debug = $2; }
176 | MRTDUMP mrtdump_mask { this_proto->mrtdump = $2; }
177 | IMPORT imexport { this_proto->in_filter = $2; }
178 | EXPORT imexport { this_proto->out_filter = $2; }
179 | TABLE rtable { this_proto->table = $2; }
180 | ROUTER ID idval { this_proto->router_id = $3; }
181 | DESCRIPTION TEXT { this_proto->dsc = $2; }
185 FILTER filter { $$ = $2; }
187 | ALL { $$ = FILTER_ACCEPT; }
188 | NONE { $$ = FILTER_REJECT; }
193 if ($1->class != SYM_TABLE) cf_error("Table name expected");
198 CF_ADDTO(conf, debug_default)
201 DEBUG PROTOCOLS debug_mask { new_config->proto_default_debug = $3; }
202 | DEBUG COMMANDS expr { new_config->cli_debug = $3; }
205 /* MRTDUMP PROTOCOLS is in systep/unix/config.Y */
207 /* Interface patterns */
209 iface_patt_node_init:
211 struct iface_patt_node *ipn = cfg_allocz(sizeof(struct iface_patt_node));
212 add_tail(&this_ipatt->ipn_list, NODE ipn);
217 iface_patt_node_body:
218 TEXT { this_ipn->pattern = $1; this_ipn->prefix = IPA_NONE; this_ipn->pxlen = 0; }
219 | prefix_or_ipa { this_ipn->pattern = NULL; this_ipn->prefix = $1.addr; this_ipn->pxlen = $1.len; }
220 | TEXT prefix_or_ipa { this_ipn->pattern = $1; this_ipn->prefix = $2.addr; this_ipn->pxlen = $2.len; }
224 { this_ipn->positive = 1; }
225 | '-' { this_ipn->positive = 0; }
229 iface_patt_node_init iface_negate iface_patt_node_body
235 | iface_patt_list ',' iface_patt_node
239 /* Direct device route protocol */
241 CF_ADDTO(proto, dev_proto '}')
243 dev_proto_start: proto_start DIRECT {
244 this_proto = proto_config_new(&proto_device, sizeof(struct rt_dev_config), $1);
245 init_list(&DIRECT_CFG->iface_list);
250 dev_proto_start proto_name '{'
251 | dev_proto proto_item ';'
252 | dev_proto dev_iface_patt ';'
257 this_ipatt = cfg_allocz(sizeof(struct iface_patt));
258 add_tail(&DIRECT_CFG->iface_list, NODE this_ipatt);
259 init_list(&this_ipatt->ipn_list);
264 INTERFACE dev_iface_init iface_patt_list
272 | '{' debug_list '}' { $$ = $2; }
277 | debug_list ',' debug_flag { $$ = $1 | $3; }
281 STATES { $$ = D_STATES; }
282 | ROUTES { $$ = D_ROUTES; }
283 | FILTERS { $$ = D_FILTERS; }
284 | INTERFACES { $$ = D_IFACES; }
285 | EVENTS { $$ = D_EVENTS; }
286 | PACKETS { $$ = D_PACKETS; }
294 | '{' mrtdump_list '}' { $$ = $2; }
299 | mrtdump_list ',' mrtdump_flag { $$ = $1 | $3; }
303 STATES { $$ = MD_STATES; }
304 | MESSAGES { $$ = MD_MESSAGES; }
310 PASSWORDS '{' password_items '}'
316 | password_item ';' password_items
320 password_item_begin '{' password_item_params '}'
321 | password_item_begin
327 this_p_list = cfg_alloc(sizeof(list));
328 init_list(this_p_list);
331 this_p_item = cfg_alloc(sizeof (struct password_item));
332 this_p_item->password = $2;
333 this_p_item->genfrom = 0;
334 this_p_item->gento = TIME_INFINITY;
335 this_p_item->accfrom = 0;
336 this_p_item->accto = TIME_INFINITY;
337 this_p_item->id = password_id++;
338 add_tail(this_p_list, &this_p_item->n);
342 password_item_params:
344 | GENERATE FROM datetime ';' password_item_params { this_p_item->genfrom = $3; }
345 | GENERATE TO datetime ';' password_item_params { this_p_item->gento = $3; }
346 | ACCEPT FROM datetime ';' password_item_params { this_p_item->accfrom = $3; }
347 | ACCEPT TO datetime ';' password_item_params { this_p_item->accto = $3; }
348 | ID expr ';' password_item_params { this_p_item->id = $2; if ($2 <= 0) cf_error("Password ID has to be greated than zero."); }
354 CF_CLI_HELP(SHOW, ..., [[Show status information]])
356 CF_CLI(SHOW STATUS,,, [[Show router status]])
357 { cmd_show_status(); } ;
359 CF_CLI(SHOW MEMORY,,, [[Show memory usage]])
360 { cmd_show_memory(); } ;
362 CF_CLI(SHOW PROTOCOLS, proto_patt2, [<protocol> | \"<pattern>\"], [[Show routing protocols]])
363 { proto_apply_cmd($3, proto_cmd_show, 0, 0); } ;
365 CF_CLI(SHOW PROTOCOLS ALL, proto_patt2, [<protocol> | \"<pattern>\"], [[Show routing protocol details]])
366 { proto_apply_cmd($4, proto_cmd_show, 0, 1); } ;
370 | /* empty */ { $$ = NULL; }
373 CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
376 CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
377 { if_show_summary(); } ;
379 CF_CLI_HELP(SHOW ROUTE, ..., [[Show routing table]])
380 CF_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]])
385 $$ = cfg_allocz(sizeof(struct rt_show_data));
387 $$->filter = FILTER_ACCEPT;
388 $$->table = config->master_rtc->table;
392 if ($$->pxlen != 256) cf_error("Only one prefix expected");
393 $$->prefix = $2.addr;
396 | r_args FOR prefix_or_ipa {
398 if ($$->pxlen != 256) cf_error("Only one prefix expected");
399 $$->prefix = $3.addr;
405 if ($3->class != SYM_TABLE) cf_error("%s is not a table", $3->name);
406 $$->table = ((struct rtable_config *)$3->def)->table;
408 | r_args FILTER filter {
410 if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
413 | r_args where_filter {
415 if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
424 $$->primary_only = 1;
426 | r_args export_or_preexport SYM {
427 struct proto_config *c = (struct proto_config *) $3->def;
429 if ($$->export_mode) cf_error("Protocol specified twice");
430 if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
431 $$->export_mode = $2;
432 $$->primary_only = 1;
433 $$->export_protocol = c->proto;
434 $$->running_on_config = c->proto->cf->global;
436 | r_args PROTOCOL SYM {
437 struct proto_config *c = (struct proto_config *) $3->def;
439 if ($$->show_protocol) cf_error("Protocol specified twice");
440 if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
441 $$->show_protocol = c->proto;
442 $$->running_on_config = c->proto->cf->global;
455 PREEXPORT { $$ = 1; }
460 CF_CLI_HELP(SHOW ROA, ..., [[Show ROA table]])
461 CF_CLI(SHOW ROA, roa_args, [<prefix> | in <prefix> | for <prefix>] [as <num>] [table <t>], [[Show ROA table]])
466 $$ = cfg_allocz(sizeof(struct roa_show_data));
467 $$->mode = ROA_SHOW_ALL;
468 $$->table = roa_table_default;
469 if (roa_table_default == NULL)
470 cf_error("No ROA table defined");
472 | roa_args roa_mode prefix {
474 if ($$->mode != ROA_SHOW_ALL) cf_error("Only one prefix expected");
475 $$->prefix = $3.addr;
483 | roa_args TABLE SYM {
485 if ($3->class != SYM_ROA) cf_error("%s is not a ROA table", $3->name);
486 $$->table = ((struct roa_table_config *)$3->def)->table;
491 { $$ = ROA_SHOW_PX; }
492 | IN { $$ = ROA_SHOW_IN; }
493 | FOR { $$ = ROA_SHOW_FOR; }
497 CF_CLI_HELP(SHOW SYMBOLS, ..., [[Show all known symbolic names]])
498 CF_CLI(SHOW SYMBOLS, sym_args, [table|filter|function|protocol|template|roa|<symbol>], [[Show all known symbolic names]])
499 { cmd_show_symbols($3); } ;
503 $$ = cfg_allocz(sizeof(struct sym_show_data));
505 | sym_args TABLE { $$ = $1; $$->type = SYM_TABLE; }
506 | sym_args FUNCTION { $$ = $1; $$->type = SYM_FUNCTION; }
507 | sym_args FILTER { $$ = $1; $$->type = SYM_FILTER; }
508 | sym_args PROTOCOL { $$ = $1; $$->type = SYM_PROTO; }
509 | sym_args TEMPLATE { $$ = $1; $$->type = SYM_TEMPLATE; }
510 | sym_args ROA { $$ = $1; $$->type = SYM_ROA; }
511 | sym_args SYM { $$ = $1; $$->sym = $2; }
517 if (roa_table_default == NULL)
518 cf_error("No ROA table defined");
519 $$ = roa_table_default;
522 if ($2->class != SYM_ROA)
523 cf_error("%s is not a ROA table", $2->name);
524 $$ = ((struct roa_table_config *)$2->def)->table;
528 CF_CLI_HELP(ADD, roa ..., [[Add ROA record]])
529 CF_CLI(ADD ROA, prefix MAX NUM AS NUM roa_table_arg, <prefix> max <num> as <num> [table <name>], [[Add ROA record]])
531 if (! cli_access_restricted())
532 { roa_add_item($8, $3.addr, $3.len, $5, $7, ROA_SRC_DYNAMIC); cli_msg(0, ""); }
535 CF_CLI_HELP(DELETE, roa ..., [[Delete ROA record]])
536 CF_CLI(DELETE ROA, prefix MAX NUM AS NUM roa_table_arg, <prefix> max <num> as <num> [table <name>], [[Delete ROA record]])
538 if (! cli_access_restricted())
539 { roa_delete_item($8, $3.addr, $3.len, $5, $7, ROA_SRC_DYNAMIC); cli_msg(0, ""); }
542 CF_CLI_HELP(FLUSH, roa [table <name>], [[Removes all dynamic ROA records]])
543 CF_CLI(FLUSH ROA, roa_table_arg, [table <name>], [[Removes all dynamic ROA records]])
545 if (! cli_access_restricted())
546 { roa_flush($3, ROA_SRC_DYNAMIC); cli_msg(0, ""); }
550 CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
551 CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
552 { rdump(&root_pool); cli_msg(0, ""); } ;
553 CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
554 { sk_dump_all(); cli_msg(0, ""); } ;
555 CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
556 { if_dump_all(); cli_msg(0, ""); } ;
557 CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
558 { neigh_dump_all(); cli_msg(0, ""); } ;
559 CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
560 { rta_dump_all(); cli_msg(0, ""); } ;
561 CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
562 { rt_dump_all(); cli_msg(0, ""); } ;
563 CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
564 { protos_dump_all(); cli_msg(0, ""); } ;
566 CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
567 cli_set_log_echo(this_cli, $2, $3);
578 /* empty */ { $$ = 4096; }
580 if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
585 CF_CLI(DISABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Disable protocol]])
586 { proto_apply_cmd($2, proto_cmd_disable, 1, 0); } ;
587 CF_CLI(ENABLE, proto_patt, <protocol> | \"<pattern>\" | all, [[Enable protocol]])
588 { proto_apply_cmd($2, proto_cmd_enable, 1, 0); } ;
589 CF_CLI(RESTART, proto_patt, <protocol> | \"<pattern>\" | all, [[Restart protocol]])
590 { proto_apply_cmd($2, proto_cmd_restart, 1, 0); } ;
591 CF_CLI(RELOAD, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol]])
592 { proto_apply_cmd($2, proto_cmd_reload, 1, CMD_RELOAD); } ;
593 CF_CLI(RELOAD IN, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol (just imported routes)]])
594 { proto_apply_cmd($3, proto_cmd_reload, 1, CMD_RELOAD_IN); } ;
595 CF_CLI(RELOAD OUT, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol (just exported routes)]])
596 { proto_apply_cmd($3, proto_cmd_reload, 1, CMD_RELOAD_OUT); } ;
598 CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging via BIRD logs]])
599 CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | interfaces | events | packets }), [[Control protocol debugging via BIRD logs]])
600 { proto_apply_cmd($2, proto_cmd_debug, 1, $3); } ;
602 CF_CLI_HELP(MRTDUMP, ..., [[Control protocol debugging via MRTdump files]])
603 CF_CLI(MRTDUMP, proto_patt mrtdump_mask, (<protocol> | <pattern> | all) (all | off | { states | messages }), [[Control protocol debugging via MRTdump format]])
604 { proto_apply_cmd($2, proto_cmd_mrtdump, 1, $3); } ;
606 CF_CLI(RESTRICT,,,[[Restrict current CLI session to safe commands]])
607 { this_cli->restricted = 1; cli_msg(16, "Access restricted"); } ;
610 SYM { $$.ptr = $1; $$.patt = 0; }
611 | ALL { $$.ptr = NULL; $$.patt = 1; }
612 | TEXT { $$.ptr = $1; $$.patt = 1; }
616 SYM { $$.ptr = $1; $$.patt = 0; }
617 | { $$.ptr = NULL; $$.patt = 1; }
618 | TEXT { $$.ptr = $1; $$.patt = 1; }
621 CF_ADDTO(dynamic_attr, IGP_METRIC
622 { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_GEN_IGP_METRIC); })