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