]> git.puffer.fish Git - mirror/frr.git/commitdiff
pimd: Convert vif and ifindex lookups to use 'struct pim_instance *'
authorDonald Sharp <sharpd@cumulusnetworks.com>
Sun, 21 May 2017 12:29:56 +0000 (08:29 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 24 Jul 2017 17:51:36 +0000 (13:51 -0400)
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
pimd/pim_cmd.c
pimd/pim_iface.c
pimd/pim_iface.h
pimd/pim_mroute.c
pimd/pim_nht.c
pimd/pim_oil.c
pimd/pim_static.c
pimd/pim_zebra.c
pimd/pim_zlookup.c

index 86dda43e9c5595f99f23917d0bc689e988587453..580486baddc9dd0c8e99a6464a8fde92d59bbffd 100644 (file)
@@ -1839,8 +1839,9 @@ static void pim_show_neighbors_single(struct vty *vty, const char *neighbor,
        }
 }
 
-static void pim_show_state(struct vty *vty, const char *src_or_group,
-                          const char *group, u_char uj)
+static void pim_show_state(struct pim_instance *pim, struct vty *vty,
+                          const char *src_or_group, const char *group,
+                          u_char uj)
 {
        struct channel_oil *c_oil;
        struct listnode *node;
@@ -1875,7 +1876,7 @@ static void pim_show_state(struct vty *vty, const char *src_or_group,
                               sizeof(grp_str));
                pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, src_str,
                               sizeof(src_str));
-               ifp_in = pim_if_find_by_vif_index(c_oil->oil.mfcc_parent);
+               ifp_in = pim_if_find_by_vif_index(pim, c_oil->oil.mfcc_parent);
 
                if (ifp_in)
                        strcpy(in_ifname, ifp_in->name);
@@ -1957,7 +1958,7 @@ static void pim_show_state(struct vty *vty, const char *src_or_group,
                        if (ttl < 1)
                                continue;
 
-                       ifp_out = pim_if_find_by_vif_index(oif_vif_index);
+                       ifp_out = pim_if_find_by_vif_index(pim, oif_vif_index);
                        pim_time_uptime(
                                oif_uptime, sizeof(oif_uptime),
                                now - c_oil->oif_creation[oif_vif_index]);
@@ -3449,7 +3450,7 @@ DEFUN (show_ip_pim_state,
        } else if (argc == 5)
                src_or_group = argv[4]->arg;
 
-       pim_show_state(vty, src_or_group, group, uj);
+       pim_show_state(pimg, vty, src_or_group, group, uj);
 
        return CMD_SUCCESS;
 }
@@ -3750,7 +3751,7 @@ DEFUN (show_ip_multicast,
        return CMD_SUCCESS;
 }
 
-static void show_mroute(struct vty *vty, u_char uj)
+static void show_mroute(struct pim_instance *pim, struct vty *vty, u_char uj)
 {
        struct listnode *node;
        struct channel_oil *c_oil;
@@ -3770,8 +3771,6 @@ static void show_mroute(struct vty *vty, u_char uj)
        int oif_vif_index;
        struct interface *ifp_in;
        char proto[100];
-       struct vrf *vrf;
-       struct pim_instance *pim;
 
        if (uj) {
                json = json_object_new_object();
@@ -3793,7 +3792,7 @@ static void show_mroute(struct vty *vty, u_char uj)
                               sizeof(grp_str));
                pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, src_str,
                               sizeof(src_str));
-               ifp_in = pim_if_find_by_vif_index(c_oil->oil.mfcc_parent);
+               ifp_in = pim_if_find_by_vif_index(pim, c_oil->oil.mfcc_parent);
 
                if (ifp_in)
                        strcpy(in_ifname, ifp_in->name);
@@ -3846,7 +3845,7 @@ static void show_mroute(struct vty *vty, u_char uj)
                        if (ttl < 1)
                                continue;
 
-                       ifp_out = pim_if_find_by_vif_index(oif_vif_index);
+                       ifp_out = pim_if_find_by_vif_index(pim, oif_vif_index);
                        pim_time_uptime(
                                oif_uptime, sizeof(oif_uptime),
                                now - c_oil->oif_creation[oif_vif_index]);
