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