blob: f8490f5ef44618058b3da55271febbbd6575b7fb [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * OSPF Interface functions.
3 * Copyright (C) 1999, 2000 Toshiaki Takada
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
25#include "thread.h"
26#include "linklist.h"
27#include "prefix.h"
28#include "if.h"
29#include "table.h"
30#include "memory.h"
31#include "command.h"
32#include "stream.h"
33#include "log.h"
34
paul68980082003-03-25 05:07:42 +000035#include "ospfd/ospfd.h"
paul718e3742002-12-13 20:15:29 +000036#include "ospfd/ospf_spf.h"
37#include "ospfd/ospf_interface.h"
38#include "ospfd/ospf_ism.h"
39#include "ospfd/ospf_asbr.h"
40#include "ospfd/ospf_lsa.h"
41#include "ospfd/ospf_lsdb.h"
42#include "ospfd/ospf_neighbor.h"
43#include "ospfd/ospf_nsm.h"
44#include "ospfd/ospf_packet.h"
45#include "ospfd/ospf_abr.h"
paul718e3742002-12-13 20:15:29 +000046#include "ospfd/ospf_network.h"
47#include "ospfd/ospf_dump.h"
48#ifdef HAVE_SNMP
49#include "ospfd/ospf_snmp.h"
50#endif /* HAVE_SNMP */
51
52
53int
54ospf_if_get_output_cost (struct ospf_interface *oi)
55{
56 /* If all else fails, use default OSPF cost */
57 u_int32_t cost;
58 u_int32_t bw, refbw;
59
60 bw = oi->ifp->bandwidth ? oi->ifp->bandwidth : OSPF_DEFAULT_BANDWIDTH;
paul68980082003-03-25 05:07:42 +000061 refbw = oi->ospf->ref_bandwidth;
paul718e3742002-12-13 20:15:29 +000062
63 /* A specifed ip ospf cost overrides a calculated one. */
64 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (oi->ifp), output_cost_cmd) ||
65 OSPF_IF_PARAM_CONFIGURED (oi->params, output_cost_cmd))
66 cost = OSPF_IF_PARAM (oi, output_cost_cmd);
67 /* See if a cost can be calculated from the zebra processes
68 interface bandwidth field. */
69 else
70 {
71 cost = (u_int32_t) ((double)refbw / (double)bw + (double)0.5);
72 if (cost < 1)
73 cost = 1;
74 else if (cost > 65535)
75 cost = 65535;
76 }
77
78 return cost;
79}
80
81void
82ospf_if_recalculate_output_cost (struct interface *ifp)
83{
84 u_int32_t newcost;
85 struct route_node *rn;
86
87 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
88 {
89 struct ospf_interface *oi;
90
91 if ( (oi = rn->info) == NULL)
92 continue;
93
94 newcost = ospf_if_get_output_cost (oi);
95
96 /* Is actual output cost changed? */
97 if (oi->output_cost != newcost)
98 {
99 oi->output_cost = newcost;
100 ospf_router_lsa_timer_add (oi->area);
101 }
102 }
103}
104
ajsa608bbf2005-03-29 17:03:49 +0000105/* Simulate down/up on the interface. This is needed, for example, when
106 the MTU changes. */
107void
108ospf_if_reset(struct interface *ifp)
109{
110 struct route_node *rn;
111
112 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
113 {
114 struct ospf_interface *oi;
115
116 if ( (oi = rn->info) == NULL)
117 continue;
118
119 ospf_if_down(oi);
120 ospf_if_up(oi);
121 }
122}
123
paul718e3742002-12-13 20:15:29 +0000124void
125ospf_if_reset_variables (struct ospf_interface *oi)
126{
127 /* Set default values. */
128 /* don't clear this flag. oi->flag = OSPF_IF_DISABLE; */
129
130 if (oi->vl_data)
131 oi->type = OSPF_IFTYPE_VIRTUALLINK;
132 else
133 /* preserve network-type */
134 if (oi->type != OSPF_IFTYPE_NBMA)
135 oi->type = OSPF_IFTYPE_BROADCAST;
136
137 oi->state = ISM_Down;
138
139 oi->crypt_seqnum = 0;
140
141 /* This must be short, (less than RxmtInterval)
142 - RFC 2328 Section 13.5 para 3. Set to 1 second to avoid Acks being
143 held back for too long - MAG */
144 oi->v_ls_ack = 1;
145}
146
paul20916fb2003-10-15 21:14:20 +0000147/* lookup oi for specified prefix/ifp */
148struct ospf_interface *
149ospf_if_table_lookup (struct interface *ifp, struct prefix *prefix)
150{
151 struct prefix p;
paulaffe1d92003-10-15 21:40:57 +0000152 struct route_node *rn;
paulb5f2c122003-11-10 23:56:29 +0000153 struct ospf_interface *rninfo;
paul20916fb2003-10-15 21:14:20 +0000154
155 p = *prefix;
156
paulaffe1d92003-10-15 21:40:57 +0000157 rn = route_node_get (IF_OIFS (ifp), &p);
paul20916fb2003-10-15 21:14:20 +0000158 /* route_node_get implicitely locks */
paulb5f2c122003-11-10 23:56:29 +0000159 rninfo = (struct ospf_interface *) rn->info;
paulaffe1d92003-10-15 21:40:57 +0000160 route_unlock_node (rn);
paulb5f2c122003-11-10 23:56:29 +0000161 return rninfo;
paul20916fb2003-10-15 21:14:20 +0000162}
163
paul718e3742002-12-13 20:15:29 +0000164void
165ospf_add_to_if (struct interface *ifp, struct ospf_interface *oi)
166{
167 struct route_node *rn;
168 struct prefix p;
169
170 p = *oi->address;
171 p.prefixlen = IPV4_MAX_PREFIXLEN;
172
173 rn = route_node_get (IF_OIFS (ifp), &p);
paul8c80cb72003-02-18 23:25:44 +0000174 /* rn->info should either be NULL or equal to this oi
175 * as route_node_get may return an existing node
176 */
paul20916fb2003-10-15 21:14:20 +0000177 assert (!rn->info || rn->info == oi);
paul718e3742002-12-13 20:15:29 +0000178 rn->info = oi;
179}
180
181void
182ospf_delete_from_if (struct interface *ifp, struct ospf_interface *oi)
183{
184 struct route_node *rn;
185 struct prefix p;
186
187 p = *oi->address;
188 p.prefixlen = IPV4_MAX_PREFIXLEN;
189
190 rn = route_node_lookup (IF_OIFS (oi->ifp), &p);
191 assert (rn);
192 assert (rn->info);
193 rn->info = NULL;
194 route_unlock_node (rn);
195 route_unlock_node (rn);
196}
197
198struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000199ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p)
paul718e3742002-12-13 20:15:29 +0000200{
201 struct ospf_interface *oi;
202
paul20916fb2003-10-15 21:14:20 +0000203 if ((oi = ospf_if_table_lookup (ifp, p)) == NULL)
204 {
205 oi = XCALLOC (MTYPE_OSPF_IF, sizeof (struct ospf_interface));
206 memset (oi, 0, sizeof (struct ospf_interface));
207 }
208 else
209 return oi;
210
paul718e3742002-12-13 20:15:29 +0000211 /* Set zebra interface pointer. */
212 oi->ifp = ifp;
213 oi->address = p;
214
215 ospf_add_to_if (ifp, oi);
paul68980082003-03-25 05:07:42 +0000216 listnode_add (ospf->oiflist, oi);
paul718e3742002-12-13 20:15:29 +0000217
218 /* Clear self-originated network-LSA. */
219 oi->network_lsa_self = NULL;
220
221 /* Initialize neighbor list. */
222 oi->nbrs = route_table_init ();
223
224 /* Initialize static neighbor list. */
225 oi->nbr_nbma = list_new ();
226
227 /* Initialize Link State Acknowledgment list. */
228 oi->ls_ack = list_new ();
229 oi->ls_ack_direct.ls_ack = list_new ();
230
231 /* Set default values. */
232 ospf_if_reset_variables (oi);
233
234 /* Add pseudo neighbor. */
235 oi->nbr_self = ospf_nbr_new (oi);
236 oi->nbr_self->state = NSM_TwoWay;
paul718e3742002-12-13 20:15:29 +0000237 oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
238 oi->nbr_self->options = OSPF_OPTION_E;
239
240 oi->ls_upd_queue = route_table_init ();
241 oi->t_ls_upd_event = NULL;
242 oi->t_ls_ack_direct = NULL;
243
paul68980082003-03-25 05:07:42 +0000244 oi->crypt_seqnum = time (NULL);
245
paul718e3742002-12-13 20:15:29 +0000246#ifdef HAVE_OPAQUE_LSA
247 ospf_opaque_type9_lsa_init (oi);
248#endif /* HAVE_OPAQUE_LSA */
249
paul68980082003-03-25 05:07:42 +0000250 oi->ospf = ospf;
paul718e3742002-12-13 20:15:29 +0000251
252 return oi;
253}
254
255/* Restore an interface to its pre UP state
256 Used from ism_interface_down only */
257void
258ospf_if_cleanup (struct ospf_interface *oi)
259{
260 struct route_node *rn;
paul1eb8ef22005-04-07 07:30:20 +0000261 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000262 struct ospf_neighbor *nbr;
paul1eb8ef22005-04-07 07:30:20 +0000263 struct ospf_nbr_nbma *nbr_nbma;
264 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000265
266 /* oi->nbrs and oi->nbr_nbma should be deletete on InterafceDown event */
267 /* delete all static neighbors attached to this interface */
paul1eb8ef22005-04-07 07:30:20 +0000268 for (ALL_LIST_ELEMENTS (oi->nbr_nbma, node, nnode, nbr_nbma))
paul718e3742002-12-13 20:15:29 +0000269 {
paul718e3742002-12-13 20:15:29 +0000270 OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll);
271
272 if (nbr_nbma->nbr)
273 {
274 nbr_nbma->nbr->nbr_nbma = NULL;
275 nbr_nbma->nbr = NULL;
276 }
277
278 nbr_nbma->oi = NULL;
279
280 listnode_delete (oi->nbr_nbma, nbr_nbma);
281 }
282
283 /* send Neighbor event KillNbr to all associated neighbors. */
284 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
285 if ((nbr = rn->info) != NULL)
286 if (nbr != oi->nbr_self)
287 OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr);
288
289 /* Cleanup Link State Acknowlegdment list. */
paul1eb8ef22005-04-07 07:30:20 +0000290 for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa))
291 ospf_lsa_unlock (lsa);
paul718e3742002-12-13 20:15:29 +0000292 list_delete_all_node (oi->ls_ack);
293
294 oi->crypt_seqnum = 0;
295
296 /* Empty link state update queue */
297 ospf_ls_upd_queue_empty (oi);
298
299 /* Handle pseudo neighbor. */
300 ospf_nbr_delete (oi->nbr_self);
301 oi->nbr_self = ospf_nbr_new (oi);
302 oi->nbr_self->state = NSM_TwoWay;
303 oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
paulf2c80652002-12-13 21:44:27 +0000304
305 switch (oi->area->external_routing)
306 {
307 case OSPF_AREA_DEFAULT:
308 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
309 break;
310 case OSPF_AREA_STUB:
311 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
312 break;
paulf2c80652002-12-13 21:44:27 +0000313 case OSPF_AREA_NSSA:
314 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
315 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
316 break;
paulf2c80652002-12-13 21:44:27 +0000317 }
paul718e3742002-12-13 20:15:29 +0000318
319 ospf_lsa_unlock (oi->network_lsa_self);
320 oi->network_lsa_self = NULL;
321 OSPF_TIMER_OFF (oi->t_network_lsa_self);
322}
323
324void
325ospf_if_free (struct ospf_interface *oi)
326{
327 ospf_if_down (oi);
328
329 assert (oi->state == ISM_Down);
330
331#ifdef HAVE_OPAQUE_LSA
332 ospf_opaque_type9_lsa_term (oi);
333#endif /* HAVE_OPAQUE_LSA */
334
335 /* Free Pseudo Neighbour */
336 ospf_nbr_delete (oi->nbr_self);
337
338 route_table_finish (oi->nbrs);
339 route_table_finish (oi->ls_upd_queue);
340
341 /* Free any lists that should be freed */
342 list_free (oi->nbr_nbma);
343
344 list_free (oi->ls_ack);
345 list_free (oi->ls_ack_direct.ls_ack);
346
347 ospf_delete_from_if (oi->ifp, oi);
348
paul68980082003-03-25 05:07:42 +0000349 listnode_delete (oi->ospf->oiflist, oi);
paul718e3742002-12-13 20:15:29 +0000350 listnode_delete (oi->area->oiflist, oi);
351
352 memset (oi, 0, sizeof (*oi));
353 XFREE (MTYPE_OSPF_IF, oi);
354}
355
356
357/*
358* check if interface with given address is configured and
hasso3fb9cd62004-10-19 19:44:43 +0000359* return it if yes. special treatment for PtP networks.
paul718e3742002-12-13 20:15:29 +0000360*/
361struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000362ospf_if_is_configured (struct ospf *ospf, struct in_addr *address)
paul718e3742002-12-13 20:15:29 +0000363{
paul1eb8ef22005-04-07 07:30:20 +0000364 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000365 struct ospf_interface *oi;
hasso3fb9cd62004-10-19 19:44:43 +0000366 struct prefix_ipv4 addr;
367
368 addr.family = AF_INET;
369 addr.prefix = *address;
370 addr.prefixlen = IPV4_MAX_PREFIXLEN;
paul718e3742002-12-13 20:15:29 +0000371
paul1eb8ef22005-04-07 07:30:20 +0000372 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
373 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul718e3742002-12-13 20:15:29 +0000374 {
375 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
hasso3fb9cd62004-10-19 19:44:43 +0000376 {
377 if (CONNECTED_DEST_HOST(oi->connected))
378 {
379 /* match only destination addr, since local addr is most likely
380 * not unique (borrowed from another interface) */
381 if (IPV4_ADDR_SAME (address,
382 &oi->connected->destination->u.prefix4))
383 return oi;
384 }
385 else
386 {
387 /* special leniency: match if addr is anywhere on PtP subnet */
388 if (prefix_match(oi->address,(struct prefix *)&addr))
389 return oi;
390 }
391 }
paul718e3742002-12-13 20:15:29 +0000392 else
hasso3fb9cd62004-10-19 19:44:43 +0000393 {
394 if (IPV4_ADDR_SAME (address, &oi->address->u.prefix4))
395 return oi;
396 }
paul718e3742002-12-13 20:15:29 +0000397 }
paul718e3742002-12-13 20:15:29 +0000398 return NULL;
399}
400
401int
402ospf_if_is_up (struct ospf_interface *oi)
403{
404 return if_is_up (oi->ifp);
405}
406
407struct ospf_interface *
hasso2db3d052004-02-11 21:52:13 +0000408ospf_if_exists (struct ospf_interface *oic)
409{
hasso52dc7ee2004-09-23 19:18:23 +0000410 struct listnode *node;
hasso2db3d052004-02-11 21:52:13 +0000411 struct ospf *ospf;
412 struct ospf_interface *oi;
413
414 ospf = ospf_lookup ();
415
paul1eb8ef22005-04-07 07:30:20 +0000416 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
417 if (oi == oic)
hasso2db3d052004-02-11 21:52:13 +0000418 return oi;
paul1eb8ef22005-04-07 07:30:20 +0000419
hasso2db3d052004-02-11 21:52:13 +0000420 return NULL;
421}
422
423struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000424ospf_if_lookup_by_local_addr (struct ospf *ospf,
425 struct interface *ifp, struct in_addr address)
paul718e3742002-12-13 20:15:29 +0000426{
hasso52dc7ee2004-09-23 19:18:23 +0000427 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000428 struct ospf_interface *oi;
429
paul1eb8ef22005-04-07 07:30:20 +0000430 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
431 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul718e3742002-12-13 20:15:29 +0000432 {
433 if (ifp && oi->ifp != ifp)
434 continue;
435
436 if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4))
437 return oi;
438 }
439
440 return NULL;
441}
442
443struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000444ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000445{
hasso52dc7ee2004-09-23 19:18:23 +0000446 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000447 struct ospf_interface *oi;
448 struct prefix ptmp;
449
450 /* Check each Interface. */
paul1eb8ef22005-04-07 07:30:20 +0000451 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
paul68980082003-03-25 05:07:42 +0000452 {
paul1eb8ef22005-04-07 07:30:20 +0000453 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul68980082003-03-25 05:07:42 +0000454 {
hasso3fb9cd62004-10-19 19:44:43 +0000455 if ((oi->type == OSPF_IFTYPE_POINTOPOINT) &&
456 CONNECTED_DEST_HOST(oi->connected))
paul68980082003-03-25 05:07:42 +0000457 {
458 prefix_copy (&ptmp, oi->connected->destination);
459 ptmp.prefixlen = IPV4_MAX_BITLEN;
460 }
461 else
462 prefix_copy (&ptmp, oi->address);
paul718e3742002-12-13 20:15:29 +0000463
paul68980082003-03-25 05:07:42 +0000464 apply_mask (&ptmp);
465 if (prefix_same (&ptmp, (struct prefix *) p))
466 return oi;
467 }
468 }
paul718e3742002-12-13 20:15:29 +0000469 return NULL;
470}
471
472/* determine receiving interface by source of packet */
473struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000474ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src)
paul718e3742002-12-13 20:15:29 +0000475{
hasso52dc7ee2004-09-23 19:18:23 +0000476 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000477 struct prefix_ipv4 addr;
478 struct ospf_interface *oi, *match;
479
480 addr.family = AF_INET;
481 addr.prefix = src;
482 addr.prefixlen = IPV4_MAX_BITLEN;
483
484 match = NULL;
485
paul1eb8ef22005-04-07 07:30:20 +0000486 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
paul718e3742002-12-13 20:15:29 +0000487 {
paul718e3742002-12-13 20:15:29 +0000488 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
489 continue;
490
hasso3fb9cd62004-10-19 19:44:43 +0000491 if ((oi->type == OSPF_IFTYPE_POINTOPOINT) &&
492 CONNECTED_DEST_HOST(oi->connected))
paul718e3742002-12-13 20:15:29 +0000493 {
494 if (IPV4_ADDR_SAME (&oi->connected->destination->u.prefix4, &src))
495 return oi;
496 }
497 else
498 {
499 if (prefix_match (oi->address, (struct prefix *) &addr))
paul0a825c72003-05-24 13:48:16 +0000500 {
paulaf8d0332003-05-24 15:31:45 +0000501 if ( (match == NULL) ||
502 (match->address->prefixlen < oi->address->prefixlen)
503 )
paul0a825c72003-05-24 13:48:16 +0000504 match = oi;
505 }
paul718e3742002-12-13 20:15:29 +0000506 }
507 }
508
509 return match;
510}
511
512void
513ospf_if_stream_set (struct ospf_interface *oi)
514{
515 /* set output fifo queue. */
516 if (oi->obuf == NULL)
517 oi->obuf = ospf_fifo_new ();
518}
519
520void
521ospf_if_stream_unset (struct ospf_interface *oi)
522{
paul68980082003-03-25 05:07:42 +0000523 struct ospf *ospf = oi->ospf;
524
paul718e3742002-12-13 20:15:29 +0000525 if (oi->obuf)
526 {
527 ospf_fifo_free (oi->obuf);
528 oi->obuf = NULL;
529
530 if (oi->on_write_q)
531 {
paul68980082003-03-25 05:07:42 +0000532 listnode_delete (ospf->oi_write_q, oi);
533 if (list_isempty(ospf->oi_write_q))
534 OSPF_TIMER_OFF (ospf->t_write);
paul718e3742002-12-13 20:15:29 +0000535 oi->on_write_q = 0;
536 }
537 }
538}
paul68980082003-03-25 05:07:42 +0000539
paul718e3742002-12-13 20:15:29 +0000540
541struct ospf_if_params *
542ospf_new_if_params ()
543{
544 struct ospf_if_params *oip;
545
546 oip = XMALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params));
paul718e3742002-12-13 20:15:29 +0000547
548 if (!oip)
549 return NULL;
550
paulf6457892003-04-17 16:11:30 +0000551 memset (oip, 0, sizeof (struct ospf_if_params));
552
paul718e3742002-12-13 20:15:29 +0000553 UNSET_IF_PARAM (oip, output_cost_cmd);
554 UNSET_IF_PARAM (oip, transmit_delay);
555 UNSET_IF_PARAM (oip, retransmit_interval);
556 UNSET_IF_PARAM (oip, passive_interface);
557 UNSET_IF_PARAM (oip, v_hello);
558 UNSET_IF_PARAM (oip, v_wait);
559 UNSET_IF_PARAM (oip, priority);
560 UNSET_IF_PARAM (oip, type);
561 UNSET_IF_PARAM (oip, auth_simple);
562 UNSET_IF_PARAM (oip, auth_crypt);
563 UNSET_IF_PARAM (oip, auth_type);
paulec1ca632003-06-04 02:23:15 +0000564
565 oip->auth_crypt = list_new ();
paul718e3742002-12-13 20:15:29 +0000566
paul718e3742002-12-13 20:15:29 +0000567 return oip;
568}
569
570void
571ospf_del_if_params (struct ospf_if_params *oip)
572{
573 list_delete (oip->auth_crypt);
574 XFREE (MTYPE_OSPF_IF_PARAMS, oip);
575}
576
577void
578ospf_free_if_params (struct interface *ifp, struct in_addr addr)
579{
580 struct ospf_if_params *oip;
581 struct prefix_ipv4 p;
582 struct route_node *rn;
gdt630e4802004-08-31 17:28:41 +0000583
584 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000585 p.prefixlen = IPV4_MAX_PREFIXLEN;
586 p.prefix = addr;
587 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
588 if (!rn || !rn->info)
589 return;
590
591 oip = rn->info;
592 route_unlock_node (rn);
593
594 if (!OSPF_IF_PARAM_CONFIGURED (oip, output_cost_cmd) &&
595 !OSPF_IF_PARAM_CONFIGURED (oip, transmit_delay) &&
596 !OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) &&
597 !OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) &&
598 !OSPF_IF_PARAM_CONFIGURED (oip, v_hello) &&
599 !OSPF_IF_PARAM_CONFIGURED (oip, v_wait) &&
600 !OSPF_IF_PARAM_CONFIGURED (oip, priority) &&
601 !OSPF_IF_PARAM_CONFIGURED (oip, type) &&
602 !OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) &&
603 !OSPF_IF_PARAM_CONFIGURED (oip, auth_type) &&
604 listcount (oip->auth_crypt) == 0)
605 {
606 ospf_del_if_params (oip);
607 rn->info = NULL;
608 route_unlock_node (rn);
609 }
610}
611
612struct ospf_if_params *
613ospf_lookup_if_params (struct interface *ifp, struct in_addr addr)
614{
615 struct prefix_ipv4 p;
616 struct route_node *rn;
617
gdt630e4802004-08-31 17:28:41 +0000618 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000619 p.prefixlen = IPV4_MAX_PREFIXLEN;
620 p.prefix = addr;
621
622 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
623
624 if (rn)
625 {
626 route_unlock_node (rn);
627 return rn->info;
628 }
629
630 return NULL;
631}
632
633struct ospf_if_params *
634ospf_get_if_params (struct interface *ifp, struct in_addr addr)
635{
636 struct prefix_ipv4 p;
637 struct route_node *rn;
638
639 p.family = AF_INET;
640 p.prefixlen = IPV4_MAX_PREFIXLEN;
641 p.prefix = addr;
642
643 rn = route_node_get (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
644
645 if (rn->info == NULL)
646 rn->info = ospf_new_if_params ();
647 else
648 route_unlock_node (rn);
649
650 return rn->info;
651}
652
653void
654ospf_if_update_params (struct interface *ifp, struct in_addr addr)
655{
656 struct route_node *rn;
657 struct ospf_interface *oi;
658
659 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
660 {
661 if ((oi = rn->info) == NULL)
662 continue;
663
664 if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &addr))
665 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
666 }
667}
668
669int
670ospf_if_new_hook (struct interface *ifp)
671{
672 int rc = 0;
673
674 ifp->info = XMALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info));
675 memset (ifp->info, 0, sizeof (struct ospf_if_info));
676
677 IF_OIFS (ifp) = route_table_init ();
678 IF_OIFS_PARAMS (ifp) = route_table_init ();
679
680 IF_DEF_PARAMS (ifp) = ospf_new_if_params ();
681
682 SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay);
683 IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
684
685 SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval);
686 IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
687
688 SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority);
689 IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
690
691 SET_IF_PARAM (IF_DEF_PARAMS (ifp), passive_interface);
692 IF_DEF_PARAMS (ifp)->passive_interface = OSPF_IF_ACTIVE;
693
694 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello);
695 IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
696
697 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait);
698 IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
699
700 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple);
701 memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
702
paul718e3742002-12-13 20:15:29 +0000703 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type);
704 IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET;
705
706#ifdef HAVE_OPAQUE_LSA
707 rc = ospf_opaque_new_if (ifp);
708#endif /* HAVE_OPAQUE_LSA */
709 return rc;
710}
711
712int
713ospf_if_delete_hook (struct interface *ifp)
714{
715 int rc = 0;
paul940b01a2004-02-17 20:07:30 +0000716 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +0000717#ifdef HAVE_OPAQUE_LSA
718 rc = ospf_opaque_del_if (ifp);
719#endif /* HAVE_OPAQUE_LSA */
paul940b01a2004-02-17 20:07:30 +0000720
paul718e3742002-12-13 20:15:29 +0000721 route_table_finish (IF_OIFS (ifp));
paul940b01a2004-02-17 20:07:30 +0000722
723 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
724 if (rn->info)
725 ospf_del_if_params (rn->info);
paul718e3742002-12-13 20:15:29 +0000726 route_table_finish (IF_OIFS_PARAMS (ifp));
paul940b01a2004-02-17 20:07:30 +0000727
paulcfc959b2003-06-04 02:28:45 +0000728 ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp));
paul718e3742002-12-13 20:15:29 +0000729 XFREE (MTYPE_OSPF_IF_INFO, ifp->info);
730 ifp->info = NULL;
731
732 return rc;
733}
734
735int
736ospf_if_is_enable (struct ospf_interface *oi)
737{
738 if (!if_is_loopback (oi->ifp))
739 if (if_is_up (oi->ifp))
740 return 1;
741
742 return 0;
743}
744
ajsba6454e2005-02-08 15:37:30 +0000745void
746ospf_if_set_multicast(struct ospf_interface *oi)
747{
748 if ((oi->state > ISM_Loopback) &&
749 (oi->type != OSPF_IFTYPE_LOOPBACK) &&
750 (oi->type != OSPF_IFTYPE_VIRTUALLINK) &&
751 (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE))
752 {
753 /* The interface should belong to the OSPF-all-routers group. */
754 if (!CHECK_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS) &&
755 (ospf_if_add_allspfrouters(oi->ospf, oi->address,
756 oi->ifp->ifindex) >= 0))
757 /* Set the flag only if the system call to join succeeded. */
758 SET_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS);
759 }
760 else
761 {
762 /* The interface should NOT belong to the OSPF-all-routers group. */
763 if (CHECK_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS))
764 {
765 ospf_if_drop_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex);
766 /* Unset the flag regardless of whether the system call to leave
767 the group succeeded, since it's much safer to assume that
768 we are not a member. */
769 UNSET_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS);
770 }
771 }
772
773 if (((oi->type == OSPF_IFTYPE_BROADCAST) ||
774 (oi->type == OSPF_IFTYPE_POINTOPOINT)) &&
775 ((oi->state == ISM_DR) || (oi->state == ISM_Backup)) &&
776 (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE))
777 {
778 /* The interface should belong to the OSPF-designated-routers group. */
779 if (!CHECK_FLAG(oi->multicast_memberships, MEMBER_DROUTERS) &&
780 (ospf_if_add_alldrouters(oi->ospf, oi->address,
781 oi->ifp->ifindex) >= 0))
782 /* Set the flag only if the system call to join succeeded. */
783 SET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS);
784 }
785 else
786 {
787 /* The interface should NOT belong to the OSPF-designated-routers group */
788 if (CHECK_FLAG(oi->multicast_memberships, MEMBER_DROUTERS))
789 {
790 ospf_if_drop_alldrouters(oi->ospf, oi->address, oi->ifp->ifindex);
791 /* Unset the flag regardless of whether the system call to leave
792 the group succeeded, since it's much safer to assume that
793 we are not a member. */
794 UNSET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS);
795 }
796 }
797}
798
paul718e3742002-12-13 20:15:29 +0000799int
800ospf_if_up (struct ospf_interface *oi)
801{
802 if (oi == NULL)
803 return 0;
804
805 if (oi->type == OSPF_IFTYPE_LOOPBACK)
806 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd);
807 else
808 {
paul718e3742002-12-13 20:15:29 +0000809 ospf_if_stream_set (oi);
810 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp);
811 }
812
813 return 1;
814}
815
816int
817ospf_if_down (struct ospf_interface *oi)
818{
819 if (oi == NULL)
820 return 0;
821
822 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
823 /* Shutdown packet reception and sending */
824 ospf_if_stream_unset (oi);
paul718e3742002-12-13 20:15:29 +0000825
826 return 1;
827}
828
829
830/* Virtual Link related functions. */
831
832struct ospf_vl_data *
833ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer)
834{
835 struct ospf_vl_data *vl_data;
836
837 vl_data = XMALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data));
838 memset (vl_data, 0, sizeof (struct ospf_vl_data));
839
840 vl_data->vl_peer.s_addr = vl_peer.s_addr;
841 vl_data->vl_area_id = area->area_id;
842 vl_data->format = area->format;
843
844 return vl_data;
845}
846
847void
848ospf_vl_data_free (struct ospf_vl_data *vl_data)
849{
850 XFREE (MTYPE_OSPF_VL_DATA, vl_data);
851}
852
853u_int vlink_count = 0;
854
855struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000856ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000857{
858 struct ospf_interface * voi;
859 struct interface * vi;
860 char ifname[INTERFACE_NAMSIZ + 1];
861 struct ospf_area *area;
862 struct in_addr area_id;
863 struct connected *co;
864 struct prefix_ipv4 *p;
865
866 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000867 zlog_debug ("ospf_vl_new(): Start");
paul718e3742002-12-13 20:15:29 +0000868 if (vlink_count == OSPF_VL_MAX_COUNT)
869 {
870 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000871 zlog_debug ("ospf_vl_new(): Alarm: "
paul718e3742002-12-13 20:15:29 +0000872 "cannot create more than OSPF_MAX_VL_COUNT virtual links");
873 return NULL;
874 }
875
876 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000877 zlog_debug ("ospf_vl_new(): creating pseudo zebra interface");
paul718e3742002-12-13 20:15:29 +0000878
ajsa3491982005-04-02 22:50:38 +0000879 snprintf (ifname, sizeof(ifname), "VLINK%d", vlink_count);
880 vi = if_create (ifname, strnlen(ifname, sizeof(ifname)));
paul718e3742002-12-13 20:15:29 +0000881 co = connected_new ();
882 co->ifp = vi;
883 listnode_add (vi->connected, co);
884
885 p = prefix_ipv4_new ();
886 p->family = AF_INET;
887 p->prefix.s_addr = 0;
888 p->prefixlen = 0;
889
890 co->address = (struct prefix *)p;
891
paul68980082003-03-25 05:07:42 +0000892 voi = ospf_if_new (ospf, vi, co->address);
paul718e3742002-12-13 20:15:29 +0000893 if (voi == NULL)
894 {
895 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000896 zlog_debug ("ospf_vl_new(): Alarm: OSPF int structure is not created");
paul718e3742002-12-13 20:15:29 +0000897 return NULL;
898 }
899 voi->connected = co;
900 voi->vl_data = vl_data;
901 voi->ifp->mtu = OSPF_VL_MTU;
902 voi->type = OSPF_IFTYPE_VIRTUALLINK;
903
paul106d2fd2003-08-01 00:24:13 +0000904 vlink_count++;
paul718e3742002-12-13 20:15:29 +0000905 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000906 zlog_debug ("ospf_vl_new(): Created name: %s", ifname);
paul718e3742002-12-13 20:15:29 +0000907 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000908 zlog_debug ("ospf_vl_new(): set if->name to %s", vi->name);
paul718e3742002-12-13 20:15:29 +0000909
910 area_id.s_addr = 0;
paul68980082003-03-25 05:07:42 +0000911 area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS);
paul718e3742002-12-13 20:15:29 +0000912 voi->area = area;
913
914 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000915 zlog_debug ("ospf_vl_new(): set associated area to the backbone");
paul718e3742002-12-13 20:15:29 +0000916
917 ospf_area_add_if (voi->area, voi);
918
919 ospf_if_stream_set (voi);
920
921 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000922 zlog_debug ("ospf_vl_new(): Stop");
paul718e3742002-12-13 20:15:29 +0000923 return voi;
924}
925
926void
927ospf_vl_if_delete (struct ospf_vl_data *vl_data)
928{
929 struct interface *ifp = vl_data->vl_oi->ifp;
930 vl_data->vl_oi->address->u.prefix4.s_addr = 0;
931 vl_data->vl_oi->address->prefixlen = 0;
932 ospf_if_free (vl_data->vl_oi);
933 if_delete (ifp);
934 vlink_count--;
935}
936
937struct ospf_vl_data *
938ospf_vl_lookup (struct ospf_area *area, struct in_addr vl_peer)
939{
940 struct ospf_vl_data *vl_data;
hasso52dc7ee2004-09-23 19:18:23 +0000941 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000942
paul1eb8ef22005-04-07 07:30:20 +0000943 for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
944 if (vl_data->vl_peer.s_addr == vl_peer.s_addr &&
945 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
946 return vl_data;
paul718e3742002-12-13 20:15:29 +0000947
948 return NULL;
949}
950
951void
952ospf_vl_shutdown (struct ospf_vl_data *vl_data)
953{
954 struct ospf_interface *oi;
955
956 if ((oi = vl_data->vl_oi) == NULL)
957 return;
958
959 oi->address->u.prefix4.s_addr = 0;
960 oi->address->prefixlen = 0;
961
962 UNSET_FLAG (oi->ifp->flags, IFF_UP);
963 /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */
964 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
965}
966
967void
paul68980082003-03-25 05:07:42 +0000968ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000969{
paul68980082003-03-25 05:07:42 +0000970 listnode_add (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000971#ifdef HAVE_SNMP
972 ospf_snmp_vl_add (vl_data);
973#endif /* HAVE_SNMP */
974}
975
976void
paul68980082003-03-25 05:07:42 +0000977ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000978{
979 ospf_vl_shutdown (vl_data);
980 ospf_vl_if_delete (vl_data);
981
982#ifdef HAVE_SNMP
983 ospf_snmp_vl_delete (vl_data);
984#endif /* HAVE_SNMP */
paul68980082003-03-25 05:07:42 +0000985 listnode_delete (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000986
987 ospf_vl_data_free (vl_data);
988}
989
paul2e6b0bb2003-06-22 08:17:12 +0000990int
paul718e3742002-12-13 20:15:29 +0000991ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v)
992{
993 int changed = 0;
994 struct ospf_interface *voi;
hasso52dc7ee2004-09-23 19:18:23 +0000995 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000996 struct vertex_nexthop *nh;
997 int i;
998 struct router_lsa *rl;
999
1000 voi = vl_data->vl_oi;
1001
1002 if (voi->output_cost != v->distance)
1003 {
paulcd59da62004-05-05 17:26:55 +00001004
paul718e3742002-12-13 20:15:29 +00001005 voi->output_cost = v->distance;
1006 changed = 1;
1007 }
1008
paul1eb8ef22005-04-07 07:30:20 +00001009 for (ALL_LIST_ELEMENTS_RO (v->nexthop, node, nh))
1010 {
1011 vl_data->out_oi = (struct ospf_interface *) nh->oi;
1012
1013 if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
1014 &vl_data->out_oi->address->u.prefix4))
1015 changed = 1;
paulcd59da62004-05-05 17:26:55 +00001016
paul1eb8ef22005-04-07 07:30:20 +00001017 voi->address->u.prefix4 = vl_data->out_oi->address->u.prefix4;
1018 voi->address->prefixlen = vl_data->out_oi->address->prefixlen;
paul718e3742002-12-13 20:15:29 +00001019
paul1eb8ef22005-04-07 07:30:20 +00001020 break; /* We take the first interface. */
1021 }
paul718e3742002-12-13 20:15:29 +00001022
1023 rl = (struct router_lsa *)v->lsa;
pauld355bfa2004-04-08 07:43:45 +00001024
1025 /* use SPF determined backlink index in struct vertex
1026 * for virtual link destination address
1027 */
1028 if (v->backlink >= 0)
paul718e3742002-12-13 20:15:29 +00001029 {
pauld355bfa2004-04-08 07:43:45 +00001030 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
1031 &rl->link[v->backlink].link_data))
1032 changed = 1;
1033 vl_data->peer_addr = rl->link[v->backlink].link_data;
1034 }
1035 else
1036 {
1037 /* This is highly odd, there is no backlink index
1038 * there should be due to the ospf_spf_has_link() check
1039 * in SPF. Lets warn and try pick a link anyway.
1040 */
1041 zlog_warn ("ospf_vl_set_params: No backlink for %s!",
1042 vl_data->vl_oi->ifp->name);
1043 for (i = 0; i < ntohs (rl->links); i++)
paul2e6b0bb2003-06-22 08:17:12 +00001044 {
pauld355bfa2004-04-08 07:43:45 +00001045 switch (rl->link[i].type)
1046 {
1047 case LSA_LINK_TYPE_VIRTUALLINK:
1048 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001049 zlog_debug ("found back link through VL");
pauld355bfa2004-04-08 07:43:45 +00001050 case LSA_LINK_TYPE_TRANSIT:
1051 case LSA_LINK_TYPE_POINTOPOINT:
paulcd59da62004-05-05 17:26:55 +00001052 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
1053 &rl->link[i].link_data))
1054 changed = 1;
pauld355bfa2004-04-08 07:43:45 +00001055 vl_data->peer_addr = rl->link[i].link_data;
1056 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001057 zlog_debug ("ospf_vl_set_params: %s peer address is %s\n",
pauld355bfa2004-04-08 07:43:45 +00001058 vl_data->vl_oi->ifp->name,
1059 inet_ntoa(vl_data->peer_addr));
1060 return changed;
1061 }
paul2e6b0bb2003-06-22 08:17:12 +00001062 }
paul718e3742002-12-13 20:15:29 +00001063 }
pauld355bfa2004-04-08 07:43:45 +00001064
1065 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001066 zlog_debug ("ospf_vl_set_params: %s peer address is %s\n",
pauld355bfa2004-04-08 07:43:45 +00001067 vl_data->vl_oi->ifp->name,
1068 inet_ntoa(vl_data->peer_addr));
1069
paul2e6b0bb2003-06-22 08:17:12 +00001070 return changed;
paul718e3742002-12-13 20:15:29 +00001071}
1072
1073
1074void
paul68980082003-03-25 05:07:42 +00001075ospf_vl_up_check (struct ospf_area *area, struct in_addr rid,
paul718e3742002-12-13 20:15:29 +00001076 struct vertex *v)
1077{
paul68980082003-03-25 05:07:42 +00001078 struct ospf *ospf = area->ospf;
hasso52dc7ee2004-09-23 19:18:23 +00001079 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001080 struct ospf_vl_data *vl_data;
1081 struct ospf_interface *oi;
1082
1083 if (IS_DEBUG_OSPF_EVENT)
1084 {
ajs60925302004-12-08 17:45:02 +00001085 zlog_debug ("ospf_vl_up_check(): Start");
1086 zlog_debug ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid));
1087 zlog_debug ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001088 }
1089
paul1eb8ef22005-04-07 07:30:20 +00001090 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
paul718e3742002-12-13 20:15:29 +00001091 {
paul718e3742002-12-13 20:15:29 +00001092 if (IS_DEBUG_OSPF_EVENT)
1093 {
ajs60925302004-12-08 17:45:02 +00001094 zlog_debug ("ospf_vl_up_check(): considering VL, name: %s",
paul718e3742002-12-13 20:15:29 +00001095 vl_data->vl_oi->ifp->name);
ajs60925302004-12-08 17:45:02 +00001096 zlog_debug ("ospf_vl_up_check(): VL area: %s, peer ID: %s",
paul718e3742002-12-13 20:15:29 +00001097 inet_ntoa (vl_data->vl_area_id),
1098 inet_ntoa (vl_data->vl_peer));
1099 }
1100
1101 if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) &&
1102 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1103 {
1104 oi = vl_data->vl_oi;
1105 SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
1106
1107 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001108 zlog_debug ("ospf_vl_up_check(): this VL matched");
paul718e3742002-12-13 20:15:29 +00001109
1110 if (oi->state == ISM_Down)
1111 {
1112 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001113 zlog_debug ("ospf_vl_up_check(): VL is down, waking it up");
paul718e3742002-12-13 20:15:29 +00001114 SET_FLAG (oi->ifp->flags, IFF_UP);
paul2e6b0bb2003-06-22 08:17:12 +00001115 OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp);
paul718e3742002-12-13 20:15:29 +00001116 }
1117
paul2e6b0bb2003-06-22 08:17:12 +00001118 if (ospf_vl_set_params (vl_data, v))
1119 {
1120 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
ajs60925302004-12-08 17:45:02 +00001121 zlog_debug ("ospf_vl_up_check: VL cost change,"
paulcd59da62004-05-05 17:26:55 +00001122 " scheduling router lsa refresh");
paul2e6b0bb2003-06-22 08:17:12 +00001123 if(ospf->backbone)
paulcd59da62004-05-05 17:26:55 +00001124 ospf_router_lsa_timer_add (ospf->backbone);
paul2e6b0bb2003-06-22 08:17:12 +00001125 else if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
ajs60925302004-12-08 17:45:02 +00001126 zlog_debug ("ospf_vl_up_check: VL cost change, no backbone!");
paul2e6b0bb2003-06-22 08:17:12 +00001127 }
paul718e3742002-12-13 20:15:29 +00001128 }
1129 }
1130}
1131
1132void
paul68980082003-03-25 05:07:42 +00001133ospf_vl_unapprove (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001134{
hasso52dc7ee2004-09-23 19:18:23 +00001135 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001136 struct ospf_vl_data *vl_data;
1137
paul1eb8ef22005-04-07 07:30:20 +00001138 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
1139 UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
paul718e3742002-12-13 20:15:29 +00001140}
1141
1142void
paul68980082003-03-25 05:07:42 +00001143ospf_vl_shut_unapproved (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001144{
paul1eb8ef22005-04-07 07:30:20 +00001145 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001146 struct ospf_vl_data *vl_data;
1147
paul1eb8ef22005-04-07 07:30:20 +00001148 for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
1149 if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
1150 ospf_vl_shutdown (vl_data);
paul718e3742002-12-13 20:15:29 +00001151}
1152
1153int
1154ospf_full_virtual_nbrs (struct ospf_area *area)
1155{
1156 if (IS_DEBUG_OSPF_EVENT)
1157 {
ajs60925302004-12-08 17:45:02 +00001158 zlog_debug ("counting fully adjacent virtual neighbors in area %s",
paul718e3742002-12-13 20:15:29 +00001159 inet_ntoa (area->area_id));
ajs60925302004-12-08 17:45:02 +00001160 zlog_debug ("there are %d of them", area->full_vls);
paul718e3742002-12-13 20:15:29 +00001161 }
1162
1163 return area->full_vls;
1164}
1165
1166int
1167ospf_vls_in_area (struct ospf_area *area)
1168{
hasso52dc7ee2004-09-23 19:18:23 +00001169 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001170 struct ospf_vl_data *vl_data;
1171 int c = 0;
1172
paul1eb8ef22005-04-07 07:30:20 +00001173 for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
1174 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1175 c++;
paul718e3742002-12-13 20:15:29 +00001176
1177 return c;
1178}
1179
1180
1181struct crypt_key *
1182ospf_crypt_key_new ()
1183{
1184 struct crypt_key *ck;
1185
1186 ck = XMALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key));
1187 memset (ck, 0, sizeof (struct crypt_key));
1188
1189 return ck;
1190}
1191
1192void
hasso52dc7ee2004-09-23 19:18:23 +00001193ospf_crypt_key_add (struct list *crypt, struct crypt_key *ck)
paul718e3742002-12-13 20:15:29 +00001194{
1195 listnode_add (crypt, ck);
1196}
1197
1198struct crypt_key *
hasso52dc7ee2004-09-23 19:18:23 +00001199ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001200{
hasso52dc7ee2004-09-23 19:18:23 +00001201 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001202 struct crypt_key *ck;
1203
paul1eb8ef22005-04-07 07:30:20 +00001204 for (ALL_LIST_ELEMENTS_RO (auth_crypt, node, ck))
1205 if (ck->key_id == key_id)
1206 return ck;
paul718e3742002-12-13 20:15:29 +00001207
1208 return NULL;
1209}
1210
1211int
hasso52dc7ee2004-09-23 19:18:23 +00001212ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001213{
paul1eb8ef22005-04-07 07:30:20 +00001214 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001215 struct crypt_key *ck;
1216
paul1eb8ef22005-04-07 07:30:20 +00001217 for (ALL_LIST_ELEMENTS (auth_crypt, node, nnode, ck))
paul718e3742002-12-13 20:15:29 +00001218 {
paul718e3742002-12-13 20:15:29 +00001219 if (ck->key_id == key_id)
1220 {
1221 listnode_delete (auth_crypt, ck);
1222 return 1;
1223 }
1224 }
1225
1226 return 0;
1227}
1228
ajsbc18d612004-12-15 15:07:19 +00001229u_char
1230ospf_default_iftype(struct interface *ifp)
1231{
1232 if (if_is_pointopoint (ifp))
1233 return OSPF_IFTYPE_POINTOPOINT;
1234 else if (if_is_loopback (ifp))
1235 return OSPF_IFTYPE_LOOPBACK;
1236 else
1237 return OSPF_IFTYPE_BROADCAST;
1238}
1239
paul718e3742002-12-13 20:15:29 +00001240void
1241ospf_if_init ()
1242{
1243 /* Initialize Zebra interface data structure. */
1244 if_init ();
paul020709f2003-04-04 02:44:16 +00001245 om->iflist = iflist;
paul718e3742002-12-13 20:15:29 +00001246 if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
1247 if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);
1248}