blob: 82c4baee91db61b941e2bd8b02d268900594a548 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * OSPF Interface functions.
3 * Copyright (C) 1999, 2000 Toshiaki Takada
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
25#include "thread.h"
26#include "linklist.h"
27#include "prefix.h"
28#include "if.h"
29#include "table.h"
30#include "memory.h"
31#include "command.h"
32#include "stream.h"
33#include "log.h"
34
paul68980082003-03-25 05:07:42 +000035#include "ospfd/ospfd.h"
paul718e3742002-12-13 20:15:29 +000036#include "ospfd/ospf_spf.h"
37#include "ospfd/ospf_interface.h"
38#include "ospfd/ospf_ism.h"
39#include "ospfd/ospf_asbr.h"
40#include "ospfd/ospf_lsa.h"
41#include "ospfd/ospf_lsdb.h"
42#include "ospfd/ospf_neighbor.h"
43#include "ospfd/ospf_nsm.h"
44#include "ospfd/ospf_packet.h"
45#include "ospfd/ospf_abr.h"
paul718e3742002-12-13 20:15:29 +000046#include "ospfd/ospf_network.h"
47#include "ospfd/ospf_dump.h"
48#ifdef HAVE_SNMP
49#include "ospfd/ospf_snmp.h"
50#endif /* HAVE_SNMP */
51
52
53int
54ospf_if_get_output_cost (struct ospf_interface *oi)
55{
56 /* If all else fails, use default OSPF cost */
57 u_int32_t cost;
58 u_int32_t bw, refbw;
59
60 bw = oi->ifp->bandwidth ? oi->ifp->bandwidth : OSPF_DEFAULT_BANDWIDTH;
paul68980082003-03-25 05:07:42 +000061 refbw = oi->ospf->ref_bandwidth;
paul718e3742002-12-13 20:15:29 +000062
63 /* A specifed ip ospf cost overrides a calculated one. */
64 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (oi->ifp), output_cost_cmd) ||
65 OSPF_IF_PARAM_CONFIGURED (oi->params, output_cost_cmd))
66 cost = OSPF_IF_PARAM (oi, output_cost_cmd);
67 /* See if a cost can be calculated from the zebra processes
68 interface bandwidth field. */
69 else
70 {
71 cost = (u_int32_t) ((double)refbw / (double)bw + (double)0.5);
72 if (cost < 1)
73 cost = 1;
74 else if (cost > 65535)
75 cost = 65535;
76 }
77
78 return cost;
79}
80
81void
82ospf_if_recalculate_output_cost (struct interface *ifp)
83{
84 u_int32_t newcost;
85 struct route_node *rn;
86
87 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
88 {
89 struct ospf_interface *oi;
90
91 if ( (oi = rn->info) == NULL)
92 continue;
93
94 newcost = ospf_if_get_output_cost (oi);
95
96 /* Is actual output cost changed? */
97 if (oi->output_cost != newcost)
98 {
99 oi->output_cost = newcost;
100 ospf_router_lsa_timer_add (oi->area);
101 }
102 }
103}
104
ajsa608bbf2005-03-29 17:03:49 +0000105/* Simulate down/up on the interface. This is needed, for example, when
106 the MTU changes. */
107void
108ospf_if_reset(struct interface *ifp)
109{
110 struct route_node *rn;
111
112 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
113 {
114 struct ospf_interface *oi;
115
116 if ( (oi = rn->info) == NULL)
117 continue;
118
119 ospf_if_down(oi);
120 ospf_if_up(oi);
121 }
122}
123
paul718e3742002-12-13 20:15:29 +0000124void
125ospf_if_reset_variables (struct ospf_interface *oi)
126{
127 /* Set default values. */
128 /* don't clear this flag. oi->flag = OSPF_IF_DISABLE; */
129
130 if (oi->vl_data)
131 oi->type = OSPF_IFTYPE_VIRTUALLINK;
132 else
133 /* preserve network-type */
134 if (oi->type != OSPF_IFTYPE_NBMA)
135 oi->type = OSPF_IFTYPE_BROADCAST;
136
137 oi->state = ISM_Down;
138
139 oi->crypt_seqnum = 0;
140
141 /* This must be short, (less than RxmtInterval)
142 - RFC 2328 Section 13.5 para 3. Set to 1 second to avoid Acks being
143 held back for too long - MAG */
144 oi->v_ls_ack = 1;
145}
146
paul20916fb2003-10-15 21:14:20 +0000147/* lookup oi for specified prefix/ifp */
paul4dadc292005-05-06 21:37:42 +0000148static struct ospf_interface *
paul20916fb2003-10-15 21:14:20 +0000149ospf_if_table_lookup (struct interface *ifp, struct prefix *prefix)
150{
151 struct prefix p;
paulaffe1d92003-10-15 21:40:57 +0000152 struct route_node *rn;
paula3387a42005-05-18 23:29:57 +0000153 struct ospf_interface *rninfo = NULL;
paul20916fb2003-10-15 21:14:20 +0000154
155 p = *prefix;
paula3387a42005-05-18 23:29:57 +0000156 p.prefixlen = IPV4_MAX_PREFIXLEN;
157
paul20916fb2003-10-15 21:14:20 +0000158 /* route_node_get implicitely locks */
paulf9ad9372005-10-21 00:45:17 +0000159 if ((rn = route_node_lookup (IF_OIFS (ifp), &p)))
paula3387a42005-05-18 23:29:57 +0000160 {
161 rninfo = (struct ospf_interface *) rn->info;
162 route_unlock_node (rn);
163 }
164
paulb5f2c122003-11-10 23:56:29 +0000165 return rninfo;
paul20916fb2003-10-15 21:14:20 +0000166}
167
paul4dadc292005-05-06 21:37:42 +0000168static void
paul718e3742002-12-13 20:15:29 +0000169ospf_add_to_if (struct interface *ifp, struct ospf_interface *oi)
170{
171 struct route_node *rn;
172 struct prefix p;
173
174 p = *oi->address;
175 p.prefixlen = IPV4_MAX_PREFIXLEN;
176
177 rn = route_node_get (IF_OIFS (ifp), &p);
paul8c80cb72003-02-18 23:25:44 +0000178 /* rn->info should either be NULL or equal to this oi
179 * as route_node_get may return an existing node
180 */
paul20916fb2003-10-15 21:14:20 +0000181 assert (!rn->info || rn->info == oi);
paul718e3742002-12-13 20:15:29 +0000182 rn->info = oi;
183}
184
paul4dadc292005-05-06 21:37:42 +0000185static void
paul718e3742002-12-13 20:15:29 +0000186ospf_delete_from_if (struct interface *ifp, struct ospf_interface *oi)
187{
188 struct route_node *rn;
189 struct prefix p;
190
191 p = *oi->address;
192 p.prefixlen = IPV4_MAX_PREFIXLEN;
193
194 rn = route_node_lookup (IF_OIFS (oi->ifp), &p);
195 assert (rn);
196 assert (rn->info);
197 rn->info = NULL;
198 route_unlock_node (rn);
199 route_unlock_node (rn);
200}
201
202struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000203ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p)
paul718e3742002-12-13 20:15:29 +0000204{
205 struct ospf_interface *oi;
206
paul20916fb2003-10-15 21:14:20 +0000207 if ((oi = ospf_if_table_lookup (ifp, p)) == NULL)
208 {
209 oi = XCALLOC (MTYPE_OSPF_IF, sizeof (struct ospf_interface));
210 memset (oi, 0, sizeof (struct ospf_interface));
211 }
212 else
213 return oi;
214
paul718e3742002-12-13 20:15:29 +0000215 /* Set zebra interface pointer. */
216 oi->ifp = ifp;
217 oi->address = p;
218
219 ospf_add_to_if (ifp, oi);
paul68980082003-03-25 05:07:42 +0000220 listnode_add (ospf->oiflist, oi);
paul718e3742002-12-13 20:15:29 +0000221
222 /* Clear self-originated network-LSA. */
223 oi->network_lsa_self = NULL;
224
225 /* Initialize neighbor list. */
226 oi->nbrs = route_table_init ();
227
228 /* Initialize static neighbor list. */
229 oi->nbr_nbma = list_new ();
230
231 /* Initialize Link State Acknowledgment list. */
232 oi->ls_ack = list_new ();
233 oi->ls_ack_direct.ls_ack = list_new ();
234
235 /* Set default values. */
236 ospf_if_reset_variables (oi);
237
238 /* Add pseudo neighbor. */
239 oi->nbr_self = ospf_nbr_new (oi);
paul718e3742002-12-13 20:15:29 +0000240
241 oi->ls_upd_queue = route_table_init ();
242 oi->t_ls_upd_event = NULL;
243 oi->t_ls_ack_direct = NULL;
244
paul68980082003-03-25 05:07:42 +0000245 oi->crypt_seqnum = time (NULL);
246
paul718e3742002-12-13 20:15:29 +0000247#ifdef HAVE_OPAQUE_LSA
248 ospf_opaque_type9_lsa_init (oi);
249#endif /* HAVE_OPAQUE_LSA */
250
paul68980082003-03-25 05:07:42 +0000251 oi->ospf = ospf;
paul718e3742002-12-13 20:15:29 +0000252
253 return oi;
254}
255
256/* Restore an interface to its pre UP state
257 Used from ism_interface_down only */
258void
259ospf_if_cleanup (struct ospf_interface *oi)
260{
261 struct route_node *rn;
paul1eb8ef22005-04-07 07:30:20 +0000262 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000263 struct ospf_neighbor *nbr;
paul1eb8ef22005-04-07 07:30:20 +0000264 struct ospf_nbr_nbma *nbr_nbma;
265 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000266
paul1a643f82006-01-11 01:08:19 +0000267 /* oi->nbrs and oi->nbr_nbma should be deleted on InterfaceDown event */
paul718e3742002-12-13 20:15:29 +0000268 /* delete all static neighbors attached to this interface */
paul1eb8ef22005-04-07 07:30:20 +0000269 for (ALL_LIST_ELEMENTS (oi->nbr_nbma, node, nnode, nbr_nbma))
paul718e3742002-12-13 20:15:29 +0000270 {
paul718e3742002-12-13 20:15:29 +0000271 OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll);
272
273 if (nbr_nbma->nbr)
274 {
275 nbr_nbma->nbr->nbr_nbma = NULL;
276 nbr_nbma->nbr = NULL;
277 }
278
279 nbr_nbma->oi = NULL;
280
281 listnode_delete (oi->nbr_nbma, nbr_nbma);
282 }
283
284 /* send Neighbor event KillNbr to all associated neighbors. */
285 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
286 if ((nbr = rn->info) != NULL)
287 if (nbr != oi->nbr_self)
288 OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr);
289
290 /* Cleanup Link State Acknowlegdment list. */
paul1eb8ef22005-04-07 07:30:20 +0000291 for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa))
292 ospf_lsa_unlock (lsa);
paul718e3742002-12-13 20:15:29 +0000293 list_delete_all_node (oi->ls_ack);
294
295 oi->crypt_seqnum = 0;
296
297 /* Empty link state update queue */
298 ospf_ls_upd_queue_empty (oi);
299
paul1a643f82006-01-11 01:08:19 +0000300 /* Reset pseudo neighbor. */
paul718e3742002-12-13 20:15:29 +0000301 ospf_nbr_delete (oi->nbr_self);
302 oi->nbr_self = ospf_nbr_new (oi);
paul1a643f82006-01-11 01:08:19 +0000303 ospf_nbr_add_self (oi);
304
paul718e3742002-12-13 20:15:29 +0000305 ospf_lsa_unlock (oi->network_lsa_self);
306 oi->network_lsa_self = NULL;
307 OSPF_TIMER_OFF (oi->t_network_lsa_self);
308}
309
310void
311ospf_if_free (struct ospf_interface *oi)
312{
313 ospf_if_down (oi);
314
315 assert (oi->state == ISM_Down);
316
317#ifdef HAVE_OPAQUE_LSA
318 ospf_opaque_type9_lsa_term (oi);
319#endif /* HAVE_OPAQUE_LSA */
320
321 /* Free Pseudo Neighbour */
322 ospf_nbr_delete (oi->nbr_self);
323
324 route_table_finish (oi->nbrs);
325 route_table_finish (oi->ls_upd_queue);
326
327 /* Free any lists that should be freed */
328 list_free (oi->nbr_nbma);
329
330 list_free (oi->ls_ack);
331 list_free (oi->ls_ack_direct.ls_ack);
332
333 ospf_delete_from_if (oi->ifp, oi);
334
paul68980082003-03-25 05:07:42 +0000335 listnode_delete (oi->ospf->oiflist, oi);
paul718e3742002-12-13 20:15:29 +0000336 listnode_delete (oi->area->oiflist, oi);
337
338 memset (oi, 0, sizeof (*oi));
339 XFREE (MTYPE_OSPF_IF, oi);
340}
341
342
343/*
344* check if interface with given address is configured and
hasso3fb9cd62004-10-19 19:44:43 +0000345* return it if yes. special treatment for PtP networks.
paul718e3742002-12-13 20:15:29 +0000346*/
347struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000348ospf_if_is_configured (struct ospf *ospf, struct in_addr *address)
paul718e3742002-12-13 20:15:29 +0000349{
paul1eb8ef22005-04-07 07:30:20 +0000350 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000351 struct ospf_interface *oi;
hasso3fb9cd62004-10-19 19:44:43 +0000352 struct prefix_ipv4 addr;
353
354 addr.family = AF_INET;
355 addr.prefix = *address;
356 addr.prefixlen = IPV4_MAX_PREFIXLEN;
paul718e3742002-12-13 20:15:29 +0000357
paul1eb8ef22005-04-07 07:30:20 +0000358 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
359 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul718e3742002-12-13 20:15:29 +0000360 {
361 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
hasso3fb9cd62004-10-19 19:44:43 +0000362 {
363 if (CONNECTED_DEST_HOST(oi->connected))
364 {
365 /* match only destination addr, since local addr is most likely
366 * not unique (borrowed from another interface) */
367 if (IPV4_ADDR_SAME (address,
368 &oi->connected->destination->u.prefix4))
369 return oi;
370 }
371 else
372 {
373 /* special leniency: match if addr is anywhere on PtP subnet */
374 if (prefix_match(oi->address,(struct prefix *)&addr))
375 return oi;
376 }
377 }
paul718e3742002-12-13 20:15:29 +0000378 else
hasso3fb9cd62004-10-19 19:44:43 +0000379 {
380 if (IPV4_ADDR_SAME (address, &oi->address->u.prefix4))
381 return oi;
382 }
paul718e3742002-12-13 20:15:29 +0000383 }
paul718e3742002-12-13 20:15:29 +0000384 return NULL;
385}
386
387int
388ospf_if_is_up (struct ospf_interface *oi)
389{
390 return if_is_up (oi->ifp);
391}
392
393struct ospf_interface *
hasso2db3d052004-02-11 21:52:13 +0000394ospf_if_exists (struct ospf_interface *oic)
395{
hasso52dc7ee2004-09-23 19:18:23 +0000396 struct listnode *node;
hasso2db3d052004-02-11 21:52:13 +0000397 struct ospf *ospf;
398 struct ospf_interface *oi;
399
400 ospf = ospf_lookup ();
401
paul1eb8ef22005-04-07 07:30:20 +0000402 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
403 if (oi == oic)
hasso2db3d052004-02-11 21:52:13 +0000404 return oi;
paul1eb8ef22005-04-07 07:30:20 +0000405
hasso2db3d052004-02-11 21:52:13 +0000406 return NULL;
407}
408
409struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000410ospf_if_lookup_by_local_addr (struct ospf *ospf,
411 struct interface *ifp, struct in_addr address)
paul718e3742002-12-13 20:15:29 +0000412{
hasso52dc7ee2004-09-23 19:18:23 +0000413 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000414 struct ospf_interface *oi;
415
paul1eb8ef22005-04-07 07:30:20 +0000416 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
417 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul718e3742002-12-13 20:15:29 +0000418 {
419 if (ifp && oi->ifp != ifp)
420 continue;
421
422 if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4))
423 return oi;
424 }
425
426 return NULL;
427}
428
429struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000430ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000431{
hasso52dc7ee2004-09-23 19:18:23 +0000432 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000433 struct ospf_interface *oi;
434 struct prefix ptmp;
435
436 /* Check each Interface. */
paul1eb8ef22005-04-07 07:30:20 +0000437 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
paul68980082003-03-25 05:07:42 +0000438 {
paul1eb8ef22005-04-07 07:30:20 +0000439 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul68980082003-03-25 05:07:42 +0000440 {
hasso3fb9cd62004-10-19 19:44:43 +0000441 if ((oi->type == OSPF_IFTYPE_POINTOPOINT) &&
442 CONNECTED_DEST_HOST(oi->connected))
paul68980082003-03-25 05:07:42 +0000443 {
444 prefix_copy (&ptmp, oi->connected->destination);
445 ptmp.prefixlen = IPV4_MAX_BITLEN;
446 }
447 else
448 prefix_copy (&ptmp, oi->address);
paul718e3742002-12-13 20:15:29 +0000449
paul68980082003-03-25 05:07:42 +0000450 apply_mask (&ptmp);
451 if (prefix_same (&ptmp, (struct prefix *) p))
452 return oi;
453 }
454 }
paul718e3742002-12-13 20:15:29 +0000455 return NULL;
456}
457
458/* determine receiving interface by source of packet */
459struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000460ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src)
paul718e3742002-12-13 20:15:29 +0000461{
hasso52dc7ee2004-09-23 19:18:23 +0000462 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000463 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
paul1eb8ef22005-04-07 07:30:20 +0000472 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
paul718e3742002-12-13 20:15:29 +0000473 {
paul718e3742002-12-13 20:15:29 +0000474 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
475 continue;
476
hasso3fb9cd62004-10-19 19:44:43 +0000477 if ((oi->type == OSPF_IFTYPE_POINTOPOINT) &&
478 CONNECTED_DEST_HOST(oi->connected))
paul718e3742002-12-13 20:15:29 +0000479 {
480 if (IPV4_ADDR_SAME (&oi->connected->destination->u.prefix4, &src))
481 return oi;
482 }
483 else
484 {
485 if (prefix_match (oi->address, (struct prefix *) &addr))
paul0a825c72003-05-24 13:48:16 +0000486 {
paulaf8d0332003-05-24 15:31:45 +0000487 if ( (match == NULL) ||
488 (match->address->prefixlen < oi->address->prefixlen)
489 )
paul0a825c72003-05-24 13:48:16 +0000490 match = oi;
491 }
paul718e3742002-12-13 20:15:29 +0000492 }
493 }
494
495 return match;
496}
497
498void
499ospf_if_stream_set (struct ospf_interface *oi)
500{
501 /* set output fifo queue. */
502 if (oi->obuf == NULL)
503 oi->obuf = ospf_fifo_new ();
504}
505
506void
507ospf_if_stream_unset (struct ospf_interface *oi)
508{
paul68980082003-03-25 05:07:42 +0000509 struct ospf *ospf = oi->ospf;
510
paul718e3742002-12-13 20:15:29 +0000511 if (oi->obuf)
512 {
513 ospf_fifo_free (oi->obuf);
514 oi->obuf = NULL;
515
516 if (oi->on_write_q)
517 {
paul68980082003-03-25 05:07:42 +0000518 listnode_delete (ospf->oi_write_q, oi);
519 if (list_isempty(ospf->oi_write_q))
520 OSPF_TIMER_OFF (ospf->t_write);
paul718e3742002-12-13 20:15:29 +0000521 oi->on_write_q = 0;
522 }
523 }
524}
paul68980082003-03-25 05:07:42 +0000525
paul718e3742002-12-13 20:15:29 +0000526
paul4dadc292005-05-06 21:37:42 +0000527static struct ospf_if_params *
528ospf_new_if_params (void)
paul718e3742002-12-13 20:15:29 +0000529{
530 struct ospf_if_params *oip;
531
532 oip = XMALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params));
paul718e3742002-12-13 20:15:29 +0000533
534 if (!oip)
535 return NULL;
536
paulf6457892003-04-17 16:11:30 +0000537 memset (oip, 0, sizeof (struct ospf_if_params));
538
paul718e3742002-12-13 20:15:29 +0000539 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);
paulf9ad9372005-10-21 00:45:17 +0000544 UNSET_IF_PARAM (oip, fast_hello);
paul718e3742002-12-13 20:15:29 +0000545 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);
paulec1ca632003-06-04 02:23:15 +0000551
552 oip->auth_crypt = list_new ();
paul718e3742002-12-13 20:15:29 +0000553
paul718e3742002-12-13 20:15:29 +0000554 return oip;
555}
556
557void
558ospf_del_if_params (struct ospf_if_params *oip)
559{
560 list_delete (oip->auth_crypt);
561 XFREE (MTYPE_OSPF_IF_PARAMS, oip);
562}
563
564void
565ospf_free_if_params (struct interface *ifp, struct in_addr addr)
566{
567 struct ospf_if_params *oip;
568 struct prefix_ipv4 p;
569 struct route_node *rn;
gdt630e4802004-08-31 17:28:41 +0000570
571 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000572 p.prefixlen = IPV4_MAX_PREFIXLEN;
573 p.prefix = addr;
574 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
575 if (!rn || !rn->info)
576 return;
577
578 oip = rn->info;
579 route_unlock_node (rn);
580
581 if (!OSPF_IF_PARAM_CONFIGURED (oip, output_cost_cmd) &&
582 !OSPF_IF_PARAM_CONFIGURED (oip, transmit_delay) &&
583 !OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) &&
584 !OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) &&
585 !OSPF_IF_PARAM_CONFIGURED (oip, v_hello) &&
paulf9ad9372005-10-21 00:45:17 +0000586 !OSPF_IF_PARAM_CONFIGURED (oip, fast_hello) &&
paul718e3742002-12-13 20:15:29 +0000587 !OSPF_IF_PARAM_CONFIGURED (oip, v_wait) &&
588 !OSPF_IF_PARAM_CONFIGURED (oip, priority) &&
589 !OSPF_IF_PARAM_CONFIGURED (oip, type) &&
590 !OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) &&
591 !OSPF_IF_PARAM_CONFIGURED (oip, auth_type) &&
592 listcount (oip->auth_crypt) == 0)
593 {
594 ospf_del_if_params (oip);
595 rn->info = NULL;
596 route_unlock_node (rn);
597 }
598}
599
600struct ospf_if_params *
601ospf_lookup_if_params (struct interface *ifp, struct in_addr addr)
602{
603 struct prefix_ipv4 p;
604 struct route_node *rn;
605
gdt630e4802004-08-31 17:28:41 +0000606 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000607 p.prefixlen = IPV4_MAX_PREFIXLEN;
608 p.prefix = addr;
609
610 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
611
612 if (rn)
613 {
614 route_unlock_node (rn);
615 return rn->info;
616 }
617
618 return NULL;
619}
620
621struct ospf_if_params *
622ospf_get_if_params (struct interface *ifp, struct in_addr addr)
623{
624 struct prefix_ipv4 p;
625 struct route_node *rn;
626
627 p.family = AF_INET;
628 p.prefixlen = IPV4_MAX_PREFIXLEN;
629 p.prefix = addr;
630
631 rn = route_node_get (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
632
633 if (rn->info == NULL)
634 rn->info = ospf_new_if_params ();
635 else
636 route_unlock_node (rn);
637
638 return rn->info;
639}
640
641void
642ospf_if_update_params (struct interface *ifp, struct in_addr addr)
643{
644 struct route_node *rn;
645 struct ospf_interface *oi;
646
647 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
648 {
649 if ((oi = rn->info) == NULL)
650 continue;
651
652 if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &addr))
653 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
654 }
655}
656
657int
658ospf_if_new_hook (struct interface *ifp)
659{
660 int rc = 0;
661
662 ifp->info = XMALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info));
663 memset (ifp->info, 0, sizeof (struct ospf_if_info));
664
665 IF_OIFS (ifp) = route_table_init ();
666 IF_OIFS_PARAMS (ifp) = route_table_init ();
667
668 IF_DEF_PARAMS (ifp) = ospf_new_if_params ();
669
670 SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay);
671 IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
672
673 SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval);
674 IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
675
676 SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority);
677 IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
678
vincentba682532005-09-29 13:52:57 +0000679 IF_DEF_PARAMS (ifp)->mtu_ignore = OSPF_MTU_IGNORE_DEFAULT;
680
paul718e3742002-12-13 20:15:29 +0000681 SET_IF_PARAM (IF_DEF_PARAMS (ifp), passive_interface);
682 IF_DEF_PARAMS (ifp)->passive_interface = OSPF_IF_ACTIVE;
683
684 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello);
685 IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
686
paulf9ad9372005-10-21 00:45:17 +0000687 SET_IF_PARAM (IF_DEF_PARAMS (ifp), fast_hello);
688 IF_DEF_PARAMS (ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT;
689
paul718e3742002-12-13 20:15:29 +0000690 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
paul718e3742002-12-13 20:15:29 +0000696 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
paul4dadc292005-05-06 21:37:42 +0000705static int
paul718e3742002-12-13 20:15:29 +0000706ospf_if_delete_hook (struct interface *ifp)
707{
708 int rc = 0;
paul940b01a2004-02-17 20:07:30 +0000709 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +0000710#ifdef HAVE_OPAQUE_LSA
711 rc = ospf_opaque_del_if (ifp);
712#endif /* HAVE_OPAQUE_LSA */
paul940b01a2004-02-17 20:07:30 +0000713
paul718e3742002-12-13 20:15:29 +0000714 route_table_finish (IF_OIFS (ifp));
paul940b01a2004-02-17 20:07:30 +0000715
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);
paul718e3742002-12-13 20:15:29 +0000719 route_table_finish (IF_OIFS_PARAMS (ifp));
paul940b01a2004-02-17 20:07:30 +0000720
paulcfc959b2003-06-04 02:28:45 +0000721 ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp));
paul718e3742002-12-13 20:15:29 +0000722 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
ajsba6454e2005-02-08 15:37:30 +0000738void
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) &&
744 (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE))
745 {
746 /* The interface should belong to the OSPF-all-routers group. */
747 if (!CHECK_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS) &&
748 (ospf_if_add_allspfrouters(oi->ospf, oi->address,
749 oi->ifp->ifindex) >= 0))
750 /* Set the flag only if the system call to join succeeded. */
751 SET_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS);
752 }
753 else
754 {
755 /* The interface should NOT belong to the OSPF-all-routers group. */
756 if (CHECK_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS))
757 {
758 ospf_if_drop_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex);
759 /* Unset the flag regardless of whether the system call to leave
760 the group succeeded, since it's much safer to assume that
761 we are not a member. */
762 UNSET_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS);
763 }
764 }
765
766 if (((oi->type == OSPF_IFTYPE_BROADCAST) ||
767 (oi->type == OSPF_IFTYPE_POINTOPOINT)) &&
768 ((oi->state == ISM_DR) || (oi->state == ISM_Backup)) &&
769 (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE))
770 {
771 /* The interface should belong to the OSPF-designated-routers group. */
772 if (!CHECK_FLAG(oi->multicast_memberships, MEMBER_DROUTERS) &&
773 (ospf_if_add_alldrouters(oi->ospf, oi->address,
774 oi->ifp->ifindex) >= 0))
775 /* Set the flag only if the system call to join succeeded. */
776 SET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS);
777 }
778 else
779 {
780 /* The interface should NOT belong to the OSPF-designated-routers group */
781 if (CHECK_FLAG(oi->multicast_memberships, MEMBER_DROUTERS))
782 {
783 ospf_if_drop_alldrouters(oi->ospf, oi->address, oi->ifp->ifindex);
784 /* Unset the flag regardless of whether the system call to leave
785 the group succeeded, since it's much safer to assume that
786 we are not a member. */
787 UNSET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS);
788 }
789 }
790}
791
paul718e3742002-12-13 20:15:29 +0000792int
793ospf_if_up (struct ospf_interface *oi)
794{
795 if (oi == NULL)
796 return 0;
797
798 if (oi->type == OSPF_IFTYPE_LOOPBACK)
799 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd);
800 else
801 {
paul718e3742002-12-13 20:15:29 +0000802 ospf_if_stream_set (oi);
803 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp);
804 }
805
806 return 1;
807}
808
809int
810ospf_if_down (struct ospf_interface *oi)
811{
812 if (oi == NULL)
813 return 0;
814
815 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
816 /* Shutdown packet reception and sending */
817 ospf_if_stream_unset (oi);
paul718e3742002-12-13 20:15:29 +0000818
819 return 1;
820}
821
822
823/* Virtual Link related functions. */
824
825struct ospf_vl_data *
826ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer)
827{
828 struct ospf_vl_data *vl_data;
829
830 vl_data = XMALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data));
831 memset (vl_data, 0, sizeof (struct ospf_vl_data));
832
833 vl_data->vl_peer.s_addr = vl_peer.s_addr;
834 vl_data->vl_area_id = area->area_id;
835 vl_data->format = area->format;
836
837 return vl_data;
838}
839
840void
841ospf_vl_data_free (struct ospf_vl_data *vl_data)
842{
843 XFREE (MTYPE_OSPF_VL_DATA, vl_data);
844}
845
846u_int vlink_count = 0;
847
848struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000849ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000850{
851 struct ospf_interface * voi;
852 struct interface * vi;
853 char ifname[INTERFACE_NAMSIZ + 1];
854 struct ospf_area *area;
855 struct in_addr area_id;
856 struct connected *co;
857 struct prefix_ipv4 *p;
858
859 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000860 zlog_debug ("ospf_vl_new(): Start");
paul718e3742002-12-13 20:15:29 +0000861 if (vlink_count == OSPF_VL_MAX_COUNT)
862 {
863 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000864 zlog_debug ("ospf_vl_new(): Alarm: "
paul718e3742002-12-13 20:15:29 +0000865 "cannot create more than OSPF_MAX_VL_COUNT virtual links");
866 return NULL;
867 }
868
869 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000870 zlog_debug ("ospf_vl_new(): creating pseudo zebra interface");
paul718e3742002-12-13 20:15:29 +0000871
ajsa3491982005-04-02 22:50:38 +0000872 snprintf (ifname, sizeof(ifname), "VLINK%d", vlink_count);
873 vi = if_create (ifname, strnlen(ifname, sizeof(ifname)));
paul718e3742002-12-13 20:15:29 +0000874 co = connected_new ();
875 co->ifp = vi;
876 listnode_add (vi->connected, co);
877
878 p = prefix_ipv4_new ();
879 p->family = AF_INET;
880 p->prefix.s_addr = 0;
881 p->prefixlen = 0;
882
883 co->address = (struct prefix *)p;
884
paul68980082003-03-25 05:07:42 +0000885 voi = ospf_if_new (ospf, vi, co->address);
paul718e3742002-12-13 20:15:29 +0000886 if (voi == NULL)
887 {
888 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000889 zlog_debug ("ospf_vl_new(): Alarm: OSPF int structure is not created");
paul718e3742002-12-13 20:15:29 +0000890 return NULL;
891 }
892 voi->connected = co;
893 voi->vl_data = vl_data;
894 voi->ifp->mtu = OSPF_VL_MTU;
895 voi->type = OSPF_IFTYPE_VIRTUALLINK;
896
paul106d2fd2003-08-01 00:24:13 +0000897 vlink_count++;
paul718e3742002-12-13 20:15:29 +0000898 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000899 zlog_debug ("ospf_vl_new(): Created name: %s", ifname);
paul718e3742002-12-13 20:15:29 +0000900 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000901 zlog_debug ("ospf_vl_new(): set if->name to %s", vi->name);
paul718e3742002-12-13 20:15:29 +0000902
903 area_id.s_addr = 0;
paul68980082003-03-25 05:07:42 +0000904 area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS);
paul718e3742002-12-13 20:15:29 +0000905 voi->area = area;
906
907 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000908 zlog_debug ("ospf_vl_new(): set associated area to the backbone");
paul718e3742002-12-13 20:15:29 +0000909
910 ospf_area_add_if (voi->area, voi);
911
912 ospf_if_stream_set (voi);
913
914 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000915 zlog_debug ("ospf_vl_new(): Stop");
paul718e3742002-12-13 20:15:29 +0000916 return voi;
917}
918
paul4dadc292005-05-06 21:37:42 +0000919static void
paul718e3742002-12-13 20:15:29 +0000920ospf_vl_if_delete (struct ospf_vl_data *vl_data)
921{
922 struct interface *ifp = vl_data->vl_oi->ifp;
923 vl_data->vl_oi->address->u.prefix4.s_addr = 0;
924 vl_data->vl_oi->address->prefixlen = 0;
925 ospf_if_free (vl_data->vl_oi);
926 if_delete (ifp);
927 vlink_count--;
928}
929
930struct ospf_vl_data *
931ospf_vl_lookup (struct ospf_area *area, struct in_addr vl_peer)
932{
933 struct ospf_vl_data *vl_data;
hasso52dc7ee2004-09-23 19:18:23 +0000934 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000935
paul1eb8ef22005-04-07 07:30:20 +0000936 for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
937 if (vl_data->vl_peer.s_addr == vl_peer.s_addr &&
938 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
939 return vl_data;
paul718e3742002-12-13 20:15:29 +0000940
941 return NULL;
942}
943
paul4dadc292005-05-06 21:37:42 +0000944static void
paul718e3742002-12-13 20:15:29 +0000945ospf_vl_shutdown (struct ospf_vl_data *vl_data)
946{
947 struct ospf_interface *oi;
948
949 if ((oi = vl_data->vl_oi) == NULL)
950 return;
951
952 oi->address->u.prefix4.s_addr = 0;
953 oi->address->prefixlen = 0;
954
955 UNSET_FLAG (oi->ifp->flags, IFF_UP);
956 /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */
957 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
958}
959
960void
paul68980082003-03-25 05:07:42 +0000961ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000962{
paul68980082003-03-25 05:07:42 +0000963 listnode_add (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000964#ifdef HAVE_SNMP
965 ospf_snmp_vl_add (vl_data);
966#endif /* HAVE_SNMP */
967}
968
969void
paul68980082003-03-25 05:07:42 +0000970ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000971{
972 ospf_vl_shutdown (vl_data);
973 ospf_vl_if_delete (vl_data);
974
975#ifdef HAVE_SNMP
976 ospf_snmp_vl_delete (vl_data);
977#endif /* HAVE_SNMP */
paul68980082003-03-25 05:07:42 +0000978 listnode_delete (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000979
980 ospf_vl_data_free (vl_data);
981}
982
paul4dadc292005-05-06 21:37:42 +0000983static int
paul718e3742002-12-13 20:15:29 +0000984ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v)
985{
986 int changed = 0;
987 struct ospf_interface *voi;
hasso52dc7ee2004-09-23 19:18:23 +0000988 struct listnode *node;
pauleb3da6d2005-10-18 04:20:33 +0000989 struct vertex_parent *vp = NULL;
paul718e3742002-12-13 20:15:29 +0000990 int i;
991 struct router_lsa *rl;
992
993 voi = vl_data->vl_oi;
994
995 if (voi->output_cost != v->distance)
996 {
paulcd59da62004-05-05 17:26:55 +0000997
paul718e3742002-12-13 20:15:29 +0000998 voi->output_cost = v->distance;
999 changed = 1;
1000 }
1001
pauleb3da6d2005-10-18 04:20:33 +00001002 for (ALL_LIST_ELEMENTS_RO (v->parents, node, vp))
paul1eb8ef22005-04-07 07:30:20 +00001003 {
pauleb3da6d2005-10-18 04:20:33 +00001004 vl_data->out_oi = vp->nexthop->oi;
paul1eb8ef22005-04-07 07:30:20 +00001005
1006 if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
1007 &vl_data->out_oi->address->u.prefix4))
1008 changed = 1;
paulcd59da62004-05-05 17:26:55 +00001009
paul1eb8ef22005-04-07 07:30:20 +00001010 voi->address->u.prefix4 = vl_data->out_oi->address->u.prefix4;
1011 voi->address->prefixlen = vl_data->out_oi->address->prefixlen;
paul718e3742002-12-13 20:15:29 +00001012
paul1eb8ef22005-04-07 07:30:20 +00001013 break; /* We take the first interface. */
1014 }
paul718e3742002-12-13 20:15:29 +00001015
1016 rl = (struct router_lsa *)v->lsa;
pauld355bfa2004-04-08 07:43:45 +00001017
1018 /* use SPF determined backlink index in struct vertex
1019 * for virtual link destination address
1020 */
pauleb3da6d2005-10-18 04:20:33 +00001021 if (vp && vp->backlink >= 0)
paul718e3742002-12-13 20:15:29 +00001022 {
pauld355bfa2004-04-08 07:43:45 +00001023 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
pauleb3da6d2005-10-18 04:20:33 +00001024 &rl->link[vp->backlink].link_data))
pauld355bfa2004-04-08 07:43:45 +00001025 changed = 1;
pauleb3da6d2005-10-18 04:20:33 +00001026 vl_data->peer_addr = rl->link[vp->backlink].link_data;
pauld355bfa2004-04-08 07:43:45 +00001027 }
1028 else
1029 {
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++)
paul2e6b0bb2003-06-22 08:17:12 +00001037 {
pauld355bfa2004-04-08 07:43:45 +00001038 switch (rl->link[i].type)
1039 {
1040 case LSA_LINK_TYPE_VIRTUALLINK:
1041 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001042 zlog_debug ("found back link through VL");
pauld355bfa2004-04-08 07:43:45 +00001043 case LSA_LINK_TYPE_TRANSIT:
1044 case LSA_LINK_TYPE_POINTOPOINT:
paulcd59da62004-05-05 17:26:55 +00001045 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
1046 &rl->link[i].link_data))
1047 changed = 1;
pauld355bfa2004-04-08 07:43:45 +00001048 vl_data->peer_addr = rl->link[i].link_data;
1049 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001050 zlog_debug ("ospf_vl_set_params: %s peer address is %s\n",
pauld355bfa2004-04-08 07:43:45 +00001051 vl_data->vl_oi->ifp->name,
1052 inet_ntoa(vl_data->peer_addr));
1053 return changed;
1054 }
paul2e6b0bb2003-06-22 08:17:12 +00001055 }
paul718e3742002-12-13 20:15:29 +00001056 }
pauld355bfa2004-04-08 07:43:45 +00001057
1058 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001059 zlog_debug ("ospf_vl_set_params: %s peer address is %s\n",
pauld355bfa2004-04-08 07:43:45 +00001060 vl_data->vl_oi->ifp->name,
1061 inet_ntoa(vl_data->peer_addr));
1062
paul2e6b0bb2003-06-22 08:17:12 +00001063 return changed;
paul718e3742002-12-13 20:15:29 +00001064}
1065
1066
1067void
paul68980082003-03-25 05:07:42 +00001068ospf_vl_up_check (struct ospf_area *area, struct in_addr rid,
paul718e3742002-12-13 20:15:29 +00001069 struct vertex *v)
1070{
paul68980082003-03-25 05:07:42 +00001071 struct ospf *ospf = area->ospf;
hasso52dc7ee2004-09-23 19:18:23 +00001072 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001073 struct ospf_vl_data *vl_data;
1074 struct ospf_interface *oi;
1075
1076 if (IS_DEBUG_OSPF_EVENT)
1077 {
ajs60925302004-12-08 17:45:02 +00001078 zlog_debug ("ospf_vl_up_check(): Start");
1079 zlog_debug ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid));
1080 zlog_debug ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001081 }
1082
paul1eb8ef22005-04-07 07:30:20 +00001083 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
paul718e3742002-12-13 20:15:29 +00001084 {
paul718e3742002-12-13 20:15:29 +00001085 if (IS_DEBUG_OSPF_EVENT)
1086 {
ajs60925302004-12-08 17:45:02 +00001087 zlog_debug ("ospf_vl_up_check(): considering VL, name: %s",
paul718e3742002-12-13 20:15:29 +00001088 vl_data->vl_oi->ifp->name);
ajs60925302004-12-08 17:45:02 +00001089 zlog_debug ("ospf_vl_up_check(): VL area: %s, peer ID: %s",
paul718e3742002-12-13 20:15:29 +00001090 inet_ntoa (vl_data->vl_area_id),
1091 inet_ntoa (vl_data->vl_peer));
1092 }
1093
1094 if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) &&
1095 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1096 {
1097 oi = vl_data->vl_oi;
1098 SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
1099
1100 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001101 zlog_debug ("ospf_vl_up_check(): this VL matched");
paul718e3742002-12-13 20:15:29 +00001102
1103 if (oi->state == ISM_Down)
1104 {
1105 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001106 zlog_debug ("ospf_vl_up_check(): VL is down, waking it up");
paul718e3742002-12-13 20:15:29 +00001107 SET_FLAG (oi->ifp->flags, IFF_UP);
paul2e6b0bb2003-06-22 08:17:12 +00001108 OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp);
paul718e3742002-12-13 20:15:29 +00001109 }
1110
paul2e6b0bb2003-06-22 08:17:12 +00001111 if (ospf_vl_set_params (vl_data, v))
1112 {
1113 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
ajs60925302004-12-08 17:45:02 +00001114 zlog_debug ("ospf_vl_up_check: VL cost change,"
paulcd59da62004-05-05 17:26:55 +00001115 " scheduling router lsa refresh");
paul2e6b0bb2003-06-22 08:17:12 +00001116 if(ospf->backbone)
paulcd59da62004-05-05 17:26:55 +00001117 ospf_router_lsa_timer_add (ospf->backbone);
paul2e6b0bb2003-06-22 08:17:12 +00001118 else if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
ajs60925302004-12-08 17:45:02 +00001119 zlog_debug ("ospf_vl_up_check: VL cost change, no backbone!");
paul2e6b0bb2003-06-22 08:17:12 +00001120 }
paul718e3742002-12-13 20:15:29 +00001121 }
1122 }
1123}
1124
1125void
paul68980082003-03-25 05:07:42 +00001126ospf_vl_unapprove (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001127{
hasso52dc7ee2004-09-23 19:18:23 +00001128 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001129 struct ospf_vl_data *vl_data;
1130
paul1eb8ef22005-04-07 07:30:20 +00001131 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
1132 UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
paul718e3742002-12-13 20:15:29 +00001133}
1134
1135void
paul68980082003-03-25 05:07:42 +00001136ospf_vl_shut_unapproved (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001137{
paul1eb8ef22005-04-07 07:30:20 +00001138 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001139 struct ospf_vl_data *vl_data;
1140
paul1eb8ef22005-04-07 07:30:20 +00001141 for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
1142 if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
1143 ospf_vl_shutdown (vl_data);
paul718e3742002-12-13 20:15:29 +00001144}
1145
1146int
1147ospf_full_virtual_nbrs (struct ospf_area *area)
1148{
1149 if (IS_DEBUG_OSPF_EVENT)
1150 {
ajs60925302004-12-08 17:45:02 +00001151 zlog_debug ("counting fully adjacent virtual neighbors in area %s",
paul718e3742002-12-13 20:15:29 +00001152 inet_ntoa (area->area_id));
ajs60925302004-12-08 17:45:02 +00001153 zlog_debug ("there are %d of them", area->full_vls);
paul718e3742002-12-13 20:15:29 +00001154 }
1155
1156 return area->full_vls;
1157}
1158
1159int
1160ospf_vls_in_area (struct ospf_area *area)
1161{
hasso52dc7ee2004-09-23 19:18:23 +00001162 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001163 struct ospf_vl_data *vl_data;
1164 int c = 0;
1165
paul1eb8ef22005-04-07 07:30:20 +00001166 for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
1167 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1168 c++;
paul718e3742002-12-13 20:15:29 +00001169
1170 return c;
1171}
1172
1173
1174struct crypt_key *
1175ospf_crypt_key_new ()
1176{
1177 struct crypt_key *ck;
1178
1179 ck = XMALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key));
1180 memset (ck, 0, sizeof (struct crypt_key));
1181
1182 return ck;
1183}
1184
1185void
hasso52dc7ee2004-09-23 19:18:23 +00001186ospf_crypt_key_add (struct list *crypt, struct crypt_key *ck)
paul718e3742002-12-13 20:15:29 +00001187{
1188 listnode_add (crypt, ck);
1189}
1190
1191struct crypt_key *
hasso52dc7ee2004-09-23 19:18:23 +00001192ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001193{
hasso52dc7ee2004-09-23 19:18:23 +00001194 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001195 struct crypt_key *ck;
1196
paul1eb8ef22005-04-07 07:30:20 +00001197 for (ALL_LIST_ELEMENTS_RO (auth_crypt, node, ck))
1198 if (ck->key_id == key_id)
1199 return ck;
paul718e3742002-12-13 20:15:29 +00001200
1201 return NULL;
1202}
1203
1204int
hasso52dc7ee2004-09-23 19:18:23 +00001205ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001206{
paul1eb8ef22005-04-07 07:30:20 +00001207 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001208 struct crypt_key *ck;
1209
paul1eb8ef22005-04-07 07:30:20 +00001210 for (ALL_LIST_ELEMENTS (auth_crypt, node, nnode, ck))
paul718e3742002-12-13 20:15:29 +00001211 {
paul718e3742002-12-13 20:15:29 +00001212 if (ck->key_id == key_id)
1213 {
1214 listnode_delete (auth_crypt, ck);
vincentba682532005-09-29 13:52:57 +00001215 XFREE (MTYPE_OSPF_CRYPT_KEY, ck);
paul718e3742002-12-13 20:15:29 +00001216 return 1;
1217 }
1218 }
1219
1220 return 0;
1221}
1222
ajsbc18d612004-12-15 15:07:19 +00001223u_char
1224ospf_default_iftype(struct interface *ifp)
1225{
1226 if (if_is_pointopoint (ifp))
1227 return OSPF_IFTYPE_POINTOPOINT;
1228 else if (if_is_loopback (ifp))
1229 return OSPF_IFTYPE_LOOPBACK;
1230 else
1231 return OSPF_IFTYPE_BROADCAST;
1232}
1233
paul718e3742002-12-13 20:15:29 +00001234void
1235ospf_if_init ()
1236{
1237 /* Initialize Zebra interface data structure. */
1238 if_init ();
paul020709f2003-04-04 02:44:16 +00001239 om->iflist = iflist;
paul718e3742002-12-13 20:15:29 +00001240 if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
1241 if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);
1242}