]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_interface.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[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 */
d7c0a89a
QY
79 uint32_t cost;
80 uint32_t bw, refbw;
d62a17ae 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 {
d7c0a89a 99 cost = (uint32_t)((double)refbw / (double)bw + (double)0.5);
d62a17ae 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{
d7c0a89a 111 uint32_t newcost;
d62a17ae 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;
4fc8a852
CS
266
267 ospf_if_stream_set(oi);
268
d62a17ae 269 QOBJ_REG(oi, ospf_interface);
270
b5a8894d
CS
271 if (IS_DEBUG_OSPF_EVENT)
272 zlog_debug("%s: ospf interface %s vrf %s id %u created",
273 __PRETTY_FUNCTION__, ifp->name,
274 ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id);
275
d62a17ae 276 return oi;
718e3744 277}
278
279/* Restore an interface to its pre UP state
280 Used from ism_interface_down only */
d62a17ae 281void ospf_if_cleanup(struct ospf_interface *oi)
718e3744 282{
d62a17ae 283 struct route_node *rn;
284 struct listnode *node, *nnode;
285 struct ospf_neighbor *nbr;
286 struct ospf_nbr_nbma *nbr_nbma;
287 struct ospf_lsa *lsa;
288
289 /* oi->nbrs and oi->nbr_nbma should be deleted on InterfaceDown event */
290 /* delete all static neighbors attached to this interface */
291 for (ALL_LIST_ELEMENTS(oi->nbr_nbma, node, nnode, nbr_nbma)) {
292 OSPF_POLL_TIMER_OFF(nbr_nbma->t_poll);
293
294 if (nbr_nbma->nbr) {
295 nbr_nbma->nbr->nbr_nbma = NULL;
296 nbr_nbma->nbr = NULL;
297 }
298
299 nbr_nbma->oi = NULL;
300
301 listnode_delete(oi->nbr_nbma, nbr_nbma);
718e3744 302 }
303
d62a17ae 304 /* send Neighbor event KillNbr to all associated neighbors. */
305 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
306 if ((nbr = rn->info) != NULL)
307 if (nbr != oi->nbr_self)
308 OSPF_NSM_EVENT_EXECUTE(nbr, NSM_KillNbr);
309
310 /* Cleanup Link State Acknowlegdment list. */
311 for (ALL_LIST_ELEMENTS(oi->ls_ack, node, nnode, lsa))
312 ospf_lsa_unlock(&lsa); /* oi->ls_ack */
313 list_delete_all_node(oi->ls_ack);
314
315 oi->crypt_seqnum = 0;
316
317 /* Empty link state update queue */
318 ospf_ls_upd_queue_empty(oi);
319
320 /* Reset pseudo neighbor. */
321 ospf_nbr_self_reset(oi, oi->ospf->router_id);
718e3744 322}
323
d62a17ae 324void ospf_if_free(struct ospf_interface *oi)
718e3744 325{
d62a17ae 326 ospf_if_down(oi);
327
4fc8a852
CS
328 if (oi->obuf)
329 ospf_fifo_free(oi->obuf);
330
d62a17ae 331 assert(oi->state == ISM_Down);
332
333 ospf_opaque_type9_lsa_term(oi);
334
335 QOBJ_UNREG(oi);
336
337 /* Free Pseudo Neighbour */
338 ospf_nbr_delete(oi->nbr_self);
718e3744 339
d62a17ae 340 route_table_finish(oi->nbrs);
341 route_table_finish(oi->ls_upd_queue);
718e3744 342
d62a17ae 343 /* Free any lists that should be freed */
6a154c88 344 list_delete(&oi->nbr_nbma);
718e3744 345
6a154c88
DL
346 list_delete(&oi->ls_ack);
347 list_delete(&oi->ls_ack_direct.ls_ack);
ae19c240 348
b5a8894d
CS
349 if (IS_DEBUG_OSPF_EVENT)
350 zlog_debug("%s: ospf interface %s vrf %s id %u deleted",
351 __PRETTY_FUNCTION__, oi->ifp->name,
352 ospf_vrf_id_to_name(oi->ifp->vrf_id),
353 oi->ifp->vrf_id);
354
d62a17ae 355 ospf_delete_from_if(oi->ifp, oi);
718e3744 356
d62a17ae 357 listnode_delete(oi->ospf->oiflist, oi);
358 listnode_delete(oi->area->oiflist, oi);
718e3744 359
d62a17ae 360 thread_cancel_event(master, oi);
cfd670f3 361
d62a17ae 362 memset(oi, 0, sizeof(*oi));
363 XFREE(MTYPE_OSPF_IF, oi);
718e3744 364}
365
d62a17ae 366int ospf_if_is_up(struct ospf_interface *oi)
718e3744 367{
d62a17ae 368 return if_is_up(oi->ifp);
718e3744 369}
370
d62a17ae 371struct ospf_interface *ospf_if_exists(struct ospf_interface *oic)
372{
373 struct listnode *node;
374 struct ospf *ospf;
375 struct ospf_interface *oi;
2db3d05d 376
b5a8894d
CS
377 if (!oic)
378 return NULL;
379
380 ospf = oic->ospf;
381 if (ospf == NULL)
d62a17ae 382 return NULL;
2db3d05d 383
d62a17ae 384 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi))
385 if (oi == oic)
386 return oi;
1eb8ef25 387
d62a17ae 388 return NULL;
2db3d05d 389}
390
c81ee5c9 391/* Lookup OSPF interface by router LSA posistion */
d62a17ae 392struct ospf_interface *ospf_if_lookup_by_lsa_pos(struct ospf_area *area,
393 int lsa_pos)
c81ee5c9 394{
d62a17ae 395 struct listnode *node;
396 struct ospf_interface *oi;
c81ee5c9 397
d62a17ae 398 for (ALL_LIST_ELEMENTS_RO(area->oiflist, node, oi)) {
399 if (lsa_pos >= oi->lsa_pos_beg && lsa_pos < oi->lsa_pos_end)
400 return oi;
401 }
402 return NULL;
c81ee5c9
JT
403}
404
d62a17ae 405struct ospf_interface *ospf_if_lookup_by_local_addr(struct ospf *ospf,
406 struct interface *ifp,
407 struct in_addr address)
718e3744 408{
d62a17ae 409 struct listnode *node;
410 struct ospf_interface *oi;
411
412 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi))
413 if (oi->type != OSPF_IFTYPE_VIRTUALLINK) {
414 if (ifp && oi->ifp != ifp)
415 continue;
416
417 if (IPV4_ADDR_SAME(&address, &oi->address->u.prefix4))
418 return oi;
419 }
420
421 return NULL;
718e3744 422}
423
d62a17ae 424struct ospf_interface *ospf_if_lookup_by_prefix(struct ospf *ospf,
425 struct prefix_ipv4 *p)
718e3744 426{
d62a17ae 427 struct listnode *node;
428 struct ospf_interface *oi;
429
430 /* Check each Interface. */
431 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
432 if (oi->type != OSPF_IFTYPE_VIRTUALLINK) {
433 struct prefix ptmp;
434
435 prefix_copy(&ptmp, CONNECTED_PREFIX(oi->connected));
436 apply_mask(&ptmp);
437 if (prefix_same(&ptmp, (struct prefix *)p))
438 return oi;
439 }
68980084 440 }
d62a17ae 441 return NULL;
718e3744 442}
443
05cf46ba 444/* determine receiving interface by ifp and source address */
d62a17ae 445struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf,
446 struct in_addr src,
447 struct interface *ifp)
718e3744 448{
d62a17ae 449 struct route_node *rn;
450 struct prefix_ipv4 addr;
451 struct ospf_interface *oi, *match;
452
453 addr.family = AF_INET;
454 addr.prefix = src;
455 addr.prefixlen = IPV4_MAX_BITLEN;
456
457 match = NULL;
458
459 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
460 oi = rn->info;
461
462 if (!oi) /* oi can be NULL for PtP aliases */
463 continue;
464
465 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
466 continue;
467
0c74bbe0 468 if (if_is_loopback(oi->ifp) || if_is_vrf(oi->ifp))
d62a17ae 469 continue;
470
471 if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED))
472 match = oi;
473 else if (prefix_match(CONNECTED_PREFIX(oi->connected),
474 (struct prefix *)&addr)) {
9d303b37
DL
475 if ((match == NULL) || (match->address->prefixlen
476 < oi->address->prefixlen))
d62a17ae 477 match = oi;
478 }
718e3744 479 }
718e3744 480
d62a17ae 481 return match;
718e3744 482}
6b0655a2 483
85c8ef06
CS
484static void ospf_if_reset_stats(struct ospf_interface *oi)
485{
486 oi->hello_in = oi->hello_out = 0;
487 oi->db_desc_in = oi->db_desc_out = 0;
488 oi->ls_req_in = oi->ls_req_out = 0;
489 oi->ls_upd_in = oi->ls_upd_out = 0;
490 oi->ls_ack_in = oi->ls_ack_out = 0;
491}
492
d62a17ae 493void ospf_if_stream_set(struct ospf_interface *oi)
718e3744 494{
d62a17ae 495 /* set output fifo queue. */
496 if (oi->obuf == NULL)
497 oi->obuf = ospf_fifo_new();
718e3744 498}
499
d62a17ae 500void ospf_if_stream_unset(struct ospf_interface *oi)
718e3744 501{
d62a17ae 502 struct ospf *ospf = oi->ospf;
503
504 if (oi->obuf) {
4fc8a852
CS
505 /* flush the interface packet queue */
506 ospf_fifo_flush(oi->obuf);
85c8ef06
CS
507 /*reset protocol stats */
508 ospf_if_reset_stats(oi);
509
d62a17ae 510 if (oi->on_write_q) {
511 listnode_delete(ospf->oi_write_q, oi);
512 if (list_isempty(ospf->oi_write_q))
513 OSPF_TIMER_OFF(ospf->t_write);
514 oi->on_write_q = 0;
515 }
516 }
718e3744 517}
68980084 518
6b0655a2 519
d62a17ae 520static struct ospf_if_params *ospf_new_if_params(void)
718e3744 521{
d62a17ae 522 struct ospf_if_params *oip;
523
524 oip = XCALLOC(MTYPE_OSPF_IF_PARAMS, sizeof(struct ospf_if_params));
525
d62a17ae 526 UNSET_IF_PARAM(oip, output_cost_cmd);
527 UNSET_IF_PARAM(oip, transmit_delay);
528 UNSET_IF_PARAM(oip, retransmit_interval);
529 UNSET_IF_PARAM(oip, passive_interface);
530 UNSET_IF_PARAM(oip, v_hello);
531 UNSET_IF_PARAM(oip, fast_hello);
532 UNSET_IF_PARAM(oip, v_wait);
533 UNSET_IF_PARAM(oip, priority);
534 UNSET_IF_PARAM(oip, type);
535 UNSET_IF_PARAM(oip, auth_simple);
536 UNSET_IF_PARAM(oip, auth_crypt);
537 UNSET_IF_PARAM(oip, auth_type);
538
539 oip->auth_crypt = list_new();
540
541 oip->network_lsa_seqnum = htonl(OSPF_INITIAL_SEQUENCE_NUMBER);
542
543 return oip;
718e3744 544}
545
d62a17ae 546void ospf_del_if_params(struct ospf_if_params *oip)
718e3744 547{
6a154c88 548 list_delete(&oip->auth_crypt);
d62a17ae 549 bfd_info_free(&(oip->bfd_info));
550 XFREE(MTYPE_OSPF_IF_PARAMS, oip);
718e3744 551}
552
d62a17ae 553void ospf_free_if_params(struct interface *ifp, struct in_addr addr)
718e3744 554{
d62a17ae 555 struct ospf_if_params *oip;
556 struct prefix_ipv4 p;
557 struct route_node *rn;
558
559 p.family = AF_INET;
560 p.prefixlen = IPV4_MAX_PREFIXLEN;
561 p.prefix = addr;
562 rn = route_node_lookup(IF_OIFS_PARAMS(ifp), (struct prefix *)&p);
563 if (!rn || !rn->info)
564 return;
565
566 oip = rn->info;
567 route_unlock_node(rn);
568
569 if (!OSPF_IF_PARAM_CONFIGURED(oip, output_cost_cmd)
570 && !OSPF_IF_PARAM_CONFIGURED(oip, transmit_delay)
571 && !OSPF_IF_PARAM_CONFIGURED(oip, retransmit_interval)
572 && !OSPF_IF_PARAM_CONFIGURED(oip, passive_interface)
573 && !OSPF_IF_PARAM_CONFIGURED(oip, v_hello)
574 && !OSPF_IF_PARAM_CONFIGURED(oip, fast_hello)
575 && !OSPF_IF_PARAM_CONFIGURED(oip, v_wait)
576 && !OSPF_IF_PARAM_CONFIGURED(oip, priority)
577 && !OSPF_IF_PARAM_CONFIGURED(oip, type)
578 && !OSPF_IF_PARAM_CONFIGURED(oip, auth_simple)
579 && !OSPF_IF_PARAM_CONFIGURED(oip, auth_type)
580 && listcount(oip->auth_crypt) == 0
581 && ntohl(oip->network_lsa_seqnum) != OSPF_INITIAL_SEQUENCE_NUMBER) {
582 ospf_del_if_params(oip);
583 rn->info = NULL;
584 route_unlock_node(rn);
585 }
718e3744 586}
587
d62a17ae 588struct ospf_if_params *ospf_lookup_if_params(struct interface *ifp,
589 struct in_addr addr)
718e3744 590{
d62a17ae 591 struct prefix_ipv4 p;
592 struct route_node *rn;
593
594 p.family = AF_INET;
595 p.prefixlen = IPV4_MAX_PREFIXLEN;
596 p.prefix = addr;
597
598 rn = route_node_lookup(IF_OIFS_PARAMS(ifp), (struct prefix *)&p);
599
600 if (rn) {
601 route_unlock_node(rn);
602 return rn->info;
603 }
604
605 return NULL;
718e3744 606}
607
d62a17ae 608struct ospf_if_params *ospf_get_if_params(struct interface *ifp,
609 struct in_addr addr)
718e3744 610{
d62a17ae 611 struct prefix_ipv4 p;
612 struct route_node *rn;
613
614 p.family = AF_INET;
615 p.prefixlen = IPV4_MAX_PREFIXLEN;
616 p.prefix = addr;
a6435618 617 apply_mask_ipv4(&p);
d62a17ae 618
619 rn = route_node_get(IF_OIFS_PARAMS(ifp), (struct prefix *)&p);
620
621 if (rn->info == NULL)
622 rn->info = ospf_new_if_params();
623 else
624 route_unlock_node(rn);
625
626 return rn->info;
718e3744 627}
628
d62a17ae 629void ospf_if_update_params(struct interface *ifp, struct in_addr addr)
718e3744 630{
d62a17ae 631 struct route_node *rn;
632 struct ospf_interface *oi;
633
634 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
635 if ((oi = rn->info) == NULL)
636 continue;
637
638 if (IPV4_ADDR_SAME(&oi->address->u.prefix4, &addr))
639 oi->params = ospf_lookup_if_params(
640 ifp, oi->address->u.prefix4);
641 }
718e3744 642}
643
d62a17ae 644int ospf_if_new_hook(struct interface *ifp)
718e3744 645{
d62a17ae 646 int rc = 0;
647
648 ifp->info = XCALLOC(MTYPE_OSPF_IF_INFO, sizeof(struct ospf_if_info));
649
650 IF_OIFS(ifp) = route_table_init();
651 IF_OIFS_PARAMS(ifp) = route_table_init();
652
653 IF_DEF_PARAMS(ifp) = ospf_new_if_params();
654
655 SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay);
656 IF_DEF_PARAMS(ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
657
658 SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval);
659 IF_DEF_PARAMS(ifp)->retransmit_interval =
660 OSPF_RETRANSMIT_INTERVAL_DEFAULT;
661
662 SET_IF_PARAM(IF_DEF_PARAMS(ifp), priority);
663 IF_DEF_PARAMS(ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
664
665 IF_DEF_PARAMS(ifp)->mtu_ignore = OSPF_MTU_IGNORE_DEFAULT;
666
667 SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello);
668 IF_DEF_PARAMS(ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
669
670 SET_IF_PARAM(IF_DEF_PARAMS(ifp), fast_hello);
671 IF_DEF_PARAMS(ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT;
672
673 SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait);
674 IF_DEF_PARAMS(ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
675
676 SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_simple);
677 memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
678
679 SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type);
680 IF_DEF_PARAMS(ifp)->auth_type = OSPF_AUTH_NOTSET;
681
682 rc = ospf_opaque_new_if(ifp);
683 return rc;
718e3744 684}
685
d62a17ae 686static int ospf_if_delete_hook(struct interface *ifp)
718e3744 687{
d62a17ae 688 int rc = 0;
689 struct route_node *rn;
690 rc = ospf_opaque_del_if(ifp);
940b01aa 691
d62a17ae 692 route_table_finish(IF_OIFS(ifp));
940b01aa 693
d62a17ae 694 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
695 if (rn->info)
696 ospf_del_if_params(rn->info);
697 route_table_finish(IF_OIFS_PARAMS(ifp));
940b01aa 698
d62a17ae 699 ospf_del_if_params((struct ospf_if_params *)IF_DEF_PARAMS(ifp));
700 XFREE(MTYPE_OSPF_IF_INFO, ifp->info);
701 ifp->info = NULL;
718e3744 702
d62a17ae 703 return rc;
718e3744 704}
705
d62a17ae 706int ospf_if_is_enable(struct ospf_interface *oi)
718e3744 707{
0c74bbe0 708 if (!(if_is_loopback(oi->ifp) || if_is_vrf(oi->ifp)))
d62a17ae 709 if (if_is_up(oi->ifp))
710 return 1;
718e3744 711
d62a17ae 712 return 0;
718e3744 713}
714
d62a17ae 715void ospf_if_set_multicast(struct ospf_interface *oi)
ba6454ec 716{
d62a17ae 717 if ((oi->state > ISM_Loopback) && (oi->type != OSPF_IFTYPE_LOOPBACK)
718 && (oi->type != OSPF_IFTYPE_VIRTUALLINK)
719 && (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE)) {
720 /* The interface should belong to the OSPF-all-routers group. */
721 if (!OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
722 && (ospf_if_add_allspfrouters(oi->ospf, oi->address,
723 oi->ifp->ifindex)
724 >= 0))
725 /* Set the flag only if the system call to join
726 * succeeded. */
727 OI_MEMBER_JOINED(oi, MEMBER_ALLROUTERS);
728 } else {
729 /* The interface should NOT belong to the OSPF-all-routers
730 * group. */
731 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) {
732 /* Only actually drop if this is the last reference */
733 if (OI_MEMBER_COUNT(oi, MEMBER_ALLROUTERS) == 1)
734 ospf_if_drop_allspfrouters(oi->ospf,
735 oi->address,
736 oi->ifp->ifindex);
737 /* Unset the flag regardless of whether the system call
738 to leave
739 the group succeeded, since it's much safer to assume
740 that
741 we are not a member. */
742 OI_MEMBER_LEFT(oi, MEMBER_ALLROUTERS);
743 }
744 }
745
746 if (((oi->type == OSPF_IFTYPE_BROADCAST)
747 || (oi->type == OSPF_IFTYPE_POINTOPOINT))
748 && ((oi->state == ISM_DR) || (oi->state == ISM_Backup))
749 && (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE)) {
750 /* The interface should belong to the OSPF-designated-routers
751 * group. */
752 if (!OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)
753 && (ospf_if_add_alldrouters(oi->ospf, oi->address,
754 oi->ifp->ifindex)
755 >= 0))
756 /* Set the flag only if the system call to join
757 * succeeded. */
758 OI_MEMBER_JOINED(oi, MEMBER_DROUTERS);
759 } else {
760 /* The interface should NOT belong to the
761 * OSPF-designated-routers group */
762 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) {
763 /* drop only if last reference */
764 if (OI_MEMBER_COUNT(oi, MEMBER_DROUTERS) == 1)
765 ospf_if_drop_alldrouters(oi->ospf, oi->address,
766 oi->ifp->ifindex);
767
768 /* Unset the flag regardless of whether the system call
769 to leave
770 the group succeeded, since it's much safer to assume
771 that
772 we are not a member. */
773 OI_MEMBER_LEFT(oi, MEMBER_DROUTERS);
774 }
775 }
ba6454ec 776}
777
d62a17ae 778int ospf_if_up(struct ospf_interface *oi)
718e3744 779{
d62a17ae 780 if (oi == NULL)
781 return 0;
782
783 if (oi->type == OSPF_IFTYPE_LOOPBACK)
784 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_LoopInd);
785 else {
d62a17ae 786 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_InterfaceUp);
787 }
788
789 return 1;
718e3744 790}
791
d62a17ae 792int ospf_if_down(struct ospf_interface *oi)
718e3744 793{
d62a17ae 794 if (oi == NULL)
795 return 0;
718e3744 796
d62a17ae 797 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
798 /* delete position in router LSA */
799 oi->lsa_pos_beg = 0;
800 oi->lsa_pos_end = 0;
801 /* Shutdown packet reception and sending */
802 ospf_if_stream_unset(oi);
718e3744 803
d62a17ae 804 return 1;
718e3744 805}
806
6b0655a2 807
718e3744 808/* Virtual Link related functions. */
809
d62a17ae 810struct ospf_vl_data *ospf_vl_data_new(struct ospf_area *area,
811 struct in_addr vl_peer)
718e3744 812{
d62a17ae 813 struct ospf_vl_data *vl_data;
718e3744 814
d62a17ae 815 vl_data = XCALLOC(MTYPE_OSPF_VL_DATA, sizeof(struct ospf_vl_data));
718e3744 816
d62a17ae 817 vl_data->vl_peer.s_addr = vl_peer.s_addr;
818 vl_data->vl_area_id = area->area_id;
819 vl_data->vl_area_id_fmt = area->area_id_fmt;
718e3744 820
d62a17ae 821 return vl_data;
718e3744 822}
823
d62a17ae 824void ospf_vl_data_free(struct ospf_vl_data *vl_data)
718e3744 825{
d62a17ae 826 XFREE(MTYPE_OSPF_VL_DATA, vl_data);
718e3744 827}
828
d7c0a89a 829unsigned int vlink_count = 0;
718e3744 830
d62a17ae 831struct ospf_interface *ospf_vl_new(struct ospf *ospf,
832 struct ospf_vl_data *vl_data)
718e3744 833{
d62a17ae 834 struct ospf_interface *voi;
835 struct interface *vi;
bcc24579 836 char ifname[INTERFACE_NAMSIZ];
d62a17ae 837 struct ospf_area *area;
838 struct in_addr area_id;
839 struct connected *co;
840 struct prefix_ipv4 *p;
841
842 if (IS_DEBUG_OSPF_EVENT)
843 zlog_debug("ospf_vl_new(): Start");
844 if (vlink_count == OSPF_VL_MAX_COUNT) {
845 if (IS_DEBUG_OSPF_EVENT)
846 zlog_debug(
847 "ospf_vl_new(): Alarm: "
848 "cannot create more than OSPF_MAX_VL_COUNT virtual links");
849 return NULL;
850 }
851
852 if (IS_DEBUG_OSPF_EVENT)
996c9314
LB
853 zlog_debug(
854 "ospf_vl_new(): creating pseudo zebra interface vrf id %u",
855 ospf->vrf_id);
d62a17ae 856
2ec42b85 857 snprintf(ifname, sizeof(ifname), "VLINK%u", vlink_count);
bcc24579 858 vi = if_create(ifname, ospf->vrf_id);
d62a17ae 859 /*
860 * if_create sets ZEBRA_INTERFACE_LINKDETECTION
861 * virtual links don't need this.
862 */
863 UNSET_FLAG(vi->status, ZEBRA_INTERFACE_LINKDETECTION);
864 co = connected_new();
865 co->ifp = vi;
866 listnode_add(vi->connected, co);
867
868 p = prefix_ipv4_new();
869 p->family = AF_INET;
870 p->prefix.s_addr = 0;
871 p->prefixlen = 0;
872
873 co->address = (struct prefix *)p;
874
875 voi = ospf_if_new(ospf, vi, co->address);
876 if (voi == NULL) {
877 if (IS_DEBUG_OSPF_EVENT)
878 zlog_debug(
879 "ospf_vl_new(): Alarm: OSPF int structure is not created");
880 return NULL;
881 }
882 voi->connected = co;
883 voi->vl_data = vl_data;
884 voi->ifp->mtu = OSPF_VL_MTU;
885 voi->type = OSPF_IFTYPE_VIRTUALLINK;
886
887 vlink_count++;
888 if (IS_DEBUG_OSPF_EVENT)
889 zlog_debug("ospf_vl_new(): Created name: %s", ifname);
890 if (IS_DEBUG_OSPF_EVENT)
891 zlog_debug("ospf_vl_new(): set if->name to %s", vi->name);
892
893 area_id.s_addr = 0;
894 area = ospf_area_get(ospf, area_id);
895 voi->area = area;
896
897 if (IS_DEBUG_OSPF_EVENT)
898 zlog_debug(
899 "ospf_vl_new(): set associated area to the backbone");
900
901 /* Add pseudo neighbor. */
902 ospf_nbr_self_reset(voi, voi->ospf->router_id);
903
904 ospf_area_add_if(voi->area, voi);
905
906 ospf_if_stream_set(voi);
907
908 if (IS_DEBUG_OSPF_EVENT)
909 zlog_debug("ospf_vl_new(): Stop");
910 return voi;
718e3744 911}
912
d62a17ae 913static void ospf_vl_if_delete(struct ospf_vl_data *vl_data)
718e3744 914{
d62a17ae 915 struct interface *ifp = vl_data->vl_oi->ifp;
916 vl_data->vl_oi->address->u.prefix4.s_addr = 0;
917 vl_data->vl_oi->address->prefixlen = 0;
918 ospf_if_free(vl_data->vl_oi);
919 if_delete(ifp);
920 vlink_count--;
718e3744 921}
922
19ce7d5e
PG
923/* for a defined area, count the number of configured vl
924 */
925int ospf_vl_count(struct ospf *ospf, struct ospf_area *area)
926{
927 int count = 0;
928 struct ospf_vl_data *vl_data;
929 struct listnode *node;
930
931 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
932 if (area
933 && !IPV4_ADDR_SAME(&vl_data->vl_area_id, &area->area_id))
934 continue;
935 count++;
936 }
937 return count;
938}
939
9c27ef9b
PJ
940/* Look up vl_data for given peer, optionally qualified to be in the
941 * specified area. NULL area returns first found..
942 */
d62a17ae 943struct ospf_vl_data *ospf_vl_lookup(struct ospf *ospf, struct ospf_area *area,
944 struct in_addr vl_peer)
718e3744 945{
d62a17ae 946 struct ospf_vl_data *vl_data;
947 struct listnode *node;
948
949 if (IS_DEBUG_OSPF_EVENT) {
950 zlog_debug("%s: Looking for %s", __func__, inet_ntoa(vl_peer));
951 if (area)
952 zlog_debug("%s: in area %s", __func__,
953 inet_ntoa(area->area_id));
954 }
955
956 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
957 if (IS_DEBUG_OSPF_EVENT)
958 zlog_debug("%s: VL %s, peer %s", __func__,
959 vl_data->vl_oi->ifp->name,
960 inet_ntoa(vl_data->vl_peer));
961
962 if (area
963 && !IPV4_ADDR_SAME(&vl_data->vl_area_id, &area->area_id))
964 continue;
965
966 if (IPV4_ADDR_SAME(&vl_data->vl_peer, &vl_peer))
967 return vl_data;
968 }
969
970 return NULL;
718e3744 971}
972
d62a17ae 973static void ospf_vl_shutdown(struct ospf_vl_data *vl_data)
718e3744 974{
d62a17ae 975 struct ospf_interface *oi;
718e3744 976
d62a17ae 977 if ((oi = vl_data->vl_oi) == NULL)
978 return;
718e3744 979
d62a17ae 980 oi->address->u.prefix4.s_addr = 0;
981 oi->address->prefixlen = 0;
718e3744 982
d62a17ae 983 UNSET_FLAG(oi->ifp->flags, IFF_UP);
984 /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */
985 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
718e3744 986}
987
d62a17ae 988void ospf_vl_add(struct ospf *ospf, struct ospf_vl_data *vl_data)
718e3744 989{
d62a17ae 990 listnode_add(ospf->vlinks, vl_data);
991 hook_call(ospf_vl_add, vl_data);
718e3744 992}
993
d62a17ae 994void ospf_vl_delete(struct ospf *ospf, struct ospf_vl_data *vl_data)
718e3744 995{
d62a17ae 996 ospf_vl_shutdown(vl_data);
997 ospf_vl_if_delete(vl_data);
718e3744 998
d62a17ae 999 hook_call(ospf_vl_delete, vl_data);
1000 listnode_delete(ospf->vlinks, vl_data);
718e3744 1001
d62a17ae 1002 ospf_vl_data_free(vl_data);
718e3744 1003}
1004
d62a17ae 1005static int ospf_vl_set_params(struct ospf_vl_data *vl_data, struct vertex *v)
718e3744 1006{
d62a17ae 1007 int changed = 0;
1008 struct ospf_interface *voi;
1009 struct listnode *node;
1010 struct vertex_parent *vp = NULL;
1011 unsigned int i;
1012 struct router_lsa *rl;
1013
1014 voi = vl_data->vl_oi;
1015
1016 if (voi->output_cost != v->distance) {
1017
1018 voi->output_cost = v->distance;
1019 changed = 1;
1020 }
1021
1022 for (ALL_LIST_ELEMENTS_RO(v->parents, node, vp)) {
1023 vl_data->nexthop.oi = vp->nexthop->oi;
1024 vl_data->nexthop.router = vp->nexthop->router;
1025
1026 if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
1027 &vl_data->nexthop.oi->address->u.prefix4))
1028 changed = 1;
1029
1030 voi->address->u.prefix4 =
1031 vl_data->nexthop.oi->address->u.prefix4;
1032 voi->address->prefixlen =
1033 vl_data->nexthop.oi->address->prefixlen;
1034
1035 break; /* We take the first interface. */
1036 }
1037
1038 rl = (struct router_lsa *)v->lsa;
1039
1040 /* use SPF determined backlink index in struct vertex
1041 * for virtual link destination address
1042 */
1043 if (vp && vp->backlink >= 0) {
1044 if (!IPV4_ADDR_SAME(&vl_data->peer_addr,
1045 &rl->link[vp->backlink].link_data))
1046 changed = 1;
1047 vl_data->peer_addr = rl->link[vp->backlink].link_data;
1048 } else {
1049 /* This is highly odd, there is no backlink index
1050 * there should be due to the ospf_spf_has_link() check
1051 * in SPF. Lets warn and try pick a link anyway.
1052 */
266469eb 1053 zlog_info("ospf_vl_set_params: No backlink for %s!",
d62a17ae 1054 vl_data->vl_oi->ifp->name);
1055 for (i = 0; i < ntohs(rl->links); i++) {
1056 switch (rl->link[i].type) {
1057 case LSA_LINK_TYPE_VIRTUALLINK:
1058 if (IS_DEBUG_OSPF_EVENT)
1059 zlog_debug(
1060 "found back link through VL");
1061 /* fallthru */
1062 case LSA_LINK_TYPE_TRANSIT:
1063 case LSA_LINK_TYPE_POINTOPOINT:
1064 if (!IPV4_ADDR_SAME(&vl_data->peer_addr,
1065 &rl->link[i].link_data))
1066 changed = 1;
1067 vl_data->peer_addr = rl->link[i].link_data;
1068 }
1069 }
1070 }
1071
1072 if (IS_DEBUG_OSPF_EVENT)
1073 zlog_debug("%s: %s peer address: %s, cost: %d,%schanged",
1074 __func__, vl_data->vl_oi->ifp->name,
1075 inet_ntoa(vl_data->peer_addr), voi->output_cost,
1076 (changed ? " " : " un"));
1077
1078 return changed;
718e3744 1079}
1080
1081
d62a17ae 1082void ospf_vl_up_check(struct ospf_area *area, struct in_addr rid,
1083 struct vertex *v)
718e3744 1084{
d62a17ae 1085 struct ospf *ospf = area->ospf;
1086 struct listnode *node;
1087 struct ospf_vl_data *vl_data;
1088 struct ospf_interface *oi;
1089
1090 if (IS_DEBUG_OSPF_EVENT) {
1091 zlog_debug("ospf_vl_up_check(): Start");
1092 zlog_debug("ospf_vl_up_check(): Router ID is %s",
1093 inet_ntoa(rid));
1094 zlog_debug("ospf_vl_up_check(): Area is %s",
1095 inet_ntoa(area->area_id));
718e3744 1096 }
1097
d62a17ae 1098 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
1099 if (IS_DEBUG_OSPF_EVENT) {
1100 zlog_debug("%s: considering VL, %s in area %s",
1101 __func__, vl_data->vl_oi->ifp->name,
1102 inet_ntoa(vl_data->vl_area_id));
1103 zlog_debug("%s: peer ID: %s", __func__,
1104 inet_ntoa(vl_data->vl_peer));
1105 }
1106
1107 if (IPV4_ADDR_SAME(&vl_data->vl_peer, &rid)
1108 && IPV4_ADDR_SAME(&vl_data->vl_area_id, &area->area_id)) {
1109 oi = vl_data->vl_oi;
1110 SET_FLAG(vl_data->flags, OSPF_VL_FLAG_APPROVED);
1111
1112 if (IS_DEBUG_OSPF_EVENT)
1113 zlog_debug(
1114 "ospf_vl_up_check(): this VL matched");
1115
1116 if (oi->state == ISM_Down) {
1117 if (IS_DEBUG_OSPF_EVENT)
1118 zlog_debug(
1119 "ospf_vl_up_check(): VL is down, waking it up");
1120 SET_FLAG(oi->ifp->flags, IFF_UP);
1121 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
1122 }
1123
1124 if (ospf_vl_set_params(vl_data, v)) {
1125 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
1126 zlog_debug(
1127 "ospf_vl_up_check: VL cost change,"
1128 " scheduling router lsa refresh");
1129 if (ospf->backbone)
1130 ospf_router_lsa_update_area(
1131 ospf->backbone);
1132 else if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
1133 zlog_debug(
1134 "ospf_vl_up_check: VL cost change, no backbone!");
1135 }
1136 }
1137 }
718e3744 1138}
1139
d62a17ae 1140void ospf_vl_unapprove(struct ospf *ospf)
718e3744 1141{
d62a17ae 1142 struct listnode *node;
1143 struct ospf_vl_data *vl_data;
718e3744 1144
d62a17ae 1145 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data))
1146 UNSET_FLAG(vl_data->flags, OSPF_VL_FLAG_APPROVED);
718e3744 1147}
1148
d62a17ae 1149void ospf_vl_shut_unapproved(struct ospf *ospf)
718e3744 1150{
d62a17ae 1151 struct listnode *node, *nnode;
1152 struct ospf_vl_data *vl_data;
718e3744 1153
d62a17ae 1154 for (ALL_LIST_ELEMENTS(ospf->vlinks, node, nnode, vl_data))
1155 if (!CHECK_FLAG(vl_data->flags, OSPF_VL_FLAG_APPROVED))
1156 ospf_vl_shutdown(vl_data);
718e3744 1157}
1158
d62a17ae 1159int ospf_full_virtual_nbrs(struct ospf_area *area)
718e3744 1160{
d62a17ae 1161 if (IS_DEBUG_OSPF_EVENT) {
1162 zlog_debug(
1163 "counting fully adjacent virtual neighbors in area %s",
1164 inet_ntoa(area->area_id));
1165 zlog_debug("there are %d of them", area->full_vls);
1166 }
1167
1168 return area->full_vls;
718e3744 1169}
1170
d62a17ae 1171int ospf_vls_in_area(struct ospf_area *area)
718e3744 1172{
d62a17ae 1173 struct listnode *node;
1174 struct ospf_vl_data *vl_data;
1175 int c = 0;
718e3744 1176
d62a17ae 1177 for (ALL_LIST_ELEMENTS_RO(area->ospf->vlinks, node, vl_data))
1178 if (IPV4_ADDR_SAME(&vl_data->vl_area_id, &area->area_id))
1179 c++;
718e3744 1180
d62a17ae 1181 return c;
718e3744 1182}
1183
6b0655a2 1184
d62a17ae 1185struct crypt_key *ospf_crypt_key_new()
718e3744 1186{
d62a17ae 1187 return XCALLOC(MTYPE_OSPF_CRYPT_KEY, sizeof(struct crypt_key));
718e3744 1188}
1189
d62a17ae 1190void ospf_crypt_key_add(struct list *crypt, struct crypt_key *ck)
718e3744 1191{
d62a17ae 1192 listnode_add(crypt, ck);
718e3744 1193}
1194
d7c0a89a 1195struct crypt_key *ospf_crypt_key_lookup(struct list *auth_crypt, uint8_t key_id)
718e3744 1196{
d62a17ae 1197 struct listnode *node;
1198 struct crypt_key *ck;
718e3744 1199
d62a17ae 1200 for (ALL_LIST_ELEMENTS_RO(auth_crypt, node, ck))
1201 if (ck->key_id == key_id)
1202 return ck;
718e3744 1203
d62a17ae 1204 return NULL;
718e3744 1205}
1206
d7c0a89a 1207int ospf_crypt_key_delete(struct list *auth_crypt, uint8_t key_id)
718e3744 1208{
d62a17ae 1209 struct listnode *node, *nnode;
1210 struct crypt_key *ck;
1211
1212 for (ALL_LIST_ELEMENTS(auth_crypt, node, nnode, ck)) {
1213 if (ck->key_id == key_id) {
1214 listnode_delete(auth_crypt, ck);
1215 XFREE(MTYPE_OSPF_CRYPT_KEY, ck);
1216 return 1;
1217 }
1218 }
1219
1220 return 0;
718e3744 1221}
1222
d7c0a89a 1223uint8_t ospf_default_iftype(struct interface *ifp)
bc18d616 1224{
d62a17ae 1225 if (if_is_pointopoint(ifp))
1226 return OSPF_IFTYPE_POINTOPOINT;
0c74bbe0 1227 else if (if_is_loopback(ifp) || if_is_vrf(ifp))
d62a17ae 1228 return OSPF_IFTYPE_LOOPBACK;
1229 else
1230 return OSPF_IFTYPE_BROADCAST;
bc18d616 1231}
1232
d62a17ae 1233void ospf_if_init()
718e3744 1234{
d62a17ae 1235 /* Initialize Zebra interface data structure. */
ce19a04a
DL
1236 hook_register_prio(if_add, 0, ospf_if_new_hook);
1237 hook_register_prio(if_del, 0, ospf_if_delete_hook);
718e3744 1238}