Statistics
| Branch: | Revision:

iof-bird-daemon / nest / config.Y @ f3792601

History | View | Annotate | Download (6.6 KB)

1
/*
2
 *	BIRD -- Core Configuration
3
 *
4
 *	(c) 1998--1999 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
static struct proto_config *this_proto;
12
static struct iface_patt *this_ipatt;
13

    
14
#include "nest/rt-dev.h"
15
#include "nest/password.h"
16

    
17
CF_DECLS
18

    
19
CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
20
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE)
21
CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID)
22

    
23
CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
24
	RIP, RIP_EXT, OSPF, OSPF_EXT, OSPF_IA, OSPF_BOUNDARY, BGP, PIPE)
25

    
26
%type <i32> idval
27
%type <f> imexport
28
%type <r> rtable
29
%type <p> password_list password_begin
30
%type <s> optsym
31
%type <ra> r_args
32

    
33
CF_GRAMMAR
34

    
35
/* Setting of router ID */
36

    
37
CF_ADDTO(conf, rtrid)
38

    
39
rtrid: ROUTER ID idval ';' {
40
   new_config->router_id = $3;
41
   }
42
 ;
43

    
44
idval:
45
   NUM { $$ = $1; }
46
 | RTRID
47
 | IPA {
48
#ifndef IPV6
49
     $$ = ipa_to_u32($1);
50
#else
51
     cf_error("Router IDs must be entered as hexadecimal numbers in IPv6 version");
52
#endif
53
   }
54
 ;
55

    
56
/* Creation of routing tables */
57

    
58
CF_ADDTO(conf, newtab)
59

    
60
newtab: TABLE SYM {
61
     struct rtable_config *c = cfg_allocz(sizeof(struct rtable_config));
62
     struct symbol *s = $2;
63
     cf_define_symbol(s, SYM_TABLE, c);
64
     c->name = s->name;
65
     add_tail(&new_config->tables, &c->n);
66
   }
67
 ;
68

    
69
/* Definition of protocols */
70

    
71
CF_ADDTO(conf, proto)
72

    
73
proto_start: PROTOCOL
74

    
75
proto_name:
76
   /* EMPTY */ {
77
     struct symbol *s = cf_default_name(this_proto->protocol->name, &this_proto->protocol->name_counter);
78
     s->class = SYM_PROTO;
79
     s->def = this_proto;
80
     this_proto->name = s->name;
81
     }
82
 | SYM {
83
     cf_define_symbol($1, SYM_PROTO, this_proto);
84
     this_proto->name = $1->name;
85
   }
86
 ;
87

    
88
proto_item:
89
   /* EMPTY */
90
 | PREFERENCE expr {
91
     if ($2 < 0 || $2 > 255) cf_error("Invalid preference");
92
     this_proto->preference = $2;
93
   }
94
 | DISABLED { this_proto->disabled = 1; }
95
 | DEBUG expr { this_proto->debug = $2; }
96
 | DEBUG ALL { this_proto->debug = ~0; }
97
 | DEBUG OFF { this_proto->debug = 0; }
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
 | ALL { $$ = FILTER_ACCEPT; }
106
 | NONE { $$ = FILTER_REJECT; }
107
 ;
108

    
109
rtable:
110
   SYM {
111
     if ($1->class != SYM_TABLE) cf_error("Table name expected");
112
     $$ = $1->def;
113
   }
114
 ;
115

    
116
/* Interface patterns */
117

    
118
iface_patt:
119
   TEXT { this_ipatt->pattern = $1; this_ipatt->prefix = IPA_NONE; this_ipatt->pxlen = 0; }
120
 | IPA pxlen { this_ipatt->pattern = NULL; this_ipatt->prefix = $1; this_ipatt->pxlen = $2; }
121
 | TEXT IPA pxlen { this_ipatt->pattern = $1; this_ipatt->prefix = $2; this_ipatt->pxlen = $3; }
122
 ;
123

    
124
/* Direct device route protocol */
125

    
126
CF_ADDTO(proto, dev_proto '}')
127

    
128
dev_proto_start: proto_start DIRECT {
129
     struct rt_dev_config *p = proto_config_new(&proto_device, sizeof(struct rt_dev_config));
130
     this_proto = &p->c;
131
     p->c.preference = DEF_PREF_DIRECT;
132
     init_list(&p->iface_list);
133
   }
134
 ;
135

    
136
dev_proto:
137
   dev_proto_start proto_name '{'
138
 | dev_proto proto_item ';'
139
 | dev_proto dev_iface_list ';'
140
 ;
141

    
142
dev_iface_entry_init:
143
   /* EMPTY */ {
144
     struct rt_dev_config *p = (void *) this_proto;
145
     struct iface_patt *k = cfg_allocz(sizeof(struct iface_patt));
146
     add_tail(&p->iface_list, &k->n);
147
     this_ipatt = k;
148
   }
