]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_neighbor.c
Merge pull request #1120 from donaldsharp/branch_million
[mirror_frr.git] / pimd / pim_neighbor.c
1 /*
2 * PIM for Quagga
3 * Copyright (C) 2008 Everton da Silva Marques
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include <zebra.h>
21
22 #include "log.h"
23 #include "prefix.h"
24 #include "memory.h"
25 #include "if.h"
26 #include "vty.h"
27 #include "plist.h"
28
29 #include "pimd.h"
30 #include "pim_neighbor.h"
31 #include "pim_time.h"
32 #include "pim_str.h"
33 #include "pim_iface.h"
34 #include "pim_pim.h"
35 #include "pim_upstream.h"
36 #include "pim_ifchannel.h"
37 #include "pim_rp.h"
38 #include "pim_zebra.h"
39 #include "pim_join.h"
40 #include "pim_jp_agg.h"
41 #include "pim_bfd.h"
42
43 static void dr_election_by_addr(struct interface *ifp)
44 {
45 struct pim_interface *pim_ifp;
46 struct listnode *node;
47 struct pim_neighbor *neigh;
48
49 pim_ifp = ifp->info;
50 zassert(pim_ifp);
51
52 pim_ifp->pim_dr_addr = pim_ifp->primary_address;
53
54 if (PIM_DEBUG_PIM_TRACE) {
55 zlog_debug("%s: on interface %s", __PRETTY_FUNCTION__,
56 ifp->name);
57 }
58
59 for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) {
60 if (ntohl(neigh->source_addr.s_addr)
61 > ntohl(pim_ifp->pim_dr_addr.s_addr)) {
62 pim_ifp->pim_dr_addr = neigh->source_addr;
63 }
64 }
65 }
66
67 static void dr_election_by_pri(struct interface *ifp)
68 {
69 struct pim_interface *pim_ifp;
70 struct listnode *node;
71 struct pim_neighbor *neigh;
72 uint32_t dr_pri;
73
74 pim_ifp = ifp->info;
75 zassert(pim_ifp);
76
77 pim_ifp->pim_dr_addr = pim_ifp->primary_address;
78 dr_pri = pim_ifp->pim_dr_priority;
79
80 if (PIM_DEBUG_PIM_TRACE) {
81 zlog_debug("%s: dr pri %u on interface %s", __PRETTY_FUNCTION__,
82 dr_pri, ifp->name);
83 }
84
85 for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) {
86 if (PIM_DEBUG_PIM_TRACE) {
87 zlog_info("%s: neigh pri %u addr %x if dr addr %x",
88 __PRETTY_FUNCTION__, neigh->dr_priority,
89 ntohl(neigh->source_addr.s_addr),
90 ntohl(pim_ifp->pim_dr_addr.s_addr));
91 }
92 if ((neigh->dr_priority > dr_pri)
93 || ((neigh->dr_priority == dr_pri)
94 && (ntohl(neigh->source_addr.s_addr)
95 > ntohl(pim_ifp->pim_dr_addr.s_addr)))) {
96 pim_ifp->pim_dr_addr = neigh->source_addr;
97 dr_pri = neigh->dr_priority;
98 }
99 }
100 }
101
102 /*
103 RFC 4601: 4.3.2. DR Election
104
105 A router's idea of the current DR on an interface can change when a
106 PIM Hello message is received, when a neighbor times out, or when a
107 router's own DR Priority changes.
108 */
109 int pim_if_dr_election(struct interface *ifp)
110 {
111 struct pim_interface *pim_ifp = ifp->info;
112 struct in_addr old_dr_addr;
113
114 ++pim_ifp->pim_dr_election_count;
115
116 old_dr_addr = pim_ifp->pim_dr_addr;
117
118 if (pim_ifp->pim_dr_num_nondrpri_neighbors) {
119 dr_election_by_addr(ifp);
120 } else {
121 dr_election_by_pri(ifp);
122 }
123
124 /* DR changed ? */
125 if (old_dr_addr.s_addr != pim_ifp->pim_dr_addr.s_addr) {
126
127 if (PIM_DEBUG_PIM_EVENTS) {
128 char dr_old_str[INET_ADDRSTRLEN];
129 char dr_new_str[INET_ADDRSTRLEN];
130 pim_inet4_dump("<old_dr?>", old_dr_addr, dr_old_str,
131 sizeof(dr_old_str));
132 pim_inet4_dump("<new_dr?>", pim_ifp->pim_dr_addr,
133 dr_new_str, sizeof(dr_new_str));
134 zlog_debug("%s: DR was %s now is %s on interface %s",
135 __PRETTY_FUNCTION__, dr_old_str, dr_new_str,
136 ifp->name);
137 }
138
139 pim_ifp->pim_dr_election_last =
140 pim_time_monotonic_sec(); /* timestamp */
141 ++pim_ifp->pim_dr_election_changes;
142 pim_if_update_join_desired(pim_ifp);
143 pim_if_update_could_assert(ifp);
144 pim_if_update_assert_tracking_desired(ifp);
145 return 1;
146 }
147
148 return 0;
149 }
150
151 static void update_dr_priority(struct pim_neighbor *neigh,
152 pim_hello_options hello_options,
153 uint32_t dr_priority)
154 {
155 pim_hello_options will_set_pri; /* boolean */
156 pim_hello_options bit_flip; /* boolean */
157 pim_hello_options pri_change; /* boolean */
158
159 will_set_pri =
160 PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_DR_PRIORITY);
161
162 bit_flip = (will_set_pri
163 != PIM_OPTION_IS_SET(neigh->hello_options,
164 PIM_OPTION_MASK_DR_PRIORITY));
165
166 if (bit_flip) {
167 struct pim_interface *pim_ifp = neigh->interface->info;
168
169 /* update num. of neighbors without dr_pri */
170
171 if (will_set_pri) {
172 --pim_ifp->pim_dr_num_nondrpri_neighbors;
173 } else {
174 ++pim_ifp->pim_dr_num_nondrpri_neighbors;
175 }
176 }
177
178 pri_change = (bit_flip || (neigh->dr_priority != dr_priority));
179
180 if (will_set_pri) {
181 neigh->dr_priority = dr_priority;
182 } else {
183 neigh->dr_priority = 0; /* cosmetic unset */
184 }
185
186 if (pri_change) {
187 /*
188 RFC 4601: 4.3.2. DR Election
189
190 A router's idea of the current DR on an interface can change
191 when a
192 PIM Hello message is received, when a neighbor times out, or
193 when a
194 router's own DR Priority changes.
195 */
196 pim_if_dr_election(
197 neigh->interface); // router's own DR Priority changes
198 }
199 }
200
201 static int on_neighbor_timer(struct thread *t)
202 {
203 struct pim_neighbor *neigh;
204 struct interface *ifp;
205 char msg[100];
206
207 neigh = THREAD_ARG(t);
208
209 ifp = neigh->interface;
210
211 if (PIM_DEBUG_PIM_TRACE) {
212 char src_str[INET_ADDRSTRLEN];
213 pim_inet4_dump("<src?>", neigh->source_addr, src_str,
214 sizeof(src_str));
215 zlog_debug(
216 "Expired %d sec holdtime for neighbor %s on interface %s",
217 neigh->holdtime, src_str, ifp->name);
218 }
219
220 snprintf(msg, sizeof(msg), "%d-sec holdtime expired", neigh->holdtime);
221 pim_neighbor_delete(ifp, neigh, msg);
222
223 /*
224 RFC 4601: 4.3.2. DR Election
225
226 A router's idea of the current DR on an interface can change when a
227 PIM Hello message is received, when a neighbor times out, or when a
228 router's own DR Priority changes.
229 */
230 pim_if_dr_election(ifp); // neighbor times out
231
232 return 0;
233 }
234
235 void pim_neighbor_timer_reset(struct pim_neighbor *neigh, uint16_t holdtime)
236 {
237 neigh->holdtime = holdtime;
238
239 THREAD_OFF(neigh->t_expire_timer);
240
241 /*
242 0xFFFF is request for no holdtime
243 */
244 if (neigh->holdtime == 0xFFFF) {
245 return;
246 }
247
248 if (PIM_DEBUG_PIM_TRACE_DETAIL) {
249 char src_str[INET_ADDRSTRLEN];
250 pim_inet4_dump("<src?>", neigh->source_addr, src_str,
251 sizeof(src_str));
252 zlog_debug("%s: starting %u sec timer for neighbor %s on %s",
253 __PRETTY_FUNCTION__, neigh->holdtime, src_str,
254 neigh->interface->name);
255 }
256
257 thread_add_timer(master, on_neighbor_timer, neigh, neigh->holdtime,
258 &neigh->t_expire_timer);
259 }
260
261 static int on_neighbor_jp_timer(struct thread *t)
262 {
263 struct pim_neighbor *neigh = THREAD_ARG(t);
264 struct pim_rpf rpf;
265
266 if (PIM_DEBUG_PIM_TRACE) {
267 char src_str[INET_ADDRSTRLEN];
268 pim_inet4_dump("<src?>", neigh->source_addr, src_str,
269 sizeof(src_str));
270 zlog_debug("%s:Sending JP Agg to %s on %s with %d groups",
271 __PRETTY_FUNCTION__, src_str, neigh->interface->name,
272 neigh->upstream_jp_agg->count);
273 }
274
275 rpf.source_nexthop.interface = neigh->interface;
276 rpf.rpf_addr.u.prefix4 = neigh->source_addr;
277 pim_joinprune_send(&rpf, neigh->upstream_jp_agg);
278
279 thread_add_timer(master, on_neighbor_jp_timer, neigh, qpim_t_periodic,
280 &neigh->jp_timer);
281
282 return 0;
283 }
284
285 static void pim_neighbor_start_jp_timer(struct pim_neighbor *neigh)
286 {
287 THREAD_TIMER_OFF(neigh->jp_timer);
288 thread_add_timer(master, on_neighbor_jp_timer, neigh, qpim_t_periodic,
289 &neigh->jp_timer);
290 }
291
292 static struct pim_neighbor *
293 pim_neighbor_new(struct interface *ifp, struct in_addr source_addr,
294 pim_hello_options hello_options, uint16_t holdtime,
295 uint16_t propagation_delay, uint16_t override_interval,
296 uint32_t dr_priority, uint32_t generation_id,
297 struct list *addr_list)
298 {
299 struct pim_interface *pim_ifp;
300 struct pim_neighbor *neigh;
301 char src_str[INET_ADDRSTRLEN];
302
303 zassert(ifp);
304 pim_ifp = ifp->info;
305 zassert(pim_ifp);
306
307 neigh = XCALLOC(MTYPE_PIM_NEIGHBOR, sizeof(*neigh));
308 if (!neigh) {
309 zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__,
310 sizeof(*neigh));
311 return 0;
312 }
313
314 neigh->creation = pim_time_monotonic_sec();
315 neigh->source_addr = source_addr;
316 neigh->hello_options = hello_options;
317 neigh->propagation_delay_msec = propagation_delay;
318 neigh->override_interval_msec = override_interval;
319 neigh->dr_priority = dr_priority;
320 neigh->generation_id = generation_id;
321 neigh->prefix_list = addr_list;
322 neigh->t_expire_timer = NULL;
323 neigh->interface = ifp;
324
325 neigh->upstream_jp_agg = list_new();
326 neigh->upstream_jp_agg->cmp = pim_jp_agg_group_list_cmp;
327 neigh->upstream_jp_agg->del =
328 (void (*)(void *))pim_jp_agg_group_list_free;
329 pim_neighbor_start_jp_timer(neigh);
330
331 pim_neighbor_timer_reset(neigh, holdtime);
332 /*
333 * The pim_ifstat_hello_sent variable is used to decide if
334 * we should expedite a hello out the interface. If we
335 * establish a new neighbor, we unfortunately need to
336 * reset the value so that we can know to hurry up and
337 * hello
338 */
339 pim_ifp->pim_ifstat_hello_sent = 0;
340
341 pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
342
343 if (PIM_DEBUG_PIM_EVENTS) {
344 zlog_debug("%s: creating PIM neighbor %s on interface %s",
345 __PRETTY_FUNCTION__, src_str, ifp->name);
346 }
347
348 zlog_info("PIM NEIGHBOR UP: neighbor %s on interface %s", src_str,
349 ifp->name);
350
351 if (neigh->propagation_delay_msec
352 > pim_ifp->pim_neighbors_highest_propagation_delay_msec) {
353 pim_ifp->pim_neighbors_highest_propagation_delay_msec =
354 neigh->propagation_delay_msec;
355 }
356 if (neigh->override_interval_msec
357 > pim_ifp->pim_neighbors_highest_override_interval_msec) {
358 pim_ifp->pim_neighbors_highest_override_interval_msec =
359 neigh->override_interval_msec;
360 }
361
362 if (!PIM_OPTION_IS_SET(neigh->hello_options,
363 PIM_OPTION_MASK_LAN_PRUNE_DELAY)) {
364 /* update num. of neighbors without hello option lan_delay */
365 ++pim_ifp->pim_number_of_nonlandelay_neighbors;
366 }
367
368 if (!PIM_OPTION_IS_SET(neigh->hello_options,
369 PIM_OPTION_MASK_DR_PRIORITY)) {
370 /* update num. of neighbors without hello option dr_pri */
371 ++pim_ifp->pim_dr_num_nondrpri_neighbors;
372 }
373
374 // Register PIM Neighbor with BFD
375 pim_bfd_trigger_event(pim_ifp, neigh, 1);
376
377 return neigh;
378 }
379
380 static void delete_prefix_list(struct pim_neighbor *neigh)
381 {
382 if (neigh->prefix_list) {
383
384 #ifdef DUMP_PREFIX_LIST
385 struct listnode *p_node;
386 struct prefix *p;
387 char addr_str[10];
388 int list_size = neigh->prefix_list
389 ? (int)listcount(neigh->prefix_list)
390 : -1;
391 int i = 0;
392 for (ALL_LIST_ELEMENTS_RO(neigh->prefix_list, p_node, p)) {
393 pim_inet4_dump("<addr?>", p->u.prefix4, addr_str,
394 sizeof(addr_str));
395 zlog_debug(
396 "%s: DUMP_PREFIX_LIST neigh=%x prefix_list=%x prefix=%x addr=%s [%d/%d]",
397 __PRETTY_FUNCTION__, (unsigned)neigh,
398 (unsigned)neigh->prefix_list, (unsigned)p,
399 addr_str, i, list_size);
400 ++i;
401 }
402 #endif
403
404 list_delete_and_null(&neigh->prefix_list);
405 }
406 }
407
408 void pim_neighbor_free(struct pim_neighbor *neigh)
409 {
410 zassert(!neigh->t_expire_timer);
411
412 delete_prefix_list(neigh);
413
414 list_delete_and_null(&neigh->upstream_jp_agg);
415 THREAD_OFF(neigh->jp_timer);
416
417 XFREE(MTYPE_PIM_NEIGHBOR, neigh);
418 }
419
420 struct pim_neighbor *pim_neighbor_find_by_secondary(struct interface *ifp,
421 struct prefix *src)
422 {
423 struct pim_interface *pim_ifp;
424 struct listnode *node, *pnode;
425 struct pim_neighbor *neigh;
426 struct prefix *p;
427
428 pim_ifp = ifp->info;
429 if (!pim_ifp)
430 return NULL;
431
432 for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) {
433 for (ALL_LIST_ELEMENTS_RO(neigh->prefix_list, pnode, p)) {
434 if (prefix_same(p, src))
435 return neigh;
436 }
437 }
438
439 return NULL;
440 }
441
442 struct pim_neighbor *pim_neighbor_find(struct interface *ifp,
443 struct in_addr source_addr)
444 {
445 struct pim_interface *pim_ifp;
446 struct listnode *node;
447 struct pim_neighbor *neigh;
448
449 if (!ifp)
450 return NULL;
451
452 pim_ifp = ifp->info;
453 if (!pim_ifp)
454 return NULL;
455
456 for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) {
457 if (source_addr.s_addr == neigh->source_addr.s_addr) {
458 return neigh;
459 }
460 }
461
462 return NULL;
463 }
464
465 /*
466 * Find the *one* interface out
467 * this interface. If more than
468 * one return NULL
469 */
470 struct pim_neighbor *pim_neighbor_find_if(struct interface *ifp)
471 {
472 struct pim_interface *pim_ifp = ifp->info;
473
474 if (!pim_ifp || pim_ifp->pim_neighbor_list->count != 1)
475 return NULL;
476
477 return listnode_head(pim_ifp->pim_neighbor_list);
478 }
479
480 /* rpf info associated with an upstream entry needs to be re-evaluated
481 * when an RPF neighbor comes or goes */
482 static void pim_neighbor_rpf_update(void)
483 {
484 /* XXX: for the time being piggyback on the timer used on rib changes
485 * to scan and update the rpf nexthop. This is expensive processing
486 * and we should be able to optimize neighbor changes differently than
487 * nexthop changes. */
488 sched_rpf_cache_refresh();
489 }
490
491 struct pim_neighbor *
492 pim_neighbor_add(struct interface *ifp, struct in_addr source_addr,
493 pim_hello_options hello_options, uint16_t holdtime,
494 uint16_t propagation_delay, uint16_t override_interval,
495 uint32_t dr_priority, uint32_t generation_id,
496 struct list *addr_list, int send_hello_now)
497 {
498 struct pim_interface *pim_ifp;
499 struct pim_neighbor *neigh;
500
501 neigh = pim_neighbor_new(ifp, source_addr, hello_options, holdtime,
502 propagation_delay, override_interval,
503 dr_priority, generation_id, addr_list);
504 if (!neigh) {
505 return 0;
506 }
507
508 pim_ifp = ifp->info;
509 zassert(pim_ifp);
510
511 listnode_add(pim_ifp->pim_neighbor_list, neigh);
512
513 if (PIM_DEBUG_PIM_TRACE_DETAIL) {
514 char str[INET_ADDRSTRLEN];
515 pim_inet4_dump("<nht_nbr?>", source_addr, str, sizeof(str));
516 zlog_debug("%s: neighbor %s added ", __PRETTY_FUNCTION__, str);
517 }
518 /*
519 RFC 4601: 4.3.2. DR Election
520
521 A router's idea of the current DR on an interface can change when a
522 PIM Hello message is received, when a neighbor times out, or when a
523 router's own DR Priority changes.
524 */
525 pim_if_dr_election(neigh->interface); // new neighbor -- should not
526 // trigger dr election...
527
528 /*
529 RFC 4601: 4.3.1. Sending Hello Messages
530
531 To allow new or rebooting routers to learn of PIM neighbors quickly,
532 when a Hello message is received from a new neighbor, or a Hello
533 message with a new GenID is received from an existing neighbor, a
534 new Hello message should be sent on this interface after a
535 randomized delay between 0 and Triggered_Hello_Delay.
536
537 This is a bit silly to do it that way. If I get a new
538 genid we need to send the hello *now* because we've
539 lined up a bunch of join/prune messages to go out the
540 interface.
541 */
542 if (send_hello_now)
543 pim_hello_restart_now(ifp);
544 else
545 pim_hello_restart_triggered(neigh->interface);
546
547 pim_upstream_find_new_rpf(pim_ifp->pim);
548
549 /* RNH can send nexthop update prior to PIM neibhor UP
550 in that case nexthop cache would not consider this neighbor
551 as RPF.
552 Upon PIM neighbor UP, iterate all RPs and update
553 nexthop cache with this neighbor.
554 */
555 pim_resolve_rp_nh(pim_ifp->pim);
556
557 pim_rp_setup(pim_ifp->pim);
558
559 pim_neighbor_rpf_update();
560 return neigh;
561 }
562
563 static uint16_t find_neighbors_next_highest_propagation_delay_msec(
564 struct interface *ifp, struct pim_neighbor *highest_neigh)
565 {
566 struct pim_interface *pim_ifp;
567 struct listnode *neigh_node;
568 struct pim_neighbor *neigh;
569 uint16_t next_highest_delay_msec;
570
571 pim_ifp = ifp->info;
572 zassert(pim_ifp);
573
574 next_highest_delay_msec = pim_ifp->pim_propagation_delay_msec;
575
576 for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neigh_node,
577 neigh)) {
578 if (neigh == highest_neigh)
579 continue;
580 if (neigh->propagation_delay_msec > next_highest_delay_msec)
581 next_highest_delay_msec = neigh->propagation_delay_msec;
582 }
583
584 return next_highest_delay_msec;
585 }
586
587 static uint16_t find_neighbors_next_highest_override_interval_msec(
588 struct interface *ifp, struct pim_neighbor *highest_neigh)
589 {
590 struct pim_interface *pim_ifp;
591 struct listnode *neigh_node;
592 struct pim_neighbor *neigh;
593 uint16_t next_highest_interval_msec;
594
595 pim_ifp = ifp->info;
596 zassert(pim_ifp);
597
598 next_highest_interval_msec = pim_ifp->pim_override_interval_msec;
599
600 for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neigh_node,
601 neigh)) {
602 if (neigh == highest_neigh)
603 continue;
604 if (neigh->override_interval_msec > next_highest_interval_msec)
605 next_highest_interval_msec =
606 neigh->override_interval_msec;
607 }
608
609 return next_highest_interval_msec;
610 }
611
612 void pim_neighbor_delete(struct interface *ifp, struct pim_neighbor *neigh,
613 const char *delete_message)
614 {
615 struct pim_interface *pim_ifp;
616 char src_str[INET_ADDRSTRLEN];
617
618 pim_ifp = ifp->info;
619 zassert(pim_ifp);
620
621 pim_inet4_dump("<src?>", neigh->source_addr, src_str, sizeof(src_str));
622 zlog_info("PIM NEIGHBOR DOWN: neighbor %s on interface %s: %s", src_str,
623 ifp->name, delete_message);
624
625 THREAD_OFF(neigh->t_expire_timer);
626
627 pim_if_assert_on_neighbor_down(ifp, neigh->source_addr);
628
629 if (!PIM_OPTION_IS_SET(neigh->hello_options,
630 PIM_OPTION_MASK_LAN_PRUNE_DELAY)) {
631 /* update num. of neighbors without hello option lan_delay */
632
633 --pim_ifp->pim_number_of_nonlandelay_neighbors;
634 }
635
636 if (!PIM_OPTION_IS_SET(neigh->hello_options,
637 PIM_OPTION_MASK_DR_PRIORITY)) {
638 /* update num. of neighbors without dr_pri */
639
640 --pim_ifp->pim_dr_num_nondrpri_neighbors;
641 }
642
643 zassert(neigh->propagation_delay_msec
644 <= pim_ifp->pim_neighbors_highest_propagation_delay_msec);
645 zassert(neigh->override_interval_msec
646 <= pim_ifp->pim_neighbors_highest_override_interval_msec);
647
648 if (pim_if_lan_delay_enabled(ifp)) {
649
650 /* will delete a neighbor with highest propagation delay? */
651 if (neigh->propagation_delay_msec
652 == pim_ifp->pim_neighbors_highest_propagation_delay_msec) {
653 /* then find the next highest propagation delay */
654 pim_ifp->pim_neighbors_highest_propagation_delay_msec =
655 find_neighbors_next_highest_propagation_delay_msec(
656 ifp, neigh);
657 }
658
659 /* will delete a neighbor with highest override interval? */
660 if (neigh->override_interval_msec
661 == pim_ifp->pim_neighbors_highest_override_interval_msec) {
662 /* then find the next highest propagation delay */
663 pim_ifp->pim_neighbors_highest_override_interval_msec =
664 find_neighbors_next_highest_override_interval_msec(
665 ifp, neigh);
666 }
667 }
668
669 if (PIM_DEBUG_PIM_TRACE) {
670 zlog_debug("%s: deleting PIM neighbor %s on interface %s",
671 __PRETTY_FUNCTION__, src_str, ifp->name);
672 }
673
674 // De-Register PIM Neighbor with BFD
675 pim_bfd_trigger_event(pim_ifp, neigh, 0);
676
677 listnode_delete(pim_ifp->pim_neighbor_list, neigh);
678
679 pim_neighbor_free(neigh);
680
681 pim_neighbor_rpf_update();
682 }
683
684 void pim_neighbor_delete_all(struct interface *ifp, const char *delete_message)
685 {
686 struct pim_interface *pim_ifp;
687 struct listnode *neigh_node;
688 struct listnode *neigh_nextnode;
689 struct pim_neighbor *neigh;
690
691 pim_ifp = ifp->info;
692 zassert(pim_ifp);
693
694 for (ALL_LIST_ELEMENTS(pim_ifp->pim_neighbor_list, neigh_node,
695 neigh_nextnode, neigh)) {
696 pim_neighbor_delete(ifp, neigh, delete_message);
697 }
698 }
699
700 struct prefix *pim_neighbor_find_secondary(struct pim_neighbor *neigh,
701 struct prefix *addr)
702 {
703 struct listnode *node;
704 struct prefix *p;
705
706 if (!neigh->prefix_list)
707 return 0;
708
709 for (ALL_LIST_ELEMENTS_RO(neigh->prefix_list, node, p)) {
710 if (prefix_same(p, addr))
711 return p;
712 }
713
714 return NULL;
715 }
716
717 /*
718 RFC 4601: 4.3.4. Maintaining Secondary Address Lists
719
720 All the advertised secondary addresses in received Hello messages
721 must be checked against those previously advertised by all other
722 PIM neighbors on that interface. If there is a conflict and the
723 same secondary address was previously advertised by another
724 neighbor, then only the most recently received mapping MUST be
725 maintained, and an error message SHOULD be logged to the
726 administrator in a rate-limited manner.
727 */
728 static void delete_from_neigh_addr(struct interface *ifp,
729 struct list *addr_list,
730 struct in_addr neigh_addr)
731 {
732 struct listnode *addr_node;
733 struct prefix *addr;
734 struct pim_interface *pim_ifp;
735
736 pim_ifp = ifp->info;
737 zassert(pim_ifp);
738
739 zassert(addr_list);
740
741 /*
742 Scan secondary address list
743 */
744 for (ALL_LIST_ELEMENTS_RO(addr_list, addr_node, addr)) {
745 struct listnode *neigh_node;
746 struct pim_neighbor *neigh;
747
748 if (addr->family != AF_INET)
749 continue;
750
751 /*
752 Scan neighbors
753 */
754 for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list,
755 neigh_node, neigh)) {
756 {
757 struct prefix *p = pim_neighbor_find_secondary(
758 neigh, addr);
759 if (p) {
760 char addr_str[INET_ADDRSTRLEN];
761 char this_neigh_str[INET_ADDRSTRLEN];
762 char other_neigh_str[INET_ADDRSTRLEN];
763
764 pim_inet4_dump(
765 "<addr?>", addr->u.prefix4,
766 addr_str, sizeof(addr_str));
767 pim_inet4_dump("<neigh1?>", neigh_addr,
768 this_neigh_str,
769 sizeof(this_neigh_str));
770 pim_inet4_dump("<neigh2?>",
771 neigh->source_addr,
772 other_neigh_str,
773 sizeof(other_neigh_str));
774
775 zlog_info(
776 "secondary addr %s recvd from neigh %s deleted from neigh %s on %s",
777 addr_str, this_neigh_str,
778 other_neigh_str, ifp->name);
779
780 listnode_delete(neigh->prefix_list, p);
781 prefix_free(p);
782 }
783 }
784
785 } /* scan neighbors */
786
787 } /* scan addr list */
788 }
789
790 void pim_neighbor_update(struct pim_neighbor *neigh,
791 pim_hello_options hello_options, uint16_t holdtime,
792 uint32_t dr_priority, struct list *addr_list)
793 {
794 struct pim_interface *pim_ifp = neigh->interface->info;
795
796 /* Received holdtime ? */
797 if (PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_HOLDTIME)) {
798 pim_neighbor_timer_reset(neigh, holdtime);
799 } else {
800 pim_neighbor_timer_reset(neigh,
801 PIM_IF_DEFAULT_HOLDTIME(pim_ifp));
802 }
803
804 #ifdef DUMP_PREFIX_LIST
805 zlog_debug(
806 "%s: DUMP_PREFIX_LIST old_prefix_list=%x old_size=%d new_prefix_list=%x new_size=%d",
807 __PRETTY_FUNCTION__, (unsigned)neigh->prefix_list,
808 neigh->prefix_list ? (int)listcount(neigh->prefix_list) : -1,
809 (unsigned)addr_list,
810 addr_list ? (int)listcount(addr_list) : -1);
811 #endif
812
813 if (neigh->prefix_list == addr_list) {
814 if (addr_list) {
815 zlog_err(
816 "%s: internal error: trying to replace same prefix list=%p",
817 __PRETTY_FUNCTION__, (void *)addr_list);
818 }
819 } else {
820 /* Delete existing secondary address list */
821 delete_prefix_list(neigh);
822 }
823
824 if (addr_list) {
825 delete_from_neigh_addr(neigh->interface, addr_list,
826 neigh->source_addr);
827 }
828
829 /* Replace secondary address list */
830 neigh->prefix_list = addr_list;
831
832 update_dr_priority(neigh, hello_options, dr_priority);
833 /*
834 Copy flags
835 */
836 neigh->hello_options = hello_options;
837 }