Florin Coras | a436a42 | 2019-08-20 07:09:31 -0700 | [diff] [blame^] | 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 | tcp_evt_track_register (elog_track_t * et) |
| 21 | { |
| 22 | tcp_dbg_main_t *tdm = &tcp_dbg_main; |
| 23 | u32 fl_len, track_index; |
| 24 | |
| 25 | fl_len = vec_len (tdm->free_track_indices); |
| 26 | if (fl_len) |
| 27 | { |
| 28 | track_index = tdm->free_track_indices[fl_len - 1]; |
| 29 | _vec_len (tdm->free_track_indices) -= 1; |
| 30 | et->track_index_plus_one = track_index + 1; |
| 31 | } |
| 32 | else |
| 33 | elog_track_register (&vlib_global_main.elog_main, et); |
| 34 | } |
| 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 | tcp_debug_show_groups (void) |
| 44 | { |
| 45 | tcp_dbg_main_t *tdm = &tcp_dbg_main; |
| 46 | vlib_main_t *vm = vlib_get_main (); |
| 47 | int i = 0; |
| 48 | |
| 49 | vlib_cli_output (vm, "%-10s%-30s%-10s", "Index", "Group", "Level"); |
| 50 | |
| 51 | for (i = 0; i < TCP_EVT_N_GRP; i++) |
| 52 | vlib_cli_output (vm, "%-10d%-30s%-10d", i, tcp_evt_grp_str[i], |
| 53 | tdm->grp_dbg_lvl[i]); |
| 54 | } |
| 55 | |
| 56 | static clib_error_t * |
| 57 | tcp_debug_fn (vlib_main_t * vm, unformat_input_t * input, |
| 58 | vlib_cli_command_t * cmd) |
| 59 | { |
| 60 | unformat_input_t _line_input, *line_input = &_line_input; |
| 61 | tcp_dbg_main_t *tdm = &tcp_dbg_main; |
| 62 | u32 group = ~0, level = ~0; |
| 63 | clib_error_t *error = 0; |
| 64 | u8 is_show = 0; |
| 65 | |
| 66 | if (!TCP_DEBUG_ALWAYS) |
| 67 | return clib_error_return (0, "must compile with TCP_DEBUG_ALWAYS set"); |
| 68 | |
| 69 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 70 | return clib_error_return (0, "expected enable | disable"); |
| 71 | |
| 72 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 73 | { |
| 74 | if (unformat (line_input, "show")) |
| 75 | is_show = 1; |
| 76 | else if (unformat (line_input, "group %d", &group)) |
| 77 | ; |
| 78 | else if (unformat (line_input, "level %d", &level)) |
| 79 | ; |
| 80 | else |
| 81 | { |
| 82 | error = clib_error_return (0, "unknown input `%U'", |
| 83 | format_unformat_error, line_input); |
| 84 | goto done; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (is_show) |
| 89 | { |
| 90 | tcp_debug_show_groups (); |
| 91 | goto done; |
| 92 | } |
| 93 | if (group >= TCP_EVT_N_GRP) |
| 94 | { |
| 95 | error = clib_error_return (0, "group out of bounds"); |
| 96 | goto done; |
| 97 | } |
| 98 | if (group == ~0 || level == ~0) |
| 99 | { |
| 100 | error = clib_error_return (0, "group and level must be set"); |
| 101 | goto done; |
| 102 | } |
| 103 | |
| 104 | tdm->grp_dbg_lvl[group] = level; |
| 105 | |
| 106 | done: |
| 107 | |
| 108 | unformat_free (line_input); |
| 109 | return error; |
| 110 | } |
| 111 | |
| 112 | /* *INDENT-OFF* */ |
| 113 | VLIB_CLI_COMMAND (tcp_debug_command, static) = |
| 114 | { |
| 115 | .path = "tcp debug", |
| 116 | .short_help = "tcp [show] [debug group <N> level <N>]", |
| 117 | .function = tcp_debug_fn, |
| 118 | }; |
| 119 | /* *INDENT-ON* */ |
| 120 | |
| 121 | /* |
| 122 | * fd.io coding-style-patch-verification: ON |
| 123 | * |
| 124 | * Local Variables: |
| 125 | * eval: (c-set-style "gnu") |
| 126 | * End: |
| 127 | */ |