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