blob: e74c375ad16dcb76ba7c2f172bd7910c1d1c294b [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
hasso3fb9cd62004-10-19 19:44:43 +0000341* return it if yes. special treatment for PtP networks.
paul718e3742002-12-13 20:15:29 +0000342*/
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;
hasso3fb9cd62004-10-19 19:44:43 +0000348 struct prefix_ipv4 addr;
349
350 addr.family = AF_INET;
351 addr.prefix = *address;
352 addr.prefixlen = IPV4_MAX_PREFIXLEN;
paul718e3742002-12-13 20:15:29 +0000353
paul68980082003-03-25 05:07:42 +0000354 for (node = listhead (ospf->oiflist); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +0000355 if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
356 {
357 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
hasso3fb9cd62004-10-19 19:44:43 +0000358 {
359 if (CONNECTED_DEST_HOST(oi->connected))
360 {
361 /* match only destination addr, since local addr is most likely
362 * not unique (borrowed from another interface) */
363 if (IPV4_ADDR_SAME (address,
364 &oi->connected->destination->u.prefix4))
365 return oi;
366 }
367 else
368 {
369 /* special leniency: match if addr is anywhere on PtP subnet */
370 if (prefix_match(oi->address,(struct prefix *)&addr))
371 return oi;
372 }
373 }
paul718e3742002-12-13 20:15:29 +0000374 else
hasso3fb9cd62004-10-19 19:44:43 +0000375 {
376 if (IPV4_ADDR_SAME (address, &oi->address->u.prefix4))
377 return oi;
378 }
paul718e3742002-12-13 20:15:29 +0000379 }
paul718e3742002-12-13 20:15:29 +0000380 return NULL;
381}
382
383int
384ospf_if_is_up (struct ospf_interface *oi)
385{
386 return if_is_up (oi->ifp);
387}
388
389struct ospf_interface *
hasso2db3d052004-02-11 21:52:13 +0000390ospf_if_exists (struct ospf_interface *oic)
391{
hasso52dc7ee2004-09-23 19:18:23 +0000392 struct listnode *node;
hasso2db3d052004-02-11 21:52:13 +0000393 struct ospf *ospf;
394 struct ospf_interface *oi;
395
396 ospf = ospf_lookup ();
397
398 for (node = listhead (ospf->oiflist); node; nextnode (node))
399 {
400 if (((oi = getdata (node)) != NULL) && (oi == oic))
401 return oi;
402 }
403 return NULL;
404}
405
406struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000407ospf_if_lookup_by_local_addr (struct ospf *ospf,
408 struct interface *ifp, struct in_addr address)
paul718e3742002-12-13 20:15:29 +0000409{
hasso52dc7ee2004-09-23 19:18:23 +0000410 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000411 struct ospf_interface *oi;
412
paul68980082003-03-25 05:07:42 +0000413 for (node = listhead (ospf->oiflist); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +0000414 if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
415 {
416 if (ifp && oi->ifp != ifp)
417 continue;
418
419 if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4))
420 return oi;
421 }
422
423 return NULL;
424}
425
426struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000427ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000428{
hasso52dc7ee2004-09-23 19:18:23 +0000429 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000430 struct ospf_interface *oi;
431 struct prefix ptmp;
432
433 /* Check each Interface. */
paul68980082003-03-25 05:07:42 +0000434 for (node = listhead (ospf->oiflist); node; nextnode (node))
435 {
436 if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
437 {
hasso3fb9cd62004-10-19 19:44:43 +0000438 if ((oi->type == OSPF_IFTYPE_POINTOPOINT) &&
439 CONNECTED_DEST_HOST(oi->connected))
paul68980082003-03-25 05:07:42 +0000440 {
441 prefix_copy (&ptmp, oi->connected->destination);
442 ptmp.prefixlen = IPV4_MAX_BITLEN;
443 }
444 else
445 prefix_copy (&ptmp, oi->address);
paul718e3742002-12-13 20:15:29 +0000446
paul68980082003-03-25 05:07:42 +0000447 apply_mask (&ptmp);
448 if (prefix_same (&ptmp, (struct prefix *) p))
449 return oi;
450 }
451 }
paul718e3742002-12-13 20:15:29 +0000452 return NULL;
453}
454
455/* determine receiving interface by source of packet */
456struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000457ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src)
paul718e3742002-12-13 20:15:29 +0000458{
hasso52dc7ee2004-09-23 19:18:23 +0000459 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000460 struct prefix_ipv4 addr;
461 struct ospf_interface *oi, *match;
462
463 addr.family = AF_INET;
464 addr.prefix = src;
465 addr.prefixlen = IPV4_MAX_BITLEN;
466
467 match = NULL;
468
paul68980082003-03-25 05:07:42 +0000469 for (node = listhead (ospf->oiflist); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +0000470 {
471 oi = getdata (node);
472
473 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
474 continue;
475
hasso3fb9cd62004-10-19 19:44:43 +0000476 if ((oi->type == OSPF_IFTYPE_POINTOPOINT) &&
477 CONNECTED_DEST_HOST(oi->connected))
paul718e3742002-12-13 20:15:29 +0000478 {
479 if (IPV4_ADDR_SAME (&oi->connected->destination->u.prefix4, &src))
480 return oi;
481 }
482 else
483 {
484 if (prefix_match (oi->address, (struct prefix *) &addr))
paul0a825c72003-05-24 13:48:16 +0000485 {
paulaf8d0332003-05-24 15:31:45 +0000486 if ( (match == NULL) ||
487 (match->address->prefixlen < oi->address->prefixlen)
488 )
paul0a825c72003-05-24 13:48:16 +0000489 match = oi;
490 }
paul718e3742002-12-13 20:15:29 +0000491 }
492 }
493
494 return match;
495}
496
497void
498ospf_if_stream_set (struct ospf_interface *oi)
499{
500 /* set output fifo queue. */
501 if (oi->obuf == NULL)
502 oi->obuf = ospf_fifo_new ();
503}
504
505void
506ospf_if_stream_unset (struct ospf_interface *oi)
507{
paul68980082003-03-25 05:07:42 +0000508 struct ospf *ospf = oi->ospf;
509
paul718e3742002-12-13 20:15:29 +0000510 if (oi->obuf)
511 {
512 ospf_fifo_free (oi->obuf);
513 oi->obuf = NULL;
514
515 if (oi->on_write_q)
516 {
paul68980082003-03-25 05:07:42 +0000517 listnode_delete (ospf->oi_write_q, oi);
518 if (list_isempty(ospf->oi_write_q))
519 OSPF_TIMER_OFF (ospf->t_write);
paul718e3742002-12-13 20:15:29 +0000520 oi->on_write_q = 0;
521 }
522 }
523}
paul68980082003-03-25 05:07:42 +0000524
paul718e3742002-12-13 20:15:29 +0000525
526struct ospf_if_params *
527ospf_new_if_params ()
528{
529 struct ospf_if_params *oip;
530
531 oip = XMALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params));
paul718e3742002-12-13 20:15:29 +0000532
533 if (!oip)
534 return NULL;
535
paulf6457892003-04-17 16:11:30 +0000536 memset (oip, 0, sizeof (struct ospf_if_params));
537
paul718e3742002-12-13 20:15:29 +0000538 UNSET_IF_PARAM (oip, output_cost_cmd);
539 UNSET_IF_PARAM (oip, transmit_delay);
540 UNSET_IF_PARAM (oip, retransmit_interval);
541 UNSET_IF_PARAM (oip, passive_interface);
542 UNSET_IF_PARAM (oip, v_hello);
543 UNSET_IF_PARAM (oip, v_wait);
544 UNSET_IF_PARAM (oip, priority);
545 UNSET_IF_PARAM (oip, type);
546 UNSET_IF_PARAM (oip, auth_simple);
547 UNSET_IF_PARAM (oip, auth_crypt);
548 UNSET_IF_PARAM (oip, auth_type);
paulec1ca632003-06-04 02:23:15 +0000549
550 oip->auth_crypt = list_new ();
paul718e3742002-12-13 20:15:29 +0000551
paul718e3742002-12-13 20:15:29 +0000552 return oip;
553}
554
555void
556ospf_del_if_params (struct ospf_if_params *oip)
557{
558 list_delete (oip->auth_crypt);
559 XFREE (MTYPE_OSPF_IF_PARAMS, oip);
560}
561
562void
563ospf_free_if_params (struct interface *ifp, struct in_addr addr)
564{
565 struct ospf_if_params *oip;
566 struct prefix_ipv4 p;
567 struct route_node *rn;
gdt630e4802004-08-31 17:28:41 +0000568
569 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000570 p.prefixlen = IPV4_MAX_PREFIXLEN;
571 p.prefix = addr;
572 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
573 if (!rn || !rn->info)
574 return;
575
576 oip = rn->info;
577 route_unlock_node (rn);
578
579 if (!OSPF_IF_PARAM_CONFIGURED (oip, output_cost_cmd) &&
580 !OSPF_IF_PARAM_CONFIGURED (oip, transmit_delay) &&
581 !OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) &&
582 !OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) &&
583 !OSPF_IF_PARAM_CONFIGURED (oip, v_hello) &&
584 !OSPF_IF_PARAM_CONFIGURED (oip, v_wait) &&
585 !OSPF_IF_PARAM_CONFIGURED (oip, priority) &&
586 !OSPF_IF_PARAM_CONFIGURED (oip, type) &&
587 !OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) &&
588 !OSPF_IF_PARAM_CONFIGURED (oip, auth_type) &&
589 listcount (oip->auth_crypt) == 0)
590 {
591 ospf_del_if_params (oip);
592 rn->info = NULL;
593 route_unlock_node (rn);
594 }
595}
596
597struct ospf_if_params *
598ospf_lookup_if_params (struct interface *ifp, struct in_addr addr)
599{
600 struct prefix_ipv4 p;
601 struct route_node *rn;
602
gdt630e4802004-08-31 17:28:41 +0000603 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000604 p.prefixlen = IPV4_MAX_PREFIXLEN;
605 p.prefix = addr;
606
607 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
608
609 if (rn)
610 {
611 route_unlock_node (rn);
612 return rn->info;
613 }
614
615 return NULL;
616}
617
618struct ospf_if_params *
619ospf_get_if_params (struct interface *ifp, struct in_addr addr)
620{
621 struct prefix_ipv4 p;
622 struct route_node *rn;
623
624 p.family = AF_INET;
625 p.prefixlen = IPV4_MAX_PREFIXLEN;
626 p.prefix = addr;
627
628 rn = route_node_get (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
629
630 if (rn->info == NULL)
631 rn->info = ospf_new_if_params ();
632 else
633 route_unlock_node (rn);
634
635 return rn->info;
636}
637
638void
639ospf_if_update_params (struct interface *ifp, struct in_addr addr)
640{
641 struct route_node *rn;
642 struct ospf_interface *oi;
643
644 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
645 {
646 if ((oi = rn->info) == NULL)
647 continue;
648
649 if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &addr))
650 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
651 }
652}
653
654int
655ospf_if_new_hook (struct interface *ifp)
656{
657 int rc = 0;
658
659 ifp->info = XMALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info));
660 memset (ifp->info, 0, sizeof (struct ospf_if_info));
661
662 IF_OIFS (ifp) = route_table_init ();
663 IF_OIFS_PARAMS (ifp) = route_table_init ();
664
665 IF_DEF_PARAMS (ifp) = ospf_new_if_params ();
666
667 SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay);
668 IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
669
670 SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval);
671 IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
672
673 SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority);
674 IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
675
676 SET_IF_PARAM (IF_DEF_PARAMS (ifp), passive_interface);
677 IF_DEF_PARAMS (ifp)->passive_interface = OSPF_IF_ACTIVE;
678
679 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello);
680 IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
681
682 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait);
683 IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
684
685 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple);
686 memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
687
paul718e3742002-12-13 20:15:29 +0000688 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type);
689 IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET;
690
691#ifdef HAVE_OPAQUE_LSA
692 rc = ospf_opaque_new_if (ifp);
693#endif /* HAVE_OPAQUE_LSA */
694 return rc;
695}
696
697int
698ospf_if_delete_hook (struct interface *ifp)
699{
700 int rc = 0;
paul940b01a2004-02-17 20:07:30 +0000701 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +0000702#ifdef HAVE_OPAQUE_LSA
703 rc = ospf_opaque_del_if (ifp);
704#endif /* HAVE_OPAQUE_LSA */
paul940b01a2004-02-17 20:07:30 +0000705
paul718e3742002-12-13 20:15:29 +0000706 route_table_finish (IF_OIFS (ifp));
paul940b01a2004-02-17 20:07:30 +0000707
708 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
709 if (rn->info)
710 ospf_del_if_params (rn->info);
paul718e3742002-12-13 20:15:29 +0000711 route_table_finish (IF_OIFS_PARAMS (ifp));
paul940b01a2004-02-17 20:07:30 +0000712
paulcfc959b2003-06-04 02:28:45 +0000713 ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp));
paul718e3742002-12-13 20:15:29 +0000714 XFREE (MTYPE_OSPF_IF_INFO, ifp->info);
715 ifp->info = NULL;
716
717 return rc;
718}
719
720int
721ospf_if_is_enable (struct ospf_interface *oi)
722{
723 if (!if_is_loopback (oi->ifp))
724 if (if_is_up (oi->ifp))
725 return 1;
726
727 return 0;
728}
729
730int
731ospf_if_up (struct ospf_interface *oi)
732{
733 if (oi == NULL)
734 return 0;
735
736 if (oi->type == OSPF_IFTYPE_LOOPBACK)
737 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd);
738 else
739 {
740 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul68980082003-03-25 05:07:42 +0000741 ospf_if_add_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex);
paul718e3742002-12-13 20:15:29 +0000742 ospf_if_stream_set (oi);
743 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp);
744 }
745
746 return 1;
747}
748
749int
750ospf_if_down (struct ospf_interface *oi)
751{
752 if (oi == NULL)
753 return 0;
754
755 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
756 /* Shutdown packet reception and sending */
757 ospf_if_stream_unset (oi);
758 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul68980082003-03-25 05:07:42 +0000759 ospf_if_drop_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex);
paul718e3742002-12-13 20:15:29 +0000760
761
762 return 1;
763}
764
765
766/* Virtual Link related functions. */
767
768struct ospf_vl_data *
769ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer)
770{
771 struct ospf_vl_data *vl_data;
772
773 vl_data = XMALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data));
774 memset (vl_data, 0, sizeof (struct ospf_vl_data));
775
776 vl_data->vl_peer.s_addr = vl_peer.s_addr;
777 vl_data->vl_area_id = area->area_id;
778 vl_data->format = area->format;
779
780 return vl_data;
781}
782
783void
784ospf_vl_data_free (struct ospf_vl_data *vl_data)
785{
786 XFREE (MTYPE_OSPF_VL_DATA, vl_data);
787}
788
789u_int vlink_count = 0;
790
791struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000792ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000793{
794 struct ospf_interface * voi;
795 struct interface * vi;
796 char ifname[INTERFACE_NAMSIZ + 1];
797 struct ospf_area *area;
798 struct in_addr area_id;
799 struct connected *co;
800 struct prefix_ipv4 *p;
801
802 if (IS_DEBUG_OSPF_EVENT)
803 zlog_info ("ospf_vl_new(): Start");
804 if (vlink_count == OSPF_VL_MAX_COUNT)
805 {
806 if (IS_DEBUG_OSPF_EVENT)
807 zlog_info ("ospf_vl_new(): Alarm: "
808 "cannot create more than OSPF_MAX_VL_COUNT virtual links");
809 return NULL;
810 }
811
812 if (IS_DEBUG_OSPF_EVENT)
813 zlog_info ("ospf_vl_new(): creating pseudo zebra interface");
814
paul106d2fd2003-08-01 00:24:13 +0000815 snprintf (ifname, INTERFACE_NAMSIZ + 1, "VLINK%d", vlink_count);
816 vi = if_create (ifname, INTERFACE_NAMSIZ);
paul718e3742002-12-13 20:15:29 +0000817 co = connected_new ();
818 co->ifp = vi;
819 listnode_add (vi->connected, co);
820
821 p = prefix_ipv4_new ();
822 p->family = AF_INET;
823 p->prefix.s_addr = 0;
824 p->prefixlen = 0;
825
826 co->address = (struct prefix *)p;
827
paul68980082003-03-25 05:07:42 +0000828 voi = ospf_if_new (ospf, vi, co->address);
paul718e3742002-12-13 20:15:29 +0000829 if (voi == NULL)
830 {
831 if (IS_DEBUG_OSPF_EVENT)
832 zlog_info ("ospf_vl_new(): Alarm: OSPF int structure is not created");
833 return NULL;
834 }
835 voi->connected = co;
836 voi->vl_data = vl_data;
837 voi->ifp->mtu = OSPF_VL_MTU;
838 voi->type = OSPF_IFTYPE_VIRTUALLINK;
839
paul106d2fd2003-08-01 00:24:13 +0000840 vlink_count++;
paul718e3742002-12-13 20:15:29 +0000841 if (IS_DEBUG_OSPF_EVENT)
842 zlog_info ("ospf_vl_new(): Created name: %s", ifname);
paul718e3742002-12-13 20:15:29 +0000843 if (IS_DEBUG_OSPF_EVENT)
844 zlog_info ("ospf_vl_new(): set if->name to %s", vi->name);
845
846 area_id.s_addr = 0;
paul68980082003-03-25 05:07:42 +0000847 area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS);
paul718e3742002-12-13 20:15:29 +0000848 voi->area = area;
849
850 if (IS_DEBUG_OSPF_EVENT)
851 zlog_info ("ospf_vl_new(): set associated area to the backbone");
852
853 ospf_area_add_if (voi->area, voi);
854
855 ospf_if_stream_set (voi);
856
857 if (IS_DEBUG_OSPF_EVENT)
858 zlog_info ("ospf_vl_new(): Stop");
859 return voi;
860}
861
862void
863ospf_vl_if_delete (struct ospf_vl_data *vl_data)
864{
865 struct interface *ifp = vl_data->vl_oi->ifp;
866 vl_data->vl_oi->address->u.prefix4.s_addr = 0;
867 vl_data->vl_oi->address->prefixlen = 0;
868 ospf_if_free (vl_data->vl_oi);
869 if_delete (ifp);
870 vlink_count--;
871}
872
873struct ospf_vl_data *
874ospf_vl_lookup (struct ospf_area *area, struct in_addr vl_peer)
875{
876 struct ospf_vl_data *vl_data;
hasso52dc7ee2004-09-23 19:18:23 +0000877 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000878
paul68980082003-03-25 05:07:42 +0000879 for (node = listhead (area->ospf->vlinks); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +0000880 if ((vl_data = getdata (node)) != NULL)
881 if (vl_data->vl_peer.s_addr == vl_peer.s_addr &&
882 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
883 return vl_data;
884
885 return NULL;
886}
887
888void
889ospf_vl_shutdown (struct ospf_vl_data *vl_data)
890{
891 struct ospf_interface *oi;
892
893 if ((oi = vl_data->vl_oi) == NULL)
894 return;
895
896 oi->address->u.prefix4.s_addr = 0;
897 oi->address->prefixlen = 0;
898
899 UNSET_FLAG (oi->ifp->flags, IFF_UP);
900 /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */
901 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
902}
903
904void
paul68980082003-03-25 05:07:42 +0000905ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000906{
paul68980082003-03-25 05:07:42 +0000907 listnode_add (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000908#ifdef HAVE_SNMP
909 ospf_snmp_vl_add (vl_data);
910#endif /* HAVE_SNMP */
911}
912
913void
paul68980082003-03-25 05:07:42 +0000914ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000915{
916 ospf_vl_shutdown (vl_data);
917 ospf_vl_if_delete (vl_data);
918
919#ifdef HAVE_SNMP
920 ospf_snmp_vl_delete (vl_data);
921#endif /* HAVE_SNMP */
paul68980082003-03-25 05:07:42 +0000922 listnode_delete (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000923
924 ospf_vl_data_free (vl_data);
925}
926
paul2e6b0bb2003-06-22 08:17:12 +0000927int
paul718e3742002-12-13 20:15:29 +0000928ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v)
929{
930 int changed = 0;
931 struct ospf_interface *voi;
hasso52dc7ee2004-09-23 19:18:23 +0000932 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000933 struct vertex_nexthop *nh;
934 int i;
935 struct router_lsa *rl;
936
937 voi = vl_data->vl_oi;
938
939 if (voi->output_cost != v->distance)
940 {
paulcd59da62004-05-05 17:26:55 +0000941
paul718e3742002-12-13 20:15:29 +0000942 voi->output_cost = v->distance;
943 changed = 1;
944 }
945
946 for (node = listhead (v->nexthop); node; nextnode (node))
947 if ((nh = getdata (node)) != NULL)
948 {
paulcd59da62004-05-05 17:26:55 +0000949 vl_data->out_oi = (struct ospf_interface *) nh->oi;
950
951 if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
952 &vl_data->out_oi->address->u.prefix4))
953 changed = 1;
954
955 voi->address->u.prefix4 = vl_data->out_oi->address->u.prefix4;
956 voi->address->prefixlen = vl_data->out_oi->address->prefixlen;
paul718e3742002-12-13 20:15:29 +0000957
paulcd59da62004-05-05 17:26:55 +0000958 break; /* We take the first interface. */
paul718e3742002-12-13 20:15:29 +0000959 }
960
961 rl = (struct router_lsa *)v->lsa;
pauld355bfa2004-04-08 07:43:45 +0000962
963 /* use SPF determined backlink index in struct vertex
964 * for virtual link destination address
965 */
966 if (v->backlink >= 0)
paul718e3742002-12-13 20:15:29 +0000967 {
pauld355bfa2004-04-08 07:43:45 +0000968 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
969 &rl->link[v->backlink].link_data))
970 changed = 1;
971 vl_data->peer_addr = rl->link[v->backlink].link_data;
972 }
973 else
974 {
975 /* This is highly odd, there is no backlink index
976 * there should be due to the ospf_spf_has_link() check
977 * in SPF. Lets warn and try pick a link anyway.
978 */
979 zlog_warn ("ospf_vl_set_params: No backlink for %s!",
980 vl_data->vl_oi->ifp->name);
981 for (i = 0; i < ntohs (rl->links); i++)
paul2e6b0bb2003-06-22 08:17:12 +0000982 {
pauld355bfa2004-04-08 07:43:45 +0000983 switch (rl->link[i].type)
984 {
985 case LSA_LINK_TYPE_VIRTUALLINK:
986 if (IS_DEBUG_OSPF_EVENT)
987 zlog_info ("found back link through VL");
988 case LSA_LINK_TYPE_TRANSIT:
989 case LSA_LINK_TYPE_POINTOPOINT:
paulcd59da62004-05-05 17:26:55 +0000990 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
991 &rl->link[i].link_data))
992 changed = 1;
pauld355bfa2004-04-08 07:43:45 +0000993 vl_data->peer_addr = rl->link[i].link_data;
994 if (IS_DEBUG_OSPF_EVENT)
paulcd59da62004-05-05 17:26:55 +0000995 zlog_info ("ospf_vl_set_params: %s peer address is %s\n",
pauld355bfa2004-04-08 07:43:45 +0000996 vl_data->vl_oi->ifp->name,
997 inet_ntoa(vl_data->peer_addr));
998 return changed;
999 }
paul2e6b0bb2003-06-22 08:17:12 +00001000 }
paul718e3742002-12-13 20:15:29 +00001001 }
pauld355bfa2004-04-08 07:43:45 +00001002
1003 if (IS_DEBUG_OSPF_EVENT)
1004 zlog_info ("ospf_vl_set_params: %s peer address is %s\n",
1005 vl_data->vl_oi->ifp->name,
1006 inet_ntoa(vl_data->peer_addr));
1007
paul2e6b0bb2003-06-22 08:17:12 +00001008 return changed;
paul718e3742002-12-13 20:15:29 +00001009}
1010
1011
1012void
paul68980082003-03-25 05:07:42 +00001013ospf_vl_up_check (struct ospf_area *area, struct in_addr rid,
paul718e3742002-12-13 20:15:29 +00001014 struct vertex *v)
1015{
paul68980082003-03-25 05:07:42 +00001016 struct ospf *ospf = area->ospf;
hasso52dc7ee2004-09-23 19:18:23 +00001017 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001018 struct ospf_vl_data *vl_data;
1019 struct ospf_interface *oi;
1020
1021 if (IS_DEBUG_OSPF_EVENT)
1022 {
1023 zlog_info ("ospf_vl_up_check(): Start");
1024 zlog_info ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid));
1025 zlog_info ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id));
1026 }
1027
paul68980082003-03-25 05:07:42 +00001028 for (node = listhead (ospf->vlinks); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +00001029 {
1030 if ((vl_data = getdata (node)) == NULL)
1031 continue;
1032
1033 if (IS_DEBUG_OSPF_EVENT)
1034 {
1035 zlog_info ("ospf_vl_up_check(): considering VL, name: %s",
1036 vl_data->vl_oi->ifp->name);
1037 zlog_info ("ospf_vl_up_check(): VL area: %s, peer ID: %s",
1038 inet_ntoa (vl_data->vl_area_id),
1039 inet_ntoa (vl_data->vl_peer));
1040 }
1041
1042 if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) &&
1043 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1044 {
1045 oi = vl_data->vl_oi;
1046 SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
1047
1048 if (IS_DEBUG_OSPF_EVENT)
1049 zlog_info ("ospf_vl_up_check(): this VL matched");
1050
1051 if (oi->state == ISM_Down)
1052 {
1053 if (IS_DEBUG_OSPF_EVENT)
1054 zlog_info ("ospf_vl_up_check(): VL is down, waking it up");
1055 SET_FLAG (oi->ifp->flags, IFF_UP);
paul2e6b0bb2003-06-22 08:17:12 +00001056 OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp);
paul718e3742002-12-13 20:15:29 +00001057 }
1058
paul2e6b0bb2003-06-22 08:17:12 +00001059 if (ospf_vl_set_params (vl_data, v))
1060 {
1061 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
paulcd59da62004-05-05 17:26:55 +00001062 zlog_info ("ospf_vl_up_check: VL cost change,"
1063 " scheduling router lsa refresh");
paul2e6b0bb2003-06-22 08:17:12 +00001064 if(ospf->backbone)
paulcd59da62004-05-05 17:26:55 +00001065 ospf_router_lsa_timer_add (ospf->backbone);
paul2e6b0bb2003-06-22 08:17:12 +00001066 else if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
1067 zlog_info ("ospf_vl_up_check: VL cost change, no backbone!");
1068 }
paul718e3742002-12-13 20:15:29 +00001069 }
1070 }
1071}
1072
1073void
paul68980082003-03-25 05:07:42 +00001074ospf_vl_unapprove (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001075{
hasso52dc7ee2004-09-23 19:18:23 +00001076 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001077 struct ospf_vl_data *vl_data;
1078
paul68980082003-03-25 05:07:42 +00001079 for (node = listhead (ospf->vlinks); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +00001080 if ((vl_data = getdata (node)) != NULL)
1081 UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
1082}
1083
1084void
paul68980082003-03-25 05:07:42 +00001085ospf_vl_shut_unapproved (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001086{
hasso52dc7ee2004-09-23 19:18:23 +00001087 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001088 struct ospf_vl_data *vl_data;
1089
paul68980082003-03-25 05:07:42 +00001090 for (node = listhead (ospf->vlinks); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +00001091 if ((vl_data = getdata (node)) != NULL)
1092 if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
1093 ospf_vl_shutdown (vl_data);
1094}
1095
1096int
1097ospf_full_virtual_nbrs (struct ospf_area *area)
1098{
1099 if (IS_DEBUG_OSPF_EVENT)
1100 {
1101 zlog_info ("counting fully adjacent virtual neighbors in area %s",
1102 inet_ntoa (area->area_id));
1103 zlog_info ("there are %d of them", area->full_vls);
1104 }
1105
1106 return area->full_vls;
1107}
1108
1109int
1110ospf_vls_in_area (struct ospf_area *area)
1111{
hasso52dc7ee2004-09-23 19:18:23 +00001112 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001113 struct ospf_vl_data *vl_data;
1114 int c = 0;
1115
paul68980082003-03-25 05:07:42 +00001116 for (node = listhead (area->ospf->vlinks); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +00001117 if ((vl_data = getdata (node)) != NULL)
1118 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1119 c++;
1120
1121 return c;
1122}
1123
1124
1125struct crypt_key *
1126ospf_crypt_key_new ()
1127{
1128 struct crypt_key *ck;
1129
1130 ck = XMALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key));
1131 memset (ck, 0, sizeof (struct crypt_key));
1132
1133 return ck;
1134}
1135
1136void
hasso52dc7ee2004-09-23 19:18:23 +00001137ospf_crypt_key_add (struct list *crypt, struct crypt_key *ck)
paul718e3742002-12-13 20:15:29 +00001138{
1139 listnode_add (crypt, ck);
1140}
1141
1142struct crypt_key *
hasso52dc7ee2004-09-23 19:18:23 +00001143ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001144{
hasso52dc7ee2004-09-23 19:18:23 +00001145 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001146 struct crypt_key *ck;
1147
1148 for (node = listhead (auth_crypt); node; nextnode (node))
1149 {
1150 ck = getdata (node);
1151 if (ck->key_id == key_id)
1152 return ck;
1153 }
1154
1155 return NULL;
1156}
1157
1158int
hasso52dc7ee2004-09-23 19:18:23 +00001159ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001160{
hasso52dc7ee2004-09-23 19:18:23 +00001161 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001162 struct crypt_key *ck;
1163
1164 for (node = listhead (auth_crypt); node; nextnode (node))
1165 {
1166 ck = getdata (node);
1167 if (ck->key_id == key_id)
1168 {
1169 listnode_delete (auth_crypt, ck);
1170 return 1;
1171 }
1172 }
1173
1174 return 0;
1175}
1176
1177void
1178ospf_if_init ()
1179{
1180 /* Initialize Zebra interface data structure. */
1181 if_init ();
paul020709f2003-04-04 02:44:16 +00001182 om->iflist = iflist;
paul718e3742002-12-13 20:15:29 +00001183 if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
1184 if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);
1185}