pimd: Remove pim->vrf_id and use pim->vrf->vrf_id

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>
This commit is contained in:
Donald Sharp 2021-05-12 14:31:45 -04:00
parent e5981db7e9
commit d3cc1e4518
18 changed files with 43 additions and 40 deletions

View 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
*/

View 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,

View 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,

View 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)) {

View 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)

View 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 {

View 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;

View 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",

View 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",

View 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);

View 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(

View 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;

View 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];

View 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;

View 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];

View 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",

View 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)

View 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);