blob: afe3acf133e817636c9e40769fcec32421995924 [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 */
Joakim Tjernlundf0f63842009-07-27 12:42:29 +0200148struct 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))
Paul Jakma1fe6ed32006-07-26 09:37:26 +0000292 ospf_lsa_unlock (&lsa); /* oi->ls_ack */
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
Paul Jakma1fe6ed32006-07-26 09:37:26 +0000305 ospf_lsa_unlock (&oi->network_lsa_self);
paul718e3742002-12-13 20:15:29 +0000306 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;
Andrew J. Schorre4529632006-12-12 19:18:21 +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 {
Andrew J. Schorre4529632006-12-12 19:18:21 +0000361 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
hasso3fb9cd62004-10-19 19:44:43 +0000362 {
Andrew J. Schorre4529632006-12-12 19:18:21 +0000363 /* special leniency: match if addr is anywhere on peer subnet */
364 if (prefix_match(CONNECTED_PREFIX(oi->connected),
365 (struct prefix *)&addr))
366 return oi;
hasso3fb9cd62004-10-19 19:44:43 +0000367 }
Andrew J. Schorre4529632006-12-12 19:18:21 +0000368 else
hasso3fb9cd62004-10-19 19:44:43 +0000369 {
370 if (IPV4_ADDR_SAME (address, &oi->address->u.prefix4))
371 return oi;
372 }
paul718e3742002-12-13 20:15:29 +0000373 }
paul718e3742002-12-13 20:15:29 +0000374 return NULL;
375}
376
377int
378ospf_if_is_up (struct ospf_interface *oi)
379{
380 return if_is_up (oi->ifp);
381}
382
383struct ospf_interface *
hasso2db3d052004-02-11 21:52:13 +0000384ospf_if_exists (struct ospf_interface *oic)
385{
hasso52dc7ee2004-09-23 19:18:23 +0000386 struct listnode *node;
hasso2db3d052004-02-11 21:52:13 +0000387 struct ospf *ospf;
388 struct ospf_interface *oi;
389
Paul Jakmae43be0e2006-05-12 23:00:06 +0000390 if ((ospf = ospf_lookup ()) == NULL)
391 return NULL;
hasso2db3d052004-02-11 21:52:13 +0000392
paul1eb8ef22005-04-07 07:30:20 +0000393 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
394 if (oi == oic)
hasso2db3d052004-02-11 21:52:13 +0000395 return oi;
paul1eb8ef22005-04-07 07:30:20 +0000396
hasso2db3d052004-02-11 21:52:13 +0000397 return NULL;
398}
399
400struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000401ospf_if_lookup_by_local_addr (struct ospf *ospf,
402 struct interface *ifp, struct in_addr address)
paul718e3742002-12-13 20:15:29 +0000403{
hasso52dc7ee2004-09-23 19:18:23 +0000404 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000405 struct ospf_interface *oi;
406
paul1eb8ef22005-04-07 07:30:20 +0000407 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
408 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul718e3742002-12-13 20:15:29 +0000409 {
410 if (ifp && oi->ifp != ifp)
411 continue;
412
413 if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4))
414 return oi;
415 }
416
417 return NULL;
418}
419
420struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000421ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p)
paul718e3742002-12-13 20:15:29 +0000422{
hasso52dc7ee2004-09-23 19:18:23 +0000423 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000424 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000425
426 /* Check each Interface. */
paul1eb8ef22005-04-07 07:30:20 +0000427 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
paul68980082003-03-25 05:07:42 +0000428 {
paul1eb8ef22005-04-07 07:30:20 +0000429 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
paul68980082003-03-25 05:07:42 +0000430 {
Andrew J. Schorre4529632006-12-12 19:18:21 +0000431 struct prefix ptmp;
432
433 prefix_copy (&ptmp, CONNECTED_PREFIX(oi->connected));
paul68980082003-03-25 05:07:42 +0000434 apply_mask (&ptmp);
435 if (prefix_same (&ptmp, (struct prefix *) p))
436 return oi;
437 }
438 }
paul718e3742002-12-13 20:15:29 +0000439 return NULL;
440}
441
Joakim Tjernlund05cf46b2009-07-27 12:42:30 +0200442/* determine receiving interface by ifp and source address */
paul718e3742002-12-13 20:15:29 +0000443struct ospf_interface *
Joakim Tjernlund05cf46b2009-07-27 12:42:30 +0200444ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src,
445 struct interface *ifp)
paul718e3742002-12-13 20:15:29 +0000446{
Joakim Tjernlund05cf46b2009-07-27 12:42:30 +0200447 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +0000448 struct prefix_ipv4 addr;
449 struct ospf_interface *oi, *match;
450
451 addr.family = AF_INET;
452 addr.prefix = src;
453 addr.prefixlen = IPV4_MAX_BITLEN;
454
455 match = NULL;
456
Joakim Tjernlund05cf46b2009-07-27 12:42:30 +0200457 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +0000458 {
Joakim Tjernlund05cf46b2009-07-27 12:42:30 +0200459 oi = rn->info;
460
461 if (!oi) /* oi can be NULL for PtP aliases */
462 continue;
463
paul718e3742002-12-13 20:15:29 +0000464 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
465 continue;
Joakim Tjernlund05cf46b2009-07-27 12:42:30 +0200466
Paul Jakma1a8ee0e2006-03-30 14:20:00 +0000467 if (if_is_loopback (oi->ifp))
468 continue;
Andrew J. Schorre4529632006-12-12 19:18:21 +0000469
470 if (prefix_match (CONNECTED_PREFIX(oi->connected),
471 (struct prefix *) &addr))
paul718e3742002-12-13 20:15:29 +0000472 {
Andrew J. Schorre4529632006-12-12 19:18:21 +0000473 if ( (match == NULL) ||
474 (match->address->prefixlen < oi->address->prefixlen)
475 )
476 match = oi;
paul718e3742002-12-13 20:15:29 +0000477 }
478 }
479
480 return match;
481}
482
483void
484ospf_if_stream_set (struct ospf_interface *oi)
485{
486 /* set output fifo queue. */
487 if (oi->obuf == NULL)
488 oi->obuf = ospf_fifo_new ();
489}
490
491void
492ospf_if_stream_unset (struct ospf_interface *oi)
493{
paul68980082003-03-25 05:07:42 +0000494 struct ospf *ospf = oi->ospf;
495
paul718e3742002-12-13 20:15:29 +0000496 if (oi->obuf)
497 {
498 ospf_fifo_free (oi->obuf);
499 oi->obuf = NULL;
500
501 if (oi->on_write_q)
502 {
paul68980082003-03-25 05:07:42 +0000503 listnode_delete (ospf->oi_write_q, oi);
504 if (list_isempty(ospf->oi_write_q))
505 OSPF_TIMER_OFF (ospf->t_write);
paul718e3742002-12-13 20:15:29 +0000506 oi->on_write_q = 0;
507 }
508 }
509}
paul68980082003-03-25 05:07:42 +0000510
paul718e3742002-12-13 20:15:29 +0000511
paul4dadc292005-05-06 21:37:42 +0000512static struct ospf_if_params *
513ospf_new_if_params (void)
paul718e3742002-12-13 20:15:29 +0000514{
515 struct ospf_if_params *oip;
516
Stephen Hemminger393deb92008-08-18 14:13:29 -0700517 oip = XCALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params));
paul718e3742002-12-13 20:15:29 +0000518
519 if (!oip)
520 return NULL;
521
paul718e3742002-12-13 20:15:29 +0000522 UNSET_IF_PARAM (oip, output_cost_cmd);
523 UNSET_IF_PARAM (oip, transmit_delay);
524 UNSET_IF_PARAM (oip, retransmit_interval);
525 UNSET_IF_PARAM (oip, passive_interface);
526 UNSET_IF_PARAM (oip, v_hello);
paulf9ad9372005-10-21 00:45:17 +0000527 UNSET_IF_PARAM (oip, fast_hello);
paul718e3742002-12-13 20:15:29 +0000528 UNSET_IF_PARAM (oip, v_wait);
529 UNSET_IF_PARAM (oip, priority);
530 UNSET_IF_PARAM (oip, type);
531 UNSET_IF_PARAM (oip, auth_simple);
532 UNSET_IF_PARAM (oip, auth_crypt);
533 UNSET_IF_PARAM (oip, auth_type);
paulec1ca632003-06-04 02:23:15 +0000534
535 oip->auth_crypt = list_new ();
paul718e3742002-12-13 20:15:29 +0000536
paul718e3742002-12-13 20:15:29 +0000537 return oip;
538}
539
540void
541ospf_del_if_params (struct ospf_if_params *oip)
542{
543 list_delete (oip->auth_crypt);
544 XFREE (MTYPE_OSPF_IF_PARAMS, oip);
545}
546
547void
548ospf_free_if_params (struct interface *ifp, struct in_addr addr)
549{
550 struct ospf_if_params *oip;
551 struct prefix_ipv4 p;
552 struct route_node *rn;
gdt630e4802004-08-31 17:28:41 +0000553
554 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000555 p.prefixlen = IPV4_MAX_PREFIXLEN;
556 p.prefix = addr;
557 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
558 if (!rn || !rn->info)
559 return;
560
561 oip = rn->info;
562 route_unlock_node (rn);
563
564 if (!OSPF_IF_PARAM_CONFIGURED (oip, output_cost_cmd) &&
565 !OSPF_IF_PARAM_CONFIGURED (oip, transmit_delay) &&
566 !OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) &&
567 !OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) &&
568 !OSPF_IF_PARAM_CONFIGURED (oip, v_hello) &&
paulf9ad9372005-10-21 00:45:17 +0000569 !OSPF_IF_PARAM_CONFIGURED (oip, fast_hello) &&
paul718e3742002-12-13 20:15:29 +0000570 !OSPF_IF_PARAM_CONFIGURED (oip, v_wait) &&
571 !OSPF_IF_PARAM_CONFIGURED (oip, priority) &&
572 !OSPF_IF_PARAM_CONFIGURED (oip, type) &&
573 !OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) &&
574 !OSPF_IF_PARAM_CONFIGURED (oip, auth_type) &&
575 listcount (oip->auth_crypt) == 0)
576 {
577 ospf_del_if_params (oip);
578 rn->info = NULL;
579 route_unlock_node (rn);
580 }
581}
582
583struct ospf_if_params *
584ospf_lookup_if_params (struct interface *ifp, struct in_addr addr)
585{
586 struct prefix_ipv4 p;
587 struct route_node *rn;
588
gdt630e4802004-08-31 17:28:41 +0000589 p.family = AF_INET;
paul718e3742002-12-13 20:15:29 +0000590 p.prefixlen = IPV4_MAX_PREFIXLEN;
591 p.prefix = addr;
592
593 rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
594
595 if (rn)
596 {
597 route_unlock_node (rn);
598 return rn->info;
599 }
600
601 return NULL;
602}
603
604struct ospf_if_params *
605ospf_get_if_params (struct interface *ifp, struct in_addr addr)
606{
607 struct prefix_ipv4 p;
608 struct route_node *rn;
609
610 p.family = AF_INET;
611 p.prefixlen = IPV4_MAX_PREFIXLEN;
612 p.prefix = addr;
613
614 rn = route_node_get (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
615
616 if (rn->info == NULL)
617 rn->info = ospf_new_if_params ();
618 else
619 route_unlock_node (rn);
620
621 return rn->info;
622}
623
624void
625ospf_if_update_params (struct interface *ifp, struct in_addr addr)
626{
627 struct route_node *rn;
628 struct ospf_interface *oi;
629
630 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
631 {
632 if ((oi = rn->info) == NULL)
633 continue;
634
635 if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &addr))
636 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
637 }
638}
639
640int
641ospf_if_new_hook (struct interface *ifp)
642{
643 int rc = 0;
644
Stephen Hemminger393deb92008-08-18 14:13:29 -0700645 ifp->info = XCALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info));
paul718e3742002-12-13 20:15:29 +0000646
647 IF_OIFS (ifp) = route_table_init ();
648 IF_OIFS_PARAMS (ifp) = route_table_init ();
649
650 IF_DEF_PARAMS (ifp) = ospf_new_if_params ();
651
652 SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay);
653 IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
654
655 SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval);
656 IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
657
658 SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority);
659 IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
660
vincentba682532005-09-29 13:52:57 +0000661 IF_DEF_PARAMS (ifp)->mtu_ignore = OSPF_MTU_IGNORE_DEFAULT;
662
paul718e3742002-12-13 20:15:29 +0000663 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello);
664 IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
665
paulf9ad9372005-10-21 00:45:17 +0000666 SET_IF_PARAM (IF_DEF_PARAMS (ifp), fast_hello);
667 IF_DEF_PARAMS (ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT;
668
paul718e3742002-12-13 20:15:29 +0000669 SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait);
670 IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
671
672 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple);
673 memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
674
paul718e3742002-12-13 20:15:29 +0000675 SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type);
676 IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET;
677
678#ifdef HAVE_OPAQUE_LSA
679 rc = ospf_opaque_new_if (ifp);
680#endif /* HAVE_OPAQUE_LSA */
681 return rc;
682}
683
paul4dadc292005-05-06 21:37:42 +0000684static int
paul718e3742002-12-13 20:15:29 +0000685ospf_if_delete_hook (struct interface *ifp)
686{
687 int rc = 0;
paul940b01a2004-02-17 20:07:30 +0000688 struct route_node *rn;
paul718e3742002-12-13 20:15:29 +0000689#ifdef HAVE_OPAQUE_LSA
690 rc = ospf_opaque_del_if (ifp);
691#endif /* HAVE_OPAQUE_LSA */
paul940b01a2004-02-17 20:07:30 +0000692
paul718e3742002-12-13 20:15:29 +0000693 route_table_finish (IF_OIFS (ifp));
paul940b01a2004-02-17 20:07:30 +0000694
695 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
696 if (rn->info)
697 ospf_del_if_params (rn->info);
paul718e3742002-12-13 20:15:29 +0000698 route_table_finish (IF_OIFS_PARAMS (ifp));
paul940b01a2004-02-17 20:07:30 +0000699
paulcfc959b2003-06-04 02:28:45 +0000700 ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp));
paul718e3742002-12-13 20:15:29 +0000701 XFREE (MTYPE_OSPF_IF_INFO, ifp->info);
702 ifp->info = NULL;
703
704 return rc;
705}
706
707int
708ospf_if_is_enable (struct ospf_interface *oi)
709{
710 if (!if_is_loopback (oi->ifp))
711 if (if_is_up (oi->ifp))
712 return 1;
713
714 return 0;
715}
716
ajsba6454e2005-02-08 15:37:30 +0000717void
718ospf_if_set_multicast(struct ospf_interface *oi)
719{
720 if ((oi->state > ISM_Loopback) &&
721 (oi->type != OSPF_IFTYPE_LOOPBACK) &&
722 (oi->type != OSPF_IFTYPE_VIRTUALLINK) &&
Andrew J. Schorre8a56f02007-04-21 20:46:31 +0000723 (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE))
ajsba6454e2005-02-08 15:37:30 +0000724 {
725 /* The interface should belong to the OSPF-all-routers group. */
Paul Jakma429ac782006-06-15 18:40:49 +0000726 if (!OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) &&
ajsba6454e2005-02-08 15:37:30 +0000727 (ospf_if_add_allspfrouters(oi->ospf, oi->address,
728 oi->ifp->ifindex) >= 0))
Paul Jakma429ac782006-06-15 18:40:49 +0000729 /* Set the flag only if the system call to join succeeded. */
730 OI_MEMBER_JOINED(oi, MEMBER_ALLROUTERS);
ajsba6454e2005-02-08 15:37:30 +0000731 }
732 else
733 {
734 /* The interface should NOT belong to the OSPF-all-routers group. */
Paul Jakma429ac782006-06-15 18:40:49 +0000735 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
ajsba6454e2005-02-08 15:37:30 +0000736 {
Paul Jakma429ac782006-06-15 18:40:49 +0000737 /* Only actually drop if this is the last reference */
738 if (OI_MEMBER_COUNT(oi, MEMBER_ALLROUTERS) == 1)
739 ospf_if_drop_allspfrouters (oi->ospf, oi->address,
740 oi->ifp->ifindex);
ajsba6454e2005-02-08 15:37:30 +0000741 /* Unset the flag regardless of whether the system call to leave
742 the group succeeded, since it's much safer to assume that
743 we are not a member. */
Paul Jakma429ac782006-06-15 18:40:49 +0000744 OI_MEMBER_LEFT(oi,MEMBER_ALLROUTERS);
ajsba6454e2005-02-08 15:37:30 +0000745 }
746 }
747
748 if (((oi->type == OSPF_IFTYPE_BROADCAST) ||
749 (oi->type == OSPF_IFTYPE_POINTOPOINT)) &&
750 ((oi->state == ISM_DR) || (oi->state == ISM_Backup)) &&
Andrew J. Schorre8a56f02007-04-21 20:46:31 +0000751 (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE))
ajsba6454e2005-02-08 15:37:30 +0000752 {
753 /* The interface should belong to the OSPF-designated-routers group. */
Paul Jakma429ac782006-06-15 18:40:49 +0000754 if (!OI_MEMBER_CHECK(oi, MEMBER_DROUTERS) &&
ajsba6454e2005-02-08 15:37:30 +0000755 (ospf_if_add_alldrouters(oi->ospf, oi->address,
756 oi->ifp->ifindex) >= 0))
757 /* Set the flag only if the system call to join succeeded. */
Paul Jakma429ac782006-06-15 18:40:49 +0000758 OI_MEMBER_JOINED(oi, MEMBER_DROUTERS);
ajsba6454e2005-02-08 15:37:30 +0000759 }
760 else
761 {
762 /* The interface should NOT belong to the OSPF-designated-routers group */
Paul Jakma429ac782006-06-15 18:40:49 +0000763 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
ajsba6454e2005-02-08 15:37:30 +0000764 {
Paul Jakma429ac782006-06-15 18:40:49 +0000765 /* drop only if last reference */
766 if (OI_MEMBER_COUNT(oi, MEMBER_DROUTERS) == 1)
767 ospf_if_drop_alldrouters(oi->ospf, oi->address, oi->ifp->ifindex);
768
ajsba6454e2005-02-08 15:37:30 +0000769 /* Unset the flag regardless of whether the system call to leave
770 the group succeeded, since it's much safer to assume that
771 we are not a member. */
Paul Jakma429ac782006-06-15 18:40:49 +0000772 OI_MEMBER_LEFT(oi, MEMBER_DROUTERS);
ajsba6454e2005-02-08 15:37:30 +0000773 }
774 }
775}
776
paul718e3742002-12-13 20:15:29 +0000777int
778ospf_if_up (struct ospf_interface *oi)
779{
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
786 {
Denis Ovsienkob7fe4142007-08-21 16:32:56 +0000787 struct ospf *ospf = ospf_lookup ();
788 if (ospf != NULL)
789 ospf_adjust_sndbuflen (ospf, oi->ifp->mtu);
790 else
Denis Ovsienkofb31c0f2007-09-18 09:03:13 +0000791 zlog_warn ("%s: ospf_lookup() returned NULL", __func__);
paul718e3742002-12-13 20:15:29 +0000792 ospf_if_stream_set (oi);
793 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp);
794 }
795
796 return 1;
797}
798
799int
800ospf_if_down (struct ospf_interface *oi)
801{
802 if (oi == NULL)
803 return 0;
804
805 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
806 /* Shutdown packet reception and sending */
807 ospf_if_stream_unset (oi);
paul718e3742002-12-13 20:15:29 +0000808
809 return 1;
810}
811
812
813/* Virtual Link related functions. */
814
815struct ospf_vl_data *
816ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer)
817{
818 struct ospf_vl_data *vl_data;
819
Stephen Hemminger393deb92008-08-18 14:13:29 -0700820 vl_data = XCALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data));
paul718e3742002-12-13 20:15:29 +0000821
822 vl_data->vl_peer.s_addr = vl_peer.s_addr;
823 vl_data->vl_area_id = area->area_id;
824 vl_data->format = area->format;
825
826 return vl_data;
827}
828
829void
830ospf_vl_data_free (struct ospf_vl_data *vl_data)
831{
832 XFREE (MTYPE_OSPF_VL_DATA, vl_data);
833}
834
835u_int vlink_count = 0;
836
837struct ospf_interface *
paul68980082003-03-25 05:07:42 +0000838ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000839{
840 struct ospf_interface * voi;
841 struct interface * vi;
842 char ifname[INTERFACE_NAMSIZ + 1];
843 struct ospf_area *area;
844 struct in_addr area_id;
845 struct connected *co;
846 struct prefix_ipv4 *p;
847
848 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000849 zlog_debug ("ospf_vl_new(): Start");
paul718e3742002-12-13 20:15:29 +0000850 if (vlink_count == OSPF_VL_MAX_COUNT)
851 {
852 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000853 zlog_debug ("ospf_vl_new(): Alarm: "
paul718e3742002-12-13 20:15:29 +0000854 "cannot create more than OSPF_MAX_VL_COUNT virtual links");
855 return NULL;
856 }
857
858 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000859 zlog_debug ("ospf_vl_new(): creating pseudo zebra interface");
paul718e3742002-12-13 20:15:29 +0000860
ajsa3491982005-04-02 22:50:38 +0000861 snprintf (ifname, sizeof(ifname), "VLINK%d", vlink_count);
862 vi = if_create (ifname, strnlen(ifname, sizeof(ifname)));
paul718e3742002-12-13 20:15:29 +0000863 co = connected_new ();
864 co->ifp = vi;
865 listnode_add (vi->connected, co);
866
867 p = prefix_ipv4_new ();
868 p->family = AF_INET;
869 p->prefix.s_addr = 0;
870 p->prefixlen = 0;
871
872 co->address = (struct prefix *)p;
873
paul68980082003-03-25 05:07:42 +0000874 voi = ospf_if_new (ospf, vi, co->address);
paul718e3742002-12-13 20:15:29 +0000875 if (voi == NULL)
876 {
877 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000878 zlog_debug ("ospf_vl_new(): Alarm: OSPF int structure is not created");
paul718e3742002-12-13 20:15:29 +0000879 return NULL;
880 }
881 voi->connected = co;
882 voi->vl_data = vl_data;
883 voi->ifp->mtu = OSPF_VL_MTU;
884 voi->type = OSPF_IFTYPE_VIRTUALLINK;
885
paul106d2fd2003-08-01 00:24:13 +0000886 vlink_count++;
paul718e3742002-12-13 20:15:29 +0000887 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000888 zlog_debug ("ospf_vl_new(): Created name: %s", ifname);
paul718e3742002-12-13 20:15:29 +0000889 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000890 zlog_debug ("ospf_vl_new(): set if->name to %s", vi->name);
paul718e3742002-12-13 20:15:29 +0000891
892 area_id.s_addr = 0;
paul68980082003-03-25 05:07:42 +0000893 area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS);
paul718e3742002-12-13 20:15:29 +0000894 voi->area = area;
895
896 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000897 zlog_debug ("ospf_vl_new(): set associated area to the backbone");
paul718e3742002-12-13 20:15:29 +0000898
Paul Jakma478aab92006-04-03 21:25:32 +0000899 ospf_nbr_add_self (voi);
paul718e3742002-12-13 20:15:29 +0000900 ospf_area_add_if (voi->area, voi);
901
902 ospf_if_stream_set (voi);
903
904 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000905 zlog_debug ("ospf_vl_new(): Stop");
paul718e3742002-12-13 20:15:29 +0000906 return voi;
907}
908
paul4dadc292005-05-06 21:37:42 +0000909static void
paul718e3742002-12-13 20:15:29 +0000910ospf_vl_if_delete (struct ospf_vl_data *vl_data)
911{
912 struct interface *ifp = vl_data->vl_oi->ifp;
913 vl_data->vl_oi->address->u.prefix4.s_addr = 0;
914 vl_data->vl_oi->address->prefixlen = 0;
915 ospf_if_free (vl_data->vl_oi);
916 if_delete (ifp);
917 vlink_count--;
918}
919
Paul Jakma9c27ef92006-05-04 07:32:57 +0000920/* Look up vl_data for given peer, optionally qualified to be in the
921 * specified area. NULL area returns first found..
922 */
paul718e3742002-12-13 20:15:29 +0000923struct ospf_vl_data *
Paul Jakma9c27ef92006-05-04 07:32:57 +0000924ospf_vl_lookup (struct ospf *ospf, struct ospf_area *area,
925 struct in_addr vl_peer)
paul718e3742002-12-13 20:15:29 +0000926{
927 struct ospf_vl_data *vl_data;
hasso52dc7ee2004-09-23 19:18:23 +0000928 struct listnode *node;
Paul Jakma9c27ef92006-05-04 07:32:57 +0000929
930 if (IS_DEBUG_OSPF_EVENT)
931 {
932 zlog_debug ("%s: Looking for %s", __func__, inet_ntoa (vl_peer));
933 if (area)
934 zlog_debug ("%s: in area %s", __func__, inet_ntoa (area->area_id));
935 }
936
937 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
938 {
939 if (IS_DEBUG_OSPF_EVENT)
940 zlog_debug ("%s: VL %s, peer %s", __func__,
941 vl_data->vl_oi->ifp->name,
942 inet_ntoa (vl_data->vl_peer));
943
944 if (area && !IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
945 continue;
946
947 if (IPV4_ADDR_SAME (&vl_data->vl_peer, &vl_peer))
948 return vl_data;
949 }
paul718e3742002-12-13 20:15:29 +0000950
951 return NULL;
952}
953
paul4dadc292005-05-06 21:37:42 +0000954static void
paul718e3742002-12-13 20:15:29 +0000955ospf_vl_shutdown (struct ospf_vl_data *vl_data)
956{
957 struct ospf_interface *oi;
958
959 if ((oi = vl_data->vl_oi) == NULL)
960 return;
961
962 oi->address->u.prefix4.s_addr = 0;
963 oi->address->prefixlen = 0;
964
965 UNSET_FLAG (oi->ifp->flags, IFF_UP);
966 /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */
967 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
968}
969
970void
paul68980082003-03-25 05:07:42 +0000971ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000972{
paul68980082003-03-25 05:07:42 +0000973 listnode_add (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000974#ifdef HAVE_SNMP
975 ospf_snmp_vl_add (vl_data);
976#endif /* HAVE_SNMP */
977}
978
979void
paul68980082003-03-25 05:07:42 +0000980ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data)
paul718e3742002-12-13 20:15:29 +0000981{
982 ospf_vl_shutdown (vl_data);
983 ospf_vl_if_delete (vl_data);
984
985#ifdef HAVE_SNMP
986 ospf_snmp_vl_delete (vl_data);
987#endif /* HAVE_SNMP */
paul68980082003-03-25 05:07:42 +0000988 listnode_delete (ospf->vlinks, vl_data);
paul718e3742002-12-13 20:15:29 +0000989
990 ospf_vl_data_free (vl_data);
991}
992
paul4dadc292005-05-06 21:37:42 +0000993static int
paul718e3742002-12-13 20:15:29 +0000994ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v)
995{
996 int changed = 0;
997 struct ospf_interface *voi;
hasso52dc7ee2004-09-23 19:18:23 +0000998 struct listnode *node;
pauleb3da6d2005-10-18 04:20:33 +0000999 struct vertex_parent *vp = NULL;
paul718e3742002-12-13 20:15:29 +00001000 int i;
1001 struct router_lsa *rl;
1002
1003 voi = vl_data->vl_oi;
1004
1005 if (voi->output_cost != v->distance)
1006 {
paulcd59da62004-05-05 17:26:55 +00001007
paul718e3742002-12-13 20:15:29 +00001008 voi->output_cost = v->distance;
1009 changed = 1;
1010 }
1011
pauleb3da6d2005-10-18 04:20:33 +00001012 for (ALL_LIST_ELEMENTS_RO (v->parents, node, vp))
paul1eb8ef22005-04-07 07:30:20 +00001013 {
Paul Jakma9c27ef92006-05-04 07:32:57 +00001014 vl_data->nexthop.oi = vp->nexthop->oi;
1015 vl_data->nexthop.router = vp->nexthop->router;
paul1eb8ef22005-04-07 07:30:20 +00001016
1017 if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
Paul Jakma9c27ef92006-05-04 07:32:57 +00001018 &vl_data->nexthop.oi->address->u.prefix4))
paul1eb8ef22005-04-07 07:30:20 +00001019 changed = 1;
paulcd59da62004-05-05 17:26:55 +00001020
Paul Jakma9c27ef92006-05-04 07:32:57 +00001021 voi->address->u.prefix4 = vl_data->nexthop.oi->address->u.prefix4;
1022 voi->address->prefixlen = vl_data->nexthop.oi->address->prefixlen;
paul718e3742002-12-13 20:15:29 +00001023
paul1eb8ef22005-04-07 07:30:20 +00001024 break; /* We take the first interface. */
1025 }
paul718e3742002-12-13 20:15:29 +00001026
1027 rl = (struct router_lsa *)v->lsa;
pauld355bfa2004-04-08 07:43:45 +00001028
1029 /* use SPF determined backlink index in struct vertex
1030 * for virtual link destination address
1031 */
pauleb3da6d2005-10-18 04:20:33 +00001032 if (vp && vp->backlink >= 0)
paul718e3742002-12-13 20:15:29 +00001033 {
pauld355bfa2004-04-08 07:43:45 +00001034 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
pauleb3da6d2005-10-18 04:20:33 +00001035 &rl->link[vp->backlink].link_data))
pauld355bfa2004-04-08 07:43:45 +00001036 changed = 1;
pauleb3da6d2005-10-18 04:20:33 +00001037 vl_data->peer_addr = rl->link[vp->backlink].link_data;
pauld355bfa2004-04-08 07:43:45 +00001038 }
1039 else
1040 {
1041 /* This is highly odd, there is no backlink index
1042 * there should be due to the ospf_spf_has_link() check
1043 * in SPF. Lets warn and try pick a link anyway.
1044 */
1045 zlog_warn ("ospf_vl_set_params: No backlink for %s!",
1046 vl_data->vl_oi->ifp->name);
1047 for (i = 0; i < ntohs (rl->links); i++)
paul2e6b0bb2003-06-22 08:17:12 +00001048 {
pauld355bfa2004-04-08 07:43:45 +00001049 switch (rl->link[i].type)
1050 {
1051 case LSA_LINK_TYPE_VIRTUALLINK:
1052 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001053 zlog_debug ("found back link through VL");
pauld355bfa2004-04-08 07:43:45 +00001054 case LSA_LINK_TYPE_TRANSIT:
1055 case LSA_LINK_TYPE_POINTOPOINT:
paulcd59da62004-05-05 17:26:55 +00001056 if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
1057 &rl->link[i].link_data))
1058 changed = 1;
pauld355bfa2004-04-08 07:43:45 +00001059 vl_data->peer_addr = rl->link[i].link_data;
pauld355bfa2004-04-08 07:43:45 +00001060 }
paul2e6b0bb2003-06-22 08:17:12 +00001061 }
paul718e3742002-12-13 20:15:29 +00001062 }
pauld355bfa2004-04-08 07:43:45 +00001063
1064 if (IS_DEBUG_OSPF_EVENT)
Paul Jakma9c27ef92006-05-04 07:32:57 +00001065 zlog_debug ("%s: %s peer address: %s, cost: %d,%schanged", __func__,
pauld355bfa2004-04-08 07:43:45 +00001066 vl_data->vl_oi->ifp->name,
Paul Jakma9c27ef92006-05-04 07:32:57 +00001067 inet_ntoa(vl_data->peer_addr),
1068 voi->output_cost,
1069 (changed ? " " : " un"));
pauld355bfa2004-04-08 07:43:45 +00001070
paul2e6b0bb2003-06-22 08:17:12 +00001071 return changed;
paul718e3742002-12-13 20:15:29 +00001072}
1073
1074
1075void
paul68980082003-03-25 05:07:42 +00001076ospf_vl_up_check (struct ospf_area *area, struct in_addr rid,
paul718e3742002-12-13 20:15:29 +00001077 struct vertex *v)
1078{
paul68980082003-03-25 05:07:42 +00001079 struct ospf *ospf = area->ospf;
hasso52dc7ee2004-09-23 19:18:23 +00001080 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001081 struct ospf_vl_data *vl_data;
1082 struct ospf_interface *oi;
1083
1084 if (IS_DEBUG_OSPF_EVENT)
1085 {
ajs60925302004-12-08 17:45:02 +00001086 zlog_debug ("ospf_vl_up_check(): Start");
1087 zlog_debug ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid));
1088 zlog_debug ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id));
paul718e3742002-12-13 20:15:29 +00001089 }
1090
paul1eb8ef22005-04-07 07:30:20 +00001091 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
paul718e3742002-12-13 20:15:29 +00001092 {
paul718e3742002-12-13 20:15:29 +00001093 if (IS_DEBUG_OSPF_EVENT)
1094 {
Paul Jakma9c27ef92006-05-04 07:32:57 +00001095 zlog_debug ("%s: considering VL, %s in area %s", __func__,
1096 vl_data->vl_oi->ifp->name,
1097 inet_ntoa (vl_data->vl_area_id));
1098 zlog_debug ("%s: peer ID: %s", __func__,
paul718e3742002-12-13 20:15:29 +00001099 inet_ntoa (vl_data->vl_peer));
1100 }
1101
1102 if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) &&
1103 IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1104 {
1105 oi = vl_data->vl_oi;
1106 SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
1107
1108 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001109 zlog_debug ("ospf_vl_up_check(): this VL matched");
paul718e3742002-12-13 20:15:29 +00001110
1111 if (oi->state == ISM_Down)
1112 {
1113 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +00001114 zlog_debug ("ospf_vl_up_check(): VL is down, waking it up");
paul718e3742002-12-13 20:15:29 +00001115 SET_FLAG (oi->ifp->flags, IFF_UP);
paul2e6b0bb2003-06-22 08:17:12 +00001116 OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp);
paul718e3742002-12-13 20:15:29 +00001117 }
1118
paul2e6b0bb2003-06-22 08:17:12 +00001119 if (ospf_vl_set_params (vl_data, v))
1120 {
1121 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
ajs60925302004-12-08 17:45:02 +00001122 zlog_debug ("ospf_vl_up_check: VL cost change,"
paulcd59da62004-05-05 17:26:55 +00001123 " scheduling router lsa refresh");
paul2e6b0bb2003-06-22 08:17:12 +00001124 if(ospf->backbone)
paulcd59da62004-05-05 17:26:55 +00001125 ospf_router_lsa_timer_add (ospf->backbone);
paul2e6b0bb2003-06-22 08:17:12 +00001126 else if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
ajs60925302004-12-08 17:45:02 +00001127 zlog_debug ("ospf_vl_up_check: VL cost change, no backbone!");
paul2e6b0bb2003-06-22 08:17:12 +00001128 }
paul718e3742002-12-13 20:15:29 +00001129 }
1130 }
1131}
1132
1133void
paul68980082003-03-25 05:07:42 +00001134ospf_vl_unapprove (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001135{
hasso52dc7ee2004-09-23 19:18:23 +00001136 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001137 struct ospf_vl_data *vl_data;
1138
paul1eb8ef22005-04-07 07:30:20 +00001139 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
1140 UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
paul718e3742002-12-13 20:15:29 +00001141}
1142
1143void
paul68980082003-03-25 05:07:42 +00001144ospf_vl_shut_unapproved (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001145{
paul1eb8ef22005-04-07 07:30:20 +00001146 struct listnode *node, *nnode;
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 (ospf->vlinks, node, nnode, vl_data))
1150 if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
1151 ospf_vl_shutdown (vl_data);
paul718e3742002-12-13 20:15:29 +00001152}
1153
1154int
1155ospf_full_virtual_nbrs (struct ospf_area *area)
1156{
1157 if (IS_DEBUG_OSPF_EVENT)
1158 {
ajs60925302004-12-08 17:45:02 +00001159 zlog_debug ("counting fully adjacent virtual neighbors in area %s",
paul718e3742002-12-13 20:15:29 +00001160 inet_ntoa (area->area_id));
ajs60925302004-12-08 17:45:02 +00001161 zlog_debug ("there are %d of them", area->full_vls);
paul718e3742002-12-13 20:15:29 +00001162 }
1163
1164 return area->full_vls;
1165}
1166
1167int
1168ospf_vls_in_area (struct ospf_area *area)
1169{
hasso52dc7ee2004-09-23 19:18:23 +00001170 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001171 struct ospf_vl_data *vl_data;
1172 int c = 0;
1173
paul1eb8ef22005-04-07 07:30:20 +00001174 for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
1175 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1176 c++;
paul718e3742002-12-13 20:15:29 +00001177
1178 return c;
1179}
1180
1181
1182struct crypt_key *
1183ospf_crypt_key_new ()
1184{
Stephen Hemminger393deb92008-08-18 14:13:29 -07001185 return XCALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key));
paul718e3742002-12-13 20:15:29 +00001186}
1187
1188void
hasso52dc7ee2004-09-23 19:18:23 +00001189ospf_crypt_key_add (struct list *crypt, struct crypt_key *ck)
paul718e3742002-12-13 20:15:29 +00001190{
1191 listnode_add (crypt, ck);
1192}
1193
1194struct crypt_key *
hasso52dc7ee2004-09-23 19:18:23 +00001195ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001196{
hasso52dc7ee2004-09-23 19:18:23 +00001197 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001198 struct crypt_key *ck;
1199
paul1eb8ef22005-04-07 07:30:20 +00001200 for (ALL_LIST_ELEMENTS_RO (auth_crypt, node, ck))
1201 if (ck->key_id == key_id)
1202 return ck;
paul718e3742002-12-13 20:15:29 +00001203
1204 return NULL;
1205}
1206
1207int
hasso52dc7ee2004-09-23 19:18:23 +00001208ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id)
paul718e3742002-12-13 20:15:29 +00001209{
paul1eb8ef22005-04-07 07:30:20 +00001210 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001211 struct crypt_key *ck;
1212
paul1eb8ef22005-04-07 07:30:20 +00001213 for (ALL_LIST_ELEMENTS (auth_crypt, node, nnode, ck))
paul718e3742002-12-13 20:15:29 +00001214 {
paul718e3742002-12-13 20:15:29 +00001215 if (ck->key_id == key_id)
1216 {
1217 listnode_delete (auth_crypt, ck);
vincentba682532005-09-29 13:52:57 +00001218 XFREE (MTYPE_OSPF_CRYPT_KEY, ck);
paul718e3742002-12-13 20:15:29 +00001219 return 1;
1220 }
1221 }
1222
1223 return 0;
1224}
1225
ajsbc18d612004-12-15 15:07:19 +00001226u_char
1227ospf_default_iftype(struct interface *ifp)
1228{
1229 if (if_is_pointopoint (ifp))
1230 return OSPF_IFTYPE_POINTOPOINT;
1231 else if (if_is_loopback (ifp))
1232 return OSPF_IFTYPE_LOOPBACK;
1233 else
1234 return OSPF_IFTYPE_BROADCAST;
1235}
1236
paul718e3742002-12-13 20:15:29 +00001237void
1238ospf_if_init ()
1239{
1240 /* Initialize Zebra interface data structure. */
1241 if_init ();
paul020709f2003-04-04 02:44:16 +00001242 om->iflist = iflist;
paul718e3742002-12-13 20:15:29 +00001243 if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
1244 if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);
1245}