]> git.proxmox.com Git - mirror_frr.git/blobdiff - pathd/path_cli.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / pathd / path_cli.c
index e5bbd9430ba07418946225d0bdf94a36c4e058b7..45f4ac7ab8da50d856ad1276fb71f1b9b2e64a44 100644 (file)
@@ -1,19 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2020  NetDEF, Inc.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -126,7 +113,7 @@ DEFPY(show_srte_policy,
        ttable_rowseps(tt, 0, BOTTOM, true, '-');
 
        RB_FOREACH (policy, srte_policy_head, &srte_policies) {
-               char endpoint[46];
+               char endpoint[ENDPOINT_STR_LENGTH];
                char binding_sid[16] = "-";
 
                ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint));
@@ -173,7 +160,7 @@ DEFPY(show_srte_policy_detail,
        vty_out(vty, "\n");
        RB_FOREACH (policy, srte_policy_head, &srte_policies) {
                struct srte_candidate *candidate;
-               char endpoint[46];
+               char endpoint[ENDPOINT_STR_LENGTH];
                char binding_sid[16] = "-";
                char *segment_list_info;
                static char undefined_info[] = "(undefined)";
@@ -1079,9 +1066,11 @@ static const char *objfun_type_name(enum objfun_type type)
                return "mss";
        case OBJFUN_MSN:
                return "msn";
-       default:
+       case OBJFUN_UNDEFINED:
                return NULL;
        }
+
+       assert(!"Reached end of function we should never hit");
 }
 
 DEFPY_NOSH(show_debugging_pathd, show_debugging_pathd_cmd,
@@ -1096,6 +1085,20 @@ DEFPY_NOSH(show_debugging_pathd, show_debugging_pathd_cmd,
        cmd_show_lib_debugs(vty);
        /* nothing to do here */
        path_ted_show_debugging(vty);
+       path_policy_show_debugging(vty);
+       return CMD_SUCCESS;
+}
+
+DEFPY(debug_path_policy, debug_path_policy_cmd, "[no] debug pathd policy",
+      NO_STR DEBUG_STR
+      "path debugging\n"
+      "policy debugging\n")
+{
+       uint32_t mode = DEBUG_NODE2MODE(vty->node);
+       bool no_debug = no;
+
+       DEBUG_MODE_SET(&path_policy_debug, mode, !no);
+       DEBUG_FLAGS_SET(&path_policy_debug, PATH_POLICY_DEBUG_BASIC, !no_debug);
        return CMD_SUCCESS;
 }
 
@@ -1294,8 +1297,34 @@ int config_write_segment_routing(struct vty *vty)
        return 1;
 }
 
+static int path_policy_cli_debug_config_write(struct vty *vty)
+{
+       if (DEBUG_MODE_CHECK(&path_policy_debug, DEBUG_MODE_CONF)) {
+               if (DEBUG_FLAGS_CHECK(&path_policy_debug,
+                                     PATH_POLICY_DEBUG_BASIC))
+                       vty_out(vty, "debug pathd policy\n");
+               return 1;
+       }
+       return 0;
+}
+
+static int path_policy_cli_debug_set_all(uint32_t flags, bool set)
+{
+       DEBUG_FLAGS_SET(&path_policy_debug, flags, set);
+
+       /* If all modes have been turned off, don't preserve options. */
+       if (!DEBUG_MODE_CHECK(&path_policy_debug, DEBUG_MODE_ALL))
+               DEBUG_CLEAR(&path_policy_debug);
+
+       return 0;
+}
+
 void path_cli_init(void)
 {
+       hook_register(nb_client_debug_config_write,
+                     path_policy_cli_debug_config_write);
+       hook_register(nb_client_debug_set_all, path_policy_cli_debug_set_all);
+
        install_node(&segment_routing_node);
        install_node(&sr_traffic_eng_node);
        install_node(&srte_segment_list_node);
@@ -1311,6 +1340,9 @@ void path_cli_init(void)
        install_element(ENABLE_NODE, &show_srte_policy_cmd);
        install_element(ENABLE_NODE, &show_srte_policy_detail_cmd);
 
+       install_element(ENABLE_NODE, &debug_path_policy_cmd);
+       install_element(CONFIG_NODE, &debug_path_policy_cmd);
+
        install_element(CONFIG_NODE, &segment_routing_cmd);
        install_element(SEGMENT_ROUTING_NODE, &sr_traffic_eng_cmd);
        install_element(SR_TRAFFIC_ENG_NODE, &srte_segment_list_cmd);