Skip to content

Commit

Permalink
eigrp, rip, ripng, lib: unlink if_rmap from vrf
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
pguibert6WIND committed Feb 19, 2019
1 parent 4b23867 commit aec0d75
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion eigrpd/eigrpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
*/
Expand Down
10 changes: 8 additions & 2 deletions lib/if_rmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lib/if_rmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions ripd/ripd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
11 changes: 7 additions & 4 deletions ripngd/ripngd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit aec0d75

Please sign in to comment.