grp.u.prefix4 = grp_addr;
memset(&nexthop, 0, sizeof(nexthop));
- if ((pim_find_or_track_nexthop(&nht_p, NULL, NULL, &pnc)) == 1) {
- // Compute PIM RPF using Cached nexthop
+ if (pim_find_or_track_nexthop(&nht_p, NULL, NULL, &pnc))
pim_ecmp_nexthop_search(&pnc, &nexthop, &nht_p, &grp, 0);
- } else
+ else
pim_ecmp_nexthop_lookup(&nexthop, vif_source, &nht_p, &grp, 0);
pim_addr_dump("<grp?>", &grp, grp_str, sizeof(grp_str));
return pnc;
}
-/* This API is used to Register an address with Zebra
- ret 1 means nexthop cache is found.
-*/
+/*
+ * pim_find_or_track_nexthop
+ *
+ * This API is used to Register an address with Zebra
+ *
+ * 1 -> Success
+ * 0 -> Failure
+ */
int pim_find_or_track_nexthop(struct prefix *addr, struct pim_upstream *up,
struct rp_info *rp,
struct pim_nexthop_cache *out_pnc)
sizeof(rpf_str));
zlog_warn("%s: pnc node allocation failed. addr %s ",
__PRETTY_FUNCTION__, rpf_str);
- return -1;
+ return 0;
}
}
struct pim_neighbor *nbr = NULL;
memset(&pnc, 0, sizeof(struct pim_nexthop_cache));
- if ((pim_find_or_track_nexthop(nht_p, NULL, NULL, &pnc)) == 1) {
- for (nh_node = pnc.nexthop; nh_node; nh_node = nh_node->next) {
- if (nh_node->gate.ipv4.s_addr == 0) {
- struct interface *ifp1 = if_lookup_by_index(
- nh_node->ifindex, pimg->vrf_id);
- nbr = pim_neighbor_find_if(ifp1);
- if (nbr) {
- nh_node->gate.ipv4 = nbr->source_addr;
- if (PIM_DEBUG_TRACE) {
- char str[PREFIX_STRLEN];
- char str1[INET_ADDRSTRLEN];
- pim_inet4_dump("<nht_nbr?>",
- nbr->source_addr,
- str1,
- sizeof(str1));
- pim_addr_dump("<nht_addr?>",
- nht_p, str,
- sizeof(str));
- zlog_debug(
- "%s: addr %s new nexthop addr %s interface %s",
- __PRETTY_FUNCTION__,
- str, str1, ifp1->name);
- }
- }
- }
+ if (!pim_find_or_track_nexthop(nht_p, NULL, NULL, &pnc))
+ return;
+
+ for (nh_node = pnc.nexthop; nh_node; nh_node = nh_node->next) {
+ if (nh_node->gate.ipv4.s_addr != 0)
+ continue;
+
+ struct interface *ifp1 =
+ if_lookup_by_index(nh_node->ifindex, pimg->vrf_id);
+ nbr = pim_neighbor_find_if(ifp1);
+ if (!nbr)
+ continue;
+
+ nh_node->gate.ipv4 = nbr->source_addr;
+ if (PIM_DEBUG_TRACE) {
+ char str[PREFIX_STRLEN];
+ char str1[INET_ADDRSTRLEN];
+ pim_inet4_dump("<nht_nbr?>", nbr->source_addr, str1,
+ sizeof(str1));
+ pim_addr_dump("<nht_addr?>", nht_p, str, sizeof(str));
+ zlog_debug(
+ "%s: addr %s new nexthop addr %s interface %s",
+ __PRETTY_FUNCTION__, str, str1, ifp1->name);
}
}
}
uint8_t nh_iter = 0, found = 0;
if (!pnc || !pnc->nexthop_num || !nexthop)
- return -1;
+ return 0;
// Current Nexthop is VALID, check to stay on the current path.
if (nexthop->interface && nexthop->interface->info
}
if (found)
- return 0;
+ return 1;
else
- return -1;
+ return 0;
}
/* This API is used to parse Registered address nexthop update coming from Zebra
zlog_warn(
"%s %s: could not find nexthop ifindex for address %s",
__FILE__, __PRETTY_FUNCTION__, addr_str);
- return -1;
+ return 0;
}
// If PIM ECMP enable then choose ECMP path.
}
i++;
}
+
if (found)
- return 0;
+ return 1;
else
- return -1;
+ return 0;
}
int pim_ecmp_fib_lookup_if_vif_index(struct in_addr addr, struct prefix *src,
__PRETTY_FUNCTION__, buf, buf1);
}
memset(&pnc, 0, sizeof(struct pim_nexthop_cache));
- if ((pim_find_or_track_nexthop(&nht_p, NULL, rp_all,
- &pnc))
- == 1) {
- // Compute PIM RPF using Cached nexthop
- if ((pim_ecmp_nexthop_search(
+ if (pim_find_or_track_nexthop(&nht_p, NULL, rp_all,
+ &pnc)) {
+ if (!pim_ecmp_nexthop_search(
&pnc, &rp_all->rp.source_nexthop,
&nht_p, &rp_all->group, 1))
- != 0)
return PIM_RP_NO_PATH;
} else {
if (pim_nexthop_lookup(
}
memset(&pnc, 0, sizeof(struct pim_nexthop_cache));
- if ((pim_find_or_track_nexthop(&nht_p, NULL, rp_info, &pnc)) == 1) {
- // Compute PIM RPF using Cached nexthop
- if (pim_ecmp_nexthop_search(&pnc, &rp_info->rp.source_nexthop,
- &nht_p, &rp_info->group, 1)
- != 0)
+ if (pim_find_or_track_nexthop(&nht_p, NULL, rp_info, &pnc)) {
+ if (!pim_ecmp_nexthop_search(&pnc, &rp_info->rp.source_nexthop,
+ &nht_p, &rp_info->group, 1))
return PIM_RP_NO_PATH;
} else {
if (pim_nexthop_lookup(&rp_info->rp.source_nexthop,
return PIM_SUCCESS;
}
-int pim_rp_setup(void)
+void pim_rp_setup(void)
{
struct listnode *node;
struct rp_info *rp_info;
- int ret = 0;
struct prefix nht_p;
struct pim_nexthop_cache pnc;
nht_p.prefixlen = IPV4_MAX_BITLEN;
nht_p.u.prefix4 = rp_info->rp.rpf_addr.u.prefix4;
memset(&pnc, 0, sizeof(struct pim_nexthop_cache));
- if ((pim_find_or_track_nexthop(&nht_p, NULL, rp_info, &pnc))
- == 1) {
- // Compute PIM RPF using Cached nexthop
- if ((pim_ecmp_nexthop_search(
- &pnc, &rp_info->rp.source_nexthop, &nht_p,
- &rp_info->group, 1))
- != 0)
- ret++;
- } else {
+ if (pim_find_or_track_nexthop(&nht_p, NULL, rp_info, &pnc))
+ pim_ecmp_nexthop_search(&pnc,
+ &rp_info->rp.source_nexthop,
+ &nht_p, &rp_info->group, 1);
+ else {
if (PIM_DEBUG_ZEBRA) {
char buf[PREFIX2STR_BUFFER];
prefix2str(&nht_p, buf, sizeof(buf));
if (pim_nexthop_lookup(&rp_info->rp.source_nexthop,
rp_info->rp.rpf_addr.u.prefix4,
1)
- != 0) {
+ != 0)
if (PIM_DEBUG_PIM_TRACE)
zlog_debug(
"Unable to lookup nexthop for rp specified");
- ret++;
- }
}
}
-
- if (ret)
- return 0;
-
- return 1;
}
/*
__PRETTY_FUNCTION__, buf, buf1);
}
memset(&pnc, 0, sizeof(struct pim_nexthop_cache));
- if ((pim_find_or_track_nexthop(&nht_p, NULL, rp_info, &pnc))
- == 1) {
- // Compute PIM RPF using Cached nexthop
+ if (pim_find_or_track_nexthop(&nht_p, NULL, rp_info, &pnc))
pim_ecmp_nexthop_search(&pnc,
&rp_info->rp.source_nexthop,
&nht_p, &rp_info->group, 1);
- } else {
+ else {
if (PIM_DEBUG_ZEBRA) {
char buf[PREFIX2STR_BUFFER];
char buf1[PREFIX2STR_BUFFER];
nht_p.prefixlen = IPV4_MAX_BITLEN;
nht_p.u.prefix4 = rp_info->rp.rpf_addr.u.prefix4;
memset(&pnc, 0, sizeof(struct pim_nexthop_cache));
- if ((pim_find_or_track_nexthop(&nht_p, NULL, rp_info, &pnc))
- == 1) {
- for (nh_node = pnc.nexthop; nh_node;
- nh_node = nh_node->next) {
- if (nh_node->gate.ipv4.s_addr == 0) {
- nbr = pim_neighbor_find_if(
- if_lookup_by_index(
- nh_node->ifindex,
- pimg->vrf_id));
- if (nbr) {
- nh_node->gate.ipv4 =
- nbr->source_addr;
- if (PIM_DEBUG_TRACE) {
- char str[PREFIX_STRLEN];
- char str1
- [INET_ADDRSTRLEN];
- struct interface *ifp1 =
- if_lookup_by_index(
- nh_node->ifindex,
- pimg->vrf_id);
- pim_inet4_dump(
- "<nht_nbr?>",
- nbr->source_addr,
- str1,
- sizeof(str1));
- pim_addr_dump(
- "<nht_addr?>",
- &nht_p, str,
- sizeof(str));
- zlog_debug(
- "%s: addr %s new nexthop addr %s interface %s",
- __PRETTY_FUNCTION__,
- str, str1,
- ifp1->name);
- }
- }
- }
+ if (!pim_find_or_track_nexthop(&nht_p, NULL, rp_info, &pnc))
+ continue;
+
+ for (nh_node = pnc.nexthop; nh_node; nh_node = nh_node->next) {
+ if (nh_node->gate.ipv4.s_addr != 0)
+ continue;
+
+ struct interface *ifp1 = if_lookup_by_index(
+ nh_node->ifindex, pimg->vrf_id);
+ nbr = pim_neighbor_find_if(ifp1);
+ if (!nbr)
+ continue;
+
+ nh_node->gate.ipv4 = nbr->source_addr;
+ if (PIM_DEBUG_TRACE) {
+ char str[PREFIX_STRLEN];
+ char str1[INET_ADDRSTRLEN];
+ pim_inet4_dump("<nht_nbr?>", nbr->source_addr,
+ str1, sizeof(str1));
+ pim_addr_dump("<nht_addr?>", &nht_p, str,
+ sizeof(str));
+ zlog_debug(
+ "%s: addr %s new nexthop addr %s interface %s",
+ __PRETTY_FUNCTION__, str, str1,
+ ifp1->name);
}
}
}
int pim_rp_config_write(struct vty *vty);
-int pim_rp_setup(void);
+void pim_rp_setup(void);
int pim_rp_i_am_rp(struct in_addr group);
void pim_rp_check_on_if_add(struct pim_interface *pim_ifp);
struct pim_rpf saved;
struct prefix nht_p;
struct pim_nexthop_cache pnc;
- int ret = 0;
struct prefix src, grp;
saved.source_nexthop = rpf->source_nexthop;
grp.prefixlen = IPV4_MAX_BITLEN;
grp.u.prefix4 = up->sg.grp;
memset(&pnc, 0, sizeof(struct pim_nexthop_cache));
- if ((ret = pim_find_or_track_nexthop(&nht_p, up, NULL, &pnc)) == 1) {
+ if (pim_find_or_track_nexthop(&nht_p, up, NULL, &pnc)) {
if (pnc.nexthop_num) {
- // Compute PIM RPF using Cached nexthop
- if (pim_ecmp_nexthop_search(
+ if (!pim_ecmp_nexthop_search(
&pnc, &up->rpf.source_nexthop, &src, &grp,
!PIM_UPSTREAM_FLAG_TEST_FHR(up->flags)
&& !PIM_UPSTREAM_FLAG_TEST_SRC_IGMP(
up->flags)))
-
- {
return PIM_RPF_FAILURE;
- }
}
} else {
- if (pim_ecmp_nexthop_lookup(
+ if (!pim_ecmp_nexthop_lookup(
&rpf->source_nexthop, up->upstream_addr, &src, &grp,
!PIM_UPSTREAM_FLAG_TEST_FHR(up->flags)
&& !PIM_UPSTREAM_FLAG_TEST_SRC_IGMP(
- up->flags))) {
+ up->flags)))
return PIM_RPF_FAILURE;
- }
}
rpf->rpf_addr.family = AF_INET;
struct in_addr vif_source;
struct pim_interface *pim_oif;
struct prefix nht_p, src, grp;
- int ret = 0;
struct pim_nexthop_cache out_pnc;
struct pim_nexthop nexthop;
struct pim_upstream *up = NULL;
grp.prefixlen = IPV4_MAX_BITLEN;
grp.u.prefix4 = sg.grp;
- if ((ret = pim_find_or_track_nexthop(&nht_p, NULL, NULL,
- &out_pnc))
- == 1) {
+ if (pim_find_or_track_nexthop(&nht_p, NULL, NULL, &out_pnc)) {
if (out_pnc.nexthop_num) {
up = pim_upstream_find(&sg);
- memset(&nexthop, 0, sizeof(struct pim_nexthop));
+ memset(&nexthop, 0, sizeof(nexthop));
if (up)
memcpy(&nexthop,
&up->rpf.source_nexthop,
sizeof(struct pim_nexthop));
- // Compute PIM RPF using Cached nexthop
pim_ecmp_nexthop_search(&out_pnc, &nexthop,
&src, &grp, 0);
if (nexthop.interface)
|| (up->channel_oil
&& up->channel_oil->oil.mfcc_parent >= MAXVIFS)) {
struct prefix nht_p, src, grp;
- int ret = 0;
struct pim_nexthop_cache out_pnc;
/* Register addr with Zebra NHT */
grp.u.prefix4 = up->sg.grp;
memset(&out_pnc, 0, sizeof(struct pim_nexthop_cache));
- if ((ret = pim_find_or_track_nexthop(&nht_p, NULL, NULL,
- &out_pnc))
- == 1) {
+ if (pim_find_or_track_nexthop(&nht_p, NULL, NULL, &out_pnc)) {
if (out_pnc.nexthop_num) {
src.family = AF_INET;
src.prefixlen = IPV4_MAX_BITLEN;
// Compute PIM RPF using Cached nexthop
if (pim_ecmp_nexthop_search(
&out_pnc, &up->rpf.source_nexthop,
- &src, &grp, 0)
- == 0)
+ &src, &grp, 0))
input_iface_vif_index =
pim_if_find_vifindex_by_ifindex(
up->rpf.source_nexthop