149
 ;
150

    
151
dev_iface_entry:
152
   dev_iface_entry_init iface_patt
153
 ;
154

    
155
dev_iface_list:
156
   INTERFACE dev_iface_entry
157
 | dev_iface_list ',' dev_iface_entry
158
 ;
159

    
160
/* Password lists */
161

    
162
password_begin: 
163
   PASSWORD TEXT {
164
     last_password_item = cfg_alloc(sizeof (struct password_item));
165
     last_password_item->password = $2;
166
     last_password_item->from = 0;
167
     last_password_item->to = TIME_INFINITY;
168
     last_password_item->id = 0;
169
     last_password_item->next = NULL;
170
     $$=last_password_item;
171
   }
172
 ;
173

    
174
password_items:
175
   /* empty */ { } 
176
 | FROM datetime password_items { last_password_item->from = $2; }
177
 | TO datetime password_items { last_password_item->to = $2; }
178
 | PASSIVE datetime password_items { last_password_item->passive = $2; }
179
 | ID NUM password_items { last_password_item->id = $2; }
180
 ;
181

    
182
password_list: 
183
   /* empty */ { $$ = NULL; } 
184
 | password_begin password_items ';' password_list {
185
     $1->next = $4;
186
     $$ = $1;
187
   }
188
 ;
189

    
190
/* Core commands */
191

    
192
CF_CLI_HELP(SHOW,,[[Show status information]])
193

    
194
CF_CLI(SHOW STATUS,,, [[Show router status]]) {
195
  cli_msg(1000, "BIRD " BIRD_VERSION);
196
  /* FIXME: Should include uptime, shutdown flag et cetera */
197
} ;
198

    
199
CF_CLI(SHOW PROTOCOLS, optsym, [<name>], [[Show routing protocols]])
200
{ proto_show($3, 0); } ;
201

    
202
CF_CLI(SHOW PROTOCOLS ALL, optsym, [<name>], [[Show routing protocol details]])
203
{ proto_show($4, 1); } ;
204

    
205
optsym:
206
   SYM
207
 | /* empty */ { $$ = NULL; }
208
 ;
209

    
210
CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
211
{ if_show(); } ;
212

    
213
CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
214
{ if_show_summary(); } ;
215

    
216
CF_CLI(SHOW ROUTE, r_args, [<prefix>] [table <t>] [filter <f>] [all], [[Show routing table]])
217
{ rt_show($3); } ;
218

    
219
r_args:
220
   /* empty */ {
221
     $$ = cfg_allocz(sizeof(struct rt_show_data));
222
     $$->pxlen = 256;
223
     $$->filter = FILTER_ACCEPT;
224
     $$->table = config->master_rtc->table;
225
   }
226
 | r_args IPA pxlen {
227
     $$ = $1;
228
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
229
     if (!ip_is_prefix($2, $3)) cf_error("Invalid prefix");
230
     $$->prefix = $2;
231
     $$->pxlen = $3;
232
   }
233
 | r_args TABLE SYM {
234
     $$ = $1;
235
     if ($3->class != SYM_TABLE) cf_error("%s is not a table", $3->name);
236
     $$->table = ((struct rtable_config *)$3->def)->table;
237
   }
238
 | r_args FILTER filter {
239
     $$ = $1;
240
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
241
     $$->filter = $3;
242
   }
243
 | r_args where_filter {
244
     $$ = $1;
245
     if ($$->filter != FILTER_ACCEPT) cf_error("Filter specified twice");
246
     $$->filter = $2;
247
   }
248
 | r_args ALL {
249
     $$ = $1;
250
     $$->verbose = 1;
251
   }
252
 ;
253

    
254
CF_CLI_HELP(DEBUG, <subsystem>, [[Show debugging information]])
255
CF_CLI(DEBUG RESOURCES,,, [[Show all allocated resource]])
256
{ rdump(&root_pool); cli_msg(0, ""); }
257
CF_CLI(DEBUG SOCKETS,,, [[Show open sockets]])
258
{ sk_dump_all(); cli_msg(0, ""); }
259
CF_CLI(DEBUG INTERFACES,,, [[Show interface information]])
260
{ if_dump_all(); cli_msg(0, ""); }
261
CF_CLI(DEBUG NEIGHBORS,,, [[Show neighbor cache]])
262
{ neigh_dump_all(); cli_msg(0, ""); }
263
CF_CLI(DEBUG ATTRIBUTES,,, [[Show attribute cache]])
264
{ rta_dump_all(); cli_msg(0, ""); }
265
CF_CLI(DEBUG ROUTES,,, [[Show routing table]])
266
{ rt_dump_all(); cli_msg(0, ""); }
267
CF_CLI(DEBUG PROTOCOLS,,, [[Show protocol information]])
268
{ protos_dump_all(); cli_msg(0, ""); }
269

    
270
CF_CODE
271

    
272
CF_END