]>
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" | |
c0325cfa | 34 | #include "zclient.h" |
7f342629 | 35 | #include "bfd.h" |
718e3744 | 36 | |
68980084 | 37 | #include "ospfd/ospfd.h" |
718e3744 | 38 | #include "ospfd/ospf_spf.h" |
39 | #include "ospfd/ospf_interface.h" | |
40 | #include "ospfd/ospf_ism.h" | |
41 | #include "ospfd/ospf_asbr.h" | |
42 | #include "ospfd/ospf_lsa.h" | |
43 | #include "ospfd/ospf_lsdb.h" | |
44 | #include "ospfd/ospf_neighbor.h" | |
45 | #include "ospfd/ospf_nsm.h" | |
46 | #include "ospfd/ospf_packet.h" | |
47 | #include "ospfd/ospf_abr.h" | |
718e3744 | 48 | #include "ospfd/ospf_network.h" |
49 | #include "ospfd/ospf_dump.h" | |
50 | #ifdef HAVE_SNMP | |
51 | #include "ospfd/ospf_snmp.h" | |
52 | #endif /* HAVE_SNMP */ | |
53 | ||
ae19c240 | 54 | DEFINE_QOBJ_TYPE(ospf_interface) |
6b0655a2 | 55 | |
718e3744 | 56 | int |
57 | ospf_if_get_output_cost (struct ospf_interface *oi) | |
58 | { | |
59 | /* If all else fails, use default OSPF cost */ | |
60 | u_int32_t cost; | |
61 | u_int32_t bw, refbw; | |
62 | ||
63 | bw = oi->ifp->bandwidth ? oi->ifp->bandwidth : OSPF_DEFAULT_BANDWIDTH; | |
68980084 | 64 | refbw = oi->ospf->ref_bandwidth; |
718e3744 | 65 | |
66 | /* A specifed ip ospf cost overrides a calculated one. */ | |
67 | if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (oi->ifp), output_cost_cmd) || | |
68 | OSPF_IF_PARAM_CONFIGURED (oi->params, output_cost_cmd)) | |
69 | cost = OSPF_IF_PARAM (oi, output_cost_cmd); | |
70 | /* See if a cost can be calculated from the zebra processes | |
71 | interface bandwidth field. */ | |
72 | else | |
73 | { | |
74 | cost = (u_int32_t) ((double)refbw / (double)bw + (double)0.5); | |
75 | if (cost < 1) | |
76 | cost = 1; | |
77 | else if (cost > 65535) | |
78 | cost = 65535; | |
79 | } | |
80 | ||
81 | return cost; | |
82 | } | |
83 | ||
84 | void | |
85 | ospf_if_recalculate_output_cost (struct interface *ifp) | |
86 | { | |
87 | u_int32_t newcost; | |
88 | struct route_node *rn; | |
89 | ||
90 | for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) | |
91 | { | |
92 | struct ospf_interface *oi; | |
93 | ||
94 | if ( (oi = rn->info) == NULL) | |
95 | continue; | |
96 | ||
97 | newcost = ospf_if_get_output_cost (oi); | |
98 | ||
99 | /* Is actual output cost changed? */ | |
100 | if (oi->output_cost != newcost) | |
101 | { | |
102 | oi->output_cost = newcost; | |
c363d386 | 103 | ospf_router_lsa_update_area (oi->area); |
718e3744 | 104 | } |
105 | } | |
106 | } | |
107 | ||
a608bbf2 | 108 | /* Simulate down/up on the interface. This is needed, for example, when |
109 | the MTU changes. */ | |
110 | void | |
111 | ospf_if_reset(struct interface *ifp) | |
112 | { | |
113 | struct route_node *rn; | |
114 | ||
115 | for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) | |
116 | { | |
117 | struct ospf_interface *oi; | |
118 | ||
119 | if ( (oi = rn->info) == NULL) | |
120 | continue; | |
121 | ||
122 | ospf_if_down(oi); | |
123 | ospf_if_up(oi); | |
124 | } | |
125 | } | |
126 | ||
718e3744 | 127 | void |
128 | ospf_if_reset_variables (struct ospf_interface *oi) | |
129 | { | |
130 | /* Set default values. */ | |
131 | /* don't clear this flag. oi->flag = OSPF_IF_DISABLE; */ | |
132 | ||
133 | if (oi->vl_data) | |
134 | oi->type = OSPF_IFTYPE_VIRTUALLINK; | |
135 | else | |
136 | /* preserve network-type */ | |
137 | if (oi->type != OSPF_IFTYPE_NBMA) | |
138 | oi->type = OSPF_IFTYPE_BROADCAST; | |
139 | ||
140 | oi->state = ISM_Down; | |
141 | ||
142 | oi->crypt_seqnum = 0; | |
143 | ||
144 | /* This must be short, (less than RxmtInterval) | |
145 | - RFC 2328 Section 13.5 para 3. Set to 1 second to avoid Acks being | |
146 | held back for too long - MAG */ | |
147 | oi->v_ls_ack = 1; | |
148 | } | |
149 | ||
20916fba | 150 | /* lookup oi for specified prefix/ifp */ |
f0f63841 | 151 | struct ospf_interface * |
20916fba | 152 | ospf_if_table_lookup (struct interface *ifp, struct prefix *prefix) |
153 | { | |
154 | struct prefix p; | |
affe1d9c | 155 | struct route_node *rn; |
a3387a44 | 156 | struct ospf_interface *rninfo = NULL; |
20916fba | 157 | |
158 | p = *prefix; | |
a3387a44 | 159 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
160 | ||
20916fba | 161 | /* route_node_get implicitely locks */ |
f9ad937f | 162 | if ((rn = route_node_lookup (IF_OIFS (ifp), &p))) |
a3387a44 | 163 | { |
164 | rninfo = (struct ospf_interface *) rn->info; | |
165 | route_unlock_node (rn); | |
166 | } | |
167 | ||
b5f2c126 | 168 | return rninfo; |
20916fba | 169 | } |
170 | ||
4dadc291 | 171 | static void |
718e3744 | 172 | ospf_add_to_if (struct interface *ifp, struct ospf_interface *oi) |
173 | { | |
174 | struct route_node *rn; | |
175 | struct prefix p; | |
176 | ||
177 | p = *oi->address; | |
178 | p.prefixlen = IPV4_MAX_PREFIXLEN; | |
179 | ||
180 | rn = route_node_get (IF_OIFS (ifp), &p); | |
8c80cb7e | 181 | /* rn->info should either be NULL or equal to this oi |
182 | * as route_node_get may return an existing node | |
183 | */ | |
20916fba | 184 | assert (!rn->info || rn->info == oi); |
718e3744 | 185 | rn->info = oi; |
186 | } | |
187 | ||
4dadc291 | 188 | static void |
718e3744 | 189 | ospf_delete_from_if (struct interface *ifp, struct ospf_interface *oi) |
190 | { | |
191 | struct route_node *rn; | |
192 | struct prefix p; | |
193 | ||
194 | p = *oi->address; | |
195 | p.prefixlen = IPV4_MAX_PREFIXLEN; | |
196 | ||
197 | rn = route_node_lookup (IF_OIFS (oi->ifp), &p); | |
198 | assert (rn); | |
199 | assert (rn->info); | |
200 | rn->info = NULL; | |
201 | route_unlock_node (rn); | |
202 | route_unlock_node (rn); | |
203 | } | |
204 | ||
205 | struct ospf_interface * | |
68980084 | 206 | ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p) |
718e3744 | 207 | { |
208 | struct ospf_interface *oi; | |
209 | ||
20916fba | 210 | if ((oi = ospf_if_table_lookup (ifp, p)) == NULL) |
211 | { | |
212 | oi = XCALLOC (MTYPE_OSPF_IF, sizeof (struct ospf_interface)); | |
213 | memset (oi, 0, sizeof (struct ospf_interface)); | |
214 | } | |
215 | else | |
216 | return oi; | |
217 | ||
718e3744 | 218 | /* Set zebra interface pointer. */ |
219 | oi->ifp = ifp; | |
220 | oi->address = p; | |
221 | ||
222 | ospf_add_to_if (ifp, oi); | |
68980084 | 223 | listnode_add (ospf->oiflist, oi); |
718e3744 | 224 | |
718e3744 | 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 | ||
ecea0cb0 JAG |
238 | /* Set pseudo neighbor to Null */ |
239 | oi->nbr_self = NULL; | |
718e3744 | 240 | |
241 | oi->ls_upd_queue = route_table_init (); | |
242 | oi->t_ls_upd_event = NULL; | |
243 | oi->t_ls_ack_direct = NULL; | |
244 | ||
68980084 | 245 | oi->crypt_seqnum = time (NULL); |
246 | ||
718e3744 | 247 | ospf_opaque_type9_lsa_init (oi); |
718e3744 | 248 | |
68980084 | 249 | oi->ospf = ospf; |
ae19c240 DL |
250 | QOBJ_REG (oi, ospf_interface); |
251 | ||
718e3744 | 252 | return oi; |
253 | } | |
254 | ||
255 | /* Restore an interface to its pre UP state | |
256 | Used from ism_interface_down only */ | |
257 | void | |
258 | ospf_if_cleanup (struct ospf_interface *oi) | |
259 | { | |
260 | struct route_node *rn; | |
1eb8ef25 | 261 | struct listnode *node, *nnode; |
718e3744 | 262 | struct ospf_neighbor *nbr; |
1eb8ef25 | 263 | struct ospf_nbr_nbma *nbr_nbma; |
264 | struct ospf_lsa *lsa; | |
718e3744 | 265 | |
1a643f88 | 266 | /* oi->nbrs and oi->nbr_nbma should be deleted on InterfaceDown event */ |
718e3744 | 267 | /* delete all static neighbors attached to this interface */ |
1eb8ef25 | 268 | for (ALL_LIST_ELEMENTS (oi->nbr_nbma, node, nnode, nbr_nbma)) |
718e3744 | 269 | { |
718e3744 | 270 | OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll); |
271 | ||
272 | if (nbr_nbma->nbr) | |
273 | { | |
274 | nbr_nbma->nbr->nbr_nbma = NULL; | |
275 | nbr_nbma->nbr = NULL; | |
276 | } | |
277 | ||
278 | nbr_nbma->oi = NULL; | |
279 | ||
280 | listnode_delete (oi->nbr_nbma, nbr_nbma); | |
281 | } | |
282 | ||
283 | /* send Neighbor event KillNbr to all associated neighbors. */ | |
284 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) | |
285 | if ((nbr = rn->info) != NULL) | |
286 | if (nbr != oi->nbr_self) | |
287 | OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr); | |
288 | ||
289 | /* Cleanup Link State Acknowlegdment list. */ | |
1eb8ef25 | 290 | for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa)) |
1fe6ed38 | 291 | ospf_lsa_unlock (&lsa); /* oi->ls_ack */ |
718e3744 | 292 | list_delete_all_node (oi->ls_ack); |
293 | ||
294 | oi->crypt_seqnum = 0; | |
295 | ||
296 | /* Empty link state update queue */ | |
297 | ospf_ls_upd_queue_empty (oi); | |
298 | ||
1a643f88 | 299 | /* Reset pseudo neighbor. */ |
58136de9 | 300 | ospf_nbr_self_reset (oi, oi->ospf->router_id); |
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 | ||
718e3744 | 310 | ospf_opaque_type9_lsa_term (oi); |
718e3744 | 311 | |
ae19c240 DL |
312 | QOBJ_UNREG (oi); |
313 | ||
718e3744 | 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); | |
7f342629 | 563 | bfd_info_free(&(oip->bfd_info)); |
718e3744 | 564 | XFREE (MTYPE_OSPF_IF_PARAMS, oip); |
565 | } | |
566 | ||
567 | void | |
568 | ospf_free_if_params (struct interface *ifp, struct in_addr addr) | |
569 | { | |
570 | struct ospf_if_params *oip; | |
571 | struct prefix_ipv4 p; | |
572 | struct route_node *rn; | |
630e4807 | 573 | |
574 | p.family = AF_INET; | |
718e3744 | 575 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
576 | p.prefix = addr; | |
577 | rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p); | |
578 | if (!rn || !rn->info) | |
579 | return; | |
580 | ||
581 | oip = rn->info; | |
582 | route_unlock_node (rn); | |
583 | ||
584 | if (!OSPF_IF_PARAM_CONFIGURED (oip, output_cost_cmd) && | |
585 | !OSPF_IF_PARAM_CONFIGURED (oip, transmit_delay) && | |
586 | !OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) && | |
587 | !OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) && | |
588 | !OSPF_IF_PARAM_CONFIGURED (oip, v_hello) && | |
f9ad937f | 589 | !OSPF_IF_PARAM_CONFIGURED (oip, fast_hello) && |
718e3744 | 590 | !OSPF_IF_PARAM_CONFIGURED (oip, v_wait) && |
591 | !OSPF_IF_PARAM_CONFIGURED (oip, priority) && | |
592 | !OSPF_IF_PARAM_CONFIGURED (oip, type) && | |
593 | !OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) && | |
594 | !OSPF_IF_PARAM_CONFIGURED (oip, auth_type) && | |
7eb5b47e PJ |
595 | listcount (oip->auth_crypt) == 0 && |
596 | ntohl (oip->network_lsa_seqnum) != OSPF_INITIAL_SEQUENCE_NUMBER) | |
718e3744 | 597 | { |
598 | ospf_del_if_params (oip); | |
599 | rn->info = NULL; | |
600 | route_unlock_node (rn); | |
601 | } | |
602 | } | |
603 | ||
604 | struct ospf_if_params * | |
605 | ospf_lookup_if_params (struct interface *ifp, struct in_addr addr) | |
606 | { | |
607 | struct prefix_ipv4 p; | |
608 | struct route_node *rn; | |
609 | ||
630e4807 | 610 | p.family = AF_INET; |
718e3744 | 611 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
612 | p.prefix = addr; | |
613 | ||
614 | rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p); | |
615 | ||
616 | if (rn) | |
617 | { | |
618 | route_unlock_node (rn); | |
619 | return rn->info; | |
620 | } | |
621 | ||
622 | return NULL; | |
623 | } | |
624 | ||
625 | struct ospf_if_params * | |
626 | ospf_get_if_params (struct interface *ifp, struct in_addr addr) | |
627 | { | |
628 | struct prefix_ipv4 p; | |
629 | struct route_node *rn; | |
630 | ||
631 | p.family = AF_INET; | |
632 | p.prefixlen = IPV4_MAX_PREFIXLEN; | |
633 | p.prefix = addr; | |
634 | ||
635 | rn = route_node_get (IF_OIFS_PARAMS (ifp), (struct prefix*)&p); | |
636 | ||
637 | if (rn->info == NULL) | |
638 | rn->info = ospf_new_if_params (); | |
639 | else | |
640 | route_unlock_node (rn); | |
641 | ||
642 | return rn->info; | |
643 | } | |
644 | ||
645 | void | |
646 | ospf_if_update_params (struct interface *ifp, struct in_addr addr) | |
647 | { | |
648 | struct route_node *rn; | |
649 | struct ospf_interface *oi; | |
650 | ||
651 | for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) | |
652 | { | |
653 | if ((oi = rn->info) == NULL) | |
654 | continue; | |
655 | ||
656 | if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &addr)) | |
657 | oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4); | |
658 | } | |
659 | } | |
660 | ||
661 | int | |
662 | ospf_if_new_hook (struct interface *ifp) | |
663 | { | |
664 | int rc = 0; | |
665 | ||
393deb9b | 666 | ifp->info = XCALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info)); |
718e3744 | 667 | |
668 | IF_OIFS (ifp) = route_table_init (); | |
669 | IF_OIFS_PARAMS (ifp) = route_table_init (); | |
670 | ||
671 | IF_DEF_PARAMS (ifp) = ospf_new_if_params (); | |
672 | ||
673 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay); | |
674 | IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
675 | ||
676 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval); | |
677 | IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
678 | ||
679 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority); | |
680 | IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
681 | ||
ba682537 | 682 | IF_DEF_PARAMS (ifp)->mtu_ignore = OSPF_MTU_IGNORE_DEFAULT; |
683 | ||
718e3744 | 684 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello); |
685 | IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
686 | ||
f9ad937f | 687 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), fast_hello); |
688 | IF_DEF_PARAMS (ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
689 | ||
718e3744 | 690 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait); |
691 | IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
692 | ||
693 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple); | |
694 | memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); | |
695 | ||
718e3744 | 696 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type); |
697 | IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET; | |
698 | ||
718e3744 | 699 | rc = ospf_opaque_new_if (ifp); |
718e3744 | 700 | return rc; |
701 | } | |
702 | ||
4dadc291 | 703 | static int |
718e3744 | 704 | ospf_if_delete_hook (struct interface *ifp) |
705 | { | |
706 | int rc = 0; | |
940b01aa | 707 | struct route_node *rn; |
718e3744 | 708 | rc = ospf_opaque_del_if (ifp); |
940b01aa | 709 | |
718e3744 | 710 | route_table_finish (IF_OIFS (ifp)); |
940b01aa | 711 | |
712 | for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn)) | |
713 | if (rn->info) | |
714 | ospf_del_if_params (rn->info); | |
718e3744 | 715 | route_table_finish (IF_OIFS_PARAMS (ifp)); |
940b01aa | 716 | |
cfc959b8 | 717 | ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp)); |
718e3744 | 718 | XFREE (MTYPE_OSPF_IF_INFO, ifp->info); |
719 | ifp->info = NULL; | |
720 | ||
721 | return rc; | |
722 | } | |
723 | ||
724 | int | |
725 | ospf_if_is_enable (struct ospf_interface *oi) | |
726 | { | |
727 | if (!if_is_loopback (oi->ifp)) | |
728 | if (if_is_up (oi->ifp)) | |
729 | return 1; | |
730 | ||
731 | return 0; | |
732 | } | |
733 | ||
ba6454ec | 734 | void |
735 | ospf_if_set_multicast(struct ospf_interface *oi) | |
736 | { | |
737 | if ((oi->state > ISM_Loopback) && | |
738 | (oi->type != OSPF_IFTYPE_LOOPBACK) && | |
739 | (oi->type != OSPF_IFTYPE_VIRTUALLINK) && | |
e8a56f02 | 740 | (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE)) |
ba6454ec | 741 | { |
742 | /* The interface should belong to the OSPF-all-routers group. */ | |
429ac78c | 743 | if (!OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) && |
ba6454ec | 744 | (ospf_if_add_allspfrouters(oi->ospf, oi->address, |
745 | oi->ifp->ifindex) >= 0)) | |
429ac78c PJ |
746 | /* Set the flag only if the system call to join succeeded. */ |
747 | OI_MEMBER_JOINED(oi, MEMBER_ALLROUTERS); | |
ba6454ec | 748 | } |
749 | else | |
750 | { | |
751 | /* The interface should NOT belong to the OSPF-all-routers group. */ | |
429ac78c | 752 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) |
ba6454ec | 753 | { |
429ac78c PJ |
754 | /* Only actually drop if this is the last reference */ |
755 | if (OI_MEMBER_COUNT(oi, MEMBER_ALLROUTERS) == 1) | |
756 | ospf_if_drop_allspfrouters (oi->ospf, oi->address, | |
757 | oi->ifp->ifindex); | |
ba6454ec | 758 | /* Unset the flag regardless of whether the system call to leave |
759 | the group succeeded, since it's much safer to assume that | |
760 | we are not a member. */ | |
429ac78c | 761 | OI_MEMBER_LEFT(oi,MEMBER_ALLROUTERS); |
ba6454ec | 762 | } |
763 | } | |
764 | ||
765 | if (((oi->type == OSPF_IFTYPE_BROADCAST) || | |
766 | (oi->type == OSPF_IFTYPE_POINTOPOINT)) && | |
767 | ((oi->state == ISM_DR) || (oi->state == ISM_Backup)) && | |
e8a56f02 | 768 | (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE)) |
ba6454ec | 769 | { |
770 | /* The interface should belong to the OSPF-designated-routers group. */ | |
429ac78c | 771 | if (!OI_MEMBER_CHECK(oi, MEMBER_DROUTERS) && |
ba6454ec | 772 | (ospf_if_add_alldrouters(oi->ospf, oi->address, |
773 | oi->ifp->ifindex) >= 0)) | |
774 | /* Set the flag only if the system call to join succeeded. */ | |
429ac78c | 775 | OI_MEMBER_JOINED(oi, MEMBER_DROUTERS); |
ba6454ec | 776 | } |
777 | else | |
778 | { | |
779 | /* The interface should NOT belong to the OSPF-designated-routers group */ | |
429ac78c | 780 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) |
ba6454ec | 781 | { |
429ac78c PJ |
782 | /* drop only if last reference */ |
783 | if (OI_MEMBER_COUNT(oi, MEMBER_DROUTERS) == 1) | |
784 | ospf_if_drop_alldrouters(oi->ospf, oi->address, oi->ifp->ifindex); | |
785 | ||
ba6454ec | 786 | /* Unset the flag regardless of whether the system call to leave |
787 | the group succeeded, since it's much safer to assume that | |
788 | we are not a member. */ | |
429ac78c | 789 | OI_MEMBER_LEFT(oi, MEMBER_DROUTERS); |
ba6454ec | 790 | } |
791 | } | |
792 | } | |
793 | ||
718e3744 | 794 | int |
795 | ospf_if_up (struct ospf_interface *oi) | |
796 | { | |
797 | if (oi == NULL) | |
798 | return 0; | |
799 | ||
800 | if (oi->type == OSPF_IFTYPE_LOOPBACK) | |
801 | OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd); | |
802 | else | |
803 | { | |
718e3744 | 804 | ospf_if_stream_set (oi); |
805 | OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp); | |
806 | } | |
807 | ||
808 | return 1; | |
809 | } | |
810 | ||
811 | int | |
812 | ospf_if_down (struct ospf_interface *oi) | |
813 | { | |
814 | if (oi == NULL) | |
815 | return 0; | |
816 | ||
817 | OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown); | |
c81ee5c9 JT |
818 | /* delete position in router LSA */ |
819 | oi->lsa_pos_beg = 0; | |
820 | oi->lsa_pos_end = 0; | |
718e3744 | 821 | /* Shutdown packet reception and sending */ |
822 | ospf_if_stream_unset (oi); | |
718e3744 | 823 | |
824 | return 1; | |
825 | } | |
826 | ||
6b0655a2 | 827 | |
718e3744 | 828 | /* Virtual Link related functions. */ |
829 | ||
830 | struct ospf_vl_data * | |
831 | ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer) | |
832 | { | |
833 | struct ospf_vl_data *vl_data; | |
834 | ||
393deb9b | 835 | vl_data = XCALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data)); |
718e3744 | 836 | |
837 | vl_data->vl_peer.s_addr = vl_peer.s_addr; | |
838 | vl_data->vl_area_id = area->area_id; | |
839 | vl_data->format = area->format; | |
840 | ||
841 | return vl_data; | |
842 | } | |
843 | ||
844 | void | |
845 | ospf_vl_data_free (struct ospf_vl_data *vl_data) | |
846 | { | |
847 | XFREE (MTYPE_OSPF_VL_DATA, vl_data); | |
848 | } | |
849 | ||
850 | u_int vlink_count = 0; | |
851 | ||
852 | struct ospf_interface * | |
68980084 | 853 | ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data) |
718e3744 | 854 | { |
855 | struct ospf_interface * voi; | |
856 | struct interface * vi; | |
857 | char ifname[INTERFACE_NAMSIZ + 1]; | |
858 | struct ospf_area *area; | |
859 | struct in_addr area_id; | |
860 | struct connected *co; | |
861 | struct prefix_ipv4 *p; | |
862 | ||
863 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 864 | zlog_debug ("ospf_vl_new(): Start"); |
718e3744 | 865 | if (vlink_count == OSPF_VL_MAX_COUNT) |
866 | { | |
867 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 868 | zlog_debug ("ospf_vl_new(): Alarm: " |
718e3744 | 869 | "cannot create more than OSPF_MAX_VL_COUNT virtual links"); |
870 | return NULL; | |
871 | } | |
872 | ||
873 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 874 | zlog_debug ("ospf_vl_new(): creating pseudo zebra interface"); |
718e3744 | 875 | |
a349198f | 876 | snprintf (ifname, sizeof(ifname), "VLINK%d", vlink_count); |
877 | vi = if_create (ifname, strnlen(ifname, sizeof(ifname))); | |
90c97340 DS |
878 | /* |
879 | * if_create sets ZEBRA_INTERFACE_LINKDETECTION | |
880 | * virtual links don't need this. | |
881 | */ | |
882 | UNSET_FLAG (vi->status, ZEBRA_INTERFACE_LINKDETECTION); | |
718e3744 | 883 | co = connected_new (); |
884 | co->ifp = vi; | |
885 | listnode_add (vi->connected, co); | |
886 | ||
887 | p = prefix_ipv4_new (); | |
888 | p->family = AF_INET; | |
889 | p->prefix.s_addr = 0; | |
890 | p->prefixlen = 0; | |
891 | ||
892 | co->address = (struct prefix *)p; | |
893 | ||
68980084 | 894 | voi = ospf_if_new (ospf, vi, co->address); |
718e3744 | 895 | if (voi == NULL) |
896 | { | |
897 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 898 | zlog_debug ("ospf_vl_new(): Alarm: OSPF int structure is not created"); |
718e3744 | 899 | return NULL; |
900 | } | |
901 | voi->connected = co; | |
902 | voi->vl_data = vl_data; | |
903 | voi->ifp->mtu = OSPF_VL_MTU; | |
904 | voi->type = OSPF_IFTYPE_VIRTUALLINK; | |
905 | ||
106d2fd5 | 906 | vlink_count++; |
718e3744 | 907 | if (IS_DEBUG_OSPF_EVENT) |
60925303 | 908 | zlog_debug ("ospf_vl_new(): Created name: %s", ifname); |
718e3744 | 909 | if (IS_DEBUG_OSPF_EVENT) |
60925303 | 910 | zlog_debug ("ospf_vl_new(): set if->name to %s", vi->name); |
718e3744 | 911 | |
912 | area_id.s_addr = 0; | |
68980084 | 913 | area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS); |
718e3744 | 914 | voi->area = area; |
915 | ||
916 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 917 | zlog_debug ("ospf_vl_new(): set associated area to the backbone"); |
718e3744 | 918 | |
ecea0cb0 | 919 | /* Add pseudo neighbor. */ |
58136de9 | 920 | ospf_nbr_self_reset (voi, voi->ospf->router_id); |
ecea0cb0 | 921 | |
718e3744 | 922 | ospf_area_add_if (voi->area, voi); |
923 | ||
924 | ospf_if_stream_set (voi); | |
925 | ||
926 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 927 | zlog_debug ("ospf_vl_new(): Stop"); |
718e3744 | 928 | return voi; |
929 | } | |
930 | ||
4dadc291 | 931 | static void |
718e3744 | 932 | ospf_vl_if_delete (struct ospf_vl_data *vl_data) |
933 | { | |
934 | struct interface *ifp = vl_data->vl_oi->ifp; | |
935 | vl_data->vl_oi->address->u.prefix4.s_addr = 0; | |
936 | vl_data->vl_oi->address->prefixlen = 0; | |
937 | ospf_if_free (vl_data->vl_oi); | |
938 | if_delete (ifp); | |
939 | vlink_count--; | |
940 | } | |
941 | ||
9c27ef9b PJ |
942 | /* Look up vl_data for given peer, optionally qualified to be in the |
943 | * specified area. NULL area returns first found.. | |
944 | */ | |
718e3744 | 945 | struct ospf_vl_data * |
9c27ef9b PJ |
946 | ospf_vl_lookup (struct ospf *ospf, struct ospf_area *area, |
947 | struct in_addr vl_peer) | |
718e3744 | 948 | { |
949 | struct ospf_vl_data *vl_data; | |
52dc7ee6 | 950 | struct listnode *node; |
9c27ef9b PJ |
951 | |
952 | if (IS_DEBUG_OSPF_EVENT) | |
953 | { | |
954 | zlog_debug ("%s: Looking for %s", __func__, inet_ntoa (vl_peer)); | |
955 | if (area) | |
956 | zlog_debug ("%s: in area %s", __func__, inet_ntoa (area->area_id)); | |
957 | } | |
958 | ||
959 | for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data)) | |
960 | { | |
961 | if (IS_DEBUG_OSPF_EVENT) | |
962 | zlog_debug ("%s: VL %s, peer %s", __func__, | |
963 | vl_data->vl_oi->ifp->name, | |
964 | inet_ntoa (vl_data->vl_peer)); | |
965 | ||
966 | if (area && !IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) | |
967 | continue; | |
968 | ||
969 | if (IPV4_ADDR_SAME (&vl_data->vl_peer, &vl_peer)) | |
970 | return vl_data; | |
971 | } | |
718e3744 | 972 | |
973 | return NULL; | |
974 | } | |
975 | ||
4dadc291 | 976 | static void |
718e3744 | 977 | ospf_vl_shutdown (struct ospf_vl_data *vl_data) |
978 | { | |
979 | struct ospf_interface *oi; | |
980 | ||
981 | if ((oi = vl_data->vl_oi) == NULL) | |
982 | return; | |
983 | ||
984 | oi->address->u.prefix4.s_addr = 0; | |
985 | oi->address->prefixlen = 0; | |
986 | ||
987 | UNSET_FLAG (oi->ifp->flags, IFF_UP); | |
988 | /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */ | |
989 | OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown); | |
990 | } | |
991 | ||
992 | void | |
68980084 | 993 | ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data) |
718e3744 | 994 | { |
68980084 | 995 | listnode_add (ospf->vlinks, vl_data); |
718e3744 | 996 | #ifdef HAVE_SNMP |
997 | ospf_snmp_vl_add (vl_data); | |
998 | #endif /* HAVE_SNMP */ | |
999 | } | |
1000 | ||
1001 | void | |
68980084 | 1002 | ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data) |
718e3744 | 1003 | { |
1004 | ospf_vl_shutdown (vl_data); | |
1005 | ospf_vl_if_delete (vl_data); | |
1006 | ||
1007 | #ifdef HAVE_SNMP | |
1008 | ospf_snmp_vl_delete (vl_data); | |
1009 | #endif /* HAVE_SNMP */ | |
68980084 | 1010 | listnode_delete (ospf->vlinks, vl_data); |
718e3744 | 1011 | |
1012 | ospf_vl_data_free (vl_data); | |
1013 | } | |
1014 | ||
4dadc291 | 1015 | static int |
718e3744 | 1016 | ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v) |
1017 | { | |
1018 | int changed = 0; | |
1019 | struct ospf_interface *voi; | |
52dc7ee6 | 1020 | struct listnode *node; |
eb3da6df | 1021 | struct vertex_parent *vp = NULL; |
b07c4cb3 | 1022 | unsigned int i; |
718e3744 | 1023 | struct router_lsa *rl; |
1024 | ||
1025 | voi = vl_data->vl_oi; | |
1026 | ||
1027 | if (voi->output_cost != v->distance) | |
1028 | { | |
cd59da68 | 1029 | |
718e3744 | 1030 | voi->output_cost = v->distance; |
1031 | changed = 1; | |
1032 | } | |
1033 | ||
eb3da6df | 1034 | for (ALL_LIST_ELEMENTS_RO (v->parents, node, vp)) |
1eb8ef25 | 1035 | { |
9c27ef9b PJ |
1036 | vl_data->nexthop.oi = vp->nexthop->oi; |
1037 | vl_data->nexthop.router = vp->nexthop->router; | |
1eb8ef25 | 1038 | |
1039 | if (!IPV4_ADDR_SAME(&voi->address->u.prefix4, | |
9c27ef9b | 1040 | &vl_data->nexthop.oi->address->u.prefix4)) |
1eb8ef25 | 1041 | changed = 1; |
cd59da68 | 1042 | |
9c27ef9b PJ |
1043 | voi->address->u.prefix4 = vl_data->nexthop.oi->address->u.prefix4; |
1044 | voi->address->prefixlen = vl_data->nexthop.oi->address->prefixlen; | |
1eb8ef25 | 1045 | |
1046 | break; /* We take the first interface. */ | |
1047 | } | |
718e3744 | 1048 | |
1049 | rl = (struct router_lsa *)v->lsa; | |
d355bfa7 | 1050 | |
1051 | /* use SPF determined backlink index in struct vertex | |
1052 | * for virtual link destination address | |
1053 | */ | |
eb3da6df | 1054 | if (vp && vp->backlink >= 0) |
d355bfa7 | 1055 | { |
1056 | if (!IPV4_ADDR_SAME (&vl_data->peer_addr, | |
eb3da6df | 1057 | &rl->link[vp->backlink].link_data)) |
d355bfa7 | 1058 | changed = 1; |
eb3da6df | 1059 | vl_data->peer_addr = rl->link[vp->backlink].link_data; |
d355bfa7 | 1060 | } |
1061 | else | |
718e3744 | 1062 | { |
d355bfa7 | 1063 | /* This is highly odd, there is no backlink index |
1064 | * there should be due to the ospf_spf_has_link() check | |
1065 | * in SPF. Lets warn and try pick a link anyway. | |
1066 | */ | |
1067 | zlog_warn ("ospf_vl_set_params: No backlink for %s!", | |
1068 | vl_data->vl_oi->ifp->name); | |
1069 | for (i = 0; i < ntohs (rl->links); i++) | |
2e6b0bbb | 1070 | { |
d355bfa7 | 1071 | switch (rl->link[i].type) |
1072 | { | |
1073 | case LSA_LINK_TYPE_VIRTUALLINK: | |
1074 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 1075 | zlog_debug ("found back link through VL"); |
d355bfa7 | 1076 | case LSA_LINK_TYPE_TRANSIT: |
1077 | case LSA_LINK_TYPE_POINTOPOINT: | |
cd59da68 | 1078 | if (!IPV4_ADDR_SAME (&vl_data->peer_addr, |
1079 | &rl->link[i].link_data)) | |
1080 | changed = 1; | |
d355bfa7 | 1081 | vl_data->peer_addr = rl->link[i].link_data; |
d355bfa7 | 1082 | } |
2e6b0bbb | 1083 | } |
718e3744 | 1084 | } |
d355bfa7 | 1085 | |
1086 | if (IS_DEBUG_OSPF_EVENT) | |
9c27ef9b | 1087 | zlog_debug ("%s: %s peer address: %s, cost: %d,%schanged", __func__, |
d355bfa7 | 1088 | vl_data->vl_oi->ifp->name, |
9c27ef9b PJ |
1089 | inet_ntoa(vl_data->peer_addr), |
1090 | voi->output_cost, | |
1091 | (changed ? " " : " un")); | |
d355bfa7 | 1092 | |
2e6b0bbb | 1093 | return changed; |
718e3744 | 1094 | } |
1095 | ||
1096 | ||
1097 | void | |
68980084 | 1098 | ospf_vl_up_check (struct ospf_area *area, struct in_addr rid, |
718e3744 | 1099 | struct vertex *v) |
1100 | { | |
68980084 | 1101 | struct ospf *ospf = area->ospf; |
52dc7ee6 | 1102 | struct listnode *node; |
718e3744 | 1103 | struct ospf_vl_data *vl_data; |
1104 | struct ospf_interface *oi; | |
1105 | ||
1106 | if (IS_DEBUG_OSPF_EVENT) | |
1107 | { | |
60925303 | 1108 | zlog_debug ("ospf_vl_up_check(): Start"); |
1109 | zlog_debug ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid)); | |
1110 | zlog_debug ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id)); | |
718e3744 | 1111 | } |
1112 | ||
1eb8ef25 | 1113 | for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data)) |
718e3744 | 1114 | { |
718e3744 | 1115 | if (IS_DEBUG_OSPF_EVENT) |
1116 | { | |
9c27ef9b PJ |
1117 | zlog_debug ("%s: considering VL, %s in area %s", __func__, |
1118 | vl_data->vl_oi->ifp->name, | |
1119 | inet_ntoa (vl_data->vl_area_id)); | |
1120 | zlog_debug ("%s: peer ID: %s", __func__, | |
718e3744 | 1121 | inet_ntoa (vl_data->vl_peer)); |
1122 | } | |
1123 | ||
1124 | if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) && | |
1125 | IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) | |
1126 | { | |
1127 | oi = vl_data->vl_oi; | |
1128 | SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED); | |
1129 | ||
1130 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 1131 | zlog_debug ("ospf_vl_up_check(): this VL matched"); |
718e3744 | 1132 | |
1133 | if (oi->state == ISM_Down) | |
1134 | { | |
1135 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 1136 | zlog_debug ("ospf_vl_up_check(): VL is down, waking it up"); |
718e3744 | 1137 | SET_FLAG (oi->ifp->flags, IFF_UP); |
2e6b0bbb | 1138 | OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp); |
718e3744 | 1139 | } |
1140 | ||
2e6b0bbb | 1141 | if (ospf_vl_set_params (vl_data, v)) |
1142 | { | |
1143 | if (IS_DEBUG_OSPF (ism, ISM_EVENTS)) | |
60925303 | 1144 | zlog_debug ("ospf_vl_up_check: VL cost change," |
cd59da68 | 1145 | " scheduling router lsa refresh"); |
c363d386 PJ |
1146 | if (ospf->backbone) |
1147 | ospf_router_lsa_update_area (ospf->backbone); | |
2e6b0bbb | 1148 | else if (IS_DEBUG_OSPF (ism, ISM_EVENTS)) |
60925303 | 1149 | zlog_debug ("ospf_vl_up_check: VL cost change, no backbone!"); |
2e6b0bbb | 1150 | } |
718e3744 | 1151 | } |
1152 | } | |
1153 | } | |
1154 | ||
1155 | void | |
68980084 | 1156 | ospf_vl_unapprove (struct ospf *ospf) |
718e3744 | 1157 | { |
52dc7ee6 | 1158 | struct listnode *node; |
718e3744 | 1159 | struct ospf_vl_data *vl_data; |
1160 | ||
1eb8ef25 | 1161 | for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data)) |
1162 | UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED); | |
718e3744 | 1163 | } |
1164 | ||
1165 | void | |
68980084 | 1166 | ospf_vl_shut_unapproved (struct ospf *ospf) |
718e3744 | 1167 | { |
1eb8ef25 | 1168 | struct listnode *node, *nnode; |
718e3744 | 1169 | struct ospf_vl_data *vl_data; |
1170 | ||
1eb8ef25 | 1171 | for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data)) |
1172 | if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED)) | |
1173 | ospf_vl_shutdown (vl_data); | |
718e3744 | 1174 | } |
1175 | ||
1176 | int | |
1177 | ospf_full_virtual_nbrs (struct ospf_area *area) | |
1178 | { | |
1179 | if (IS_DEBUG_OSPF_EVENT) | |
1180 | { | |
60925303 | 1181 | zlog_debug ("counting fully adjacent virtual neighbors in area %s", |
718e3744 | 1182 | inet_ntoa (area->area_id)); |
60925303 | 1183 | zlog_debug ("there are %d of them", area->full_vls); |
718e3744 | 1184 | } |
1185 | ||
1186 | return area->full_vls; | |
1187 | } | |
1188 | ||
1189 | int | |
1190 | ospf_vls_in_area (struct ospf_area *area) | |
1191 | { | |
52dc7ee6 | 1192 | struct listnode *node; |
718e3744 | 1193 | struct ospf_vl_data *vl_data; |
1194 | int c = 0; | |
1195 | ||
1eb8ef25 | 1196 | for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data)) |
1197 | if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) | |
1198 | c++; | |
718e3744 | 1199 | |
1200 | return c; | |
1201 | } | |
1202 | ||
6b0655a2 | 1203 | |
718e3744 | 1204 | struct crypt_key * |
1205 | ospf_crypt_key_new () | |
1206 | { | |
393deb9b | 1207 | return XCALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key)); |
718e3744 | 1208 | } |
1209 | ||
1210 | void | |
52dc7ee6 | 1211 | ospf_crypt_key_add (struct list *crypt, struct crypt_key *ck) |
718e3744 | 1212 | { |
1213 | listnode_add (crypt, ck); | |
1214 | } | |
1215 | ||
1216 | struct crypt_key * | |
52dc7ee6 | 1217 | ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id) |
718e3744 | 1218 | { |
52dc7ee6 | 1219 | struct listnode *node; |
718e3744 | 1220 | struct crypt_key *ck; |
1221 | ||
1eb8ef25 | 1222 | for (ALL_LIST_ELEMENTS_RO (auth_crypt, node, ck)) |
1223 | if (ck->key_id == key_id) | |
1224 | return ck; | |
718e3744 | 1225 | |
1226 | return NULL; | |
1227 | } | |
1228 | ||
1229 | int | |
52dc7ee6 | 1230 | ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id) |
718e3744 | 1231 | { |
1eb8ef25 | 1232 | struct listnode *node, *nnode; |
718e3744 | 1233 | struct crypt_key *ck; |
1234 | ||
1eb8ef25 | 1235 | for (ALL_LIST_ELEMENTS (auth_crypt, node, nnode, ck)) |
718e3744 | 1236 | { |
718e3744 | 1237 | if (ck->key_id == key_id) |
1238 | { | |
1239 | listnode_delete (auth_crypt, ck); | |
ba682537 | 1240 | XFREE (MTYPE_OSPF_CRYPT_KEY, ck); |
718e3744 | 1241 | return 1; |
1242 | } | |
1243 | } | |
1244 | ||
1245 | return 0; | |
1246 | } | |
1247 | ||
bc18d616 | 1248 | u_char |
1249 | ospf_default_iftype(struct interface *ifp) | |
1250 | { | |
1251 | if (if_is_pointopoint (ifp)) | |
1252 | return OSPF_IFTYPE_POINTOPOINT; | |
1253 | else if (if_is_loopback (ifp)) | |
1254 | return OSPF_IFTYPE_LOOPBACK; | |
1255 | else | |
1256 | return OSPF_IFTYPE_BROADCAST; | |
1257 | } | |
1258 | ||
718e3744 | 1259 | void |
1260 | ospf_if_init () | |
1261 | { | |
1262 | /* Initialize Zebra interface data structure. */ | |
b2d7c082 | 1263 | om->iflist = vrf_iflist (VRF_DEFAULT); |
718e3744 | 1264 | if_add_hook (IF_NEW_HOOK, ospf_if_new_hook); |
1265 | if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook); | |
1266 | } |