back to topotato report
topotato coverage report
Current view: top level - bgpd/rfapi - vnc_debug.c (source / functions) Hit Total Coverage
Test: aggregated run ( view descriptions ) Lines: 10 55 18.2 %
Date: 2023-02-24 19:38:44 Functions: 1 6 16.7 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2016, LabN Consulting, L.L.C.
       4             :  *
       5             :  * This program is free software; you can redistribute it and/or
       6             :  * modify it under the terms of the GNU General Public License
       7             :  * as published by the Free Software Foundation; either version 2
       8             :  * of the License, or (at your option) any later version.
       9             :  *
      10             :  * This program is distributed in the hope that it will be useful,
      11             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :  * GNU General Public License for more details.
      14             :  *
      15             :  * You should have received a copy of the GNU General Public License along
      16             :  * with this program; see the file COPYING; if not, write to the Free Software
      17             :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      18             :  */
      19             : 
      20             : #include "lib/zebra.h"
      21             : 
      22             : #include <lib/version.h>
      23             : #include "lib/prefix.h"
      24             : #include "lib/linklist.h"
      25             : #include "lib/stream.h"
      26             : #include "lib/command.h"
      27             : #include "lib/log.h"
      28             : #include "bgpd/rfapi/vnc_debug.h"
      29             : 
      30             : /*
      31             :  * debug state storage
      32             :  */
      33             : unsigned long conf_vnc_debug;
      34             : unsigned long term_vnc_debug;
      35             : 
      36             : struct vnc_debug {
      37             :         unsigned long bit;
      38             :         const char *name;
      39             : };
      40             : 
      41             : static const struct vnc_debug vncdebug[] = {
      42             :         {VNC_DEBUG_RFAPI_QUERY, "rfapi-query"},
      43             :         {VNC_DEBUG_IMPORT_BI_ATTACH, "import-bi-attach"},
      44             :         {VNC_DEBUG_IMPORT_DEL_REMOTE, "import-del-remote"},
      45             :         {VNC_DEBUG_EXPORT_BGP_GETCE, "export-bgp-getce"},
      46             :         {VNC_DEBUG_EXPORT_BGP_DIRECT_ADD, "export-bgp-direct-add"},
      47             :         {VNC_DEBUG_IMPORT_BGP_ADD_ROUTE, "import-bgp-add-route"},
      48             :         {VNC_DEBUG_VERBOSE, "verbose"},
      49             : };
      50             : 
      51             : #define VNC_STR "VNC information\n"
      52             : 
      53             : /***********************************************************************
      54             :  *      debug bgp vnc <foo>
      55             :  ***********************************************************************/
      56           0 : DEFUN (debug_bgp_vnc,
      57             :        debug_bgp_vnc_cmd,
      58             :        "debug bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>",
      59             :        DEBUG_STR
      60             :        BGP_STR
      61             :        VNC_STR
      62             :        "rfapi query handling\n"
      63             :        "import BI atachment\n"
      64             :        "import delete remote routes\n"
      65             :        "verbose logging\n")
      66             : {
      67           0 :         size_t i;
      68             : 
      69           0 :         for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
      70           0 :                 if (strmatch(argv[3]->text, vncdebug[i].name)) {
      71           0 :                         if (vty->node == CONFIG_NODE) {
      72           0 :                                 conf_vnc_debug |= vncdebug[i].bit;
      73           0 :                                 term_vnc_debug |= vncdebug[i].bit;
      74             :                         } else {
      75           0 :                                 term_vnc_debug |= vncdebug[i].bit;
      76           0 :                                 vty_out(vty, "BGP vnc %s debugging is on\n",
      77             :                                         vncdebug[i].name);
      78             :                         }
      79           0 :                         return CMD_SUCCESS;
      80             :                 }
      81             :         }
      82           0 :         vty_out(vty, "Unknown debug flag: %s\n", argv[3]->arg);
      83           0 :         return CMD_WARNING_CONFIG_FAILED;
      84             : }
      85             : 
      86           0 : DEFUN (no_debug_bgp_vnc,
      87             :        no_debug_bgp_vnc_cmd,
      88             :        "no debug bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>",
      89             :        NO_STR
      90             :        DEBUG_STR
      91             :        BGP_STR
      92             :        VNC_STR
      93             :        "rfapi query handling\n"
      94             :        "import BI atachment\n"
      95             :        "import delete remote routes\n"
      96             :        "verbose logging\n")
      97             : {
      98           0 :         size_t i;
      99             : 
     100           0 :         for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
     101           0 :                 if (strmatch(argv[argc - 1]->text, vncdebug[i].name)) {
     102           0 :                         if (vty->node == CONFIG_NODE) {
     103           0 :                                 conf_vnc_debug &= ~vncdebug[i].bit;
     104           0 :                                 term_vnc_debug &= ~vncdebug[i].bit;
     105             :                         } else {
     106           0 :                                 term_vnc_debug &= ~vncdebug[i].bit;
     107           0 :                                 vty_out(vty, "BGP vnc %s debugging is off\n",
     108             :                                         vncdebug[i].name);
     109             :                         }
     110           0 :                         return CMD_SUCCESS;
     111             :                 }
     112             :         }
     113           0 :         vty_out(vty, "Unknown debug flag: %s\n", argv[3]->arg);
     114           0 :         return CMD_WARNING_CONFIG_FAILED;
     115             : }
     116             : 
     117             : /***********************************************************************
     118             :  *      no debug bgp vnc all
     119             :  ***********************************************************************/
     120             : 
     121           0 : DEFUN (no_debug_bgp_vnc_all,
     122             :        no_debug_bgp_vnc_all_cmd,
     123             :        "no debug all bgp vnc",
     124             :        NO_STR
     125             :        DEBUG_STR
     126             :        "Disable all VNC debugging\n"
     127             :        BGP_STR
     128             :        VNC_STR)
     129             : {
     130           0 :         term_vnc_debug = 0;
     131           0 :         vty_out(vty, "All possible VNC debugging has been turned off\n");
     132             : 
     133           0 :         return CMD_SUCCESS;
     134             : }
     135             : 
     136             : /***********************************************************************
     137             :  *      show/save
     138             :  ***********************************************************************/
     139             : 
     140           0 : DEFUN_NOSH (show_debugging_bgp_vnc,
     141             :             show_debugging_bgp_vnc_cmd,
     142             :             "show debugging bgp vnc",
     143             :             SHOW_STR
     144             :             DEBUG_STR
     145             :             BGP_STR
     146             :             VNC_STR)
     147             : {
     148           0 :         size_t i;
     149             : 
     150           0 :         vty_out(vty, "BGP VNC debugging status:\n");
     151             : 
     152           0 :         for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
     153           0 :                 if (term_vnc_debug & vncdebug[i].bit) {
     154           0 :                         vty_out(vty, "  BGP VNC %s debugging is on\n",
     155           0 :                                 vncdebug[i].name);
     156             :                 }
     157             :         }
     158           0 :         vty_out(vty, "\n");
     159           0 :         return CMD_SUCCESS;
     160             : }
     161             : 
     162           0 : static int bgp_vnc_config_write_debug(struct vty *vty)
     163             : {
     164           0 :         int write = 0;
     165           0 :         size_t i;
     166             : 
     167           0 :         for (i = 0; i < array_size(vncdebug); ++i) {
     168           0 :                 if (conf_vnc_debug & vncdebug[i].bit) {
     169           0 :                         vty_out(vty, "debug bgp vnc %s\n", vncdebug[i].name);
     170           0 :                         write++;
     171             :                 }
     172             :         }
     173           0 :         return write;
     174             : }
     175             : 
     176             : static int bgp_vnc_config_write_debug(struct vty *vty);
     177             : static struct cmd_node debug_node = {
     178             :         .name = "vnc debug",
     179             :         .node = DEBUG_VNC_NODE,
     180             :         .prompt = "",
     181             :         .config_write = bgp_vnc_config_write_debug,
     182             : };
     183             : 
     184          48 : void vnc_debug_init(void)
     185             : {
     186          48 :         install_node(&debug_node);
     187          48 :         install_element(ENABLE_NODE, &show_debugging_bgp_vnc_cmd);
     188             : 
     189          48 :         install_element(ENABLE_NODE, &debug_bgp_vnc_cmd);
     190          48 :         install_element(CONFIG_NODE, &debug_bgp_vnc_cmd);
     191          48 :         install_element(ENABLE_NODE, &no_debug_bgp_vnc_cmd);
     192          48 :         install_element(CONFIG_NODE, &no_debug_bgp_vnc_cmd);
     193             : 
     194          48 :         install_element(ENABLE_NODE, &no_debug_bgp_vnc_all_cmd);
     195          48 :         install_element(CONFIG_NODE, &no_debug_bgp_vnc_all_cmd);
     196          48 : }

Generated by: LCOV version v1.16-topotato