summaryrefslogtreecommitdiff
path: root/lib/routemap.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/routemap.c')
-rw-r--r--lib/routemap.c85
1 files changed, 56 insertions, 29 deletions
diff --git a/lib/routemap.c b/lib/routemap.c
index eca02e8366..580d898448 100644
--- a/lib/routemap.c
+++ b/lib/routemap.c
@@ -474,15 +474,10 @@ int generic_match_add(struct vty *vty, struct route_map_index *index,
const char *command, const char *arg,
route_map_event_t type)
{
- int ret;
+ enum rmap_compile_rets ret;
ret = route_map_add_match(index, command, arg, type);
switch (ret) {
- case RMAP_COMPILE_SUCCESS:
- if (type != RMAP_EVENT_MATCH_ADDED) {
- route_map_upd8_dependency(type, arg, index->map->name);
- }
- break;
case RMAP_RULE_MISSING:
vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst);
return CMD_WARNING_CONFIG_FAILED;
@@ -493,6 +488,11 @@ int generic_match_add(struct vty *vty, struct route_map_index *index,
frr_protonameinst);
return CMD_WARNING_CONFIG_FAILED;
break;
+ case RMAP_COMPILE_SUCCESS:
+ /*
+ * Nothing to do here move along
+ */
+ break;
}
return CMD_SUCCESS;
@@ -502,7 +502,7 @@ int generic_match_delete(struct vty *vty, struct route_map_index *index,
const char *command, const char *arg,
route_map_event_t type)
{
- int ret;
+ enum rmap_compile_rets ret;
int retval = CMD_SUCCESS;
char *dep_name = NULL;
const char *tmpstr;
@@ -521,7 +521,7 @@ int generic_match_delete(struct vty *vty, struct route_map_index *index,
rmap_name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, index->map->name);
}
- ret = route_map_delete_match(index, command, dep_name);
+ ret = route_map_delete_match(index, command, dep_name, type);
switch (ret) {
case RMAP_RULE_MISSING:
vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst);
@@ -534,8 +534,9 @@ int generic_match_delete(struct vty *vty, struct route_map_index *index,
retval = CMD_WARNING_CONFIG_FAILED;
break;
case RMAP_COMPILE_SUCCESS:
- if (type != RMAP_EVENT_MATCH_DELETED && dep_name)
- route_map_upd8_dependency(type, dep_name, rmap_name);
+ /*
+ * Nothing to do here
+ */
break;
}
@@ -548,7 +549,7 @@ int generic_match_delete(struct vty *vty, struct route_map_index *index,
int generic_set_add(struct vty *vty, struct route_map_index *index,
const char *command, const char *arg)
{
- int ret;
+ enum rmap_compile_rets ret;
ret = route_map_add_set(index, command, arg);
switch (ret) {
@@ -572,7 +573,7 @@ int generic_set_add(struct vty *vty, struct route_map_index *index,
int generic_set_delete(struct vty *vty, struct route_map_index *index,
const char *command, const char *arg)
{
- int ret;
+ enum rmap_compile_rets ret;
ret = route_map_delete_set(index, command, arg);
switch (ret) {
@@ -1388,14 +1389,17 @@ static route_map_event_t get_route_map_delete_event(route_map_event_t type)
}
/* Add match statement to route map. */
-int route_map_add_match(struct route_map_index *index, const char *match_name,
- const char *match_arg, route_map_event_t type)
+enum rmap_compile_rets route_map_add_match(struct route_map_index *index,
+ const char *match_name,
+ const char *match_arg,
+ route_map_event_t type)
{
struct route_map_rule *rule;
struct route_map_rule *next;
struct route_map_rule_cmd *cmd;
void *compile;
int8_t delete_rmap_event_type = 0;
+ const char *rule_key;
/* First lookup rule for add match statement. */
cmd = route_map_lookup_match(match_name);
@@ -1409,6 +1413,12 @@ int route_map_add_match(struct route_map_index *index, const char *match_name,
return RMAP_COMPILE_ERROR;
} else
compile = NULL;
+ /* use the compiled results if applicable */
+ if (compile && cmd->func_get_rmap_rule_key)
+ rule_key = (*cmd->func_get_rmap_rule_key)
+ (compile);
+ else
+ rule_key = match_arg;
/* If argument is completely same ignore it. */
for (rule = index->match_list.head; rule; rule = next) {
@@ -1422,7 +1432,7 @@ int route_map_add_match(struct route_map_index *index, const char *match_name,
if (cmd->func_free)
(*cmd->func_free)(compile);
- return RMAP_DUPLICATE_RULE;
+ return RMAP_COMPILE_SUCCESS;
}
/* Remove the dependency of the route-map on the rule
@@ -1433,7 +1443,7 @@ int route_map_add_match(struct route_map_index *index, const char *match_name,
get_route_map_delete_event(type);
route_map_upd8_dependency(
delete_rmap_event_type,
- rule->rule_str,
+ rule_key,
index->map->name);
}
@@ -1459,25 +1469,29 @@ int route_map_add_match(struct route_map_index *index, const char *match_name,
route_map_notify_dependencies(index->map->name,
RMAP_EVENT_CALL_ADDED);
}
+ if (type != RMAP_EVENT_MATCH_ADDED)
+ route_map_upd8_dependency(type, rule_key, index->map->name);
return RMAP_COMPILE_SUCCESS;
}
/* Delete specified route match rule. */
-int route_map_delete_match(struct route_map_index *index,
- const char *match_name, const char *match_arg)
+enum rmap_compile_rets route_map_delete_match(struct route_map_index *index,
+ const char *match_name,
+ const char *match_arg,
+ route_map_event_t type)
{
struct route_map_rule *rule;
struct route_map_rule_cmd *cmd;
+ const char *rule_key;
cmd = route_map_lookup_match(match_name);
if (cmd == NULL)
- return 1;
+ return RMAP_RULE_MISSING;
for (rule = index->match_list.head; rule; rule = rule->next)
if (rule->cmd == cmd && (rulecmp(rule->rule_str, match_arg) == 0
|| match_arg == NULL)) {
- route_map_rule_delete(&index->match_list, rule);
/* Execute event hook. */
if (route_map_master.event_hook) {
(*route_map_master.event_hook)(index->map->name);
@@ -1485,15 +1499,27 @@ int route_map_delete_match(struct route_map_index *index,
index->map->name,
RMAP_EVENT_CALL_ADDED);
}
- return 0;
+ if (cmd->func_get_rmap_rule_key)
+ rule_key = (*cmd->func_get_rmap_rule_key)
+ (rule->value);
+ else
+ rule_key = match_arg;
+
+ if (type != RMAP_EVENT_MATCH_DELETED && rule_key)
+ route_map_upd8_dependency(type, rule_key,
+ index->map->name);
+
+ route_map_rule_delete(&index->match_list, rule);
+ return RMAP_COMPILE_SUCCESS;
}
/* Can't find matched rule. */
- return 1;
+ return RMAP_RULE_MISSING;
}
/* Add route-map set statement to the route map. */
-int route_map_add_set(struct route_map_index *index, const char *set_name,
- const char *set_arg)
+enum rmap_compile_rets route_map_add_set(struct route_map_index *index,
+ const char *set_name,
+ const char *set_arg)
{
struct route_map_rule *rule;
struct route_map_rule *next;
@@ -1543,15 +1569,16 @@ int route_map_add_set(struct route_map_index *index, const char *set_name,
}
/* Delete route map set rule. */
-int route_map_delete_set(struct route_map_index *index, const char *set_name,
- const char *set_arg)
+enum rmap_compile_rets route_map_delete_set(struct route_map_index *index,
+ const char *set_name,
+ const char *set_arg)
{
struct route_map_rule *rule;
struct route_map_rule_cmd *cmd;
cmd = route_map_lookup_set(set_name);
if (cmd == NULL)
- return 1;
+ return RMAP_RULE_MISSING;
for (rule = index->set_list.head; rule; rule = rule->next)
if ((rule->cmd == cmd) && (rulecmp(rule->rule_str, set_arg) == 0
@@ -1564,10 +1591,10 @@ int route_map_delete_set(struct route_map_index *index, const char *set_name,
index->map->name,
RMAP_EVENT_CALL_ADDED);
}
- return 0;
+ return RMAP_COMPILE_SUCCESS;
}
/* Can't find matched rule. */
- return 1;
+ return RMAP_RULE_MISSING;
}
static enum route_map_cmd_result_t