]> git.puffer.fish Git - mirror/frr.git/commitdiff
pimd: pim_nexthop_lookup should return true/false 4060/head
authorDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 1 Apr 2019 19:41:32 +0000 (15:41 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 2 Apr 2019 12:20:36 +0000 (08:20 -0400)
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>
pimd/pim_cmd.c
pimd/pim_igmp_mtrace.c
pimd/pim_mroute.c
pimd/pim_rpf.c
pimd/pim_rpf.h

index f9140802fbb07545d9447b289f040443ac490232..3e61782f8df5cd0dac591c167976ac65c97ee4e0 100644 (file)
@@ -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);
index f51e0c0d2f1a1e2be1a3c6df3032a89a17ee7766..0758e2f784eb6c7ddec8300fe0b7b1d39e1fd701 100644 (file)
@@ -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 "
index bba4031744bf4c3b6c9b6a1c55153c8b1163f40e..92065ff957fc839f3ddbbd78cac2933e38c08ee5 100644 (file)
@@ -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,
index ee145a5b51a56501da7508fa300f0d10d0825d16..55f788b5bb8db373295f5a9a3f77c5209f1d2483 100644 (file)
@@ -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,
index a4793df667f379ce10aba5c21a4052c481d958b6..57bb22674fa6209b64d9935b5c70b24f86e9b2ba 100644 (file)
@@ -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);