]> git.proxmox.com Git - mirror_frr.git/blobdiff - isisd/isis_cli.c
Merge pull request #4539 from opensourcerouting/7.1/watchfrr-sd-timeout
[mirror_frr.git] / isisd / isis_cli.c
index c68f49f92dd89221d14f898b76f372357a1e1f2e..0334b98a122fb71c54a0704b8d97cf068a266457 100644 (file)
@@ -89,7 +89,7 @@ DEFPY(no_router_isis, no_router_isis_cmd, "no router isis WORD$tag",
                return CMD_ERR_NOTHING_TODO;
        }
 
-       nb_cli_enqueue_change(vty, ".", NB_OP_DELETE, NULL);
+       nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
        area = isis_area_lookup(tag);
        if (area && area->circuit_list && listcount(area->circuit_list)) {
                for (ALL_LIST_ELEMENTS(area->circuit_list, node, nnode,
@@ -103,7 +103,7 @@ DEFPY(no_router_isis, no_router_isis_cmd, "no router isis WORD$tag",
                                temp_xpath, XPATH_MAXLEN,
                                "/frr-interface:lib/interface[name='%s'][vrf='%s']/frr-isisd:isis",
                                circuit->interface->name, vrf_name);
-                       nb_cli_enqueue_change(vty, temp_xpath, NB_OP_DELETE,
+                       nb_cli_enqueue_change(vty, temp_xpath, NB_OP_DESTROY,
                                              NULL);
                }
        }
@@ -136,8 +136,6 @@ DEFPY(ip_router_isis, ip_router_isis_cmd, "ip router isis WORD$tag",
        const char *circ_type;
        struct isis_area *area;
        struct interface *ifp;
-       const struct lyd_node *dnode =
-               yang_dnode_get(running_config->dnode, VTY_CURR_XPATH);
 
        /* area will be created if it is not present. make sure the yang model
         * is synced with FRR and call the appropriate NB cb.
@@ -190,10 +188,14 @@ DEFPY(ip_router_isis, ip_router_isis_cmd, "ip router isis WORD$tag",
        }
 
        /* check if the interface is a loopback and if so set it as passive */
-       ifp = yang_dnode_get_entry(dnode, false);
-       if (ifp && if_is_loopback(ifp))
-               nb_cli_enqueue_change(vty, "./frr-isisd:isis/passive",
-                                     NB_OP_MODIFY, "true");
+       pthread_rwlock_rdlock(&running_config->lock);
+       {
+               ifp = nb_running_get_entry(NULL, VTY_CURR_XPATH, false);
+               if (ifp && if_is_loopback(ifp))
+                       nb_cli_enqueue_change(vty, "./frr-isisd:isis/passive",
+                                             NB_OP_MODIFY, "true");
+       }
+       pthread_rwlock_unlock(&running_config->lock);
 
        return nb_cli_apply_changes(vty, NULL);
 }
@@ -208,8 +210,6 @@ DEFPY(ip6_router_isis, ip6_router_isis_cmd, "ipv6 router isis WORD$tag",
        const char *circ_type;
        struct isis_area *area;
        struct interface *ifp;
-       const struct lyd_node *dnode =
-               yang_dnode_get(running_config->dnode, VTY_CURR_XPATH);
 
        /* area will be created if it is not present. make sure the yang model
         * is synced with FRR and call the appropriate NB cb.
@@ -262,10 +262,14 @@ DEFPY(ip6_router_isis, ip6_router_isis_cmd, "ipv6 router isis WORD$tag",
        }
 
        /* check if the interface is a loopback and if so set it as passive */
-       ifp = yang_dnode_get_entry(dnode, false);
-       if (ifp && if_is_loopback(ifp))
-               nb_cli_enqueue_change(vty, "./frr-isisd:isis/passive",
-                                     NB_OP_MODIFY, "true");
+       pthread_rwlock_rdlock(&running_config->lock);
+       {
+               ifp = nb_running_get_entry(NULL, VTY_CURR_XPATH, false);
+               if (ifp && if_is_loopback(ifp))
+                       nb_cli_enqueue_change(vty, "./frr-isisd:isis/passive",
+                                             NB_OP_MODIFY, "true");
+       }
+       pthread_rwlock_unlock(&running_config->lock);
 
        return nb_cli_apply_changes(vty, NULL);
 }
@@ -279,27 +283,28 @@ DEFPY(no_ip_router_isis, no_ip_router_isis_cmd,
       "IS-IS routing protocol\n"
       "Routing process tag\n")
 {
-       const struct lyd_node *dnode =
-               yang_dnode_get(running_config->dnode, VTY_CURR_XPATH);
+       const struct lyd_node *dnode;
+
+       dnode = yang_dnode_get(vty->candidate_config->dnode,
+                              "%s/frr-isisd:isis", VTY_CURR_XPATH);
+       if (!dnode)
+               return CMD_SUCCESS;
 
-       /* if both ipv4 and ipv6 are off delete the interface isis container too
+       /*
+        * If both ipv4 and ipv6 are off delete the interface isis container.
         */
-       if (!strncmp(ip, "ipv6", strlen("ipv6"))) {
-               if (dnode
-                   && !yang_dnode_get_bool(dnode,
-                                           "./frr-isisd:isis/ipv4-routing"))
+       if (strmatch(ip, "ipv6")) {
+               if (!yang_dnode_get_bool(dnode, "./ipv4-routing"))
                        nb_cli_enqueue_change(vty, "./frr-isisd:isis",
-                                             NB_OP_DELETE, NULL);
+                                             NB_OP_DESTROY, NULL);
                else
                        nb_cli_enqueue_change(vty,
                                              "./frr-isisd:isis/ipv6-routing",
                                              NB_OP_MODIFY, "false");
-       } else { /* no ipv4  */
-               if (dnode
-                   && !yang_dnode_get_bool(dnode,
-                                           "./frr-isisd:isis/ipv6-routing"))
+       } else {
+               if (!yang_dnode_get_bool(dnode, "./ipv6-routing"))
                        nb_cli_enqueue_change(vty, "./frr-isisd:isis",
-                                             NB_OP_DELETE, NULL);
+                                             NB_OP_DESTROY, NULL);
                else
                        nb_cli_enqueue_change(vty,
                                              "./frr-isisd:isis/ipv4-routing",
@@ -336,7 +341,7 @@ DEFPY(net, net_cmd, "[no] net WORD",
       "XX.XXXX. ... .XXX.XX  Network entity title (NET)\n")
 {
        nb_cli_enqueue_change(vty, "./area-address",
-                             no ? NB_OP_DELETE : NB_OP_CREATE, net);
+                             no ? NB_OP_DESTROY : NB_OP_CREATE, net);
 
        return nb_cli_apply_changes(vty, NULL);
 }
@@ -371,20 +376,26 @@ DEFPY(no_is_type, no_is_type_cmd,
       "Act as both a station router and an area router\n"
       "Act as an area router only\n")
 {
-       const char *value = NULL;
-       const struct lyd_node *dnode =
-               yang_dnode_get(running_config->dnode, VTY_CURR_XPATH);
-       struct isis_area *area = yang_dnode_get_entry(dnode, false);
+       const char *value;
+
+       pthread_rwlock_rdlock(&running_config->lock);
+       {
+               struct isis_area *area;
+
+               area = nb_running_get_entry(NULL, VTY_CURR_XPATH, false);
+
+               /*
+                * Put the is-type back to defaults:
+                * - level-1-2 on first area
+                * - level-1 for the rest
+                */
+               if (area && listgetdata(listhead(isis->area_list)) == area)
+                       value = "level-1-2";
+               else
+                       value = NULL;
+       }
+       pthread_rwlock_unlock(&running_config->lock);
 
-       /*
-        * Put the is-type back to defaults:
-        * - level-1-2 on first area
-        * - level-1 for the rest
-        */
-       if (area && listgetdata(listhead(isis->area_list)) == area)
-               value = "level-1-2";
-       else
-               value = NULL;
        nb_cli_enqueue_change(vty, "./is-type", NB_OP_MODIFY, value);
 
        return nb_cli_apply_changes(vty, NULL);
@@ -589,7 +600,7 @@ DEFPY(no_area_passwd, no_area_passwd_cmd,
       "Configure the authentication password for an area\n"
       "Set the authentication password for a routing domain\n")
 {
-       nb_cli_enqueue_change(vty, ".", NB_OP_DELETE, NULL);
+       nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
 
        return nb_cli_apply_changes(vty, "./%s", cmd);
 }
@@ -892,7 +903,7 @@ DEFPY(no_spf_delay_ietf, no_spf_delay_ietf_cmd,
       "Maximum duration needed to learn all the events related to a single failure\n"
       "Maximum duration needed to learn all the events related to a single failure (in milliseconds)\n")
 {
-       nb_cli_enqueue_change(vty, "./spf/ietf-backoff-delay", NB_OP_DELETE,
+       nb_cli_enqueue_change(vty, "./spf/ietf-backoff-delay", NB_OP_DESTROY,
                              NULL);
 
        return nb_cli_apply_changes(vty, NULL);
@@ -931,12 +942,12 @@ void cli_show_isis_purge_origin(struct vty *vty, struct lyd_node *dnode,
 }
 
 /*
- * XPath: /frr-isisd:isis/mpls-te
+ * XPath: /frr-isisd:isis/instance/mpls-te
  */
 DEFPY(isis_mpls_te_on, isis_mpls_te_on_cmd, "mpls-te on",
       MPLS_TE_STR "Enable the MPLS-TE functionality\n")
 {
-       nb_cli_enqueue_change(vty, "/frr-isisd:isis/mpls-te", NB_OP_CREATE,
+       nb_cli_enqueue_change(vty, "./mpls-te", NB_OP_CREATE,
                              NULL);
 
        return nb_cli_apply_changes(vty, NULL);
@@ -945,9 +956,9 @@ DEFPY(isis_mpls_te_on, isis_mpls_te_on_cmd, "mpls-te on",
 DEFPY(no_isis_mpls_te_on, no_isis_mpls_te_on_cmd, "no mpls-te [on]",
       NO_STR
       "Disable the MPLS-TE functionality\n"
-      "Enable the MPLS-TE functionality\n")
+      "Disable the MPLS-TE functionality\n")
 {
-       nb_cli_enqueue_change(vty, "/frr-isisd:isis/mpls-te", NB_OP_DELETE,
+       nb_cli_enqueue_change(vty, "./mpls-te", NB_OP_DESTROY,
                              NULL);
 
        return nb_cli_apply_changes(vty, NULL);
@@ -960,7 +971,7 @@ void cli_show_isis_mpls_te(struct vty *vty, struct lyd_node *dnode,
 }
 
 /*
- * XPath: /frr-isisd:isis/mpls-te/router-address
+ * XPath: /frr-isisd:isis/instance/mpls-te/router-address
  */
 DEFPY(isis_mpls_te_router_addr, isis_mpls_te_router_addr_cmd,
       "mpls-te router-address A.B.C.D",
@@ -968,12 +979,24 @@ DEFPY(isis_mpls_te_router_addr, isis_mpls_te_router_addr_cmd,
       "Stable IP address of the advertising router\n"
       "MPLS-TE router address in IPv4 address format\n")
 {
-       nb_cli_enqueue_change(vty, "/frr-isisd:isis/mpls-te/router-address",
+       nb_cli_enqueue_change(vty, "./mpls-te/router-address",
                              NB_OP_MODIFY, router_address_str);
 
        return nb_cli_apply_changes(vty, NULL);
 }
 
+DEFPY(no_isis_mpls_te_router_addr, no_isis_mpls_te_router_addr_cmd,
+      "no mpls-te router-address [A.B.C.D]",
+      NO_STR MPLS_TE_STR
+      "Delete IP address of the advertising router\n"
+      "MPLS-TE router address in IPv4 address format\n")
+{
+       nb_cli_enqueue_change(vty, "./mpls-te/router-address",
+                             NB_OP_DESTROY, NULL);
+
+       return nb_cli_apply_changes(vty, NULL);
+}
+
 void cli_show_isis_mpls_te_router_addr(struct vty *vty, struct lyd_node *dnode,
                                       bool show_defaults)
 {
@@ -989,7 +1012,7 @@ DEFPY(isis_mpls_te_inter_as, isis_mpls_te_inter_as_cmd,
       "AREA native mode self originate INTER-AS LSP with L1 and L2 flooding scope\n"
       "AS native mode self originate INTER-AS LSP with L2 only flooding scope\n")
 {
-       vty_out(vty, "MPLS-TE Inter-AS is not yet supported.");
+       vty_out(vty, "MPLS-TE Inter-AS is not yet supported\n");
        return CMD_SUCCESS;
 }
 
@@ -999,7 +1022,7 @@ DEFPY(isis_mpls_te_inter_as, isis_mpls_te_inter_as_cmd,
 DEFPY(isis_default_originate, isis_default_originate_cmd,
       "[no] default-information originate <ipv4|ipv6>$ip"
       " <level-1|level-2>$level [always]$always"
-      " [<metric (0-16777215)$metric|route-map WORD$rmap>]",
+      " [{metric (0-16777215)$metric|route-map WORD$rmap}]",
       NO_STR
       "Control distribution of default information\n"
       "Distribute a default route\n"
@@ -1014,17 +1037,16 @@ DEFPY(isis_default_originate, isis_default_originate_cmd,
       "Pointer to route-map entries\n")
 {
        if (no)
-               nb_cli_enqueue_change(vty, ".", NB_OP_DELETE, NULL);
+               nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
        else {
                nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
                nb_cli_enqueue_change(vty, "./always", NB_OP_MODIFY,
                                      always ? "true" : "false");
                nb_cli_enqueue_change(vty, "./route-map",
-                                     rmap ? NB_OP_MODIFY : NB_OP_DELETE,
+                                     rmap ? NB_OP_MODIFY : NB_OP_DESTROY,
                                      rmap ? rmap : NULL);
-               nb_cli_enqueue_change(vty, "./metric",
-                                     metric ? NB_OP_MODIFY : NB_OP_DELETE,
-                                     metric ? metric_str : NULL);
+               nb_cli_enqueue_change(vty, "./metric", NB_OP_MODIFY,
+                                     metric_str ? metric_str : NULL);
                if (strmatch(ip, "ipv6") && !always) {
                        vty_out(vty,
                                "Zebra doesn't implement default-originate for IPv6 yet\n");
@@ -1042,8 +1064,6 @@ static void vty_print_def_origin(struct vty *vty, struct lyd_node *dnode,
                                 const char *family, const char *level,
                                 bool show_defaults)
 {
-       const char *metric;
-
        vty_out(vty, " default-information originate %s %s", family, level);
        if (yang_dnode_get_bool(dnode, "./always"))
                vty_out(vty, " always");
@@ -1051,11 +1071,10 @@ static void vty_print_def_origin(struct vty *vty, struct lyd_node *dnode,
        if (yang_dnode_exists(dnode, "./route-map"))
                vty_out(vty, " route-map %s",
                        yang_dnode_get_string(dnode, "./route-map"));
-       else if (yang_dnode_exists(dnode, "./metric")) {
-               metric = yang_dnode_get_string(dnode, "./metric");
-               if (show_defaults || !yang_dnode_is_default(dnode, "./metric"))
-                       vty_out(vty, " metric %s", metric);
-       }
+       if (show_defaults || !yang_dnode_is_default(dnode, "./metric"))
+               vty_out(vty, " metric %s",
+                       yang_dnode_get_string(dnode, "./metric"));
+
        vty_out(vty, "\n");
 }
 
@@ -1082,7 +1101,7 @@ DEFPY(isis_redistribute, isis_redistribute_cmd,
       "[no] redistribute <ipv4|ipv6>$ip " PROTO_REDIST_STR
       "$proto"
       " <level-1|level-2>$level"
-      " [<metric (0-16777215)|route-map WORD>]",
+      " [{metric (0-16777215)|route-map WORD}]",
       NO_STR REDIST_STR
       "Redistribute IPv4 routes\n"
       "Redistribute IPv6 routes\n" PROTO_REDIST_HELP
@@ -1094,15 +1113,14 @@ DEFPY(isis_redistribute, isis_redistribute_cmd,
       "Pointer to route-map entries\n")
 {
        if (no)
-               nb_cli_enqueue_change(vty, ".", NB_OP_DELETE, NULL);
+               nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
        else {
                nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
                nb_cli_enqueue_change(vty, "./route-map",
-                                     route_map ? NB_OP_MODIFY : NB_OP_DELETE,
+                                     route_map ? NB_OP_MODIFY : NB_OP_DESTROY,
                                      route_map ? route_map : NULL);
-               nb_cli_enqueue_change(vty, "./metric",
-                                     metric ? NB_OP_MODIFY : NB_OP_DELETE,
-                                     metric ? metric_str : NULL);
+               nb_cli_enqueue_change(vty, "./metric", NB_OP_MODIFY,
+                                     metric_str ? metric_str : NULL);
        }
 
        return nb_cli_apply_changes(
@@ -1111,16 +1129,16 @@ DEFPY(isis_redistribute, isis_redistribute_cmd,
 }
 
 static void vty_print_redistribute(struct vty *vty, struct lyd_node *dnode,
-                                  const char *family)
+                                  bool show_defaults, const char *family)
 {
        const char *level = yang_dnode_get_string(dnode, "./level");
        const char *protocol = yang_dnode_get_string(dnode, "./protocol");
 
        vty_out(vty, " redistribute %s %s %s", family, protocol, level);
-       if (yang_dnode_exists(dnode, "./metric"))
+       if (show_defaults || !yang_dnode_is_default(dnode, "./metric"))
                vty_out(vty, " metric %s",
                        yang_dnode_get_string(dnode, "./metric"));
-       else if (yang_dnode_exists(dnode, "./route-map"))
+       if (yang_dnode_exists(dnode, "./route-map"))
                vty_out(vty, " route-map %s",
                        yang_dnode_get_string(dnode, "./route-map"));
        vty_out(vty, "\n");
@@ -1129,12 +1147,12 @@ static void vty_print_redistribute(struct vty *vty, struct lyd_node *dnode,
 void cli_show_isis_redistribute_ipv4(struct vty *vty, struct lyd_node *dnode,
                                     bool show_defaults)
 {
-       vty_print_redistribute(vty, dnode, "ipv4");
+       vty_print_redistribute(vty, dnode, show_defaults, "ipv4");
 }
 void cli_show_isis_redistribute_ipv6(struct vty *vty, struct lyd_node *dnode,
                                     bool show_defaults)
 {
-       vty_print_redistribute(vty, dnode, "ipv6");
+       vty_print_redistribute(vty, dnode, show_defaults, "ipv6");
 }
 
 /*
@@ -1182,7 +1200,7 @@ DEFPY(isis_topology, isis_topology_cmd,
                         topology);
 
        if (no)
-               nb_cli_enqueue_change(vty, ".", NB_OP_DELETE, NULL);
+               nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
        else {
                nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
                nb_cli_enqueue_change(vty, "./overload", NB_OP_MODIFY,
@@ -1297,7 +1315,7 @@ DEFPY(no_isis_passwd, no_isis_passwd_cmd, "no isis password [<md5|clear> WORD]",
       "Cleartext password\n"
       "Circuit password\n")
 {
-       nb_cli_enqueue_change(vty, "./frr-isisd:isis/password", NB_OP_DELETE,
+       nb_cli_enqueue_change(vty, "./frr-isisd:isis/password", NB_OP_DESTROY,
                              NULL);
 
        return nb_cli_apply_changes(vty, NULL);
@@ -1765,52 +1783,43 @@ DEFPY(no_isis_circuit_type, no_isis_circuit_type_cmd,
       "Level-1-2 adjacencies are formed\n"
       "Level-2 only adjacencies are formed\n")
 {
-       const struct lyd_node *dnode;
-       struct interface *ifp;
-       struct isis_circuit *circuit;
-       int is_type;
-       const char *circ_type;
+       const char *circ_type = NULL;
 
        /*
         * Default value depends on whether the circuit is part of an area,
         * and the is-type of the area if there is one. So we need to do this
         * here.
         */
-       dnode = yang_dnode_get(running_config->dnode, VTY_CURR_XPATH);
-       ifp = yang_dnode_get_entry(dnode, false);
-       if (!ifp)
-               goto def_val;
+       pthread_rwlock_rdlock(&running_config->lock);
+       {
+               struct interface *ifp;
+               struct isis_circuit *circuit;
 
-       circuit = circuit_scan_by_ifp(ifp);
-       if (!circuit)
-               goto def_val;
+               ifp = nb_running_get_entry(NULL, VTY_CURR_XPATH, false);
+               if (!ifp)
+                       goto unlock;
 
-       if (circuit->state == C_STATE_UP)
-               is_type = circuit->area->is_type;
-       else
-               goto def_val;
+               circuit = circuit_scan_by_ifp(ifp);
+               if (!circuit || circuit->state != C_STATE_UP)
+                       goto unlock;
 
-       switch (is_type) {
-       case IS_LEVEL_1:
-               circ_type = "level-1";
-               break;
-       case IS_LEVEL_2:
-               circ_type = "level-2";
-               break;
-       case IS_LEVEL_1_AND_2:
-               circ_type = "level-1-2";
-               break;
-       default:
-               return CMD_ERR_NO_MATCH;
+               switch (circuit->area->is_type) {
+               case IS_LEVEL_1:
+                       circ_type = "level-1";
+                       break;
+               case IS_LEVEL_2:
+                       circ_type = "level-2";
+                       break;
+               case IS_LEVEL_1_AND_2:
+                       circ_type = "level-1-2";
+                       break;
+               }
        }
-       nb_cli_enqueue_change(vty, "./frr-isisd:isis/circuit-type",
-                             NB_OP_MODIFY, circ_type);
+unlock:
+       pthread_rwlock_unlock(&running_config->lock);
 
-       return nb_cli_apply_changes(vty, NULL);
-
-def_val:
        nb_cli_enqueue_change(vty, "./frr-isisd:isis/circuit-type",
-                             NB_OP_MODIFY, NULL);
+                             NB_OP_MODIFY, circ_type);
 
        return nb_cli_apply_changes(vty, NULL);
 }
@@ -1977,6 +1986,7 @@ void isis_cli_init(void)
        install_element(ISIS_NODE, &isis_mpls_te_on_cmd);
        install_element(ISIS_NODE, &no_isis_mpls_te_on_cmd);
        install_element(ISIS_NODE, &isis_mpls_te_router_addr_cmd);
+       install_element(ISIS_NODE, &no_isis_mpls_te_router_addr_cmd);
        install_element(ISIS_NODE, &isis_mpls_te_inter_as_cmd);
 
        install_element(ISIS_NODE, &isis_default_originate_cmd);