blob: d21dea3b38fe8630f8fb99aab3eed6e2801ce403 [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);
240 oi->nbr_self->state = NSM_TwoWay;
paul718e3742002-12-13 20:15:29 +0000241 oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
242 oi->nbr_self->options = OSPF_OPTION_E;
243
244 oi->ls_upd_queue = route_table_init ();
245 oi->t_ls_upd_event = NULL;
246 oi->t_ls_ack_direct = NULL;
247
paul68980082003-03-25 05:07:42 +0000248 oi->crypt_seqnum = time (NULL);
249
paul718e3742002-12-13 20:15:29 +0000250#ifdef HAVE_OPAQUE_LSA
251 ospf_opaque_type9_lsa_init (oi);
252#endif /* HAVE_OPAQUE_LSA */
253
paul68980082003-03-25 05:07:42 +0000254 oi->ospf = ospf;
paul718e3742002-12-13 20:15:29 +0000255
256 return oi;
257}
258
259/* Restore an interface to its pre UP state
260 Used from ism_interface_down only */
261void
262ospf_if_cleanup (struct ospf_interface *oi)
263{
264 struct route_node *rn;
paul1eb8ef22005-04-07 07:30:20 +0000265 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000266 struct ospf_neighbor *nbr;
paul1eb8ef22005-04-07 07:30:20 +0000267 struct ospf_nbr_nbma *nbr_nbma;
268 struct ospf_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000269
270 /* oi->nbrs and oi->nbr_nbma should be deletete on InterafceDown event */
271 /* delete all static neighbors attached to this interface */
paul1eb8ef22005-04-07 07:30:20 +0000272 for (ALL_LIST_ELEMENTS (oi->nbr_nbma, node, nnode, nbr_nbma))
paul718e3742002-12-13 20:15:29 +0000273 {
paul718e3742002-12-13 20:15:29 +0000274 OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll);
275
276 if (nbr_nbma->nbr)
277 {
278 nbr_nbma->nbr->nbr_nbma = NULL;
279 nbr_nbma->nbr = NULL;
280 }
281
282 nbr_nbma->oi = NULL;
283
284 listnode_delete (oi->nbr_nbma, nbr_nbma);
285 }
286
287 /* send Neighbor event KillNbr to all associated neighbors. */
288 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
289 if ((nbr = rn->info) != NULL)
290 if (nbr != oi->nbr_self)
291 OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr);
292
293 /* Cleanup Link State Acknowlegdment list. */
paul1eb8ef22005-04-07 07:30:20 +0000294 for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa))
295 ospf_lsa_unlock (lsa);
paul718e3742002-12-13 20:15:29 +0000296 list_delete_all_node (oi->ls_ack);
297
298 oi->crypt_seqnum = 0;
299
300 /* Empty link state update queue */
301 ospf_ls_upd_queue_empty (oi);
302
303 /* Handle pseudo neighbor. */
304 ospf_nbr_delete (oi->nbr_self);
305 oi->nbr_self = ospf_nbr_new (oi);
306 oi->nbr_self->state = NSM_TwoWay;
307 oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
paulf2c80652002-12-13 21:44:27 +0000308
309 switch (oi->area->external_routing)
310 {
311 case OSPF_AREA_DEFAULT:
312 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
313 break;
314 case OSPF_AREA_STUB:
315 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
316 break;
paulf2c80652002-12-13 21:44:27 +0000317 case OSPF_AREA_NSSA:
318 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
319 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
320 break;
paulf2c80652002-12-13 21:44:27 +0000321 }
paul718e3742002-12-13 20:15:29 +0000322
323 ospf_lsa_unlock (oi->network_lsa_self);
324 oi->network_lsa_self = NULL;
325 OSPF_TIMER_OFF (oi->t_network_lsa_self);
326}
327
328void
329ospf_if_free (struct ospf_interface *oi)
330{
331 ospf_if_down (oi);
332
333 assert (oi->state == ISM_Down);
334
335#ifdef HAVE_OPAQUE_LSA
336 ospf_opaque_type9_lsa_term (oi);
337#endif /* HAVE_OPAQUE_LSA */
338
339 /* Free Pseudo Neighbour */
340 ospf_nbr_delete (oi->nbr_self);
341
342 route_table_finish (oi->nbrs);
343 route_table_finish (oi->ls_upd_queue);
344
345 /* Free any lists that should be freed */
346 list_free (oi->nbr_nbma);
347
348 list_free (oi->ls_ack);
349 list_free (oi->ls_ack_direct.ls_ack);
350
351 ospf_delete_from_if (oi->ifp, oi);
352
paul68980082003-03-25 05:07:42 +0000353 listnode_delete (oi->ospf->oiflist, oi);
paul718e3742002-12-13 20:15:29 +0000354 listnode_delete (oi->area->oiflist, oi);
355
356 memset (oi, 0, sizeof (*oi));
357 XFREE (MTYPE_OSPF_IF, oi);
358}
359
360
361/*
362* check if interface with given address is configured and
hasso3fb9cd62004-10-19 19:44:43 +0000363* return it if yes. special treatment for PtP networks.
paul718e3742002-12-13 20:15:29 +0000364*/
365struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000366ospf_if_is_configured (struct ospf *ospf, struct in_addr *address)
paul718e3742002-12-13 20:15:29 +0000367{
paul1eb8ef22005-04-07 07:30:20 +0000368 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000369 struct ospf_interface *oi;
hasso3fb9cd62004-10-19 19:44:43 +0000370 struct prefix_ipv4 addr;
371
372 addr.family = AF_INET;
373 addr.prefix = *address;
374 addr.prefixlen = IPV4_MAX_PREFIXLEN;
paul718e3742002-12-13 20:15:29 +0000375
paul1eb8ef22005-04-07 07:30:20 +0000376 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
377 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul718e3742002-12-13 20:15:29 +0000378 {
379 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
hasso3fb9cd62004-10-19 19:44:43 +0000380 {
381 if (CONNECTED_DEST_HOST(oi->connected))
382 {
383 /* match only destination addr, since local addr is most likely
384 * not unique (borrowed from another interface) */
385 if (IPV4_ADDR_SAME (address,
386 &oi->connected->destination->u.prefix4))
387 return oi;
388 }
389 else
390 {
391 /* special leniency: match if addr is anywhere on PtP subnet */
392 if (prefix_match(oi->address,(struct prefix *)&addr))
393 return oi;
394 }
395 }
paul718e3742002-12-13 20:15:29 +0000396 else
hasso3fb9cd62004-10-19 19:44:43 +0000397 {
398 if (IPV4_ADDR_SAME (address, &oi->address->u.prefix4))
399 return oi;
400 }
paul718e3742002-12-13 20:15:29 +0000401 }
paul718e3742002-12-13 20:15:29 +0000402 return NULL;
403}
404
405int
406ospf_if_is_up (struct ospf_interface *oi)
407{
408 return if_is_up (oi->ifp);
409}
410
411struct ospf_interface *
hasso2db3d052004-02-11 21:52:13 +0000412ospf_if_exists (struct ospf_interface *oic)
413{
hasso52dc7ee2004-09-23 19:18:23 +0000414 struct listnode *node;
hasso2db3d052004-02-11 21:52:13 +0000415 struct ospf *ospf;
416 struct ospf_interface *oi;
417
418 ospf = ospf_lookup ();
419
paul1eb8ef22005-04-07 07:30:20 +0000420 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
421 if (oi == oic)
hasso2db3d052004-02-11 21:52:13 +0000422 return oi;
paul1eb8ef22005-04-07 07:30:20 +0000423
hasso2db3d052004-02-11 21:52:13 +0000424 return NULL;
425}
426
427struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000428ospf_if_lookup_by_local_addr (struct ospf *ospf,
429 struct interface *ifp, struct in_addr address)
paul718e3742002-12-13 20:15:29 +0000430{
hasso52dc7ee2004-09-23 19:18:23 +0000431 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000432 struct ospf_interface *oi;
433
paul1eb8ef22005-04-07 07:30:20 +0000434 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
435 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul718e3742002-12-13 20:15:29 +0000436 {
437 if (ifp && oi->ifp != ifp)
438 continue;
439
440 if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4))
441 return oi;
442 }
443
444 return NULL;
445}
446
447struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000448ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000449{
hasso52dc7ee2004-09-23 19:18:23 +0000450 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000451 struct ospf_interface *oi;
452 struct prefix ptmp;
453
454 /* Check each Interface. */
paul1eb8ef22005-04-07 07:30:20 +0000455 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
paul68980082003-03-25 05:07:42 +0000456 {
paul1eb8ef22005-04-07 07:30:20 +0000457 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul68980082003-03-25 05:07:42 +0000458 {
hasso3fb9cd62004-10-19 19:44:43 +0000459 if ((oi->type == OSPF_IFTYPE_POINTOPOINT) &&
460 CONNECTED_DEST_HOST(oi->connected))
paul68980082003-03-25 05:07:42 +0000461 {
462 prefix_copy (&ptmp, oi->connected->destination);
463 ptmp.prefixlen = IPV4_MAX_BITLEN;
464 }
465 else
466 prefix_copy (&ptmp, oi->address);
paul718e3742002-12-13 20:15:29 +0000467
paul68980082003-03-25 05:07:42 +0000468 apply_mask (&ptmp);
469 if (prefix_same (&ptmp, (struct prefix *) p))
470 return oi;
471 }
472 }
paul718e3742002-12-13 20:15:29 +0000473 return NULL;
474}
475
476/* determine receiving interface by source of packet */
477struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000478ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src)
paul718e3742002-12-13 20:15:29 +0000479{
hasso52dc7ee2004-09-23 19:18:23 +0000480 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000481 struct prefix_ipv4 addr;
482 struct ospf_interface *oi, *match;
483
484 addr.family = AF_INET;
485 addr.prefix = src;
486 addr.prefixlen = IPV4_MAX_BITLEN;
487
488 match = NULL;
489
paul1eb8ef22005-04-07 07:30:20 +0000490 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
paul718e3742002-12-13 20:15:29 +0000491 {
paul718e3742002-12-13 20:15:29 +0000492 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
493 continue;
494
hasso3fb9cd62004-10-19 19:44:43 +0000495 if ((oi->type == OSPF_IFTYPE_POINTOPOINT) &&
496 CONNECTED_DEST_HOST(oi->connected))
paul718e3742002-12-13 20:15:29 +0000497 {
498 if (IPV4_ADDR_SAME (&oi->connected->destination->u.prefix4, &src))
499 return oi;
500 }
501 else
502 {
503 if (prefix_match (oi->address, (struct prefix *) &addr))
paul0a825c72003-05-24 13:48:16 +0000504 {
paulaf8d0332003-05-24 15:31:45 +0000505 if ( (match == NULL) ||
506 (match->address->prefixlen < oi->address->prefixlen)
507 )
paul0a825c72003-05-24 13:48:16 +0000508 match = oi;
509 }
paul718e3742002-12-13 20:15:29 +0000510 }
511 }
512
513 return match;
514}
515
516void
517ospf_if_stream_set (struct ospf_interface *oi)
518{
519 /* set output fifo queue. */
520 if (oi->obuf == NULL)
521 oi->obuf = ospf_fifo_new ();
522}
523
524void
525ospf_if_stream_unset (struct ospf_interface *oi)
526{
paul68980082003-03-25 05:07:42 +0000527 struct ospf *ospf = oi->ospf;
528
paul718e3742002-12-13 20:15:29 +0000529 if (oi->obuf)
530 {
531 ospf_fifo_free (oi->obuf);
532 oi->obuf = NULL;
533
534 if (oi->on_write_q)
535 {
paul68980082003-03-25 05:07:42 +0000536 listnode_delete (ospf->oi_write_q, oi);
537 if (list_isempty(ospf->oi_write_q))
538 OSPF_TIMER_OFF (ospf->t_write);
paul718e3742002-12-13 20:15:29 +0000539 oi->on_write_q = 0;
540 }
541 }
542}
paul68980082003-03-25 05:07:42 +0000543
paul718e3742002-12-13 20:15:29 +0000544
paul4dadc292005-05-06 21:37:42 +0000545static struct ospf_if_params *
546ospf_new_if_params (void)
paul718e3742002-12-13 20:15:29 +0000547{
548 struct ospf_if_params *oip;
549
550 oip = XMALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params));
paul718e3742002-12-13 20:15:29 +0000551
552 if (!oip)
553 return NULL;
554
paulf6457892003-04-17 16:11:30 +0000555 memset (oip, 0, sizeof (struct ospf_if_params));
556
paul718e3742002-12-13 20:15:29 +0000557 UNSET_IF_PARAM (oip, output_cost_cmd);
558 UNSET_IF_PARAM (oip, transmit_delay);
559 UNSET_IF_PARAM (oip, retransmit_interval);
560 UNSET_IF_PARAM (oip, passive_interface);
561 UNSET_IF_PARAM (oip, v_hello);
paulf9ad9372005-10-21 00:45:17 +0000562 UNSET_IF_PARAM (oip, fast_hello);
paul718e3742002-12-13 20:15:29 +0000563 UNSET_IF_PARAM (oip, v_wait);
564 UNSET_IF_PARAM (oip, priority);
565 UNSET_IF_PARAM (oip, type);
566 UNSET_IF_PARAM (oip, auth_simple);
567 UNSET_IF_PARAM (oip, auth_crypt);
568 UNSET_IF_PARAM (oip, auth_type);
paulec1ca632003-06-04 02:23:15 +0000569
570 oip->auth_crypt = list_new ();
paul718e3742002-12-13 20:15:29 +0000571
paul718e3742002-12-13 20:15:29 +0000572 return oip;
573}
574
575void
576ospf_del_if_params (struct ospf_if_params *oip)
577{
578 list_delete (oip->auth_crypt);
579 XFREE (MTYPE_OSPF_IF_PARAMS, oip);
580}
581
582void
583ospf_free_if_params (struct interface *ifp, struct in_addr addr)
584{
585 struct ospf_if_params *oip;
586 struct prefix_ipv4 p;
587 struct route_node *rn;
gdt630e4802004-08-31 17:28:41 +0000588
589 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000590 p.prefixlen = IPV4_MAX_PREFIXLEN;
591 p.prefix = addr;
592 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
593 if (!rn || !rn->info)
594 return;
595
596 oip = rn->info;
597 route_unlock_node (rn);
598
599 if (!OSPF_IF_PARAM_CONFIGURED (oip, output_cost_cmd) &&
600 !OSPF_IF_PARAM_CONFIGURED (oip, transmit_delay) &&
601 !OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) &&
602 !OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) &&
603 !OSPF_IF_PARAM_CONFIGURED (oip, v_hello) &&
paulf9ad9372005-10-21 00:45:17 +0000604 !OSPF_IF_PARAM_CONFIGURED (oip, fast_hello) &&
paul718e3742002-12-13 20:15:29 +0000605 !OSPF_IF_PARAM_CONFIGURED (oip, v_wait) &&
606 !OSPF_IF_PARAM_CONFIGURED (oip, priority) &&
607 !OSPF_IF_PARAM_CONFIGURED (oip, type) &&
608 !OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) &&
609 !OSPF_IF_PARAM_CONFIGURED (oip, auth_type) &&
610 listcount (oip->auth_crypt) == 0)
611 {
612 ospf_del_if_params (oip);
613 rn->info = NULL;
614 route_unlock_node (rn);
615 }
616}
617
618struct ospf_if_params *
619ospf_lookup_if_params (struct interface *ifp, struct in_addr addr)
620{
621 struct prefix_ipv4 p;
622 struct route_node *rn;
623
gdt630e4802004-08-31 17:28:41 +0000624 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000625 p.prefixlen = IPV4_MAX_PREFIXLEN;
626 p.prefix = addr;
627
628 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
629
630 if (rn)
631 {
632 route_unlock_node (rn);
633 return rn->info;
634 }
635
636 return NULL;
637}
638
639struct ospf_if_params *
640ospf_get_if_params (struct interface *ifp, struct in_addr addr)
641{
642 struct prefix_ipv4 p;
643 struct route_node *rn;
644
645 p.family = AF_INET;
646 p.prefixlen = IPV4_MAX_PREFIXLEN;
647 p.prefix = addr;
648
649 rn = route_node_get (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
650
651 if (rn->info == NULL)
652 rn->info = ospf_new_if_params ();
653 else
654 route_unlock_node (rn);
655
656 return rn->info;
657}
658
659void
660ospf_if_update_params (struct interface *ifp, struct in_addr addr)
661{
662 struct route_node *rn;
663 struct ospf_interface *oi;
664
665 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
666 {
667 if ((oi = rn->info) == NULL)
668 continue;
669
670 if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &addr))
671 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
672 }
673}
674
675int
676ospf_if_new_hook (struct interface *ifp)
677{
678 int rc = 0;
679
680 ifp->info = XMALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info));
681 memset (ifp->info, 0, sizeof (struct ospf_if_info));
682
683 IF_OIFS (ifp) = route_table_init ();
684 IF_OIFS_PARAMS (ifp) = route_table_init ();
685
686 IF_DEF_PARAMS (ifp) = ospf_new_if_params ();
687
688 SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay);
689 IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
690
691 SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval);
692 IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
693
694 SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority);
695 IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
696
vincentba682532005-09-29 13:52:57 +0000697 IF_DEF_PARAMS (ifp)->mtu_ignore = OSPF_MTU_IGNORE_DEFAULT;
698
paul718e3742002-12-13 20:15:29 +0000699 SET_IF_PARAM (IF_DEF_PARAMS (ifp), passive_interface);
700 IF_DEF_PARAMS (ifp)->passive_interface = OSPF_IF_ACTIVE;
701
702 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello);
703 IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
704
paulf9ad9372005-10-21 00:45:17 +0000705 SET_IF_PARAM (IF_DEF_PARAMS (ifp), fast_hello);
706 IF_DEF_PARAMS (ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT;
707
paul718e3742002-12-13 20:15:29 +0000708 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait);
709 IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
710
711 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple);
712 memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
713
paul718e3742002-12-13 20:15:29 +0000714 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type);
715 IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET;
716
717#ifdef HAVE_OPAQUE_LSA
718 rc = ospf_opaque_new_if (ifp);
719#endif /* HAVE_OPAQUE_LSA */
720 return rc;
721}
722
paul4dadc292005-05-06 21:37:42 +0000723static int
paul718e3742002-12-13 20:15:29 +0000724ospf_if_delete_hook (struct interface *ifp)
725{
726 int rc = 0;
paul940b01a2004-02-17 20:07:30 +0000727 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +0000728#ifdef HAVE_OPAQUE_LSA
729 rc = ospf_opaque_del_if (ifp);
730#endif /* HAVE_OPAQUE_LSA */
paul940b01a2004-02-17 20:07:30 +0000731
paul718e3742002-12-13 20:15:29 +0000732 route_table_finish (IF_OIFS (ifp));
paul940b01a2004-02-17 20:07:30 +0000733
734 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
735 if (rn->info)
736 ospf_del_if_params (rn->info);
paul718e3742002-12-13 20:15:29 +0000737 route_table_finish (IF_OIFS_PARAMS (ifp));
paul940b01a2004-02-17 20:07:30 +0000738
paulcfc959b2003-06-04 02:28:45 +0000739 ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp));
paul718e3742002-12-13 20:15:29 +0000740 XFREE (MTYPE_OSPF_IF_INFO, ifp->info);
741 ifp->info = NULL;
742
743 return rc;
744}
745
746int
747ospf_if_is_enable (struct ospf_interface *oi)
748{
749 if (!if_is_loopback (oi->ifp))
750 if (if_is_up (oi->ifp))
751 return 1;
752
753 return 0;
754}
755
ajsba6454e2005-02-08 15:37:30 +0000756void
757ospf_if_set_multicast(struct ospf_interface *oi)
758{
759 if ((oi->state > ISM_Loopback) &&
760 (oi->type != OSPF_IFTYPE_LOOPBACK) &&
761 (oi->type != OSPF_IFTYPE_VIRTUALLINK) &&
762 (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE))
763 {
764 /* The interface should belong to the OSPF-all-routers group. */
765 if (!CHECK_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS) &&
766 (ospf_if_add_allspfrouters(oi->ospf, oi->address,
767 oi->ifp->ifindex) >= 0))
768 /* Set the flag only if the system call to join succeeded. */
769 SET_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS);
770 }
771 else
772 {
773 /* The interface should NOT belong to the OSPF-all-routers group. */
774 if (CHECK_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS))
775 {
776 ospf_if_drop_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex);
777 /* Unset the flag regardless of whether the system call to leave
778 the group succeeded, since it's much safer to assume that
779 we are not a member. */
780 UNSET_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS);
781 }
782 }
783
784 if (((oi->type == OSPF_IFTYPE_BROADCAST) ||
785 (oi->type == OSPF_IFTYPE_POINTOPOINT)) &&
786 ((oi->state == ISM_DR) || (oi->state == ISM_Backup)) &&
787 (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE))
788 {
789 /* The interface should belong to the OSPF-designated-routers group. */
790 if (!CHECK_FLAG(oi->multicast_memberships, MEMBER_DROUTERS) &&
791 (ospf_if_add_alldrouters(oi->ospf, oi->address,
792 oi->ifp->ifindex) >= 0))
793 /* Set the flag only if the system call to join succeeded. */
794 SET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS);
795 }
796 else
797 {
798 /* The interface should NOT belong to the OSPF-designated-routers group */
799 if (CHECK_FLAG(oi->multicast_memberships, MEMBER_DROUTERS))
800 {
801 ospf_if_drop_alldrouters(oi->ospf, oi->address, oi->ifp->ifindex);
802 /* Unset the flag regardless of whether the system call to leave
803 the group succeeded, since it's much safer to assume that
804 we are not a member. */
805 UNSET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS);
806 }
807 }
808}
809
paul718e3742002-12-13 20:15:29 +0000810int
811ospf_if_up (struct ospf_interface *oi)
812{
813 if (oi == NULL)
814 return 0;
815
816 if (oi->type == OSPF_IFTYPE_LOOPBACK)
817 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd);
818 else
819 {
paul718e3742002-12-13 20:15:29 +0000820 ospf_if_stream_set (oi);
821 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp);
822 }
823
824 return 1;
825}
826
827int
828ospf_if_down (struct ospf_interface *oi)
829{
830 if (oi == NULL)
831 return 0;
832
833 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
834 /* Shutdown packet reception and sending */
835 ospf_if_stream_unset (oi);
paul718e3742002-12-13 20:15:29 +0000836
837 return 1;
838}
839
840
841/* Virtual Link related functions. */
842
843struct ospf_vl_data *
844ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer)
845{
846 struct ospf_vl_data *vl_data;
847
848 vl_data = XMALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data));
849 memset (vl_data, 0, sizeof (struct ospf_vl_data));
850
851 vl_data->vl_peer.s_addr = vl_peer.s_addr;
852 vl_data->vl_area_id = area->area_id;
853 vl_data->format = area->format;
854
855 return vl_data;
856}
857
858void
859ospf_vl_data_free (struct ospf_vl_data *vl_data)
860{
861 XFREE (MTYPE_OSPF_VL_DATA, vl_data);
862}
863
864u_int vlink_count = 0;
865
866struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000867ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000868{
869 struct ospf_interface * voi;
870 struct interface * vi;
871 char ifname[INTERFACE_NAMSIZ + 1];
872 struct ospf_area *area;
873 struct in_addr area_id;
874 struct connected *co;
875 struct prefix_ipv4 *p;
876
877 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000878 zlog_debug ("ospf_vl_new(): Start");
paul718e3742002-12-13 20:15:29 +0000879 if (vlink_count == OSPF_VL_MAX_COUNT)
880 {
881 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000882 zlog_debug ("ospf_vl_new(): Alarm: "
paul718e3742002-12-13 20:15:29 +0000883 "cannot create more than OSPF_MAX_VL_COUNT virtual links");
884 return NULL;
885 }
886
887 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000888 zlog_debug ("ospf_vl_new(): creating pseudo zebra interface");
paul718e3742002-12-13 20:15:29 +0000889
ajsa3491982005-04-02 22:50:38 +0000890 snprintf (ifname, sizeof(ifname), "VLINK%d", vlink_count);
891 vi = if_create (ifname, strnlen(ifname, sizeof(ifname)));
paul718e3742002-12-13 20:15:29 +0000892 co = connected_new ();
893 co->ifp = vi;
894 listnode_add (vi->connected, co);
895
896 p = prefix_ipv4_new ();
897 p->family = AF_INET;
898 p->prefix.s_addr = 0;
899 p->prefixlen = 0;
900
901 co->address = (struct prefix *)p;
902
paul68980082003-03-25 05:07:42 +0000903 voi = ospf_if_new (ospf, vi, co->address);
paul718e3742002-12-13 20:15:29 +0000904 if (voi == NULL)
905 {
906 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000907 zlog_debug ("ospf_vl_new(): Alarm: OSPF int structure is not created");
paul718e3742002-12-13 20:15:29 +0000908 return NULL;
909 }
910 voi->connected = co;
911 voi->vl_data = vl_data;
912 voi->ifp->mtu = OSPF_VL_MTU;
913 voi->type = OSPF_IFTYPE_VIRTUALLINK;
914
paul106d2fd2003-08-01 00:24:13 +0000915 vlink_count++;
paul718e3742002-12-13 20:15:29 +0000916 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000917 zlog_debug ("ospf_vl_new(): Created name: %s", ifname);
paul718e3742002-12-13 20:15:29 +0000918 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000919 zlog_debug ("ospf_vl_new(): set if->name to %s", vi->name);
paul718e3742002-12-13 20:15:29 +0000920
921 area_id.s_addr = 0;
paul68980082003-03-25 05:07:42 +0000922 area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS);
paul718e3742002-12-13 20:15:29 +0000923 voi->area = area;
924
925 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000926 zlog_debug ("ospf_vl_new(): set associated area to the backbone");
paul718e3742002-12-13 20:15:29 +0000927
928 ospf_area_add_if (voi->area, voi);
929
930 ospf_if_stream_set (voi);
931
932 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000933 zlog_debug ("ospf_vl_new(): Stop");
paul718e3742002-12-13 20:15:29 +0000934 return voi;
935}
936
paul4dadc292005-05-06 21:37:42 +0000937static void
paul718e3742002-12-13 20:15:29 +0000938ospf_vl_if_delete (struct ospf_vl_data *vl_data)
939{
940 struct interface *ifp = vl_data->vl_oi->ifp;
941 vl_data->vl_oi->address->u.prefix4.s_addr = 0;
942 vl_data->vl_oi->address->prefixlen = 0;
943 ospf_if_free (vl_data->vl_oi);
944 if_delete (ifp);
945 vlink_count--;
946}
947
948struct ospf_vl_data *
949ospf_vl_lookup (struct ospf_area *area, struct in_addr vl_peer)
950{
951 struct ospf_vl_data *vl_data;
hasso52dc7ee2004-09-23 19:18:23 +0000952 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000953
paul1eb8ef22005-04-07 07:30:20 +0000954 for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
955 if (vl_data->vl_peer.s_addr == vl_peer.s_addr &&
956 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
957 return vl_data;
paul718e3742002-12-13 20:15:29 +0000958
959 return NULL;
960}
961
paul4dadc292005-05-06 21:37:42 +0000962static void
paul718e3742002-12-13 20:15:29 +0000963ospf_vl_shutdown (struct ospf_vl_data *vl_data)
964{
965 struct ospf_interface *oi;
966
967 if ((oi = vl_data->vl_oi) == NULL)
968 return;
969
970 oi->address->u.prefix4.s_addr = 0;
971 oi->address->prefixlen = 0;
972
973 UNSET_FLAG (oi->ifp->flags, IFF_UP);
974 /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */
975 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
976}
977
978void
paul68980082003-03-25 05:07:42 +0000979ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000980{
paul68980082003-03-25 05:07:42 +0000981 listnode_add (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000982#ifdef HAVE_SNMP
983 ospf_snmp_vl_add (vl_data);
984#endif /* HAVE_SNMP */
985}
986
987void
paul68980082003-03-25 05:07:42 +0000988ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000989{
990 ospf_vl_shutdown (vl_data);
991 ospf_vl_if_delete (vl_data);
992
993#ifdef HAVE_SNMP
994 ospf_snmp_vl_delete (vl_data);
995#endif /* HAVE_SNMP */
paul68980082003-03-25 05:07:42 +0000996 listnode_delete (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000997
998 ospf_vl_data_free (vl_data);
999}
1000
paul4dadc292005-05-06 21:37:42 +00001001static int
paul718e3742002-12-13 20:15:29 +00001002ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v)
1003{
1004 int changed = 0;
1005 struct ospf_interface *voi;
hasso52dc7ee2004-09-23 19:18:23 +00001006 struct listnode *node;
pauleb3da6d2005-10-18 04:20:33 +00001007 struct vertex_parent *vp = NULL;
paul718e3742002-12-13 20:15:29 +00001008 int i;
1009 struct router_lsa *rl;
1010
1011 voi = vl_data->vl_oi;
1012
1013 if (voi->output_cost != v->distance)
1014 {
paulcd59da62004-05-05 17:26:55 +00001015
paul718e3742002-12-13 20:15:29 +00001016 voi->output_cost = v->distance;
1017 changed = 1;
1018 }
1019
pauleb3da6d2005-10-18 04:20:33 +00001020 for (ALL_LIST_ELEMENTS_RO (v->parents, node, vp))
paul1eb8ef22005-04-07 07:30:20 +00001021 {
pauleb3da6d2005-10-18 04:20:33 +00001022 vl_data->out_oi = vp->nexthop->oi;
paul1eb8ef22005-04-07 07:30:20 +00001023
1024 if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
1025 &vl_data->out_oi->address->u.prefix4))
1026 changed = 1;
paulcd59da62004-05-05 17:26:55 +00001027
paul1eb8ef22005-04-07 07:30:20 +00001028 voi->address->u.prefix4 = vl_data->out_oi->address->u.prefix4;
1029 voi->address->prefixlen = vl_data->out_oi->address->prefixlen;
paul718e3742002-12-13 20:15:29 +00001030
paul1eb8ef22005-04-07 07:30:20 +00001031 break; /* We take the first interface. */
1032 }
paul718e3742002-12-13 20:15:29 +00001033
1034 rl = (struct router_lsa *)v->lsa;
pauld355bfa2004-04-08 07:43:45 +00001035
1036 /* use SPF determined backlink index in struct vertex
1037 * for virtual link destination address
1038 */
pauleb3da6d2005-10-18 04:20:33 +00001039 if (vp && vp->backlink >= 0)
paul718e3742002-12-13 20:15:29 +00001040 {
pauld355bfa2004-04-08 07:43:45 +00001041 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
pauleb3da6d2005-10-18 04:20:33 +00001042 &rl->link[vp->backlink].link_data))
pauld355bfa2004-04-08 07:43:45 +00001043 changed = 1;
pauleb3da6d2005-10-18 04:20:33 +00001044 vl_data->peer_addr = rl->link[vp->backlink].link_data;
pauld355bfa2004-04-08 07:43:45 +00001045 }
1046 else
1047 {
1048 /* This is highly odd, there is no backlink index
1049 * there should be due to the ospf_spf_has_link() check
1050 * in SPF. Lets warn and try pick a link anyway.
1051 */
1052 zlog_warn ("ospf_vl_set_params: No backlink for %s!",
1053 vl_data->vl_oi->ifp->name);
1054 for (i = 0; i < ntohs (rl->links); i++)
paul2e6b0bb2003-06-22 08:17:12 +00001055 {
pauld355bfa2004-04-08 07:43:45 +00001056 switch (rl->link[i].type)
1057 {
1058 case LSA_LINK_TYPE_VIRTUALLINK:
1059 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001060 zlog_debug ("found back link through VL");
pauld355bfa2004-04-08 07:43:45 +00001061 case LSA_LINK_TYPE_TRANSIT:
1062 case LSA_LINK_TYPE_POINTOPOINT:
paulcd59da62004-05-05 17:26:55 +00001063 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
1064 &rl->link[i].link_data))
1065 changed = 1;
pauld355bfa2004-04-08 07:43:45 +00001066 vl_data->peer_addr = rl->link[i].link_data;
1067 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001068 zlog_debug ("ospf_vl_set_params: %s peer address is %s\n",
pauld355bfa2004-04-08 07:43:45 +00001069 vl_data->vl_oi->ifp->name,
1070 inet_ntoa(vl_data->peer_addr));
1071 return changed;
1072 }
paul2e6b0bb2003-06-22 08:17:12 +00001073 }
paul718e3742002-12-13 20:15:29 +00001074 }
pauld355bfa2004-04-08 07:43:45 +00001075
1076 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001077 zlog_debug ("ospf_vl_set_params: %s peer address is %s\n",
pauld355bfa2004-04-08 07:43:45 +00001078 vl_data->vl_oi->ifp->name,
1079 inet_ntoa(vl_data->peer_addr));
1080
paul2e6b0bb2003-06-22 08:17:12 +00001081 return changed;
paul718e3742002-12-13 20:15:29 +00001082}
1083
1084
1085void
paul68980082003-03-25 05:07:42 +00001086ospf_vl_up_check (struct ospf_area *area, struct in_addr rid,
paul718e3742002-12-13 20:15:29 +00001087 struct vertex *v)
1088{
paul68980082003-03-25 05:07:42 +00001089 struct ospf *ospf = area->ospf;
hasso52dc7ee2004-09-23 19:18:23 +00001090 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001091 struct ospf_vl_data *vl_data;
1092 struct ospf_interface *oi;
1093
1094 if (IS_DEBUG_OSPF_EVENT)
1095 {
ajs60925302004-12-08 17:45:02 +00001096 zlog_debug ("ospf_vl_up_check(): Start");
1097 zlog_debug ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid));
1098 zlog_debug ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001099 }
1100
paul1eb8ef22005-04-07 07:30:20 +00001101 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
paul718e3742002-12-13 20:15:29 +00001102 {
paul718e3742002-12-13 20:15:29 +00001103 if (IS_DEBUG_OSPF_EVENT)
1104 {
ajs60925302004-12-08 17:45:02 +00001105 zlog_debug ("ospf_vl_up_check(): considering VL, name: %s",
paul718e3742002-12-13 20:15:29 +00001106 vl_data->vl_oi->ifp->name);
ajs60925302004-12-08 17:45:02 +00001107 zlog_debug ("ospf_vl_up_check(): VL area: %s, peer ID: %s",
paul718e3742002-12-13 20:15:29 +00001108 inet_ntoa (vl_data->vl_area_id),
1109 inet_ntoa (vl_data->vl_peer));
1110 }
1111
1112 if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) &&
1113 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1114 {
1115 oi = vl_data->vl_oi;
1116 SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
1117
1118 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001119 zlog_debug ("ospf_vl_up_check(): this VL matched");
paul718e3742002-12-13 20:15:29 +00001120
1121 if (oi->state == ISM_Down)
1122 {
1123 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001124 zlog_debug ("ospf_vl_up_check(): VL is down, waking it up");
paul718e3742002-12-13 20:15:29 +00001125 SET_FLAG (oi->ifp->flags, IFF_UP);
paul2e6b0bb2003-06-22 08:17:12 +00001126 OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp);
paul718e3742002-12-13 20:15:29 +00001127 }
1128
paul2e6b0bb2003-06-22 08:17:12 +00001129 if (ospf_vl_set_params (vl_data, v))
1130 {
1131 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
ajs60925302004-12-08 17:45:02 +00001132 zlog_debug ("ospf_vl_up_check: VL cost change,"
paulcd59da62004-05-05 17:26:55 +00001133 " scheduling router lsa refresh");
paul2e6b0bb2003-06-22 08:17:12 +00001134 if(ospf->backbone)
paulcd59da62004-05-05 17:26:55 +00001135 ospf_router_lsa_timer_add (ospf->backbone);
paul2e6b0bb2003-06-22 08:17:12 +00001136 else if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
ajs60925302004-12-08 17:45:02 +00001137 zlog_debug ("ospf_vl_up_check: VL cost change, no backbone!");
paul2e6b0bb2003-06-22 08:17:12 +00001138 }
paul718e3742002-12-13 20:15:29 +00001139 }
1140 }
1141}
1142
1143void
paul68980082003-03-25 05:07:42 +00001144ospf_vl_unapprove (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001145{
hasso52dc7ee2004-09-23 19:18:23 +00001146 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001147 struct ospf_vl_data *vl_data;
1148
paul1eb8ef22005-04-07 07:30:20 +00001149 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
1150 UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
paul718e3742002-12-13 20:15:29 +00001151}
1152
1153void
paul68980082003-03-25 05:07:42 +00001154ospf_vl_shut_unapproved (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001155{
paul1eb8ef22005-04-07 07:30:20 +00001156 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001157 struct ospf_vl_data *vl_data;
1158
paul1eb8ef22005-04-07 07:30:20 +00001159 for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
1160 if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
1161 ospf_vl_shutdown (vl_data);
paul718e3742002-12-13 20:15:29 +00001162}
1163
1164int
1165ospf_full_virtual_nbrs (struct ospf_area *area)
1166{
1167 if (IS_DEBUG_OSPF_EVENT)
1168 {
ajs60925302004-12-08 17:45:02 +00001169 zlog_debug ("counting fully adjacent virtual neighbors in area %s",
paul718e3742002-12-13 20:15:29 +00001170 inet_ntoa (area->area_id));
ajs60925302004-12-08 17:45:02 +00001171 zlog_debug ("there are %d of them", area->full_vls);
paul718e3742002-12-13 20:15:29 +00001172 }
1173
1174 return area->full_vls;
1175}
1176
1177int
1178ospf_vls_in_area (struct ospf_area *area)
1179{
hasso52dc7ee2004-09-23 19:18:23 +00001180 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001181 struct ospf_vl_data *vl_data;
1182 int c = 0;
1183
paul1eb8ef22005-04-07 07:30:20 +00001184 for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
1185 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1186 c++;
paul718e3742002-12-13 20:15:29 +00001187
1188 return c;
1189}
1190
1191
1192struct crypt_key *
1193ospf_crypt_key_new ()
1194{
1195 struct crypt_key *ck;
1196
1197 ck = XMALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key));
1198 memset (ck, 0, sizeof (struct crypt_key));
1199
1200 return ck;
1201}
1202
1203void
hasso52dc7ee2004-09-23 19:18:23 +00001204ospf_crypt_key_add (struct list *crypt, struct crypt_key *ck)
paul718e3742002-12-13 20:15:29 +00001205{
1206 listnode_add (crypt, ck);
1207}
1208
1209struct crypt_key *
hasso52dc7ee2004-09-23 19:18:23 +00001210ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001211{
hasso52dc7ee2004-09-23 19:18:23 +00001212 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001213 struct crypt_key *ck;
1214
paul1eb8ef22005-04-07 07:30:20 +00001215 for (ALL_LIST_ELEMENTS_RO (auth_crypt, node, ck))
1216 if (ck->key_id == key_id)
1217 return ck;
paul718e3742002-12-13 20:15:29 +00001218
1219 return NULL;
1220}
1221
1222int
hasso52dc7ee2004-09-23 19:18:23 +00001223ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001224{
paul1eb8ef22005-04-07 07:30:20 +00001225 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001226 struct crypt_key *ck;
1227
paul1eb8ef22005-04-07 07:30:20 +00001228 for (ALL_LIST_ELEMENTS (auth_crypt, node, nnode, ck))
paul718e3742002-12-13 20:15:29 +00001229 {
paul718e3742002-12-13 20:15:29 +00001230 if (ck->key_id == key_id)
1231 {
1232 listnode_delete (auth_crypt, ck);
vincentba682532005-09-29 13:52:57 +00001233 XFREE (MTYPE_OSPF_CRYPT_KEY, ck);
paul718e3742002-12-13 20:15:29 +00001234 return 1;
1235 }
1236 }
1237
1238 return 0;
1239}
1240
ajsbc18d612004-12-15 15:07:19 +00001241u_char
1242ospf_default_iftype(struct interface *ifp)
1243{
1244 if (if_is_pointopoint (ifp))
1245 return OSPF_IFTYPE_POINTOPOINT;
1246 else if (if_is_loopback (ifp))
1247 return OSPF_IFTYPE_LOOPBACK;
1248 else
1249 return OSPF_IFTYPE_BROADCAST;
1250}
1251
paul718e3742002-12-13 20:15:29 +00001252void
1253ospf_if_init ()
1254{
1255 /* Initialize Zebra interface data structure. */
1256 if_init ();
paul020709f2003-04-04 02:44:16 +00001257 om->iflist = iflist;
paul718e3742002-12-13 20:15:29 +00001258 if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
1259 if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);
1260}