]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_rp.c
Merge pull request #5288 from SumitAgarwal123/bfd_docs
[mirror_frr.git] / pimd / pim_rp.c
1 /*
2 * PIM for Quagga
3 * Copyright (C) 2015 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 #include <zebra.h>
21
22 #include "lib/json.h"
23 #include "log.h"
24 #include "network.h"
25 #include "if.h"
26 #include "linklist.h"
27 #include "prefix.h"
28 #include "memory.h"
29 #include "vty.h"
30 #include "vrf.h"
31 #include "plist.h"
32 #include "nexthop.h"
33 #include "table.h"
34 #include "lib_errors.h"
35
36 #include "pimd.h"
37 #include "pim_vty.h"
38 #include "pim_str.h"
39 #include "pim_iface.h"
40 #include "pim_rp.h"
41 #include "pim_str.h"
42 #include "pim_rpf.h"
43 #include "pim_sock.h"
44 #include "pim_memory.h"
45 #include "pim_iface.h"
46 #include "pim_msdp.h"
47 #include "pim_nht.h"
48 #include "pim_mroute.h"
49 #include "pim_oil.h"
50 #include "pim_zebra.h"
51 #include "pim_bsm.h"
52
53 /* Cleanup pim->rpf_hash each node data */
54 void pim_rp_list_hash_clean(void *data)
55 {
56 struct pim_nexthop_cache *pnc = (struct pim_nexthop_cache *)data;
57
58 list_delete(&pnc->rp_list);
59
60 hash_clean(pnc->upstream_hash, NULL);
61 hash_free(pnc->upstream_hash);
62 pnc->upstream_hash = NULL;
63 if (pnc->nexthop)
64 nexthops_free(pnc->nexthop);
65
66 XFREE(MTYPE_PIM_NEXTHOP_CACHE, pnc);
67 }
68
69 static void pim_rp_info_free(struct rp_info *rp_info)
70 {
71 XFREE(MTYPE_PIM_FILTER_NAME, rp_info->plist);
72
73 XFREE(MTYPE_PIM_RP, rp_info);
74 }
75
76 int pim_rp_list_cmp(void *v1, void *v2)
77 {
78 struct rp_info *rp1 = (struct rp_info *)v1;
79 struct rp_info *rp2 = (struct rp_info *)v2;
80
81 /*
82 * Sort by RP IP address
83 */
84 if (rp1->rp.rpf_addr.u.prefix4.s_addr
85 < rp2->rp.rpf_addr.u.prefix4.s_addr)
86 return -1;
87
88 if (rp1->rp.rpf_addr.u.prefix4.s_addr
89 > rp2->rp.rpf_addr.u.prefix4.s_addr)
90 return 1;
91
92 /*
93 * Sort by group IP address
94 */
95 if (rp1->group.u.prefix4.s_addr < rp2->group.u.prefix4.s_addr)
96 return -1;
97
98 if (rp1->group.u.prefix4.s_addr > rp2->group.u.prefix4.s_addr)
99 return 1;
100
101 return 0;
102 }
103
104 void pim_rp_init(struct pim_instance *pim)
105 {
106 struct rp_info *rp_info;
107 struct route_node *rn;
108
109 pim->rp_list = list_new();
110 pim->rp_list->del = (void (*)(void *))pim_rp_info_free;
111 pim->rp_list->cmp = pim_rp_list_cmp;
112
113 pim->rp_table = route_table_init();
114
115 rp_info = XCALLOC(MTYPE_PIM_RP, sizeof(*rp_info));
116
117 if (!str2prefix("224.0.0.0/4", &rp_info->group)) {
118 flog_err(EC_LIB_DEVELOPMENT,
119 "Unable to convert 224.0.0.0/4 to prefix");
120 list_delete(&pim->rp_list);
121 route_table_finish(pim->rp_table);
122 XFREE(MTYPE_PIM_RP, rp_info);
123 return;
124 }
125 rp_info->group.family = AF_INET;
126 rp_info->rp.rpf_addr.family = AF_INET;
127 rp_info->rp.rpf_addr.prefixlen = IPV4_MAX_PREFIXLEN;
128 rp_info->rp.rpf_addr.u.prefix4.s_addr = INADDR_NONE;
129
130 listnode_add(pim->rp_list, rp_info);
131
132 rn = route_node_get(pim->rp_table, &rp_info->group);
133 rn->info = rp_info;
134 if (PIM_DEBUG_PIM_TRACE)
135 zlog_debug(
136 "Allocated: %p for rp_info: %p(224.0.0.0/4) Lock: %d",
137 rn, rp_info, rn->lock);
138 }
139
140 void pim_rp_free(struct pim_instance *pim)
141 {
142 if (pim->rp_list)
143 list_delete(&pim->rp_list);
144 }
145
146 /*
147 * Given an RP's prefix-list, return the RP's rp_info for that prefix-list
148 */
149 static struct rp_info *pim_rp_find_prefix_list(struct pim_instance *pim,
150 struct in_addr rp,
151 const char *plist)
152 {
153 struct listnode *node;
154 struct rp_info *rp_info;
155
156 for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
157 if (rp.s_addr == rp_info->rp.rpf_addr.u.prefix4.s_addr
158 && rp_info->plist && strcmp(rp_info->plist, plist) == 0) {
159 return rp_info;
160 }
161 }
162
163 return NULL;
164 }
165
166 /*
167 * Return true if plist is used by any rp_info
168 */
169 static int pim_rp_prefix_list_used(struct pim_instance *pim, const char *plist)
170 {
171 struct listnode *node;
172 struct rp_info *rp_info;
173
174 for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
175 if (rp_info->plist && strcmp(rp_info->plist, plist) == 0) {
176 return 1;
177 }
178 }
179
180 return 0;
181 }
182
183 /*
184 * Given an RP's address, return the RP's rp_info that is an exact match for
185 * 'group'
186 */
187 static struct rp_info *pim_rp_find_exact(struct pim_instance *pim,
188 struct in_addr rp,
189 const struct prefix *group)
190 {
191 struct listnode *node;
192 struct rp_info *rp_info;
193
194 for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
195 if (rp.s_addr == rp_info->rp.rpf_addr.u.prefix4.s_addr
196 && prefix_same(&rp_info->group, group))
197 return rp_info;
198 }
199
200 return NULL;
201 }
202
203 /*
204 * Given a group, return the rp_info for that group
205 */
206 struct rp_info *pim_rp_find_match_group(struct pim_instance *pim,
207 const struct prefix *group)
208 {
209 struct listnode *node;
210 struct rp_info *best = NULL;
211 struct rp_info *rp_info;
212 struct prefix_list *plist;
213 const struct prefix *p, *bp;
214 struct route_node *rn;
215
216 bp = NULL;
217 for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
218 if (rp_info->plist) {
219 plist = prefix_list_lookup(AFI_IP, rp_info->plist);
220
221 if (prefix_list_apply_which_prefix(plist, &p, group)
222 == PREFIX_DENY)
223 continue;
224
225 if (!best) {
226 best = rp_info;
227 bp = p;
228 continue;
229 }
230
231 if (bp && bp->prefixlen < p->prefixlen) {
232 best = rp_info;
233 bp = p;
234 }
235 }
236 }
237
238 rn = route_node_match(pim->rp_table, group);
239 if (!rn) {
240 flog_err(
241 EC_LIB_DEVELOPMENT,
242 "%s: BUG We should have found default group information\n",
243 __PRETTY_FUNCTION__);
244 return best;
245 }
246
247 rp_info = rn->info;
248 if (PIM_DEBUG_PIM_TRACE) {
249 char buf[PREFIX_STRLEN];
250
251 route_unlock_node(rn);
252 zlog_debug("Lookedup: %p for rp_info: %p(%s) Lock: %d", rn,
253 rp_info,
254 prefix2str(&rp_info->group, buf, sizeof(buf)),
255 rn->lock);
256 }
257
258 if (!best)
259 return rp_info;
260
261 if (rp_info->group.prefixlen < best->group.prefixlen)
262 best = rp_info;
263
264 return best;
265 }
266
267 /*
268 * When the user makes "ip pim rp" configuration changes or if they change the
269 * prefix-list(s) used by these statements we must tickle the upstream state
270 * for each group to make them re-lookup who their RP should be.
271 *
272 * This is a placeholder function for now.
273 */
274 static void pim_rp_refresh_group_to_rp_mapping(struct pim_instance *pim)
275 {
276 pim_msdp_i_am_rp_changed(pim);
277 }
278
279 void pim_rp_prefix_list_update(struct pim_instance *pim,
280 struct prefix_list *plist)
281 {
282 struct listnode *node;
283 struct rp_info *rp_info;
284 int refresh_needed = 0;
285
286 for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
287 if (rp_info->plist
288 && strcmp(rp_info->plist, prefix_list_name(plist)) == 0) {
289 refresh_needed = 1;
290 break;
291 }
292 }
293
294 if (refresh_needed)
295 pim_rp_refresh_group_to_rp_mapping(pim);
296 }
297
298 static int pim_rp_check_interface_addrs(struct rp_info *rp_info,
299 struct pim_interface *pim_ifp)
300 {
301 struct listnode *node;
302 struct pim_secondary_addr *sec_addr;
303
304 if (pim_ifp->primary_address.s_addr
305 == rp_info->rp.rpf_addr.u.prefix4.s_addr)
306 return 1;
307
308 if (!pim_ifp->sec_addr_list) {
309 return 0;
310 }
311
312 for (ALL_LIST_ELEMENTS_RO(pim_ifp->sec_addr_list, node, sec_addr)) {
313 if (prefix_same(&sec_addr->addr, &rp_info->rp.rpf_addr)) {
314 return 1;
315 }
316 }
317
318 return 0;
319 }
320
321 static void pim_rp_check_interfaces(struct pim_instance *pim,
322 struct rp_info *rp_info)
323 {
324 struct interface *ifp;
325
326 rp_info->i_am_rp = 0;
327 FOR_ALL_INTERFACES (pim->vrf, ifp) {
328 struct pim_interface *pim_ifp = ifp->info;
329
330 if (!pim_ifp)
331 continue;
332
333 if (pim_rp_check_interface_addrs(rp_info, pim_ifp)) {
334 rp_info->i_am_rp = 1;
335 }
336 }
337 }
338
339 void pim_upstream_update(struct pim_instance *pim, struct pim_upstream *up)
340 {
341 struct pim_rpf old_rpf;
342 enum pim_rpf_result rpf_result;
343 struct in_addr old_upstream_addr;
344 struct in_addr new_upstream_addr;
345 struct prefix nht_p;
346
347 old_upstream_addr = up->upstream_addr;
348 pim_rp_set_upstream_addr(pim, &new_upstream_addr, up->sg.src,
349 up->sg.grp);
350
351 if (PIM_DEBUG_PIM_TRACE)
352 zlog_debug("%s: pim upstream update for old upstream %s",
353 __PRETTY_FUNCTION__,
354 inet_ntoa(old_upstream_addr));
355
356 if (old_upstream_addr.s_addr == new_upstream_addr.s_addr)
357 return;
358
359 /* Lets consider a case, where a PIM upstream has a better RP as a
360 * result of a new RP configuration with more precise group range.
361 * This upstream has to be added to the upstream hash of new RP's
362 * NHT(pnc) and has to be removed from old RP's NHT upstream hash
363 */
364 if (old_upstream_addr.s_addr != INADDR_ANY) {
365 /* Deregister addr with Zebra NHT */
366 nht_p.family = AF_INET;
367 nht_p.prefixlen = IPV4_MAX_BITLEN;
368 nht_p.u.prefix4 = old_upstream_addr;
369 if (PIM_DEBUG_PIM_TRACE) {
370 char buf[PREFIX2STR_BUFFER];
371
372 prefix2str(&nht_p, buf, sizeof(buf));
373 zlog_debug("%s: Deregister upstream %s addr %s with Zebra NHT",
374 __PRETTY_FUNCTION__, up->sg_str, buf);
375 }
376 pim_delete_tracked_nexthop(pim, &nht_p, up, NULL, false);
377 }
378
379 /* Update the upstream address */
380 up->upstream_addr = new_upstream_addr;
381
382 old_rpf.source_nexthop.interface = up->rpf.source_nexthop.interface;
383
384 rpf_result = pim_rpf_update(pim, up, &old_rpf);
385 if (rpf_result == PIM_RPF_FAILURE)
386 pim_mroute_del(up->channel_oil, __PRETTY_FUNCTION__);
387
388 /* update kernel multicast forwarding cache (MFC) */
389 if (up->rpf.source_nexthop.interface && up->channel_oil) {
390 ifindex_t ifindex = up->rpf.source_nexthop.interface->ifindex;
391 int vif_index = pim_if_find_vifindex_by_ifindex(pim, ifindex);
392 /* Pass Current selected NH vif index to mroute download */
393 if (vif_index)
394 pim_scan_individual_oil(up->channel_oil, vif_index);
395 else {
396 if (PIM_DEBUG_PIM_NHT)
397 zlog_debug(
398 "%s: NHT upstream %s channel_oil IIF %s vif_index is not valid",
399 __PRETTY_FUNCTION__, up->sg_str,
400 up->rpf.source_nexthop.interface->name);
401 }
402 }
403
404 if (rpf_result == PIM_RPF_CHANGED)
405 pim_zebra_upstream_rpf_changed(pim, up, &old_rpf);
406
407 pim_zebra_update_all_interfaces(pim);
408 }
409
410 int pim_rp_new_config(struct pim_instance *pim, const char *rp,
411 const char *group_range, const char *plist)
412 {
413 int result = 0;
414 struct prefix group;
415 struct in_addr rp_addr;
416
417 if (group_range == NULL)
418 result = str2prefix("224.0.0.0/4", &group);
419 else {
420 result = str2prefix(group_range, &group);
421 if (result) {
422 struct prefix temp;
423
424 prefix_copy(&temp, &group);
425 apply_mask(&temp);
426 if (!prefix_same(&group, &temp))
427 return PIM_GROUP_BAD_ADDR_MASK_COMBO;
428 }
429 }
430
431 if (!result)
432 return PIM_GROUP_BAD_ADDRESS;
433
434 result = inet_pton(AF_INET, rp, &rp_addr);
435
436 if (result <= 0)
437 return PIM_RP_BAD_ADDRESS;
438
439 result = pim_rp_new(pim, rp_addr, group, plist, RP_SRC_STATIC);
440 return result;
441 }
442
443 int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr,
444 struct prefix group, const char *plist,
445 enum rp_source rp_src_flag)
446 {
447 int result = 0;
448 char rp[INET_ADDRSTRLEN];
449 struct rp_info *rp_info;
450 struct rp_info *rp_all;
451 struct prefix group_all;
452 struct listnode *node, *nnode;
453 struct rp_info *tmp_rp_info;
454 char buffer[BUFSIZ];
455 struct prefix nht_p;
456 struct route_node *rn;
457 struct pim_upstream *up;
458 struct listnode *upnode;
459
460 if (rp_addr.s_addr == INADDR_ANY ||
461 rp_addr.s_addr == INADDR_NONE)
462 return PIM_RP_BAD_ADDRESS;
463
464 rp_info = XCALLOC(MTYPE_PIM_RP, sizeof(*rp_info));
465
466 rp_info->rp.rpf_addr.family = AF_INET;
467 rp_info->rp.rpf_addr.prefixlen = IPV4_MAX_PREFIXLEN;
468 rp_info->rp.rpf_addr.u.prefix4 = rp_addr;
469 prefix_copy(&rp_info->group, &group);
470 rp_info->rp_src = rp_src_flag;
471
472 inet_ntop(AF_INET, &rp_info->rp.rpf_addr.u.prefix4, rp, sizeof(rp));
473
474 if (plist) {
475 /*
476 * Return if the prefix-list is already configured for this RP
477 */
478 if (pim_rp_find_prefix_list(pim, rp_info->rp.rpf_addr.u.prefix4,
479 plist)) {
480 XFREE(MTYPE_PIM_RP, rp_info);
481 return PIM_SUCCESS;
482 }
483
484 /*
485 * Barf if the prefix-list is already configured for an RP
486 */
487 if (pim_rp_prefix_list_used(pim, plist)) {
488 XFREE(MTYPE_PIM_RP, rp_info);
489 return PIM_RP_PFXLIST_IN_USE;
490 }
491
492 /*
493 * Free any existing rp_info entries for this RP
494 */
495 for (ALL_LIST_ELEMENTS(pim->rp_list, node, nnode,
496 tmp_rp_info)) {
497 if (rp_info->rp.rpf_addr.u.prefix4.s_addr
498 == tmp_rp_info->rp.rpf_addr.u.prefix4.s_addr) {
499 if (tmp_rp_info->plist)
500 pim_rp_del_config(pim, rp, NULL,
501 tmp_rp_info->plist);
502 else
503 pim_rp_del_config(
504 pim, rp,
505 prefix2str(&tmp_rp_info->group,
506 buffer, BUFSIZ),
507 NULL);
508 }
509 }
510
511 rp_info->plist = XSTRDUP(MTYPE_PIM_FILTER_NAME, plist);
512 } else {
513
514 if (!str2prefix("224.0.0.0/4", &group_all)) {
515 XFREE(MTYPE_PIM_RP, rp_info);
516 return PIM_GROUP_BAD_ADDRESS;
517 }
518 rp_all = pim_rp_find_match_group(pim, &group_all);
519
520 /*
521 * Barf if group is a non-multicast subnet
522 */
523 if (!prefix_match(&rp_all->group, &rp_info->group)) {
524 XFREE(MTYPE_PIM_RP, rp_info);
525 return PIM_GROUP_BAD_ADDRESS;
526 }
527
528 /*
529 * Remove any prefix-list rp_info entries for this RP
530 */
531 for (ALL_LIST_ELEMENTS(pim->rp_list, node, nnode,
532 tmp_rp_info)) {
533 if (tmp_rp_info->plist
534 && rp_info->rp.rpf_addr.u.prefix4.s_addr
535 == tmp_rp_info->rp.rpf_addr.u.prefix4
536 .s_addr) {
537 pim_rp_del_config(pim, rp, NULL,
538 tmp_rp_info->plist);
539 }
540 }
541
542 /*
543 * Take over the 224.0.0.0/4 group if the rp is INADDR_NONE
544 */
545 if (prefix_same(&rp_all->group, &rp_info->group)
546 && pim_rpf_addr_is_inaddr_none(&rp_all->rp)) {
547 rp_all->rp.rpf_addr = rp_info->rp.rpf_addr;
548 rp_all->rp_src = rp_src_flag;
549 XFREE(MTYPE_PIM_RP, rp_info);
550
551 /* Register addr with Zebra NHT */
552 nht_p.family = AF_INET;
553 nht_p.prefixlen = IPV4_MAX_BITLEN;
554 nht_p.u.prefix4 =
555 rp_all->rp.rpf_addr.u.prefix4; // RP address
556 if (PIM_DEBUG_PIM_NHT_RP) {
557 char buf[PREFIX2STR_BUFFER];
558 char buf1[PREFIX2STR_BUFFER];
559 prefix2str(&nht_p, buf, sizeof(buf));
560 prefix2str(&rp_all->group, buf1, sizeof(buf1));
561 zlog_debug(
562 "%s: NHT Register rp_all addr %s grp %s ",
563 __PRETTY_FUNCTION__, buf, buf1);
564 }
565
566 for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode,
567 up)) {
568 /* Find (*, G) upstream whose RP is not
569 * configured yet
570 */
571 if ((up->upstream_addr.s_addr == INADDR_ANY)
572 && (up->sg.src.s_addr == INADDR_ANY)) {
573 struct prefix grp;
574 struct rp_info *trp_info;
575
576 grp.family = AF_INET;
577 grp.prefixlen = IPV4_MAX_BITLEN;
578 grp.u.prefix4 = up->sg.grp;
579 trp_info = pim_rp_find_match_group(
580 pim, &grp);
581 if (trp_info == rp_all)
582 pim_upstream_update(pim, up);
583 }
584 }
585
586 pim_rp_check_interfaces(pim, rp_all);
587 pim_rp_refresh_group_to_rp_mapping(pim);
588 pim_find_or_track_nexthop(pim, &nht_p, NULL, rp_all,
589 false, NULL);
590
591 if (!pim_ecmp_nexthop_lookup(pim,
592 &rp_all->rp.source_nexthop,
593 &nht_p, &rp_all->group, 1))
594 return PIM_RP_NO_PATH;
595 return PIM_SUCCESS;
596 }
597
598 /*
599 * Return if the group is already configured for this RP
600 */
601 tmp_rp_info = pim_rp_find_exact(
602 pim, rp_info->rp.rpf_addr.u.prefix4, &rp_info->group);
603 if (tmp_rp_info) {
604 if ((tmp_rp_info->rp_src != rp_src_flag)
605 && (rp_src_flag == RP_SRC_STATIC))
606 tmp_rp_info->rp_src = rp_src_flag;
607 XFREE(MTYPE_PIM_RP, rp_info);
608 return result;
609 }
610
611 /*
612 * Barf if this group is already covered by some other RP
613 */
614 tmp_rp_info = pim_rp_find_match_group(pim, &rp_info->group);
615
616 if (tmp_rp_info) {
617 if (tmp_rp_info->plist) {
618 XFREE(MTYPE_PIM_RP, rp_info);
619 return PIM_GROUP_PFXLIST_OVERLAP;
620 } else {
621 /*
622 * If the only RP that covers this group is an
623 * RP configured for
624 * 224.0.0.0/4 that is fine, ignore that one.
625 * For all others
626 * though we must return PIM_GROUP_OVERLAP
627 */
628 if (prefix_same(&rp_info->group,
629 &tmp_rp_info->group)) {
630 if ((rp_src_flag == RP_SRC_STATIC)
631 && (tmp_rp_info->rp_src
632 == RP_SRC_STATIC)) {
633 XFREE(MTYPE_PIM_RP, rp_info);
634 return PIM_GROUP_OVERLAP;
635 }
636
637 result = pim_rp_change(
638 pim,
639 rp_info->rp.rpf_addr.u.prefix4,
640 tmp_rp_info->group,
641 rp_src_flag);
642 XFREE(MTYPE_PIM_RP, rp_info);
643 return result;
644 }
645 }
646 }
647 }
648
649 listnode_add_sort(pim->rp_list, rp_info);
650 rn = route_node_get(pim->rp_table, &rp_info->group);
651 rn->info = rp_info;
652
653 if (PIM_DEBUG_PIM_TRACE) {
654 char buf[PREFIX_STRLEN];
655
656 zlog_debug("Allocated: %p for rp_info: %p(%s) Lock: %d", rn,
657 rp_info,
658 prefix2str(&rp_info->group, buf, sizeof(buf)),
659 rn->lock);
660 }
661
662 for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode, up)) {
663 if (up->sg.src.s_addr == INADDR_ANY) {
664 struct prefix grp;
665 struct rp_info *trp_info;
666
667 grp.family = AF_INET;
668 grp.prefixlen = IPV4_MAX_BITLEN;
669 grp.u.prefix4 = up->sg.grp;
670 trp_info = pim_rp_find_match_group(pim, &grp);
671
672 if (trp_info == rp_info)
673 pim_upstream_update(pim, up);
674 }
675 }
676
677 pim_rp_check_interfaces(pim, rp_info);
678 pim_rp_refresh_group_to_rp_mapping(pim);
679
680 /* Register addr with Zebra NHT */
681 nht_p.family = AF_INET;
682 nht_p.prefixlen = IPV4_MAX_BITLEN;
683 nht_p.u.prefix4 = rp_info->rp.rpf_addr.u.prefix4;
684 if (PIM_DEBUG_PIM_NHT_RP) {
685 char buf[PREFIX2STR_BUFFER];
686 char buf1[PREFIX2STR_BUFFER];
687 prefix2str(&nht_p, buf, sizeof(buf));
688 prefix2str(&rp_info->group, buf1, sizeof(buf1));
689 zlog_debug("%s: NHT Register RP addr %s grp %s with Zebra ",
690 __PRETTY_FUNCTION__, buf, buf1);
691 }
692 pim_find_or_track_nexthop(pim, &nht_p, NULL, rp_info, false, NULL);
693 if (!pim_ecmp_nexthop_lookup(pim, &rp_info->rp.source_nexthop, &nht_p,
694 &rp_info->group, 1))
695 return PIM_RP_NO_PATH;
696
697 return PIM_SUCCESS;
698 }
699
700 int pim_rp_del_config(struct pim_instance *pim, const char *rp,
701 const char *group_range, const char *plist)
702 {
703 struct prefix group;
704 struct in_addr rp_addr;
705 int result;
706
707 if (group_range == NULL)
708 result = str2prefix("224.0.0.0/4", &group);
709 else
710 result = str2prefix(group_range, &group);
711
712 if (!result)
713 return PIM_GROUP_BAD_ADDRESS;
714
715 result = inet_pton(AF_INET, rp, &rp_addr);
716 if (result <= 0)
717 return PIM_RP_BAD_ADDRESS;
718
719 result = pim_rp_del(pim, rp_addr, group, plist, RP_SRC_STATIC);
720 return result;
721 }
722
723 int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr,
724 struct prefix group, const char *plist,
725 enum rp_source rp_src_flag)
726 {
727 struct prefix g_all;
728 struct rp_info *rp_info;
729 struct rp_info *rp_all;
730 struct prefix nht_p;
731 struct route_node *rn;
732 bool was_plist = false;
733 struct rp_info *trp_info;
734 struct pim_upstream *up;
735 struct listnode *upnode;
736 struct bsgrp_node *bsgrp = NULL;
737 struct bsm_rpinfo *bsrp = NULL;
738 char grp_str[PREFIX2STR_BUFFER];
739 char rp_str[INET_ADDRSTRLEN];
740
741 if (!inet_ntop(AF_INET, &rp_addr, rp_str, sizeof(rp_str)))
742 sprintf(rp_str, "<rp?>");
743 prefix2str(&group, grp_str, sizeof(grp_str));
744
745 if (plist)
746 rp_info = pim_rp_find_prefix_list(pim, rp_addr, plist);
747 else
748 rp_info = pim_rp_find_exact(pim, rp_addr, &group);
749
750 if (!rp_info)
751 return PIM_RP_NOT_FOUND;
752
753 if (rp_info->plist) {
754 XFREE(MTYPE_PIM_FILTER_NAME, rp_info->plist);
755 was_plist = true;
756 }
757
758 if (PIM_DEBUG_PIM_TRACE)
759 zlog_debug("%s: Delete RP %s for the group %s",
760 __PRETTY_FUNCTION__, rp_str, grp_str);
761
762 /* While static RP is getting deleted, we need to check if dynamic RP
763 * present for the same group in BSM RP table, then install the dynamic
764 * RP for the group node into the main rp table
765 */
766 if (rp_src_flag == RP_SRC_STATIC) {
767 bsgrp = pim_bsm_get_bsgrp_node(&pim->global_scope, &group);
768
769 if (bsgrp) {
770 bsrp = listnode_head(bsgrp->bsrp_list);
771 if (bsrp) {
772 if (PIM_DEBUG_PIM_TRACE) {
773 char bsrp_str[INET_ADDRSTRLEN];
774
775 if (!inet_ntop(AF_INET, bsrp, bsrp_str,
776 sizeof(bsrp_str)))
777 sprintf(bsrp_str, "<bsrp?>");
778
779 zlog_debug("%s: BSM RP %s found for the group %s",
780 __PRETTY_FUNCTION__,
781 bsrp_str, grp_str);
782 }
783 return pim_rp_change(pim, bsrp->rp_address,
784 group, RP_SRC_BSR);
785 }
786 } else {
787 if (PIM_DEBUG_PIM_TRACE)
788 zlog_debug(
789 "%s: BSM RP not found for the group %s",
790 __PRETTY_FUNCTION__, grp_str);
791 }
792 }
793
794 /* Deregister addr with Zebra NHT */
795 nht_p.family = AF_INET;
796 nht_p.prefixlen = IPV4_MAX_BITLEN;
797 nht_p.u.prefix4 = rp_info->rp.rpf_addr.u.prefix4;
798 if (PIM_DEBUG_PIM_NHT_RP) {
799 char buf[PREFIX2STR_BUFFER];
800 prefix2str(&nht_p, buf, sizeof(buf));
801 zlog_debug("%s: Deregister RP addr %s with Zebra ",
802 __PRETTY_FUNCTION__, buf);
803 }
804 pim_delete_tracked_nexthop(pim, &nht_p, NULL, rp_info, false);
805
806 if (!str2prefix("224.0.0.0/4", &g_all))
807 return PIM_RP_BAD_ADDRESS;
808
809 rp_all = pim_rp_find_match_group(pim, &g_all);
810
811 if (rp_all == rp_info) {
812 for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode, up)) {
813 /* Find the upstream (*, G) whose upstream address is
814 * same as the deleted RP
815 */
816 if ((up->upstream_addr.s_addr
817 == rp_info->rp.rpf_addr.u.prefix4.s_addr)
818 && (up->sg.src.s_addr == INADDR_ANY)) {
819 struct prefix grp;
820 grp.family = AF_INET;
821 grp.prefixlen = IPV4_MAX_BITLEN;
822 grp.u.prefix4 = up->sg.grp;
823 trp_info = pim_rp_find_match_group(pim, &grp);
824 if (trp_info == rp_all) {
825 pim_upstream_rpf_clear(pim, up);
826 up->upstream_addr.s_addr = INADDR_ANY;
827 }
828 }
829 }
830 rp_all->rp.rpf_addr.family = AF_INET;
831 rp_all->rp.rpf_addr.u.prefix4.s_addr = INADDR_NONE;
832 rp_all->i_am_rp = 0;
833 return PIM_SUCCESS;
834 }
835
836 listnode_delete(pim->rp_list, rp_info);
837
838 if (!was_plist) {
839 rn = route_node_get(pim->rp_table, &rp_info->group);
840 if (rn) {
841 if (rn->info != rp_info)
842 flog_err(
843 EC_LIB_DEVELOPMENT,
844 "Expected rn->info to be equal to rp_info");
845
846 if (PIM_DEBUG_PIM_TRACE) {
847 char buf[PREFIX_STRLEN];
848
849 zlog_debug(
850 "%s:Found for Freeing: %p for rp_info: %p(%s) Lock: %d",
851 __PRETTY_FUNCTION__, rn, rp_info,
852 prefix2str(&rp_info->group, buf,
853 sizeof(buf)),
854 rn->lock);
855 }
856 rn->info = NULL;
857 route_unlock_node(rn);
858 route_unlock_node(rn);
859 }
860 }
861
862 pim_rp_refresh_group_to_rp_mapping(pim);
863
864 for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode, up)) {
865 /* Find the upstream (*, G) whose upstream address is same as
866 * the deleted RP
867 */
868 if ((up->upstream_addr.s_addr
869 == rp_info->rp.rpf_addr.u.prefix4.s_addr)
870 && (up->sg.src.s_addr == INADDR_ANY)) {
871 struct prefix grp;
872
873 grp.family = AF_INET;
874 grp.prefixlen = IPV4_MAX_BITLEN;
875 grp.u.prefix4 = up->sg.grp;
876
877 trp_info = pim_rp_find_match_group(pim, &grp);
878
879 /* RP not found for the group grp */
880 if (pim_rpf_addr_is_inaddr_none(&trp_info->rp)) {
881 pim_upstream_rpf_clear(pim, up);
882 pim_rp_set_upstream_addr(
883 pim, &up->upstream_addr, up->sg.src,
884 up->sg.grp);
885 }
886
887 /* RP found for the group grp */
888 else
889 pim_upstream_update(pim, up);
890 }
891 }
892
893 XFREE(MTYPE_PIM_RP, rp_info);
894 return PIM_SUCCESS;
895 }
896
897 int pim_rp_change(struct pim_instance *pim, struct in_addr new_rp_addr,
898 struct prefix group, enum rp_source rp_src_flag)
899 {
900 struct prefix nht_p;
901 struct route_node *rn;
902 int result = 0;
903 struct rp_info *rp_info = NULL;
904 struct pim_upstream *up;
905 struct listnode *upnode;
906
907 rn = route_node_lookup(pim->rp_table, &group);
908 if (!rn) {
909 result = pim_rp_new(pim, new_rp_addr, group, NULL, rp_src_flag);
910 return result;
911 }
912
913 rp_info = rn->info;
914
915 if (!rp_info) {
916 route_unlock_node(rn);
917 result = pim_rp_new(pim, new_rp_addr, group, NULL, rp_src_flag);
918 return result;
919 }
920
921 if (rp_info->rp.rpf_addr.u.prefix4.s_addr == new_rp_addr.s_addr) {
922 if (rp_info->rp_src != rp_src_flag) {
923 rp_info->rp_src = rp_src_flag;
924 route_unlock_node(rn);
925 return PIM_SUCCESS;
926 }
927 }
928
929 nht_p.family = AF_INET;
930 nht_p.prefixlen = IPV4_MAX_BITLEN;
931
932 /* Deregister old RP addr with Zebra NHT */
933 if (rp_info->rp.rpf_addr.u.prefix4.s_addr != INADDR_ANY) {
934 nht_p.u.prefix4 = rp_info->rp.rpf_addr.u.prefix4;
935 if (PIM_DEBUG_PIM_NHT_RP) {
936 char buf[PREFIX2STR_BUFFER];
937
938 prefix2str(&nht_p, buf, sizeof(buf));
939 zlog_debug("%s: Deregister RP addr %s with Zebra ",
940 __PRETTY_FUNCTION__, buf);
941 }
942 pim_delete_tracked_nexthop(pim, &nht_p, NULL, rp_info, false);
943 }
944
945 pim_rp_nexthop_del(rp_info);
946 listnode_delete(pim->rp_list, rp_info);
947 /* Update the new RP address*/
948 rp_info->rp.rpf_addr.u.prefix4 = new_rp_addr;
949 rp_info->rp_src = rp_src_flag;
950 rp_info->i_am_rp = 0;
951
952 listnode_add_sort(pim->rp_list, rp_info);
953
954 for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode, up)) {
955 if (up->sg.src.s_addr == INADDR_ANY) {
956 struct prefix grp;
957 struct rp_info *trp_info;
958
959 grp.family = AF_INET;
960 grp.prefixlen = IPV4_MAX_BITLEN;
961 grp.u.prefix4 = up->sg.grp;
962 trp_info = pim_rp_find_match_group(pim, &grp);
963
964 if (trp_info == rp_info)
965 pim_upstream_update(pim, up);
966 }
967 }
968
969 /* Register new RP addr with Zebra NHT */
970 nht_p.u.prefix4 = rp_info->rp.rpf_addr.u.prefix4;
971 if (PIM_DEBUG_PIM_NHT_RP) {
972 char buf[PREFIX2STR_BUFFER];
973 char buf1[PREFIX2STR_BUFFER];
974
975 prefix2str(&nht_p, buf, sizeof(buf));
976 prefix2str(&rp_info->group, buf1, sizeof(buf1));
977 zlog_debug("%s: NHT Register RP addr %s grp %s with Zebra ",
978 __PRETTY_FUNCTION__, buf, buf1);
979 }
980
981 pim_find_or_track_nexthop(pim, &nht_p, NULL, rp_info, false, NULL);
982 if (!pim_ecmp_nexthop_lookup(pim, &rp_info->rp.source_nexthop, &nht_p,
983 &rp_info->group, 1)) {
984 route_unlock_node(rn);
985 return PIM_RP_NO_PATH;
986 }
987
988 pim_rp_check_interfaces(pim, rp_info);
989
990 route_unlock_node(rn);
991
992 pim_rp_refresh_group_to_rp_mapping(pim);
993
994 return result;
995 }
996
997 void pim_rp_setup(struct pim_instance *pim)
998 {
999 struct listnode *node;
1000 struct rp_info *rp_info;
1001 struct prefix nht_p;
1002
1003 for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
1004 if (rp_info->rp.rpf_addr.u.prefix4.s_addr == INADDR_NONE)
1005 continue;
1006
1007 nht_p.family = AF_INET;
1008 nht_p.prefixlen = IPV4_MAX_BITLEN;
1009 nht_p.u.prefix4 = rp_info->rp.rpf_addr.u.prefix4;
1010
1011 pim_find_or_track_nexthop(pim, &nht_p, NULL, rp_info, false,
1012 NULL);
1013 if (!pim_ecmp_nexthop_lookup(pim, &rp_info->rp.source_nexthop,
1014 &nht_p, &rp_info->group, 1))
1015 if (PIM_DEBUG_PIM_NHT_RP)
1016 zlog_debug(
1017 "Unable to lookup nexthop for rp specified");
1018 }
1019 }
1020
1021 /*
1022 * Checks to see if we should elect ourself the actual RP when new if
1023 * addresses are added against an interface.
1024 */
1025 void pim_rp_check_on_if_add(struct pim_interface *pim_ifp)
1026 {
1027 struct listnode *node;
1028 struct rp_info *rp_info;
1029 bool i_am_rp_changed = false;
1030 struct pim_instance *pim = pim_ifp->pim;
1031
1032 if (pim->rp_list == NULL)
1033 return;
1034
1035 for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
1036 if (pim_rpf_addr_is_inaddr_none(&rp_info->rp))
1037 continue;
1038
1039 /* if i_am_rp is already set nothing to be done (adding new
1040 * addresses
1041 * is not going to make a difference). */
1042 if (rp_info->i_am_rp) {
1043 continue;
1044 }
1045
1046 if (pim_rp_check_interface_addrs(rp_info, pim_ifp)) {
1047 i_am_rp_changed = true;
1048 rp_info->i_am_rp = 1;
1049 if (PIM_DEBUG_PIM_NHT_RP) {
1050 char rp[PREFIX_STRLEN];
1051 pim_addr_dump("<rp?>", &rp_info->rp.rpf_addr,
1052 rp, sizeof(rp));
1053 zlog_debug("%s: %s: i am rp", __func__, rp);
1054 }
1055 }
1056 }
1057
1058 if (i_am_rp_changed) {
1059 pim_msdp_i_am_rp_changed(pim);
1060 }
1061 }
1062
1063 /* up-optimized re-evaluation of "i_am_rp". this is used when ifaddresses
1064 * are removed. Removing numbers is an uncommon event in an active network
1065 * so I have made no attempt to optimize it. */
1066 void pim_i_am_rp_re_evaluate(struct pim_instance *pim)
1067 {
1068 struct listnode *node;
1069 struct rp_info *rp_info;
1070 bool i_am_rp_changed = false;
1071 int old_i_am_rp;
1072
1073 if (pim->rp_list == NULL)
1074 return;
1075
1076 for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
1077 if (pim_rpf_addr_is_inaddr_none(&rp_info->rp))
1078 continue;
1079
1080 old_i_am_rp = rp_info->i_am_rp;
1081 pim_rp_check_interfaces(pim, rp_info);
1082
1083 if (old_i_am_rp != rp_info->i_am_rp) {
1084 i_am_rp_changed = true;
1085 if (PIM_DEBUG_PIM_NHT_RP) {
1086 char rp[PREFIX_STRLEN];
1087 pim_addr_dump("<rp?>", &rp_info->rp.rpf_addr,
1088 rp, sizeof(rp));
1089 if (rp_info->i_am_rp) {
1090 zlog_debug("%s: %s: i am rp", __func__,
1091 rp);
1092 } else {
1093 zlog_debug("%s: %s: i am no longer rp",
1094 __func__, rp);
1095 }
1096 }
1097 }
1098 }
1099
1100 if (i_am_rp_changed) {
1101 pim_msdp_i_am_rp_changed(pim);
1102 }
1103 }
1104
1105 /*
1106 * I_am_RP(G) is true if the group-to-RP mapping indicates that
1107 * this router is the RP for the group.
1108 *
1109 * Since we only have static RP, all groups are part of this RP
1110 */
1111 int pim_rp_i_am_rp(struct pim_instance *pim, struct in_addr group)
1112 {
1113 struct prefix g;
1114 struct rp_info *rp_info;
1115
1116 memset(&g, 0, sizeof(g));
1117 g.family = AF_INET;
1118 g.prefixlen = 32;
1119 g.u.prefix4 = group;
1120
1121 rp_info = pim_rp_find_match_group(pim, &g);
1122
1123 if (rp_info)
1124 return rp_info->i_am_rp;
1125
1126 return 0;
1127 }
1128
1129 /*
1130 * RP(G)
1131 *
1132 * Return the RP that the Group belongs too.
1133 */
1134 struct pim_rpf *pim_rp_g(struct pim_instance *pim, struct in_addr group)
1135 {
1136 struct prefix g;
1137 struct rp_info *rp_info;
1138
1139 memset(&g, 0, sizeof(g));
1140 g.family = AF_INET;
1141 g.prefixlen = 32;
1142 g.u.prefix4 = group;
1143
1144 rp_info = pim_rp_find_match_group(pim, &g);
1145
1146 if (rp_info) {
1147 struct prefix nht_p;
1148
1149 /* Register addr with Zebra NHT */
1150 nht_p.family = AF_INET;
1151 nht_p.prefixlen = IPV4_MAX_BITLEN;
1152 nht_p.u.prefix4 = rp_info->rp.rpf_addr.u.prefix4;
1153 if (PIM_DEBUG_PIM_NHT_RP) {
1154 char buf[PREFIX2STR_BUFFER];
1155 char buf1[PREFIX2STR_BUFFER];
1156 prefix2str(&nht_p, buf, sizeof(buf));
1157 prefix2str(&rp_info->group, buf1, sizeof(buf1));
1158 zlog_debug(
1159 "%s: NHT Register RP addr %s grp %s with Zebra",
1160 __PRETTY_FUNCTION__, buf, buf1);
1161 }
1162 pim_find_or_track_nexthop(pim, &nht_p, NULL, rp_info, false,
1163 NULL);
1164 pim_rpf_set_refresh_time(pim);
1165 (void)pim_ecmp_nexthop_lookup(pim, &rp_info->rp.source_nexthop,
1166 &nht_p, &rp_info->group, 1);
1167 return (&rp_info->rp);
1168 }
1169
1170 // About to Go Down
1171 return NULL;
1172 }
1173
1174 /*
1175 * Set the upstream IP address we want to talk to based upon
1176 * the rp configured and the source address
1177 *
1178 * If we have don't have a RP configured and the source address is *
1179 * then set the upstream addr as INADDR_ANY and return failure.
1180 *
1181 */
1182 int pim_rp_set_upstream_addr(struct pim_instance *pim, struct in_addr *up,
1183 struct in_addr source, struct in_addr group)
1184 {
1185 struct rp_info *rp_info;
1186 struct prefix g;
1187
1188 memset(&g, 0, sizeof(g));
1189 g.family = AF_INET;
1190 g.prefixlen = 32;
1191 g.u.prefix4 = group;
1192
1193 rp_info = pim_rp_find_match_group(pim, &g);
1194
1195 if (!rp_info || ((pim_rpf_addr_is_inaddr_none(&rp_info->rp))
1196 && (source.s_addr == INADDR_ANY))) {
1197 if (PIM_DEBUG_PIM_NHT_RP)
1198 zlog_debug("%s: Received a (*,G) with no RP configured",
1199 __PRETTY_FUNCTION__);
1200 up->s_addr = INADDR_ANY;
1201 return 0;
1202 }
1203
1204 *up = (source.s_addr == INADDR_ANY) ? rp_info->rp.rpf_addr.u.prefix4
1205 : source;
1206
1207 return 1;
1208 }
1209
1210 int pim_rp_config_write(struct pim_instance *pim, struct vty *vty,
1211 const char *spaces)
1212 {
1213 struct listnode *node;
1214 struct rp_info *rp_info;
1215 char rp_buffer[32];
1216 char group_buffer[32];
1217 int count = 0;
1218
1219 for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
1220 if (pim_rpf_addr_is_inaddr_none(&rp_info->rp))
1221 continue;
1222
1223 if (rp_info->rp_src == RP_SRC_BSR)
1224 continue;
1225
1226 if (rp_info->plist)
1227 vty_out(vty, "%sip pim rp %s prefix-list %s\n", spaces,
1228 inet_ntop(AF_INET,
1229 &rp_info->rp.rpf_addr.u.prefix4,
1230 rp_buffer, 32),
1231 rp_info->plist);
1232 else
1233 vty_out(vty, "%sip pim rp %s %s\n", spaces,
1234 inet_ntop(AF_INET,
1235 &rp_info->rp.rpf_addr.u.prefix4,
1236 rp_buffer, 32),
1237 prefix2str(&rp_info->group, group_buffer, 32));
1238 count++;
1239 }
1240
1241 return count;
1242 }
1243
1244 bool pim_rp_check_is_my_ip_address(struct pim_instance *pim,
1245 struct in_addr dest_addr)
1246 {
1247 if (if_lookup_exact_address(&dest_addr, AF_INET, pim->vrf_id))
1248 return true;
1249
1250 return false;
1251 }
1252
1253 void pim_rp_show_information(struct pim_instance *pim, struct vty *vty, bool uj)
1254 {
1255 struct rp_info *rp_info;
1256 struct rp_info *prev_rp_info = NULL;
1257 struct listnode *node;
1258 char source[7];
1259
1260 json_object *json = NULL;
1261 json_object *json_rp_rows = NULL;
1262 json_object *json_row = NULL;
1263
1264 if (uj)
1265 json = json_object_new_object();
1266 else
1267 vty_out(vty,
1268 "RP address group/prefix-list OIF I am RP Source\n");
1269 for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
1270 if (!pim_rpf_addr_is_inaddr_none(&rp_info->rp)) {
1271 char buf[48];
1272
1273 if (rp_info->rp_src == RP_SRC_STATIC)
1274 strcpy(source, "Static");
1275 else if (rp_info->rp_src == RP_SRC_BSR)
1276 strcpy(source, "BSR");
1277 else
1278 strcpy(source, "None");
1279 if (uj) {
1280 /*
1281 * If we have moved on to a new RP then add the
1282 * entry for the previous RP
1283 */
1284 if (prev_rp_info
1285 && prev_rp_info->rp.rpf_addr.u.prefix4
1286 .s_addr
1287 != rp_info->rp.rpf_addr.u.prefix4
1288 .s_addr) {
1289 json_object_object_add(
1290 json,
1291 inet_ntoa(prev_rp_info->rp
1292 .rpf_addr.u
1293 .prefix4),
1294 json_rp_rows);
1295 json_rp_rows = NULL;
1296 }
1297
1298 if (!json_rp_rows)
1299 json_rp_rows = json_object_new_array();
1300
1301 json_row = json_object_new_object();
1302 if (rp_info->rp.source_nexthop.interface)
1303 json_object_string_add(
1304 json_row, "outboundInterface",
1305 rp_info->rp.source_nexthop
1306 .interface->name);
1307
1308 if (rp_info->i_am_rp)
1309 json_object_boolean_true_add(json_row,
1310 "iAmRP");
1311
1312 if (rp_info->plist)
1313 json_object_string_add(json_row,
1314 "prefixList",
1315 rp_info->plist);
1316 else
1317 json_object_string_add(
1318 json_row, "group",
1319 prefix2str(&rp_info->group, buf,
1320 48));
1321 json_object_string_add(json_row, "source",
1322 source);
1323
1324 json_object_array_add(json_rp_rows, json_row);
1325 } else {
1326 vty_out(vty, "%-15s ",
1327 inet_ntoa(rp_info->rp.rpf_addr.u
1328 .prefix4));
1329
1330 if (rp_info->plist)
1331 vty_out(vty, "%-18s ", rp_info->plist);
1332 else
1333 vty_out(vty, "%-18s ",
1334 prefix2str(&rp_info->group, buf,
1335 48));
1336
1337 if (rp_info->rp.source_nexthop.interface)
1338 vty_out(vty, "%-16s ",
1339 rp_info->rp.source_nexthop
1340 .interface->name);
1341 else
1342 vty_out(vty, "%-16s ", "(Unknown)");
1343
1344 if (rp_info->i_am_rp)
1345 vty_out(vty, "yes");
1346 else
1347 vty_out(vty, "no");
1348
1349 vty_out(vty, "%14s\n", source);
1350 }
1351 prev_rp_info = rp_info;
1352 }
1353 }
1354
1355 if (uj) {
1356 if (prev_rp_info && json_rp_rows)
1357 json_object_object_add(
1358 json,
1359 inet_ntoa(prev_rp_info->rp.rpf_addr.u.prefix4),
1360 json_rp_rows);
1361
1362 vty_out(vty, "%s\n", json_object_to_json_string_ext(
1363 json, JSON_C_TO_STRING_PRETTY));
1364 json_object_free(json);
1365 }
1366 }
1367
1368 void pim_resolve_rp_nh(struct pim_instance *pim, struct pim_neighbor *nbr)
1369 {
1370 struct listnode *node = NULL;
1371 struct rp_info *rp_info = NULL;
1372 struct nexthop *nh_node = NULL;
1373 struct prefix nht_p;
1374 struct pim_nexthop_cache pnc;
1375
1376 for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
1377 if (rp_info->rp.rpf_addr.u.prefix4.s_addr == INADDR_NONE)
1378 continue;
1379
1380 nht_p.family = AF_INET;
1381 nht_p.prefixlen = IPV4_MAX_BITLEN;
1382 nht_p.u.prefix4 = rp_info->rp.rpf_addr.u.prefix4;
1383 memset(&pnc, 0, sizeof(struct pim_nexthop_cache));
1384 if (!pim_find_or_track_nexthop(pim, &nht_p, NULL, rp_info,
1385 false, &pnc))
1386 continue;
1387
1388 for (nh_node = pnc.nexthop; nh_node; nh_node = nh_node->next) {
1389 if (nh_node->gate.ipv4.s_addr != 0)
1390 continue;
1391
1392 struct interface *ifp1 = if_lookup_by_index(
1393 nh_node->ifindex, pim->vrf_id);
1394
1395 if (nbr->interface != ifp1)
1396 continue;
1397
1398 nh_node->gate.ipv4 = nbr->source_addr;
1399 if (PIM_DEBUG_PIM_NHT_RP) {
1400 char str[PREFIX_STRLEN];
1401 char str1[INET_ADDRSTRLEN];
1402 pim_inet4_dump("<nht_nbr?>", nbr->source_addr,
1403 str1, sizeof(str1));
1404 pim_addr_dump("<nht_addr?>", &nht_p, str,
1405 sizeof(str));
1406 zlog_debug(
1407 "%s: addr %s new nexthop addr %s interface %s",
1408 __PRETTY_FUNCTION__, str, str1,
1409 ifp1->name);
1410 }
1411 }
1412 }
1413 }