@@ -3948,145 +3947,125 @@ static void show_mroute(struct vty *vty, u_char uj)
        }
 
        /* Print list of static routes */
-       RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name)
-       {
-               pim = vrf->info;
-               if (!pim)
+       for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, s_route)) {
+               first = 1;
+
+               if (!s_route->c_oil.installed)
                        continue;
 
-               for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, s_route)) {
-                       first = 1;
+               pim_inet4_dump("<group?>", s_route->group, grp_str,
+                              sizeof(grp_str));
+               pim_inet4_dump("<source?>", s_route->source, src_str,
+                              sizeof(src_str));
+               ifp_in = pim_if_find_by_vif_index(pim, s_route->iif);
+               found_oif = 0;
 
-                       if (!s_route->c_oil.installed)
-                               continue;
+               if (ifp_in)
+                       strcpy(in_ifname, ifp_in->name);
+               else
+                       strcpy(in_ifname, "<iif?>");
 
-                       pim_inet4_dump("<group?>", s_route->group, grp_str,
-                                      sizeof(grp_str));
-                       pim_inet4_dump("<source?>", s_route->source, src_str,
-                                      sizeof(src_str));
-                       ifp_in = pim_if_find_by_vif_index(s_route->iif);
-                       found_oif = 0;
+               if (uj) {
 
-                       if (ifp_in)
-                               strcpy(in_ifname, ifp_in->name);
-                       else
-                               strcpy(in_ifname, "<iif?>");
+                       /* Find the group, create it if it doesn't exist */
+                       json_object_object_get_ex(json, grp_str, &json_group);
 
-                       if (uj) {
+                       if (!json_group) {
+                               json_group = json_object_new_object();
+                               json_object_object_add(json, grp_str,
+                                                      json_group);
+                       }
 
-                               /* Find the group, create it if it doesn't exist
-                                */
-                               json_object_object_get_ex(json, grp_str,
-                                                         &json_group);
+                       /* Find the source nested under the group, create it if
+                        * it doesn't exist */
+                       json_object_object_get_ex(json_group, src_str,
+                                                 &json_source);
 
-                               if (!json_group) {
-                                       json_group = json_object_new_object();
-                                       json_object_object_add(json, grp_str,
-                                                              json_group);
-                               }
+                       if (!json_source) {
+                               json_source = json_object_new_object();
+                               json_object_object_add(json_group, src_str,
+                                                      json_source);
+                       }
+
+                       json_object_string_add(json_source, "iif", in_ifname);
+                       json_oil = NULL;
+               } else {
+                       strcpy(proto, "STATIC");
+               }
 
-                               /* Find the source nested under the group,
-                                * create it if it doesn't exist */
-                               json_object_object_get_ex(json_group, src_str,
-                                                         &json_source);
+               for (oif_vif_index = 0; oif_vif_index < MAXVIFS;
+                    ++oif_vif_index) {
+                       struct interface *ifp_out;
+                       char oif_uptime[10];
+                       int ttl;
 
-                               if (!json_source) {
-                                       json_source = json_object_new_object();
-                                       json_object_object_add(json_group,
-                                                              src_str,
-                                                              json_source);
-                               }
+                       ttl = s_route->oif_ttls[oif_vif_index];
+                       if (ttl < 1)
+                               continue;
 
-                               json_object_string_add(json_source, "iif",
-                                                      in_ifname);
-                               json_oil = NULL;
-                       } else {
-                               strcpy(proto, "STATIC");
-                       }
+                       ifp_out = pim_if_find_by_vif_index(pim, oif_vif_index);
+                       pim_time_uptime(
+                               oif_uptime, sizeof(oif_uptime),
+                               now
+                                       - s_route->c_oil
+                                                 .oif_creation[oif_vif_index]);
+                       found_oif = 1;
 
-                       for (oif_vif_index = 0; oif_vif_index < MAXVIFS;
-                            ++oif_vif_index) {
-                               struct interface *ifp_out;
-                               char oif_uptime[10];
-                               int ttl;
-
-                               ttl = s_route->oif_ttls[oif_vif_index];
-                               if (ttl < 1)
-                                       continue;
-
-                               ifp_out =
-                                       pim_if_find_by_vif_index(oif_vif_index);
-                               pim_time_uptime(
-                                       oif_uptime, sizeof(oif_uptime),
-                                       now
-                                               - s_route->c_oil.oif_creation
-                                                         [oif_vif_index]);
-                               found_oif = 1;
-
-                               if (ifp_out)
-                                       strcpy(out_ifname, ifp_out->name);
-                               else
-                                       strcpy(out_ifname, "<oif?>");
+                       if (ifp_out)
+                               strcpy(out_ifname, ifp_out->name);
+                       else
+                               strcpy(out_ifname, "<oif?>");
 
-                               if (uj) {
-                                       json_ifp_out = json_object_new_object();
-                                       json_object_string_add(json_ifp_out,
-                                                              "source",
-                                                              src_str);
-                                       json_object_string_add(
-                                               json_ifp_out, "group", grp_str);
-                                       json_object_boolean_true_add(
-                                               json_ifp_out, "protocolStatic");
-                                       json_object_string_add(
-                                               json_ifp_out,
-                                               "inboundInterface", in_ifname);
-                                       json_object_int_add(
-                                               json_ifp_out, "iVifI",
-                                               s_route->c_oil.oil.mfcc_parent);
-                                       json_object_string_add(
-                                               json_ifp_out,
-                                               "outboundInterface",
-                                               out_ifname);
-                                       json_object_int_add(json_ifp_out,
-                                                           "oVifI",
-                                                           oif_vif_index);
-                                       json_object_int_add(json_ifp_out, "ttl",
-                                                           ttl);
-                                       json_object_string_add(json_ifp_out,
-                                                              "upTime",
-                                                              oif_uptime);
-                                       if (!json_oil) {
-                                               json_oil =
-                                                       json_object_new_object();
-                                               json_object_object_add(
-                                                       json_source, "oil",
-                                                       json_oil);
-                                       }
-                                       json_object_object_add(json_oil,
-                                                              out_ifname,
-                                                              json_ifp_out);
-                               } else {
-                                       vty_out(vty,
-                                               "%-15s %-15s %-6s %-10s %-10s %-3d  %8s %s\n",
-                                               src_str, grp_str, proto,
-                                               in_ifname, out_ifname, ttl,
-                                               oif_uptime, vrf->name);
-                                       if (first) {
-                                               src_str[0] = '\0';
-                                               grp_str[0] = '\0';
-                                               in_ifname[0] = '\0';
-                                               first = 0;
-                                       }
+                       if (uj) {
+                               json_ifp_out = json_object_new_object();
+                               json_object_string_add(json_ifp_out, "source",
+                                                      src_str);
+                               json_object_string_add(json_ifp_out, "group",
+                                                      grp_str);
+                               json_object_boolean_true_add(json_ifp_out,
+                                                            "protocolStatic");
+                               json_object_string_add(json_ifp_out,
+                                                      "inboundInterface",
+                                                      in_ifname);
+                               json_object_int_add(
+                                       json_ifp_out, "iVifI",
+                                       s_route->c_oil.oil.mfcc_parent);
+                               json_object_string_add(json_ifp_out,
+                                                      "outboundInterface",
+                                                      out_ifname);
+                               json_object_int_add(json_ifp_out, "oVifI",
+                                                   oif_vif_index);
+                               json_object_int_add(json_ifp_out, "ttl", ttl);
+                               json_object_string_add(json_ifp_out, "upTime",
+                                                      oif_uptime);
+                               if (!json_oil) {
+                                       json_oil = json_object_new_object();
+                                       json_object_object_add(json_source,
+                                                              "oil", json_oil);
                                }
-                       }
-
-                       if (!uj && !found_oif) {
+                               json_object_object_add(json_oil, out_ifname,
+                                                      json_ifp_out);
+                       } else {
                                vty_out(vty,
                                        "%-15s %-15s %-6s %-10s %-10s %-3d  %8s %s\n",
                                        src_str, grp_str, proto, in_ifname,
-                                       "none", 0, "--:--:--", vrf->name);
+                                       out_ifname, ttl, oif_uptime,
+                                       pim->vrf->name);
+                               if (first) {
+                                       src_str[0] = '\0';
+                                       grp_str[0] = '\0';
+                                       in_ifname[0] = '\0';
+                                       first = 0;
+                               }
                        }
                }
+
+               if (!uj && !found_oif) {
+                       vty_out(vty,
+                               "%-15s %-15s %-6s %-10s %-10s %-3d  %8s %s\n",
+                               src_str, grp_str, proto, in_ifname, "none", 0,
+                               "--:--:--", pim->vrf->name);
+               }
        }
 
        if (uj) {
@@ -4105,7 +4084,7 @@ DEFUN (show_ip_mroute,
        JSON_STR)
 {
        u_char uj = use_json(argc, argv);
-       show_mroute(vty, uj);
+       show_mroute(pimg, vty, uj);
        return CMD_SUCCESS;
 }
 
index ef06fdfb895b0a48b2f831922a8ca3eb5fc51a4f..cc7e03935d5feb982c2855d4345fa0193cca0245 100644 (file)
@@ -1054,28 +1054,19 @@ int pim_if_del_vif(struct interface *ifp)
 }
 
 // DBS - VRF Revist
-struct interface *pim_if_find_by_vif_index(ifindex_t vif_index)
+struct interface *pim_if_find_by_vif_index(struct pim_instance *pim,
+                                          ifindex_t vif_index)
 {
        struct listnode *ifnode;
        struct interface *ifp;
-       struct pim_instance *pim;
-       struct vrf *vrf;
 
-       RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name)
-       {
-               pim = vrf->info;
-               if (!pim)
-                       continue;
-
-               for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode,
-                                         ifp)) {
-                       if (ifp->info) {
-                               struct pim_interface *pim_ifp;
-                               pim_ifp = ifp->info;
+       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, ifp)) {
+               if (ifp->info) {
+                       struct pim_interface *pim_ifp;
+                       pim_ifp = ifp->info;
 
-                               if (vif_index == pim_ifp->mroute_vif_index)
-                                       return ifp;
-                       }
+                       if (vif_index == pim_ifp->mroute_vif_index)
+                               return ifp;
                }
        }
 
