2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2002-12-13 21:15:29 +01:00
|
|
|
/* route-map for interface.
|
|
|
|
* Copyright (C) 1999 Kunihiro Ishiguro
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
|
|
|
#include "hash.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "if.h"
|
2003-05-24 23:41:49 +02:00
|
|
|
#include "if_rmap.h"
|
2023-04-02 02:33:25 +02:00
|
|
|
#include "ripd/ripd.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
DEFINE_MTYPE_STATIC(LIB, IF_RMAP_CTX, "Interface route map container");
|
2019-02-19 21:08:43 +01:00
|
|
|
DEFINE_MTYPE_STATIC(LIB, IF_RMAP_CTX_NAME,
|
|
|
|
"Interface route map container name");
|
2015-05-29 05:48:31 +02:00
|
|
|
DEFINE_MTYPE_STATIC(LIB, IF_RMAP, "Interface route map");
|
|
|
|
DEFINE_MTYPE_STATIC(LIB, IF_RMAP_NAME, "I.f. route map name");
|
|
|
|
|
2019-04-03 22:34:18 +02:00
|
|
|
static struct list *if_rmap_ctx_list;
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
static struct if_rmap *if_rmap_new(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct if_rmap *new;
|
|
|
|
|
|
|
|
new = XCALLOC(MTYPE_IF_RMAP, sizeof(struct if_rmap));
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void if_rmap_free(struct if_rmap *if_rmap)
|
|
|
|
{
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_IF_RMAP_NAME, if_rmap->ifname);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]);
|
|
|
|
XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
XFREE(MTYPE_IF_RMAP, if_rmap);
|
|
|
|
}
|
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
struct if_rmap *if_rmap_lookup(struct if_rmap_ctx *ctx, const char *ifname)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct if_rmap key;
|
|
|
|
struct if_rmap *if_rmap;
|
|
|
|
|
2004-10-10 Paul Jakma <paul@dishone.st>
* version.h.in: (pid_output*) add const qualifier.
* command.h: Change DEFUN func to take const char *[] rather
than char **, to begin process of fixing compile warnings in lib/.
Nearly all other changes in this commit follow from this change.
* buffer.{c,h}: (buffer_write) pointer-arithmetic is gccism, take
const void * and cast an automatic const char *p to it.
(buffer_putstr) add const
* command.c: (zencrypt) const qualifier
(cmd_execute_command_real) ditto
(cmd_execute_command_strict) ditto
(config_log_file) ditto.
Fix leak of getcwd() returned string.
* memory.{c,h}: Add MTYPE_DISTRIBUTE_IFNAME for struct dist ifname.
* distribute.{c,h}: Update with const qualifier.
(distribute_free) use MTYPE_DISTRIBUTE_IFNAME
(distribute_lookup) Cast to char *, note that it's ok.
(distribute_hash_alloc) use MTYPE_DISTRIBUTE_IFNAME.
(distribute_get) Cast to char *, note that it's ok.
* filter.c: Update with const qualifier.
* if.{c,h}: ditto.
* if_rmap.{c,h}: ditto.
(if_rmap_lookup) Cast to char *, note that it's ok.
(if_rmap_get) ditto.
* log.{c,h}: Update with const qualifier.
* plist.{c,h}: ditto.
* routemap.{c,h}: ditto.
* smux.{c,h}: ditto. Fix some signed/unsigned comparisons.
* sockopt.c: (getsockopt_cmsg_data) add return for error case.
* vty.c: Update with const qualifier.
2004-10-10 13:56:56 +02:00
|
|
|
/* temporary copy */
|
2015-11-22 01:47:32 +01:00
|
|
|
key.ifname = (ifname) ? XSTRDUP(MTYPE_IF_RMAP_NAME, ifname) : NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
if_rmap = hash_lookup(ctx->ifrmaphash, &key);
|
2015-11-22 01:47:32 +01:00
|
|
|
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_IF_RMAP_NAME, key.ifname);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
return if_rmap;
|
|
|
|
}
|
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
void if_rmap_hook_add(struct if_rmap_ctx *ctx,
|
|
|
|
void (*func)(struct if_rmap_ctx *ctx,
|
|
|
|
struct if_rmap *))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-01-14 08:58:36 +01:00
|
|
|
ctx->if_rmap_add_hook = func;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
void if_rmap_hook_delete(struct if_rmap_ctx *ctx,
|
|
|
|
void (*func)(struct if_rmap_ctx *ctx,
|
|
|
|
struct if_rmap *))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-01-14 08:58:36 +01:00
|
|
|
ctx->if_rmap_delete_hook = func;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
static void *if_rmap_hash_alloc(void *arg)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2015-05-20 03:04:26 +02:00
|
|
|
struct if_rmap *ifarg = (struct if_rmap *)arg;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct if_rmap *if_rmap;
|
|
|
|
|
|
|
|
if_rmap = if_rmap_new();
|
2005-10-26 07:05:16 +02:00
|
|
|
if_rmap->ifname = XSTRDUP(MTYPE_IF_RMAP_NAME, ifarg->ifname);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
return if_rmap;
|
|
|
|
}
|
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
static struct if_rmap *if_rmap_get(struct if_rmap_ctx *ctx, const char *ifname)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct if_rmap key;
|
2015-05-20 03:04:26 +02:00
|
|
|
struct if_rmap *ret;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2004-10-10 Paul Jakma <paul@dishone.st>
* version.h.in: (pid_output*) add const qualifier.
* command.h: Change DEFUN func to take const char *[] rather
than char **, to begin process of fixing compile warnings in lib/.
Nearly all other changes in this commit follow from this change.
* buffer.{c,h}: (buffer_write) pointer-arithmetic is gccism, take
const void * and cast an automatic const char *p to it.
(buffer_putstr) add const
* command.c: (zencrypt) const qualifier
(cmd_execute_command_real) ditto
(cmd_execute_command_strict) ditto
(config_log_file) ditto.
Fix leak of getcwd() returned string.
* memory.{c,h}: Add MTYPE_DISTRIBUTE_IFNAME for struct dist ifname.
* distribute.{c,h}: Update with const qualifier.
(distribute_free) use MTYPE_DISTRIBUTE_IFNAME
(distribute_lookup) Cast to char *, note that it's ok.
(distribute_hash_alloc) use MTYPE_DISTRIBUTE_IFNAME.
(distribute_get) Cast to char *, note that it's ok.
* filter.c: Update with const qualifier.
* if.{c,h}: ditto.
* if_rmap.{c,h}: ditto.
(if_rmap_lookup) Cast to char *, note that it's ok.
(if_rmap_get) ditto.
* log.{c,h}: Update with const qualifier.
* plist.{c,h}: ditto.
* routemap.{c,h}: ditto.
* smux.{c,h}: ditto. Fix some signed/unsigned comparisons.
* sockopt.c: (getsockopt_cmsg_data) add return for error case.
* vty.c: Update with const qualifier.
2004-10-10 13:56:56 +02:00
|
|
|
/* temporary copy */
|
2015-11-22 01:47:32 +01:00
|
|
|
key.ifname = (ifname) ? XSTRDUP(MTYPE_IF_RMAP_NAME, ifname) : NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
ret = hash_get(ctx->ifrmaphash, &key, if_rmap_hash_alloc);
|
2015-11-22 01:47:32 +01:00
|
|
|
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_IF_RMAP_NAME, key.ifname);
|
2015-05-20 03:04:26 +02:00
|
|
|
|
|
|
|
return ret;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 22:19:07 +02:00
|
|
|
static unsigned int if_rmap_hash_make(const void *data)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2010-08-27 23:11:14 +02:00
|
|
|
const struct if_rmap *if_rmap = data;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2010-08-27 23:11:14 +02:00
|
|
|
return string_hash_make(if_rmap->ifname);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2018-10-17 21:27:12 +02:00
|
|
|
static bool if_rmap_hash_cmp(const void *arg1, const void *arg2)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2008-08-14 17:25:25 +02:00
|
|
|
const struct if_rmap *if_rmap1 = arg1;
|
|
|
|
const struct if_rmap *if_rmap2 = arg2;
|
|
|
|
|
|
|
|
return strcmp(if_rmap1->ifname, if_rmap2->ifname) == 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
static struct if_rmap *if_rmap_set(struct if_rmap_ctx *ctx,
|
|
|
|
const char *ifname, enum if_rmap_type type,
|
2004-10-10 Paul Jakma <paul@dishone.st>
* version.h.in: (pid_output*) add const qualifier.
* command.h: Change DEFUN func to take const char *[] rather
than char **, to begin process of fixing compile warnings in lib/.
Nearly all other changes in this commit follow from this change.
* buffer.{c,h}: (buffer_write) pointer-arithmetic is gccism, take
const void * and cast an automatic const char *p to it.
(buffer_putstr) add const
* command.c: (zencrypt) const qualifier
(cmd_execute_command_real) ditto
(cmd_execute_command_strict) ditto
(config_log_file) ditto.
Fix leak of getcwd() returned string.
* memory.{c,h}: Add MTYPE_DISTRIBUTE_IFNAME for struct dist ifname.
* distribute.{c,h}: Update with const qualifier.
(distribute_free) use MTYPE_DISTRIBUTE_IFNAME
(distribute_lookup) Cast to char *, note that it's ok.
(distribute_hash_alloc) use MTYPE_DISTRIBUTE_IFNAME.
(distribute_get) Cast to char *, note that it's ok.
* filter.c: Update with const qualifier.
* if.{c,h}: ditto.
* if_rmap.{c,h}: ditto.
(if_rmap_lookup) Cast to char *, note that it's ok.
(if_rmap_get) ditto.
* log.{c,h}: Update with const qualifier.
* plist.{c,h}: ditto.
* routemap.{c,h}: ditto.
* smux.{c,h}: ditto. Fix some signed/unsigned comparisons.
* sockopt.c: (getsockopt_cmsg_data) add return for error case.
* vty.c: Update with const qualifier.
2004-10-10 13:56:56 +02:00
|
|
|
const char *routemap_name)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct if_rmap *if_rmap;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
if_rmap = if_rmap_get(ctx, ifname);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (type == IF_RMAP_IN) {
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]);
|
2005-10-26 07:05:16 +02:00
|
|
|
if_rmap->routemap[IF_RMAP_IN] =
|
|
|
|
XSTRDUP(MTYPE_IF_RMAP_NAME, routemap_name);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
if (type == IF_RMAP_OUT) {
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]);
|
2005-10-26 07:05:16 +02:00
|
|
|
if_rmap->routemap[IF_RMAP_OUT] =
|
|
|
|
XSTRDUP(MTYPE_IF_RMAP_NAME, routemap_name);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
if (ctx->if_rmap_add_hook)
|
|
|
|
(ctx->if_rmap_add_hook)(ctx, if_rmap);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
return if_rmap;
|
|
|
|
}
|
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
static int if_rmap_unset(struct if_rmap_ctx *ctx,
|
|
|
|
const char *ifname, enum if_rmap_type type,
|
2004-10-10 Paul Jakma <paul@dishone.st>
* version.h.in: (pid_output*) add const qualifier.
* command.h: Change DEFUN func to take const char *[] rather
than char **, to begin process of fixing compile warnings in lib/.
Nearly all other changes in this commit follow from this change.
* buffer.{c,h}: (buffer_write) pointer-arithmetic is gccism, take
const void * and cast an automatic const char *p to it.
(buffer_putstr) add const
* command.c: (zencrypt) const qualifier
(cmd_execute_command_real) ditto
(cmd_execute_command_strict) ditto
(config_log_file) ditto.
Fix leak of getcwd() returned string.
* memory.{c,h}: Add MTYPE_DISTRIBUTE_IFNAME for struct dist ifname.
* distribute.{c,h}: Update with const qualifier.
(distribute_free) use MTYPE_DISTRIBUTE_IFNAME
(distribute_lookup) Cast to char *, note that it's ok.
(distribute_hash_alloc) use MTYPE_DISTRIBUTE_IFNAME.
(distribute_get) Cast to char *, note that it's ok.
* filter.c: Update with const qualifier.
* if.{c,h}: ditto.
* if_rmap.{c,h}: ditto.
(if_rmap_lookup) Cast to char *, note that it's ok.
(if_rmap_get) ditto.
* log.{c,h}: Update with const qualifier.
* plist.{c,h}: ditto.
* routemap.{c,h}: ditto.
* smux.{c,h}: ditto. Fix some signed/unsigned comparisons.
* sockopt.c: (getsockopt_cmsg_data) add return for error case.
* vty.c: Update with const qualifier.
2004-10-10 13:56:56 +02:00
|
|
|
const char *routemap_name)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct if_rmap *if_rmap;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
if_rmap = if_rmap_lookup(ctx, ifname);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (!if_rmap)
|
|
|
|
return 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (type == IF_RMAP_IN) {
|
|
|
|
if (!if_rmap->routemap[IF_RMAP_IN])
|
|
|
|
return 0;
|
|
|
|
if (strcmp(if_rmap->routemap[IF_RMAP_IN], routemap_name) != 0)
|
|
|
|
return 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2005-10-26 07:05:16 +02:00
|
|
|
XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (type == IF_RMAP_OUT) {
|
|
|
|
if (!if_rmap->routemap[IF_RMAP_OUT])
|
|
|
|
return 0;
|
|
|
|
if (strcmp(if_rmap->routemap[IF_RMAP_OUT], routemap_name) != 0)
|
|
|
|
return 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2005-10-26 07:05:16 +02:00
|
|
|
XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
if (ctx->if_rmap_delete_hook)
|
|
|
|
ctx->if_rmap_delete_hook(ctx, if_rmap);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (if_rmap->routemap[IF_RMAP_IN] == NULL
|
|
|
|
&& if_rmap->routemap[IF_RMAP_OUT] == NULL) {
|
2019-01-14 08:58:36 +01:00
|
|
|
hash_release(ctx->ifrmaphash, if_rmap);
|
2002-12-13 21:15:29 +01:00
|
|
|
if_rmap_free(if_rmap);
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-05-24 23:41:49 +02:00
|
|
|
DEFUN (if_rmap,
|
|
|
|
if_rmap_cmd,
|
2016-09-23 15:47:20 +02:00
|
|
|
"route-map RMAP_NAME <in|out> IFNAME",
|
2002-12-13 21:15:29 +01:00
|
|
|
"Route map set\n"
|
|
|
|
"Route map name\n"
|
|
|
|
"Route map set for input filtering\n"
|
|
|
|
"Route map set for output filtering\n"
|
|
|
|
"Route map interface name\n")
|
|
|
|
{
|
2016-09-23 22:17:29 +02:00
|
|
|
int idx_rmap_name = 1;
|
|
|
|
int idx_in_out = 2;
|
|
|
|
int idx_ifname = 3;
|
2002-12-13 21:15:29 +01:00
|
|
|
enum if_rmap_type type;
|
2023-04-02 02:33:25 +02:00
|
|
|
struct if_rmap_ctx *ctx;
|
|
|
|
const struct lyd_node *dnode;
|
|
|
|
struct rip *rip;
|
|
|
|
|
|
|
|
dnode = yang_dnode_get(running_config->dnode, VTY_CURR_XPATH);
|
|
|
|
rip = nb_running_get_entry(dnode, NULL, true);
|
|
|
|
ctx = rip->if_rmap_ctx;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-09-23 23:34:33 +02:00
|
|
|
if (strncmp(argv[idx_in_out]->text, "in", 1) == 0)
|
2002-12-13 21:15:29 +01:00
|
|
|
type = IF_RMAP_IN;
|
2016-09-23 23:34:33 +02:00
|
|
|
else if (strncmp(argv[idx_in_out]->text, "out", 1) == 0)
|
2002-12-13 21:15:29 +01:00
|
|
|
type = IF_RMAP_OUT;
|
|
|
|
else {
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, "route-map direction must be [in|out]\n");
|
2017-07-13 21:56:08 +02:00
|
|
|
return CMD_WARNING_CONFIG_FAILED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
if_rmap_set(ctx, argv[idx_ifname]->arg,
|
|
|
|
type, argv[idx_rmap_name]->arg);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
return CMD_SUCCESS;
|
2016-09-23 22:17:29 +02:00
|
|
|
}
|
2003-05-25 17:13:49 +02:00
|
|
|
|
2003-05-24 23:41:49 +02:00
|
|
|
DEFUN (no_if_rmap,
|
|
|
|
no_if_rmap_cmd,
|
2016-09-23 15:47:20 +02:00
|
|
|
"no route-map ROUTEMAP_NAME <in|out> IFNAME",
|
2002-12-13 21:15:29 +01:00
|
|
|
NO_STR
|
|
|
|
"Route map unset\n"
|
|
|
|
"Route map name\n"
|
|
|
|
"Route map for input filtering\n"
|
|
|
|
"Route map for output filtering\n"
|
|
|
|
"Route map interface name\n")
|
|
|
|
{
|
2016-09-23 22:17:29 +02:00
|
|
|
int idx_routemap_name = 2;
|
|
|
|
int idx_in_out = 3;
|
|
|
|
int idx_ifname = 4;
|
2002-12-13 21:15:29 +01:00
|
|
|
int ret;
|
|
|
|
enum if_rmap_type type;
|
2019-01-14 08:58:36 +01:00
|
|
|
struct if_rmap_ctx *ctx =
|
|
|
|
(struct if_rmap_ctx *)listnode_head(if_rmap_ctx_list);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-09-23 22:17:29 +02:00
|
|
|
if (strncmp(argv[idx_in_out]->arg, "i", 1) == 0)
|
2002-12-13 21:15:29 +01:00
|
|
|
type = IF_RMAP_IN;
|
2016-09-23 22:17:29 +02:00
|
|
|
else if (strncmp(argv[idx_in_out]->arg, "o", 1) == 0)
|
2002-12-13 21:15:29 +01:00
|
|
|
type = IF_RMAP_OUT;
|
|
|
|
else {
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, "route-map direction must be [in|out]\n");
|
2017-07-13 21:56:08 +02:00
|
|
|
return CMD_WARNING_CONFIG_FAILED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
ret = if_rmap_unset(ctx, argv[idx_ifname]->arg, type,
|
2016-09-23 22:17:29 +02:00
|
|
|
argv[idx_routemap_name]->arg);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (!ret) {
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, "route-map doesn't exist\n");
|
2017-07-13 21:56:08 +02:00
|
|
|
return CMD_WARNING_CONFIG_FAILED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
return CMD_SUCCESS;
|
2016-09-23 22:17:29 +02:00
|
|
|
}
|
2003-05-25 17:13:49 +02:00
|
|
|
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Configuration write function. */
|
2019-01-14 08:58:36 +01:00
|
|
|
int config_write_if_rmap(struct vty *vty,
|
|
|
|
struct if_rmap_ctx *ctx)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2004-10-05 23:01:23 +02:00
|
|
|
unsigned int i;
|
2019-02-19 16:46:52 +01:00
|
|
|
struct hash_bucket *mp;
|
2002-12-13 21:15:29 +01:00
|
|
|
int write = 0;
|
2019-01-14 08:58:36 +01:00
|
|
|
struct hash *ifrmaphash = ctx->ifrmaphash;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
for (i = 0; i < ifrmaphash->size; i++)
|
|
|
|
for (mp = ifrmaphash->index[i]; mp; mp = mp->next) {
|
|
|
|
struct if_rmap *if_rmap;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if_rmap = mp->data;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (if_rmap->routemap[IF_RMAP_IN]) {
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, " route-map %s in %s\n",
|
2002-12-13 21:15:29 +01:00
|
|
|
if_rmap->routemap[IF_RMAP_IN],
|
2017-06-21 05:10:57 +02:00
|
|
|
if_rmap->ifname);
|
2002-12-13 21:15:29 +01:00
|
|
|
write++;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (if_rmap->routemap[IF_RMAP_OUT]) {
|
2017-07-13 17:49:13 +02:00
|
|
|
vty_out(vty, " route-map %s out %s\n",
|
2002-12-13 21:15:29 +01:00
|
|
|
if_rmap->routemap[IF_RMAP_OUT],
|
2017-06-21 05:10:57 +02:00
|
|
|
if_rmap->ifname);
|
2002-12-13 21:15:29 +01:00
|
|
|
write++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return write;
|
|
|
|
}
|
|
|
|
|
2019-01-14 08:58:36 +01:00
|
|
|
void if_rmap_ctx_delete(struct if_rmap_ctx *ctx)
|
|
|
|
{
|
2019-04-19 21:54:29 +02:00
|
|
|
listnode_delete(if_rmap_ctx_list, ctx);
|
2023-03-21 13:54:21 +01:00
|
|
|
hash_clean_and_free(&ctx->ifrmaphash, (void (*)(void *))if_rmap_free);
|
2019-02-19 21:08:43 +01:00
|
|
|
if (ctx->name)
|
|
|
|
XFREE(MTYPE_IF_RMAP_CTX_NAME, ctx);
|
2019-01-14 08:58:36 +01:00
|
|
|
XFREE(MTYPE_IF_RMAP_CTX, ctx);
|
|
|
|
}
|
|
|
|
|
2019-02-19 21:08:43 +01:00
|
|
|
/* name is optional: either vrf name, or other */
|
|
|
|
struct if_rmap_ctx *if_rmap_ctx_create(const char *name)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-01-14 08:58:36 +01:00
|
|
|
struct if_rmap_ctx *ctx;
|
|
|
|
|
|
|
|
ctx = XCALLOC(MTYPE_IF_RMAP_CTX, sizeof(struct if_rmap_ctx));
|
2019-02-19 21:08:43 +01:00
|
|
|
|
2023-04-02 02:33:25 +02:00
|
|
|
ctx->name = XSTRDUP(MTYPE_IF_RMAP_CTX_NAME, name);
|
2019-01-14 08:58:36 +01:00
|
|
|
ctx->ifrmaphash = hash_create_size(4, if_rmap_hash_make, if_rmap_hash_cmp,
|
|
|
|
"Interface Route-Map Hash");
|
|
|
|
if (!if_rmap_ctx_list)
|
|
|
|
if_rmap_ctx_list = list_new();
|
|
|
|
listnode_add(if_rmap_ctx_list, ctx);
|
|
|
|
return ctx;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2003-05-24 23:41:49 +02:00
|
|
|
void if_rmap_init(int node)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2003-05-24 23:41:49 +02:00
|
|
|
if (node == RIPNG_NODE) {
|
2003-05-25 17:13:49 +02:00
|
|
|
} else if (node == RIP_NODE) {
|
|
|
|
install_element(RIP_NODE, &if_rmap_cmd);
|
|
|
|
install_element(RIP_NODE, &no_if_rmap_cmd);
|
2003-05-24 23:41:49 +02:00
|
|
|
}
|
2019-01-14 08:58:36 +01:00
|
|
|
if_rmap_ctx_list = list_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
void if_rmap_terminate(void)
|
|
|
|
{
|
|
|
|
if (!if_rmap_ctx_list)
|
|
|
|
return;
|
|
|
|
list_delete(&if_rmap_ctx_list);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|