Skip to content

Commit

Permalink
pimd: Update nexthops when lookup mode changes
Browse files Browse the repository at this point in the history
Link up the RPF lookup mode changing to a force update to RP's and
upstreams registered for nexthop lookup cache updates.

Signed-off-by: Nathan Bahr <[email protected]>
  • Loading branch information
nabahr committed Oct 27, 2024
1 parent 4585f61 commit 5c606a4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pimd/pim_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,7 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_mc
struct vrf *vrf;
struct pim_instance *pim;
const char *mode;
enum pim_rpf_lookup_mode old_mode;

switch (args->event) {
case NB_EV_VALIDATE:
Expand All @@ -1692,9 +1693,8 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_mc
pim = vrf->info;
mode = yang_dnode_get_string(args->dnode, NULL);

if (strmatch(mode, "none"))
pim->rpf_mode = MCAST_NO_CONFIG;
else if (strmatch(mode, "urib-only"))
old_mode = pim->rpf_mode;
if (strmatch(mode, "urib-only"))
pim->rpf_mode = MCAST_URIB_ONLY;
else if (strmatch(mode, "mrib-only"))
pim->rpf_mode = MCAST_MRIB_ONLY;
Expand All @@ -1710,7 +1710,12 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_mc
return CMD_WARNING_CONFIG_FAILED;
}

/* TODO: Signal to redo lookups? */
if (pim->rpf_mode != old_mode &&
/* MCAST_MIX_MRIB_FIRST is the default if not configured */
(old_mode != MCAST_NO_CONFIG && pim->rpf_mode != MCAST_MIX_MRIB_FIRST)) {
pim_nht_mode_changed(pim);
}

break;
}

Expand All @@ -1722,6 +1727,7 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_mc
{
struct vrf *vrf;
struct pim_instance *pim;
enum pim_rpf_lookup_mode old_mode;

switch (args->event) {
case NB_EV_VALIDATE:
Expand All @@ -1731,8 +1737,12 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_mc
case NB_EV_APPLY:
vrf = nb_running_get_entry(args->dnode, NULL, true);
pim = vrf->info;
old_mode = pim->rpf_mode;
pim->rpf_mode = MCAST_NO_CONFIG;
/* TODO: Signal to redo lookups? */
/* MCAST_MIX_MRIB_FIRST is the default if not configured */
if (old_mode != MCAST_NO_CONFIG && old_mode != MCAST_MIX_MRIB_FIRST) {
pim_nht_mode_changed(pim);
}
break;
}

Expand Down
30 changes: 30 additions & 0 deletions pimd/pim_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,36 @@ void pim_nexthop_update(struct vrf *vrf, struct prefix *match, struct zapi_route
pim_nht_crp_update(pim, pnc);
}

static int pim_nht_hash_mode_update_helper(struct hash_bucket *bucket, void *arg)
{
struct pim_nexthop_cache *pnc = bucket->data;
struct pnc_hash_walk_data *pwd = arg;
struct pim_instance *pim = pwd->pim;

if (listcount(pnc->rp_list))
pim_update_rp_nh(pim, pnc);

if (pnc->upstream_hash->count)
pim_update_upstream_nh(pim, pnc);

if (pnc->candrp_count)
pim_nht_crp_update(pim, pnc);

return HASHWALK_CONTINUE;
}

void pim_nht_mode_changed(struct pim_instance *pim)
{
struct pnc_hash_walk_data pwd;

/* Update the refresh time to force new lookups if needed */
pim_rpf_set_refresh_time(pim);

/* Force update the registered RP and upstreams for all cache entries */
pwd.pim = pim;
hash_walk(pim->nht_hash, pim_nht_hash_mode_update_helper, &pwd);
}

/* Cleanup pim->nht_hash each node data */
static void pim_nht_hash_clean(void *data)
{
Expand Down
3 changes: 3 additions & 0 deletions pimd/pim_nht.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ int pim_nht_lookup_ecmp_if_vif_index(struct pim_instance *pim, pim_addr src, str
/* Tracked nexthop update from zebra */
void pim_nexthop_update(struct vrf *vrf, struct prefix *match, struct zapi_route *nhr);

/* RPF lookup mode changed via configuration */
void pim_nht_mode_changed(struct pim_instance *pim);

/* NHT init and finish funcitons */
void pim_nht_init(struct pim_instance *pim);
void pim_nht_terminate(struct pim_instance *pim);
Expand Down

0 comments on commit 5c606a4

Please sign in to comment.