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