forked from Mirror/frr
pimd: Refactor some functions
A bunch of functions had return values that were never checked for ( and not needed ) and opposite return values for proper calling function boolean logic. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
da82728dbf
commit
cb9c7c50d3
|
@ -3599,10 +3599,9 @@ DEFUN (show_ip_pim_nexthop_lookup,
|
|||
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));
|
||||
|
|
|
@ -142,9 +142,14 @@ struct pim_nexthop_cache *pim_nexthop_cache_add(struct pim_rpf *rpf_addr)
|
|||
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)
|
||||
|
@ -172,7 +177,7 @@ int pim_find_or_track_nexthop(struct prefix *addr, struct pim_upstream *up,
|
|||
sizeof(rpf_str));
|
||||
zlog_warn("%s: pnc node allocation failed. addr %s ",
|
||||
__PRETTY_FUNCTION__, rpf_str);
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -299,31 +304,29 @@ void pim_resolve_upstream_nh(struct prefix *nht_p)
|
|||
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) {
|
||||
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) {
|
||||
struct interface *ifp1 = if_lookup_by_index(
|
||||
nh_node->ifindex, pimg->vrf_id);
|
||||
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) {
|
||||
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,
|
||||
pim_inet4_dump("<nht_nbr?>", nbr->source_addr, str1,
|
||||
sizeof(str1));
|
||||
pim_addr_dump("<nht_addr?>",
|
||||
nht_p, str,
|
||||
sizeof(str));
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
__PRETTY_FUNCTION__, str, str1, ifp1->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -499,7 +502,7 @@ int pim_ecmp_nexthop_search(struct pim_nexthop_cache *pnc,
|
|||
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
|
||||
|
@ -653,9 +656,9 @@ int pim_ecmp_nexthop_search(struct pim_nexthop_cache *pnc,
|
|||
}
|
||||
|
||||
if (found)
|
||||
return 0;
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This API is used to parse Registered address nexthop update coming from Zebra
|
||||
|
@ -899,7 +902,7 @@ int pim_ecmp_nexthop_lookup(struct pim_nexthop *nexthop, struct in_addr addr,
|
|||
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.
|
||||
|
@ -1001,10 +1004,11 @@ int pim_ecmp_nexthop_lookup(struct pim_nexthop *nexthop, struct in_addr addr,
|
|||
}
|
||||
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,
|
||||
|
|
|
@ -402,14 +402,11 @@ int pim_rp_new(const char *rp, const char *group_range, const char *plist)
|
|||
__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(
|
||||
|
@ -474,11 +471,9 @@ int pim_rp_new(const char *rp, const char *group_range, const char *plist)
|
|||
}
|
||||
|
||||
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,
|
||||
|
@ -554,11 +549,10 @@ int pim_rp_del(const char *rp, const char *group_range, const char *plist)
|
|||
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;
|
||||
|
||||
|
@ -570,15 +564,11 @@ int pim_rp_setup(void)
|
|||
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));
|
||||
|
@ -589,19 +579,12 @@ int pim_rp_setup(void)
|
|||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -745,13 +728,11 @@ struct pim_rpf *pim_rp_g(struct in_addr group)
|
|||
__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];
|
||||
|
@ -989,44 +970,32 @@ void pim_resolve_rp_nh(void)
|
|||
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_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];
|
||||
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,
|
||||
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,
|
||||
__PRETTY_FUNCTION__, str, str1,
|
||||
ifp1->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ void pim_rp_prefix_list_update(struct prefix_list *plist);
|
|||
|
||||
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);
|
||||
|
|
|
@ -194,7 +194,6 @@ enum pim_rpf_result pim_rpf_update(struct pim_upstream *up, struct pim_rpf *old,
|
|||
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;
|
||||
|
@ -219,28 +218,23 @@ enum pim_rpf_result pim_rpf_update(struct pim_upstream *up, struct pim_rpf *old,
|
|||
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;
|
||||
rpf->rpf_addr.u.prefix4 = pim_rpf_find_rpf_addr(up);
|
||||
|
|
|
@ -849,7 +849,6 @@ void igmp_source_forward_start(struct igmp_source *source)
|
|||
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;
|
||||
|
@ -871,17 +870,14 @@ void igmp_source_forward_start(struct igmp_source *source)
|
|||
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)
|
||||
|
@ -1096,7 +1092,6 @@ void pim_forward_start(struct pim_ifchannel *ch)
|
|||
|| (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 */
|
||||
|
@ -1108,9 +1103,7 @@ void pim_forward_start(struct pim_ifchannel *ch)
|
|||
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;
|
||||
|
@ -1122,8 +1115,7 @@ void pim_forward_start(struct pim_ifchannel *ch)
|
|||
// 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
|
||||
|
|
Loading…
Reference in a new issue