]>
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. | |
896014f4 | 6 | * |
718e3744 | 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 | * | |
896014f4 DL |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 20 | */ |
21 | ||
22 | #include <zebra.h> | |
23 | ||
24 | #include "thread.h" | |
25 | #include "linklist.h" | |
26 | #include "prefix.h" | |
27 | #include "if.h" | |
28 | #include "table.h" | |
29 | #include "memory.h" | |
30 | #include "command.h" | |
31 | #include "stream.h" | |
32 | #include "log.h" | |
c0325cfa | 33 | #include "zclient.h" |
7f342629 | 34 | #include "bfd.h" |
132a782e | 35 | #include "ldp_sync.h" |
718e3744 | 36 | |
68980084 | 37 | #include "ospfd/ospfd.h" |
659f4e40 | 38 | #include "ospfd/ospf_bfd.h" |
718e3744 | 39 | #include "ospfd/ospf_spf.h" |
40 | #include "ospfd/ospf_interface.h" | |
41 | #include "ospfd/ospf_ism.h" | |
42 | #include "ospfd/ospf_asbr.h" | |
43 | #include "ospfd/ospf_lsa.h" | |
44 | #include "ospfd/ospf_lsdb.h" | |
45 | #include "ospfd/ospf_neighbor.h" | |
46 | #include "ospfd/ospf_nsm.h" | |
47 | #include "ospfd/ospf_packet.h" | |
48 | #include "ospfd/ospf_abr.h" | |
718e3744 | 49 | #include "ospfd/ospf_network.h" |
50 | #include "ospfd/ospf_dump.h" | |
132a782e | 51 | #include "ospfd/ospf_ldp_sync.h" |
effee187 | 52 | #include "ospfd/ospf_route.h" |
0b4124c1 | 53 | #include "ospfd/ospf_te.h" |
718e3744 | 54 | |
96244aca | 55 | DEFINE_QOBJ_TYPE(ospf_interface); |
8451921b DL |
56 | DEFINE_HOOK(ospf_vl_add, (struct ospf_vl_data * vd), (vd)); |
57 | DEFINE_HOOK(ospf_vl_delete, (struct ospf_vl_data * vd), (vd)); | |
58 | DEFINE_HOOK(ospf_if_update, (struct interface * ifp), (ifp)); | |
59 | DEFINE_HOOK(ospf_if_delete, (struct interface * ifp), (ifp)); | |
6b0655a2 | 60 | |
2bc7673f CS |
61 | int ospf_interface_neighbor_count(struct ospf_interface *oi) |
62 | { | |
63 | int count = 0; | |
64 | struct route_node *rn; | |
65 | struct ospf_neighbor *nbr = NULL; | |
66 | ||
67 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
68 | nbr = rn->info; | |
69 | if (nbr) { | |
70 | /* Do not show myself. */ | |
71 | if (nbr == oi->nbr_self) | |
72 | continue; | |
73 | /* Down state is not shown. */ | |
74 | if (nbr->state == NSM_Down) | |
75 | continue; | |
76 | count++; | |
77 | } | |
78 | } | |
79 | ||
80 | return count; | |
81 | } | |
82 | ||
d62a17ae | 83 | int ospf_if_get_output_cost(struct ospf_interface *oi) |
718e3744 | 84 | { |
d62a17ae | 85 | /* If all else fails, use default OSPF cost */ |
d7c0a89a QY |
86 | uint32_t cost; |
87 | uint32_t bw, refbw; | |
d62a17ae | 88 | |
132a782e | 89 | /* if LDP-IGP Sync is running on interface set cost so interface |
90 | * is used only as last resort | |
91 | */ | |
92 | if (ldp_sync_if_is_enabled(IF_DEF_PARAMS(oi->ifp)->ldp_sync_info)) | |
93 | return (LDP_OSPF_LSINFINITY); | |
94 | ||
d62a17ae | 95 | /* ifp speed and bw can be 0 in some platforms, use ospf default bw |
96 | if bw is configured under interface it would be used. | |
97 | */ | |
98 | if (!oi->ifp->bandwidth && oi->ifp->speed) | |
99 | bw = oi->ifp->speed; | |
100 | else | |
101 | bw = oi->ifp->bandwidth ? oi->ifp->bandwidth | |
102 | : OSPF_DEFAULT_BANDWIDTH; | |
103 | refbw = oi->ospf->ref_bandwidth; | |
104 | ||
105 | /* A specifed ip ospf cost overrides a calculated one. */ | |
106 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), output_cost_cmd) | |
107 | || OSPF_IF_PARAM_CONFIGURED(oi->params, output_cost_cmd)) | |
108 | cost = OSPF_IF_PARAM(oi, output_cost_cmd); | |
109 | /* See if a cost can be calculated from the zebra processes | |
110 | interface bandwidth field. */ | |
111 | else { | |
d7c0a89a | 112 | cost = (uint32_t)((double)refbw / (double)bw + (double)0.5); |
d62a17ae | 113 | if (cost < 1) |
114 | cost = 1; | |
115 | else if (cost > 65535) | |
116 | cost = 65535; | |
117 | } | |
118 | ||
119 | return cost; | |
718e3744 | 120 | } |
121 | ||
d62a17ae | 122 | void ospf_if_recalculate_output_cost(struct interface *ifp) |
718e3744 | 123 | { |
d7c0a89a | 124 | uint32_t newcost; |
d62a17ae | 125 | struct route_node *rn; |
126 | ||
127 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
128 | struct ospf_interface *oi; | |
129 | ||
130 | if ((oi = rn->info) == NULL) | |
131 | continue; | |
132 | ||
133 | newcost = ospf_if_get_output_cost(oi); | |
134 | ||
135 | /* Is actual output cost changed? */ | |
136 | if (oi->output_cost != newcost) { | |
137 | oi->output_cost = newcost; | |
138 | ospf_router_lsa_update_area(oi->area); | |
139 | } | |
718e3744 | 140 | } |
718e3744 | 141 | } |
142 | ||
d62a17ae | 143 | /* Simulate down/up on the interface. This is needed, for example, when |
a608bbf2 | 144 | the MTU changes. */ |
d62a17ae | 145 | void ospf_if_reset(struct interface *ifp) |
a608bbf2 | 146 | { |
d62a17ae | 147 | struct route_node *rn; |
148 | ||
149 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
150 | struct ospf_interface *oi; | |
151 | ||
152 | if ((oi = rn->info) == NULL) | |
153 | continue; | |
154 | ||
155 | ospf_if_down(oi); | |
156 | ospf_if_up(oi); | |
157 | } | |
a608bbf2 | 158 | } |
159 | ||
d62a17ae | 160 | void ospf_if_reset_variables(struct ospf_interface *oi) |
718e3744 | 161 | { |
d62a17ae | 162 | /* Set default values. */ |
163 | /* don't clear this flag. oi->flag = OSPF_IF_DISABLE; */ | |
718e3744 | 164 | |
d62a17ae | 165 | if (oi->vl_data) |
166 | oi->type = OSPF_IFTYPE_VIRTUALLINK; | |
167 | else | |
168 | /* preserve network-type */ | |
169 | if (oi->type != OSPF_IFTYPE_NBMA) | |
170 | oi->type = OSPF_IFTYPE_BROADCAST; | |
718e3744 | 171 | |
d62a17ae | 172 | oi->state = ISM_Down; |
718e3744 | 173 | |
d62a17ae | 174 | oi->crypt_seqnum = 0; |
718e3744 | 175 | |
d62a17ae | 176 | /* This must be short, (less than RxmtInterval) |
177 | - RFC 2328 Section 13.5 para 3. Set to 1 second to avoid Acks being | |
178 | held back for too long - MAG */ | |
179 | oi->v_ls_ack = 1; | |
718e3744 | 180 | } |
181 | ||
20916fba | 182 | /* lookup oi for specified prefix/ifp */ |
d62a17ae | 183 | struct ospf_interface *ospf_if_table_lookup(struct interface *ifp, |
184 | struct prefix *prefix) | |
20916fba | 185 | { |
d62a17ae | 186 | struct prefix p; |
187 | struct route_node *rn; | |
188 | struct ospf_interface *rninfo = NULL; | |
189 | ||
190 | p = *prefix; | |
936fbaef | 191 | p.prefixlen = IPV4_MAX_BITLEN; |
d62a17ae | 192 | |
193 | /* route_node_get implicitely locks */ | |
194 | if ((rn = route_node_lookup(IF_OIFS(ifp), &p))) { | |
195 | rninfo = (struct ospf_interface *)rn->info; | |
196 | route_unlock_node(rn); | |
197 | } | |
198 | ||
199 | return rninfo; | |
20916fba | 200 | } |
201 | ||
d62a17ae | 202 | static void ospf_add_to_if(struct interface *ifp, struct ospf_interface *oi) |
718e3744 | 203 | { |
d62a17ae | 204 | struct route_node *rn; |
205 | struct prefix p; | |
206 | ||
207 | p = *oi->address; | |
936fbaef | 208 | p.prefixlen = IPV4_MAX_BITLEN; |
a6435618 | 209 | apply_mask(&p); |
d62a17ae | 210 | |
211 | rn = route_node_get(IF_OIFS(ifp), &p); | |
212 | /* rn->info should either be NULL or equal to this oi | |
213 | * as route_node_get may return an existing node | |
214 | */ | |
215 | assert(!rn->info || rn->info == oi); | |
216 | rn->info = oi; | |
718e3744 | 217 | } |
218 | ||
d62a17ae | 219 | static void ospf_delete_from_if(struct interface *ifp, |
220 | struct ospf_interface *oi) | |
718e3744 | 221 | { |
d62a17ae | 222 | struct route_node *rn; |
223 | struct prefix p; | |
224 | ||
225 | p = *oi->address; | |
936fbaef | 226 | p.prefixlen = IPV4_MAX_BITLEN; |
d62a17ae | 227 | |
228 | rn = route_node_lookup(IF_OIFS(oi->ifp), &p); | |
229 | assert(rn); | |
230 | assert(rn->info); | |
231 | rn->info = NULL; | |
232 | route_unlock_node(rn); | |
233 | route_unlock_node(rn); | |
718e3744 | 234 | } |
235 | ||
d62a17ae | 236 | struct ospf_interface *ospf_if_new(struct ospf *ospf, struct interface *ifp, |
237 | struct prefix *p) | |
718e3744 | 238 | { |
d62a17ae | 239 | struct ospf_interface *oi; |
240 | ||
36a106e0 DS |
241 | oi = ospf_if_table_lookup(ifp, p); |
242 | if (oi) | |
d62a17ae | 243 | return oi; |
244 | ||
36a106e0 DS |
245 | oi = XCALLOC(MTYPE_OSPF_IF, sizeof(struct ospf_interface)); |
246 | ||
247 | oi->obuf = ospf_fifo_new(); | |
248 | ||
d62a17ae | 249 | /* Set zebra interface pointer. */ |
250 | oi->ifp = ifp; | |
251 | oi->address = p; | |
252 | ||
253 | ospf_add_to_if(ifp, oi); | |
254 | listnode_add(ospf->oiflist, oi); | |
255 | ||
256 | /* Initialize neighbor list. */ | |
257 | oi->nbrs = route_table_init(); | |
258 | ||
259 | /* Initialize static neighbor list. */ | |
260 | oi->nbr_nbma = list_new(); | |
261 | ||
262 | /* Initialize Link State Acknowledgment list. */ | |
263 | oi->ls_ack = list_new(); | |
264 | oi->ls_ack_direct.ls_ack = list_new(); | |
265 | ||
266 | /* Set default values. */ | |
267 | ospf_if_reset_variables(oi); | |
268 | ||
269 | /* Set pseudo neighbor to Null */ | |
270 | oi->nbr_self = NULL; | |
271 | ||
272 | oi->ls_upd_queue = route_table_init(); | |
273 | oi->t_ls_upd_event = NULL; | |
274 | oi->t_ls_ack_direct = NULL; | |
275 | ||
276 | oi->crypt_seqnum = time(NULL); | |
277 | ||
278 | ospf_opaque_type9_lsa_init(oi); | |
279 | ||
280 | oi->ospf = ospf; | |
4fc8a852 | 281 | |
d62a17ae | 282 | QOBJ_REG(oi, ospf_interface); |
283 | ||
b5a8894d CS |
284 | if (IS_DEBUG_OSPF_EVENT) |
285 | zlog_debug("%s: ospf interface %s vrf %s id %u created", | |
15569c58 DA |
286 | __func__, ifp->name, ospf_get_name(ospf), |
287 | ospf->vrf_id); | |
b5a8894d | 288 | |
d62a17ae | 289 | return oi; |
718e3744 | 290 | } |
291 | ||
292 | /* Restore an interface to its pre UP state | |
293 | Used from ism_interface_down only */ | |
d62a17ae | 294 | void ospf_if_cleanup(struct ospf_interface *oi) |
718e3744 | 295 | { |
d62a17ae | 296 | struct route_node *rn; |
297 | struct listnode *node, *nnode; | |
298 | struct ospf_neighbor *nbr; | |
299 | struct ospf_nbr_nbma *nbr_nbma; | |
300 | struct ospf_lsa *lsa; | |
301 | ||
302 | /* oi->nbrs and oi->nbr_nbma should be deleted on InterfaceDown event */ | |
303 | /* delete all static neighbors attached to this interface */ | |
304 | for (ALL_LIST_ELEMENTS(oi->nbr_nbma, node, nnode, nbr_nbma)) { | |
305 | OSPF_POLL_TIMER_OFF(nbr_nbma->t_poll); | |
306 | ||
307 | if (nbr_nbma->nbr) { | |
308 | nbr_nbma->nbr->nbr_nbma = NULL; | |
309 | nbr_nbma->nbr = NULL; | |
310 | } | |
311 | ||
312 | nbr_nbma->oi = NULL; | |
313 | ||
314 | listnode_delete(oi->nbr_nbma, nbr_nbma); | |
718e3744 | 315 | } |
316 | ||
d62a17ae | 317 | /* send Neighbor event KillNbr to all associated neighbors. */ |
318 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) | |
319 | if ((nbr = rn->info) != NULL) | |
320 | if (nbr != oi->nbr_self) | |
321 | OSPF_NSM_EVENT_EXECUTE(nbr, NSM_KillNbr); | |
322 | ||
323 | /* Cleanup Link State Acknowlegdment list. */ | |
324 | for (ALL_LIST_ELEMENTS(oi->ls_ack, node, nnode, lsa)) | |
325 | ospf_lsa_unlock(&lsa); /* oi->ls_ack */ | |
326 | list_delete_all_node(oi->ls_ack); | |
327 | ||
328 | oi->crypt_seqnum = 0; | |
329 | ||
330 | /* Empty link state update queue */ | |
331 | ospf_ls_upd_queue_empty(oi); | |
332 | ||
333 | /* Reset pseudo neighbor. */ | |
334 | ospf_nbr_self_reset(oi, oi->ospf->router_id); | |
718e3744 | 335 | } |
336 | ||
d62a17ae | 337 | void ospf_if_free(struct ospf_interface *oi) |
718e3744 | 338 | { |
d62a17ae | 339 | ospf_if_down(oi); |
340 | ||
36a106e0 | 341 | ospf_fifo_free(oi->obuf); |
4fc8a852 | 342 | |
d62a17ae | 343 | assert(oi->state == ISM_Down); |
344 | ||
345 | ospf_opaque_type9_lsa_term(oi); | |
346 | ||
347 | QOBJ_UNREG(oi); | |
348 | ||
349 | /* Free Pseudo Neighbour */ | |
350 | ospf_nbr_delete(oi->nbr_self); | |
718e3744 | 351 | |
d62a17ae | 352 | route_table_finish(oi->nbrs); |
353 | route_table_finish(oi->ls_upd_queue); | |
718e3744 | 354 | |
d62a17ae | 355 | /* Free any lists that should be freed */ |
6a154c88 | 356 | list_delete(&oi->nbr_nbma); |
718e3744 | 357 | |
6a154c88 DL |
358 | list_delete(&oi->ls_ack); |
359 | list_delete(&oi->ls_ack_direct.ls_ack); | |
ae19c240 | 360 | |
b5a8894d CS |
361 | if (IS_DEBUG_OSPF_EVENT) |
362 | zlog_debug("%s: ospf interface %s vrf %s id %u deleted", | |
15569c58 | 363 | __func__, oi->ifp->name, |
a36898e7 DS |
364 | ospf_vrf_id_to_name(oi->ifp->vrf_id), |
365 | oi->ifp->vrf_id); | |
b5a8894d | 366 | |
d62a17ae | 367 | ospf_delete_from_if(oi->ifp, oi); |
718e3744 | 368 | |
d62a17ae | 369 | listnode_delete(oi->ospf->oiflist, oi); |
370 | listnode_delete(oi->area->oiflist, oi); | |
718e3744 | 371 | |
d62a17ae | 372 | thread_cancel_event(master, oi); |
cfd670f3 | 373 | |
d62a17ae | 374 | memset(oi, 0, sizeof(*oi)); |
375 | XFREE(MTYPE_OSPF_IF, oi); | |
718e3744 | 376 | } |
377 | ||
d62a17ae | 378 | int ospf_if_is_up(struct ospf_interface *oi) |
718e3744 | 379 | { |
d62a17ae | 380 | return if_is_up(oi->ifp); |
718e3744 | 381 | } |
382 | ||
d62a17ae | 383 | struct ospf_interface *ospf_if_exists(struct ospf_interface *oic) |
384 | { | |
385 | struct listnode *node; | |
386 | struct ospf *ospf; | |
387 | struct ospf_interface *oi; | |
2db3d05d | 388 | |
b5a8894d CS |
389 | if (!oic) |
390 | return NULL; | |
391 | ||
392 | ospf = oic->ospf; | |
393 | if (ospf == NULL) | |
d62a17ae | 394 | return NULL; |
2db3d05d | 395 | |
d62a17ae | 396 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) |
397 | if (oi == oic) | |
398 | return oi; | |
1eb8ef25 | 399 | |
d62a17ae | 400 | return NULL; |
2db3d05d | 401 | } |
402 | ||
c81ee5c9 | 403 | /* Lookup OSPF interface by router LSA posistion */ |
d62a17ae | 404 | struct ospf_interface *ospf_if_lookup_by_lsa_pos(struct ospf_area *area, |
405 | int lsa_pos) | |
c81ee5c9 | 406 | { |
d62a17ae | 407 | struct listnode *node; |
408 | struct ospf_interface *oi; | |
c81ee5c9 | 409 | |
d62a17ae | 410 | for (ALL_LIST_ELEMENTS_RO(area->oiflist, node, oi)) { |
411 | if (lsa_pos >= oi->lsa_pos_beg && lsa_pos < oi->lsa_pos_end) | |
412 | return oi; | |
413 | } | |
414 | return NULL; | |
c81ee5c9 JT |
415 | } |
416 | ||
d62a17ae | 417 | struct ospf_interface *ospf_if_lookup_by_local_addr(struct ospf *ospf, |
418 | struct interface *ifp, | |
419 | struct in_addr address) | |
718e3744 | 420 | { |
d62a17ae | 421 | struct listnode *node; |
422 | struct ospf_interface *oi; | |
423 | ||
424 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) | |
425 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) { | |
426 | if (ifp && oi->ifp != ifp) | |
427 | continue; | |
428 | ||
429 | if (IPV4_ADDR_SAME(&address, &oi->address->u.prefix4)) | |
430 | return oi; | |
431 | } | |
432 | ||
433 | return NULL; | |
718e3744 | 434 | } |
435 | ||
d62a17ae | 436 | struct ospf_interface *ospf_if_lookup_by_prefix(struct ospf *ospf, |
437 | struct prefix_ipv4 *p) | |
718e3744 | 438 | { |
d62a17ae | 439 | struct listnode *node; |
440 | struct ospf_interface *oi; | |
441 | ||
442 | /* Check each Interface. */ | |
443 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
444 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) { | |
445 | struct prefix ptmp; | |
446 | ||
447 | prefix_copy(&ptmp, CONNECTED_PREFIX(oi->connected)); | |
448 | apply_mask(&ptmp); | |
449 | if (prefix_same(&ptmp, (struct prefix *)p)) | |
450 | return oi; | |
451 | } | |
68980084 | 452 | } |
d62a17ae | 453 | return NULL; |
718e3744 | 454 | } |
455 | ||
05cf46ba | 456 | /* determine receiving interface by ifp and source address */ |
d62a17ae | 457 | struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf, |
458 | struct in_addr src, | |
459 | struct interface *ifp) | |
718e3744 | 460 | { |
d62a17ae | 461 | struct route_node *rn; |
462 | struct prefix_ipv4 addr; | |
463 | struct ospf_interface *oi, *match; | |
464 | ||
465 | addr.family = AF_INET; | |
466 | addr.prefix = src; | |
467 | addr.prefixlen = IPV4_MAX_BITLEN; | |
468 | ||
469 | match = NULL; | |
470 | ||
471 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
472 | oi = rn->info; | |
473 | ||
474 | if (!oi) /* oi can be NULL for PtP aliases */ | |
475 | continue; | |
476 | ||
477 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) | |
478 | continue; | |
479 | ||
0c74bbe0 | 480 | if (if_is_loopback(oi->ifp) || if_is_vrf(oi->ifp)) |
d62a17ae | 481 | continue; |
482 | ||
483 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) | |
484 | match = oi; | |
485 | else if (prefix_match(CONNECTED_PREFIX(oi->connected), | |
486 | (struct prefix *)&addr)) { | |
9d303b37 DL |
487 | if ((match == NULL) || (match->address->prefixlen |
488 | < oi->address->prefixlen)) | |
d62a17ae | 489 | match = oi; |
490 | } | |
718e3744 | 491 | } |
718e3744 | 492 | |
d62a17ae | 493 | return match; |
718e3744 | 494 | } |
6b0655a2 | 495 | |
85c8ef06 CS |
496 | static void ospf_if_reset_stats(struct ospf_interface *oi) |
497 | { | |
498 | oi->hello_in = oi->hello_out = 0; | |
499 | oi->db_desc_in = oi->db_desc_out = 0; | |
500 | oi->ls_req_in = oi->ls_req_out = 0; | |
501 | oi->ls_upd_in = oi->ls_upd_out = 0; | |
502 | oi->ls_ack_in = oi->ls_ack_out = 0; | |
503 | } | |
504 | ||
d62a17ae | 505 | void ospf_if_stream_unset(struct ospf_interface *oi) |
718e3744 | 506 | { |
d62a17ae | 507 | struct ospf *ospf = oi->ospf; |
508 | ||
36a106e0 DS |
509 | /* flush the interface packet queue */ |
510 | ospf_fifo_flush(oi->obuf); | |
511 | /*reset protocol stats */ | |
512 | ospf_if_reset_stats(oi); | |
513 | ||
514 | if (oi->on_write_q) { | |
515 | listnode_delete(ospf->oi_write_q, oi); | |
516 | if (list_isempty(ospf->oi_write_q)) | |
517 | OSPF_TIMER_OFF(ospf->t_write); | |
518 | oi->on_write_q = 0; | |
d62a17ae | 519 | } |
718e3744 | 520 | } |
68980084 | 521 | |
6b0655a2 | 522 | |
d62a17ae | 523 | static struct ospf_if_params *ospf_new_if_params(void) |
718e3744 | 524 | { |
d62a17ae | 525 | struct ospf_if_params *oip; |
526 | ||
527 | oip = XCALLOC(MTYPE_OSPF_IF_PARAMS, sizeof(struct ospf_if_params)); | |
528 | ||
d62a17ae | 529 | UNSET_IF_PARAM(oip, output_cost_cmd); |
530 | UNSET_IF_PARAM(oip, transmit_delay); | |
531 | UNSET_IF_PARAM(oip, retransmit_interval); | |
532 | UNSET_IF_PARAM(oip, passive_interface); | |
533 | UNSET_IF_PARAM(oip, v_hello); | |
534 | UNSET_IF_PARAM(oip, fast_hello); | |
535 | UNSET_IF_PARAM(oip, v_wait); | |
536 | UNSET_IF_PARAM(oip, priority); | |
537 | UNSET_IF_PARAM(oip, type); | |
538 | UNSET_IF_PARAM(oip, auth_simple); | |
539 | UNSET_IF_PARAM(oip, auth_crypt); | |
540 | UNSET_IF_PARAM(oip, auth_type); | |
bf617538 | 541 | UNSET_IF_PARAM(oip, if_area); |
d62a17ae | 542 | |
543 | oip->auth_crypt = list_new(); | |
544 | ||
545 | oip->network_lsa_seqnum = htonl(OSPF_INITIAL_SEQUENCE_NUMBER); | |
182d6bdc | 546 | oip->is_v_wait_set = false; |
d62a17ae | 547 | |
bc97889b AL |
548 | oip->ptp_dmvpn = 0; |
549 | ||
d62a17ae | 550 | return oip; |
718e3744 | 551 | } |
552 | ||
659f4e40 RZ |
553 | static void ospf_del_if_params(struct interface *ifp, |
554 | struct ospf_if_params *oip) | |
718e3744 | 555 | { |
6a154c88 | 556 | list_delete(&oip->auth_crypt); |
659f4e40 | 557 | ospf_interface_disable_bfd(ifp, oip); |
132a782e | 558 | ldp_sync_info_free(&(oip->ldp_sync_info)); |
d62a17ae | 559 | XFREE(MTYPE_OSPF_IF_PARAMS, oip); |
718e3744 | 560 | } |
561 | ||
d62a17ae | 562 | void ospf_free_if_params(struct interface *ifp, struct in_addr addr) |
718e3744 | 563 | { |
d62a17ae | 564 | struct ospf_if_params *oip; |
565 | struct prefix_ipv4 p; | |
566 | struct route_node *rn; | |
567 | ||
568 | p.family = AF_INET; | |
936fbaef | 569 | p.prefixlen = IPV4_MAX_BITLEN; |
d62a17ae | 570 | p.prefix = addr; |
571 | rn = route_node_lookup(IF_OIFS_PARAMS(ifp), (struct prefix *)&p); | |
572 | if (!rn || !rn->info) | |
573 | return; | |
574 | ||
575 | oip = rn->info; | |
576 | route_unlock_node(rn); | |
577 | ||
578 | if (!OSPF_IF_PARAM_CONFIGURED(oip, output_cost_cmd) | |
579 | && !OSPF_IF_PARAM_CONFIGURED(oip, transmit_delay) | |
580 | && !OSPF_IF_PARAM_CONFIGURED(oip, retransmit_interval) | |
581 | && !OSPF_IF_PARAM_CONFIGURED(oip, passive_interface) | |
582 | && !OSPF_IF_PARAM_CONFIGURED(oip, v_hello) | |
583 | && !OSPF_IF_PARAM_CONFIGURED(oip, fast_hello) | |
584 | && !OSPF_IF_PARAM_CONFIGURED(oip, v_wait) | |
585 | && !OSPF_IF_PARAM_CONFIGURED(oip, priority) | |
586 | && !OSPF_IF_PARAM_CONFIGURED(oip, type) | |
587 | && !OSPF_IF_PARAM_CONFIGURED(oip, auth_simple) | |
588 | && !OSPF_IF_PARAM_CONFIGURED(oip, auth_type) | |
bf617538 | 589 | && !OSPF_IF_PARAM_CONFIGURED(oip, if_area) |
2917d36b | 590 | && listcount(oip->auth_crypt) == 0) { |
659f4e40 | 591 | ospf_del_if_params(ifp, oip); |
d62a17ae | 592 | rn->info = NULL; |
593 | route_unlock_node(rn); | |
594 | } | |
718e3744 | 595 | } |
596 | ||
d62a17ae | 597 | struct ospf_if_params *ospf_lookup_if_params(struct interface *ifp, |
598 | struct in_addr addr) | |
718e3744 | 599 | { |
d62a17ae | 600 | struct prefix_ipv4 p; |
601 | struct route_node *rn; | |
602 | ||
603 | p.family = AF_INET; | |
936fbaef | 604 | p.prefixlen = IPV4_MAX_BITLEN; |
d62a17ae | 605 | p.prefix = addr; |
606 | ||
607 | rn = route_node_lookup(IF_OIFS_PARAMS(ifp), (struct prefix *)&p); | |
608 | ||
609 | if (rn) { | |
610 | route_unlock_node(rn); | |
611 | return rn->info; | |
612 | } | |
613 | ||
614 | return NULL; | |
718e3744 | 615 | } |
616 | ||
d62a17ae | 617 | struct ospf_if_params *ospf_get_if_params(struct interface *ifp, |
618 | struct in_addr addr) | |
718e3744 | 619 | { |
d62a17ae | 620 | struct prefix_ipv4 p; |
621 | struct route_node *rn; | |
622 | ||
623 | p.family = AF_INET; | |
936fbaef | 624 | p.prefixlen = IPV4_MAX_BITLEN; |
d62a17ae | 625 | p.prefix = addr; |
a6435618 | 626 | apply_mask_ipv4(&p); |
d62a17ae | 627 | |
628 | rn = route_node_get(IF_OIFS_PARAMS(ifp), (struct prefix *)&p); | |
629 | ||
630 | if (rn->info == NULL) | |
631 | rn->info = ospf_new_if_params(); | |
632 | else | |
633 | route_unlock_node(rn); | |
634 | ||
635 | return rn->info; | |
718e3744 | 636 | } |
637 | ||
d62a17ae | 638 | void ospf_if_update_params(struct interface *ifp, struct in_addr addr) |
718e3744 | 639 | { |
d62a17ae | 640 | struct route_node *rn; |
641 | struct ospf_interface *oi; | |
642 | ||
643 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
644 | if ((oi = rn->info) == NULL) | |
645 | continue; | |
646 | ||
647 | if (IPV4_ADDR_SAME(&oi->address->u.prefix4, &addr)) | |
648 | oi->params = ospf_lookup_if_params( | |
649 | ifp, oi->address->u.prefix4); | |
650 | } | |
718e3744 | 651 | } |
652 | ||
d62a17ae | 653 | int ospf_if_new_hook(struct interface *ifp) |
718e3744 | 654 | { |
d62a17ae | 655 | int rc = 0; |
656 | ||
657 | ifp->info = XCALLOC(MTYPE_OSPF_IF_INFO, sizeof(struct ospf_if_info)); | |
658 | ||
659 | IF_OIFS(ifp) = route_table_init(); | |
660 | IF_OIFS_PARAMS(ifp) = route_table_init(); | |
661 | ||
662 | IF_DEF_PARAMS(ifp) = ospf_new_if_params(); | |
663 | ||
664 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
665 | IF_DEF_PARAMS(ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
666 | ||
667 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
668 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
669 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
670 | ||
671 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), priority); | |
672 | IF_DEF_PARAMS(ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
673 | ||
674 | IF_DEF_PARAMS(ifp)->mtu_ignore = OSPF_MTU_IGNORE_DEFAULT; | |
675 | ||
676 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
677 | IF_DEF_PARAMS(ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
678 | ||
679 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), fast_hello); | |
680 | IF_DEF_PARAMS(ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
681 | ||
682 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
683 | IF_DEF_PARAMS(ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
684 | ||
685 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_simple); | |
686 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); | |
687 | ||
688 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
689 | IF_DEF_PARAMS(ifp)->auth_type = OSPF_AUTH_NOTSET; | |
690 | ||
691 | rc = ospf_opaque_new_if(ifp); | |
692 | return rc; | |
718e3744 | 693 | } |
694 | ||
d62a17ae | 695 | static int ospf_if_delete_hook(struct interface *ifp) |
718e3744 | 696 | { |
d62a17ae | 697 | int rc = 0; |
698 | struct route_node *rn; | |
699 | rc = ospf_opaque_del_if(ifp); | |
940b01aa | 700 | |
e2134a79 RZ |
701 | /* |
702 | * This function must be called before `route_table_finish` due to | |
703 | * BFD integration need to iterate over the interface neighbors to | |
704 | * remove all registrations. | |
705 | */ | |
706 | ospf_del_if_params(ifp, IF_DEF_PARAMS(ifp)); | |
707 | ||
d62a17ae | 708 | route_table_finish(IF_OIFS(ifp)); |
940b01aa | 709 | |
d62a17ae | 710 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn)) |
711 | if (rn->info) | |
659f4e40 | 712 | ospf_del_if_params(ifp, rn->info); |
d62a17ae | 713 | route_table_finish(IF_OIFS_PARAMS(ifp)); |
940b01aa | 714 | |
d62a17ae | 715 | XFREE(MTYPE_OSPF_IF_INFO, ifp->info); |
718e3744 | 716 | |
d62a17ae | 717 | return rc; |
718e3744 | 718 | } |
719 | ||
d62a17ae | 720 | int ospf_if_is_enable(struct ospf_interface *oi) |
718e3744 | 721 | { |
0c74bbe0 | 722 | if (!(if_is_loopback(oi->ifp) || if_is_vrf(oi->ifp))) |
d62a17ae | 723 | if (if_is_up(oi->ifp)) |
724 | return 1; | |
718e3744 | 725 | |
d62a17ae | 726 | return 0; |
718e3744 | 727 | } |
728 | ||
d62a17ae | 729 | void ospf_if_set_multicast(struct ospf_interface *oi) |
ba6454ec | 730 | { |
d62a17ae | 731 | if ((oi->state > ISM_Loopback) && (oi->type != OSPF_IFTYPE_LOOPBACK) |
732 | && (oi->type != OSPF_IFTYPE_VIRTUALLINK) | |
733 | && (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE)) { | |
734 | /* The interface should belong to the OSPF-all-routers group. */ | |
735 | if (!OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
736 | && (ospf_if_add_allspfrouters(oi->ospf, oi->address, | |
737 | oi->ifp->ifindex) | |
738 | >= 0)) | |
739 | /* Set the flag only if the system call to join | |
740 | * succeeded. */ | |
741 | OI_MEMBER_JOINED(oi, MEMBER_ALLROUTERS); | |
742 | } else { | |
743 | /* The interface should NOT belong to the OSPF-all-routers | |
744 | * group. */ | |
745 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) { | |
746 | /* Only actually drop if this is the last reference */ | |
747 | if (OI_MEMBER_COUNT(oi, MEMBER_ALLROUTERS) == 1) | |
748 | ospf_if_drop_allspfrouters(oi->ospf, | |
749 | oi->address, | |
750 | oi->ifp->ifindex); | |
751 | /* Unset the flag regardless of whether the system call | |
752 | to leave | |
753 | the group succeeded, since it's much safer to assume | |
754 | that | |
755 | we are not a member. */ | |
756 | OI_MEMBER_LEFT(oi, MEMBER_ALLROUTERS); | |
757 | } | |
758 | } | |
759 | ||
760 | if (((oi->type == OSPF_IFTYPE_BROADCAST) | |
761 | || (oi->type == OSPF_IFTYPE_POINTOPOINT)) | |
762 | && ((oi->state == ISM_DR) || (oi->state == ISM_Backup)) | |
763 | && (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE)) { | |
764 | /* The interface should belong to the OSPF-designated-routers | |
765 | * group. */ | |
766 | if (!OI_MEMBER_CHECK(oi, MEMBER_DROUTERS) | |
767 | && (ospf_if_add_alldrouters(oi->ospf, oi->address, | |
768 | oi->ifp->ifindex) | |
769 | >= 0)) | |
770 | /* Set the flag only if the system call to join | |
771 | * succeeded. */ | |
772 | OI_MEMBER_JOINED(oi, MEMBER_DROUTERS); | |
773 | } else { | |
774 | /* The interface should NOT belong to the | |
775 | * OSPF-designated-routers group */ | |
776 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
777 | /* drop only if last reference */ | |
778 | if (OI_MEMBER_COUNT(oi, MEMBER_DROUTERS) == 1) | |
779 | ospf_if_drop_alldrouters(oi->ospf, oi->address, | |
780 | oi->ifp->ifindex); | |
781 | ||
782 | /* Unset the flag regardless of whether the system call | |
783 | to leave | |
784 | the group succeeded, since it's much safer to assume | |
785 | that | |
786 | we are not a member. */ | |
787 | OI_MEMBER_LEFT(oi, MEMBER_DROUTERS); | |
788 | } | |
789 | } | |
ba6454ec | 790 | } |
791 | ||
d62a17ae | 792 | int ospf_if_up(struct ospf_interface *oi) |
718e3744 | 793 | { |
d62a17ae | 794 | if (oi == NULL) |
795 | return 0; | |
796 | ||
797 | if (oi->type == OSPF_IFTYPE_LOOPBACK) | |
798 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_LoopInd); | |
799 | else { | |
d62a17ae | 800 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_InterfaceUp); |
801 | } | |
802 | ||
803 | return 1; | |
718e3744 | 804 | } |
805 | ||
d62a17ae | 806 | int ospf_if_down(struct ospf_interface *oi) |
718e3744 | 807 | { |
df074ec3 | 808 | struct ospf *ospf; |
effee187 DS |
809 | struct route_node *rn; |
810 | struct ospf_route *or; | |
811 | struct listnode *nh; | |
812 | struct ospf_path *op; | |
df074ec3 | 813 | |
d62a17ae | 814 | if (oi == NULL) |
815 | return 0; | |
718e3744 | 816 | |
df074ec3 | 817 | ospf = oi->ospf; |
818 | ||
819 | /* Cease the HELPER role for all the neighbours | |
820 | * of this interface. | |
821 | */ | |
822 | if (ospf->is_helper_supported) { | |
823 | struct route_node *rn = NULL; | |
824 | ||
825 | if (ospf_interface_neighbor_count(oi)) { | |
826 | for (rn = route_top(oi->nbrs); rn; | |
827 | rn = route_next(rn)) { | |
828 | struct ospf_neighbor *nbr = NULL; | |
829 | ||
830 | if (!rn->info) | |
831 | continue; | |
832 | ||
833 | nbr = rn->info; | |
834 | ||
835 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) | |
836 | ospf_gr_helper_exit( | |
837 | nbr, OSPF_GR_HELPER_TOPO_CHG); | |
838 | } | |
839 | } | |
840 | } | |
841 | ||
d62a17ae | 842 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); |
843 | /* delete position in router LSA */ | |
844 | oi->lsa_pos_beg = 0; | |
845 | oi->lsa_pos_end = 0; | |
846 | /* Shutdown packet reception and sending */ | |
847 | ospf_if_stream_unset(oi); | |
718e3744 | 848 | |
effee187 DS |
849 | for (rn = route_top(ospf->new_table); rn; rn = route_next(rn)) { |
850 | or = rn->info; | |
851 | ||
852 | if (!or) | |
853 | continue; | |
854 | ||
855 | for (nh = listhead(or->paths); nh; | |
856 | nh = listnextnode_unchecked(nh)) { | |
857 | op = listgetdata(nh); | |
858 | if (op->ifindex == oi->ifp->ifindex) { | |
859 | or->changed = true; | |
860 | break; | |
861 | } | |
862 | } | |
863 | } | |
864 | ||
d62a17ae | 865 | return 1; |
718e3744 | 866 | } |
867 | ||
6b0655a2 | 868 | |
718e3744 | 869 | /* Virtual Link related functions. */ |
870 | ||
d62a17ae | 871 | struct ospf_vl_data *ospf_vl_data_new(struct ospf_area *area, |
872 | struct in_addr vl_peer) | |
718e3744 | 873 | { |
d62a17ae | 874 | struct ospf_vl_data *vl_data; |
718e3744 | 875 | |
d62a17ae | 876 | vl_data = XCALLOC(MTYPE_OSPF_VL_DATA, sizeof(struct ospf_vl_data)); |
718e3744 | 877 | |
d62a17ae | 878 | vl_data->vl_peer.s_addr = vl_peer.s_addr; |
879 | vl_data->vl_area_id = area->area_id; | |
880 | vl_data->vl_area_id_fmt = area->area_id_fmt; | |
718e3744 | 881 | |
d62a17ae | 882 | return vl_data; |
718e3744 | 883 | } |
884 | ||
d62a17ae | 885 | void ospf_vl_data_free(struct ospf_vl_data *vl_data) |
718e3744 | 886 | { |
d62a17ae | 887 | XFREE(MTYPE_OSPF_VL_DATA, vl_data); |
718e3744 | 888 | } |
889 | ||
d7c0a89a | 890 | unsigned int vlink_count = 0; |
718e3744 | 891 | |
d62a17ae | 892 | struct ospf_interface *ospf_vl_new(struct ospf *ospf, |
893 | struct ospf_vl_data *vl_data) | |
718e3744 | 894 | { |
d62a17ae | 895 | struct ospf_interface *voi; |
896 | struct interface *vi; | |
bcc24579 | 897 | char ifname[INTERFACE_NAMSIZ]; |
d62a17ae | 898 | struct ospf_area *area; |
899 | struct in_addr area_id; | |
900 | struct connected *co; | |
901 | struct prefix_ipv4 *p; | |
902 | ||
903 | if (IS_DEBUG_OSPF_EVENT) | |
868a0861 | 904 | zlog_debug("ospf_vl_new()(%s): Start", ospf_get_name(ospf)); |
d62a17ae | 905 | if (vlink_count == OSPF_VL_MAX_COUNT) { |
906 | if (IS_DEBUG_OSPF_EVENT) | |
907 | zlog_debug( | |
3efd0893 | 908 | "ospf_vl_new(): Alarm: cannot create more than OSPF_MAX_VL_COUNT virtual links"); |
d62a17ae | 909 | return NULL; |
910 | } | |
911 | ||
912 | if (IS_DEBUG_OSPF_EVENT) | |
996c9314 LB |
913 | zlog_debug( |
914 | "ospf_vl_new(): creating pseudo zebra interface vrf id %u", | |
915 | ospf->vrf_id); | |
d62a17ae | 916 | |
2ec42b85 | 917 | snprintf(ifname, sizeof(ifname), "VLINK%u", vlink_count); |
d5c65bf1 | 918 | vi = if_create_name(ifname, ospf->vrf_id); |
d62a17ae | 919 | /* |
d5c65bf1 | 920 | * if_create_name sets ZEBRA_INTERFACE_LINKDETECTION |
d62a17ae | 921 | * virtual links don't need this. |
922 | */ | |
923 | UNSET_FLAG(vi->status, ZEBRA_INTERFACE_LINKDETECTION); | |
924 | co = connected_new(); | |
925 | co->ifp = vi; | |
926 | listnode_add(vi->connected, co); | |
927 | ||
928 | p = prefix_ipv4_new(); | |
929 | p->family = AF_INET; | |
975a328e | 930 | p->prefix.s_addr = INADDR_ANY; |
d62a17ae | 931 | p->prefixlen = 0; |
932 | ||
933 | co->address = (struct prefix *)p; | |
934 | ||
935 | voi = ospf_if_new(ospf, vi, co->address); | |
936 | if (voi == NULL) { | |
937 | if (IS_DEBUG_OSPF_EVENT) | |
938 | zlog_debug( | |
939 | "ospf_vl_new(): Alarm: OSPF int structure is not created"); | |
940 | return NULL; | |
941 | } | |
942 | voi->connected = co; | |
943 | voi->vl_data = vl_data; | |
944 | voi->ifp->mtu = OSPF_VL_MTU; | |
945 | voi->type = OSPF_IFTYPE_VIRTUALLINK; | |
946 | ||
947 | vlink_count++; | |
948 | if (IS_DEBUG_OSPF_EVENT) | |
949 | zlog_debug("ospf_vl_new(): Created name: %s", ifname); | |
950 | if (IS_DEBUG_OSPF_EVENT) | |
951 | zlog_debug("ospf_vl_new(): set if->name to %s", vi->name); | |
952 | ||
975a328e | 953 | area_id.s_addr = INADDR_ANY; |
d62a17ae | 954 | area = ospf_area_get(ospf, area_id); |
955 | voi->area = area; | |
956 | ||
957 | if (IS_DEBUG_OSPF_EVENT) | |
958 | zlog_debug( | |
959 | "ospf_vl_new(): set associated area to the backbone"); | |
960 | ||
961 | /* Add pseudo neighbor. */ | |
962 | ospf_nbr_self_reset(voi, voi->ospf->router_id); | |
963 | ||
964 | ospf_area_add_if(voi->area, voi); | |
965 | ||
d62a17ae | 966 | if (IS_DEBUG_OSPF_EVENT) |
967 | zlog_debug("ospf_vl_new(): Stop"); | |
968 | return voi; | |
718e3744 | 969 | } |
970 | ||
d62a17ae | 971 | static void ospf_vl_if_delete(struct ospf_vl_data *vl_data) |
718e3744 | 972 | { |
7a004ccf DS |
973 | struct interface *ifp = vl_data->vl_oi->ifp; |
974 | ||
975a328e | 975 | vl_data->vl_oi->address->u.prefix4.s_addr = INADDR_ANY; |
d62a17ae | 976 | vl_data->vl_oi->address->prefixlen = 0; |
977 | ospf_if_free(vl_data->vl_oi); | |
7a004ccf | 978 | if_delete(&ifp); |
d62a17ae | 979 | vlink_count--; |
718e3744 | 980 | } |
981 | ||
19ce7d5e PG |
982 | /* for a defined area, count the number of configured vl |
983 | */ | |
984 | int ospf_vl_count(struct ospf *ospf, struct ospf_area *area) | |
985 | { | |
986 | int count = 0; | |
987 | struct ospf_vl_data *vl_data; | |
988 | struct listnode *node; | |
989 | ||
990 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
991 | if (area | |
992 | && !IPV4_ADDR_SAME(&vl_data->vl_area_id, &area->area_id)) | |
993 | continue; | |
994 | count++; | |
995 | } | |
996 | return count; | |
997 | } | |
998 | ||
9c27ef9b PJ |
999 | /* Look up vl_data for given peer, optionally qualified to be in the |
1000 | * specified area. NULL area returns first found.. | |
1001 | */ | |
d62a17ae | 1002 | struct ospf_vl_data *ospf_vl_lookup(struct ospf *ospf, struct ospf_area *area, |
1003 | struct in_addr vl_peer) | |
718e3744 | 1004 | { |
d62a17ae | 1005 | struct ospf_vl_data *vl_data; |
1006 | struct listnode *node; | |
1007 | ||
1008 | if (IS_DEBUG_OSPF_EVENT) { | |
96b663a3 | 1009 | zlog_debug("%s: Looking for %pI4", __func__, &vl_peer); |
d62a17ae | 1010 | if (area) |
96b663a3 MS |
1011 | zlog_debug("%s: in area %pI4", __func__, |
1012 | &area->area_id); | |
d62a17ae | 1013 | } |
1014 | ||
1015 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
1016 | if (IS_DEBUG_OSPF_EVENT) | |
96b663a3 | 1017 | zlog_debug("%s: VL %s, peer %pI4", __func__, |
d62a17ae | 1018 | vl_data->vl_oi->ifp->name, |
96b663a3 | 1019 | &vl_data->vl_peer); |
d62a17ae | 1020 | |
1021 | if (area | |
1022 | && !IPV4_ADDR_SAME(&vl_data->vl_area_id, &area->area_id)) | |
1023 | continue; | |
1024 | ||
1025 | if (IPV4_ADDR_SAME(&vl_data->vl_peer, &vl_peer)) | |
1026 | return vl_data; | |
1027 | } | |
1028 | ||
1029 | return NULL; | |
718e3744 | 1030 | } |
1031 | ||
d62a17ae | 1032 | static void ospf_vl_shutdown(struct ospf_vl_data *vl_data) |
718e3744 | 1033 | { |
d62a17ae | 1034 | struct ospf_interface *oi; |
718e3744 | 1035 | |
d62a17ae | 1036 | if ((oi = vl_data->vl_oi) == NULL) |
1037 | return; | |
718e3744 | 1038 | |
975a328e | 1039 | oi->address->u.prefix4.s_addr = INADDR_ANY; |
d62a17ae | 1040 | oi->address->prefixlen = 0; |
718e3744 | 1041 | |
d62a17ae | 1042 | UNSET_FLAG(oi->ifp->flags, IFF_UP); |
1043 | /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */ | |
1044 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
718e3744 | 1045 | } |
1046 | ||
d62a17ae | 1047 | void ospf_vl_add(struct ospf *ospf, struct ospf_vl_data *vl_data) |
718e3744 | 1048 | { |
d62a17ae | 1049 | listnode_add(ospf->vlinks, vl_data); |
1050 | hook_call(ospf_vl_add, vl_data); | |
718e3744 | 1051 | } |
1052 | ||
d62a17ae | 1053 | void ospf_vl_delete(struct ospf *ospf, struct ospf_vl_data *vl_data) |
718e3744 | 1054 | { |
d62a17ae | 1055 | ospf_vl_shutdown(vl_data); |
1056 | ospf_vl_if_delete(vl_data); | |
718e3744 | 1057 | |
d62a17ae | 1058 | hook_call(ospf_vl_delete, vl_data); |
1059 | listnode_delete(ospf->vlinks, vl_data); | |
718e3744 | 1060 | |
d62a17ae | 1061 | ospf_vl_data_free(vl_data); |
718e3744 | 1062 | } |
1063 | ||
1d376ff5 G |
1064 | static int ospf_vl_set_params(struct ospf_area *area, |
1065 | struct ospf_vl_data *vl_data, struct vertex *v) | |
718e3744 | 1066 | { |
d62a17ae | 1067 | int changed = 0; |
1068 | struct ospf_interface *voi; | |
1069 | struct listnode *node; | |
1070 | struct vertex_parent *vp = NULL; | |
1071 | unsigned int i; | |
1072 | struct router_lsa *rl; | |
1d376ff5 | 1073 | struct ospf_interface *oi; |
d62a17ae | 1074 | |
1075 | voi = vl_data->vl_oi; | |
1076 | ||
1077 | if (voi->output_cost != v->distance) { | |
1078 | ||
1079 | voi->output_cost = v->distance; | |
1080 | changed = 1; | |
1081 | } | |
1082 | ||
1083 | for (ALL_LIST_ELEMENTS_RO(v->parents, node, vp)) { | |
1d376ff5 | 1084 | vl_data->nexthop.lsa_pos = vp->nexthop->lsa_pos; |
d62a17ae | 1085 | vl_data->nexthop.router = vp->nexthop->router; |
1086 | ||
1d376ff5 G |
1087 | /* |
1088 | * Only deal with interface data when the local | |
1089 | * (calculating) node is the SPF root node | |
1090 | */ | |
1091 | if (!area->spf_dry_run) { | |
1092 | oi = ospf_if_lookup_by_lsa_pos( | |
1093 | area, vl_data->nexthop.lsa_pos); | |
d62a17ae | 1094 | |
1d376ff5 G |
1095 | if (!IPV4_ADDR_SAME(&voi->address->u.prefix4, |
1096 | &oi->address->u.prefix4)) | |
1097 | changed = 1; | |
1098 | ||
1099 | voi->address->u.prefix4 = oi->address->u.prefix4; | |
1100 | voi->address->prefixlen = oi->address->prefixlen; | |
1101 | } | |
d62a17ae | 1102 | |
1103 | break; /* We take the first interface. */ | |
1104 | } | |
1105 | ||
1106 | rl = (struct router_lsa *)v->lsa; | |
1107 | ||
1108 | /* use SPF determined backlink index in struct vertex | |
1109 | * for virtual link destination address | |
1110 | */ | |
1111 | if (vp && vp->backlink >= 0) { | |
1112 | if (!IPV4_ADDR_SAME(&vl_data->peer_addr, | |
1113 | &rl->link[vp->backlink].link_data)) | |
1114 | changed = 1; | |
1115 | vl_data->peer_addr = rl->link[vp->backlink].link_data; | |
1116 | } else { | |
1117 | /* This is highly odd, there is no backlink index | |
1118 | * there should be due to the ospf_spf_has_link() check | |
1119 | * in SPF. Lets warn and try pick a link anyway. | |
1120 | */ | |
266469eb | 1121 | zlog_info("ospf_vl_set_params: No backlink for %s!", |
d62a17ae | 1122 | vl_data->vl_oi->ifp->name); |
1123 | for (i = 0; i < ntohs(rl->links); i++) { | |
1124 | switch (rl->link[i].type) { | |
1125 | case LSA_LINK_TYPE_VIRTUALLINK: | |
1126 | if (IS_DEBUG_OSPF_EVENT) | |
1127 | zlog_debug( | |
1128 | "found back link through VL"); | |
1129 | /* fallthru */ | |
1130 | case LSA_LINK_TYPE_TRANSIT: | |
1131 | case LSA_LINK_TYPE_POINTOPOINT: | |
1132 | if (!IPV4_ADDR_SAME(&vl_data->peer_addr, | |
1133 | &rl->link[i].link_data)) | |
1134 | changed = 1; | |
1135 | vl_data->peer_addr = rl->link[i].link_data; | |
1136 | } | |
1137 | } | |
1138 | } | |
1139 | ||
1140 | if (IS_DEBUG_OSPF_EVENT) | |
96b663a3 | 1141 | zlog_debug("%s: %s peer address: %pI4, cost: %d,%schanged", |
d62a17ae | 1142 | __func__, vl_data->vl_oi->ifp->name, |
96b663a3 | 1143 | &vl_data->peer_addr, voi->output_cost, |
d62a17ae | 1144 | (changed ? " " : " un")); |
1145 | ||
1146 | return changed; | |
718e3744 | 1147 | } |
1148 | ||
1149 | ||
d62a17ae | 1150 | void ospf_vl_up_check(struct ospf_area *area, struct in_addr rid, |
1151 | struct vertex *v) | |
718e3744 | 1152 | { |
d62a17ae | 1153 | struct ospf *ospf = area->ospf; |
1154 | struct listnode *node; | |
1155 | struct ospf_vl_data *vl_data; | |
1156 | struct ospf_interface *oi; | |
1157 | ||
1158 | if (IS_DEBUG_OSPF_EVENT) { | |
1159 | zlog_debug("ospf_vl_up_check(): Start"); | |
96b663a3 MS |
1160 | zlog_debug("ospf_vl_up_check(): Router ID is %pI4", |
1161 | &rid); | |
1162 | zlog_debug("ospf_vl_up_check(): Area is %pI4", | |
1163 | &area->area_id); | |
718e3744 | 1164 | } |
1165 | ||
d62a17ae | 1166 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { |
1167 | if (IS_DEBUG_OSPF_EVENT) { | |
96b663a3 | 1168 | zlog_debug("%s: considering VL, %s in area %pI4", |
d62a17ae | 1169 | __func__, vl_data->vl_oi->ifp->name, |
96b663a3 MS |
1170 | &vl_data->vl_area_id); |
1171 | zlog_debug("%s: peer ID: %pI4", __func__, | |
1172 | &vl_data->vl_peer); | |
d62a17ae | 1173 | } |
1174 | ||
1175 | if (IPV4_ADDR_SAME(&vl_data->vl_peer, &rid) | |
1176 | && IPV4_ADDR_SAME(&vl_data->vl_area_id, &area->area_id)) { | |
1177 | oi = vl_data->vl_oi; | |
1178 | SET_FLAG(vl_data->flags, OSPF_VL_FLAG_APPROVED); | |
1179 | ||
1180 | if (IS_DEBUG_OSPF_EVENT) | |
1181 | zlog_debug( | |
1182 | "ospf_vl_up_check(): this VL matched"); | |
1183 | ||
1184 | if (oi->state == ISM_Down) { | |
1185 | if (IS_DEBUG_OSPF_EVENT) | |
1186 | zlog_debug( | |
1187 | "ospf_vl_up_check(): VL is down, waking it up"); | |
1188 | SET_FLAG(oi->ifp->flags, IFF_UP); | |
1189 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
1190 | } | |
1191 | ||
1d376ff5 | 1192 | if (ospf_vl_set_params(area, vl_data, v)) { |
d62a17ae | 1193 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
1194 | zlog_debug( | |
3efd0893 | 1195 | "ospf_vl_up_check: VL cost change, scheduling router lsa refresh"); |
d62a17ae | 1196 | if (ospf->backbone) |
1197 | ospf_router_lsa_update_area( | |
1198 | ospf->backbone); | |
1199 | else if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) | |
1200 | zlog_debug( | |
1201 | "ospf_vl_up_check: VL cost change, no backbone!"); | |
1202 | } | |
1203 | } | |
1204 | } | |
718e3744 | 1205 | } |
1206 | ||
d62a17ae | 1207 | void ospf_vl_unapprove(struct ospf *ospf) |
718e3744 | 1208 | { |
d62a17ae | 1209 | struct listnode *node; |
1210 | struct ospf_vl_data *vl_data; | |
718e3744 | 1211 | |
d62a17ae | 1212 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) |
1213 | UNSET_FLAG(vl_data->flags, OSPF_VL_FLAG_APPROVED); | |
718e3744 | 1214 | } |
1215 | ||
d62a17ae | 1216 | void ospf_vl_shut_unapproved(struct ospf *ospf) |
718e3744 | 1217 | { |
d62a17ae | 1218 | struct listnode *node, *nnode; |
1219 | struct ospf_vl_data *vl_data; | |
718e3744 | 1220 | |
d62a17ae | 1221 | for (ALL_LIST_ELEMENTS(ospf->vlinks, node, nnode, vl_data)) |
1222 | if (!CHECK_FLAG(vl_data->flags, OSPF_VL_FLAG_APPROVED)) | |
1223 | ospf_vl_shutdown(vl_data); | |
718e3744 | 1224 | } |
1225 | ||
d62a17ae | 1226 | int ospf_full_virtual_nbrs(struct ospf_area *area) |
718e3744 | 1227 | { |
d62a17ae | 1228 | if (IS_DEBUG_OSPF_EVENT) { |
1229 | zlog_debug( | |
96b663a3 MS |
1230 | "counting fully adjacent virtual neighbors in area %pI4", |
1231 | &area->area_id); | |
d62a17ae | 1232 | zlog_debug("there are %d of them", area->full_vls); |
1233 | } | |
1234 | ||
1235 | return area->full_vls; | |
718e3744 | 1236 | } |
1237 | ||
d62a17ae | 1238 | int ospf_vls_in_area(struct ospf_area *area) |
718e3744 | 1239 | { |
d62a17ae | 1240 | struct listnode *node; |
1241 | struct ospf_vl_data *vl_data; | |
1242 | int c = 0; | |
718e3744 | 1243 | |
d62a17ae | 1244 | for (ALL_LIST_ELEMENTS_RO(area->ospf->vlinks, node, vl_data)) |
1245 | if (IPV4_ADDR_SAME(&vl_data->vl_area_id, &area->area_id)) | |
1246 | c++; | |
718e3744 | 1247 | |
d62a17ae | 1248 | return c; |
718e3744 | 1249 | } |
1250 | ||
6b0655a2 | 1251 | |
4d762f26 | 1252 | struct crypt_key *ospf_crypt_key_new(void) |
718e3744 | 1253 | { |
d62a17ae | 1254 | return XCALLOC(MTYPE_OSPF_CRYPT_KEY, sizeof(struct crypt_key)); |
718e3744 | 1255 | } |
1256 | ||
d62a17ae | 1257 | void ospf_crypt_key_add(struct list *crypt, struct crypt_key *ck) |
718e3744 | 1258 | { |
d62a17ae | 1259 | listnode_add(crypt, ck); |
718e3744 | 1260 | } |
1261 | ||
d7c0a89a | 1262 | struct crypt_key *ospf_crypt_key_lookup(struct list *auth_crypt, uint8_t key_id) |
718e3744 | 1263 | { |
d62a17ae | 1264 | struct listnode *node; |
1265 | struct crypt_key *ck; | |
718e3744 | 1266 | |
d62a17ae | 1267 | for (ALL_LIST_ELEMENTS_RO(auth_crypt, node, ck)) |
1268 | if (ck->key_id == key_id) | |
1269 | return ck; | |
718e3744 | 1270 | |
d62a17ae | 1271 | return NULL; |
718e3744 | 1272 | } |
1273 | ||
d7c0a89a | 1274 | int ospf_crypt_key_delete(struct list *auth_crypt, uint8_t key_id) |
718e3744 | 1275 | { |
d62a17ae | 1276 | struct listnode *node, *nnode; |
1277 | struct crypt_key *ck; | |
1278 | ||
1279 | for (ALL_LIST_ELEMENTS(auth_crypt, node, nnode, ck)) { | |
1280 | if (ck->key_id == key_id) { | |
1281 | listnode_delete(auth_crypt, ck); | |
1282 | XFREE(MTYPE_OSPF_CRYPT_KEY, ck); | |
1283 | return 1; | |
1284 | } | |
1285 | } | |
1286 | ||
1287 | return 0; | |
718e3744 | 1288 | } |
1289 | ||
d7c0a89a | 1290 | uint8_t ospf_default_iftype(struct interface *ifp) |
bc18d616 | 1291 | { |
d62a17ae | 1292 | if (if_is_pointopoint(ifp)) |
1293 | return OSPF_IFTYPE_POINTOPOINT; | |
0c74bbe0 | 1294 | else if (if_is_loopback(ifp) || if_is_vrf(ifp)) |
d62a17ae | 1295 | return OSPF_IFTYPE_LOOPBACK; |
1296 | else | |
1297 | return OSPF_IFTYPE_BROADCAST; | |
bc18d616 | 1298 | } |
1299 | ||
ef7bd2a3 DS |
1300 | void ospf_if_interface(struct interface *ifp) |
1301 | { | |
1302 | hook_call(ospf_if_update, ifp); | |
1303 | } | |
1304 | ||
cbf32f74 | 1305 | uint32_t ospf_if_count_area_params(struct interface *ifp) |
138c5a74 | 1306 | { |
cbf15681 IR |
1307 | struct ospf_if_params *params; |
1308 | struct route_node *rn; | |
1309 | uint32_t count = 0; | |
cbf32f74 IR |
1310 | |
1311 | params = IF_DEF_PARAMS(ifp); | |
1312 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) | |
1313 | count++; | |
1314 | ||
1315 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn)) | |
1316 | if ((params = rn->info) | |
1317 | && OSPF_IF_PARAM_CONFIGURED(params, if_area)) | |
1318 | count++; | |
1319 | ||
1320 | return count; | |
1321 | } | |
1322 | ||
1323 | static int ospf_ifp_create(struct interface *ifp) | |
1324 | { | |
1325 | struct ospf *ospf = NULL; | |
2655301d | 1326 | struct ospf_if_info *oii; |
ef7bd2a3 DS |
1327 | |
1328 | if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) | |
1329 | zlog_debug( | |
1330 | "Zebra: interface add %s vrf %s[%u] index %d flags %llx metric %d mtu %d speed %u", | |
1331 | ifp->name, ospf_vrf_id_to_name(ifp->vrf_id), | |
1332 | ifp->vrf_id, ifp->ifindex, | |
1333 | (unsigned long long)ifp->flags, ifp->metric, ifp->mtu, | |
1334 | ifp->speed); | |
1335 | ||
1336 | assert(ifp->info); | |
1337 | ||
2655301d DS |
1338 | oii = ifp->info; |
1339 | oii->curr_mtu = ifp->mtu; | |
1340 | ||
ef7bd2a3 DS |
1341 | if (IF_DEF_PARAMS(ifp) |
1342 | && !OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), type)) { | |
1343 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
1344 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); | |
1345 | } | |
1346 | ||
1347 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
1348 | if (!ospf) | |
1349 | return 0; | |
1350 | ||
cbf32f74 | 1351 | if (ospf_if_count_area_params(ifp) > 0) |
cbf15681 | 1352 | ospf_interface_area_set(ospf, ifp); |
cbf15681 | 1353 | |
ef7bd2a3 DS |
1354 | ospf_if_recalculate_output_cost(ifp); |
1355 | ||
1356 | ospf_if_update(ospf, ifp); | |
1357 | ||
0b4124c1 KS |
1358 | if (HAS_LINK_PARAMS(ifp)) |
1359 | ospf_mpls_te_update_if(ifp); | |
1360 | ||
ef7bd2a3 DS |
1361 | hook_call(ospf_if_update, ifp); |
1362 | ||
138c5a74 DS |
1363 | return 0; |
1364 | } | |
1365 | ||
1366 | static int ospf_ifp_up(struct interface *ifp) | |
1367 | { | |
ddbf3e60 DS |
1368 | struct ospf_interface *oi; |
1369 | struct route_node *rn; | |
85d25587 | 1370 | struct ospf_if_info *oii = ifp->info; |
ddbf3e60 | 1371 | |
85d25587 | 1372 | ospf_if_recalculate_output_cost(ifp); |
ddbf3e60 | 1373 | |
85d25587 | 1374 | if (oii && oii->curr_mtu != ifp->mtu) { |
ddbf3e60 DS |
1375 | if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) |
1376 | zlog_debug( | |
85d25587 DS |
1377 | "Zebra: Interface[%s] MTU change %u -> %u.", |
1378 | ifp->name, oii->curr_mtu, ifp->mtu); | |
ddbf3e60 | 1379 | |
85d25587 DS |
1380 | oii->curr_mtu = ifp->mtu; |
1381 | /* Must reset the interface (simulate down/up) when MTU | |
1382 | * changes. */ | |
1383 | ospf_if_reset(ifp); | |
ddbf3e60 | 1384 | |
ddbf3e60 DS |
1385 | return 0; |
1386 | } | |
1387 | ||
1388 | if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) | |
1389 | zlog_debug("Zebra: Interface[%s] state change to up.", | |
1390 | ifp->name); | |
1391 | ||
1392 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
1393 | if ((oi = rn->info) == NULL) | |
1394 | continue; | |
1395 | ||
1396 | ospf_if_up(oi); | |
1397 | } | |
1398 | ||
0b4124c1 KS |
1399 | if (HAS_LINK_PARAMS(ifp)) |
1400 | ospf_mpls_te_update_if(ifp); | |
1401 | ||
138c5a74 DS |
1402 | return 0; |
1403 | } | |
1404 | ||
1405 | static int ospf_ifp_down(struct interface *ifp) | |
1406 | { | |
b0b69e59 DS |
1407 | struct ospf_interface *oi; |
1408 | struct route_node *node; | |
1409 | ||
1410 | if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) | |
1411 | zlog_debug("Zebra: Interface[%s] state change to down.", | |
1412 | ifp->name); | |
1413 | ||
1414 | for (node = route_top(IF_OIFS(ifp)); node; node = route_next(node)) { | |
1415 | if ((oi = node->info) == NULL) | |
1416 | continue; | |
1417 | ospf_if_down(oi); | |
1418 | } | |
1419 | ||
138c5a74 DS |
1420 | return 0; |
1421 | } | |
1422 | ||
1423 | static int ospf_ifp_destroy(struct interface *ifp) | |
1424 | { | |
cbf15681 | 1425 | struct ospf *ospf; |
3c3c3252 DS |
1426 | struct route_node *rn; |
1427 | ||
1428 | if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) | |
1429 | zlog_debug( | |
1430 | "Zebra: interface delete %s vrf %s[%u] index %d flags %llx metric %d mtu %d", | |
1431 | ifp->name, ospf_vrf_id_to_name(ifp->vrf_id), | |
1432 | ifp->vrf_id, ifp->ifindex, | |
1433 | (unsigned long long)ifp->flags, ifp->metric, ifp->mtu); | |
1434 | ||
1435 | hook_call(ospf_if_delete, ifp); | |
1436 | ||
cbf15681 IR |
1437 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
1438 | if (ospf) { | |
cbf32f74 | 1439 | if (ospf_if_count_area_params(ifp) > 0) |
cbf15681 | 1440 | ospf_interface_area_unset(ospf, ifp); |
cbf15681 IR |
1441 | } |
1442 | ||
3c3c3252 DS |
1443 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
1444 | if (rn->info) | |
1445 | ospf_if_free((struct ospf_interface *)rn->info); | |
1446 | ||
138c5a74 DS |
1447 | return 0; |
1448 | } | |
1449 | ||
be418160 | 1450 | /* Resetting ospf hello timer */ |
1451 | void ospf_reset_hello_timer(struct interface *ifp, struct in_addr addr, | |
1452 | bool is_addr) | |
1453 | { | |
1454 | struct route_node *rn; | |
1455 | ||
1456 | if (is_addr) { | |
1457 | struct prefix p; | |
1458 | struct ospf_interface *oi = NULL; | |
1459 | ||
1460 | p.u.prefix4 = addr; | |
1461 | p.family = AF_INET; | |
46a8c343 | 1462 | p.prefixlen = IPV4_MAX_BITLEN; |
be418160 | 1463 | |
1464 | oi = ospf_if_table_lookup(ifp, &p); | |
1465 | ||
1466 | if (oi) { | |
1467 | /* Send hello before restart the hello timer | |
1468 | * to avoid session flaps in case of bigger | |
1469 | * hello interval configurations. | |
1470 | */ | |
1471 | ospf_hello_send(oi); | |
1472 | ||
1473 | /* Restart hello timer for this interface */ | |
1474 | OSPF_ISM_TIMER_OFF(oi->t_hello); | |
1475 | OSPF_HELLO_TIMER_ON(oi); | |
1476 | } | |
1477 | ||
1478 | return; | |
1479 | } | |
1480 | ||
1481 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
1482 | struct ospf_interface *oi = rn->info; | |
1483 | ||
1484 | if (!oi) | |
1485 | continue; | |
1486 | ||
1487 | /* If hello interval configured on this oi, don't restart. */ | |
1488 | if (OSPF_IF_PARAM_CONFIGURED(oi->params, v_hello)) | |
1489 | continue; | |
1490 | ||
1491 | /* Send hello before restart the hello timer | |
1492 | * to avoid session flaps in case of bigger | |
1493 | * hello interval configurations. | |
1494 | */ | |
1495 | ospf_hello_send(oi); | |
1496 | ||
1497 | /* Restart the hello timer. */ | |
1498 | OSPF_ISM_TIMER_OFF(oi->t_hello); | |
1499 | OSPF_HELLO_TIMER_ON(oi); | |
1500 | } | |
1501 | } | |
1502 | ||
4d762f26 | 1503 | void ospf_if_init(void) |
718e3744 | 1504 | { |
138c5a74 DS |
1505 | if_zapi_callbacks(ospf_ifp_create, ospf_ifp_up, |
1506 | ospf_ifp_down, ospf_ifp_destroy); | |
1507 | ||
d62a17ae | 1508 | /* Initialize Zebra interface data structure. */ |
ce19a04a DL |
1509 | hook_register_prio(if_add, 0, ospf_if_new_hook); |
1510 | hook_register_prio(if_del, 0, ospf_if_delete_hook); | |
718e3744 | 1511 | } |