@@ -1085,12 +1076,12 @@ struct interface *pim_if_find_by_vif_index(ifindex_t vif_index)
 /*
   pim_if_add_vif() uses ifindex as vif_index
  */
-int pim_if_find_vifindex_by_ifindex(ifindex_t ifindex)
+int pim_if_find_vifindex_by_ifindex(struct pim_instance *pim, ifindex_t ifindex)
 {
        struct pim_interface *pim_ifp;
        struct interface *ifp;
 
-       ifp = if_lookup_by_index(ifindex, pimg->vrf_id);
+       ifp = if_lookup_by_index(ifindex, pim->vrf_id);
        if (!ifp || !ifp->info)
                return -1;
        pim_ifp = ifp->info;
index ef81152af98d39f3d03a70bde78a1dc26e44fd23..e4b1b8e675a40dcd807a91d77489c17bcbdb1697 100644 (file)
@@ -169,8 +169,10 @@ int pim_if_del_vif(struct interface *ifp);
 void pim_if_add_vif_all(struct pim_instance *pim);
 void pim_if_del_vif_all(struct pim_instance *pim);
 
-struct interface *pim_if_find_by_vif_index(ifindex_t vif_index);
-int pim_if_find_vifindex_by_ifindex(ifindex_t ifindex);
+struct interface *pim_if_find_by_vif_index(struct pim_instance *pim,
+                                          ifindex_t vif_index);
+int pim_if_find_vifindex_by_ifindex(struct pim_instance *pim,
+                                   ifindex_t ifindex);
 
 int pim_if_lan_delay_enabled(struct interface *ifp);
 uint16_t pim_if_effective_propagation_delay_msec(struct interface *ifp);
index 8b9269518c69b7f57dfd6e5fd3ae37c682a2bb8d..4c0820b6034219f70a7c1d0dc80ba6dcecb7f38f 100644 (file)
@@ -197,6 +197,7 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp,
        if (up->channel_oil->oil.mfcc_parent >= MAXVIFS) {
                int vif_index = 0;
                vif_index = pim_if_find_vifindex_by_ifindex(
+                       pim_ifp->pim,
                        up->rpf.source_nexthop.interface->ifindex);
                up->channel_oil->oil.mfcc_parent = vif_index;
        }
@@ -597,7 +598,7 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf,
        } else {
                msg = (const struct igmpmsg *)buf;
 
-               ifp = pim_if_find_by_vif_index(msg->im_vif);
+               ifp = pim_if_find_by_vif_index(pim, msg->im_vif);
 
                if (!ifp)
                        return 0;
index eb8bfa7115b6d6ac6712316aaa98d7e9cf324a94..1cc5e78da7cbd973dd9a3ba3680ae8a8a441ea0f 100644 (file)
@@ -358,7 +358,8 @@ static int pim_update_upstream_nh(struct pim_instance *pim,
                if (up->channel_oil) {
                        ifindex_t ifindex =
                                up->rpf.source_nexthop.interface->ifindex;
-                       vif_index = pim_if_find_vifindex_by_ifindex(ifindex);
+                       vif_index =
+                               pim_if_find_vifindex_by_ifindex(pim, ifindex);
                        /* Pass Current selected NH vif index to mroute download
                         */
                        if (vif_index)
@@ -1063,7 +1064,7 @@ int pim_ecmp_fib_lookup_if_vif_index(struct pim_instance *pim,
                        ifindex2ifname(first_ifindex, pim->vrf_id), addr_str);
        }
 
-       vif_index = pim_if_find_vifindex_by_ifindex(first_ifindex);
+       vif_index = pim_if_find_vifindex_by_ifindex(pim, first_ifindex);
 
        if (vif_index < 0) {
                if (PIM_DEBUG_ZEBRA) {
index d4398d1c23b911ee811d45cc95b8ca9b42ad3263..375acbc663c7017122d7b26571833219350c74b1 100644 (file)
@@ -169,7 +169,7 @@ struct channel_oil *pim_channel_oil_add(struct prefix_sg *sg,
                return c_oil;
        }
 
-       ifp = pim_if_find_by_vif_index(input_vif_index);
+       ifp = pim_if_find_by_vif_index(pimg, input_vif_index);
        if (!ifp) {
                /* warning only */
                zlog_warn(
index 981335ea15c715eb9e27a0e340e216f2b8a3a5d0..980933aa8a88936cabd5e6d8dab65e8b7ca592e0 100644 (file)
@@ -358,7 +358,8 @@ int pim_static_write_mroute(struct vty *vty, struct pim_instance *pim,
                        for (i = 0; i < MAXVIFS; i++)
                                if (sroute->oif_ttls[i]) {
                                        struct interface *oifp =
-                                               pim_if_find_by_vif_index(i);
+                                               pim_if_find_by_vif_index(pim,
+                                                                        i);
                                        if (sroute->source.s_addr == 0)
                                                vty_out(vty,
                                                        " ip mroute %s %s\n",
index f911293219a9aa62676c291c3715fdb81b7657e1..e77086059fb45e040c4e7ac8dbbdff79284299d4 100644 (file)
@@ -545,10 +545,10 @@ void pim_scan_individual_oil(struct channel_oil *c_oil, int in_vif_index)
        }
 
        if (PIM_DEBUG_ZEBRA) {
-               struct interface *old_iif =
-                       pim_if_find_by_vif_index(c_oil->oil.mfcc_parent);
-               struct interface *new_iif =
-                       pim_if_find_by_vif_index(input_iface_vif_index);
+               struct interface *old_iif = pim_if_find_by_vif_index(
+                       c_oil->pim, c_oil->oil.mfcc_parent);
+               struct interface *new_iif = pim_if_find_by_vif_index(
+                       c_oil->pim, input_iface_vif_index);
                char source_str[INET_ADDRSTRLEN];
                char group_str[INET_ADDRSTRLEN];
                pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str,
@@ -564,8 +564,8 @@ void pim_scan_individual_oil(struct channel_oil *c_oil, int in_vif_index)
 
        /* new iif loops to existing oif ? */
        if (c_oil->oil.mfcc_ttls[input_iface_vif_index]) {
-               struct interface *new_iif =
-                       pim_if_find_by_vif_index(input_iface_vif_index);
+               struct interface *new_iif = pim_if_find_by_vif_index(
+                       c_oil->pim, input_iface_vif_index);
 
                if (PIM_DEBUG_ZEBRA) {
                        char source_str[INET_ADDRSTRLEN];
@@ -590,10 +590,10 @@ void pim_scan_individual_oil(struct channel_oil *c_oil, int in_vif_index)
        if (pim_mroute_add(c_oil, __PRETTY_FUNCTION__)) {
                if (PIM_DEBUG_MROUTE) {
                        /* just log warning */
-                       struct interface *old_iif =
-                               pim_if_find_by_vif_index(old_vif_index);
-                       struct interface *new_iif =
-                               pim_if_find_by_vif_index(input_iface_vif_index);
+                       struct interface *old_iif = pim_if_find_by_vif_index(
+                               c_oil->pim, old_vif_index);
+                       struct interface *new_iif = pim_if_find_by_vif_index(
+                               c_oil->pim, input_iface_vif_index);
                        char source_str[INET_ADDRSTRLEN];
                        char group_str[INET_ADDRSTRLEN];
                        pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin,
@@ -627,7 +627,8 @@ void pim_scan_oil()
                if (c_oil->up && c_oil->up->rpf.source_nexthop.interface) {
                        ifindex = c_oil->up->rpf.source_nexthop
                                          .interface->ifindex;
-                       vif_index = pim_if_find_vifindex_by_ifindex(ifindex);
+                       vif_index = pim_if_find_vifindex_by_ifindex(c_oil->pim,
+                                                                   ifindex);
                        /* Pass Current selected NH vif index to mroute download
                         */
                        if (vif_index)
@@ -917,6 +918,7 @@ void igmp_source_forward_start(struct igmp_source *source)
                                if (nexthop.interface)
                                        input_iface_vif_index =
                                                pim_if_find_vifindex_by_ifindex(
+                                                       pimg,
                                                        nexthop.interface->ifindex);
                        } else {
                                if (PIM_DEBUG_ZEBRA) {
@@ -1154,6 +1156,7 @@ void pim_forward_start(struct pim_ifchannel *ch)
                                            0))
                                        input_iface_vif_index =
                                                pim_if_find_vifindex_by_ifindex(
+                                                       pimg,
                                                        up->rpf.source_nexthop
                                                                .interface->ifindex);
                                else {
@@ -1197,8 +1200,8 @@ void pim_forward_start(struct pim_ifchannel *ch)
                        return;
                }
                if (PIM_DEBUG_TRACE) {
-                       struct interface *in_intf =
-                               pim_if_find_by_vif_index(input_iface_vif_index);
+                       struct interface *in_intf = pim_if_find_by_vif_index(
+                               pimg, input_iface_vif_index);
                        zlog_debug(
                                "%s: Update channel_oil IIF %s VIFI %d entry %s ",
                                __PRETTY_FUNCTION__,
index bde5042b6b110705a0628229f5cfa1a8c2fe6064..26d0dffe73a320f5c038d644f1a8c38b39c6bf7a 100644 (file)
@@ -472,7 +472,7 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil)
        int count = 0;
        int ret;
        struct interface *ifp =
-               pim_if_find_by_vif_index(c_oil->oil.mfcc_parent);
+               pim_if_find_by_vif_index(c_oil->pim, c_oil->oil.mfcc_parent);
 
        if (PIM_DEBUG_ZEBRA) {
                struct prefix_sg more;