]>
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 | ||
52 | \f | |
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; | |
100 | ospf_router_lsa_timer_add (oi->area); | |
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 */ |
4dadc291 | 148 | static 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 | |
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); | |
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 | #ifdef HAVE_OPAQUE_LSA |
248 | ospf_opaque_type9_lsa_init (oi); | |
249 | #endif /* HAVE_OPAQUE_LSA */ | |
250 | ||
68980084 | 251 | oi->ospf = ospf; |
718e3744 | 252 | |
253 | return oi; | |
254 | } | |
255 | ||
256 | /* Restore an interface to its pre UP state | |
257 | Used from ism_interface_down only */ | |
258 | void | |
259 | ospf_if_cleanup (struct ospf_interface *oi) | |
260 | { | |
261 | struct route_node *rn; | |
1eb8ef25 | 262 | struct listnode *node, *nnode; |
718e3744 | 263 | struct ospf_neighbor *nbr; |
1eb8ef25 | 264 | struct ospf_nbr_nbma *nbr_nbma; |
265 | struct ospf_lsa *lsa; | |
718e3744 | 266 | |
1a643f88 | 267 | /* oi->nbrs and oi->nbr_nbma should be deleted on InterfaceDown event */ |
718e3744 | 268 | /* delete all static neighbors attached to this interface */ |
1eb8ef25 | 269 | for (ALL_LIST_ELEMENTS (oi->nbr_nbma, node, nnode, nbr_nbma)) |
718e3744 | 270 | { |
718e3744 | 271 | 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. */ | |
1eb8ef25 | 291 | for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa)) |
292 | ospf_lsa_unlock (lsa); | |
718e3744 | 293 | 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 | ||
1a643f88 | 300 | /* Reset pseudo neighbor. */ |
718e3744 | 301 | ospf_nbr_delete (oi->nbr_self); |
302 | oi->nbr_self = ospf_nbr_new (oi); | |
1a643f88 | 303 | ospf_nbr_add_self (oi); |
304 | ||
718e3744 | 305 | ospf_lsa_unlock (oi->network_lsa_self); |
306 | oi->network_lsa_self = NULL; | |
307 | OSPF_TIMER_OFF (oi->t_network_lsa_self); | |
308 | } | |
309 | ||
310 | void | |
311 | ospf_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 | ||
68980084 | 335 | listnode_delete (oi->ospf->oiflist, oi); |
718e3744 | 336 | listnode_delete (oi->area->oiflist, oi); |
337 | ||
338 | memset (oi, 0, sizeof (*oi)); | |
339 | XFREE (MTYPE_OSPF_IF, oi); | |
340 | } | |
341 | ||
342 | \f | |
343 | /* | |
344 | * check if interface with given address is configured and | |
3fb9cd6e | 345 | * return it if yes. special treatment for PtP networks. |
718e3744 | 346 | */ |
347 | struct ospf_interface * | |
68980084 | 348 | ospf_if_is_configured (struct ospf *ospf, struct in_addr *address) |
718e3744 | 349 | { |
1eb8ef25 | 350 | struct listnode *node, *nnode; |
718e3744 | 351 | struct ospf_interface *oi; |
3fb9cd6e | 352 | struct prefix_ipv4 addr; |
353 | ||
354 | addr.family = AF_INET; | |
355 | addr.prefix = *address; | |
356 | addr.prefixlen = IPV4_MAX_PREFIXLEN; | |
718e3744 | 357 | |
1eb8ef25 | 358 | for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi)) |
359 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) | |
718e3744 | 360 | { |
361 | if (oi->type == OSPF_IFTYPE_POINTOPOINT) | |
3fb9cd6e | 362 | { |
363 | if (CONNECTED_DEST_HOST(oi->connected)) | |
364 | { | |
365 | /* match only destination addr, since local addr is most likely | |
366 | * not unique (borrowed from another interface) */ | |
367 | if (IPV4_ADDR_SAME (address, | |
368 | &oi->connected->destination->u.prefix4)) | |
369 | return oi; | |
370 | } | |
371 | else | |
372 | { | |
373 | /* special leniency: match if addr is anywhere on PtP subnet */ | |
374 | if (prefix_match(oi->address,(struct prefix *)&addr)) | |
375 | return oi; | |
376 | } | |
377 | } | |
718e3744 | 378 | else |
3fb9cd6e | 379 | { |
380 | if (IPV4_ADDR_SAME (address, &oi->address->u.prefix4)) | |
381 | return oi; | |
382 | } | |
718e3744 | 383 | } |
718e3744 | 384 | return NULL; |
385 | } | |
386 | ||
387 | int | |
388 | ospf_if_is_up (struct ospf_interface *oi) | |
389 | { | |
390 | return if_is_up (oi->ifp); | |
391 | } | |
392 | ||
2db3d05d | 393 | struct ospf_interface * |
394 | ospf_if_exists (struct ospf_interface *oic) | |
395 | { | |
52dc7ee6 | 396 | struct listnode *node; |
2db3d05d | 397 | struct ospf *ospf; |
398 | struct ospf_interface *oi; | |
399 | ||
400 | ospf = ospf_lookup (); | |
401 | ||
1eb8ef25 | 402 | for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) |
403 | if (oi == oic) | |
2db3d05d | 404 | return oi; |
1eb8ef25 | 405 | |
2db3d05d | 406 | return NULL; |
407 | } | |
408 | ||
718e3744 | 409 | struct ospf_interface * |
68980084 | 410 | ospf_if_lookup_by_local_addr (struct ospf *ospf, |
411 | struct interface *ifp, struct in_addr address) | |
718e3744 | 412 | { |
52dc7ee6 | 413 | struct listnode *node; |
718e3744 | 414 | struct ospf_interface *oi; |
415 | ||
1eb8ef25 | 416 | for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) |
417 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) | |
718e3744 | 418 | { |
419 | if (ifp && oi->ifp != ifp) | |
420 | continue; | |
421 | ||
422 | if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4)) | |
423 | return oi; | |
424 | } | |
425 | ||
426 | return NULL; | |
427 | } | |
428 | ||
429 | struct ospf_interface * | |
68980084 | 430 | ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p) |
718e3744 | 431 | { |
52dc7ee6 | 432 | struct listnode *node; |
718e3744 | 433 | struct ospf_interface *oi; |
434 | struct prefix ptmp; | |
435 | ||
436 | /* Check each Interface. */ | |
1eb8ef25 | 437 | for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) |
68980084 | 438 | { |
1eb8ef25 | 439 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) |
68980084 | 440 | { |
3fb9cd6e | 441 | if ((oi->type == OSPF_IFTYPE_POINTOPOINT) && |
442 | CONNECTED_DEST_HOST(oi->connected)) | |
68980084 | 443 | { |
444 | prefix_copy (&ptmp, oi->connected->destination); | |
445 | ptmp.prefixlen = IPV4_MAX_BITLEN; | |
446 | } | |
447 | else | |
448 | prefix_copy (&ptmp, oi->address); | |
718e3744 | 449 | |
68980084 | 450 | apply_mask (&ptmp); |
451 | if (prefix_same (&ptmp, (struct prefix *) p)) | |
452 | return oi; | |
453 | } | |
454 | } | |
718e3744 | 455 | return NULL; |
456 | } | |
457 | ||
458 | /* determine receiving interface by source of packet */ | |
459 | struct ospf_interface * | |
68980084 | 460 | ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src) |
718e3744 | 461 | { |
52dc7ee6 | 462 | struct listnode *node; |
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 | ||
1eb8ef25 | 472 | for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) |
718e3744 | 473 | { |
718e3744 | 474 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
475 | continue; | |
476 | ||
1a8ee0ec PJ |
477 | if (if_is_loopback (oi->ifp)) |
478 | continue; | |
479 | ||
3fb9cd6e | 480 | if ((oi->type == OSPF_IFTYPE_POINTOPOINT) && |
481 | CONNECTED_DEST_HOST(oi->connected)) | |
718e3744 | 482 | { |
483 | if (IPV4_ADDR_SAME (&oi->connected->destination->u.prefix4, &src)) | |
484 | return oi; | |
485 | } | |
486 | else | |
487 | { | |
488 | if (prefix_match (oi->address, (struct prefix *) &addr)) | |
0a825c79 | 489 | { |
af8d0336 | 490 | if ( (match == NULL) || |
491 | (match->address->prefixlen < oi->address->prefixlen) | |
492 | ) | |
0a825c79 | 493 | match = oi; |
494 | } | |
718e3744 | 495 | } |
496 | } | |
497 | ||
498 | return match; | |
499 | } | |
500 | \f | |
501 | void | |
502 | ospf_if_stream_set (struct ospf_interface *oi) | |
503 | { | |
504 | /* set output fifo queue. */ | |
505 | if (oi->obuf == NULL) | |
506 | oi->obuf = ospf_fifo_new (); | |
507 | } | |
508 | ||
509 | void | |
510 | ospf_if_stream_unset (struct ospf_interface *oi) | |
511 | { | |
68980084 | 512 | struct ospf *ospf = oi->ospf; |
513 | ||
718e3744 | 514 | if (oi->obuf) |
515 | { | |
516 | ospf_fifo_free (oi->obuf); | |
517 | oi->obuf = NULL; | |
518 | ||
519 | if (oi->on_write_q) | |
520 | { | |
68980084 | 521 | listnode_delete (ospf->oi_write_q, oi); |
522 | if (list_isempty(ospf->oi_write_q)) | |
523 | OSPF_TIMER_OFF (ospf->t_write); | |
718e3744 | 524 | oi->on_write_q = 0; |
525 | } | |
526 | } | |
527 | } | |
68980084 | 528 | |
718e3744 | 529 | \f |
4dadc291 | 530 | static struct ospf_if_params * |
531 | ospf_new_if_params (void) | |
718e3744 | 532 | { |
533 | struct ospf_if_params *oip; | |
534 | ||
535 | oip = XMALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params)); | |
718e3744 | 536 | |
537 | if (!oip) | |
538 | return NULL; | |
539 | ||
f645789b | 540 | memset (oip, 0, sizeof (struct ospf_if_params)); |
541 | ||
718e3744 | 542 | UNSET_IF_PARAM (oip, output_cost_cmd); |
543 | UNSET_IF_PARAM (oip, transmit_delay); | |
544 | UNSET_IF_PARAM (oip, retransmit_interval); | |
545 | UNSET_IF_PARAM (oip, passive_interface); | |
546 | UNSET_IF_PARAM (oip, v_hello); | |
f9ad937f | 547 | UNSET_IF_PARAM (oip, fast_hello); |
718e3744 | 548 | UNSET_IF_PARAM (oip, v_wait); |
549 | UNSET_IF_PARAM (oip, priority); | |
550 | UNSET_IF_PARAM (oip, type); | |
551 | UNSET_IF_PARAM (oip, auth_simple); | |
552 | UNSET_IF_PARAM (oip, auth_crypt); | |
553 | UNSET_IF_PARAM (oip, auth_type); | |
ec1ca63c | 554 | |
555 | oip->auth_crypt = list_new (); | |
718e3744 | 556 | |
718e3744 | 557 | return oip; |
558 | } | |
559 | ||
560 | void | |
561 | ospf_del_if_params (struct ospf_if_params *oip) | |
562 | { | |
563 | list_delete (oip->auth_crypt); | |
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) && | |
595 | listcount (oip->auth_crypt) == 0) | |
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 | ||
665 | ifp->info = XMALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info)); | |
666 | memset (ifp->info, 0, sizeof (struct ospf_if_info)); | |
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), passive_interface); |
685 | IF_DEF_PARAMS (ifp)->passive_interface = OSPF_IF_ACTIVE; | |
686 | ||
687 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello); | |
688 | IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
689 | ||
f9ad937f | 690 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), fast_hello); |
691 | IF_DEF_PARAMS (ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
692 | ||
718e3744 | 693 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait); |
694 | IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
695 | ||
696 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple); | |
697 | memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); | |
698 | ||
718e3744 | 699 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type); |
700 | IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET; | |
701 | ||
702 | #ifdef HAVE_OPAQUE_LSA | |
703 | rc = ospf_opaque_new_if (ifp); | |
704 | #endif /* HAVE_OPAQUE_LSA */ | |
705 | return rc; | |
706 | } | |
707 | ||
4dadc291 | 708 | static int |
718e3744 | 709 | ospf_if_delete_hook (struct interface *ifp) |
710 | { | |
711 | int rc = 0; | |
940b01aa | 712 | struct route_node *rn; |
718e3744 | 713 | #ifdef HAVE_OPAQUE_LSA |
714 | rc = ospf_opaque_del_if (ifp); | |
715 | #endif /* HAVE_OPAQUE_LSA */ | |
940b01aa | 716 | |
718e3744 | 717 | route_table_finish (IF_OIFS (ifp)); |
940b01aa | 718 | |
719 | for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn)) | |
720 | if (rn->info) | |
721 | ospf_del_if_params (rn->info); | |
718e3744 | 722 | route_table_finish (IF_OIFS_PARAMS (ifp)); |
940b01aa | 723 | |
cfc959b8 | 724 | ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp)); |
718e3744 | 725 | XFREE (MTYPE_OSPF_IF_INFO, ifp->info); |
726 | ifp->info = NULL; | |
727 | ||
728 | return rc; | |
729 | } | |
730 | ||
731 | int | |
732 | ospf_if_is_enable (struct ospf_interface *oi) | |
733 | { | |
734 | if (!if_is_loopback (oi->ifp)) | |
735 | if (if_is_up (oi->ifp)) | |
736 | return 1; | |
737 | ||
738 | return 0; | |
739 | } | |
740 | ||
ba6454ec | 741 | void |
742 | ospf_if_set_multicast(struct ospf_interface *oi) | |
743 | { | |
744 | if ((oi->state > ISM_Loopback) && | |
745 | (oi->type != OSPF_IFTYPE_LOOPBACK) && | |
746 | (oi->type != OSPF_IFTYPE_VIRTUALLINK) && | |
747 | (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE)) | |
748 | { | |
749 | /* The interface should belong to the OSPF-all-routers group. */ | |
750 | if (!CHECK_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS) && | |
751 | (ospf_if_add_allspfrouters(oi->ospf, oi->address, | |
752 | oi->ifp->ifindex) >= 0)) | |
753 | /* Set the flag only if the system call to join succeeded. */ | |
754 | SET_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS); | |
755 | } | |
756 | else | |
757 | { | |
758 | /* The interface should NOT belong to the OSPF-all-routers group. */ | |
759 | if (CHECK_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS)) | |
760 | { | |
761 | ospf_if_drop_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex); | |
762 | /* Unset the flag regardless of whether the system call to leave | |
763 | the group succeeded, since it's much safer to assume that | |
764 | we are not a member. */ | |
765 | UNSET_FLAG(oi->multicast_memberships, MEMBER_ALLROUTERS); | |
766 | } | |
767 | } | |
768 | ||
769 | if (((oi->type == OSPF_IFTYPE_BROADCAST) || | |
770 | (oi->type == OSPF_IFTYPE_POINTOPOINT)) && | |
771 | ((oi->state == ISM_DR) || (oi->state == ISM_Backup)) && | |
772 | (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE)) | |
773 | { | |
774 | /* The interface should belong to the OSPF-designated-routers group. */ | |
775 | if (!CHECK_FLAG(oi->multicast_memberships, MEMBER_DROUTERS) && | |
776 | (ospf_if_add_alldrouters(oi->ospf, oi->address, | |
777 | oi->ifp->ifindex) >= 0)) | |
778 | /* Set the flag only if the system call to join succeeded. */ | |
779 | SET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS); | |
780 | } | |
781 | else | |
782 | { | |
783 | /* The interface should NOT belong to the OSPF-designated-routers group */ | |
784 | if (CHECK_FLAG(oi->multicast_memberships, MEMBER_DROUTERS)) | |
785 | { | |
786 | ospf_if_drop_alldrouters(oi->ospf, oi->address, oi->ifp->ifindex); | |
787 | /* Unset the flag regardless of whether the system call to leave | |
788 | the group succeeded, since it's much safer to assume that | |
789 | we are not a member. */ | |
790 | UNSET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS); | |
791 | } | |
792 | } | |
793 | } | |
794 | ||
718e3744 | 795 | int |
796 | ospf_if_up (struct ospf_interface *oi) | |
797 | { | |
798 | if (oi == NULL) | |
799 | return 0; | |
800 | ||
801 | if (oi->type == OSPF_IFTYPE_LOOPBACK) | |
802 | OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd); | |
803 | else | |
804 | { | |
718e3744 | 805 | ospf_if_stream_set (oi); |
806 | OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp); | |
807 | } | |
808 | ||
809 | return 1; | |
810 | } | |
811 | ||
812 | int | |
813 | ospf_if_down (struct ospf_interface *oi) | |
814 | { | |
815 | if (oi == NULL) | |
816 | return 0; | |
817 | ||
818 | OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown); | |
819 | /* Shutdown packet reception and sending */ | |
820 | ospf_if_stream_unset (oi); | |
718e3744 | 821 | |
822 | return 1; | |
823 | } | |
824 | ||
825 | \f | |
826 | /* Virtual Link related functions. */ | |
827 | ||
828 | struct ospf_vl_data * | |
829 | ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer) | |
830 | { | |
831 | struct ospf_vl_data *vl_data; | |
832 | ||
833 | vl_data = XMALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data)); | |
834 | memset (vl_data, 0, sizeof (struct ospf_vl_data)); | |
835 | ||
836 | vl_data->vl_peer.s_addr = vl_peer.s_addr; | |
837 | vl_data->vl_area_id = area->area_id; | |
838 | vl_data->format = area->format; | |
839 | ||
840 | return vl_data; | |
841 | } | |
842 | ||
843 | void | |
844 | ospf_vl_data_free (struct ospf_vl_data *vl_data) | |
845 | { | |
846 | XFREE (MTYPE_OSPF_VL_DATA, vl_data); | |
847 | } | |
848 | ||
849 | u_int vlink_count = 0; | |
850 | ||
851 | struct ospf_interface * | |
68980084 | 852 | ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data) |
718e3744 | 853 | { |
854 | struct ospf_interface * voi; | |
855 | struct interface * vi; | |
856 | char ifname[INTERFACE_NAMSIZ + 1]; | |
857 | struct ospf_area *area; | |
858 | struct in_addr area_id; | |
859 | struct connected *co; | |
860 | struct prefix_ipv4 *p; | |
861 | ||
862 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 863 | zlog_debug ("ospf_vl_new(): Start"); |
718e3744 | 864 | if (vlink_count == OSPF_VL_MAX_COUNT) |
865 | { | |
866 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 867 | zlog_debug ("ospf_vl_new(): Alarm: " |
718e3744 | 868 | "cannot create more than OSPF_MAX_VL_COUNT virtual links"); |
869 | return NULL; | |
870 | } | |
871 | ||
872 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 873 | zlog_debug ("ospf_vl_new(): creating pseudo zebra interface"); |
718e3744 | 874 | |
a349198f | 875 | snprintf (ifname, sizeof(ifname), "VLINK%d", vlink_count); |
876 | vi = if_create (ifname, strnlen(ifname, sizeof(ifname))); | |
718e3744 | 877 | co = connected_new (); |
878 | co->ifp = vi; | |
879 | listnode_add (vi->connected, co); | |
880 | ||
881 | p = prefix_ipv4_new (); | |
882 | p->family = AF_INET; | |
883 | p->prefix.s_addr = 0; | |
884 | p->prefixlen = 0; | |
885 | ||
886 | co->address = (struct prefix *)p; | |
887 | ||
68980084 | 888 | voi = ospf_if_new (ospf, vi, co->address); |
718e3744 | 889 | if (voi == NULL) |
890 | { | |
891 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 892 | zlog_debug ("ospf_vl_new(): Alarm: OSPF int structure is not created"); |
718e3744 | 893 | return NULL; |
894 | } | |
895 | voi->connected = co; | |
896 | voi->vl_data = vl_data; | |
897 | voi->ifp->mtu = OSPF_VL_MTU; | |
898 | voi->type = OSPF_IFTYPE_VIRTUALLINK; | |
899 | ||
106d2fd5 | 900 | vlink_count++; |
718e3744 | 901 | if (IS_DEBUG_OSPF_EVENT) |
60925303 | 902 | zlog_debug ("ospf_vl_new(): Created name: %s", ifname); |
718e3744 | 903 | if (IS_DEBUG_OSPF_EVENT) |
60925303 | 904 | zlog_debug ("ospf_vl_new(): set if->name to %s", vi->name); |
718e3744 | 905 | |
906 | area_id.s_addr = 0; | |
68980084 | 907 | area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS); |
718e3744 | 908 | voi->area = area; |
909 | ||
910 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 911 | zlog_debug ("ospf_vl_new(): set associated area to the backbone"); |
718e3744 | 912 | |
913 | ospf_area_add_if (voi->area, voi); | |
914 | ||
915 | ospf_if_stream_set (voi); | |
916 | ||
917 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 918 | zlog_debug ("ospf_vl_new(): Stop"); |
718e3744 | 919 | return voi; |
920 | } | |
921 | ||
4dadc291 | 922 | static void |
718e3744 | 923 | ospf_vl_if_delete (struct ospf_vl_data *vl_data) |
924 | { | |
925 | struct interface *ifp = vl_data->vl_oi->ifp; | |
926 | vl_data->vl_oi->address->u.prefix4.s_addr = 0; | |
927 | vl_data->vl_oi->address->prefixlen = 0; | |
928 | ospf_if_free (vl_data->vl_oi); | |
929 | if_delete (ifp); | |
930 | vlink_count--; | |
931 | } | |
932 | ||
933 | struct ospf_vl_data * | |
934 | ospf_vl_lookup (struct ospf_area *area, struct in_addr vl_peer) | |
935 | { | |
936 | struct ospf_vl_data *vl_data; | |
52dc7ee6 | 937 | struct listnode *node; |
718e3744 | 938 | |
1eb8ef25 | 939 | for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data)) |
940 | if (vl_data->vl_peer.s_addr == vl_peer.s_addr && | |
941 | IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) | |
942 | return vl_data; | |
718e3744 | 943 | |
944 | return NULL; | |
945 | } | |
946 | ||
4dadc291 | 947 | static void |
718e3744 | 948 | ospf_vl_shutdown (struct ospf_vl_data *vl_data) |
949 | { | |
950 | struct ospf_interface *oi; | |
951 | ||
952 | if ((oi = vl_data->vl_oi) == NULL) | |
953 | return; | |
954 | ||
955 | oi->address->u.prefix4.s_addr = 0; | |
956 | oi->address->prefixlen = 0; | |
957 | ||
958 | UNSET_FLAG (oi->ifp->flags, IFF_UP); | |
959 | /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */ | |
960 | OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown); | |
961 | } | |
962 | ||
963 | void | |
68980084 | 964 | ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data) |
718e3744 | 965 | { |
68980084 | 966 | listnode_add (ospf->vlinks, vl_data); |
718e3744 | 967 | #ifdef HAVE_SNMP |
968 | ospf_snmp_vl_add (vl_data); | |
969 | #endif /* HAVE_SNMP */ | |
970 | } | |
971 | ||
972 | void | |
68980084 | 973 | ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data) |
718e3744 | 974 | { |
975 | ospf_vl_shutdown (vl_data); | |
976 | ospf_vl_if_delete (vl_data); | |
977 | ||
978 | #ifdef HAVE_SNMP | |
979 | ospf_snmp_vl_delete (vl_data); | |
980 | #endif /* HAVE_SNMP */ | |
68980084 | 981 | listnode_delete (ospf->vlinks, vl_data); |
718e3744 | 982 | |
983 | ospf_vl_data_free (vl_data); | |
984 | } | |
985 | ||
4dadc291 | 986 | static int |
718e3744 | 987 | ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v) |
988 | { | |
989 | int changed = 0; | |
990 | struct ospf_interface *voi; | |
52dc7ee6 | 991 | struct listnode *node; |
eb3da6df | 992 | struct vertex_parent *vp = NULL; |
718e3744 | 993 | int i; |
994 | struct router_lsa *rl; | |
995 | ||
996 | voi = vl_data->vl_oi; | |
997 | ||
998 | if (voi->output_cost != v->distance) | |
999 | { | |
cd59da68 | 1000 | |
718e3744 | 1001 | voi->output_cost = v->distance; |
1002 | changed = 1; | |
1003 | } | |
1004 | ||
eb3da6df | 1005 | for (ALL_LIST_ELEMENTS_RO (v->parents, node, vp)) |
1eb8ef25 | 1006 | { |
eb3da6df | 1007 | vl_data->out_oi = vp->nexthop->oi; |
1eb8ef25 | 1008 | |
1009 | if (!IPV4_ADDR_SAME(&voi->address->u.prefix4, | |
1010 | &vl_data->out_oi->address->u.prefix4)) | |
1011 | changed = 1; | |
cd59da68 | 1012 | |
1eb8ef25 | 1013 | voi->address->u.prefix4 = vl_data->out_oi->address->u.prefix4; |
1014 | voi->address->prefixlen = vl_data->out_oi->address->prefixlen; | |
1015 | ||
1016 | break; /* We take the first interface. */ | |
1017 | } | |
718e3744 | 1018 | |
1019 | rl = (struct router_lsa *)v->lsa; | |
d355bfa7 | 1020 | |
1021 | /* use SPF determined backlink index in struct vertex | |
1022 | * for virtual link destination address | |
1023 | */ | |
eb3da6df | 1024 | if (vp && vp->backlink >= 0) |
d355bfa7 | 1025 | { |
1026 | if (!IPV4_ADDR_SAME (&vl_data->peer_addr, | |
eb3da6df | 1027 | &rl->link[vp->backlink].link_data)) |
d355bfa7 | 1028 | changed = 1; |
eb3da6df | 1029 | vl_data->peer_addr = rl->link[vp->backlink].link_data; |
d355bfa7 | 1030 | } |
1031 | else | |
718e3744 | 1032 | { |
d355bfa7 | 1033 | /* This is highly odd, there is no backlink index |
1034 | * there should be due to the ospf_spf_has_link() check | |
1035 | * in SPF. Lets warn and try pick a link anyway. | |
1036 | */ | |
1037 | zlog_warn ("ospf_vl_set_params: No backlink for %s!", | |
1038 | vl_data->vl_oi->ifp->name); | |
1039 | for (i = 0; i < ntohs (rl->links); i++) | |
2e6b0bbb | 1040 | { |
d355bfa7 | 1041 | switch (rl->link[i].type) |
1042 | { | |
1043 | case LSA_LINK_TYPE_VIRTUALLINK: | |
1044 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 1045 | zlog_debug ("found back link through VL"); |
d355bfa7 | 1046 | case LSA_LINK_TYPE_TRANSIT: |
1047 | case LSA_LINK_TYPE_POINTOPOINT: | |
cd59da68 | 1048 | if (!IPV4_ADDR_SAME (&vl_data->peer_addr, |
1049 | &rl->link[i].link_data)) | |
1050 | changed = 1; | |
d355bfa7 | 1051 | vl_data->peer_addr = rl->link[i].link_data; |
1052 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 1053 | zlog_debug ("ospf_vl_set_params: %s peer address is %s\n", |
d355bfa7 | 1054 | vl_data->vl_oi->ifp->name, |
1055 | inet_ntoa(vl_data->peer_addr)); | |
1056 | return changed; | |
1057 | } | |
2e6b0bbb | 1058 | } |
718e3744 | 1059 | } |
d355bfa7 | 1060 | |
1061 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 1062 | zlog_debug ("ospf_vl_set_params: %s peer address is %s\n", |
d355bfa7 | 1063 | vl_data->vl_oi->ifp->name, |
1064 | inet_ntoa(vl_data->peer_addr)); | |
1065 | ||
2e6b0bbb | 1066 | return changed; |
718e3744 | 1067 | } |
1068 | ||
1069 | ||
1070 | void | |
68980084 | 1071 | ospf_vl_up_check (struct ospf_area *area, struct in_addr rid, |
718e3744 | 1072 | struct vertex *v) |
1073 | { | |
68980084 | 1074 | struct ospf *ospf = area->ospf; |
52dc7ee6 | 1075 | struct listnode *node; |
718e3744 | 1076 | struct ospf_vl_data *vl_data; |
1077 | struct ospf_interface *oi; | |
1078 | ||
1079 | if (IS_DEBUG_OSPF_EVENT) | |
1080 | { | |
60925303 | 1081 | zlog_debug ("ospf_vl_up_check(): Start"); |
1082 | zlog_debug ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid)); | |
1083 | zlog_debug ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id)); | |
718e3744 | 1084 | } |
1085 | ||
1eb8ef25 | 1086 | for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data)) |
718e3744 | 1087 | { |
718e3744 | 1088 | if (IS_DEBUG_OSPF_EVENT) |
1089 | { | |
60925303 | 1090 | zlog_debug ("ospf_vl_up_check(): considering VL, name: %s", |
718e3744 | 1091 | vl_data->vl_oi->ifp->name); |
60925303 | 1092 | zlog_debug ("ospf_vl_up_check(): VL area: %s, peer ID: %s", |
718e3744 | 1093 | inet_ntoa (vl_data->vl_area_id), |
1094 | inet_ntoa (vl_data->vl_peer)); | |
1095 | } | |
1096 | ||
1097 | if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) && | |
1098 | IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) | |
1099 | { | |
1100 | oi = vl_data->vl_oi; | |
1101 | SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED); | |
1102 | ||
1103 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 1104 | zlog_debug ("ospf_vl_up_check(): this VL matched"); |
718e3744 | 1105 | |
1106 | if (oi->state == ISM_Down) | |
1107 | { | |
1108 | if (IS_DEBUG_OSPF_EVENT) | |
60925303 | 1109 | zlog_debug ("ospf_vl_up_check(): VL is down, waking it up"); |
718e3744 | 1110 | SET_FLAG (oi->ifp->flags, IFF_UP); |
2e6b0bbb | 1111 | OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp); |
718e3744 | 1112 | } |
1113 | ||
2e6b0bbb | 1114 | if (ospf_vl_set_params (vl_data, v)) |
1115 | { | |
1116 | if (IS_DEBUG_OSPF (ism, ISM_EVENTS)) | |
60925303 | 1117 | zlog_debug ("ospf_vl_up_check: VL cost change," |
cd59da68 | 1118 | " scheduling router lsa refresh"); |
2e6b0bbb | 1119 | if(ospf->backbone) |
cd59da68 | 1120 | ospf_router_lsa_timer_add (ospf->backbone); |
2e6b0bbb | 1121 | else if (IS_DEBUG_OSPF (ism, ISM_EVENTS)) |
60925303 | 1122 | zlog_debug ("ospf_vl_up_check: VL cost change, no backbone!"); |
2e6b0bbb | 1123 | } |
718e3744 | 1124 | } |
1125 | } | |
1126 | } | |
1127 | ||
1128 | void | |
68980084 | 1129 | ospf_vl_unapprove (struct ospf *ospf) |
718e3744 | 1130 | { |
52dc7ee6 | 1131 | struct listnode *node; |
718e3744 | 1132 | struct ospf_vl_data *vl_data; |
1133 | ||
1eb8ef25 | 1134 | for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data)) |
1135 | UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED); | |
718e3744 | 1136 | } |
1137 | ||
1138 | void | |
68980084 | 1139 | ospf_vl_shut_unapproved (struct ospf *ospf) |
718e3744 | 1140 | { |
1eb8ef25 | 1141 | struct listnode *node, *nnode; |
718e3744 | 1142 | struct ospf_vl_data *vl_data; |
1143 | ||
1eb8ef25 | 1144 | for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data)) |
1145 | if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED)) | |
1146 | ospf_vl_shutdown (vl_data); | |
718e3744 | 1147 | } |
1148 | ||
1149 | int | |
1150 | ospf_full_virtual_nbrs (struct ospf_area *area) | |
1151 | { | |
1152 | if (IS_DEBUG_OSPF_EVENT) | |
1153 | { | |
60925303 | 1154 | zlog_debug ("counting fully adjacent virtual neighbors in area %s", |
718e3744 | 1155 | inet_ntoa (area->area_id)); |
60925303 | 1156 | zlog_debug ("there are %d of them", area->full_vls); |
718e3744 | 1157 | } |
1158 | ||
1159 | return area->full_vls; | |
1160 | } | |
1161 | ||
1162 | int | |
1163 | ospf_vls_in_area (struct ospf_area *area) | |
1164 | { | |
52dc7ee6 | 1165 | struct listnode *node; |
718e3744 | 1166 | struct ospf_vl_data *vl_data; |
1167 | int c = 0; | |
1168 | ||
1eb8ef25 | 1169 | for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data)) |
1170 | if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) | |
1171 | c++; | |
718e3744 | 1172 | |
1173 | return c; | |
1174 | } | |
1175 | ||
1176 | \f | |
1177 | struct crypt_key * | |
1178 | ospf_crypt_key_new () | |
1179 | { | |
1180 | struct crypt_key *ck; | |
1181 | ||
1182 | ck = XMALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key)); | |
1183 | memset (ck, 0, sizeof (struct crypt_key)); | |
1184 | ||
1185 | return ck; | |
1186 | } | |
1187 | ||
1188 | void | |
52dc7ee6 | 1189 | ospf_crypt_key_add (struct list *crypt, struct crypt_key *ck) |
718e3744 | 1190 | { |
1191 | listnode_add (crypt, ck); | |
1192 | } | |
1193 | ||
1194 | struct crypt_key * | |
52dc7ee6 | 1195 | ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id) |
718e3744 | 1196 | { |
52dc7ee6 | 1197 | struct listnode *node; |
718e3744 | 1198 | struct crypt_key *ck; |
1199 | ||
1eb8ef25 | 1200 | for (ALL_LIST_ELEMENTS_RO (auth_crypt, node, ck)) |
1201 | if (ck->key_id == key_id) | |
1202 | return ck; | |
718e3744 | 1203 | |
1204 | return NULL; | |
1205 | } | |
1206 | ||
1207 | int | |
52dc7ee6 | 1208 | ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id) |
718e3744 | 1209 | { |
1eb8ef25 | 1210 | struct listnode *node, *nnode; |
718e3744 | 1211 | struct crypt_key *ck; |
1212 | ||
1eb8ef25 | 1213 | for (ALL_LIST_ELEMENTS (auth_crypt, node, nnode, ck)) |
718e3744 | 1214 | { |
718e3744 | 1215 | if (ck->key_id == key_id) |
1216 | { | |
1217 | listnode_delete (auth_crypt, ck); | |
ba682537 | 1218 | XFREE (MTYPE_OSPF_CRYPT_KEY, ck); |
718e3744 | 1219 | return 1; |
1220 | } | |
1221 | } | |
1222 | ||
1223 | return 0; | |
1224 | } | |
1225 | ||
bc18d616 | 1226 | u_char |
1227 | ospf_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 | ||
718e3744 | 1237 | void |
1238 | ospf_if_init () | |
1239 | { | |
1240 | /* Initialize Zebra interface data structure. */ | |
1241 | if_init (); | |
020709f9 | 1242 | om->iflist = iflist; |
718e3744 | 1243 | if_add_hook (IF_NEW_HOOK, ospf_if_new_hook); |
1244 | if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook); | |
1245 | } |