2 * BIRD -- OSPF Configuration
4 * (c) 1999--2004 Ondrej Filip <feela@network.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
11 #include "proto/ospf/ospf.h"
15 #define OSPF_CFG ((struct ospf_config *) this_proto)
16 #define OSPF_PATT ((struct ospf_iface_patt *) this_ipatt)
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;
26 ospf_iface_finish(void)
28 struct ospf_iface_patt *ip = OSPF_PATT;
31 ip->deadint = ip->deadc * ip->helloint;
33 ip->passwords = get_passwords();
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");
38 if ((ip->autype == OSPF_AUTH_NONE) && (ip->passwords != NULL))
39 log(L_WARN "Password option without authentication option does not make sense");
45 ospf_iface_finish(void)
47 struct ospf_iface_patt *ip = OSPF_PATT;
50 ip->deadint = ip->deadc * ip->helloint;
52 if ((ip->autype != OSPF_AUTH_NONE) || (get_passwords() != NULL))
53 cf_error("Authentication not supported in OSPFv3");
58 ospf_area_finish(void)
60 if ((this_area->areaid == 0) && (this_area->type != OPT_E))
61 cf_error( "Backbone area cannot be stub/NSSA");
65 ospf_proto_finish(void)
67 struct ospf_config *cf = OSPF_CFG;
69 if (EMPTY_LIST(cf->area_list))
70 cf_error( "No configured areas in OSPF");
74 struct ospf_area_config *ac;
75 WALK_LIST(ac, cf->area_list)
83 if (cf->abr && !backbone)
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);
93 if (!cf->abr && !EMPTY_LIST(cf->vlink_list))
94 cf_error( "Vlinks cannot be used on single area router");
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)
112 CF_ADDTO(proto, ospf_proto '}' { ospf_proto_finish(); } )
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;
125 ospf_proto_start proto_name '{'
126 | ospf_proto ospf_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"); }
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;
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);
153 ospf_area: ospf_area_start '{' ospf_area_opts '}' { ospf_area_finish(); }
158 | ospf_area_opts 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
176 ospf_stubnet_start '{' ospf_stubnet_opts '}'
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;
191 | ospf_stubnet_opts ospf_stubnet_item ';'
195 HIDDEN bool { this_stubnet->hidden = $2; }
196 | SUMMARY bool { this_stubnet->summary = $2; }
197 | COST expr { this_stubnet->cost = $2; }
201 ospf_vlink_start '{' ospf_vlink_opts '}' { ospf_iface_finish(); }
207 | ospf_vlink_opts 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 ; }
223 ospf_vlink_start: VIRTUAL LINK idval
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;
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;
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"); }
278 | pref_list pref_item
281 pref_item: pref_base pref_opt ';' ;
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;
294 | HIDDEN { this_pref->hidden = 1; }
295 | TAG expr { this_pref->tag = $2; }
309 this_nbma = cfg_allocz(sizeof(struct nbma_node));
310 add_tail(&OSPF_PATT->nbma_list, NODE this_nbma);
312 this_nbma->eligible=0;
316 ipa_ne: IPA ELIGIBLE ';'
318 this_nbma = cfg_allocz(sizeof(struct nbma_node));
319 add_tail(&OSPF_PATT->nbma_list, NODE this_nbma);
321 this_nbma->eligible=1;
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;
349 | ospf_iface_opts ospf_iface_item ';'
354 | '{' ospf_iface_opts '}'
358 ospf_iface_start iface_patt_list ospf_iface_opt_list { ospf_iface_finish(); }
363 | /* empty */ { $$ = NULL; }
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); })
371 CF_CLI(SHOW OSPF, optsym, [<name>], [[Show information about OSPF protocol]])
372 { ospf_sh(proto_get_named($3, &proto_ospf)); };
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); };
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); };
380 CF_CLI_HELP(SHOW OSPF TOPOLOGY, [all] [<name>], [[Show information about OSPF network topology]])
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); };
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); };
388 CF_CLI_HELP(SHOW OSPF STATE, [all] [<name>], [[Show information about OSPF network state]])
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); };
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); };
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)); };