eigrp, rip, ripng, lib: unlink if_rmap from vrf

an interface rmap context can be created from a custom name string,
instead of a vrf. This ability permits to handle several instances of
interface route map in the same vrf. The naming convention will be
transparent on what the name is for in the daemon code.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
This commit is contained in:
Philippe Guibert 2019-02-19 21:08:43 +01:00
parent 4b23867cad
commit aec0d75667
5 changed files with 26 additions and 14 deletions

View file

@ -209,7 +209,7 @@ static struct eigrp *eigrp_new(const char *AS)
/*
eigrp->if_rmap_ctx = if_rmap_ctx_create(
vrf_lookup_by_id(VRF_DEFAULT));
VRF_DEFAULT_NAME);
if_rmap_hook_add (eigrp_if_rmap_update);
if_rmap_hook_delete (eigrp_if_rmap_update);
*/

View file

@ -27,6 +27,7 @@
#include "if_rmap.h"
DEFINE_MTYPE_STATIC(LIB, IF_RMAP_CTX, "Interface route map container")
DEFINE_MTYPE_STATIC(LIB, IF_RMAP_CTX_NAME, "Interface route map container name")
DEFINE_MTYPE_STATIC(LIB, IF_RMAP, "Interface route map")
DEFINE_MTYPE_STATIC(LIB, IF_RMAP_NAME, "I.f. route map name")
@ -300,15 +301,20 @@ int config_write_if_rmap(struct vty *vty,
void if_rmap_ctx_delete(struct if_rmap_ctx *ctx)
{
hash_clean(ctx->ifrmaphash, (void (*)(void *))if_rmap_free);
if (ctx->name)
XFREE(MTYPE_IF_RMAP_CTX_NAME, ctx);
XFREE(MTYPE_IF_RMAP_CTX, ctx);
}
struct if_rmap_ctx *if_rmap_ctx_create(struct vrf *vrf)
/* name is optional: either vrf name, or other */
struct if_rmap_ctx *if_rmap_ctx_create(const char *name)
{
struct if_rmap_ctx *ctx;
ctx = XCALLOC(MTYPE_IF_RMAP_CTX, sizeof(struct if_rmap_ctx));
ctx->vrf = vrf;
if (ctx->name)
ctx->name = XSTRDUP(MTYPE_IF_RMAP_CTX_NAME, name);
ctx->ifrmaphash = hash_create_size(4, if_rmap_hash_make, if_rmap_hash_cmp,
"Interface Route-Map Hash");
if (!if_rmap_ctx_list)

View file

@ -44,11 +44,11 @@ struct if_rmap_ctx {
void (*if_rmap_delete_hook)(struct if_rmap_ctx *ctx,
struct if_rmap *ifrmap);
/* vrf information */
struct vrf *vrf;
/* naming information */
char *name;
};
extern struct if_rmap_ctx *if_rmap_ctx_create(struct vrf *vrf);
extern struct if_rmap_ctx *if_rmap_ctx_create(const char *name);
extern void if_rmap_ctx_delete(struct if_rmap_ctx *ctx);
extern void if_rmap_init(int node);
extern void if_rmap_terminate(void);

View file

@ -2717,8 +2717,7 @@ int rip_create(int socket)
rip_distribute_update);
/* if rmap install. */
rip->if_rmap_ctx = if_rmap_ctx_create(
vrf_lookup_by_id(VRF_DEFAULT));
rip->if_rmap_ctx = if_rmap_ctx_create(VRF_DEFAULT_NAME);
if_rmap_hook_add(rip->if_rmap_ctx, rip_if_rmap_update);
if_rmap_hook_delete(rip->if_rmap_ctx, rip_if_rmap_update);
@ -3409,11 +3408,15 @@ void rip_clean(void)
static void rip_if_rmap_update(struct if_rmap_ctx *ctx,
struct if_rmap *if_rmap)
{
struct interface *ifp;
struct interface *ifp = NULL;
struct rip_interface *ri;
struct route_map *rmap;
struct vrf *vrf = NULL;
ifp = if_lookup_by_name(if_rmap->ifname, ctx->vrf->vrf_id);
if (ctx->name)
vrf = vrf_lookup_by_name(ctx->name);
if (vrf)
ifp = if_lookup_by_name(if_rmap->ifname, vrf->vrf_id);
if (ifp == NULL)
return;

View file

@ -1821,8 +1821,7 @@ int ripng_create(int socket)
ripng_distribute_update);
/* if rmap install. */
ripng->if_rmap_ctx = if_rmap_ctx_create(
vrf_lookup_by_id(VRF_DEFAULT));
ripng->if_rmap_ctx = if_rmap_ctx_create(VRF_DEFAULT_NAME);
if_rmap_hook_add(ripng->if_rmap_ctx, ripng_if_rmap_update);
if_rmap_hook_delete(ripng->if_rmap_ctx, ripng_if_rmap_update);
@ -2490,11 +2489,15 @@ void ripng_clean(void)
static void ripng_if_rmap_update(struct if_rmap_ctx *ctx,
struct if_rmap *if_rmap)
{
struct interface *ifp;
struct interface *ifp = NULL;
struct ripng_interface *ri;
struct route_map *rmap;
struct vrf *vrf = NULL;
ifp = if_lookup_by_name(if_rmap->ifname, ctx->vrf->vrf_id);
if (ctx->name)
vrf = vrf_lookup_by_name(ctx->name);
if (vrf)
ifp = if_lookup_by_name(if_rmap->ifname, vrf->vrf_id);
if (ifp == NULL)
return;