Skip to content

Commit

Permalink
pimd: Refactor pim NHT
Browse files Browse the repository at this point in the history
Refactor the next hop tracking in PIM to fully support the configured RPF lookup mode.
Moved many NHT related functions to pim_nht.h/c
NHT now tracks both MRIB and URIB tables and makes nexthop decisions based on the configured lookup mode.

Signed-off-by: Nathan Bahr <[email protected]>
  • Loading branch information
nabahr committed Dec 13, 2024
1 parent cc865c0 commit 6d30c8f
Show file tree
Hide file tree
Showing 20 changed files with 931 additions and 824 deletions.
2 changes: 1 addition & 1 deletion pimd/pim_bsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ void pim_bsm_clear(struct pim_instance *pim)
__func__, &nht_p);
}

pim_delete_tracked_nexthop(pim, nht_p, NULL, rp_info);
pim_nht_delete_tracked(pim, nht_p, NULL, rp_info);

if (!pim_get_all_mcast_group(&g_all))
return;
Expand Down
4 changes: 2 additions & 2 deletions pimd/pim_bsr_rpdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ void pim_crp_nht_update(struct pim_instance *pim, struct pim_nexthop_cache *pnc)
struct bsr_crp_rp *rp, ref;
bool ok;

ref.addr = pnc->rpf.rpf_addr;
ref.addr = pnc->addr;
rp = bsr_crp_rps_find(scope->ebsr_rps, &ref);
assertf(rp, "addr=%pPA", &ref.addr);

ok = CHECK_FLAG(pnc->flags, PIM_NEXTHOP_VALID);
ok = pim_nht_pnc_is_valid(pim, pnc);
if (ok == rp->nht_ok)
return;

Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3288,7 +3288,7 @@ DEFUN (show_ip_rib,
return CMD_WARNING;
}

if (!pim_nexthop_lookup(vrf->info, &nexthop, addr, 0)) {
if (!pim_nht_lookup(vrf->info, &nexthop, addr, 0)) {
vty_out(vty,
"Failure querying RIB nexthop for unicast address %s\n",
addr_str);
Expand Down
5 changes: 1 addition & 4 deletions pimd/pim_cmd_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2947,10 +2947,7 @@ int pim_show_nexthop_lookup_cmd_helper(const char *vrf, struct vty *vty,
pim_addr_to_prefix(&grp, group);
memset(&nexthop, 0, sizeof(nexthop));

result =
pim_ecmp_nexthop_lookup(v->info, &nexthop, vif_source, &grp, 0);

if (!result) {
if (!pim_nht_lookup_ecmp(v->info, &nexthop, vif_source, &grp, false)) {
vty_out(vty,
"Nexthop Lookup failed, no usable routes returned.\n");
return CMD_SUCCESS;
Expand Down
29 changes: 8 additions & 21 deletions pimd/pim_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,26 +601,13 @@ void pim_if_addr_add(struct connected *ifc)
ifp->name);
}
}
struct pim_nexthop_cache *pnc = NULL;
struct pim_rpf rpf;
struct zclient *zclient = NULL;

zclient = pim_zebra_zclient_get();
/* RP config might come prior to (local RP's interface)
IF UP event.
In this case, pnc would not have pim enabled
nexthops.
Once Interface is UP and pim info is available,
reregister
with RNH address to receive update and add the
interface as nexthop. */
memset(&rpf, 0, sizeof(struct pim_rpf));
rpf.rpf_addr = pim_addr_from_prefix(ifc->address);
pnc = pim_nexthop_cache_find(pim_ifp->pim, &rpf);
if (pnc)
pim_sendmsg_zebra_rnh(pim_ifp->pim, zclient,
pnc,
ZEBRA_NEXTHOP_REGISTER);

/* RP config might come prior to local RP's interface IF UP event.
* In this case, pnc would not have pim enabled nexthops. Once
* Interface is UP and pim info is available, reregister with RNH
* address to receive update and add the interface as nexthop.
*/
pim_nht_get(pim_ifp->pim, pim_addr_from_prefix(ifc->address));
}
} /* pim */

Expand Down Expand Up @@ -2043,7 +2030,7 @@ void pim_pim_interface_delete(struct interface *ifp)
* pim_ifp->pim_neighbor_list.
*/
pim_sock_delete(ifp, "pim unconfigured on interface");
pim_upstream_nh_if_update(pim_ifp->pim, ifp);
pim_nht_upstream_if_update(pim_ifp->pim, ifp);

