User pass the string match large-community 1 exact-match from CLI.
Now route map lib has got the string as "1 exact-match". It passes the string
to call back for compilation. BGP will parse this string and came to know
that for "1" it has to do exact match. Routemap lib has to save "1" in it’s
dependency table. Here routemap is saving this as a “1 exact-match”
which is wrong. The solution is used the compiled data.
Signed-off-by: vishaldhingra <vdhingra@vmware.com>
XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom);
}
+/*
+ * In routemap processing there is a need to add the
+ * name as a rule_key in the dependency table. Routemap
+ * lib is unaware of rule_key when exact-match clause
+ * is in use. routemap lib uses the compiled output to
+ * get the rule_key value.
+ */
+static void *route_match_get_community_key(void *rule)
+{
+ struct rmap_community *rcom;
+
+ rcom = rule;
+ return rcom->name;
+}
+
+
/* Route map commands for community matching. */
struct route_map_rule_cmd route_match_community_cmd = {
"community", route_match_community, route_match_community_compile,
- route_match_community_free};
+ route_match_community_free, route_match_get_community_key};
/* Match function for lcommunity match. */
static enum route_map_cmd_result_t
/* Route map commands for community matching. */
struct route_map_rule_cmd route_match_lcommunity_cmd = {
"large-community", route_match_lcommunity,
- route_match_lcommunity_compile, route_match_lcommunity_free};
+ route_match_lcommunity_compile, route_match_lcommunity_free,
+ route_match_get_community_key};
/* Match function for extcommunity match. */
retval = CMD_WARNING_CONFIG_FAILED;
break;
case RMAP_COMPILE_SUCCESS:
- if (type != RMAP_EVENT_MATCH_ADDED) {
- route_map_upd8_dependency(type, arg, index->map->name);
- }
- break;
- case RMAP_DUPLICATE_RULE:
/*
* Intentionally doing nothing here.
*/
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, "%% BGP Can't find rule.\n");
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);
- break;
- case RMAP_DUPLICATE_RULE:
/*
* Nothing to do here
*/
vty_out(vty, "%% BGP Argument is malformed.\n");
return CMD_WARNING_CONFIG_FAILED;
case RMAP_COMPILE_SUCCESS:
- case RMAP_DUPLICATE_RULE:
/*
* Intentionally doing nothing here
*/
VTY_DECLVAR_CONTEXT(route_map_index, index);
enum rmap_compile_rets ret;
- ret = route_map_delete_match(index, "rpki", argv[3]->arg);
+ ret = route_map_delete_match(index, "rpki", argv[3]->arg,
+ RMAP_EVENT_MATCH_DELETED);
if (ret) {
switch (ret) {
case RMAP_RULE_MISSING:
vty_out(vty, "%% BGP Argument is malformed.\n");
break;
case RMAP_COMPILE_SUCCESS:
- case RMAP_DUPLICATE_RULE:
/*
* Nothing to do here
*/
return CMD_WARNING_CONFIG_FAILED;
break;
case RMAP_COMPILE_SUCCESS:
- case RMAP_DUPLICATE_RULE:
/*
* Intentionally not handling these cases
*/
{
enum rmap_compile_rets ret;
- ret = route_map_delete_match(index, command, arg);
+ ret = route_map_delete_match(index, command, arg, type);
switch (ret) {
case RMAP_RULE_MISSING:
vty_out(vty, "%% Can't find rule.\n");
return CMD_WARNING_CONFIG_FAILED;
break;
case RMAP_COMPILE_SUCCESS:
- case RMAP_DUPLICATE_RULE:
/*
* These cases intentionally ignored
*/
}
break;
case RMAP_COMPILE_SUCCESS:
- case RMAP_DUPLICATE_RULE:
/*
* These cases intentionally left blank here
*/
return CMD_WARNING_CONFIG_FAILED;
break;
case RMAP_COMPILE_SUCCESS:
- case RMAP_DUPLICATE_RULE:
/*
* These cases intentionally not handled
*/
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;
frr_protonameinst);
return CMD_WARNING_CONFIG_FAILED;
break;
- case RMAP_DUPLICATE_RULE:
+ case RMAP_COMPILE_SUCCESS:
/*
* Nothing to do here move along
*/
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);
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);
- break;
- case RMAP_DUPLICATE_RULE:
/*
* Nothing to do here
*/
return CMD_WARNING_CONFIG_FAILED;
break;
case RMAP_COMPILE_SUCCESS:
- case RMAP_DUPLICATE_RULE:
break;
}
return CMD_WARNING_CONFIG_FAILED;
break;
case RMAP_COMPILE_SUCCESS:
- case RMAP_DUPLICATE_RULE:
break;
}
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);
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) {
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
get_route_map_delete_event(type);
route_map_upd8_dependency(
delete_rmap_event_type,
- rule->rule_str,
+ rule_key,
index->map->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. */
enum rmap_compile_rets route_map_delete_match(struct route_map_index *index,
const char *match_name,
- const char *match_arg)
+ 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)
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);
index->map->name,
RMAP_EVENT_CALL_ADDED);
}
+ 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. */
/* Free allocated value by func_compile (). */
void (*func_free)(void *);
+
+ /** To get the rule key after Compilation **/
+ void *(*func_get_rmap_rule_key)(void *val);
};
/* Route map apply error. */
/* Route map rule can't compile */
RMAP_COMPILE_ERROR,
- /* Route map rule is duplicate */
- RMAP_DUPLICATE_RULE
};
/* Route map rule list. */
/* Delete specified route match rule. */
extern enum rmap_compile_rets
route_map_delete_match(struct route_map_index *index,
- const char *match_name, const char *match_arg);
+ const char *match_name, const char *match_arg,
+ route_map_event_t type);
extern const char *route_map_get_match_arg(struct route_map_index *index,
const char *match_name);
return CMD_WARNING_CONFIG_FAILED;
break;
case RMAP_COMPILE_SUCCESS:
- case RMAP_DUPLICATE_RULE:
break;
}
retval = CMD_WARNING_CONFIG_FAILED;
break;
case RMAP_COMPILE_SUCCESS:
- if (type != RMAP_EVENT_MATCH_ADDED) {
- route_map_upd8_dependency(type, arg, index->map->name);
- }
- break;
- case RMAP_DUPLICATE_RULE:
/*
* Nothing to do here
*/
rmap_name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, index->map->name);
}
- ret = route_map_delete_match(index, command, arg);
+ ret = route_map_delete_match(index, command, arg, type);
switch (ret) {
case RMAP_RULE_MISSING:
vty_out(vty, "%% Zebra Can't find rule.\n");
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);
- break;
- case RMAP_DUPLICATE_RULE:
/*
* Nothing to do here
*/