]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: add backward compatibility for route map
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 1 Oct 2019 18:52:51 +0000 (15:52 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 4 Feb 2020 17:05:43 +0000 (14:05 -0300)
Allow old CLI users to still print their configuration without migrating
to northbound.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
lib/routemap_cli.c

index 987693c961995f370fb90a67ae734bd173d95651..7023710564deda1f2a5a40d71595778381a7d78b 100644 (file)
@@ -46,6 +46,9 @@ DEFPY_NOSH(
        ROUTE_MAP_OP_CMD_STR
        ROUTE_MAP_SEQUENCE_CMD_STR)
 {
        ROUTE_MAP_OP_CMD_STR
        ROUTE_MAP_SEQUENCE_CMD_STR)
 {
+       struct route_map_index *rmi;
+       struct route_map *rm;
+       int action_type;
        char xpath_action[XPATH_MAXLEN + 64];
        char xpath_index[XPATH_MAXLEN + 32];
        char xpath[XPATH_MAXLEN];
        char xpath_action[XPATH_MAXLEN + 64];
        char xpath_index[XPATH_MAXLEN + 32];
        char xpath[XPATH_MAXLEN];
@@ -63,9 +66,16 @@ DEFPY_NOSH(
        nb_cli_enqueue_change(vty, xpath_action, NB_OP_MODIFY, action);
 
        rv = nb_cli_apply_changes(vty, NULL);
        nb_cli_enqueue_change(vty, xpath_action, NB_OP_MODIFY, action);
 
        rv = nb_cli_apply_changes(vty, NULL);
-       if (rv == CMD_SUCCESS)
+       if (rv == CMD_SUCCESS) {
                VTY_PUSH_XPATH(RMAP_NODE, xpath_index);
 
                VTY_PUSH_XPATH(RMAP_NODE, xpath_index);
 
+               /* Add support for non-migrated route map users. */
+               rm = route_map_get(name);
+               action_type = (action[0] == 'p') ? RMAP_PERMIT : RMAP_DENY;
+               rmi = route_map_index_get(rm, action_type, sequence);
+               VTY_PUSH_CONTEXT(RMAP_NODE, rmi);
+       }
+
        return rv;
 }
 
        return rv;
 }
 
@@ -105,11 +115,55 @@ DEFPY(
 void route_map_instance_show(struct vty *vty, struct lyd_node *dnode,
                             bool show_defaults)
 {
 void route_map_instance_show(struct vty *vty, struct lyd_node *dnode,
                             bool show_defaults)
 {
+       const struct route_map_rule *rmr;
+       const struct route_map_index *rmi;
        const char *name = yang_dnode_get_string(dnode, "../name");
        const char *action = yang_dnode_get_string(dnode, "./action");
        const char *sequence = yang_dnode_get_string(dnode, "./sequence");
 
        vty_out(vty, "route-map %s %s %s\n", name, action, sequence);
        const char *name = yang_dnode_get_string(dnode, "../name");
        const char *action = yang_dnode_get_string(dnode, "./action");
        const char *sequence = yang_dnode_get_string(dnode, "./sequence");
 
        vty_out(vty, "route-map %s %s %s\n", name, action, sequence);
+
+       rmi = nb_running_get_entry(dnode, NULL, false);
+       if (rmi == NULL) {
+               /*
+                * We can't have outdated rules if route map hasn't
+                * been created yet.
+                */
+               return;
+       }
+
+#define SKIP_RULE(name) if (strcmp((name), rmr->cmd->str) == 0) continue
+
+       /* Print route map `match` for old CLI users. */
+       for (rmr = rmi->match_list.head; rmr; rmr = rmr->next) {
+               /* Skip all matches implemented by northbound. */
+               SKIP_RULE("interface");
+               SKIP_RULE("ip address");
+               SKIP_RULE("ip address prefix-list");
+               SKIP_RULE("ip next-hop");
+               SKIP_RULE("ip next-hop prefix-list");
+               SKIP_RULE("ip next-hop type");
+               SKIP_RULE("ipv6 address");
+               SKIP_RULE("ipv6 address prefix-list");
+               SKIP_RULE("ipv6 next-hop type");
+               SKIP_RULE("metric");
+               SKIP_RULE("tag");
+
+               vty_out(vty, " match %s %s\n", rmr->cmd->str,
+                       rmr->rule_str ? rmr->rule_str : "");
+       }
+
+       /* Print route map `set` for old CLI users. */
+       for (rmr = rmi->set_list.head; rmr; rmr = rmr->next) {
+               /* Skip all sets implemented by northbound. */
+               SKIP_RULE("metric");
+               SKIP_RULE("tag");
+
+               vty_out(vty, " set %s %s\n", rmr->cmd->str,
+                       rmr->rule_str ? rmr->rule_str : "");
+       }
+
+#undef SKIP_RULE
 }
 
 void route_map_instance_show_end(struct vty *vty, struct lyd_node *dnode)
 }
 
 void route_map_instance_show_end(struct vty *vty, struct lyd_node *dnode)