summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2019-04-01 15:41:32 -0400
committerDonald Sharp <sharpd@cumulusnetworks.com>2019-04-02 08:20:36 -0400
commitade155e146939906da26ce52f9edb1052fadd015 (patch)
tree28a91b1de44e9f1597f16922ba040a2201e334ed
parentc9cd7fbc3f4e0c7722897db71220ae997de1975f (diff)
pimd: pim_nexthop_lookup should return true/false
The current reverse logic led to this code construct if (!pim_nexthop_lookup(...)) { //Do something successfull } This is backwards and will cause logic errors when people use this code. Fix to use true/false for success/failure. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
-rw-r--r--pimd/pim_cmd.c2
-rw-r--r--pimd/pim_igmp_mtrace.c14
-rw-r--r--pimd/pim_mroute.c7
-rw-r--r--pimd/pim_rpf.c14
-rw-r--r--pimd/pim_rpf.h4
5 files changed, 16 insertions, 25 deletions
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c
index f9140802fb..3e61782f8d 100644
--- a/pimd/pim_cmd.c
+++ b/pimd/pim_cmd.c
@@ -5026,7 +5026,7 @@ DEFUN (show_ip_rib,
return CMD_WARNING;
}
- if (pim_nexthop_lookup(vrf->info, &nexthop, addr, 0)) {
+ if (!pim_nexthop_lookup(vrf->info, &nexthop, addr, 0)) {
vty_out(vty,
"Failure querying RIB nexthop for unicast address %s\n",
addr_str);
diff --git a/pimd/pim_igmp_mtrace.c b/pimd/pim_igmp_mtrace.c
index f51e0c0d2f..0758e2f784 100644
--- a/pimd/pim_igmp_mtrace.c
+++ b/pimd/pim_igmp_mtrace.c
@@ -66,16 +66,13 @@ static bool mtrace_fwd_info_weak(struct pim_instance *pim,
struct pim_nexthop nexthop;
struct interface *ifp_in;
struct in_addr nh_addr;
- int ret;
char nexthop_str[INET_ADDRSTRLEN];
nh_addr.s_addr = 0;
memset(&nexthop, 0, sizeof(nexthop));
- ret = pim_nexthop_lookup(pim, &nexthop, mtracep->src_addr, 1);
-
- if (ret != 0) {
+ if (!pim_nexthop_lookup(pim, &nexthop, mtracep->src_addr, 1)) {
if (PIM_DEBUG_MTRACE)
zlog_debug("mtrace not found neighbor");
return false;
@@ -418,9 +415,7 @@ static int mtrace_un_forward_packet(struct pim_instance *pim, struct ip *ip_hdr,
if (interface == NULL) {
memset(&nexthop, 0, sizeof(nexthop));
- ret = pim_nexthop_lookup(pim, &nexthop, ip_hdr->ip_dst, 0);
-
- if (ret != 0) {
+ if (!pim_nexthop_lookup(pim, &nexthop, ip_hdr->ip_dst, 0)) {
close(fd);
if (PIM_DEBUG_MTRACE)
zlog_warn(
@@ -568,7 +563,6 @@ static int mtrace_send_response(struct pim_instance *pim,
struct igmp_mtrace *mtracep, size_t mtrace_len)
{
struct pim_nexthop nexthop;
- int ret;
mtracep->type = PIM_IGMP_MTRACE_RESPONSE;
@@ -599,9 +593,7 @@ static int mtrace_send_response(struct pim_instance *pim,
} else {
memset(&nexthop, 0, sizeof(nexthop));
/* TODO: should use unicast rib lookup */
- ret = pim_nexthop_lookup(pim, &nexthop, mtracep->rsp_addr, 1);
-
- if (ret != 0) {
+ if (!pim_nexthop_lookup(pim, &nexthop, mtracep->rsp_addr, 1)) {
if (PIM_DEBUG_MTRACE)
zlog_warn(
"Dropped response qid=%ud, no route to "
diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c
index bba4031744..92065ff957 100644
--- a/pimd/pim_mroute.c
+++ b/pimd/pim_mroute.c
@@ -513,8 +513,7 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp,
if (!PIM_UPSTREAM_FLAG_TEST_FHR(up->flags)) {
// No if channel, but upstream we are at the RP.
if (pim_nexthop_lookup(pim_ifp->pim, &source,
- up->upstream_register, 0)
- == 0) {
+ up->upstream_register, 0)) {
pim_register_stop_send(source.interface, &sg,
pim_ifp->primary_address,
up->upstream_register);
@@ -531,8 +530,8 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp,
} else {
if (I_am_RP(pim_ifp->pim, up->sg.grp)) {
if (pim_nexthop_lookup(pim_ifp->pim, &source,
- up->upstream_register, 0)
- == 0)
+ up->upstream_register,
+ 0))
pim_register_stop_send(
source.interface, &sg,
pim_ifp->primary_address,
diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c
index ee145a5b51..55f788b5bb 100644
--- a/pimd/pim_rpf.c
+++ b/pimd/pim_rpf.c
@@ -48,8 +48,8 @@ void pim_rpf_set_refresh_time(struct pim_instance *pim)
pim->last_route_change_time);
}
-int pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop,
- struct in_addr addr, int neighbor_needed)
+bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop,
+ struct in_addr addr, int neighbor_needed)
{
struct pim_zlookup_nexthop nexthop_tab[MULTIPATH_NUM];
struct pim_neighbor *nbr = NULL;
@@ -65,7 +65,7 @@ int pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop,
* it will never work
*/
if (addr.s_addr == INADDR_NONE)
- return -1;
+ return false;
if ((nexthop->last_lookup.s_addr == addr.s_addr)
&& (nexthop->last_lookup_time > pim->last_route_change_time)) {
@@ -83,7 +83,7 @@ int pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop,
pim->last_route_change_time, nexthop_str);
}
pim->nexthop_lookups_avoided++;
- return 0;
+ return true;
} else {
if (PIM_DEBUG_TRACE) {
char addr_str[INET_ADDRSTRLEN];
@@ -107,7 +107,7 @@ int pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop,
zlog_warn(
"%s %s: could not find nexthop ifindex for address %s",
__FILE__, __PRETTY_FUNCTION__, addr_str);
- return -1;
+ return false;
}
while (!found && (i < num_ifindex)) {
@@ -179,9 +179,9 @@ int pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop,
nexthop->last_lookup = addr;
nexthop->last_lookup_time = pim_time_monotonic_usec();
nexthop->nbr = nbr;
- return 0;
+ return true;
} else
- return -1;
+ return false;
}
static int nexthop_mismatch(const struct pim_nexthop *nh1,
diff --git a/pimd/pim_rpf.h b/pimd/pim_rpf.h
index a4793df667..57bb22674f 100644
--- a/pimd/pim_rpf.h
+++ b/pimd/pim_rpf.h
@@ -59,8 +59,8 @@ struct pim_upstream;
unsigned int pim_rpf_hash_key(void *arg);
bool pim_rpf_equal(const void *arg1, const void *arg2);
-int pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop,
- struct in_addr addr, int neighbor_needed);
+bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop,
+ struct in_addr addr, int neighbor_needed);
enum pim_rpf_result pim_rpf_update(struct pim_instance *pim,
struct pim_upstream *up, struct pim_rpf *old,
uint8_t is_new);