Skip to content

Commit

Permalink
staticd: fix NHT for dst-src routes
Browse files Browse the repository at this point in the history
staticd's NHT code wasn't updating dst-src routes :(

Fixes: FRRouting#14247
Signed-off-by: David Lamparter <[email protected]>
  • Loading branch information
eqvinox committed Jan 28, 2025
1 parent 2af7806 commit 2726a23
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
29 changes: 14 additions & 15 deletions staticd/static_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ static void static_nht_update_path(struct static_path *pn, struct prefix *nhp,
static_zebra_route_add(pn, true);
}

static void static_nht_update_safi(struct prefix *sp, struct prefix *nhp,
uint32_t nh_num, afi_t afi, safi_t safi,
static void static_nht_update_safi(const struct prefix *sp, const struct prefix *ssrc_p,
struct prefix *nhp, uint32_t nh_num, afi_t afi, safi_t safi,
struct static_vrf *svrf, vrf_id_t nh_vrf_id)
{
struct route_table *stable;
Expand All @@ -63,7 +63,7 @@ static void static_nht_update_safi(struct prefix *sp, struct prefix *nhp,
return;

if (sp) {
rn = srcdest_rnode_lookup(stable, sp, NULL);
rn = srcdest_rnode_lookup(stable, sp, (const struct prefix_ipv6 *)ssrc_p);
if (rn && rn->info) {
si = static_route_info_from_rnode(rn);
frr_each(static_path_list, &si->path_list, pn) {
Expand All @@ -75,7 +75,7 @@ static void static_nht_update_safi(struct prefix *sp, struct prefix *nhp,
return;
}

for (rn = route_top(stable); rn; rn = route_next(rn)) {
for (rn = route_top(stable); rn; rn = srcdest_route_next(rn)) {
si = static_route_info_from_rnode(rn);
if (!si)
continue;
Expand All @@ -85,14 +85,13 @@ static void static_nht_update_safi(struct prefix *sp, struct prefix *nhp,
}
}

void static_nht_update(struct prefix *sp, struct prefix *nhp, uint32_t nh_num,
afi_t afi, safi_t safi, vrf_id_t nh_vrf_id)
void static_nht_update(const struct prefix *sp, const struct prefix *ssrc_p, struct prefix *nhp,
uint32_t nh_num, afi_t afi, safi_t safi, vrf_id_t nh_vrf_id)
{
struct static_vrf *svrf;

RB_FOREACH (svrf, svrf_name_head, &svrfs)
static_nht_update_safi(sp, nhp, nh_num, afi, safi, svrf,
nh_vrf_id);
static_nht_update_safi(sp, ssrc_p, nhp, nh_num, afi, safi, svrf, nh_vrf_id);
}

static void static_nht_reset_start_safi(struct prefix *nhp, afi_t afi,
Expand All @@ -109,7 +108,7 @@ static void static_nht_reset_start_safi(struct prefix *nhp, afi_t afi,
if (!stable)
return;

for (rn = route_top(stable); rn; rn = route_next(rn)) {
for (rn = route_top(stable); rn; rn = srcdest_route_next(rn)) {
si = static_route_info_from_rnode(rn);
if (!si)
continue;
Expand Down Expand Up @@ -150,8 +149,8 @@ void static_nht_reset_start(struct prefix *nhp, afi_t afi, safi_t safi,
static_nht_reset_start_safi(nhp, afi, safi, svrf, nh_vrf_id);
}

static void static_nht_mark_state_safi(struct prefix *sp, afi_t afi,
safi_t safi, struct vrf *vrf,
static void static_nht_mark_state_safi(const struct prefix *sp, const struct prefix *ssrc_p,
afi_t afi, safi_t safi, struct vrf *vrf,
enum static_install_states state)
{
struct static_vrf *svrf;
Expand All @@ -169,7 +168,7 @@ static void static_nht_mark_state_safi(struct prefix *sp, afi_t afi,
if (!stable)
return;

rn = srcdest_rnode_lookup(stable, sp, NULL);
rn = srcdest_rnode_lookup(stable, sp, (const struct prefix_ipv6 *)ssrc_p);
if (!rn)
return;
si = rn->info;
Expand All @@ -184,8 +183,8 @@ static void static_nht_mark_state_safi(struct prefix *sp, afi_t afi,
route_unlock_node(rn);
}

void static_nht_mark_state(struct prefix *sp, safi_t safi, vrf_id_t vrf_id,
enum static_install_states state)
void static_nht_mark_state(const struct prefix *sp, const struct prefix *ssrc_p, safi_t safi,
vrf_id_t vrf_id, enum static_install_states state)
{
struct vrf *vrf;

Expand All @@ -198,5 +197,5 @@ void static_nht_mark_state(struct prefix *sp, safi_t safi, vrf_id_t vrf_id,
if (!vrf || !vrf->info)
return;

static_nht_mark_state_safi(sp, afi, safi, vrf, state);
static_nht_mark_state_safi(sp, ssrc_p, afi, safi, vrf, state);
}
14 changes: 6 additions & 8 deletions staticd/static_nht.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ extern "C" {
* us call this function to find the nexthop we are tracking so it
* can be installed or removed.
*
* sp -> The route we are looking at. If NULL then look at all
* routes.
* sp + ssrc_p -> The route we are looking at. If NULL then look at all routes.
* nhp -> The nexthop that is being tracked.
* nh_num -> number of valid nexthops.
* afi -> The afi we are working in.
* vrf_id -> The vrf the nexthop is in.
*/
extern void static_nht_update(struct prefix *sp, struct prefix *nhp,
uint32_t nh_num, afi_t afi, safi_t safi,
extern void static_nht_update(const struct prefix *sp, const struct prefix *ssrc_p,
struct prefix *nhp, uint32_t nh_num, afi_t afi, safi_t safi,
vrf_id_t vrf_id);

/*
Expand All @@ -35,11 +34,10 @@ extern void static_nht_reset_start(struct prefix *nhp, afi_t afi, safi_t safi,
vrf_id_t nh_vrf_id);

/*
* For the given prefix, sp, mark it as in a particular state
* For the given prefix, sp + ssrc_p, mark it as in a particular state
*/
extern void static_nht_mark_state(struct prefix *sp, safi_t safi,
vrf_id_t vrf_id,
enum static_install_states state);
extern void static_nht_mark_state(const struct prefix *sp, const struct prefix *ssrc_p, safi_t safi,
vrf_id_t vrf_id, enum static_install_states state);

/*
* For the given nexthop, returns the string
Expand Down
29 changes: 17 additions & 12 deletions staticd/static_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,37 @@ static int static_ifp_down(struct interface *ifp)

static int route_notify_owner(ZAPI_CALLBACK_ARGS)
{
struct prefix p;
struct prefix p, src_p, *src_pp;
enum zapi_route_notify_owner note;
uint32_t table_id;
safi_t safi;

if (!zapi_route_notify_decode(zclient->ibuf, &p, &table_id, &note, NULL,
&safi))
if (!zapi_route_notify_decode_srcdest(zclient->ibuf, &p, &src_p, &table_id, &note, NULL,
&safi))
return -1;

src_pp = src_p.prefixlen ? &src_p : NULL;

switch (note) {
case ZAPI_ROUTE_FAIL_INSTALL:
static_nht_mark_state(&p, safi, vrf_id, STATIC_NOT_INSTALLED);
static_nht_mark_state(&p, src_pp, safi, vrf_id, STATIC_NOT_INSTALLED);
zlog_warn("%s: Route %pFX failed to install for table: %u",
__func__, &p, table_id);
break;
case ZAPI_ROUTE_BETTER_ADMIN_WON:
static_nht_mark_state(&p, safi, vrf_id, STATIC_NOT_INSTALLED);
static_nht_mark_state(&p, src_pp, safi, vrf_id, STATIC_NOT_INSTALLED);
zlog_warn(
"%s: Route %pFX over-ridden by better route for table: %u",
__func__, &p, table_id);
break;
case ZAPI_ROUTE_INSTALLED:
static_nht_mark_state(&p, safi, vrf_id, STATIC_INSTALLED);
static_nht_mark_state(&p, src_pp, safi, vrf_id, STATIC_INSTALLED);
break;
case ZAPI_ROUTE_REMOVED:
static_nht_mark_state(&p, safi, vrf_id, STATIC_NOT_INSTALLED);
static_nht_mark_state(&p, src_pp, safi, vrf_id, STATIC_NOT_INSTALLED);
break;
case ZAPI_ROUTE_REMOVE_FAIL:
static_nht_mark_state(&p, safi, vrf_id, STATIC_INSTALLED);
static_nht_mark_state(&p, src_pp, safi, vrf_id, STATIC_INSTALLED);
zlog_warn("%s: Route %pFX failure to remove for table: %u",
__func__, &p, table_id);
break;
Expand Down Expand Up @@ -226,8 +228,8 @@ static void static_zebra_nexthop_update(struct vrf *vrf, struct prefix *matched,
nhtd->nh_num = nhr->nexthop_num;

static_nht_reset_start(matched, afi, nhr->safi, nhtd->nh_vrf_id);
static_nht_update(NULL, matched, nhr->nexthop_num, afi,
nhr->safi, nhtd->nh_vrf_id);
static_nht_update(NULL, NULL, matched, nhr->nexthop_num, afi, nhr->safi,
nhtd->nh_vrf_id);
} else
zlog_err("No nhtd?");
}
Expand Down Expand Up @@ -312,10 +314,13 @@ void static_zebra_nht_register(struct static_nexthop *nh, bool reg)
{
struct static_path *pn = nh->pn;
struct route_node *rn = pn->rn;
const struct prefix *p, *src_p;
struct static_route_info *si = static_route_info_from_rnode(rn);
struct static_nht_data *nhtd, lookup = {};
uint32_t cmd;

srcdest_rnode_prefixes(rn, &p, &src_p);

if (!static_zebra_nht_get_prefix(nh, &lookup.nh))
return;
lookup.nh_vrf_id = nh->nh_vrf_id;
Expand Down Expand Up @@ -351,8 +356,8 @@ void static_zebra_nht_register(struct static_nexthop *nh, bool reg)
if (nh->state == STATIC_NOT_INSTALLED ||
nh->state == STATIC_SENT_TO_ZEBRA)
nh->state = STATIC_START;
static_nht_update(&rn->p, &nhtd->nh, nhtd->nh_num, afi,
si->safi, nh->nh_vrf_id);
static_nht_update(p, src_p, &nhtd->nh, nhtd->nh_num, afi, si->safi,
nh->nh_vrf_id);
return;
}

Expand Down

0 comments on commit 2726a23

Please sign in to comment.