if (!pim_ifp->gm_enable) {
pim_if_addr_del_all(ifp);
Expand Down
9 changes: 5 additions & 4 deletions pimd/pim_igmp_mtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "pim_oil.h"
#include "pim_ifchannel.h"
#include "pim_macro.h"
#include "pim_nht.h"
#include "pim_igmp_mtrace.h"

static struct in_addr mtrace_primary_address(struct interface *ifp)
Expand Down Expand Up @@ -58,14 +59,14 @@ static bool mtrace_fwd_info_weak(struct pim_instance *pim,

memset(&nexthop, 0, sizeof(nexthop));

if (!pim_nexthop_lookup(pim, &nexthop, mtracep->src_addr, 1)) {
if (!pim_nht_lookup(pim, &nexthop, mtracep->src_addr, 1)) {
if (PIM_DEBUG_MTRACE)
zlog_debug("mtrace not found neighbor");
return false;
}

if (PIM_DEBUG_MTRACE)
zlog_debug("mtrace pim_nexthop_lookup OK");
zlog_debug("mtrace pim_nht_lookup OK");

if (PIM_DEBUG_MTRACE)
zlog_debug("mtrace next_hop=%pPAs", &nexthop.mrib_nexthop_addr);
Expand Down Expand Up @@ -353,7 +354,7 @@ static int mtrace_un_forward_packet(struct pim_instance *pim, struct ip *ip_hdr,

if (interface == NULL) {
memset(&nexthop, 0, sizeof(nexthop));
if (!pim_nexthop_lookup(pim, &nexthop, ip_hdr->ip_dst, 0)) {
if (!pim_nht_lookup(pim, &nexthop, ip_hdr->ip_dst, 0)) {
if (PIM_DEBUG_MTRACE)
zlog_debug(
"Dropping mtrace packet, no route to destination");
Expand Down Expand Up @@ -535,7 +536,7 @@ static int mtrace_send_response(struct pim_instance *pim,
} else {
memset(&nexthop, 0, sizeof(nexthop));
/* TODO: should use unicast rib lookup */
if (!pim_nexthop_lookup(pim, &nexthop, mtracep->rsp_addr, 1)) {
if (!pim_nht_lookup(pim, &nexthop, mtracep->rsp_addr, 1)) {
if (PIM_DEBUG_MTRACE)
zlog_debug(
"Dropped response qid=%ud, no route to response address",
Expand Down
12 changes: 3 additions & 9 deletions pimd/pim_instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "pim_ssm.h"
#include "pim_rpf.h"
#include "pim_rp.h"
#include "pim_nht.h"
#include "pim_mroute.h"
#include "pim_oil.h"
#include "pim_static.h"
Expand Down Expand Up @@ -46,8 +47,7 @@ static void pim_instance_terminate(struct pim_instance *pim)

pim_bsm_proc_free(pim);

/* Traverse and cleanup rpf_hash */
hash_clean_and_free(&pim->rpf_hash, (void *)pim_rp_list_hash_clean);
pim_nht_terminate(pim);

pim_if_terminate(pim);

Expand Down Expand Up @@ -75,7 +75,6 @@ static void pim_instance_terminate(struct pim_instance *pim)
static struct pim_instance *pim_instance_init(struct vrf *vrf)
{
struct pim_instance *pim;
char hash_name[64];

pim = XCALLOC(MTYPE_PIM_PIM_INSTANCE, sizeof(struct pim_instance));

Expand All @@ -98,12 +97,7 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf)
#endif /* PIM_IPV == 4 */
pim_vxlan_init(pim);

snprintf(hash_name, sizeof(hash_name), "PIM %s RPF Hash", vrf->name);
pim->rpf_hash = hash_create_size(256, pim_rpf_hash_key, pim_rpf_equal,
hash_name);

if (PIM_DEBUG_ZEBRA)
zlog_debug("%s: NHT rpf hash init ", __func__);
pim_nht_init(pim);

pim->ssm_info = pim_ssm_init();

Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct pim_instance {
/* The name of the register-accept prefix-list */
char *register_plist;

struct hash *rpf_hash;
struct hash *nht_hash;
enum pim_rpf_lookup_mode rpf_mode;

void *ssm_info; /* per-vrf SSM configuration */
Expand Down
8 changes: 3 additions & 5 deletions pimd/pim_mroute.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "pim_vxlan.h"
#include "pim_msg.h"
#include "pim_util.h"
#include "pim_nht.h"

static void mroute_read_on(struct pim_instance *pim);
static int pim_upstream_mroute_update(struct channel_oil *c_oil,
Expand Down Expand Up @@ -566,8 +567,7 @@ int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf,
* setting the SPTBIT to true
*/
if (!(pim_addr_is_any(up->upstream_register)) &&
pim_nexthop_lookup(pim_ifp->pim, &source,
up->upstream_register, 0)) {
pim_nht_lookup(pim_ifp->pim, &source, up->upstream_register, 0)) {
pim_register_stop_send(source.interface, &sg,
pim_ifp->primary_address,
up->upstream_register);
Expand All @@ -580,9 +580,7 @@ int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf,
__func__);
} else {
if (I_am_RP(pim_ifp->pim, up->sg.grp)) {
if (pim_nexthop_lookup(pim_ifp->pim, &source,
up->upstream_register,
0))
if (pim_nht_lookup(pim_ifp->pim, &source, up->upstream_register, 0))
pim_register_stop_send(
source.interface, &sg,
pim_ifp->primary_address,
Expand Down
3 changes: 2 additions & 1 deletion pimd/pim_msdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "pim_time.h"
#include "pim_upstream.h"
#include "pim_oil.h"
#include "pim_nht.h"

#include "pim_msdp.h"
#include "pim_msdp_packet.h"
Expand Down Expand Up @@ -691,7 +692,7 @@ bool pim_msdp_peer_rpf_check(struct pim_msdp_peer *mp, struct in_addr rp)
}

/* check if the MSDP peer is the nexthop for the RP */
if (pim_nexthop_lookup(mp->pim, &nexthop, rp, 0) &&
if (pim_nht_lookup(mp->pim, &nexthop, rp, 0) &&
nexthop.mrib_nexthop_addr.s_addr == mp->peer.s_addr) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static int pim_cmd_interface_add(struct interface *ifp)
pim_ifp->pim_enable = true;

pim_if_addr_add_all(ifp);
pim_upstream_nh_if_update(pim_ifp->pim, ifp);
pim_nht_upstream_if_update(pim_ifp->pim, ifp);
pim_if_membership_refresh(ifp);

pim_if_create_pimreg(pim_ifp->pim);
Expand Down
Loading

0 comments on commit 6d30c8f

Please sign in to comment.