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