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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <cnat/cnat_session.h>
17 #include <cnat/cnat_client.h>
20 cnat_scanner_process (vlib_main_t * vm,
21 vlib_node_runtime_t * rt, vlib_frame_t * f)
23 uword event_type, *event_data = 0;
24 cnat_main_t *cm = &cnat_main;
26 int enabled = 0, i = 0;
31 vlib_process_wait_for_event_or_clock (vm, cm->scanner_timeout);
33 vlib_process_wait_for_event (vm);
35 event_type = vlib_process_get_events (vm, &event_data);
36 vec_reset_length (event_data);
38 start_time = vlib_time_now (vm);
45 case CNAT_SCANNER_OFF:
55 cnat_client_throttle_pool_process ();
56 i = cnat_session_scan (vm, start_time, i);
62 VLIB_REGISTER_NODE (cnat_scanner_process_node) = {
63 .function = cnat_scanner_process,
64 .type = VLIB_NODE_TYPE_PROCESS,
65 .name = "cnat-scanner-process",
70 cnat_scanner_cmd (vlib_main_t * vm,
71 unformat_input_t * input, vlib_cli_command_t * c)
73 cnat_scanner_cmd_t cmd;
75 cmd = CNAT_SCANNER_ON;
77 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
79 if (unformat (input, "on"))
80 cmd = CNAT_SCANNER_ON;
81 else if (unformat (input, "off"))
82 cmd = CNAT_SCANNER_OFF;
84 return (clib_error_return (0, "unknown input '%U'",
85 format_unformat_error, input));
87 cnat_enable_disable_scanner (cmd);
93 VLIB_CLI_COMMAND (cnat_scanner_cmd_node, static) = {
94 .path = "test cnat scanner",
95 .function = cnat_scanner_cmd,
96 .short_help = "test cnat scanner",
100 static clib_error_t *
101 cnat_scanner_init (vlib_main_t * vm)
103 cnat_main_t *cm = &cnat_main;
104 cm->scanner_node_index = cnat_scanner_process_node.index;
109 VLIB_INIT_FUNCTION (cnat_scanner_init);
112 * fd.io coding-style-patch-verification: ON
115 * eval: (c-set-style "gnu")