]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_interface.c
zebra: Export zclient_socket_un().
[mirror_frr.git] / ospfd / ospf_interface.c
CommitLineData
718e3744 1/*
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"
c0325cfa 34#include "zclient.h"
7f342629 35#include "bfd.h"
718e3744 36
68980084 37#include "ospfd/ospfd.h"
718e3744 38#include "ospfd/ospf_spf.h"
39#include "ospfd/ospf_interface.h"
40#include "ospfd/ospf_ism.h"
41#include "ospfd/ospf_asbr.h"
42#include "ospfd/ospf_lsa.h"
43#include "ospfd/ospf_lsdb.h"
44#include "ospfd/ospf_neighbor.h"
45#include "ospfd/ospf_nsm.h"
46#include "ospfd/ospf_packet.h"
47#include "ospfd/ospf_abr.h"
718e3744 48#include "ospfd/ospf_network.h"
49#include "ospfd/ospf_dump.h"
50#ifdef HAVE_SNMP
51#include "ospfd/ospf_snmp.h"
52#endif /* HAVE_SNMP */
53
6b0655a2 54
718e3744 55int
56ospf_if_get_output_cost (struct ospf_interface *oi)
57{
58 /* If all else fails, use default OSPF cost */
59 u_int32_t cost;
60 u_int32_t bw, refbw;
61
62 bw = oi->ifp->bandwidth ? oi->ifp->bandwidth : OSPF_DEFAULT_BANDWIDTH;
68980084 63 refbw = oi->ospf->ref_bandwidth;
718e3744 64
65 /* A specifed ip ospf cost overrides a calculated one. */
66 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (oi->ifp), output_cost_cmd) ||
67 OSPF_IF_PARAM_CONFIGURED (oi->params, output_cost_cmd))
68 cost = OSPF_IF_PARAM (oi, output_cost_cmd);
69 /* See if a cost can be calculated from the zebra processes
70 interface bandwidth field. */
71 else
72 {
73 cost = (u_int32_t) ((double)refbw / (double)bw + (double)0.5);
74 if (cost < 1)
75 cost = 1;
76 else if (cost > 65535)
77 cost = 65535;
78 }
79
80 return cost;
81}
82
83void
84ospf_if_recalculate_output_cost (struct interface *ifp)
85{
86 u_int32_t newcost;
87 struct route_node *rn;
88
89 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
90 {
91 struct ospf_interface *oi;
92
93 if ( (oi = rn->info) == NULL)
94 continue;
95
96 newcost = ospf_if_get_output_cost (oi);
97
98 /* Is actual output cost changed? */
99 if (oi->output_cost != newcost)
100 {
101 oi->output_cost = newcost;
c363d386 102 ospf_router_lsa_update_area (oi->area);
718e3744 103 }
104 }
105}
106
a608bbf2 107/* Simulate down/up on the interface. This is needed, for example, when
108 the MTU changes. */
109void
110ospf_if_reset(struct interface *ifp)
111{
112 struct route_node *rn;
113
114 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
115 {
116 struct ospf_interface *oi;
117
118 if ( (oi = rn->info) == NULL)
119 continue;
120
121 ospf_if_down(oi);
122 ospf_if_up(oi);
123 }
124}
125
718e3744 126void
127ospf_if_reset_variables (struct ospf_interface *oi)
128{
129 /* Set default values. */
130 /* don't clear this flag. oi->flag = OSPF_IF_DISABLE; */
131
132 if (oi->vl_data)
133 oi->type = OSPF_IFTYPE_VIRTUALLINK;
134 else
135 /* preserve network-type */
136 if (oi->type != OSPF_IFTYPE_NBMA)
137 oi->type = OSPF_IFTYPE_BROADCAST;
138
139 oi->state = ISM_Down;
140
141 oi->crypt_seqnum = 0;
142
143 /* This must be short, (less than RxmtInterval)
144 - RFC 2328 Section 13.5 para 3. Set to 1 second to avoid Acks being
145 held back for too long - MAG */
146 oi->v_ls_ack = 1;
147}
148
20916fba 149/* lookup oi for specified prefix/ifp */
f0f63841 150struct ospf_interface *
20916fba 151ospf_if_table_lookup (struct interface *ifp, struct prefix *prefix)
152{
153 struct prefix p;
affe1d9c 154 struct route_node *rn;
a3387a44 155 struct ospf_interface *rninfo = NULL;
20916fba 156
157 p = *prefix;
a3387a44 158 p.prefixlen = IPV4_MAX_PREFIXLEN;
159
20916fba 160 /* route_node_get implicitely locks */
f9ad937f 161 if ((rn = route_node_lookup (IF_OIFS (ifp), &p)))
a3387a44 162 {
163 rninfo = (struct ospf_interface *) rn->info;
164 route_unlock_node (rn);
165 }
166
b5f2c126 167 return rninfo;
20916fba 168}
169
4dadc291 170static void
718e3744 171ospf_add_to_if (struct interface *ifp, struct ospf_interface *oi)
172{
173 struct route_node *rn;
174 struct prefix p;
175
176 p = *oi->address;
177 p.prefixlen = IPV4_MAX_PREFIXLEN;
178
179 rn = route_node_get (IF_OIFS (ifp), &p);
8c80cb7e 180 /* rn->info should either be NULL or equal to this oi
181 * as route_node_get may return an existing node
182 */
20916fba 183 assert (!rn->info || rn->info == oi);
718e3744 184 rn->info = oi;
185}
186
4dadc291 187static void
718e3744 188ospf_delete_from_if (struct interface *ifp, struct ospf_interface *oi)
189{
190 struct route_node *rn;
191 struct prefix p;
192
193 p = *oi->address;
194 p.prefixlen = IPV4_MAX_PREFIXLEN;
195
196 rn = route_node_lookup (IF_OIFS (oi->ifp), &p);
197 assert (rn);
198 assert (rn->info);
199 rn->info = NULL;
200 route_unlock_node (rn);
201 route_unlock_node (rn);
202}
203
204struct ospf_interface *
68980084 205ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p)
718e3744 206{
207 struct ospf_interface *oi;
208
20916fba 209 if ((oi = ospf_if_table_lookup (ifp, p)) == NULL)
210 {
211 oi = XCALLOC (MTYPE_OSPF_IF, sizeof (struct ospf_interface));
212 memset (oi, 0, sizeof (struct ospf_interface));
213 }
214 else
215 return oi;
216
718e3744 217 /* Set zebra interface pointer. */
218 oi->ifp = ifp;
219 oi->address = p;
220
221 ospf_add_to_if (ifp, oi);
68980084 222 listnode_add (ospf->oiflist, oi);
718e3744 223
718e3744 224 /* Initialize neighbor list. */
225 oi->nbrs = route_table_init ();
226
227 /* Initialize static neighbor list. */
228 oi->nbr_nbma = list_new ();
229
230 /* Initialize Link State Acknowledgment list. */
231 oi->ls_ack = list_new ();
232 oi->ls_ack_direct.ls_ack = list_new ();
233
234 /* Set default values. */
235 ospf_if_reset_variables (oi);
236
237 /* Add pseudo neighbor. */
238 oi->nbr_self = ospf_nbr_new (oi);
718e3744 239
240 oi->ls_upd_queue = route_table_init ();
241 oi->t_ls_upd_event = NULL;
242 oi->t_ls_ack_direct = NULL;
243
68980084 244 oi->crypt_seqnum = time (NULL);
245
718e3744 246#ifdef HAVE_OPAQUE_LSA
247 ospf_opaque_type9_lsa_init (oi);
248#endif /* HAVE_OPAQUE_LSA */
249
68980084 250 oi->ospf = ospf;
718e3744 251
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;
1eb8ef25 261 struct listnode *node, *nnode;
718e3744 262 struct ospf_neighbor *nbr;
1eb8ef25 263 struct ospf_nbr_nbma *nbr_nbma;
264 struct ospf_lsa *lsa;
718e3744 265
1a643f88 266 /* oi->nbrs and oi->nbr_nbma should be deleted on InterfaceDown event */
718e3744 267 /* delete all static neighbors attached to this interface */
1eb8ef25 268 for (ALL_LIST_ELEMENTS (oi->nbr_nbma, node, nnode, nbr_nbma))
718e3744 269 {
718e3744 270 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. */
1eb8ef25 290 for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa))
1fe6ed38 291 ospf_lsa_unlock (&lsa); /* oi->ls_ack */
718e3744 292 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
1a643f88 299 /* Reset pseudo neighbor. */
cdd0c849 300 ospf_nbr_self_reset (oi);
718e3744 301}
302
303void
304ospf_if_free (struct ospf_interface *oi)
305{
306 ospf_if_down (oi);
307
308 assert (oi->state == ISM_Down);
309
310#ifdef HAVE_OPAQUE_LSA
311 ospf_opaque_type9_lsa_term (oi);
312#endif /* HAVE_OPAQUE_LSA */
313
314 /* Free Pseudo Neighbour */
315 ospf_nbr_delete (oi->nbr_self);
316
317 route_table_finish (oi->nbrs);
318 route_table_finish (oi->ls_upd_queue);
319
320 /* Free any lists that should be freed */
321 list_free (oi->nbr_nbma);
322
323 list_free (oi->ls_ack);
324 list_free (oi->ls_ack_direct.ls_ack);
325
326 ospf_delete_from_if (oi->ifp, oi);
327
68980084 328 listnode_delete (oi->ospf->oiflist, oi);
718e3744 329 listnode_delete (oi->area->oiflist, oi);
330
cfd670f3
PJ
331 thread_cancel_event (master, oi);
332
718e3744 333 memset (oi, 0, sizeof (*oi));
334 XFREE (MTYPE_OSPF_IF, oi);
335}
336
6b0655a2 337
718e3744 338/*
339* check if interface with given address is configured and
3fb9cd6e 340* return it if yes. special treatment for PtP networks.
718e3744 341*/
342struct ospf_interface *
68980084 343ospf_if_is_configured (struct ospf *ospf, struct in_addr *address)
718e3744 344{
1eb8ef25 345 struct listnode *node, *nnode;
718e3744 346 struct ospf_interface *oi;
3fb9cd6e 347 struct prefix_ipv4 addr;
348
349 addr.family = AF_INET;
350 addr.prefix = *address;
351 addr.prefixlen = IPV4_MAX_PREFIXLEN;
e4529636 352
1eb8ef25 353 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
354 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
718e3744 355 {
525c1839
DS
356 if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED))
357 {
358 if (htonl(oi->ifp->ifindex) == address->s_addr)
359 return oi;
360 }
361 else if (oi->type == OSPF_IFTYPE_POINTOPOINT)
3fb9cd6e 362 {
e4529636
AS
363 /* special leniency: match if addr is anywhere on peer subnet */
364 if (prefix_match(CONNECTED_PREFIX(oi->connected),
365 (struct prefix *)&addr))
366 return oi;
3fb9cd6e 367 }
e4529636 368 else
3fb9cd6e 369 {
370 if (IPV4_ADDR_SAME (address, &oi->address->u.prefix4))
371 return oi;
372 }
718e3744 373 }
718e3744 374 return NULL;
375}
376
377int
378ospf_if_is_up (struct ospf_interface *oi)
379{
380 return if_is_up (oi->ifp);
381}
382
2db3d05d 383struct ospf_interface *
384ospf_if_exists (struct ospf_interface *oic)
385{
52dc7ee6 386 struct listnode *node;
2db3d05d 387 struct ospf *ospf;
388 struct ospf_interface *oi;
389
e43be0ed
PJ
390 if ((ospf = ospf_lookup ()) == NULL)
391 return NULL;
2db3d05d 392
1eb8ef25 393 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
394 if (oi == oic)
2db3d05d 395 return oi;
1eb8ef25 396
2db3d05d 397 return NULL;
398}
399
c81ee5c9
JT
400/* Lookup OSPF interface by router LSA posistion */
401struct ospf_interface *
402ospf_if_lookup_by_lsa_pos (struct ospf_area *area, int lsa_pos)
403{
404 struct listnode *node;
405 struct ospf_interface *oi;
406
407 for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
408 {
409 if (lsa_pos >= oi->lsa_pos_beg && lsa_pos < oi->lsa_pos_end)
410 return oi;
411 }
412 return NULL;
413}
414
718e3744 415struct ospf_interface *
68980084 416ospf_if_lookup_by_local_addr (struct ospf *ospf,
417 struct interface *ifp, struct in_addr address)
718e3744 418{
52dc7ee6 419 struct listnode *node;
718e3744 420 struct ospf_interface *oi;
421
1eb8ef25 422 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
423 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
718e3744 424 {
425 if (ifp && oi->ifp != ifp)
426 continue;
427
428 if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4))
429 return oi;
430 }
431
432 return NULL;
433}
434
435struct ospf_interface *
68980084 436ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p)
718e3744 437{
52dc7ee6 438 struct listnode *node;
718e3744 439 struct ospf_interface *oi;
718e3744 440
441 /* Check each Interface. */
1eb8ef25 442 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
68980084 443 {
1eb8ef25 444 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
68980084 445 {
e4529636
AS
446 struct prefix ptmp;
447
448 prefix_copy (&ptmp, CONNECTED_PREFIX(oi->connected));
68980084 449 apply_mask (&ptmp);
450 if (prefix_same (&ptmp, (struct prefix *) p))
451 return oi;
452 }
453 }
718e3744 454 return NULL;
455}
456
05cf46ba 457/* determine receiving interface by ifp and source address */
718e3744 458struct ospf_interface *
05cf46ba
JT
459ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src,
460 struct interface *ifp)
718e3744 461{
05cf46ba 462 struct route_node *rn;
718e3744 463 struct prefix_ipv4 addr;
464 struct ospf_interface *oi, *match;
465
466 addr.family = AF_INET;
467 addr.prefix = src;
468 addr.prefixlen = IPV4_MAX_BITLEN;
469
470 match = NULL;
471
05cf46ba 472 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
718e3744 473 {
05cf46ba
JT
474 oi = rn->info;
475
476 if (!oi) /* oi can be NULL for PtP aliases */
477 continue;
478
718e3744 479 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
480 continue;
05cf46ba 481
1a8ee0ec
PJ
482 if (if_is_loopback (oi->ifp))
483 continue;
e4529636 484
525c1839
DS
485 if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED))
486 match = oi;
487 else if (prefix_match (CONNECTED_PREFIX(oi->connected),
488 (struct prefix *) &addr))
718e3744 489 {
e4529636
AS
490 if ( (match == NULL) ||
491 (match->address->prefixlen < oi->address->prefixlen)
492 )
493 match = oi;
718e3744 494 }
495 }
496
497 return match;
498}
6b0655a2 499
718e3744 500void
501ospf_if_stream_set (struct ospf_interface *oi)
502{
503 /* set output fifo queue. */
504 if (oi->obuf == NULL)
505 oi->obuf = ospf_fifo_new ();
506}
507
508void
509ospf_if_stream_unset (struct ospf_interface *oi)
510{
68980084 511 struct ospf *ospf = oi->ospf;
512
718e3744 513 if (oi->obuf)
514 {
515 ospf_fifo_free (oi->obuf);
516 oi->obuf = NULL;
517
518 if (oi->on_write_q)
519 {
68980084 520 listnode_delete (ospf->oi_write_q, oi);
521 if (list_isempty(ospf->oi_write_q))
522 OSPF_TIMER_OFF (ospf->t_write);
718e3744 523 oi->on_write_q = 0;
524 }
525 }
526}
68980084 527
6b0655a2 528
4dadc291 529static struct ospf_if_params *
530ospf_new_if_params (void)
718e3744 531{
532 struct ospf_if_params *oip;
533
393deb9b 534 oip = XCALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params));
718e3744 535
536 if (!oip)
537 return NULL;
538
718e3744 539 UNSET_IF_PARAM (oip, output_cost_cmd);
540 UNSET_IF_PARAM (oip, transmit_delay);
541 UNSET_IF_PARAM (oip, retransmit_interval);
542 UNSET_IF_PARAM (oip, passive_interface);
543 UNSET_IF_PARAM (oip, v_hello);
f9ad937f 544 UNSET_IF_PARAM (oip, fast_hello);
718e3744 545 UNSET_IF_PARAM (oip, v_wait);
546 UNSET_IF_PARAM (oip, priority);
547 UNSET_IF_PARAM (oip, type);
548 UNSET_IF_PARAM (oip, auth_simple);
549 UNSET_IF_PARAM (oip, auth_crypt);
550 UNSET_IF_PARAM (oip, auth_type);
ec1ca63c 551
552 oip->auth_crypt = list_new ();
718e3744 553
7eb5b47e
PJ
554 oip->network_lsa_seqnum = htonl(OSPF_INITIAL_SEQUENCE_NUMBER);
555
718e3744 556 return oip;
557}
558
559void
560ospf_del_if_params (struct ospf_if_params *oip)
561{
562 list_delete (oip->auth_crypt);
7f342629 563 bfd_info_free(&(oip->bfd_info));
718e3744 564 XFREE (MTYPE_OSPF_IF_PARAMS, oip);
565}
566
567void
568ospf_free_if_params (struct interface *ifp, struct in_addr addr)
569{
570 struct ospf_if_params *oip;
571 struct prefix_ipv4 p;
572 struct route_node *rn;
630e4807 573
574 p.family = AF_INET;
718e3744 575 p.prefixlen = IPV4_MAX_PREFIXLEN;
576 p.prefix = addr;
577 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
578 if (!rn || !rn->info)
579 return;
580
581 oip = rn->info;
582 route_unlock_node (rn);
583
584 if (!OSPF_IF_PARAM_CONFIGURED (oip, output_cost_cmd) &&
585 !OSPF_IF_PARAM_CONFIGURED (oip, transmit_delay) &&
586 !OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) &&
587 !OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) &&
588 !OSPF_IF_PARAM_CONFIGURED (oip, v_hello) &&
f9ad937f 589 !OSPF_IF_PARAM_CONFIGURED (oip, fast_hello) &&
718e3744 590 !OSPF_IF_PARAM_CONFIGURED (oip, v_wait) &&
591 !OSPF_IF_PARAM_CONFIGURED (oip, priority) &&
592 !OSPF_IF_PARAM_CONFIGURED (oip, type) &&
593 !OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) &&
594 !OSPF_IF_PARAM_CONFIGURED (oip, auth_type) &&
7eb5b47e
PJ
595 listcount (oip->auth_crypt) == 0 &&
596 ntohl (oip->network_lsa_seqnum) != OSPF_INITIAL_SEQUENCE_NUMBER)
718e3744 597 {
598 ospf_del_if_params (oip);
599 rn->info = NULL;
600 route_unlock_node (rn);
601 }
602}
603
604struct ospf_if_params *
605ospf_lookup_if_params (struct interface *ifp, struct in_addr addr)
606{
607 struct prefix_ipv4 p;
608 struct route_node *rn;
609
630e4807 610 p.family = AF_INET;
718e3744 611 p.prefixlen = IPV4_MAX_PREFIXLEN;
612 p.prefix = addr;
613
614 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
615
616 if (rn)
617 {
618 route_unlock_node (rn);
619 return rn->info;
620 }
621
622 return NULL;
623}
624
625struct ospf_if_params *
626ospf_get_if_params (struct interface *ifp, struct in_addr addr)
627{
628 struct prefix_ipv4 p;
629 struct route_node *rn;
630
631 p.family = AF_INET;
632 p.prefixlen = IPV4_MAX_PREFIXLEN;
633 p.prefix = addr;
634
635 rn = route_node_get (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
636
637 if (rn->info == NULL)
638 rn->info = ospf_new_if_params ();
639 else
640 route_unlock_node (rn);
641
642 return rn->info;
643}
644
645void
646ospf_if_update_params (struct interface *ifp, struct in_addr addr)
647{
648 struct route_node *rn;
649 struct ospf_interface *oi;
650
651 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
652 {
653 if ((oi = rn->info) == NULL)
654 continue;
655
656 if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &addr))
657 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
658 }
659}
660
661int
662ospf_if_new_hook (struct interface *ifp)
663{
664 int rc = 0;
665
393deb9b 666 ifp->info = XCALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info));
718e3744 667
668 IF_OIFS (ifp) = route_table_init ();
669 IF_OIFS_PARAMS (ifp) = route_table_init ();
670
671 IF_DEF_PARAMS (ifp) = ospf_new_if_params ();
672
673 SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay);
674 IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
675
676 SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval);
677 IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
678
679 SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority);
680 IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
681
ba682537 682 IF_DEF_PARAMS (ifp)->mtu_ignore = OSPF_MTU_IGNORE_DEFAULT;
683
718e3744 684 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello);
685 IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
686
f9ad937f 687 SET_IF_PARAM (IF_DEF_PARAMS (ifp), fast_hello);
688 IF_DEF_PARAMS (ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT;
689
718e3744 690 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait);
691 IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
692
693 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple);
694 memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
695
718e3744 696 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type);
697 IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET;
698
699#ifdef HAVE_OPAQUE_LSA
700 rc = ospf_opaque_new_if (ifp);
701#endif /* HAVE_OPAQUE_LSA */
702 return rc;
703}
704
4dadc291 705static int
718e3744 706ospf_if_delete_hook (struct interface *ifp)
707{
708 int rc = 0;
940b01aa 709 struct route_node *rn;
718e3744 710#ifdef HAVE_OPAQUE_LSA
711 rc = ospf_opaque_del_if (ifp);
712#endif /* HAVE_OPAQUE_LSA */
940b01aa 713
718e3744 714 route_table_finish (IF_OIFS (ifp));
940b01aa 715
716 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
717 if (rn->info)
718 ospf_del_if_params (rn->info);
718e3744 719 route_table_finish (IF_OIFS_PARAMS (ifp));
940b01aa 720
cfc959b8 721 ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp));
718e3744 722 XFREE (MTYPE_OSPF_IF_INFO, ifp->info);
723 ifp->info = NULL;
724
725 return rc;
726}
727
728int
729ospf_if_is_enable (struct ospf_interface *oi)
730{
731 if (!if_is_loopback (oi->ifp))
732 if (if_is_up (oi->ifp))
733 return 1;
734
735 return 0;
736}
737
ba6454ec 738void
739ospf_if_set_multicast(struct ospf_interface *oi)
740{
741 if ((oi->state > ISM_Loopback) &&
742 (oi->type != OSPF_IFTYPE_LOOPBACK) &&
743 (oi->type != OSPF_IFTYPE_VIRTUALLINK) &&
e8a56f02 744 (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE))
ba6454ec 745 {
746 /* The interface should belong to the OSPF-all-routers group. */
429ac78c 747 if (!OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) &&
ba6454ec 748 (ospf_if_add_allspfrouters(oi->ospf, oi->address,
749 oi->ifp->ifindex) >= 0))
429ac78c
PJ
750 /* Set the flag only if the system call to join succeeded. */
751 OI_MEMBER_JOINED(oi, MEMBER_ALLROUTERS);
ba6454ec 752 }
753 else
754 {
755 /* The interface should NOT belong to the OSPF-all-routers group. */
429ac78c 756 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
ba6454ec 757 {
429ac78c
PJ
758 /* Only actually drop if this is the last reference */
759 if (OI_MEMBER_COUNT(oi, MEMBER_ALLROUTERS) == 1)
760 ospf_if_drop_allspfrouters (oi->ospf, oi->address,
761 oi->ifp->ifindex);
ba6454ec 762 /* Unset the flag regardless of whether the system call to leave
763 the group succeeded, since it's much safer to assume that
764 we are not a member. */
429ac78c 765 OI_MEMBER_LEFT(oi,MEMBER_ALLROUTERS);
ba6454ec 766 }
767 }
768
769 if (((oi->type == OSPF_IFTYPE_BROADCAST) ||
770 (oi->type == OSPF_IFTYPE_POINTOPOINT)) &&
771 ((oi->state == ISM_DR) || (oi->state == ISM_Backup)) &&
e8a56f02 772 (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE))
ba6454ec 773 {
774 /* The interface should belong to the OSPF-designated-routers group. */
429ac78c 775 if (!OI_MEMBER_CHECK(oi, MEMBER_DROUTERS) &&
ba6454ec 776 (ospf_if_add_alldrouters(oi->ospf, oi->address,
777 oi->ifp->ifindex) >= 0))
778 /* Set the flag only if the system call to join succeeded. */
429ac78c 779 OI_MEMBER_JOINED(oi, MEMBER_DROUTERS);
ba6454ec 780 }
781 else
782 {
783 /* The interface should NOT belong to the OSPF-designated-routers group */
429ac78c 784 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
ba6454ec 785 {
429ac78c
PJ
786 /* drop only if last reference */
787 if (OI_MEMBER_COUNT(oi, MEMBER_DROUTERS) == 1)
788 ospf_if_drop_alldrouters(oi->ospf, oi->address, oi->ifp->ifindex);
789
ba6454ec 790 /* Unset the flag regardless of whether the system call to leave
791 the group succeeded, since it's much safer to assume that
792 we are not a member. */
429ac78c 793 OI_MEMBER_LEFT(oi, MEMBER_DROUTERS);
ba6454ec 794 }
795 }
796}
797
718e3744 798int
799ospf_if_up (struct ospf_interface *oi)
800{
801 if (oi == NULL)
802 return 0;
803
804 if (oi->type == OSPF_IFTYPE_LOOPBACK)
805 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd);
806 else
807 {
b7fe4141
DO
808 struct ospf *ospf = ospf_lookup ();
809 if (ospf != NULL)
810 ospf_adjust_sndbuflen (ospf, oi->ifp->mtu);
811 else
fb31c0fe 812 zlog_warn ("%s: ospf_lookup() returned NULL", __func__);
718e3744 813 ospf_if_stream_set (oi);
814 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp);
815 }
816
817 return 1;
818}
819
820int
821ospf_if_down (struct ospf_interface *oi)
822{
823 if (oi == NULL)
824 return 0;
825
826 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
c81ee5c9
JT
827 /* delete position in router LSA */
828 oi->lsa_pos_beg = 0;
829 oi->lsa_pos_end = 0;
718e3744 830 /* Shutdown packet reception and sending */
831 ospf_if_stream_unset (oi);
718e3744 832
833 return 1;
834}
835
6b0655a2 836
718e3744 837/* Virtual Link related functions. */
838
839struct ospf_vl_data *
840ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer)
841{
842 struct ospf_vl_data *vl_data;
843
393deb9b 844 vl_data = XCALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data));
718e3744 845
846 vl_data->vl_peer.s_addr = vl_peer.s_addr;
847 vl_data->vl_area_id = area->area_id;
848 vl_data->format = area->format;
849
850 return vl_data;
851}
852
853void
854ospf_vl_data_free (struct ospf_vl_data *vl_data)
855{
856 XFREE (MTYPE_OSPF_VL_DATA, vl_data);
857}
858
859u_int vlink_count = 0;
860
861struct ospf_interface *
68980084 862ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data)
718e3744 863{
864 struct ospf_interface * voi;
865 struct interface * vi;
866 char ifname[INTERFACE_NAMSIZ + 1];
867 struct ospf_area *area;
868 struct in_addr area_id;
869 struct connected *co;
870 struct prefix_ipv4 *p;
871
872 if (IS_DEBUG_OSPF_EVENT)
60925303 873 zlog_debug ("ospf_vl_new(): Start");
718e3744 874 if (vlink_count == OSPF_VL_MAX_COUNT)
875 {
876 if (IS_DEBUG_OSPF_EVENT)
60925303 877 zlog_debug ("ospf_vl_new(): Alarm: "
718e3744 878 "cannot create more than OSPF_MAX_VL_COUNT virtual links");
879 return NULL;
880 }
881
882 if (IS_DEBUG_OSPF_EVENT)
60925303 883 zlog_debug ("ospf_vl_new(): creating pseudo zebra interface");
718e3744 884
a349198f 885 snprintf (ifname, sizeof(ifname), "VLINK%d", vlink_count);
886 vi = if_create (ifname, strnlen(ifname, sizeof(ifname)));
90c97340
DS
887 /*
888 * if_create sets ZEBRA_INTERFACE_LINKDETECTION
889 * virtual links don't need this.
890 */
891 UNSET_FLAG (vi->status, ZEBRA_INTERFACE_LINKDETECTION);
718e3744 892 co = connected_new ();
893 co->ifp = vi;
894 listnode_add (vi->connected, co);
895
896 p = prefix_ipv4_new ();
897 p->family = AF_INET;
898 p->prefix.s_addr = 0;
899 p->prefixlen = 0;
900
901 co->address = (struct prefix *)p;
902
68980084 903 voi = ospf_if_new (ospf, vi, co->address);
718e3744 904 if (voi == NULL)
905 {
906 if (IS_DEBUG_OSPF_EVENT)
60925303 907 zlog_debug ("ospf_vl_new(): Alarm: OSPF int structure is not created");
718e3744 908 return NULL;
909 }
910 voi->connected = co;
911 voi->vl_data = vl_data;
912 voi->ifp->mtu = OSPF_VL_MTU;
913 voi->type = OSPF_IFTYPE_VIRTUALLINK;
914
106d2fd5 915 vlink_count++;
718e3744 916 if (IS_DEBUG_OSPF_EVENT)
60925303 917 zlog_debug ("ospf_vl_new(): Created name: %s", ifname);
718e3744 918 if (IS_DEBUG_OSPF_EVENT)
60925303 919 zlog_debug ("ospf_vl_new(): set if->name to %s", vi->name);
718e3744 920
921 area_id.s_addr = 0;
68980084 922 area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS);
718e3744 923 voi->area = area;
924
925 if (IS_DEBUG_OSPF_EVENT)
60925303 926 zlog_debug ("ospf_vl_new(): set associated area to the backbone");
718e3744 927
478aab98 928 ospf_nbr_add_self (voi);
718e3744 929 ospf_area_add_if (voi->area, voi);
930
931 ospf_if_stream_set (voi);
932
933 if (IS_DEBUG_OSPF_EVENT)
60925303 934 zlog_debug ("ospf_vl_new(): Stop");
718e3744 935 return voi;
936}
937
4dadc291 938static void
718e3744 939ospf_vl_if_delete (struct ospf_vl_data *vl_data)
940{
941 struct interface *ifp = vl_data->vl_oi->ifp;
942 vl_data->vl_oi->address->u.prefix4.s_addr = 0;
943 vl_data->vl_oi->address->prefixlen = 0;
944 ospf_if_free (vl_data->vl_oi);
945 if_delete (ifp);
946 vlink_count--;
947}
948
9c27ef9b
PJ
949/* Look up vl_data for given peer, optionally qualified to be in the
950 * specified area. NULL area returns first found..
951 */
718e3744 952struct ospf_vl_data *
9c27ef9b
PJ
953ospf_vl_lookup (struct ospf *ospf, struct ospf_area *area,
954 struct in_addr vl_peer)
718e3744 955{
956 struct ospf_vl_data *vl_data;
52dc7ee6 957 struct listnode *node;
9c27ef9b
PJ
958
959 if (IS_DEBUG_OSPF_EVENT)
960 {
961 zlog_debug ("%s: Looking for %s", __func__, inet_ntoa (vl_peer));
962 if (area)
963 zlog_debug ("%s: in area %s", __func__, inet_ntoa (area->area_id));
964 }
965
966 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
967 {
968 if (IS_DEBUG_OSPF_EVENT)
969 zlog_debug ("%s: VL %s, peer %s", __func__,
970 vl_data->vl_oi->ifp->name,
971 inet_ntoa (vl_data->vl_peer));
972
973 if (area && !IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
974 continue;
975
976 if (IPV4_ADDR_SAME (&vl_data->vl_peer, &vl_peer))
977 return vl_data;
978 }
718e3744 979
980 return NULL;
981}
982
4dadc291 983static void
718e3744 984ospf_vl_shutdown (struct ospf_vl_data *vl_data)
985{
986 struct ospf_interface *oi;
987
988 if ((oi = vl_data->vl_oi) == NULL)
989 return;
990
991 oi->address->u.prefix4.s_addr = 0;
992 oi->address->prefixlen = 0;
993
994 UNSET_FLAG (oi->ifp->flags, IFF_UP);
995 /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */
996 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
997}
998
999void
68980084 1000ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data)
718e3744 1001{
68980084 1002 listnode_add (ospf->vlinks, vl_data);
718e3744 1003#ifdef HAVE_SNMP
1004 ospf_snmp_vl_add (vl_data);
1005#endif /* HAVE_SNMP */
1006}
1007
1008void
68980084 1009ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data)
718e3744 1010{
1011 ospf_vl_shutdown (vl_data);
1012 ospf_vl_if_delete (vl_data);
1013
1014#ifdef HAVE_SNMP
1015 ospf_snmp_vl_delete (vl_data);
1016#endif /* HAVE_SNMP */
68980084 1017 listnode_delete (ospf->vlinks, vl_data);
718e3744 1018
1019 ospf_vl_data_free (vl_data);
1020}
1021
4dadc291 1022static int
718e3744 1023ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v)
1024{
1025 int changed = 0;
1026 struct ospf_interface *voi;
52dc7ee6 1027 struct listnode *node;
eb3da6df 1028 struct vertex_parent *vp = NULL;
b07c4cb3 1029 unsigned int i;
718e3744 1030 struct router_lsa *rl;
1031
1032 voi = vl_data->vl_oi;
1033
1034 if (voi->output_cost != v->distance)
1035 {
cd59da68 1036
718e3744 1037 voi->output_cost = v->distance;
1038 changed = 1;
1039 }
1040
eb3da6df 1041 for (ALL_LIST_ELEMENTS_RO (v->parents, node, vp))
1eb8ef25 1042 {
9c27ef9b
PJ
1043 vl_data->nexthop.oi = vp->nexthop->oi;
1044 vl_data->nexthop.router = vp->nexthop->router;
1eb8ef25 1045
1046 if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
9c27ef9b 1047 &vl_data->nexthop.oi->address->u.prefix4))
1eb8ef25 1048 changed = 1;
cd59da68 1049
9c27ef9b
PJ
1050 voi->address->u.prefix4 = vl_data->nexthop.oi->address->u.prefix4;
1051 voi->address->prefixlen = vl_data->nexthop.oi->address->prefixlen;
1eb8ef25 1052
1053 break; /* We take the first interface. */
1054 }
718e3744 1055
1056 rl = (struct router_lsa *)v->lsa;
d355bfa7 1057
1058 /* use SPF determined backlink index in struct vertex
1059 * for virtual link destination address
1060 */
eb3da6df 1061 if (vp && vp->backlink >= 0)
d355bfa7 1062 {
1063 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
eb3da6df 1064 &rl->link[vp->backlink].link_data))
d355bfa7 1065 changed = 1;
eb3da6df 1066 vl_data->peer_addr = rl->link[vp->backlink].link_data;
d355bfa7 1067 }
1068 else
718e3744 1069 {
d355bfa7 1070 /* This is highly odd, there is no backlink index
1071 * there should be due to the ospf_spf_has_link() check
1072 * in SPF. Lets warn and try pick a link anyway.
1073 */
1074 zlog_warn ("ospf_vl_set_params: No backlink for %s!",
1075 vl_data->vl_oi->ifp->name);
1076 for (i = 0; i < ntohs (rl->links); i++)
2e6b0bbb 1077 {
d355bfa7 1078 switch (rl->link[i].type)
1079 {
1080 case LSA_LINK_TYPE_VIRTUALLINK:
1081 if (IS_DEBUG_OSPF_EVENT)
60925303 1082 zlog_debug ("found back link through VL");
d355bfa7 1083 case LSA_LINK_TYPE_TRANSIT:
1084 case LSA_LINK_TYPE_POINTOPOINT:
cd59da68 1085 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
1086 &rl->link[i].link_data))
1087 changed = 1;
d355bfa7 1088 vl_data->peer_addr = rl->link[i].link_data;
d355bfa7 1089 }
2e6b0bbb 1090 }
718e3744 1091 }
d355bfa7 1092
1093 if (IS_DEBUG_OSPF_EVENT)
9c27ef9b 1094 zlog_debug ("%s: %s peer address: %s, cost: %d,%schanged", __func__,
d355bfa7 1095 vl_data->vl_oi->ifp->name,
9c27ef9b
PJ
1096 inet_ntoa(vl_data->peer_addr),
1097 voi->output_cost,
1098 (changed ? " " : " un"));
d355bfa7 1099
2e6b0bbb 1100 return changed;
718e3744 1101}
1102
1103
1104void
68980084 1105ospf_vl_up_check (struct ospf_area *area, struct in_addr rid,
718e3744 1106 struct vertex *v)
1107{
68980084 1108 struct ospf *ospf = area->ospf;
52dc7ee6 1109 struct listnode *node;
718e3744 1110 struct ospf_vl_data *vl_data;
1111 struct ospf_interface *oi;
1112
1113 if (IS_DEBUG_OSPF_EVENT)
1114 {
60925303 1115 zlog_debug ("ospf_vl_up_check(): Start");
1116 zlog_debug ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid));
1117 zlog_debug ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id));
718e3744 1118 }
1119
1eb8ef25 1120 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
718e3744 1121 {
718e3744 1122 if (IS_DEBUG_OSPF_EVENT)
1123 {
9c27ef9b
PJ
1124 zlog_debug ("%s: considering VL, %s in area %s", __func__,
1125 vl_data->vl_oi->ifp->name,
1126 inet_ntoa (vl_data->vl_area_id));
1127 zlog_debug ("%s: peer ID: %s", __func__,
718e3744 1128 inet_ntoa (vl_data->vl_peer));
1129 }
1130
1131 if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) &&
1132 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1133 {
1134 oi = vl_data->vl_oi;
1135 SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
1136
1137 if (IS_DEBUG_OSPF_EVENT)
60925303 1138 zlog_debug ("ospf_vl_up_check(): this VL matched");
718e3744 1139
1140 if (oi->state == ISM_Down)
1141 {
1142 if (IS_DEBUG_OSPF_EVENT)
60925303 1143 zlog_debug ("ospf_vl_up_check(): VL is down, waking it up");
718e3744 1144 SET_FLAG (oi->ifp->flags, IFF_UP);
2e6b0bbb 1145 OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp);
718e3744 1146 }
1147
2e6b0bbb 1148 if (ospf_vl_set_params (vl_data, v))
1149 {
1150 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
60925303 1151 zlog_debug ("ospf_vl_up_check: VL cost change,"
cd59da68 1152 " scheduling router lsa refresh");
c363d386
PJ
1153 if (ospf->backbone)
1154 ospf_router_lsa_update_area (ospf->backbone);
2e6b0bbb 1155 else if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
60925303 1156 zlog_debug ("ospf_vl_up_check: VL cost change, no backbone!");
2e6b0bbb 1157 }
718e3744 1158 }
1159 }
1160}
1161
1162void
68980084 1163ospf_vl_unapprove (struct ospf *ospf)
718e3744 1164{
52dc7ee6 1165 struct listnode *node;
718e3744 1166 struct ospf_vl_data *vl_data;
1167
1eb8ef25 1168 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
1169 UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
718e3744 1170}
1171
1172void
68980084 1173ospf_vl_shut_unapproved (struct ospf *ospf)
718e3744 1174{
1eb8ef25 1175 struct listnode *node, *nnode;
718e3744 1176 struct ospf_vl_data *vl_data;
1177
1eb8ef25 1178 for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
1179 if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
1180 ospf_vl_shutdown (vl_data);
718e3744 1181}
1182
1183int
1184ospf_full_virtual_nbrs (struct ospf_area *area)
1185{
1186 if (IS_DEBUG_OSPF_EVENT)
1187 {
60925303 1188 zlog_debug ("counting fully adjacent virtual neighbors in area %s",
718e3744 1189 inet_ntoa (area->area_id));
60925303 1190 zlog_debug ("there are %d of them", area->full_vls);
718e3744 1191 }
1192
1193 return area->full_vls;
1194}
1195
1196int
1197ospf_vls_in_area (struct ospf_area *area)
1198{
52dc7ee6 1199 struct listnode *node;
718e3744 1200 struct ospf_vl_data *vl_data;
1201 int c = 0;
1202
1eb8ef25 1203 for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
1204 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1205 c++;
718e3744 1206
1207 return c;
1208}
1209
6b0655a2 1210
718e3744 1211struct crypt_key *
1212ospf_crypt_key_new ()
1213{
393deb9b 1214 return XCALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key));
718e3744 1215}
1216
1217void
52dc7ee6 1218ospf_crypt_key_add (struct list *crypt, struct crypt_key *ck)
718e3744 1219{
1220 listnode_add (crypt, ck);
1221}
1222
1223struct crypt_key *
52dc7ee6 1224ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id)
718e3744 1225{
52dc7ee6 1226 struct listnode *node;
718e3744 1227 struct crypt_key *ck;
1228
1eb8ef25 1229 for (ALL_LIST_ELEMENTS_RO (auth_crypt, node, ck))
1230 if (ck->key_id == key_id)
1231 return ck;
718e3744 1232
1233 return NULL;
1234}
1235
1236int
52dc7ee6 1237ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id)
718e3744 1238{
1eb8ef25 1239 struct listnode *node, *nnode;
718e3744 1240 struct crypt_key *ck;
1241
1eb8ef25 1242 for (ALL_LIST_ELEMENTS (auth_crypt, node, nnode, ck))
718e3744 1243 {
718e3744 1244 if (ck->key_id == key_id)
1245 {
1246 listnode_delete (auth_crypt, ck);
ba682537 1247 XFREE (MTYPE_OSPF_CRYPT_KEY, ck);
718e3744 1248 return 1;
1249 }
1250 }
1251
1252 return 0;
1253}
1254
bc18d616 1255u_char
1256ospf_default_iftype(struct interface *ifp)
1257{
1258 if (if_is_pointopoint (ifp))
1259 return OSPF_IFTYPE_POINTOPOINT;
1260 else if (if_is_loopback (ifp))
1261 return OSPF_IFTYPE_LOOPBACK;
1262 else
1263 return OSPF_IFTYPE_BROADCAST;
1264}
1265
718e3744 1266void
1267ospf_if_init ()
1268{
1269 /* Initialize Zebra interface data structure. */
b2d7c082 1270 om->iflist = vrf_iflist (VRF_DEFAULT);
718e3744 1271 if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
1272 if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);
1273}