LCOV - code coverage report
Current view: top level - plugins/cnat - cnat_scanner.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 37 40 92.5 %
Date: 2023-07-05 22:20:52 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2020 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             : 
      16             : #include <cnat/cnat_session.h>
      17             : #include <cnat/cnat_client.h>
      18             : 
      19             : static uword
      20         559 : cnat_scanner_process (vlib_main_t * vm,
      21             :                       vlib_node_runtime_t * rt, vlib_frame_t * f)
      22             : {
      23         559 :   uword event_type, *event_data = 0;
      24         559 :   cnat_main_t *cm = &cnat_main;
      25             :   f64 start_time;
      26         559 :   int enabled = 0, i = 0;
      27             : 
      28             :   while (1)
      29             :     {
      30         605 :       if (enabled)
      31          41 :         vlib_process_wait_for_event_or_clock (vm, cm->scanner_timeout);
      32             :       else
      33         564 :         vlib_process_wait_for_event (vm);
      34             : 
      35          46 :       event_type = vlib_process_get_events (vm, &event_data);
      36          46 :       vec_reset_length (event_data);
      37             : 
      38          46 :       start_time = vlib_time_now (vm);
      39             : 
      40          46 :       switch (event_type)
      41             :         {
      42             :           /* timer expired */
      43          39 :         case ~0:
      44          39 :           break;
      45           5 :         case CNAT_SCANNER_OFF:
      46           5 :           enabled = 0;
      47           5 :           break;
      48           2 :         case CNAT_SCANNER_ON:
      49           2 :           enabled = 1;
      50           2 :           break;
      51           0 :         default:
      52           0 :           ASSERT (0);
      53             :         }
      54             : 
      55          46 :       cnat_client_throttle_pool_process ();
      56          46 :       i = cnat_session_scan (vm, start_time, i);
      57             :     }
      58             :   return 0;
      59             : }
      60             : 
      61      159080 : VLIB_REGISTER_NODE (cnat_scanner_process_node) = {
      62             :   .function = cnat_scanner_process,
      63             :   .type = VLIB_NODE_TYPE_PROCESS,
      64             :   .name = "cnat-scanner-process",
      65             : };
      66             : 
      67             : static clib_error_t *
      68           4 : cnat_scanner_cmd (vlib_main_t * vm,
      69             :                   unformat_input_t * input, vlib_cli_command_t * c)
      70             : {
      71             :   cnat_scanner_cmd_t cmd;
      72             : 
      73           4 :   cmd = CNAT_SCANNER_ON;
      74             : 
      75           8 :   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
      76             :     {
      77           4 :       if (unformat (input, "on"))
      78           2 :         cmd = CNAT_SCANNER_ON;
      79           2 :       else if (unformat (input, "off"))
      80           2 :         cmd = CNAT_SCANNER_OFF;
      81             :       else
      82           0 :         return (clib_error_return (0, "unknown input '%U'",
      83             :                                    format_unformat_error, input));
      84             :     }
      85           4 :   cnat_enable_disable_scanner (cmd);
      86             : 
      87           4 :   return (NULL);
      88             : }
      89             : 
      90      245447 : VLIB_CLI_COMMAND (cnat_scanner_cmd_node, static) = {
      91             :   .path = "test cnat scanner",
      92             :   .function = cnat_scanner_cmd,
      93             :   .short_help = "test cnat scanner",
      94             : };
      95             : 
      96             : static clib_error_t *
      97         559 : cnat_scanner_init (vlib_main_t * vm)
      98             : {
      99         559 :   cnat_main_t *cm = &cnat_main;
     100         559 :   cm->scanner_node_index = cnat_scanner_process_node.index;
     101             : 
     102         559 :   return (NULL);
     103             : }
     104             : 
     105        1679 : VLIB_INIT_FUNCTION (cnat_scanner_init);
     106             : 
     107             : /*
     108             :  * fd.io coding-style-patch-verification: ON
     109             :  *
     110             :  * Local Variables:
     111             :  * eval: (c-set-style "gnu")
     112             :  * End:
     113             :  */

Generated by: LCOV version 1.14