LCOV - code coverage report
Current view: top level - vnet/tcp - tcp_debug.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 1 37 2.7 %
Date: 2023-07-05 22:20:52 Functions: 2 6 33.3 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2019 Cisco and/or its affiliates.
       3             :  * Licensed under the Apache License, Version 2.0 (the "License");
       4             :  * you may not use this file except in compliance with the License.
       5             :  * You may obtain a copy of the License at:
       6             :  *
       7             :  *     http://www.apache.org/licenses/LICENSE-2.0
       8             :  *
       9             :  * Unless required by applicable law or agreed to in writing, software
      10             :  * distributed under the License is distributed on an "AS IS" BASIS,
      11             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             :  * See the License for the specific language governing permissions and
      13             :  * limitations under the License.
      14             :  */
      15             : #include <vnet/tcp/tcp_debug.h>
      16             : 
      17             : tcp_dbg_main_t tcp_dbg_main;
      18             : 
      19             : void
      20           0 : tcp_evt_track_register (elog_track_t * et)
      21             : {
      22           0 :   tcp_dbg_main_t *tdm = &tcp_dbg_main;
      23             :   u32 fl_len, track_index;
      24             : 
      25           0 :   fl_len = vec_len (tdm->free_track_indices);
      26           0 :   if (fl_len)
      27             :     {
      28           0 :       track_index = tdm->free_track_indices[fl_len - 1];
      29           0 :       vec_dec_len (tdm->free_track_indices, 1);
      30           0 :       et->track_index_plus_one = track_index + 1;
      31             :     }
      32             :   else
      33           0 :     elog_track_register (&vlib_global_main.elog_main, et);
      34           0 : }
      35             : 
      36             : static const char *tcp_evt_grp_str[] = {
      37             : #define _(sym, str) str,
      38             :   foreach_tcp_evt_grp
      39             : #undef _
      40             : };
      41             : 
      42             : static void
      43           0 : tcp_debug_show_groups (void)
      44             : {
      45           0 :   tcp_dbg_main_t *tdm = &tcp_dbg_main;
      46           0 :   vlib_main_t *vm = vlib_get_main ();
      47           0 :   int i = 0;
      48             : 
      49           0 :   vlib_cli_output (vm, "%-10s%-30s%-10s", "Index", "Group", "Level");
      50             : 
      51           0 :   for (i = 0; i < TCP_EVT_N_GRP; i++)
      52           0 :     vlib_cli_output (vm, "%-10d%-30s%-10d", i, tcp_evt_grp_str[i],
      53           0 :                      tdm->grp_dbg_lvl[i]);
      54           0 : }
      55             : 
      56             : static void
      57           0 : tcp_debug_check_lc (void)
      58             : {
      59           0 :   tcp_dbg_main_t *tdm = &tcp_dbg_main;
      60           0 :   int i, have_enabled = 0;
      61             : 
      62           0 :   if (tdm->grp_dbg_lvl[TCP_EVT_GRP_LC])
      63           0 :     return;
      64             : 
      65           0 :   for (i = 0; i < TCP_EVT_N_GRP; i++)
      66             :     {
      67           0 :       if (tdm->grp_dbg_lvl[i])
      68             :         {
      69           0 :           have_enabled = 1;
      70           0 :           break;
      71             :         }
      72             :     }
      73             : 
      74             :   /* Make sure LC is enabled for track initialization */
      75           0 :   if (have_enabled)
      76           0 :     tdm->grp_dbg_lvl[TCP_EVT_GRP_LC] = 1;
      77             : }
      78             : 
      79             : static clib_error_t *
      80           0 : tcp_debug_fn (vlib_main_t * vm, unformat_input_t * input,
      81             :               vlib_cli_command_t * cmd)
      82             : {
      83           0 :   unformat_input_t _line_input, *line_input = &_line_input;
      84           0 :   tcp_dbg_main_t *tdm = &tcp_dbg_main;
      85           0 :   u32 group = ~0, level = ~0;
      86           0 :   clib_error_t *error = 0;
      87           0 :   u8 is_show = 0;
      88             : 
      89             :   if (!TCP_DEBUG_ALWAYS)
      90           0 :     return clib_error_return (0, "must compile with TCP_DEBUG_ALWAYS set");
      91             : 
      92             :   if (!unformat_user (input, unformat_line_input, line_input))
      93             :     return clib_error_return (0, "expected enable | disable");
      94             : 
      95             :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
      96             :     {
      97             :       if (unformat (line_input, "show"))
      98             :         is_show = 1;
      99             :       else if (unformat (line_input, "group %d", &group))
     100             :         ;
     101             :       else if (unformat (line_input, "level %d", &level))
     102             :         ;
     103             :       else
     104             :         {
     105             :           error = clib_error_return (0, "unknown input `%U'",
     106             :                                      format_unformat_error, line_input);
     107             :           goto done;
     108             :         }
     109             :     }
     110             : 
     111             :   if (is_show)
     112             :     {
     113             :       tcp_debug_show_groups ();
     114             :       goto done;
     115             :     }
     116             :   if (group >= TCP_EVT_N_GRP)
     117             :     {
     118             :       error = clib_error_return (0, "group out of bounds");
     119             :       goto done;
     120             :     }
     121             :   if (group == ~0 || level == ~0)
     122             :     {
     123             :       error = clib_error_return (0, "group and level must be set");
     124             :       goto done;
     125             :     }
     126             : 
     127             :   tdm->grp_dbg_lvl[group] = level;
     128             : 
     129             :   tcp_debug_check_lc ();
     130             : 
     131             : done:
     132             : 
     133             :   unformat_free (line_input);
     134             :   return error;
     135             : }
     136             : 
     137             : /* *INDENT-OFF* */
     138      272887 : VLIB_CLI_COMMAND (tcp_debug_command, static) =
     139             : {
     140             :   .path = "tcp debug",
     141             :   .short_help = "tcp [show] [debug group <N> level <N>]",
     142             :   .function = tcp_debug_fn,
     143             : };
     144             : /* *INDENT-ON* */
     145             : 
     146             : /*
     147             :  * fd.io coding-style-patch-verification: ON
     148             :  *
     149             :  * Local Variables:
     150             :  * eval: (c-set-style "gnu")
     151             :  * End:
     152             :  */

Generated by: LCOV version 1.14