]> git.ipfire.org Git - thirdparty/bird.git/blob - nest/config.Y
Implemented `show route <...> stats'.
[thirdparty/bird.git] / nest / config.Y
1 /*
2 * BIRD -- Core Configuration
3 *
4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 CF_HDR
10
11 #include "nest/rt-dev.h"
12 #include "nest/password.h"
13 #include "nest/cmds.h"
14
15 CF_DEFINES
16
17 static struct proto_config *this_proto;
18 static struct iface_patt *this_ipatt;
19
20 CF_DECLS
21
22 CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
23 CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
24 CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
25 CF_KEYWORDS(PRIMARY, STATS)
26
27 CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
28 RIP, OSPF, OSPF_EXT, OSPF_IA, OSPF_BOUNDARY, BGP, PIPE)
29
30 %type <i32> idval
31 %type <f> imexport
32 %type <r> rtable
33 %type <p> password_list password_begin
34 %type <s> optsym
35 %type <ra> r_args
36 %type <i> echo_mask echo_size debug_mask debug_list debug_flag import_or_proto
37 %type <t> proto_patt
38
39 CF_GRAMMAR
40
41 /* Setting of router ID */
42
43 CF_ADDTO(conf, rtrid)
44
45 rtrid: ROUTER ID idval ';' {
46 new_config->router_id = $3;
47 }
48 ;
49
50 idval:
51 NUM { $$ = $1; }
52 | RTRID
53 | IPA {
54 #ifndef IPV6
55 $$ = ipa_to_u32($1);
56 #else
57 cf_error("Router IDs must be entered as hexadecimal numbers in IPv6 version");
58 #endif
59 }
60 ;
61
62 /* Creation of routing tables */
63
64 CF_ADDTO(conf, newtab)
65
66 newtab: TABLE SYM {
67 rt_new_table($2);
68 }
69 ;
70
71 /* Definition of protocols */
72
73 CF_ADDTO(conf, proto)
74
75 proto_start: PROTOCOL
76
77 proto_name:
78 /* EMPTY */ {
79 struct symbol *s = cf_default_name(this_proto->protocol->template, &this_proto->protocol->name_counter);
80 s->class = SYM_PROTO;
81 s->def = this_proto;
82 this_proto->name = s->name;
83 }
84 | SYM {
85 cf_define_symbol($1, SYM_PROTO, this_proto);
86 this_proto->name = $1->name;
87 }
88 ;
89
90 proto_item:
91 /* EMPTY */
92 | PREFERENCE expr {
93 if ($2 < 0 || $2 > 255) cf_error("Invalid preference");
94 this_proto->preference = $2;
95 }
96 | DISABLED { this_proto->disabled = 1; }
97 | DEBUG debug_mask { this_proto->debug = $2; }
98 | IMPORT imexport { this_proto->in_filter = $2; }
99 | EXPORT imexport { this_proto->out_filter = $2; }
100 | TABLE rtable { this_proto->table = $2; }
101 ;
102
103 imexport:
104 FILTER filter { $$ = $2; }
105 | where_filter
106 | ALL { $$ = FILTER_ACCEPT; }
107 | NONE { $$ = FILTER_REJECT; }
108 ;
109
110 rtable:
111 SYM {
112 if ($1->class != SYM_TABLE) cf_error("Table name expected");
113 $$ = $1->def;
114 }
115 ;
116
117 CF_ADDTO(conf, debug_default)
118
119 debug_default:
120 DEBUG PROTOCOLS debug_mask { new_config->proto_default_debug = $3; }
121 ;
122
123 /* Interface patterns */
124
125 iface_patt:
126 TEXT { this_ipatt->pattern = $1; this_ipatt->prefix = IPA_NONE; this_ipatt->pxlen = 0; }
127 | IPA pxlen { this_ipatt->pattern = NULL; this_ipatt->prefix = $1; this_ipatt->pxlen = $2; }
128 | TEXT IPA pxlen { this_ipatt->pattern = $1; this_ipatt->prefix = $2; this_ipatt->pxlen = $3; }
129 ;
130
131 /* Direct device route protocol */
132
133 CF_ADDTO(proto, dev_proto '}')
134
135 dev_proto_start: proto_start DIRECT {
136 struct rt_dev_config *p = proto_config_new(&proto_device, sizeof(struct rt_dev_config));
137 this_proto = &p->c;
138 p->c.preference = DEF_PREF_DIRECT;
139 init_list(&p->iface_list);
140 }
141 ;
142
143 dev_proto:
144 dev_proto_start proto_name '{'
145 | dev_proto proto_item ';'
146 | dev_proto dev_iface_list ';'
147 ;
148
149 dev_iface_entry_init:
150 /* EMPTY */ {
151 struct rt_dev_config *p = (void *) this_proto;
152 struct iface_patt *k = cfg_allocz(sizeof(struct iface_patt));
153 add_tail(&p->iface_list, &k->n);
154 this_ipatt = k;
155 }
156 ;
157
158 dev_iface_entry:
159 dev_iface_entry_init iface_patt
160 ;
161
162 dev_iface_list:
163 INTERFACE dev_iface_entry
164 | dev_iface_list ',' dev_iface_entry
165 ;
166
167 /* Debug flags */
168
169 debug_mask:
170 ALL { $$ = ~0; }
171 | OFF { $$ = 0; }
172 | '{' debug_list '}' { $$ = $2; }
173 ;
174
175 debug_list:
176 debug_flag
177 | debug_list ',' debug_flag { $$ = $1 | $3; }
178 ;
179
180 debug_flag:
181 STATES { $$ = D_STATES; }
182 | ROUTES { $$ = D_ROUTES; }
183 | FILTERS { $$ = D_FILTERS; }
184 | INTERFACES { $$ = D_IFACES; }
185 | EVENTS { $$ = D_EVENTS; }
186 | PACKETS { $$ = D_PACKETS; }
187 ;
188
189 /* Password lists */
190
191 password_begin:
192 PASSWORD TEXT {
193 last_password_item = cfg_alloc(sizeof (struct password_item));
194 last_password_item->password = $2;
195 last_password_item->from = 0;
196 last_password_item->to = TIME_INFINITY;
197 last_password_item->id = 0;
198 last_password_item->next = NULL;
199 $$=last_password_item;
200 }
201 ;
202
203 password_items:
204 /* empty */ { }
205 | FROM datetime password_items { last_password_item->from = $2; }
206 | TO datetime password_items { last_password_item->to = $2; }
207 | PASSIVE datetime password_items { last_password_item->passive = $2; }
208 | ID NUM password_items { last_password_item->id = $2; }
209 ;
210
211 password_list:
212 /* empty */ { $$ = NULL; }
213 | password_begin password_items ';' password_list {
214 $1->next = $4;
215 $$ = $1;
216 }
217 ;
218
219 /* Core commands */
220
221 CF_CLI_HELP(SHOW, ..., [[Show status information]])
222
223 CF_CLI(SHOW STATUS,,, [[Show router status]])
224 { cmd_show_status(); }
225
226 CF_CLI(SHOW PROTOCOLS, optsym, [<name>], [[Show routing protocols]])
227 { proto_show($3, 0); } ;
228
229 CF_CLI(SHOW PROTOCOLS ALL, optsym, [<name>], [[Show routing protocol details]])
230 { proto_show($4, 1); } ;
231
232 optsym:
233 SYM
234 | /* empty */ { $$ = NULL; }
235 ;
236
237 CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
238 { if_show(); } ;
239
240 CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
241 { if_show_summary(); } ;
242
243 CF_CLI(SHOW ROUTE, r_args, [<prefix>] [table <t>] [filter <f>] [all] [primary] [(import|protocol) <p>] [stats], [[Show routing table]])
244 { rt_show($3); } ;
245
246 r_args:
247 /* empty */ {
248 $$ = cfg_allocz(sizeof(struct rt_show_data));
249 $$->pxlen = 256;
250 $$->filter = FILTER_ACCEPT;
251 $$->table = config->master_rtc->table;
252 }
253 | r_args IPA pxlen {
254 $$ = $1;
255 if ($$->pxlen != 256) cf_error("Only one prefix expected");
256 if (!ip_is_prefix($2, $3)) cf_error("Invalid prefix");
257 $$->prefix = $2;
258 $$->pxlen = $3;
259 }
260 | r_args TABLE SYM {
261 $$ = $1;
262 if ($3->class != SYM_TABLE) cf_error("%s is not a table", $3->name);
263 $$->table = ((struct rtable_config *)$3->def)->table;
264 }
265 | r_args FILTER filter {
266 $$ = $1;
267 if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
268 $$->filter = $3;
269 }
270 | r_args where_filter {
271 $$ = $1;
272 if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
273 $$->filter = $2;
274 }
275 | r_args ALL {
276 $$ = $1;
277 $$->verbose = 1;
278 }
279 | r_args PRIMARY {
280 $$ = $1;
281 $$->primary_only = 1;
282 }
283 | r_args import_or_proto SYM {
284 struct proto_config *c = (struct proto_config *) $3->def;
285 $$ = $1;
286 if ($$->import_mode) cf_error("Protocol specified twice");
287 if ($3->class != SYM_PROTO || !c->proto) cf_error("%s is not a protocol", $3->name);
288 $$->import_mode = $2;
289 $$->primary_only = 1;
290 $$->import_protocol = c->proto;
291 $$->running_on_config = c->proto->cf->global;
292 }
293 | r_args STATS {
294 $$ = $1;
295 $$->stats = 1;
296 }
297 ;
298
299 import_or_proto:
300 IMPORT { $$ = 1; }
301 | PROTOCOL { $$ = 2; }
302 ;
303
304 CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
305 { cmd_show_symbols($3); } ;
306
307 CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
308 CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
309 { rdump(&root_pool); cli_msg(0, ""); } ;
310 CF_CLI(DUMP SOCKETS,,, [[Dump open sockets]])
311 { sk_dump_all(); cli_msg(0, ""); } ;
312 CF_CLI(DUMP INTERFACES,,, [[Dump interface information]])
313 { if_dump_all(); cli_msg(0, ""); } ;
314 CF_CLI(DUMP NEIGHBORS,,, [[Dump neighbor cache]])
315 { neigh_dump_all(); cli_msg(0, ""); } ;
316 CF_CLI(DUMP ATTRIBUTES,,, [[Dump attribute cache]])
317 { rta_dump_all(); cli_msg(0, ""); } ;
318 CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
319 { rt_dump_all(); cli_msg(0, ""); } ;
320 CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
321 { protos_dump_all(); cli_msg(0, ""); } ;
322
323 CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
324 cli_set_log_echo(this_cli, $2, $3);
325 cli_msg(0, "");
326 } ;
327
328 echo_mask:
329 ALL { $$ = ~0; }
330 | OFF { $$ = 0; }
331 | NUM
332 ;
333
334 echo_size:
335 /* empty */ { $$ = 4096; }
336 | NUM {
337 if ($1 < 256 || $1 > 65536) cf_error("Invalid log buffer size");
338 $$ = $1;
339 }
340 ;
341
342 CF_CLI(DISABLE, proto_patt, <protocol> | <pattern> | all, [[Disable protocol]])
343 { proto_xxable($2, 0); } ;
344 CF_CLI(ENABLE, proto_patt, <protocol> | <pattern> | all, [[Enable protocol]])
345 { proto_xxable($2, 1); } ;
346 CF_CLI(RESTART, proto_patt, <protocol> | <pattern> | all, [[Restart protocol]])
347 { proto_xxable($2, 2); } ;
348
349 CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging]])
350 CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging]])
351 { proto_debug($2, $3); }
352
353 proto_patt:
354 SYM { $$ = $1->name; }
355 | ALL { $$ = "*"; }
356 | TEXT
357 ;
358
359 CF_CODE
360
361 CF_END