]> git.ipfire.org Git - thirdparty/bird.git/blob - proto/ospf/config.Y
OSPF NSSA support, inter-area LSA translation.
[thirdparty/bird.git] / proto / ospf / config.Y
1 /*
2 * BIRD -- OSPF Configuration
3 *
4 * (c) 1999--2004 Ondrej Filip <feela@network.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 CF_HDR
10
11 #include "proto/ospf/ospf.h"
12
13 CF_DEFINES
14
15 #define OSPF_CFG ((struct ospf_config *) this_proto)
16 #define OSPF_PATT ((struct ospf_iface_patt *) this_ipatt)
17
18 static struct ospf_area_config *this_area;
19 static struct nbma_node *this_nbma;
20 static list *this_nets;
21 static struct area_net_config *this_pref;
22 static struct ospf_stubnet_config *this_stubnet;
23
24 #ifdef OSPFv2
25 static void
26 ospf_iface_finish(void)
27 {
28 struct ospf_iface_patt *ip = OSPF_PATT;
29
30 if (ip->deadint == 0)
31 ip->deadint = ip->deadc * ip->helloint;
32
33 ip->passwords = get_passwords();
34
35 if ((ip->autype == OSPF_AUTH_CRYPT) && (ip->helloint < 5))
36 log(L_WARN "Hello or poll interval less that 5 makes cryptographic authenication prone to replay attacks");
37
38 if ((ip->autype == OSPF_AUTH_NONE) && (ip->passwords != NULL))
39 log(L_WARN "Password option without authentication option does not make sense");
40 }
41 #endif
42
43 #ifdef OSPFv3
44 static void
45 ospf_iface_finish(void)
46 {
47 struct ospf_iface_patt *ip = OSPF_PATT;
48
49 if (ip->deadint == 0)
50 ip->deadint = ip->deadc * ip->helloint;
51
52 if ((ip->autype != OSPF_AUTH_NONE) || (get_passwords() != NULL))
53 cf_error("Authentication not supported in OSPFv3");
54 }
55 #endif
56
57 static void
58 ospf_area_finish(void)
59 {
60 if ((this_area->areaid == 0) && (this_area->type != OPT_E))
61 cf_error( "Backbone area cannot be stub/NSSA");
62 }
63
64 static void
65 ospf_proto_finish(void)
66 {
67 struct ospf_config *cf = OSPF_CFG;
68
69 if (EMPTY_LIST(cf->area_list))
70 cf_error( "No configured areas in OSPF");
71
72 int areano = 0;
73 int backbone = 0;
74 struct ospf_area_config *ac;
75 WALK_LIST(ac, cf->area_list)
76 {
77 areano++;
78 if (ac->areaid == 0)
79 backbone = 1;
80 }
81 cf->abr = areano > 1;
82
83 if (cf->abr && !backbone)
84 {
85 struct ospf_area_config *ac = cfg_allocz(sizeof(struct ospf_area_config));
86 add_head(&cf->area_list, NODE ac);
87 init_list(&ac->patt_list);
88 init_list(&ac->net_list);
89 init_list(&ac->enet_list);
90 init_list(&ac->stubnet_list);
91 }
92
93 if (!cf->abr && !EMPTY_LIST(cf->vlink_list))
94 cf_error( "Vlinks cannot be used on single area router");
95 }
96
97 CF_DECLS
98
99 CF_KEYWORDS(OSPF, AREA, OSPF_METRIC1, OSPF_METRIC2, OSPF_TAG, OSPF_ROUTER_ID)
100 CF_KEYWORDS(NEIGHBORS, RFC1583COMPAT, STUB, TICK, COST, RETRANSMIT)
101 CF_KEYWORDS(HELLO, TRANSMIT, PRIORITY, DEAD, TYPE, BROADCAST, BCAST)
102 CF_KEYWORDS(NONBROADCAST, NBMA, POINTOPOINT, PTP, POINTOMULTIPOINT, PTMP)
103 CF_KEYWORDS(NONE, SIMPLE, AUTHENTICATION, STRICT, CRYPTOGRAPHIC)
104 CF_KEYWORDS(ELIGIBLE, POLL, NETWORKS, HIDDEN, VIRTUAL, CHECK, LINK)
105 CF_KEYWORDS(RX, BUFFER, LARGE, NORMAL, STUBNET, HIDDEN, SUMMARY, TAG, EXTERNAL)
106 CF_KEYWORDS(WAIT, DELAY, LSADB, ECMP, LIMIT, WEIGHT, NSSA, TRANSLATOR, STABILITY)
107
108 %type <t> opttext
109
110 CF_GRAMMAR
111
112 CF_ADDTO(proto, ospf_proto '}' { ospf_proto_finish(); } )
113
114 ospf_proto_start: proto_start OSPF {
115 this_proto = proto_config_new(&proto_ospf, sizeof(struct ospf_config));
116 this_proto->preference = DEF_PREF_OSPF;
117 init_list(&OSPF_CFG->area_list);
118 init_list(&OSPF_CFG->vlink_list);
119 OSPF_CFG->rfc1583 = DEFAULT_RFC1583;
120 OSPF_CFG->tick = DEFAULT_OSPFTICK;
121 }
122 ;
123
124 ospf_proto:
125 ospf_proto_start proto_name '{'
126 | ospf_proto ospf_proto_item ';'
127 ;
128
129 ospf_proto_item:
130 proto_item
131 | RFC1583COMPAT bool { OSPF_CFG->rfc1583 = $2; }
132 | ECMP bool { OSPF_CFG->ecmp = $2 ? DEFAULT_ECMP_LIMIT : 0; }
133 | ECMP bool LIMIT expr { OSPF_CFG->ecmp = $2 ? $4 : 0; if ($4 < 0) cf_error("ECMP limit cannot be negative"); }
134 | TICK expr { OSPF_CFG->tick = $2; if($2<=0) cf_error("Tick must be greater than zero"); }
135 | ospf_area
136 ;
137
138 ospf_area_start: AREA idval {
139 this_area = cfg_allocz(sizeof(struct ospf_area_config));
140 add_tail(&OSPF_CFG->area_list, NODE this_area);
141 this_area->areaid = $2;
142 this_area->stub_cost = DEFAULT_STUB_COST;
143 this_area->type = OPT_E;
144 this_area->transint = DEFAULT_TRANSINT;
145
146 init_list(&this_area->patt_list);
147 init_list(&this_area->net_list);
148 init_list(&this_area->enet_list);
149 init_list(&this_area->stubnet_list);
150 }
151 ;
152
153 ospf_area: ospf_area_start '{' ospf_area_opts '}' { ospf_area_finish(); }
154 ;
155
156 ospf_area_opts:
157 /* empty */
158 | ospf_area_opts ospf_area_item ';'
159 ;
160
161 ospf_area_item:
162 STUB COST expr { this_area->stub_cost = $3 ; if($3<=0) cf_error("Stub cost must be greater than zero"); }
163 | STUB bool { this_area->type = $2 ? 0 : OPT_E; /* We should remove the option */ }
164 | NSSA { this_area->type = OPT_N; }
165 | SUMMARY bool { this_area->summary = $2; }
166 | TRANSLATOR bool { this_area->translator = $2; }
167 | TRANSLATOR STABILITY expr { this_area->transint = $3; }
168 | NETWORKS { this_nets = &this_area->net_list; } '{' pref_list '}'
169 | EXTERNAL { this_nets = &this_area->enet_list; } '{' pref_list '}'
170 | STUBNET ospf_stubnet
171 | INTERFACE ospf_iface
172 | ospf_vlink
173 ;
174
175 ospf_stubnet:
176 ospf_stubnet_start '{' ospf_stubnet_opts '}'
177 | ospf_stubnet_start
178 ;
179
180 ospf_stubnet_start:
181 prefix {
182 this_stubnet = cfg_allocz(sizeof(struct ospf_stubnet_config));
183 add_tail(&this_area->stubnet_list, NODE this_stubnet);
184 this_stubnet->px = $1;
185 this_stubnet->cost = COST_D;
186 }
187 ;
188
189 ospf_stubnet_opts:
190 /* empty */
191 | ospf_stubnet_opts ospf_stubnet_item ';'
192 ;
193
194 ospf_stubnet_item:
195 HIDDEN bool { this_stubnet->hidden = $2; }
196 | SUMMARY bool { this_stubnet->summary = $2; }
197 | COST expr { this_stubnet->cost = $2; }
198 ;
199
200 ospf_vlink:
201 ospf_vlink_start '{' ospf_vlink_opts '}' { ospf_iface_finish(); }
202 | ospf_vlink_start
203 ;
204
205 ospf_vlink_opts:
206 /* empty */
207 | ospf_vlink_opts ospf_vlink_item ';'
208 ;
209
210 ospf_vlink_item:
211 | HELLO expr { OSPF_PATT->helloint = $2 ; if (($2<=0) || ($2>65535)) cf_error("Hello interval must be in range 1-65535"); }
212 | RETRANSMIT expr { OSPF_PATT->rxmtint = $2 ; if ($2<=0) cf_error("Retransmit int must be greater than zero"); }
213 | TRANSMIT DELAY expr { OSPF_PATT->inftransdelay = $3 ; if (($3<=0) || ($3>65535)) cf_error("Transmit delay must be in range 1-65535"); }
214 | WAIT expr { OSPF_PATT->waitint = $2 ; }
215 | DEAD expr { OSPF_PATT->deadint = $2 ; if ($2<=1) cf_error("Dead interval must be greater than one"); }
216 | DEAD COUNT expr { OSPF_PATT->deadc = $3 ; if ($3<=1) cf_error("Dead count must be greater than one"); }
217 | AUTHENTICATION NONE { OSPF_PATT->autype = OSPF_AUTH_NONE ; }
218 | AUTHENTICATION SIMPLE { OSPF_PATT->autype = OSPF_AUTH_SIMPLE ; }
219 | AUTHENTICATION CRYPTOGRAPHIC { OSPF_PATT->autype = OSPF_AUTH_CRYPT ; }
220 | password_list
221 ;
222
223 ospf_vlink_start: VIRTUAL LINK idval
224 {
225 if (this_area->areaid == 0) cf_error("Virtual link cannot be in backbone");
226 this_ipatt = cfg_allocz(sizeof(struct ospf_iface_patt));
227 add_tail(&OSPF_CFG->vlink_list, NODE this_ipatt);
228 init_list(&this_ipatt->ipn_list);
229 OSPF_PATT->voa = this_area->areaid;
230 OSPF_PATT->vid = $3;
231 OSPF_PATT->helloint = HELLOINT_D;
232 OSPF_PATT->rxmtint = RXMTINT_D;
233 OSPF_PATT->inftransdelay = INFTRANSDELAY_D;
234 OSPF_PATT->waitint = WAIT_DMH*HELLOINT_D;
235 OSPF_PATT->deadc = DEADC_D;
236 OSPF_PATT->deadint = 0;
237 OSPF_PATT->type = OSPF_IT_VLINK;
238 init_list(&OSPF_PATT->nbma_list);
239 OSPF_PATT->autype = OSPF_AUTH_NONE;
240 reset_passwords();
241 }
242 ;
243
244 ospf_iface_item:
245 COST expr { OSPF_PATT->cost = $2 ; if (($2<=0) || ($2>65535)) cf_error("Cost must be in range 1-65535"); }
246 | HELLO expr { OSPF_PATT->helloint = $2 ; if (($2<=0) || ($2>65535)) cf_error("Hello interval must be in range 1-65535"); }
247 | POLL expr { OSPF_PATT->pollint = $2 ; if ($2<=0) cf_error("Poll int must be greater than zero"); }
248 | RETRANSMIT expr { OSPF_PATT->rxmtint = $2 ; if ($2<=0) cf_error("Retransmit int must be greater than zero"); }
249 | WAIT expr { OSPF_PATT->waitint = $2 ; }
250 | DEAD expr { OSPF_PATT->deadint = $2 ; if ($2<=1) cf_error("Dead interval must be greater than one"); }
251 | DEAD COUNT expr { OSPF_PATT->deadc = $3 ; if ($3<=1) cf_error("Dead count must be greater than one"); }
252 | TYPE BROADCAST { OSPF_PATT->type = OSPF_IT_BCAST ; }
253 | TYPE BCAST { OSPF_PATT->type = OSPF_IT_BCAST ; }
254 | TYPE NONBROADCAST { OSPF_PATT->type = OSPF_IT_NBMA ; }
255 | TYPE NBMA { OSPF_PATT->type = OSPF_IT_NBMA ; }
256 | TYPE POINTOPOINT { OSPF_PATT->type = OSPF_IT_PTP ; }
257 | TYPE PTP { OSPF_PATT->type = OSPF_IT_PTP ; }
258 | TYPE POINTOMULTIPOINT { OSPF_PATT->type = OSPF_IT_PTMP ; }
259 | TYPE PTMP { OSPF_PATT->type = OSPF_IT_PTMP ; }
260 | TRANSMIT DELAY expr { OSPF_PATT->inftransdelay = $3 ; if (($3<=0) || ($3>65535)) cf_error("Transmit delay must be in range 1-65535"); }
261 | PRIORITY expr { OSPF_PATT->priority = $2 ; if (($2<0) || ($2>255)) cf_error("Priority must be in range 0-255"); }
262 | STRICT NONBROADCAST bool { OSPF_PATT->strictnbma = $3 ; }
263 | STUB bool { OSPF_PATT->stub = $2 ; }
264 | CHECK LINK bool { OSPF_PATT->check_link = $3; }
265 | ECMP WEIGHT expr { OSPF_PATT->ecmp_weight = $3 - 1; if (($3<1) || ($3>256)) cf_error("ECMP weight must be in range 1-256"); }
266 | NEIGHBORS '{' ipa_list '}'
267 | AUTHENTICATION NONE { OSPF_PATT->autype = OSPF_AUTH_NONE ; }
268 | AUTHENTICATION SIMPLE { OSPF_PATT->autype = OSPF_AUTH_SIMPLE ; }
269 | AUTHENTICATION CRYPTOGRAPHIC { OSPF_PATT->autype = OSPF_AUTH_CRYPT ; }
270 | RX BUFFER LARGE { OSPF_PATT->rxbuf = OSPF_RXBUF_LARGE ; }
271 | RX BUFFER NORMAL { OSPF_PATT->rxbuf = OSPF_RXBUF_NORMAL ; }
272 | RX BUFFER expr { OSPF_PATT->rxbuf = $3 ; if (($3 < OSPF_RXBUF_MINSIZE) || ($3 > OSPF_MAX_PKT_SIZE)) cf_error("Buffer size must be in range 256-65535"); }
273 | password_list
274 ;
275
276 pref_list:
277 /* empty */
278 | pref_list pref_item
279 ;
280
281 pref_item: pref_base pref_opt ';' ;
282
283 pref_base: prefix
284 {
285 this_pref = cfg_allocz(sizeof(struct area_net_config));
286 add_tail(this_nets, NODE this_pref);
287 this_pref->px.addr = $1.addr;
288 this_pref->px.len = $1.len;
289 }
290 ;
291
292 pref_opt:
293 /* empty */
294 | HIDDEN { this_pref->hidden = 1; }
295 | TAG expr { this_pref->tag = $2; }
296 ;
297
298 ipa_list:
299 /* empty */
300 | ipa_list ipa_item
301 ;
302
303 ipa_item:
304 ipa_el
305 | ipa_ne;
306
307 ipa_el: IPA ';'
308 {
309 this_nbma = cfg_allocz(sizeof(struct nbma_node));
310 add_tail(&OSPF_PATT->nbma_list, NODE this_nbma);
311 this_nbma->ip=$1;
312 this_nbma->eligible=0;
313 }
314 ;
315
316 ipa_ne: IPA ELIGIBLE ';'
317 {
318 this_nbma = cfg_allocz(sizeof(struct nbma_node));
319 add_tail(&OSPF_PATT->nbma_list, NODE this_nbma);
320 this_nbma->ip=$1;
321 this_nbma->eligible=1;
322 }
323 ;
324
325
326 ospf_iface_start:
327 {
328 this_ipatt = cfg_allocz(sizeof(struct ospf_iface_patt));
329 add_tail(&this_area->patt_list, NODE this_ipatt);
330 init_list(&this_ipatt->ipn_list);
331 OSPF_PATT->cost = COST_D;
332 OSPF_PATT->helloint = HELLOINT_D;
333 OSPF_PATT->pollint = POLLINT_D;
334 OSPF_PATT->rxmtint = RXMTINT_D;
335 OSPF_PATT->inftransdelay = INFTRANSDELAY_D;
336 OSPF_PATT->priority = PRIORITY_D;
337 OSPF_PATT->waitint = WAIT_DMH*HELLOINT_D;
338 OSPF_PATT->deadc = DEADC_D;
339 OSPF_PATT->deadint = 0;
340 OSPF_PATT->type = OSPF_IT_UNDEF;
341 init_list(&OSPF_PATT->nbma_list);
342 OSPF_PATT->autype = OSPF_AUTH_NONE;
343 reset_passwords();
344 }
345 ;
346
347 ospf_iface_opts:
348 /* empty */
349 | ospf_iface_opts ospf_iface_item ';'
350 ;
351
352 ospf_iface_opt_list:
353 /* empty */
354 | '{' ospf_iface_opts '}'
355 ;
356
357 ospf_iface:
358 ospf_iface_start iface_patt_list ospf_iface_opt_list { ospf_iface_finish(); }
359 ;
360
361 opttext:
362 TEXT
363 | /* empty */ { $$ = NULL; }
364 ;
365
366 CF_ADDTO(dynamic_attr, OSPF_METRIC1 { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_OSPF_METRIC1); })
367 CF_ADDTO(dynamic_attr, OSPF_METRIC2 { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_OSPF_METRIC2); })
368 CF_ADDTO(dynamic_attr, OSPF_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_OSPF_TAG); })
369 CF_ADDTO(dynamic_attr, OSPF_ROUTER_ID { $$ = f_new_dynamic_attr(EAF_TYPE_ROUTER_ID | EAF_TEMP, T_QUAD, EA_OSPF_ROUTER_ID); })
370
371 CF_CLI(SHOW OSPF, optsym, [<name>], [[Show information about OSPF protocol]])
372 { ospf_sh(proto_get_named($3, &proto_ospf)); };
373
374 CF_CLI(SHOW OSPF NEIGHBORS, optsym opttext, [<name>] [\"<interface>\"], [[Show information about OSPF neighbors]])
375 { ospf_sh_neigh(proto_get_named($4, &proto_ospf), $5); };
376
377 CF_CLI(SHOW OSPF INTERFACE, optsym opttext, [<name>] [\"<interface>\"], [[Show information about interface]])
378 { ospf_sh_iface(proto_get_named($4, &proto_ospf), $5); };
379
380 CF_CLI_HELP(SHOW OSPF TOPOLOGY, [all] [<name>], [[Show information about OSPF network topology]])
381
382 CF_CLI(SHOW OSPF TOPOLOGY, optsym opttext, [<name>], [[Show information about reachable OSPF network topology]])
383 { ospf_sh_state(proto_get_named($4, &proto_ospf), 0, 1); };
384
385 CF_CLI(SHOW OSPF TOPOLOGY ALL, optsym opttext, [<name>], [[Show information about all OSPF network topology]])
386 { ospf_sh_state(proto_get_named($5, &proto_ospf), 0, 0); };
387
388 CF_CLI_HELP(SHOW OSPF STATE, [all] [<name>], [[Show information about OSPF network state]])
389
390 CF_CLI(SHOW OSPF STATE, optsym opttext, [<name>], [[Show information about reachable OSPF network state]])
391 { ospf_sh_state(proto_get_named($4, &proto_ospf), 1, 1); };
392
393 CF_CLI(SHOW OSPF STATE ALL, optsym opttext, [<name>], [[Show information about all OSPF network state]])
394 { ospf_sh_state(proto_get_named($5, &proto_ospf), 1, 0); };
395
396 CF_CLI(SHOW OSPF LSADB, optsym opttext, [<name>], [[Show content of OSPF LSA database]])
397 { ospf_sh_lsadb(proto_get_named($4, &proto_ospf)); };
398
399 CF_CODE
400
401 CF_END