diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2021-10-04 13:05:18 +0200 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2022-03-27 14:57:22 +0200 |
commit | 6bcc46657efbab070d36487b690258f8fa2bafbb (patch) | |
tree | 3a26b75f7b4cc64320819b9402a69b5a87478282 /staticd | |
parent | staticd: use inline prefix in NHT data (diff) | |
download | frr-6bcc46657efbab070d36487b690258f8fa2bafbb.tar.xz frr-6bcc46657efbab070d36487b690258f8fa2bafbb.zip |
staticd: track nexthops per-SAFI
This stops intermixing SAFI_UNICAST NHT into SAFI_MULTICAST static
routes.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'staticd')
-rw-r--r-- | staticd/static_nht.c | 29 | ||||
-rw-r--r-- | staticd/static_nht.h | 8 | ||||
-rw-r--r-- | staticd/static_zebra.c | 37 |
3 files changed, 40 insertions, 34 deletions
diff --git a/staticd/static_nht.c b/staticd/static_nht.c index e1d6ba15d..1d87a83c9 100644 --- a/staticd/static_nht.c +++ b/staticd/static_nht.c @@ -101,18 +101,15 @@ 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, vrf_id_t nh_vrf_id) +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) { struct vrf *vrf; - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - static_nht_update_safi(sp, nhp, nh_num, afi, SAFI_UNICAST, - vrf, nh_vrf_id); - static_nht_update_safi(sp, nhp, nh_num, afi, SAFI_MULTICAST, - vrf, nh_vrf_id); - } + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) + static_nht_update_safi(sp, nhp, nh_num, afi, safi, vrf, + nh_vrf_id); } static void static_nht_reset_start_safi(struct prefix *nhp, afi_t afi, @@ -166,16 +163,13 @@ static void static_nht_reset_start_safi(struct prefix *nhp, afi_t afi, } } -void static_nht_reset_start(struct prefix *nhp, afi_t afi, vrf_id_t nh_vrf_id) +void static_nht_reset_start(struct prefix *nhp, afi_t afi, safi_t safi, + vrf_id_t nh_vrf_id) { struct vrf *vrf; - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - static_nht_reset_start_safi(nhp, afi, SAFI_UNICAST, - vrf, nh_vrf_id); - static_nht_reset_start_safi(nhp, afi, SAFI_MULTICAST, - vrf, nh_vrf_id); - } + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) + static_nht_reset_start_safi(nhp, afi, safi, vrf, nh_vrf_id); } static void static_nht_mark_state_safi(struct prefix *sp, afi_t afi, @@ -212,7 +206,7 @@ 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, vrf_id_t vrf_id, +void static_nht_mark_state(struct prefix *sp, safi_t safi, vrf_id_t vrf_id, enum static_install_states state) { struct vrf *vrf; @@ -226,6 +220,5 @@ void static_nht_mark_state(struct prefix *sp, vrf_id_t vrf_id, if (!vrf || !vrf->info) return; - static_nht_mark_state_safi(sp, afi, SAFI_UNICAST, vrf, state); - static_nht_mark_state_safi(sp, afi, SAFI_MULTICAST, vrf, state); + static_nht_mark_state_safi(sp, afi, safi, vrf, state); } diff --git a/staticd/static_nht.h b/staticd/static_nht.h index 08dba2ebb..c29acc32e 100644 --- a/staticd/static_nht.h +++ b/staticd/static_nht.h @@ -37,19 +37,21 @@ extern "C" { * 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, vrf_id_t vrf_id); + uint32_t nh_num, afi_t afi, safi_t safi, + vrf_id_t vrf_id); /* * For the given tracked nexthop, nhp, mark all routes that use * this route as in starting state again. */ -extern void static_nht_reset_start(struct prefix *nhp, afi_t afi, +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 */ -extern void static_nht_mark_state(struct prefix *sp, vrf_id_t vrf_id, +extern void static_nht_mark_state(struct prefix *sp, safi_t safi, + vrf_id_t vrf_id, enum static_install_states state); /* diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c index 882c77018..af153b4bc 100644 --- a/staticd/static_zebra.c +++ b/staticd/static_zebra.c @@ -51,6 +51,7 @@ struct static_nht_data { struct static_nht_hash_item itm; struct prefix nh; + safi_t safi; vrf_id_t nh_vrf_id; @@ -63,6 +64,8 @@ static int static_nht_data_cmp(const struct static_nht_data *nhtd1, { if (nhtd1->nh_vrf_id != nhtd2->nh_vrf_id) return numcmp(nhtd1->nh_vrf_id, nhtd2->nh_vrf_id); + if (nhtd1->safi != nhtd2->safi) + return numcmp(nhtd1->safi, nhtd2->safi); return prefix_cmp(&nhtd1->nh, &nhtd2->nh); } @@ -72,7 +75,7 @@ static unsigned int static_nht_data_hash(const struct static_nht_data *nhtd) unsigned int key = 0; key = prefix_hash_key(&nhtd->nh); - return jhash_1word(nhtd->nh_vrf_id, key); + return jhash_2words(nhtd->nh_vrf_id, nhtd->safi, key); } DECLARE_HASH(static_nht_hash, struct static_nht_data, itm, static_nht_data_cmp, @@ -139,31 +142,32 @@ static int route_notify_owner(ZAPI_CALLBACK_ARGS) struct prefix p; enum zapi_route_notify_owner note; uint32_t table_id; + safi_t safi; - if (!zapi_route_notify_decode(zclient->ibuf, &p, &table_id, ¬e, - NULL, NULL)) + if (!zapi_route_notify_decode(zclient->ibuf, &p, &table_id, ¬e, NULL, + &safi)) return -1; switch (note) { case ZAPI_ROUTE_FAIL_INSTALL: - static_nht_mark_state(&p, vrf_id, STATIC_NOT_INSTALLED); + static_nht_mark_state(&p, 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, vrf_id, STATIC_NOT_INSTALLED); + static_nht_mark_state(&p, 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, vrf_id, STATIC_INSTALLED); + static_nht_mark_state(&p, safi, vrf_id, STATIC_INSTALLED); break; case ZAPI_ROUTE_REMOVED: - static_nht_mark_state(&p, vrf_id, STATIC_NOT_INSTALLED); + static_nht_mark_state(&p, safi, vrf_id, STATIC_NOT_INSTALLED); break; case ZAPI_ROUTE_REMOVE_FAIL: - static_nht_mark_state(&p, vrf_id, STATIC_INSTALLED); + static_nht_mark_state(&p, safi, vrf_id, STATIC_INSTALLED); zlog_warn("%s: Route %pFX failure to remove for table: %u", __func__, &p, table_id); break; @@ -215,15 +219,17 @@ static int static_zebra_nexthop_update(ZAPI_CALLBACK_ARGS) memset(&lookup, 0, sizeof(lookup)); lookup.nh = matched; lookup.nh_vrf_id = vrf_id; + lookup.safi = nhr.safi; nhtd = static_nht_hash_find(static_nht_hash, &lookup); if (nhtd) { nhtd->nh_num = nhr.nexthop_num; - static_nht_reset_start(&matched, afi, nhtd->nh_vrf_id); + static_nht_reset_start(&matched, afi, nhr.safi, + nhtd->nh_vrf_id); static_nht_update(NULL, &matched, nhr.nexthop_num, afi, - nhtd->nh_vrf_id); + nhr.safi, nhtd->nh_vrf_id); } else zlog_err("No nhtd?"); @@ -247,6 +253,7 @@ static_nht_hash_getref(const struct static_nht_data *ref) prefix_copy(&nhtd->nh, &ref->nh); nhtd->nh_vrf_id = ref->nh_vrf_id; + nhtd->safi = ref->safi; static_nht_hash_add(static_nht_hash, nhtd); } @@ -277,6 +284,7 @@ void static_zebra_nht_register(struct static_nexthop *nh, bool reg) { struct static_path *pn = nh->pn; struct route_node *rn = pn->rn; + struct static_route_info *si = static_route_info_from_rnode(rn); struct static_nht_data lookup; uint32_t cmd; struct prefix p; @@ -315,6 +323,7 @@ void static_zebra_nht_register(struct static_nexthop *nh, bool reg) memset(&lookup, 0, sizeof(lookup)); lookup.nh = p; lookup.nh_vrf_id = nh->nh_vrf_id; + lookup.safi = si->safi; nh->nh_registered = reg; @@ -329,7 +338,7 @@ void static_zebra_nht_register(struct static_nexthop *nh, bool reg) &p, rn, nhtd->nh_num); if (nhtd->nh_num) static_nht_update(&rn->p, &nhtd->nh, - nhtd->nh_num, afi, + nhtd->nh_num, afi, si->safi, nh->nh_vrf_id); return; } @@ -346,7 +355,7 @@ void static_zebra_nht_register(struct static_nexthop *nh, bool reg) DEBUGD(&static_dbg_route, "%s nexthop(%pFX) for %pRN", reg ? "Registering" : "Unregistering", &p, rn); - if (zclient_send_rnh(zclient, cmd, &p, SAFI_UNICAST, false, false, + if (zclient_send_rnh(zclient, cmd, &p, si->safi, false, false, nh->nh_vrf_id) == ZCLIENT_SEND_FAILURE) zlog_warn("%s: Failure to send nexthop to zebra", __func__); } @@ -358,6 +367,7 @@ int static_zebra_nh_update(struct static_nexthop *nh) { struct static_path *pn = nh->pn; struct route_node *rn = pn->rn; + struct static_route_info *si = static_route_info_from_rnode(rn); struct static_nht_data *nhtd, lookup = {}; struct prefix p = {}; afi_t afi = AFI_IP; @@ -387,12 +397,13 @@ int static_zebra_nh_update(struct static_nexthop *nh) lookup.nh = p; lookup.nh_vrf_id = nh->nh_vrf_id; + lookup.safi = si->safi; nhtd = static_nht_hash_find(static_nht_hash, &lookup); if (nhtd && nhtd->nh_num) { nh->state = STATIC_START; static_nht_update(&rn->p, &nhtd->nh, nhtd->nh_num, afi, - nh->nh_vrf_id); + si->safi, nh->nh_vrf_id); return 1; } return 0; |