back to topotato report
topotato coverage report
Current view: top level - staticd - static_debug.c (source / functions) Hit Total Coverage
Test: test_pim_cbsr.py::PIMCandidateBSRTest Lines: 3 31 9.7 %
Date: 2023-02-16 02:09:14 Functions: 1 6 16.7 %

          Line data    Source code
       1             : /*
       2             :  * Staticd debug related functions
       3             :  * Copyright (C) 2019 Volta Networks Inc.
       4             :  * Mark Stapp
       5             :  *
       6             :  * This file is part of FRRouting (FRR).
       7             :  *
       8             :  * This program is free software; you can redistribute it and/or modify it
       9             :  * under the terms of the GNU General Public License as published by the
      10             :  * Free Software Foundation; either version 2, or (at your option) any
      11             :  * later version.
      12             :  *
      13             :  * This program is distributed in the hope that it will be useful, but
      14             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU General Public License along
      19             :  * with this program; see the file COPYING; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23             : #include <zebra.h>
      24             : 
      25             : #include "lib/command.h"
      26             : #include "lib/debug.h"
      27             : #include "lib/bfd.h"
      28             : 
      29             : #include "static_debug.h"
      30             : 
      31             : /*
      32             :  * Debug infra: a debug struct for each category, and a corresponding
      33             :  * string.
      34             :  */
      35             : 
      36             : /* clang-format off */
      37             : struct debug static_dbg_events = {0, "Staticd events"};
      38             : struct debug static_dbg_route = {0, "Staticd route"};
      39             : struct debug static_dbg_bfd = {0, "Staticd bfd"};
      40             : 
      41             : struct debug *static_debug_arr[] =  {
      42             :         &static_dbg_events,
      43             :         &static_dbg_route,
      44             :         &static_dbg_bfd
      45             : };
      46             : 
      47             : const char *static_debugs_conflines[] = {
      48             :         "debug static events",
      49             :         "debug static route",
      50             :         "debug static bfd"
      51             : };
      52             : /* clang-format on */
      53             : 
      54             : 
      55             : /*
      56             :  * Set or unset all staticd debugs
      57             :  *
      58             :  * flags
      59             :  *    The flags to set
      60             :  *
      61             :  * set
      62             :  *    Whether to set or unset the specified flags
      63             :  */
      64           0 : static void static_debug_set_all(uint32_t flags, bool set)
      65             : {
      66           0 :         for (unsigned int i = 0; i < array_size(static_debug_arr); i++) {
      67           0 :                 DEBUG_FLAGS_SET(static_debug_arr[i], flags, set);
      68             : 
      69             :                 /* if all modes have been turned off, don't preserve options */
      70           0 :                 if (!DEBUG_MODE_CHECK(static_debug_arr[i], DEBUG_MODE_ALL))
      71           0 :                         DEBUG_CLEAR(static_debug_arr[i]);
      72             :         }
      73           0 : }
      74             : 
      75           0 : static int static_debug_config_write_helper(struct vty *vty, bool config)
      76             : {
      77           0 :         uint32_t mode = DEBUG_MODE_ALL;
      78             : 
      79           0 :         if (config)
      80           0 :                 mode = DEBUG_MODE_CONF;
      81             : 
      82           0 :         for (unsigned int i = 0; i < array_size(static_debug_arr); i++)
      83           0 :                 if (DEBUG_MODE_CHECK(static_debug_arr[i], mode))
      84           0 :                         vty_out(vty, "%s\n", static_debugs_conflines[i]);
      85             : 
      86           0 :         return 0;
      87             : }
      88             : 
      89           0 : int static_config_write_debug(struct vty *vty)
      90             : {
      91           0 :         return static_debug_config_write_helper(vty, true);
      92             : }
      93             : 
      94           0 : int static_debug_status_write(struct vty *vty)
      95             : {
      96           0 :         return static_debug_config_write_helper(vty, false);
      97             : }
      98             : 
      99             : /*
     100             :  * Set debugging status.
     101             :  *
     102             :  * vtynode
     103             :  *    vty->node
     104             :  *
     105             :  * onoff
     106             :  *    Whether to turn the specified debugs on or off
     107             :  *
     108             :  * events
     109             :  *    Debug general internal events
     110             :  *
     111             :  */
     112           0 : void static_debug_set(int vtynode, bool onoff, bool events, bool route,
     113             :                       bool bfd)
     114             : {
     115           0 :         uint32_t mode = DEBUG_NODE2MODE(vtynode);
     116             : 
     117           0 :         if (events)
     118           0 :                 DEBUG_MODE_SET(&static_dbg_events, mode, onoff);
     119           0 :         if (route)
     120           0 :                 DEBUG_MODE_SET(&static_dbg_route, mode, onoff);
     121           0 :         if (bfd) {
     122           0 :                 DEBUG_MODE_SET(&static_dbg_bfd, mode, onoff);
     123           0 :                 bfd_protocol_integration_set_debug(onoff);
     124             :         }
     125           0 : }
     126             : 
     127             : /*
     128             :  * Debug lib initialization
     129             :  */
     130             : 
     131             : struct debug_callbacks static_dbg_cbs = {
     132             :         .debug_set_all = static_debug_set_all
     133             : };
     134             : 
     135           3 : void static_debug_init(void)
     136             : {
     137           3 :         debug_init(&static_dbg_cbs);
     138           3 : }

Generated by: LCOV version v1.16-topotato