FD.io VPP  v20.09-64-g4f7b92f0a
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 typedef enum cnat_scanner_cmd_t_
20 {
24 
25 static uword
28 {
29  uword event_type, *event_data = 0;
31  f64 start_time;
32  int enabled = 1, i = 0;
33 
34  while (1)
35  {
36  if (enabled)
38  else
40 
41  event_type = vlib_process_get_events (vm, &event_data);
42  vec_reset_length (event_data);
43 
44  start_time = vlib_time_now (vm);
45 
46  switch (event_type)
47  {
48  /* timer expired */
49  case ~0:
50  break;
51  case CNAT_SCANNER_OFF:
52  enabled = 0;
53  break;
54  case CNAT_SCANNER_ON:
55  enabled = 1;
56  break;
57  default:
58  ASSERT (0);
59  }
60 
62  i = cnat_session_scan (vm, start_time, i);
63  }
64  return 0;
65 }
66 
67 /* *INDENT-OFF* */
69  .function = cnat_scanner_process,
70  .type = VLIB_NODE_TYPE_PROCESS,
71  .name = "cnat-scanner-process",
72 };
73 /* *INDENT-ON* */
74 
75 static clib_error_t *
78 {
80 
81  cmd = CNAT_SCANNER_ON;
82 
84  {
85  if (unformat (input, "on"))
86  cmd = CNAT_SCANNER_ON;
87  else if (unformat (input, "off"))
88  cmd = CNAT_SCANNER_OFF;
89  else
90  return (clib_error_return (0, "unknown input '%U'",
91  format_unformat_error, input));
92  }
93 
95 
96  return (NULL);
97 }
98 
99 /* *INDENT-OFF* */
100 VLIB_CLI_COMMAND (cnat_scanner_cmd_node, static) = {
101  .path = "test cnat scanner",
102  .function = cnat_scanner_cmd,
103  .short_help = "test cnat scanner",
104 };
105 /* *INDENT-ON* */
106 
107 /*
108  * fd.io coding-style-patch-verification: ON
109  *
110  * Local Variables:
111  * eval: (c-set-style "gnu")
112  * End:
113  */
u64 cnat_session_scan(vlib_main_t *vm, f64 start_time, int i)
Scan the session DB for expired sessions.
Definition: cnat_session.c:157
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:751
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:656
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:333
vlib_main_t * vm
Definition: in2out_ed.c:1582
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
enum cnat_scanner_cmd_t_ cnat_scanner_cmd_t
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:579
#define clib_error_return(e, args...)
Definition: error.h:99
vnet_crypto_main_t * cm
Definition: quic_crypto.c:53
static clib_error_t * cnat_scanner_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *c)
Definition: cnat_scanner.c:76
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:1015
struct _unformat_input_t unformat_input_t
void cnat_client_throttle_pool_process()
Definition: cnat_client.c:74
cnat_scanner_cmd_t_
Definition: cnat_scanner.c:19
f64 scanner_timeout
Definition: cnat_types.h:111
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
svmdb_client_t * c
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
vlib_node_registration_t cnat_scanner_process_node
(constructor) VLIB_REGISTER_NODE (cnat_scanner_process_node)
Definition: cnat_scanner.c:68
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
#define ASSERT(truth)
static uword cnat_scanner_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: cnat_scanner.c:26
u64 uword
Definition: types.h:112
cnat_main_t cnat_main
Definition: cnat_types.c:18
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171