isisd: introduce new route update hook

This hook will be called whenever a route is added, updated or
deleted.  It will be used, for instance, by the SR code to keep
Prefix-SIDs in sync with their associated routes.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2019-08-07 19:44:11 -03:00
parent 0a5f3f4fb9
commit 6cf3833922
2 changed files with 21 additions and 7 deletions

View File

@ -49,9 +49,15 @@
#include "isis_route.h" #include "isis_route.h"
#include "isis_zebra.h" #include "isis_zebra.h"
DEFINE_HOOK(isis_route_update_hook,
(struct isis_area * area, struct prefix *prefix,
struct isis_route_info *route_info),
(area, prefix, route_info))
static struct isis_nexthop *nexthoplookup(struct list *nexthops, int family, static struct isis_nexthop *nexthoplookup(struct list *nexthops, int family,
union g_addr *ip, ifindex_t ifindex); union g_addr *ip, ifindex_t ifindex);
static void isis_route_update(struct prefix *prefix, struct prefix_ipv6 *src_p, static void isis_route_update(struct isis_area *area, struct prefix *prefix,
struct prefix_ipv6 *src_p,
struct isis_route_info *route_info); struct isis_route_info *route_info);
static struct isis_nexthop *isis_nexthop_create(int family, union g_addr *ip, static struct isis_nexthop *isis_nexthop_create(int family, union g_addr *ip,
@ -318,7 +324,7 @@ struct isis_route_info *isis_route_create(struct prefix *prefix,
return route_info; return route_info;
} }
static void isis_route_delete(struct route_node *rode, static void isis_route_delete(struct isis_area *area, struct route_node *rode,
struct route_table *table) struct route_table *table)
{ {
struct isis_route_info *rinfo; struct isis_route_info *rinfo;
@ -345,14 +351,15 @@ static void isis_route_delete(struct route_node *rode,
UNSET_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE); UNSET_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE);
if (isis->debugs & DEBUG_RTE_EVENTS) if (isis->debugs & DEBUG_RTE_EVENTS)
zlog_debug("ISIS-Rte: route delete %s", buff); zlog_debug("ISIS-Rte: route delete %s", buff);
isis_route_update(prefix, src_p, rinfo); isis_route_update(area, prefix, src_p, rinfo);
} }
isis_route_info_delete(rinfo); isis_route_info_delete(rinfo);
rode->info = NULL; rode->info = NULL;
route_unlock_node(rode); route_unlock_node(rode);
} }
static void isis_route_update(struct prefix *prefix, struct prefix_ipv6 *src_p, static void isis_route_update(struct isis_area *area, struct prefix *prefix,
struct prefix_ipv6 *src_p,
struct isis_route_info *route_info) struct isis_route_info *route_info)
{ {
if (CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) { if (CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) {
@ -360,6 +367,7 @@ static void isis_route_update(struct prefix *prefix, struct prefix_ipv6 *src_p,
return; return;
isis_zebra_route_add_route(prefix, src_p, route_info); isis_zebra_route_add_route(prefix, src_p, route_info);
hook_call(isis_route_update_hook, area, prefix, route_info);
SET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); SET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC); UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC);
@ -368,6 +376,7 @@ static void isis_route_update(struct prefix *prefix, struct prefix_ipv6 *src_p,
return; return;
isis_zebra_route_del_route(prefix, src_p, route_info); isis_zebra_route_del_route(prefix, src_p, route_info);
hook_call(isis_route_update_hook, area, prefix, route_info);
UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
} }
@ -413,7 +422,7 @@ static void _isis_route_verify_table(struct isis_area *area,
buff); buff);
} }
isis_route_update(dst_p, src_p, rinfo); isis_route_update(area, dst_p, src_p, rinfo);
if (CHECK_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE)) if (CHECK_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE))
continue; continue;
@ -422,7 +431,7 @@ static void _isis_route_verify_table(struct isis_area *area,
* directly for * directly for
* validating => no problems with deleting routes. */ * validating => no problems with deleting routes. */
if (!tables) { if (!tables) {
isis_route_delete(rnode, table); isis_route_delete(area, rnode, table);
continue; continue;
} }
@ -445,7 +454,7 @@ static void _isis_route_verify_table(struct isis_area *area,
route_unlock_node(drnode); route_unlock_node(drnode);
} }
isis_route_delete(rnode, table); isis_route_delete(area, rnode, table);
} }
} }

View File

@ -44,6 +44,11 @@ struct isis_route_info {
struct list *nexthops; struct list *nexthops;
}; };
DECLARE_HOOK(isis_route_update_hook,
(struct isis_area * area, struct prefix *prefix,
struct isis_route_info *route_info),
(area, prefix, route_info))
struct isis_route_info *isis_route_create(struct prefix *prefix, struct isis_route_info *isis_route_create(struct prefix *prefix,
struct prefix_ipv6 *src_p, struct prefix_ipv6 *src_p,
uint32_t cost, uint32_t cost,