]> git.ipfire.org Git - thirdparty/bird.git/blob - nest/config.Y
MPLS subsystem
[thirdparty/bird.git] / nest / config.Y
1 /*
2 * BIRD -- Core Configuration
3 *
4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
5 * (c) 2004 Ondrej Filip <feela@network.cz>
6 *
7 * Can be freely distributed and used under the terms of the GNU GPL.
8 */
9
10 CF_HDR
11
12 #include "nest/rt-dev.h"
13 #include "nest/password.h"
14 #include "nest/cmds.h"
15 #include "nest/mpls.h"
16 #include "lib/lists.h"
17 #include "lib/mac.h"
18
19 CF_DEFINES
20
21 static struct rtable_config *this_table;
22 static struct proto_config *this_proto;
23 static struct channel_config *this_channel;
24 static struct iface_patt *this_ipatt;
25 static struct iface_patt_node *this_ipn;
26 /* static struct roa_table_config *this_roa_table; */
27 static list *this_p_list;
28 static struct password_item *this_p_item;
29 static int password_id;
30 static struct bfd_options *this_bfd_opts;
31
32 static void
33 iface_patt_check(void)
34 {
35 struct iface_patt_node *pn;
36
37 WALK_LIST(pn, this_ipatt->ipn_list)
38 if (!pn->pattern || pn->prefix.type)
39 cf_error("Interface name/mask expected, not IP prefix");
40 }
41
42 static inline void
43 init_password_list(void)
44 {
45 if (!this_p_list) {
46 this_p_list = cfg_allocz(sizeof(list));
47 init_list(this_p_list);
48 password_id = 1;
49 }
50 }
51
52 static inline void
53 init_password(const void *key, uint length, uint id)
54 {
55 this_p_item = cfg_allocz(sizeof (struct password_item));
56 this_p_item->password = key;
57 this_p_item->length = length;
58 this_p_item->genfrom = 0;
59 this_p_item->gento = TIME_INFINITY;
60 this_p_item->accfrom = 0;
61 this_p_item->accto = TIME_INFINITY;
62 this_p_item->id = id;
63 this_p_item->alg = ALG_UNDEFINED;
64 add_tail(this_p_list, &this_p_item->n);
65 }
66
67 static inline void
68 reset_passwords(void)
69 {
70 this_p_list = NULL;
71 }
72
73 static inline list *
74 get_passwords(void)
75 {
76 list *rv = this_p_list;
77 this_p_list = NULL;
78 return rv;
79 }
80
81 static inline void
82 init_bfd_opts(struct bfd_options **opts)
83 {
84 cf_check_bfd(1);
85
86 if (! *opts)
87 *opts = bfd_new_options();
88 }
89
90 static inline void
91 open_bfd_opts(struct bfd_options **opts)
92 {
93 init_bfd_opts(opts);
94 this_bfd_opts = *opts;
95 }
96
97 static inline void
98 close_bfd_opts(void)
99 {
100 this_bfd_opts = NULL;
101 }
102
103 static void
104 proto_postconfig(void)
105 {
106 CALL(this_proto->protocol->postconfig, this_proto);
107 this_channel = NULL;
108 this_proto = NULL;
109 }
110
111
112 #define DIRECT_CFG ((struct rt_dev_config *) this_proto)
113
114 CF_DECLS
115
116 CF_KEYWORDS(ROUTER, ID, HOSTNAME, PROTOCOL, TEMPLATE, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
117 CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, VRF, DEFAULT, TABLE, STATES, ROUTES, FILTERS)
118 CF_KEYWORDS(IPV4, IPV6, VPN4, VPN6, ROA4, ROA6, FLOW4, FLOW6, SADR, MPLS)
119 CF_KEYWORDS(RECEIVE, LIMIT, ACTION, WARN, BLOCK, RESTART, DISABLE, KEEP, FILTERED, RPKI)
120 CF_KEYWORDS(PASSWORD, KEY, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, CHANNELS, INTERFACES)
121 CF_KEYWORDS(ALGORITHM, KEYED, HMAC, MD5, SHA1, SHA256, SHA384, SHA512, BLAKE2S128, BLAKE2S256, BLAKE2B256, BLAKE2B512)
122 CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, IN, COMMANDS, PREEXPORT, NOEXPORT, EXPORTED, GENERATE)
123 CF_KEYWORDS(BGP, PASSWORDS, DESCRIPTION)
124 CF_KEYWORDS(RELOAD, IN, OUT, MRTDUMP, MESSAGES, RESTRICT, MEMORY, IGP_METRIC, CLASS, DSCP)
125 CF_KEYWORDS(TIMEFORMAT, ISO, SHORT, LONG, ROUTE, PROTOCOL, BASE, LOG, S, MS, US)
126 CF_KEYWORDS(GRACEFUL, RESTART, WAIT, MAX, AS)
127 CF_KEYWORDS(MIN, IDLE, RX, TX, INTERVAL, MULTIPLIER, PASSIVE)
128 CF_KEYWORDS(CHECK, LINK)
129 CF_KEYWORDS(SORTED, TRIE, MIN, MAX, SETTLE, TIME, GC, THRESHOLD, PERIOD)
130 CF_KEYWORDS(MPLS_LABEL, MPLS_POLICY, MPLS_CLASS)
131
132 /* For r_args_channel */
133 CF_KEYWORDS(IPV4, IPV4_MC, IPV4_MPLS, IPV6, IPV6_MC, IPV6_MPLS, IPV6_SADR, VPN4, VPN4_MC, VPN4_MPLS, VPN6, VPN6_MC, VPN6_MPLS, ROA4, ROA6, FLOW4, FLOW6, MPLS, PRI, SEC)
134
135 CF_ENUM(T_ENUM_RTS, RTS_, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
136 RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE, BABEL)
137 CF_ENUM(T_ENUM_SCOPE, SCOPE_, HOST, LINK, SITE, ORGANIZATION, UNIVERSE, UNDEFINED)
138 CF_ENUM(T_ENUM_RTD, RTD_, UNICAST, BLACKHOLE, UNREACHABLE, PROHIBIT)
139 CF_ENUM(T_ENUM_ROA, ROA_, UNKNOWN, VALID, INVALID)
140 CF_ENUM_PX(T_ENUM_AF, AF_, AFI_, IPV4, IPV6)
141 CF_ENUM(T_ENUM_MPLS_POLICY, MPLS_POLICY_, NONE, STATIC, PREFIX, AGGREGATE)
142
143 %type <i32> idval
144 %type <f> imexport
145 %type <r> rtable
146 %type <s> optproto
147 %type <ra> r_args
148 %type <sd> sym_args
149 %type <i> proto_start echo_mask echo_size debug_mask debug_list debug_flag mrtdump_mask mrtdump_list mrtdump_flag export_mode limit_action net_type net_type_base tos password_algorithm
150 %type <ps> proto_patt proto_patt2
151 %type <cc> channel_start proto_channel
152 %type <cl> limit_spec
153 %type <net> r_args_for_val
154 %type <net_ptr> r_args_for
155 %type <t> channel_sym
156 %type <c> channel_arg
157
158 CF_GRAMMAR
159
160 /* Setting of router ID */
161
162 conf: rtrid ;
163
164 rtrid:
165 ROUTER ID idval ';' { new_config->router_id = $3; }
166 | ROUTER ID FROM iface_patt ';' { new_config->router_id_from = this_ipatt; }
167 ;
168
169 idval:
170 NUM { $$ = $1; }
171 | '(' term ')' { $$ = cf_eval_int($2); }
172 | IP4 { $$ = ip4_to_u32($1); }
173 | CF_SYM_KNOWN {
174 if ($1->class == (SYM_CONSTANT | T_INT) || $1->class == (SYM_CONSTANT | T_QUAD))
175 $$ = SYM_VAL($1).i;
176 else if (($1->class == (SYM_CONSTANT | T_IP)) && ipa_is_ip4(SYM_VAL($1).ip))
177 $$ = ipa_to_u32(SYM_VAL($1).ip);
178 else
179 cf_error("Number or IPv4 address constant expected");
180 }
181 ;
182
183 conf: hostname_override ;
184
185 hostname_override: HOSTNAME text ';' { new_config->hostname = $2; } ;
186
187 conf: gr_opts ;
188
189 gr_opts: GRACEFUL RESTART WAIT expr ';' { new_config->gr_wait = $4; } ;
190
191
192 /* Network types (for tables, channels) */
193
194 net_type_base:
195 IPV4 { $$ = NET_IP4; }
196 | IPV6 { $$ = NET_IP6; }
197 | IPV6 SADR { $$ = NET_IP6_SADR; }
198 | VPN4 { $$ = NET_VPN4; }
199 | VPN6 { $$ = NET_VPN6; }
200 | ROA4 { $$ = NET_ROA4; }
201 | ROA6 { $$ = NET_ROA6; }
202 | FLOW4{ $$ = NET_FLOW4; }
203 | FLOW6{ $$ = NET_FLOW6; }
204 ;
205
206 net_type:
207 net_type_base
208 | MPLS { $$ = NET_MPLS; }
209 ;
210
211 CF_ENUM(T_ENUM_NETTYPE, NET_, IP4, IP6, VPN4, VPN6, ROA4, ROA6, FLOW4, FLOW6, IP6_SADR)
212
213
214 /* Creation of routing tables */
215
216 conf: table ;
217
218 table: table_start table_sorted table_opt_list ;
219
220 table_start: net_type TABLE symbol {
221 this_table = rt_new_table($3, $1);
222 }
223 ;
224
225 table_sorted:
226 /* empty */
227 | SORTED { this_table->sorted = 1; }
228 ;
229
230 table_opt:
231 SORTED bool { this_table->sorted = $2; }
232 | TRIE bool {
233 if (!net_val_match(this_table->addr_type, NB_IP | NB_VPN | NB_ROA | NB_IP6_SADR))
234 cf_error("Trie option not supported for %s table", net_label[this_table->addr_type]);
235 this_table->trie_used = $2;
236 }
237 | MIN SETTLE TIME expr_us { this_table->min_settle_time = $4; }
238 | MAX SETTLE TIME expr_us { this_table->max_settle_time = $4; }
239 | GC THRESHOLD expr { this_table->gc_threshold = $3; }
240 | GC PERIOD expr_us { this_table->gc_period = (uint) $3; if ($3 > 3600 S_) cf_error("GC period must be at most 3600 s"); }
241 ;
242
243 table_opts:
244 /* empty */
245 | table_opts table_opt ';'
246 ;
247
248 table_opt_list:
249 /* empty */
250 | '{' table_opts '}'
251 ;
252
253
254 /* Definition of protocols */
255
256 conf: proto { proto_postconfig(); } ;
257
258 proto_start:
259 PROTOCOL { $$ = SYM_PROTO; }
260 | TEMPLATE { $$ = SYM_TEMPLATE; }
261 ;
262
263 proto_name:
264 /* EMPTY */ {
265 struct symbol *s = cf_default_name(new_config, this_proto->protocol->template, &this_proto->protocol->name_counter);
266 s->class = this_proto->class;
267 s->proto = this_proto;
268 this_proto->name = s->name;
269 }
270 | symbol {
271 cf_define_symbol(new_config, $1, this_proto->class, proto, this_proto);
272 this_proto->name = $1->name;
273 }
274 | FROM CF_SYM_KNOWN {
275 if (($2->class != SYM_TEMPLATE) && ($2->class != SYM_PROTO)) cf_error("Template or protocol name expected");
276
277 struct symbol *s = cf_default_name(new_config, this_proto->protocol->template, &this_proto->protocol->name_counter);
278 s->class = this_proto->class;
279 s->proto = this_proto;
280 this_proto->name = s->name;
281
282 proto_copy_config(this_proto, $2->proto);
283 }
284 | symbol FROM CF_SYM_KNOWN {
285 if (($3->class != SYM_TEMPLATE) && ($3->class != SYM_PROTO)) cf_error("Template or protocol name expected");
286
287 cf_define_symbol(new_config, $1, this_proto->class, proto, this_proto);
288 this_proto->name = $1->name;
289
290 proto_copy_config(this_proto, $3->proto);
291 }
292 ;
293
294 proto_item:
295 /* EMPTY */
296 | DISABLED bool { this_proto->disabled = $2; }
297 | DEBUG debug_mask { this_proto->debug = $2; }
298 | MRTDUMP mrtdump_mask { this_proto->mrtdump = $2; }
299 | ROUTER ID idval { this_proto->router_id = $3; }
300 | DESCRIPTION text { this_proto->dsc = $2; }
301 | VRF text { this_proto->vrf = if_get_by_name($2); this_proto->vrf_set = 1; }
302 | VRF DEFAULT { this_proto->vrf = NULL; this_proto->vrf_set = 1; }
303 ;
304
305
306 channel_start: net_type_base
307 {
308 $$ = this_channel = channel_config_get(NULL, net_label[$1], $1, this_proto);
309 };
310
311 channel_item_:
312 TABLE rtable {
313 if (this_channel->net_type && ($2->addr_type != this_channel->net_type))
314 cf_error("Incompatible table type");
315 this_channel->table = $2;
316 }
317 | IMPORT imexport { this_channel->in_filter = $2; }
318 | EXPORT imexport { this_channel->out_filter = $2; }
319 | RECEIVE LIMIT limit_spec { this_channel->rx_limit = $3; }
320 | IMPORT LIMIT limit_spec { this_channel->in_limit = $3; }
321 | EXPORT LIMIT limit_spec { this_channel->out_limit = $3; }
322 | PREFERENCE expr { this_channel->preference = $2; check_u16($2); }
323 | IMPORT KEEP FILTERED bool { this_channel->in_keep_filtered = $4; }
324 | RPKI RELOAD bool { this_channel->rpki_reload = $3; }
325 ;
326
327 /* To avoid grammar collision in Pipe protocol */
328 channel_item:
329 channel_item_
330 | DEBUG debug_mask { this_channel->debug = $2; }
331 ;
332
333 channel_opts:
334 /* empty */
335 | channel_opts channel_item ';'
336 ;
337
338 channel_opt_list:
339 /* empty */
340 | '{' channel_opts '}'
341 ;
342
343 channel_end:
344 {
345 if (!this_channel->table)
346 cf_error("Routing table not specified");
347
348 this_channel = NULL;
349 };
350
351 proto_channel: channel_start channel_opt_list channel_end;
352
353
354 rtable: CF_SYM_KNOWN { cf_assert_symbol($1, SYM_TABLE); $$ = $1->table; } ;
355
356 imexport:
357 FILTER filter { $$ = $2; }
358 | where_filter
359 | ALL { $$ = FILTER_ACCEPT; }
360 | NONE { $$ = FILTER_REJECT; }
361 ;
362
363 limit_action:
364 /* default */ { $$ = PLA_DISABLE; }
365 | ACTION WARN { $$ = PLA_WARN; }
366 | ACTION BLOCK { $$ = PLA_BLOCK; }
367 | ACTION RESTART { $$ = PLA_RESTART; }
368 | ACTION DISABLE { $$ = PLA_DISABLE; }
369 ;
370
371 limit_spec:
372 expr limit_action { $$ = (struct channel_limit){ .limit = $1, $$.action = $2 }; }
373 | OFF { $$ = (struct channel_limit){}; }
374 ;
375
376
377 conf: debug_default ;
378
379 debug_default:
380 DEBUG PROTOCOLS debug_mask { new_config->proto_default_debug = $3; }
381 | DEBUG CHANNELS debug_mask { new_config->channel_default_debug = $3; }
382 | DEBUG COMMANDS expr { new_config->cli_debug = $3; }
383 ;
384
385 /* MRTDUMP PROTOCOLS is in systep/unix/config.Y */
386
387 conf: timeformat_base ;
388
389 timeformat_which:
390 ROUTE { $$ = &new_config->tf_route; }
391 | PROTOCOL { $$ = &new_config->tf_proto; }
392 | BASE { $$ = &new_config->tf_base; }
393 | LOG { $$ = &new_config->tf_log; }
394 ;
395
396 timeformat_spec:
397 timeformat_which TEXT { *$1 = (struct timeformat){$2, NULL, 0}; }
398 | timeformat_which TEXT expr TEXT { *$1 = (struct timeformat){$2, $4, (s64) $3 S_}; }
399 | timeformat_which ISO SHORT { *$1 = TM_ISO_SHORT_S; }
400 | timeformat_which ISO SHORT MS { *$1 = TM_ISO_SHORT_MS; }
401 | timeformat_which ISO SHORT US { *$1 = TM_ISO_SHORT_US; }
402 | timeformat_which ISO LONG { *$1 = TM_ISO_LONG_S; }
403 | timeformat_which ISO LONG MS { *$1 = TM_ISO_LONG_MS; }
404 | timeformat_which ISO LONG US { *$1 = TM_ISO_LONG_US; }
405 ;
406
407 timeformat_base:
408 TIMEFORMAT timeformat_spec ';'
409 ;
410
411
412 /* Interface patterns */
413
414 iface_patt_node_init:
415 /* EMPTY */ {
416 struct iface_patt_node *ipn = cfg_allocz(sizeof(struct iface_patt_node));
417 add_tail(&this_ipatt->ipn_list, NODE ipn);
418 this_ipn = ipn;
419 }
420 ;
421
422 iface_patt_node_body:
423 TEXT { this_ipn->pattern = $1; /* this_ipn->prefix stays zero */ }
424 | opttext net_or_ipa { this_ipn->pattern = $1; this_ipn->prefix = $2; }
425 ;
426
427 iface_negate:
428 { this_ipn->positive = 1; }
429 | '-' { this_ipn->positive = 0; }
430 ;
431
432 iface_patt_node:
433 iface_patt_node_init iface_negate iface_patt_node_body
434 ;
435
436
437 iface_patt_list:
438 iface_patt_node
439 | iface_patt_list ',' iface_patt_node
440 ;
441
442 /* For name/mask-only iface patterns */
443 iface_patt_list_nopx: iface_patt_list { iface_patt_check(); }
444
445 iface_patt_init: {
446 /* Generic this_ipatt init */
447 this_ipatt = cfg_allocz(sizeof(struct iface_patt));
448 init_list(&this_ipatt->ipn_list);
449 }
450 ;
451
452 iface_patt:
453 iface_patt_init iface_patt_list
454 ;
455
456 tos:
457 CLASS expr { $$ = $2 & 0xfc; if ($2 > 255) cf_error("TX class must be in range 0-255"); }
458 | DSCP expr { $$ = ($2 & 0x3f) << 2; if ($2 > 63) cf_error("TX DSCP must be in range 0-63"); }
459 ;
460
461 /* Direct device route protocol */
462
463 proto: dev_proto '}' ;
464
465 dev_proto_start: proto_start DIRECT {
466 this_proto = proto_config_new(&proto_device, $1);
467 init_list(&DIRECT_CFG->iface_list);
468 }
469 ;
470
471 dev_proto:
472 dev_proto_start proto_name '{'
473 | dev_proto proto_item ';'
474 | dev_proto proto_channel ';'
475 | dev_proto dev_iface_patt ';'
476 | dev_proto CHECK LINK bool ';' { DIRECT_CFG->check_link = $4; }
477 ;
478
479 dev_iface_init:
480 /* EMPTY */ {
481 this_ipatt = cfg_allocz(sizeof(struct iface_patt));
482 add_tail(&DIRECT_CFG->iface_list, NODE this_ipatt);
483 init_list(&this_ipatt->ipn_list);
484 }
485 ;
486
487 dev_iface_patt:
488 INTERFACE dev_iface_init iface_patt_list
489 ;
490
491 /* Debug flags */
492
493 debug_mask:
494 ALL { $$ = ~0; }
495 | OFF { $$ = 0; }
496 | '{' debug_list '}' { $$ = $2; }
497 ;
498
499 debug_list:
500 debug_flag
501 | debug_list ',' debug_flag { $$ = $1 | $3; }
502 ;
503
504 debug_flag:
505 STATES { $$ = D_STATES; }
506 | ROUTES { $$ = D_ROUTES; }
507 | FILTERS { $$ = D_FILTERS; }
508 | INTERFACES { $$ = D_IFACES; }
509 | EVENTS { $$ = D_EVENTS; }
510 | PACKETS { $$ = D_PACKETS; }
511 ;
512
513 /* MRTDump flags */
514
515 mrtdump_mask:
516 ALL { $$ = ~0; }
517 | OFF { $$ = 0; }
518 | '{' mrtdump_list '}' { $$ = $2; }
519 ;
520
521 mrtdump_list:
522 mrtdump_flag
523 | mrtdump_list ',' mrtdump_flag { $$ = $1 | $3; }
524 ;
525
526 mrtdump_flag:
527 STATES { $$ = MD_STATES; }
528 | MESSAGES { $$ = MD_MESSAGES; }
529 ;
530
531 /* Password lists */
532
533 password_list:
534 password_list_body
535 ;
536
537 password_list_body:
538 PASSWORDS '{' password_items '}'
539 | password_item
540 ;
541
542 password_items:
543 /* empty */
544 | password_item ';' password_items
545 ;
546
547 password_item:
548 password_item_begin '{' password_item_params '}' password_item_end
549 | password_item_begin password_item_end
550 ;
551
552 pass_key: PASSWORD | KEY;
553
554 password_item_begin: pass_key bytestring_text
555 {
556 init_password_list();
557 if ($2.type == T_BYTESTRING)
558 init_password($2.val.bs->data, $2.val.bs->length, password_id++);
559 else if ($2.type == T_STRING)
560 init_password($2.val.s, strlen($2.val.s), password_id++);
561 else bug("Bad bytestring_text");
562 };
563
564 password_item_params:
565 /* empty */ { }
566 | GENERATE FROM time ';' password_item_params { this_p_item->genfrom = $3; }
567 | GENERATE TO time ';' password_item_params { this_p_item->gento = $3; }
568 | ACCEPT FROM time ';' password_item_params { this_p_item->accfrom = $3; }
569 | ACCEPT TO time ';' password_item_params { this_p_item->accto = $3; }
570 | FROM time ';' password_item_params { this_p_item->genfrom = this_p_item->accfrom = $2; }
571 | TO time ';' password_item_params { this_p_item->gento = this_p_item->accto = $2; }
572 | ID expr ';' password_item_params { this_p_item->id = $2; if ($2 > 255) cf_error("Password ID must be in range 0-255"); }
573 | ALGORITHM password_algorithm ';' password_item_params { this_p_item->alg = $2; }
574 ;
575
576 password_algorithm:
577 KEYED MD5 { $$ = ALG_MD5; }
578 | KEYED SHA1 { $$ = ALG_SHA1; }
579 | KEYED SHA256 { $$ = ALG_SHA256; }
580 | KEYED SHA384 { $$ = ALG_SHA384; }
581 | KEYED SHA512 { $$ = ALG_SHA512; }
582 | HMAC MD5 { $$ = ALG_HMAC_MD5; }
583 | HMAC SHA1 { $$ = ALG_HMAC_SHA1; }
584 | HMAC SHA256 { $$ = ALG_HMAC_SHA256; }
585 | HMAC SHA384 { $$ = ALG_HMAC_SHA384; }
586 | HMAC SHA512 { $$ = ALG_HMAC_SHA512; }
587 | BLAKE2S128 { $$ = ALG_BLAKE2S_128; }
588 | BLAKE2S256 { $$ = ALG_BLAKE2S_256; }
589 | BLAKE2B256 { $$ = ALG_BLAKE2B_256; }
590 | BLAKE2B512 { $$ = ALG_BLAKE2B_512; }
591 ;
592
593 password_item_end:
594 {
595 password_validate_length(this_p_item);
596 };
597
598
599 /* BFD options */
600
601 bfd_item:
602 INTERVAL expr_us { this_bfd_opts->min_rx_int = this_bfd_opts->min_tx_int = $2; }
603 | MIN RX INTERVAL expr_us { this_bfd_opts->min_rx_int = $4; }
604 | MIN TX INTERVAL expr_us { this_bfd_opts->min_tx_int = $4; }
605 | IDLE TX INTERVAL expr_us { this_bfd_opts->idle_tx_int = $4; }
606 | MULTIPLIER expr { this_bfd_opts->multiplier = $2; }
607 | PASSIVE bool { this_bfd_opts->passive = $2; this_bfd_opts->passive_set = 1; }
608 | GRACEFUL { this_bfd_opts->mode = BGP_BFD_GRACEFUL; }
609 ;
610
611 bfd_items:
612 /* empty */
613 | bfd_items bfd_item ';'
614 ;
615
616 bfd_opts:
617 '{' bfd_items '}'
618 ;
619
620 /* Core commands */
621 CF_CLI_HELP(SHOW, ..., [[Show status information]])
622
623 CF_CLI(SHOW STATUS,,, [[Show router status]])
624 { cmd_show_status(); } ;
625
626 CF_CLI(SHOW MEMORY,,, [[Show memory usage]])
627 { cmd_show_memory(); } ;
628
629 CF_CLI(SHOW PROTOCOLS, proto_patt2, [<protocol> | \"<pattern>\"], [[Show routing protocols]])
630 { proto_apply_cmd($3, proto_cmd_show, 0, 0); } ;
631
632 CF_CLI(SHOW PROTOCOLS ALL, proto_patt2, [<protocol> | \"<pattern>\"], [[Show routing protocol details]])
633 { proto_apply_cmd($4, proto_cmd_show, 0, 1); } ;
634
635 optproto:
636 CF_SYM_KNOWN { cf_assert_symbol($1, SYM_PROTO); $$ = $1; }
637 | /* empty */ { $$ = NULL; }
638 ;
639
640 CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
641 { if_show(); } ;
642
643 CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
644 { if_show_summary(); } ;
645
646 CF_CLI_HELP(SHOW ROUTE, ..., [[Show routing table]])
647 CF_CLI(SHOW ROUTE, r_args, [[[<prefix>|for <prefix>|for <ip>|in <prefix>] [table <t>] [(import|export) table <p>.<c>] [filter <f>|where <cond>] [all] [primary] [filtered] [(export|preexport|noexport) <p>] [protocol <p>] [stats|count]]], [[Show routing table]])
648 { rt_show($3); } ;
649
650 r_args:
651 /* empty */ {
652 $$ = cfg_allocz(sizeof(struct rt_show_data));
653 init_list(&($$->tables));
654 $$->filter = FILTER_ACCEPT;
655 $$->running_on_config = config;
656 }
657 | r_args net_any {
658 $$ = $1;
659 if ($$->addr) cf_error("Only one prefix expected");
660 $$->addr = $2;
661 $$->addr_mode = RSD_ADDR_EQUAL;
662 }
663 | r_args FOR r_args_for {
664 $$ = $1;
665 if ($$->addr) cf_error("Only one prefix expected");
666 $$->addr = $3;
667 $$->addr_mode = RSD_ADDR_FOR;
668 }
669 | r_args IN net_any {
670 $$ = $1;
671 if ($$->addr) cf_error("Only one prefix expected");
672 if (!net_type_match($3, NB_IP)) cf_error("Only IP networks accepted for 'in' argument");
673 $$->addr = $3;
674 $$->addr_mode = RSD_ADDR_IN;
675 }
676 | r_args TABLE symbol_known {
677 cf_assert_symbol($3, SYM_TABLE);
678 $$ = $1;
679 rt_show_add_table($$, $3->table->table);
680 $$->tables_defined_by = RSD_TDB_DIRECT;
681 }
682 | r_args TABLE ALL {
683 struct rtable_config *t;
684 $$ = $1;
685 WALK_LIST(t, config->tables)
686 rt_show_add_table($$, t->table);
687 $$->tables_defined_by = RSD_TDB_ALL;
688 }
689 | r_args IMPORT TABLE channel_arg {
690 if (!$4->in_table) cf_error("No import table in channel %s.%s", $4->proto->name, $4->name);
691 rt_show_add_table($$, $4->in_table);
692 $$->tables_defined_by = RSD_TDB_DIRECT;
693 }
694 | r_args EXPORT TABLE channel_arg {
695 if (!$4->out_table) cf_error("No export table in channel %s.%s", $4->proto->name, $4->name);
696 rt_show_add_table($$, $4->out_table);
697 $$->tables_defined_by = RSD_TDB_DIRECT;
698 }
699 | r_args FILTER filter {
700 $$ = $1;
701 if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
702 $$->filter = $3;
703 }
704 | r_args where_filter {
705 $$ = $1;
706 if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
707 $$->filter = $2;
708 }
709 | r_args ALL {
710 $$ = $1;
711 $$->verbose = 1;
712 }
713 | r_args PRIMARY {
714 $$ = $1;
715 $$->primary_only = 1;
716 }
717 | r_args FILTERED {
718 $$ = $1;
719 $$->filtered = 1;
720 }
721 | r_args export_mode symbol_known {
722 cf_assert_symbol($3, SYM_PROTO);
723 struct proto_config *c = (struct proto_config *) $3->proto;
724 $$ = $1;
725 if ($$->export_mode) cf_error("Export specified twice");
726 if (!c->proto) cf_error("%s is not a protocol", $3->name);
727 $$->export_mode = $2;
728 $$->export_protocol = c->proto;
729 $$->tables_defined_by = RSD_TDB_INDIRECT;
730 }
731 | r_args export_mode channel_arg {
732 $$ = $1;
733 if ($$->export_mode) cf_error("Export specified twice");
734 $$->export_mode = $2;
735 $$->export_channel = $3;
736 $$->tables_defined_by = RSD_TDB_INDIRECT;
737 }
738 | r_args PROTOCOL symbol_known {
739 cf_assert_symbol($3, SYM_PROTO);
740 struct proto_config *c = (struct proto_config *) $3->proto;
741 $$ = $1;
742 if ($$->show_protocol) cf_error("Protocol specified twice");
743 if (!c->proto) cf_error("%s is not a protocol", $3->name);
744 $$->show_protocol = c->proto;
745 $$->tables_defined_by = RSD_TDB_INDIRECT;
746 }
747 | r_args STATS {
748 $$ = $1;
749 $$->stats = 1;
750 }
751 | r_args COUNT {
752 $$ = $1;
753 $$->stats = 2;
754 }
755 ;
756
757 r_args_for:
758 r_args_for_val {
759 $$ = cfg_alloc($1.length);
760 net_copy($$, &$1);
761 }
762 | net_vpn4_
763 | net_vpn6_
764 | net_ip6_sadr_
765 | VPN_RD IP4 {
766 $$ = cfg_alloc(sizeof(net_addr_vpn4));
767 net_fill_vpn4($$, $2, IP4_MAX_PREFIX_LENGTH, $1);
768 }
769 | VPN_RD IP6 {
770 $$ = cfg_alloc(sizeof(net_addr_vpn6));
771 net_fill_vpn6($$, $2, IP6_MAX_PREFIX_LENGTH, $1);
772 }
773 | IP6 FROM IP6 {
774 $$ = cfg_alloc(sizeof(net_addr_ip6_sadr));
775 net_fill_ip6_sadr($$, $1, IP6_MAX_PREFIX_LENGTH, $3, IP6_MAX_PREFIX_LENGTH);
776 }
777 | CF_SYM_KNOWN {
778 if ($1->class == (SYM_CONSTANT | T_IP))
779 {
780 $$ = cfg_alloc(ipa_is_ip4(SYM_VAL($1).ip) ? sizeof(net_addr_ip4) : sizeof(net_addr_ip6));
781 net_fill_ip_host($$, SYM_VAL($1).ip);
782 }
783 else if (($1->class == (SYM_CONSTANT | T_NET)) && net_type_match(SYM_VAL($1).net, NB_IP | NB_VPN))
784 $$ = (net_addr *) SYM_VAL($1).net; /* Avoid const warning */
785 else
786 cf_error("IP address or network constant expected");
787 }
788 ;
789
790 r_args_for_val:
791 net_ip4_
792 | net_ip6_
793 | IP4 { net_fill_ip4(&($$), $1, IP4_MAX_PREFIX_LENGTH); }
794 | IP6 { net_fill_ip6(&($$), $1, IP6_MAX_PREFIX_LENGTH); }
795
796 export_mode:
797 PREEXPORT { $$ = RSEM_PREEXPORT; }
798 | EXPORT { $$ = RSEM_EXPORT; }
799 | NOEXPORT { $$ = RSEM_NOEXPORT; }
800 | EXPORTED { $$ = RSEM_EXPORTED; }
801 ;
802
803 /* This is ugly hack */
804 channel_sym:
805 IPV4 { $$ = "ipv4"; }
806 | IPV4_MC { $$ = "ipv4-mc"; }
807 | IPV4_MPLS { $$ = "ipv4-mpls"; }
808 | IPV6 { $$ = "ipv6"; }
809 | IPV6_MC { $$ = "ipv6-mc"; }
810 | IPV6_MPLS { $$ = "ipv6-mpls"; }
811 | IPV6_SADR { $$ = "ipv6-sadr"; }
812 | VPN4 { $$ = "vpn4"; }
813 | VPN4_MC { $$ = "vpn4-mc"; }
814 | VPN4_MPLS { $$ = "vpn4-mpls"; }
815 | VPN6 { $$ = "vpn6"; }
816 | VPN6_MC { $$ = "vpn6-mc"; }
817 | VPN6_MPLS { $$ = "vpn6-mpls"; }
818 | ROA4 { $$ = "roa4"; }
819 | ROA6 { $$ = "roa6"; }
820 | FLOW4 { $$ = "flow4"; }
821 | FLOW6 { $$ = "flow6"; }
822 | MPLS { $$ = "mpls"; }
823 | PRI { $$ = "pri"; }
824 | SEC { $$ = "sec"; }
825 ;
826
827 channel_arg:
828 CF_SYM_KNOWN '.' channel_sym {
829 cf_assert_symbol($1, SYM_PROTO);
830 struct proto *p = $1->proto->proto;
831 if (!p) cf_error("%s is not a protocol", $1->name);
832 $$ = proto_find_channel_by_name(p, $3);
833 if (!$$) cf_error("Channel %s.%s not found", $1->name, $3);
834 }
835 ;
836
837 CF_CLI_HELP(SHOW SYMBOLS, ..., [[Show all known symbolic names]])
838 CF_CLI(SHOW SYMBOLS, sym_args, [table|filter|function|protocol|template|<symbol>], [[Show all known symbolic names]])
839 { cmd_show_symbols($3); } ;
840
841 sym_args:
842 /* empty */ {
843 $$ = cfg_allocz(sizeof(struct sym_show_data));
844 }
845 | sym_args TABLE { $$ = $1; $$->type = SYM_TABLE; }
846 | sym_args FUNCTION { $$ = $1; $$->type = SYM_FUNCTION; }
847 | sym_args FILTER { $$ = $1; $$->type = SYM_FILTER; }
848 | sym_args PROTOCOL { $$ = $1; $$->type = SYM_PROTO; }
849 | sym_args TEMPLATE { $$ = $1; $$->type = SYM_TEMPLATE; }
850 | sym_args CF_SYM_KNOWN { $$ = $1; $$->sym = $2; }
851 ;
852
853
854 CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
855 CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
856 { rdump(&root_pool); cli_msg(0, ""); } ;
857 CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
858 { sk_dump_all(); cli_msg(0, ""); } ;
859 CF_CLI(DUMP EVENTS,,, [[Dump event log]])
860 { io_log_dump(); cli_msg(0, ""); } ;
861 CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
862 { if_dump_all(); cli_msg(0, ""); } ;
863 CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
864 { neigh_dump_all(); cli_msg(0, ""); } ;
865 CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
866 { rta_dump_all(); cli_msg(0, ""); } ;
867 CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
868 { rt_dump_all(); cli_msg(0, ""); } ;
869 CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
870 { protos_dump_all(); cli_msg(0, ""); } ;
871 CF_CLI(DUMP FILTER ALL,,, [[Dump all filters in linearized form]])
872 { filters_dump_all(); cli_msg(0, ""); } ;
873
874 CF_CLI(EVAL, term, <expr>, [[Evaluate an expression]])
875 { cmd_eval(f_linearize($2, 1)); } ;
876
877 CF_CLI_HELP(ECHO, ..., [[Control echoing of log messages]])
878 CF_CLI(ECHO, echo_mask echo_size, (all | off | { debug|trace|info|remote|warning|error|auth [, ...] }) [<buffer-size>], [[Control echoing of log messages]]) {
879 cli_set_log_echo(this_cli, $2, $3);
880 cli_msg(0, "");
881 } ;
882
883 echo_mask:
884 ALL { $$ = ~0; }
885 | OFF { $$ = 0; }
886 | '{' log_mask_list '}' { $$ = $2; }
887 ;
888
889 echo_size:
890 /* empty */ { $$ = 4096; }
891 | NUM {
892 if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
893 $$ = $1;
894 }
895 ;
896
897 CF_CLI(DISABLE, proto_patt opttext, (<protocol> | \"<pattern>\" | all) [message], [[Disable protocol]])
898 { proto_apply_cmd($2, proto_cmd_disable, 1, (uintptr_t) $3); } ;
899 CF_CLI(ENABLE, proto_patt opttext, (<protocol> | \"<pattern>\" | all) [message], [[Enable protocol]])
900 { proto_apply_cmd($2, proto_cmd_enable, 1, (uintptr_t) $3); } ;
901 CF_CLI(RESTART, proto_patt opttext, (<protocol> | \"<pattern>\" | all) [message], [[Restart protocol]])
902 { proto_apply_cmd($2, proto_cmd_restart, 1, (uintptr_t) $3); } ;
903 CF_CLI(RELOAD, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol]])
904 { proto_apply_cmd($2, proto_cmd_reload, 1, CMD_RELOAD); } ;
905 CF_CLI(RELOAD IN, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol (just imported routes)]])
906 { proto_apply_cmd($3, proto_cmd_reload, 1, CMD_RELOAD_IN); } ;
907 CF_CLI(RELOAD OUT, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protocol (just exported routes)]])
908 { proto_apply_cmd($3, proto_cmd_reload, 1, CMD_RELOAD_OUT); } ;
909
910 CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging via BIRD logs]])
911 CF_CLI(DEBUG, debug_args, (<protocol> | <channel> | \"<pattern>\" | all) (all | off | { states|routes|filters|interfaces|events|packets [, ...] }), [[Control protocol debugging via BIRD logs]])
912 { /* Done in debug_args */ };
913
914 debug_args:
915 proto_patt debug_mask { proto_apply_cmd($1, proto_cmd_debug, 1, $2); }
916 | channel_arg debug_mask { channel_cmd_debug($1, $2); }
917 ;
918
919 CF_CLI_HELP(MRTDUMP, ..., [[Control protocol debugging via MRTdump files]])
920 CF_CLI(MRTDUMP, proto_patt mrtdump_mask, (<protocol> | \"<pattern>\" | all) (all | off | { states|messages [, ...] }), [[Control protocol debugging via MRTdump format]])
921 { proto_apply_cmd($2, proto_cmd_mrtdump, 1, $3); } ;
922
923 CF_CLI(RESTRICT,,,[[Restrict current CLI session to safe commands]])
924 { this_cli->restricted = 1; cli_msg(16, "Access restricted"); } ;
925
926 proto_patt:
927 CF_SYM_KNOWN { cf_assert_symbol($1, SYM_PROTO); $$.ptr = $1; $$.patt = 0; }
928 | ALL { $$.ptr = NULL; $$.patt = 1; }
929 | TEXT { $$.ptr = $1; $$.patt = 1; }
930 ;
931
932 proto_patt2:
933 CF_SYM_KNOWN { cf_assert_symbol($1, SYM_PROTO); $$.ptr = $1; $$.patt = 0; }
934 | { $$.ptr = NULL; $$.patt = 1; }
935 | TEXT { $$.ptr = $1; $$.patt = 1; }
936 ;
937
938 dynamic_attr: IGP_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_GEN_IGP_METRIC); } ;
939
940 dynamic_attr: MPLS_LABEL { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_MPLS_LABEL); } ;
941 dynamic_attr: MPLS_POLICY { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_ENUM_MPLS_POLICY, EA_MPLS_POLICY); } ;
942 dynamic_attr: MPLS_CLASS { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_MPLS_CLASS); } ;
943
944
945 CF_CODE
946
947 CF_END