]> git.puffer.fish Git - mirror/frr.git/commitdiff
pimd: Remove pim->vrf_id and use pim->vrf->vrf_id 8616/head
authorDonald Sharp <sharpd@nvidia.com>
Wed, 12 May 2021 18:31:45 +0000 (14:31 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Wed, 12 May 2021 18:36:59 +0000 (14:36 -0400)
VRF creation can happen from either cli or from
knowledged about the vrf learned from zebra.
In the case where we learn about the vrf from
the cli, the vrf id is UNKNOWN.  Upon actual
creation of the vrf, lib/vrf.c touches up the vrf_id
and calls pim_vrf_enable to turn it on properly.
At this point in time we have a pim->vrf_id of
UNKNOWN and the vrf->vrf_id of the right value.

There is no point in duplicating this data.  So just
remove all pim->vrf_id and use the vrf->vrf_id instead
since we keep a copy of the pim->vrf pointer.

This will remove some crashes where we expect the
pim->vrf_id to be usable and it's not.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
18 files changed:
pimd/pim_bsm.c
pimd/pim_cmd.c
pimd/pim_iface.c
pimd/pim_igmp_mtrace.c
pimd/pim_instance.c
pimd/pim_instance.h
pimd/pim_mroute.c
pimd/pim_msdp_socket.c
pimd/pim_nb_config.c
pimd/pim_nht.c
pimd/pim_pim.c
pimd/pim_rp.c
pimd/pim_rpf.c
pimd/pim_ssm.c
pimd/pim_ssmpingd.c
pimd/pim_vty.c
pimd/pim_vxlan.c
pimd/pim_zlookup.c

index 3fbe3317ba9ca52e552e6cbc3b29ddf19baa8279..ad5257630bb130246258125a496596b6aad13e1a 100644 (file)
@@ -1320,7 +1320,7 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf,
                        }
                }
        } else if (if_lookup_exact_address(&ip_hdr->ip_dst, AF_INET,
-                                          pim->vrf_id)) {
+                                          pim->vrf->vrf_id)) {
                /* Unicast BSM received - if ucast bsm not enabled on
                 * the interface, drop it
                 */
index 90aa15beee2d4d81bbd49a4bf15c62cada046884..d5348eeb60a633c2e9a014294bc275c4f5fb1021 100644 (file)
@@ -810,7 +810,7 @@ static void igmp_show_interface_join(struct pim_instance *pim, struct vty *vty,
        if (uj) {
                json = json_object_new_object();
                json_object_string_add(json, "vrf",
-                                      vrf_id_to_name(pim->vrf_id));
+                                      vrf_id_to_name(pim->vrf->vrf_id));
        } else {
                vty_out(vty,
                        "Interface        Address         Source          Group           Socket Uptime  \n");
@@ -2971,7 +2971,7 @@ static int pim_print_pnc_cache_walkcb(struct hash_bucket *bucket, void *arg)
 
        for (nh_node = pnc->nexthop; nh_node; nh_node = nh_node->next) {
                first_ifindex = nh_node->ifindex;
-               ifp = if_lookup_by_index(first_ifindex, pim->vrf_id);
+               ifp = if_lookup_by_index(first_ifindex, pim->vrf->vrf_id);
 
                vty_out(vty, "%-15s ", inet_ntop(AF_INET,
                                                 &pnc->rpf.rpf_addr.u.prefix4,
index 4a04c7a91e1ee1f2cd5421a1a651af2edf276174..353f1330015f570244db5c4613cd8c158ab9da61 100644 (file)
@@ -1050,7 +1050,7 @@ 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, pim->vrf_id);
+       ifp = if_lookup_by_index(ifindex, pim->vrf->vrf_id);
        if (!ifp || !ifp->info)
                return -1;
        pim_ifp = ifp->info;
@@ -1477,13 +1477,13 @@ void pim_if_create_pimreg(struct pim_instance *pim)
        char pimreg_name[INTERFACE_NAMSIZ];
 
        if (!pim->regiface) {
-               if (pim->vrf_id == VRF_DEFAULT)
+               if (pim->vrf->vrf_id == VRF_DEFAULT)
                        strlcpy(pimreg_name, "pimreg", sizeof(pimreg_name));
                else
                        snprintf(pimreg_name, sizeof(pimreg_name), "pimreg%u",
                                 pim->vrf->data.l.table_id);
 
-               pim->regiface = if_create_name(pimreg_name, pim->vrf_id);
+               pim->regiface = if_create_name(pimreg_name, pim->vrf->vrf_id);
                pim->regiface->ifindex = PIM_OIF_PIM_REGISTER_VIF;
 
                pim_if_new(pim->regiface, false, false, true,
index d36a275f85e6b18e38c86306d0bf07eed46d4943..73af44fc4657c365695cdd97b461f3e50995a3bf 100644 (file)
@@ -597,7 +597,7 @@ int igmp_mtrace_recv_qry_req(struct igmp_sock *igmp, struct ip *ip_hdr,
         */
        if (!IPV4_CLASS_DE(ntohl(ip_hdr->ip_dst.s_addr)))
                if (!if_lookup_exact_address(&ip_hdr->ip_dst, AF_INET,
-                                            pim->vrf_id))
+                                            pim->vrf->vrf_id))
                        return mtrace_forward_packet(pim, ip_hdr);
 
        if (igmp_msg_len < (int)sizeof(struct igmp_mtrace)) {
index a7048ecefaaefef715d0b6dc9ce67ba6747ed895..47358f38e1f17b7acdae70e5f7532ed5a6861d43 100644 (file)
@@ -92,7 +92,6 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf)
        pim->ecmp_enable = false;
        pim->ecmp_rebalance_enable = false;
 
-       pim->vrf_id = vrf->vrf_id;
        pim->vrf = vrf;
 
        pim->spt.switchover = PIM_SPT_IMMEDIATE;
@@ -177,7 +176,7 @@ static int pim_vrf_enable(struct vrf *vrf)
        struct pim_instance *pim = (struct pim_instance *)vrf->info;
        struct interface *ifp;
 
-       zlog_debug("%s: for %s", __func__, vrf->name);
+       zlog_debug("%s: for %s %u", __func__, vrf->name, vrf->vrf_id);
 
        FOR_ALL_INTERFACES (vrf, ifp) {
                if (!ifp->info)
index 2b76da21b2658d579e39c770b163a8ff109e0ef9..72c726690c915f2fbd51e6b60ce7b4545ea299ae 100644 (file)
@@ -127,7 +127,7 @@ struct pim_router {
 
 /* Per VRF PIM DB */
 struct pim_instance {
-       vrf_id_t vrf_id;
+       // vrf_id_t vrf_id;
        struct vrf *vrf;
 
        struct {
index afd38face303015063be8b5bea560889a0a376d5..ab6d8c17dfc5286d0a70439e568d4404f4022b0a 100644 (file)
@@ -56,7 +56,7 @@ static int pim_mroute_set(struct pim_instance *pim, int enable)
        /*
         * We need to create the VRF table for the pim mroute_socket
         */
-       if (pim->vrf_id != VRF_DEFAULT) {
+       if (pim->vrf->vrf_id != VRF_DEFAULT) {
                frr_with_privs(&pimd_privs) {
 
                        data = pim->vrf->data.l.table_id;
@@ -609,7 +609,7 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf,
                 * the source
                 * of the IP packet.
                 */
-               ifp = if_lookup_by_index(ifindex, pim->vrf_id);
+               ifp = if_lookup_by_index(ifindex, pim->vrf->vrf_id);
 
                if (!ifp || !ifp->info)
                        return 0;
index 9c3cdb27115fef0db5f52ad26db70e0382c3c2d7..78a8265a1c88362c68743ad61112150efb57af47 100644 (file)
@@ -156,9 +156,9 @@ int pim_msdp_sock_listen(struct pim_instance *pim)
        sockopt_reuseaddr(sock);
        sockopt_reuseport(sock);
 
-       if (pim->vrf_id != VRF_DEFAULT) {
+       if (pim->vrf->vrf_id != VRF_DEFAULT) {
                struct interface *ifp =
-                       if_lookup_by_name(pim->vrf->name, pim->vrf_id);
+                       if_lookup_by_name(pim->vrf->name, pim->vrf->vrf_id);
                if (!ifp) {
                        flog_err(EC_LIB_INTERFACE,
                                 "%s: Unable to lookup vrf interface: %s",
@@ -243,9 +243,9 @@ int pim_msdp_sock_connect(struct pim_msdp_peer *mp)
                return -1;
        }
 
-       if (mp->pim->vrf_id != VRF_DEFAULT) {
-               struct interface *ifp =
-                       if_lookup_by_name(mp->pim->vrf->name, mp->pim->vrf_id);
+       if (mp->pim->vrf->vrf_id != VRF_DEFAULT) {
+               struct interface *ifp = if_lookup_by_name(mp->pim->vrf->name,
+                                                         mp->pim->vrf->vrf_id);
                if (!ifp) {
                        flog_err(EC_LIB_INTERFACE,
                                 "%s: Unable to lookup vrf interface: %s",
index 4598297f93b3c7e93689583caec7d80a85bcd8be..6fe83599b0e6c25926ebc96c559a28f6f3bb5db7 100644 (file)
@@ -220,7 +220,7 @@ static int pim_cmd_spt_switchover(struct pim_instance *pim,
 static int pim_ssm_cmd_worker(struct pim_instance *pim, const char *plist,
                char *errmsg, size_t errmsg_len)
 {
-       int result = pim_ssm_range_set(pim, pim->vrf_id, plist);
+       int result = pim_ssm_range_set(pim, pim->vrf->vrf_id, plist);
        int ret = NB_ERR;
 
        if (result == PIM_SSM_ERR_NONE)
@@ -2399,7 +2399,7 @@ int lib_interface_pim_address_family_mroute_destroy(
                pim = pim_iifp->pim;
 
                oifname = yang_dnode_get_string(args->dnode, "./oif");
-               oif = if_lookup_by_name(oifname, pim->vrf_id);
+               oif = if_lookup_by_name(oifname, pim->vrf->vrf_id);
 
                if (!oif) {
                        snprintf(args->errmsg, args->errmsg_len,
@@ -2458,7 +2458,7 @@ int lib_interface_pim_address_family_mroute_oif_modify(
                pim = pim_iifp->pim;
 
                oifname = yang_dnode_get_string(args->dnode, NULL);
-               oif = if_lookup_by_name(oifname, pim->vrf_id);
+               oif = if_lookup_by_name(oifname, pim->vrf->vrf_id);
 
                if (oif && (iif->ifindex == oif->ifindex)) {
                        strlcpy(args->errmsg,
@@ -2477,7 +2477,7 @@ int lib_interface_pim_address_family_mroute_oif_modify(
                pim = pim_iifp->pim;
 
                oifname = yang_dnode_get_string(args->dnode, NULL);
-               oif = if_lookup_by_name(oifname, pim->vrf_id);
+               oif = if_lookup_by_name(oifname, pim->vrf->vrf_id);
                if (!oif) {
                        snprintf(args->errmsg, args->errmsg_len,
                                 "No such interface name %s",
index 68e0a45690e82c7d8cbaaa973b40a43aa3759d46..23ba3498ae6db3ee070ef72754f00b234ad9c80c 100644 (file)
@@ -54,7 +54,7 @@ void pim_sendmsg_zebra_rnh(struct pim_instance *pim, struct zclient *zclient,
        int ret;
 
        p = &(pnc->rpf.rpf_addr);
-       ret = zclient_send_rnh(zclient, command, p, false, pim->vrf_id);
+       ret = zclient_send_rnh(zclient, command, p, false, pim->vrf->vrf_id);
        if (ret == ZCLIENT_SEND_FAILURE)
                zlog_warn("sendmsg_nexthop: zclient_send_message() failed");
 
@@ -266,7 +266,7 @@ bool pim_nexthop_match(struct pim_instance *pim, struct in_addr addr,
        while (i < num_ifindex) {
                first_ifindex = nexthop_tab[i].ifindex;
 
-               ifp = if_lookup_by_index(first_ifindex, pim->vrf_id);
+               ifp = if_lookup_by_index(first_ifindex, pim->vrf->vrf_id);
                if (!ifp) {
                        if (PIM_DEBUG_ZEBRA) {
                                char addr_str[INET_ADDRSTRLEN];
@@ -344,7 +344,7 @@ bool pim_nexthop_match_nht_cache(struct pim_instance *pim, struct in_addr addr,
 
        for (nh_node = pnc->nexthop; nh_node; nh_node = nh_node->next) {
                first_ifindex = nh_node->ifindex;
-               ifp = if_lookup_by_index(first_ifindex, pim->vrf_id);
+               ifp = if_lookup_by_index(first_ifindex, pim->vrf->vrf_id);
                if (!ifp) {
                        if (PIM_DEBUG_PIM_NHT) {
                                char addr_str[INET_ADDRSTRLEN];
@@ -590,7 +590,8 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim,
         */
        for (nh_node = pnc->nexthop, i = 0; nh_node;
             nh_node = nh_node->next, i++) {
-               ifps[i] = if_lookup_by_index(nh_node->ifindex, pim->vrf_id);
+               ifps[i] =
+                       if_lookup_by_index(nh_node->ifindex, pim->vrf->vrf_id);
                if (ifps[i]) {
                        nbrs[i] = pim_neighbor_find(ifps[i],
                                                    nh_node->gate.ipv4);
@@ -774,7 +775,7 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS)
                                break;
                        case NEXTHOP_TYPE_IPV6_IFINDEX:
                                ifp1 = if_lookup_by_index(nexthop->ifindex,
-                                                         pim->vrf_id);
+                                                         pim->vrf->vrf_id);
 
                                if (!ifp1)
                                        nbr = NULL;
@@ -793,7 +794,8 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS)
                                break;
                        }
 
-                       ifp = if_lookup_by_index(nexthop->ifindex, pim->vrf_id);
+                       ifp = if_lookup_by_index(nexthop->ifindex,
+                                                pim->vrf->vrf_id);
                        if (!ifp) {
                                if (PIM_DEBUG_PIM_NHT) {
                                        char buf[NEXTHOP_STRLEN];
@@ -940,7 +942,7 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim,
         */
        for (i = 0; i < num_ifindex; i++) {
                ifps[i] = if_lookup_by_index(nexthop_tab[i].ifindex,
-                                            pim->vrf_id);
+                                            pim->vrf->vrf_id);
                if (ifps[i]) {
                        nbrs[i] = pim_neighbor_find(
                                ifps[i], nexthop_tab[i].nexthop_addr.u.prefix4);
@@ -1076,7 +1078,8 @@ int pim_ecmp_fib_lookup_if_vif_index(struct pim_instance *pim,
        if (PIM_DEBUG_PIM_NHT)
                zlog_debug(
                        "%s: found nexthop ifindex=%d (interface %s(%s)) for address %s",
-                       __func__, ifindex, ifindex2ifname(ifindex, pim->vrf_id),
+                       __func__, ifindex,
+                       ifindex2ifname(ifindex, pim->vrf->vrf_id),
                        pim->vrf->name, addr_str);
 
        vif_index = pim_if_find_vifindex_by_ifindex(pim, ifindex);
index 4ba08a19d8e0ebcfa287e1ea12ad5b328775fced..e7ac0d4e5b2f6bc5f6f1cf3c4b12e13884c6cebc 100644 (file)
@@ -369,7 +369,7 @@ static int pim_sock_read(struct thread *t)
                 * the right ifindex, so just use it.  We know
                 * it's the right interface because we bind to it
                 */
-               ifp = if_lookup_by_index(ifindex, pim_ifp->pim->vrf_id);
+               ifp = if_lookup_by_index(ifindex, pim_ifp->pim->vrf->vrf_id);
                if (!ifp || !ifp->info) {
                        if (PIM_DEBUG_PIM_PACKETS)
                                zlog_debug(
index feaeea929d7dca5dd61861ce64eda32b3c0503f3..a31fec036fc6a1ef7d36ca586c3193773cfc4b10 100644 (file)
@@ -1159,7 +1159,7 @@ int pim_rp_config_write(struct pim_instance *pim, struct vty *vty,
 bool pim_rp_check_is_my_ip_address(struct pim_instance *pim,
                                   struct in_addr dest_addr)
 {
-       if (if_lookup_exact_address(&dest_addr, AF_INET, pim->vrf_id))
+       if (if_lookup_exact_address(&dest_addr, AF_INET, pim->vrf->vrf_id))
                return true;
 
        return false;
@@ -1323,7 +1323,7 @@ void pim_resolve_rp_nh(struct pim_instance *pim, struct pim_neighbor *nbr)
                                continue;
 
                        struct interface *ifp1 = if_lookup_by_index(
-                               nh_node->ifindex, pim->vrf_id);
+                               nh_node->ifindex, pim->vrf->vrf_id);
 
                        if (nbr->interface != ifp1)
                                continue;
index 043ccdb848fb699f50190932f1f6af0371a6d173..98944e8fed78696b2fe86abfc02cc03dc1d65a96 100644 (file)
@@ -112,7 +112,7 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop,
        while (!found && (i < num_ifindex)) {
                first_ifindex = nexthop_tab[i].ifindex;
 
-               ifp = if_lookup_by_index(first_ifindex, pim->vrf_id);
+               ifp = if_lookup_by_index(first_ifindex, pim->vrf->vrf_id);
                if (!ifp) {
                        if (PIM_DEBUG_ZEBRA) {
                                char addr_str[INET_ADDRSTRLEN];
index 8d3e04f5da511a867b7a0ae76e69da9711cb9926..6c5883aebff4887d11dfe4adf81dd692edb071c1 100644 (file)
@@ -112,7 +112,7 @@ int pim_ssm_range_set(struct pim_instance *pim, vrf_id_t vrf_id,
        struct pim_ssm *ssm;
        int change = 0;
 
-       if (vrf_id != pim->vrf_id)
+       if (vrf_id != pim->vrf->vrf_id)
                return PIM_SSM_ERR_NO_VRF;
 
        ssm = pim->ssm_info;
index 03e77de161f33b45aa4cd5aebf98db2a60d35296..abd95e648e22ca156971a29a73c2f8925c796654 100644 (file)
@@ -267,7 +267,7 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss)
                return -1;
        }
 
-       ifp = if_lookup_by_index(ifindex, ss->pim->vrf_id);
+       ifp = if_lookup_by_index(ifindex, ss->pim->vrf->vrf_id);
 
        if (buf[0] != PIM_SSMPINGD_REQUEST) {
                char source_str[INET_ADDRSTRLEN];
index 929d35101ea84cc024a34d9e6ec9a6cae7236941..c049ef4029e8213a742a4f0a8902f32ffa897d5f 100644 (file)
@@ -171,7 +171,7 @@ int pim_global_config_write_worker(struct pim_instance *pim, struct vty *vty)
        struct pim_ssm *ssm = pim->ssm_info;
        char spaces[10];
 
-       if (pim->vrf_id == VRF_DEFAULT)
+       if (pim->vrf->vrf_id == VRF_DEFAULT)
                snprintf(spaces, sizeof(spaces), "%s", "");
        else
                snprintf(spaces, sizeof(spaces), "%s", " ");
@@ -186,7 +186,7 @@ int pim_global_config_write_worker(struct pim_instance *pim, struct vty *vty)
 
        writes += pim_rp_config_write(pim, vty, spaces);
 
-       if (pim->vrf_id == VRF_DEFAULT) {
+       if (pim->vrf->vrf_id == VRF_DEFAULT) {
                if (router->register_suppress_time
                    != PIM_REGISTER_SUPPRESSION_TIME_DEFAULT) {
                        vty_out(vty, "%sip pim register-suppress-time %d\n",
index 6a12c7fb13df772f2b0a1bea809423437b743529..5d5ea1bfe6c027eeec01eb675a4719d2b1e5aa94 100644 (file)
@@ -1076,7 +1076,7 @@ void pim_vxlan_add_vif(struct interface *ifp)
        struct pim_interface *pim_ifp = ifp->info;
        struct pim_instance *pim = pim_ifp->pim;
 
-       if (pim->vrf_id != VRF_DEFAULT)
+       if (pim->vrf->vrf_id != VRF_DEFAULT)
                return;
 
        if (if_is_loopback_or_vrf(ifp))
@@ -1095,7 +1095,7 @@ void pim_vxlan_del_vif(struct interface *ifp)
        struct pim_interface *pim_ifp = ifp->info;
        struct pim_instance *pim = pim_ifp->pim;
 
-       if (pim->vrf_id != VRF_DEFAULT)
+       if (pim->vrf->vrf_id != VRF_DEFAULT)
                return;
 
        if (pim->vxlan.default_iif == ifp)
index 72505a69931f041aafc9566d5dd95b242a6289d3..9ccf1fedd421171d2c44e31deccc61bceaf0c40b 100644 (file)
@@ -544,7 +544,8 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil)
                return -1;
 
        stream_reset(s);
-       zclient_create_header(s, ZEBRA_IPMR_ROUTE_STATS, c_oil->pim->vrf_id);
+       zclient_create_header(s, ZEBRA_IPMR_ROUTE_STATS,
+                             c_oil->pim->vrf->vrf_id);
        stream_put_in_addr(s, &c_oil->oil.mfcc_origin);
        stream_put_in_addr(s, &c_oil->oil.mfcc_mcastgrp);
        stream_putl(s, ifp->ifindex);