blob: 277d508b45611cdc6fa6d8a54deca6d685ebfffd [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
105void
106ospf_if_reset_variables (struct ospf_interface *oi)
107{
108 /* Set default values. */
109 /* don't clear this flag. oi->flag = OSPF_IF_DISABLE; */
110
111 if (oi->vl_data)
112 oi->type = OSPF_IFTYPE_VIRTUALLINK;
113 else
114 /* preserve network-type */
115 if (oi->type != OSPF_IFTYPE_NBMA)
116 oi->type = OSPF_IFTYPE_BROADCAST;
117
118 oi->state = ISM_Down;
119
120 oi->crypt_seqnum = 0;
121
122 /* This must be short, (less than RxmtInterval)
123 - RFC 2328 Section 13.5 para 3. Set to 1 second to avoid Acks being
124 held back for too long - MAG */
125 oi->v_ls_ack = 1;
126}
127
paul20916fb2003-10-15 21:14:20 +0000128/* lookup oi for specified prefix/ifp */
129struct ospf_interface *
130ospf_if_table_lookup (struct interface *ifp, struct prefix *prefix)
131{
132 struct prefix p;
paulaffe1d92003-10-15 21:40:57 +0000133 struct route_node *rn;
paulb5f2c122003-11-10 23:56:29 +0000134 struct ospf_interface *rninfo;
paul20916fb2003-10-15 21:14:20 +0000135
136 p = *prefix;
137
paulaffe1d92003-10-15 21:40:57 +0000138 rn = route_node_get (IF_OIFS (ifp), &p);
paul20916fb2003-10-15 21:14:20 +0000139 /* route_node_get implicitely locks */
paulb5f2c122003-11-10 23:56:29 +0000140 rninfo = (struct ospf_interface *) rn->info;
paulaffe1d92003-10-15 21:40:57 +0000141 route_unlock_node (rn);
paulb5f2c122003-11-10 23:56:29 +0000142 return rninfo;
paul20916fb2003-10-15 21:14:20 +0000143}
144
paul718e3742002-12-13 20:15:29 +0000145void
146ospf_add_to_if (struct interface *ifp, struct ospf_interface *oi)
147{
148 struct route_node *rn;
149 struct prefix p;
150
151 p = *oi->address;
152 p.prefixlen = IPV4_MAX_PREFIXLEN;
153
154 rn = route_node_get (IF_OIFS (ifp), &p);
paul8c80cb72003-02-18 23:25:44 +0000155 /* rn->info should either be NULL or equal to this oi
156 * as route_node_get may return an existing node
157 */
paul20916fb2003-10-15 21:14:20 +0000158 assert (!rn->info || rn->info == oi);
paul718e3742002-12-13 20:15:29 +0000159 rn->info = oi;
160}
161
162void
163ospf_delete_from_if (struct interface *ifp, struct ospf_interface *oi)
164{
165 struct route_node *rn;
166 struct prefix p;
167
168 p = *oi->address;
169 p.prefixlen = IPV4_MAX_PREFIXLEN;
170
171 rn = route_node_lookup (IF_OIFS (oi->ifp), &p);
172 assert (rn);
173 assert (rn->info);
174 rn->info = NULL;
175 route_unlock_node (rn);
176 route_unlock_node (rn);
177}
178
179struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000180ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p)
paul718e3742002-12-13 20:15:29 +0000181{
182 struct ospf_interface *oi;
183
paul20916fb2003-10-15 21:14:20 +0000184 if ((oi = ospf_if_table_lookup (ifp, p)) == NULL)
185 {
186 oi = XCALLOC (MTYPE_OSPF_IF, sizeof (struct ospf_interface));
187 memset (oi, 0, sizeof (struct ospf_interface));
188 }
189 else
190 return oi;
191
paul718e3742002-12-13 20:15:29 +0000192 /* Set zebra interface pointer. */
193 oi->ifp = ifp;
194 oi->address = p;
195
196 ospf_add_to_if (ifp, oi);
paul68980082003-03-25 05:07:42 +0000197 listnode_add (ospf->oiflist, oi);
paul718e3742002-12-13 20:15:29 +0000198
199 /* Clear self-originated network-LSA. */
200 oi->network_lsa_self = NULL;
201
202 /* Initialize neighbor list. */
203 oi->nbrs = route_table_init ();
204
205 /* Initialize static neighbor list. */
206 oi->nbr_nbma = list_new ();
207
208 /* Initialize Link State Acknowledgment list. */
209 oi->ls_ack = list_new ();
210 oi->ls_ack_direct.ls_ack = list_new ();
211
212 /* Set default values. */
213 ospf_if_reset_variables (oi);
214
215 /* Add pseudo neighbor. */
216 oi->nbr_self = ospf_nbr_new (oi);
217 oi->nbr_self->state = NSM_TwoWay;
paul718e3742002-12-13 20:15:29 +0000218 oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
219 oi->nbr_self->options = OSPF_OPTION_E;
220
221 oi->ls_upd_queue = route_table_init ();
222 oi->t_ls_upd_event = NULL;
223 oi->t_ls_ack_direct = NULL;
224
paul68980082003-03-25 05:07:42 +0000225 oi->crypt_seqnum = time (NULL);
226
paul718e3742002-12-13 20:15:29 +0000227#ifdef HAVE_OPAQUE_LSA
228 ospf_opaque_type9_lsa_init (oi);
229#endif /* HAVE_OPAQUE_LSA */
230
paul68980082003-03-25 05:07:42 +0000231 oi->ospf = ospf;
paul718e3742002-12-13 20:15:29 +0000232
233 return oi;
234}
235
236/* Restore an interface to its pre UP state
237 Used from ism_interface_down only */
238void
239ospf_if_cleanup (struct ospf_interface *oi)
240{
241 struct route_node *rn;
hasso52dc7ee2004-09-23 19:18:23 +0000242 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000243 struct ospf_neighbor *nbr;
244
245 /* oi->nbrs and oi->nbr_nbma should be deletete on InterafceDown event */
246 /* delete all static neighbors attached to this interface */
247 for (node = listhead (oi->nbr_nbma); node; )
248 {
249 struct ospf_nbr_nbma *nbr_nbma = getdata (node);
250 nextnode (node);
251
252 OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll);
253
254 if (nbr_nbma->nbr)
255 {
256 nbr_nbma->nbr->nbr_nbma = NULL;
257 nbr_nbma->nbr = NULL;
258 }
259
260 nbr_nbma->oi = NULL;
261
262 listnode_delete (oi->nbr_nbma, nbr_nbma);
263 }
264
265 /* send Neighbor event KillNbr to all associated neighbors. */
266 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
267 if ((nbr = rn->info) != NULL)
268 if (nbr != oi->nbr_self)
269 OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr);
270
271 /* Cleanup Link State Acknowlegdment list. */
272 for (node = listhead (oi->ls_ack); node; nextnode (node))
273 ospf_lsa_unlock (node->data);
274 list_delete_all_node (oi->ls_ack);
275
276 oi->crypt_seqnum = 0;
277
278 /* Empty link state update queue */
279 ospf_ls_upd_queue_empty (oi);
280
281 /* Handle pseudo neighbor. */
282 ospf_nbr_delete (oi->nbr_self);
283 oi->nbr_self = ospf_nbr_new (oi);
284 oi->nbr_self->state = NSM_TwoWay;
285 oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
paulf2c80652002-12-13 21:44:27 +0000286
287 switch (oi->area->external_routing)
288 {
289 case OSPF_AREA_DEFAULT:
290 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
291 break;
292 case OSPF_AREA_STUB:
293 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
294 break;
paulf2c80652002-12-13 21:44:27 +0000295 case OSPF_AREA_NSSA:
296 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
297 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
298 break;
paulf2c80652002-12-13 21:44:27 +0000299 }
paul718e3742002-12-13 20:15:29 +0000300
301 ospf_lsa_unlock (oi->network_lsa_self);
302 oi->network_lsa_self = NULL;
303 OSPF_TIMER_OFF (oi->t_network_lsa_self);
304}
305
306void
307ospf_if_free (struct ospf_interface *oi)
308{
309 ospf_if_down (oi);
310
311 assert (oi->state == ISM_Down);
312
313#ifdef HAVE_OPAQUE_LSA
314 ospf_opaque_type9_lsa_term (oi);
315#endif /* HAVE_OPAQUE_LSA */
316
317 /* Free Pseudo Neighbour */
318 ospf_nbr_delete (oi->nbr_self);
319
320 route_table_finish (oi->nbrs);
321 route_table_finish (oi->ls_upd_queue);
322
323 /* Free any lists that should be freed */
324 list_free (oi->nbr_nbma);
325
326 list_free (oi->ls_ack);
327 list_free (oi->ls_ack_direct.ls_ack);
328
329 ospf_delete_from_if (oi->ifp, oi);
330
paul68980082003-03-25 05:07:42 +0000331 listnode_delete (oi->ospf->oiflist, oi);
paul718e3742002-12-13 20:15:29 +0000332 listnode_delete (oi->area->oiflist, oi);
333
334 memset (oi, 0, sizeof (*oi));
335 XFREE (MTYPE_OSPF_IF, oi);
336}
337
338
339/*
340* check if interface with given address is configured and
341* return it if yes.
342*/
343struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000344ospf_if_is_configured (struct ospf *ospf, struct in_addr *address)
paul718e3742002-12-13 20:15:29 +0000345{
hasso52dc7ee2004-09-23 19:18:23 +0000346 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000347 struct ospf_interface *oi;
348 struct prefix *addr;
349
paul68980082003-03-25 05:07:42 +0000350 for (node = listhead (ospf->oiflist); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +0000351 if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
352 {
353 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
354 addr = oi->connected->destination;
355 else
356 addr = oi->address;
357
358 if (IPV4_ADDR_SAME (address, &addr->u.prefix4))
359 return oi;
360 }
361
362 return NULL;
363}
364
365int
366ospf_if_is_up (struct ospf_interface *oi)
367{
368 return if_is_up (oi->ifp);
369}
370
371struct ospf_interface *
hasso2db3d052004-02-11 21:52:13 +0000372ospf_if_exists (struct ospf_interface *oic)
373{
hasso52dc7ee2004-09-23 19:18:23 +0000374 struct listnode *node;
hasso2db3d052004-02-11 21:52:13 +0000375 struct ospf *ospf;
376 struct ospf_interface *oi;
377
378 ospf = ospf_lookup ();
379
380 for (node = listhead (ospf->oiflist); node; nextnode (node))
381 {
382 if (((oi = getdata (node)) != NULL) && (oi == oic))
383 return oi;
384 }
385 return NULL;
386}
387
388struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000389ospf_if_lookup_by_local_addr (struct ospf *ospf,
390 struct interface *ifp, struct in_addr address)
paul718e3742002-12-13 20:15:29 +0000391{
hasso52dc7ee2004-09-23 19:18:23 +0000392 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000393 struct ospf_interface *oi;
394
paul68980082003-03-25 05:07:42 +0000395 for (node = listhead (ospf->oiflist); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +0000396 if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
397 {
398 if (ifp && oi->ifp != ifp)
399 continue;
400
401 if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4))
402 return oi;
403 }
404
405 return NULL;
406}
407
408struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000409ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000410{
hasso52dc7ee2004-09-23 19:18:23 +0000411 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000412 struct ospf_interface *oi;
413 struct prefix ptmp;
414
415 /* Check each Interface. */
paul68980082003-03-25 05:07:42 +0000416 for (node = listhead (ospf->oiflist); node; nextnode (node))
417 {
418 if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
419 {
420 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
421 {
422 prefix_copy (&ptmp, oi->connected->destination);
423 ptmp.prefixlen = IPV4_MAX_BITLEN;
424 }
425 else
426 prefix_copy (&ptmp, oi->address);
paul718e3742002-12-13 20:15:29 +0000427
paul68980082003-03-25 05:07:42 +0000428 apply_mask (&ptmp);
429 if (prefix_same (&ptmp, (struct prefix *) p))
430 return oi;
431 }
432 }
paul718e3742002-12-13 20:15:29 +0000433 return NULL;
434}
435
436/* determine receiving interface by source of packet */
437struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000438ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src)
paul718e3742002-12-13 20:15:29 +0000439{
hasso52dc7ee2004-09-23 19:18:23 +0000440 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000441 struct prefix_ipv4 addr;
442 struct ospf_interface *oi, *match;
443
444 addr.family = AF_INET;
445 addr.prefix = src;
446 addr.prefixlen = IPV4_MAX_BITLEN;
447
448 match = NULL;
449
paul68980082003-03-25 05:07:42 +0000450 for (node = listhead (ospf->oiflist); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +0000451 {
452 oi = getdata (node);
453
454 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
455 continue;
456
457 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
458 {
459 if (IPV4_ADDR_SAME (&oi->connected->destination->u.prefix4, &src))
460 return oi;
461 }
462 else
463 {
464 if (prefix_match (oi->address, (struct prefix *) &addr))
paul0a825c72003-05-24 13:48:16 +0000465 {
paulaf8d0332003-05-24 15:31:45 +0000466 if ( (match == NULL) ||
467 (match->address->prefixlen < oi->address->prefixlen)
468 )
paul0a825c72003-05-24 13:48:16 +0000469 match = oi;
470 }
paul718e3742002-12-13 20:15:29 +0000471 }
472 }
473
474 return match;
475}
476
477void
478ospf_if_stream_set (struct ospf_interface *oi)
479{
480 /* set output fifo queue. */
481 if (oi->obuf == NULL)
482 oi->obuf = ospf_fifo_new ();
483}
484
485void
486ospf_if_stream_unset (struct ospf_interface *oi)
487{
paul68980082003-03-25 05:07:42 +0000488 struct ospf *ospf = oi->ospf;
489
paul718e3742002-12-13 20:15:29 +0000490 if (oi->obuf)
491 {
492 ospf_fifo_free (oi->obuf);
493 oi->obuf = NULL;
494
495 if (oi->on_write_q)
496 {
paul68980082003-03-25 05:07:42 +0000497 listnode_delete (ospf->oi_write_q, oi);
498 if (list_isempty(ospf->oi_write_q))
499 OSPF_TIMER_OFF (ospf->t_write);
paul718e3742002-12-13 20:15:29 +0000500 oi->on_write_q = 0;
501 }
502 }
503}
paul68980082003-03-25 05:07:42 +0000504
paul718e3742002-12-13 20:15:29 +0000505
506struct ospf_if_params *
507ospf_new_if_params ()
508{
509 struct ospf_if_params *oip;
510
511 oip = XMALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params));
paul718e3742002-12-13 20:15:29 +0000512
513 if (!oip)
514 return NULL;
515
paulf6457892003-04-17 16:11:30 +0000516 memset (oip, 0, sizeof (struct ospf_if_params));
517
paul718e3742002-12-13 20:15:29 +0000518 UNSET_IF_PARAM (oip, output_cost_cmd);
519 UNSET_IF_PARAM (oip, transmit_delay);
520 UNSET_IF_PARAM (oip, retransmit_interval);
521 UNSET_IF_PARAM (oip, passive_interface);
522 UNSET_IF_PARAM (oip, v_hello);
523 UNSET_IF_PARAM (oip, v_wait);
524 UNSET_IF_PARAM (oip, priority);
525 UNSET_IF_PARAM (oip, type);
526 UNSET_IF_PARAM (oip, auth_simple);
527 UNSET_IF_PARAM (oip, auth_crypt);
528 UNSET_IF_PARAM (oip, auth_type);
paulec1ca632003-06-04 02:23:15 +0000529
530 oip->auth_crypt = list_new ();
paul718e3742002-12-13 20:15:29 +0000531
paul718e3742002-12-13 20:15:29 +0000532 return oip;
533}
534
535void
536ospf_del_if_params (struct ospf_if_params *oip)
537{
538 list_delete (oip->auth_crypt);
539 XFREE (MTYPE_OSPF_IF_PARAMS, oip);
540}
541
542void
543ospf_free_if_params (struct interface *ifp, struct in_addr addr)
544{
545 struct ospf_if_params *oip;
546 struct prefix_ipv4 p;
547 struct route_node *rn;
gdt630e4802004-08-31 17:28:41 +0000548
549 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000550 p.prefixlen = IPV4_MAX_PREFIXLEN;
551 p.prefix = addr;
552 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
553 if (!rn || !rn->info)
554 return;
555
556 oip = rn->info;
557 route_unlock_node (rn);
558
559 if (!OSPF_IF_PARAM_CONFIGURED (oip, output_cost_cmd) &&
560 !OSPF_IF_PARAM_CONFIGURED (oip, transmit_delay) &&
561 !OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) &&
562 !OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) &&
563 !OSPF_IF_PARAM_CONFIGURED (oip, v_hello) &&
564 !OSPF_IF_PARAM_CONFIGURED (oip, v_wait) &&
565 !OSPF_IF_PARAM_CONFIGURED (oip, priority) &&
566 !OSPF_IF_PARAM_CONFIGURED (oip, type) &&
567 !OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) &&
568 !OSPF_IF_PARAM_CONFIGURED (oip, auth_type) &&
569 listcount (oip->auth_crypt) == 0)
570 {
571 ospf_del_if_params (oip);
572 rn->info = NULL;
573 route_unlock_node (rn);
574 }
575}
576
577struct ospf_if_params *
578ospf_lookup_if_params (struct interface *ifp, struct in_addr addr)
579{
580 struct prefix_ipv4 p;
581 struct route_node *rn;
582
gdt630e4802004-08-31 17:28:41 +0000583 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000584 p.prefixlen = IPV4_MAX_PREFIXLEN;
585 p.prefix = addr;
586
587 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
588
589 if (rn)
590 {
591 route_unlock_node (rn);
592 return rn->info;
593 }
594
595 return NULL;
596}
597
598struct ospf_if_params *
599ospf_get_if_params (struct interface *ifp, struct in_addr addr)
600{
601 struct prefix_ipv4 p;
602 struct route_node *rn;
603
604 p.family = AF_INET;
605 p.prefixlen = IPV4_MAX_PREFIXLEN;
606 p.prefix = addr;
607
608 rn = route_node_get (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
609
610 if (rn->info == NULL)
611 rn->info = ospf_new_if_params ();
612 else
613 route_unlock_node (rn);
614
615 return rn->info;
616}
617
618void
619ospf_if_update_params (struct interface *ifp, struct in_addr addr)
620{
621 struct route_node *rn;
622 struct ospf_interface *oi;
623
624 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
625 {
626 if ((oi = rn->info) == NULL)
627 continue;
628
629 if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &addr))
630 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
631 }
632}
633
634int
635ospf_if_new_hook (struct interface *ifp)
636{
637 int rc = 0;
638
639 ifp->info = XMALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info));
640 memset (ifp->info, 0, sizeof (struct ospf_if_info));
641
642 IF_OIFS (ifp) = route_table_init ();
643 IF_OIFS_PARAMS (ifp) = route_table_init ();
644
645 IF_DEF_PARAMS (ifp) = ospf_new_if_params ();
646
647 SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay);
648 IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
649
650 SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval);
651 IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
652
653 SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority);
654 IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
655
656 SET_IF_PARAM (IF_DEF_PARAMS (ifp), passive_interface);
657 IF_DEF_PARAMS (ifp)->passive_interface = OSPF_IF_ACTIVE;
658
659 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello);
660 IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
661
662 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait);
663 IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
664
665 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple);
666 memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
667
paul718e3742002-12-13 20:15:29 +0000668 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type);
669 IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET;
670
671#ifdef HAVE_OPAQUE_LSA
672 rc = ospf_opaque_new_if (ifp);
673#endif /* HAVE_OPAQUE_LSA */
674 return rc;
675}
676
677int
678ospf_if_delete_hook (struct interface *ifp)
679{
680 int rc = 0;
paul940b01a2004-02-17 20:07:30 +0000681 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +0000682#ifdef HAVE_OPAQUE_LSA
683 rc = ospf_opaque_del_if (ifp);
684#endif /* HAVE_OPAQUE_LSA */
paul940b01a2004-02-17 20:07:30 +0000685
paul718e3742002-12-13 20:15:29 +0000686 route_table_finish (IF_OIFS (ifp));
paul940b01a2004-02-17 20:07:30 +0000687
688 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
689 if (rn->info)
690 ospf_del_if_params (rn->info);
paul718e3742002-12-13 20:15:29 +0000691 route_table_finish (IF_OIFS_PARAMS (ifp));
paul940b01a2004-02-17 20:07:30 +0000692
paulcfc959b2003-06-04 02:28:45 +0000693 ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp));
paul718e3742002-12-13 20:15:29 +0000694 XFREE (MTYPE_OSPF_IF_INFO, ifp->info);
695 ifp->info = NULL;
696
697 return rc;
698}
699
700int
701ospf_if_is_enable (struct ospf_interface *oi)
702{
703 if (!if_is_loopback (oi->ifp))
704 if (if_is_up (oi->ifp))
705 return 1;
706
707 return 0;
708}
709
710int
711ospf_if_up (struct ospf_interface *oi)
712{
713 if (oi == NULL)
714 return 0;
715
716 if (oi->type == OSPF_IFTYPE_LOOPBACK)
717 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd);
718 else
719 {
720 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul68980082003-03-25 05:07:42 +0000721 ospf_if_add_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex);
paul718e3742002-12-13 20:15:29 +0000722 ospf_if_stream_set (oi);
723 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp);
724 }
725
726 return 1;
727}
728
729int
730ospf_if_down (struct ospf_interface *oi)
731{
732 if (oi == NULL)
733 return 0;
734
735 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
736 /* Shutdown packet reception and sending */
737 ospf_if_stream_unset (oi);
738 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul68980082003-03-25 05:07:42 +0000739 ospf_if_drop_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex);
paul718e3742002-12-13 20:15:29 +0000740
741
742 return 1;
743}
744
745
746/* Virtual Link related functions. */
747
748struct ospf_vl_data *
749ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer)
750{
751 struct ospf_vl_data *vl_data;
752
753 vl_data = XMALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data));
754 memset (vl_data, 0, sizeof (struct ospf_vl_data));
755
756 vl_data->vl_peer.s_addr = vl_peer.s_addr;
757 vl_data->vl_area_id = area->area_id;
758 vl_data->format = area->format;
759
760 return vl_data;
761}
762
763void
764ospf_vl_data_free (struct ospf_vl_data *vl_data)
765{
766 XFREE (MTYPE_OSPF_VL_DATA, vl_data);
767}
768
769u_int vlink_count = 0;
770
771struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000772ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000773{
774 struct ospf_interface * voi;
775 struct interface * vi;
776 char ifname[INTERFACE_NAMSIZ + 1];
777 struct ospf_area *area;
778 struct in_addr area_id;
779 struct connected *co;
780 struct prefix_ipv4 *p;
781
782 if (IS_DEBUG_OSPF_EVENT)
783 zlog_info ("ospf_vl_new(): Start");
784 if (vlink_count == OSPF_VL_MAX_COUNT)
785 {
786 if (IS_DEBUG_OSPF_EVENT)
787 zlog_info ("ospf_vl_new(): Alarm: "
788 "cannot create more than OSPF_MAX_VL_COUNT virtual links");
789 return NULL;
790 }
791
792 if (IS_DEBUG_OSPF_EVENT)
793 zlog_info ("ospf_vl_new(): creating pseudo zebra interface");
794
paul106d2fd2003-08-01 00:24:13 +0000795 snprintf (ifname, INTERFACE_NAMSIZ + 1, "VLINK%d", vlink_count);
796 vi = if_create (ifname, INTERFACE_NAMSIZ);
paul718e3742002-12-13 20:15:29 +0000797 co = connected_new ();
798 co->ifp = vi;
799 listnode_add (vi->connected, co);
800
801 p = prefix_ipv4_new ();
802 p->family = AF_INET;
803 p->prefix.s_addr = 0;
804 p->prefixlen = 0;
805
806 co->address = (struct prefix *)p;
807
paul68980082003-03-25 05:07:42 +0000808 voi = ospf_if_new (ospf, vi, co->address);
paul718e3742002-12-13 20:15:29 +0000809 if (voi == NULL)
810 {
811 if (IS_DEBUG_OSPF_EVENT)
812 zlog_info ("ospf_vl_new(): Alarm: OSPF int structure is not created");
813 return NULL;
814 }
815 voi->connected = co;
816 voi->vl_data = vl_data;
817 voi->ifp->mtu = OSPF_VL_MTU;
818 voi->type = OSPF_IFTYPE_VIRTUALLINK;
819
paul106d2fd2003-08-01 00:24:13 +0000820 vlink_count++;
paul718e3742002-12-13 20:15:29 +0000821 if (IS_DEBUG_OSPF_EVENT)
822 zlog_info ("ospf_vl_new(): Created name: %s", ifname);
paul718e3742002-12-13 20:15:29 +0000823 if (IS_DEBUG_OSPF_EVENT)
824 zlog_info ("ospf_vl_new(): set if->name to %s", vi->name);
825
826 area_id.s_addr = 0;
paul68980082003-03-25 05:07:42 +0000827 area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS);
paul718e3742002-12-13 20:15:29 +0000828 voi->area = area;
829
830 if (IS_DEBUG_OSPF_EVENT)
831 zlog_info ("ospf_vl_new(): set associated area to the backbone");
832
833 ospf_area_add_if (voi->area, voi);
834
835 ospf_if_stream_set (voi);
836
837 if (IS_DEBUG_OSPF_EVENT)
838 zlog_info ("ospf_vl_new(): Stop");
839 return voi;
840}
841
842void
843ospf_vl_if_delete (struct ospf_vl_data *vl_data)
844{
845 struct interface *ifp = vl_data->vl_oi->ifp;
846 vl_data->vl_oi->address->u.prefix4.s_addr = 0;
847 vl_data->vl_oi->address->prefixlen = 0;
848 ospf_if_free (vl_data->vl_oi);
849 if_delete (ifp);
850 vlink_count--;
851}
852
853struct ospf_vl_data *
854ospf_vl_lookup (struct ospf_area *area, struct in_addr vl_peer)
855{
856 struct ospf_vl_data *vl_data;
hasso52dc7ee2004-09-23 19:18:23 +0000857 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000858
paul68980082003-03-25 05:07:42 +0000859 for (node = listhead (area->ospf->vlinks); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +0000860 if ((vl_data = getdata (node)) != NULL)
861 if (vl_data->vl_peer.s_addr == vl_peer.s_addr &&
862 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
863 return vl_data;
864
865 return NULL;
866}
867
868void
869ospf_vl_shutdown (struct ospf_vl_data *vl_data)
870{
871 struct ospf_interface *oi;
872
873 if ((oi = vl_data->vl_oi) == NULL)
874 return;
875
876 oi->address->u.prefix4.s_addr = 0;
877 oi->address->prefixlen = 0;
878
879 UNSET_FLAG (oi->ifp->flags, IFF_UP);
880 /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */
881 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
882}
883
884void
paul68980082003-03-25 05:07:42 +0000885ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000886{
paul68980082003-03-25 05:07:42 +0000887 listnode_add (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000888#ifdef HAVE_SNMP
889 ospf_snmp_vl_add (vl_data);
890#endif /* HAVE_SNMP */
891}
892
893void
paul68980082003-03-25 05:07:42 +0000894ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000895{
896 ospf_vl_shutdown (vl_data);
897 ospf_vl_if_delete (vl_data);
898
899#ifdef HAVE_SNMP
900 ospf_snmp_vl_delete (vl_data);
901#endif /* HAVE_SNMP */
paul68980082003-03-25 05:07:42 +0000902 listnode_delete (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000903
904 ospf_vl_data_free (vl_data);
905}
906
paul2e6b0bb2003-06-22 08:17:12 +0000907int
paul718e3742002-12-13 20:15:29 +0000908ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v)
909{
910 int changed = 0;
911 struct ospf_interface *voi;
hasso52dc7ee2004-09-23 19:18:23 +0000912 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000913 struct vertex_nexthop *nh;
914 int i;
915 struct router_lsa *rl;
916
917 voi = vl_data->vl_oi;
918
919 if (voi->output_cost != v->distance)
920 {
paulcd59da62004-05-05 17:26:55 +0000921
paul718e3742002-12-13 20:15:29 +0000922 voi->output_cost = v->distance;
923 changed = 1;
924 }
925
926 for (node = listhead (v->nexthop); node; nextnode (node))
927 if ((nh = getdata (node)) != NULL)
928 {
paulcd59da62004-05-05 17:26:55 +0000929 vl_data->out_oi = (struct ospf_interface *) nh->oi;
930
931 if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
932 &vl_data->out_oi->address->u.prefix4))
933 changed = 1;
934
935 voi->address->u.prefix4 = vl_data->out_oi->address->u.prefix4;
936 voi->address->prefixlen = vl_data->out_oi->address->prefixlen;
paul718e3742002-12-13 20:15:29 +0000937
paulcd59da62004-05-05 17:26:55 +0000938 break; /* We take the first interface. */
paul718e3742002-12-13 20:15:29 +0000939 }
940
941 rl = (struct router_lsa *)v->lsa;
pauld355bfa2004-04-08 07:43:45 +0000942
943 /* use SPF determined backlink index in struct vertex
944 * for virtual link destination address
945 */
946 if (v->backlink >= 0)
paul718e3742002-12-13 20:15:29 +0000947 {
pauld355bfa2004-04-08 07:43:45 +0000948 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
949 &rl->link[v->backlink].link_data))
950 changed = 1;
951 vl_data->peer_addr = rl->link[v->backlink].link_data;
952 }
953 else
954 {
955 /* This is highly odd, there is no backlink index
956 * there should be due to the ospf_spf_has_link() check
957 * in SPF. Lets warn and try pick a link anyway.
958 */
959 zlog_warn ("ospf_vl_set_params: No backlink for %s!",
960 vl_data->vl_oi->ifp->name);
961 for (i = 0; i < ntohs (rl->links); i++)
paul2e6b0bb2003-06-22 08:17:12 +0000962 {
pauld355bfa2004-04-08 07:43:45 +0000963 switch (rl->link[i].type)
964 {
965 case LSA_LINK_TYPE_VIRTUALLINK:
966 if (IS_DEBUG_OSPF_EVENT)
967 zlog_info ("found back link through VL");
968 case LSA_LINK_TYPE_TRANSIT:
969 case LSA_LINK_TYPE_POINTOPOINT:
paulcd59da62004-05-05 17:26:55 +0000970 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
971 &rl->link[i].link_data))
972 changed = 1;
pauld355bfa2004-04-08 07:43:45 +0000973 vl_data->peer_addr = rl->link[i].link_data;
974 if (IS_DEBUG_OSPF_EVENT)
paulcd59da62004-05-05 17:26:55 +0000975 zlog_info ("ospf_vl_set_params: %s peer address is %s\n",
pauld355bfa2004-04-08 07:43:45 +0000976 vl_data->vl_oi->ifp->name,
977 inet_ntoa(vl_data->peer_addr));
978 return changed;
979 }
paul2e6b0bb2003-06-22 08:17:12 +0000980 }
paul718e3742002-12-13 20:15:29 +0000981 }
pauld355bfa2004-04-08 07:43:45 +0000982
983 if (IS_DEBUG_OSPF_EVENT)
984 zlog_info ("ospf_vl_set_params: %s peer address is %s\n",
985 vl_data->vl_oi->ifp->name,
986 inet_ntoa(vl_data->peer_addr));
987
paul2e6b0bb2003-06-22 08:17:12 +0000988 return changed;
paul718e3742002-12-13 20:15:29 +0000989}
990
991
992void
paul68980082003-03-25 05:07:42 +0000993ospf_vl_up_check (struct ospf_area *area, struct in_addr rid,
paul718e3742002-12-13 20:15:29 +0000994 struct vertex *v)
995{
paul68980082003-03-25 05:07:42 +0000996 struct ospf *ospf = area->ospf;
hasso52dc7ee2004-09-23 19:18:23 +0000997 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000998 struct ospf_vl_data *vl_data;
999 struct ospf_interface *oi;
1000
1001 if (IS_DEBUG_OSPF_EVENT)
1002 {
1003 zlog_info ("ospf_vl_up_check(): Start");
1004 zlog_info ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid));
1005 zlog_info ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id));
1006 }
1007
paul68980082003-03-25 05:07:42 +00001008 for (node = listhead (ospf->vlinks); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +00001009 {
1010 if ((vl_data = getdata (node)) == NULL)
1011 continue;
1012
1013 if (IS_DEBUG_OSPF_EVENT)
1014 {
1015 zlog_info ("ospf_vl_up_check(): considering VL, name: %s",
1016 vl_data->vl_oi->ifp->name);
1017 zlog_info ("ospf_vl_up_check(): VL area: %s, peer ID: %s",
1018 inet_ntoa (vl_data->vl_area_id),
1019 inet_ntoa (vl_data->vl_peer));
1020 }
1021
1022 if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) &&
1023 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1024 {
1025 oi = vl_data->vl_oi;
1026 SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
1027
1028 if (IS_DEBUG_OSPF_EVENT)
1029 zlog_info ("ospf_vl_up_check(): this VL matched");
1030
1031 if (oi->state == ISM_Down)
1032 {
1033 if (IS_DEBUG_OSPF_EVENT)
1034 zlog_info ("ospf_vl_up_check(): VL is down, waking it up");
1035 SET_FLAG (oi->ifp->flags, IFF_UP);
paul2e6b0bb2003-06-22 08:17:12 +00001036 OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp);
paul718e3742002-12-13 20:15:29 +00001037 }
1038
paul2e6b0bb2003-06-22 08:17:12 +00001039 if (ospf_vl_set_params (vl_data, v))
1040 {
1041 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
paulcd59da62004-05-05 17:26:55 +00001042 zlog_info ("ospf_vl_up_check: VL cost change,"
1043 " scheduling router lsa refresh");
paul2e6b0bb2003-06-22 08:17:12 +00001044 if(ospf->backbone)
paulcd59da62004-05-05 17:26:55 +00001045 ospf_router_lsa_timer_add (ospf->backbone);
paul2e6b0bb2003-06-22 08:17:12 +00001046 else if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
1047 zlog_info ("ospf_vl_up_check: VL cost change, no backbone!");
1048 }
paul718e3742002-12-13 20:15:29 +00001049 }
1050 }
1051}
1052
1053void
paul68980082003-03-25 05:07:42 +00001054ospf_vl_unapprove (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001055{
hasso52dc7ee2004-09-23 19:18:23 +00001056 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001057 struct ospf_vl_data *vl_data;
1058
paul68980082003-03-25 05:07:42 +00001059 for (node = listhead (ospf->vlinks); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +00001060 if ((vl_data = getdata (node)) != NULL)
1061 UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
1062}
1063
1064void
paul68980082003-03-25 05:07:42 +00001065ospf_vl_shut_unapproved (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001066{
hasso52dc7ee2004-09-23 19:18:23 +00001067 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001068 struct ospf_vl_data *vl_data;
1069
paul68980082003-03-25 05:07:42 +00001070 for (node = listhead (ospf->vlinks); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +00001071 if ((vl_data = getdata (node)) != NULL)
1072 if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
1073 ospf_vl_shutdown (vl_data);
1074}
1075
1076int
1077ospf_full_virtual_nbrs (struct ospf_area *area)
1078{
1079 if (IS_DEBUG_OSPF_EVENT)
1080 {
1081 zlog_info ("counting fully adjacent virtual neighbors in area %s",
1082 inet_ntoa (area->area_id));
1083 zlog_info ("there are %d of them", area->full_vls);
1084 }
1085
1086 return area->full_vls;
1087}
1088
1089int
1090ospf_vls_in_area (struct ospf_area *area)
1091{
hasso52dc7ee2004-09-23 19:18:23 +00001092 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001093 struct ospf_vl_data *vl_data;
1094 int c = 0;
1095
paul68980082003-03-25 05:07:42 +00001096 for (node = listhead (area->ospf->vlinks); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +00001097 if ((vl_data = getdata (node)) != NULL)
1098 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1099 c++;
1100
1101 return c;
1102}
1103
1104
1105struct crypt_key *
1106ospf_crypt_key_new ()
1107{
1108 struct crypt_key *ck;
1109
1110 ck = XMALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key));
1111 memset (ck, 0, sizeof (struct crypt_key));
1112
1113 return ck;
1114}
1115
1116void
hasso52dc7ee2004-09-23 19:18:23 +00001117ospf_crypt_key_add (struct list *crypt, struct crypt_key *ck)
paul718e3742002-12-13 20:15:29 +00001118{
1119 listnode_add (crypt, ck);
1120}
1121
1122struct crypt_key *
hasso52dc7ee2004-09-23 19:18:23 +00001123ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001124{
hasso52dc7ee2004-09-23 19:18:23 +00001125 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001126 struct crypt_key *ck;
1127
1128 for (node = listhead (auth_crypt); node; nextnode (node))
1129 {
1130 ck = getdata (node);
1131 if (ck->key_id == key_id)
1132 return ck;
1133 }
1134
1135 return NULL;
1136}
1137
1138int
hasso52dc7ee2004-09-23 19:18:23 +00001139ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001140{
hasso52dc7ee2004-09-23 19:18:23 +00001141 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001142 struct crypt_key *ck;
1143
1144 for (node = listhead (auth_crypt); node; nextnode (node))
1145 {
1146 ck = getdata (node);
1147 if (ck->key_id == key_id)
1148 {
1149 listnode_delete (auth_crypt, ck);
1150 return 1;
1151 }
1152 }
1153
1154 return 0;
1155}
1156
1157void
1158ospf_if_init ()
1159{
1160 /* Initialize Zebra interface data structure. */
1161 if_init ();
paul020709f2003-04-04 02:44:16 +00001162 om->iflist = iflist;
paul718e3742002-12-13 20:15:29 +00001163 if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
1164 if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);
1165}