FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
cnat_scanner.c
Go to the documentation of this file.
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
22 {
23  uword event_type, *event_data = 0;
25  f64 start_time;
26  int enabled = 0, i = 0;
27 
28  while (1)
29  {
30  if (enabled)
31  vlib_process_wait_for_event_or_clock (vm, cm->scanner_timeout);
32  else
34 
35  event_type = vlib_process_get_events (vm, &event_data);
36  vec_reset_length (event_data);
37 
38  start_time = vlib_time_now (vm);
39 
40  switch (event_type)
41  {
42  /* timer expired */
43  case ~0:
44  break;
45  case CNAT_SCANNER_OFF:
46  enabled = 0;
47  break;
48  case CNAT_SCANNER_ON:
49  enabled = 1;
50  break;
51  default:
52  ASSERT (0);
53  }
54 
56  i = cnat_session_scan (vm, start_time, i);
57  }
58  return 0;
59 }
60 
62  .function = cnat_scanner_process,
63  .type = VLIB_NODE_TYPE_PROCESS,
64  .name = "cnat-scanner-process",
65 };
66 
67 static clib_error_t *
70 {
72 
73  cmd = CNAT_SCANNER_ON;
74 
76  {
77  if (unformat (input, "on"))
78  cmd = CNAT_SCANNER_ON;
79  else if (unformat (input, "off"))
80  cmd = CNAT_SCANNER_OFF;
81  else
82  return (clib_error_return (0, "unknown input '%U'",
83  format_unformat_error, input));
84  }
86 
87  return (NULL);
88 }
89 
91  .path = "test cnat scanner",
92  .function = cnat_scanner_cmd,
93  .short_help = "test cnat scanner",
94 };
95 
96 static clib_error_t *
98 {
100  cm->scanner_node_index = cnat_scanner_process_node.index;
101 
102  return (NULL);
103 }
104 
106 
107 /*
108  * fd.io coding-style-patch-verification: ON
109  *
110  * Local Variables:
111  * eval: (c-set-style "gnu")
112  * End:
113  */
vec_reset_length
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
Definition: vec_bootstrap.h:194
cnat_session_scan
u64 cnat_session_scan(vlib_main_t *vm, f64 start_time, int i)
Scan the session DB for expired sessions.
Definition: cnat_session.c:176
cnat_client_throttle_pool_process
void cnat_client_throttle_pool_process()
Definition: cnat_client.c:69
vlib_process_wait_for_event
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:660
f
vlib_frame_t * f
Definition: interface_output.c:1098
cnat_main
cnat_main_t cnat_main
Definition: cnat_types.c:18
cnat_session.h
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
CNAT_SCANNER_OFF
@ CNAT_SCANNER_OFF
Definition: cnat_types.h:184
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
cnat_scanner_cmd
static clib_error_t * cnat_scanner_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *c)
Definition: cnat_scanner.c:68
unformat_input_t
struct _unformat_input_t unformat_input_t
vlib_frame_t
Definition: node.h:372
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vlib_process_get_events
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type,...
Definition: node_funcs.h:583
CNAT_SCANNER_ON
@ CNAT_SCANNER_ON
Definition: cnat_types.h:185
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
uword
u64 uword
Definition: types.h:112
cnat_scanner_process_node
vlib_node_registration_t cnat_scanner_process_node
(constructor) VLIB_REGISTER_NODE (cnat_scanner_process_node)
Definition: cnat_scanner.c:61
f64
double f64
Definition: types.h:142
cnat_scanner_cmd_node
static vlib_cli_command_t cnat_scanner_cmd_node
(constructor) VLIB_CLI_COMMAND (cnat_scanner_cmd_node)
Definition: cnat_scanner.c:90
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:594
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vlib_process_wait_for_event_or_clock
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:755
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
cnat_scanner_cmd_t
enum cnat_scanner_cmd_t_ cnat_scanner_cmd_t
cnat_client.h
VLIB_NODE_TYPE_PROCESS
@ VLIB_NODE_TYPE_PROCESS
Definition: node.h:84
cnat_enable_disable_scanner
void cnat_enable_disable_scanner(cnat_scanner_cmd_t event_type)
Enable/Disable session cleanup.
Definition: cnat_types.c:169
vlib_main_t
Definition: main.h:102
clib_error_t
Definition: clib_error.h:21
rt
vnet_interface_output_runtime_t * rt
Definition: interface_output.c:419
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
i
int i
Definition: flowhash_template.h:376
vlib_time_now
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:327
cnat_scanner_init
static clib_error_t * cnat_scanner_init(vlib_main_t *vm)
Definition: cnat_scanner.c:97
vlib_node_runtime_t
Definition: node.h:454
vlib_cli_command_t
Definition: cli.h:92
cnat_scanner_process
static uword cnat_scanner_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: cnat_scanner.c:20
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
cnat_main_
Definition: cnat_types.h:94
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169