blob: 36133523e34f6fe5b105a772d4ed730886650a4a [file] [log] [blame]
Dave Barach68b0fb02017-02-28 15:15:56 -05001/*
2 * Copyright (c) 2017 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/session/application.h>
16#include <vnet/session/session.h>
17
Florin Coras93992a92017-05-24 18:03:56 -070018u8 *
19format_stream_session_fifos (u8 * s, va_list * args)
20{
21 stream_session_t *ss = va_arg (*args, stream_session_t *);
Florin Coras6534b7a2017-07-18 05:38:03 -040022 int verbose = va_arg (*args, int);
Florin Coras52207f12018-07-12 14:48:06 -070023 session_event_t _e, *e = &_e;
Florin Coras6534b7a2017-07-18 05:38:03 -040024 u8 found;
25
Florin Coras7fb0fe12018-04-09 09:24:52 -070026 if (!ss->server_rx_fifo || !ss->server_tx_fifo)
27 return s;
28
Florin Coras54693d22018-07-17 10:46:29 -070029 s = format (s, " Rx fifo: %U", format_svm_fifo, ss->server_rx_fifo,
30 verbose);
Florin Coras6534b7a2017-07-18 05:38:03 -040031 if (verbose > 2 && ss->server_rx_fifo->has_event)
32 {
33 found = session_node_lookup_fifo_event (ss->server_rx_fifo, e);
34 s = format (s, " session node event: %s\n",
35 found ? "found" : "not found");
36 }
Florin Coras54693d22018-07-17 10:46:29 -070037 s = format (s, " Tx fifo: %U", format_svm_fifo, ss->server_tx_fifo,
38 verbose);
Florin Coras6534b7a2017-07-18 05:38:03 -040039 if (verbose > 2 && ss->server_tx_fifo->has_event)
40 {
41 found = session_node_lookup_fifo_event (ss->server_tx_fifo, e);
42 s = format (s, " session node event: %s\n",
43 found ? "found" : "not found");
44 }
Florin Coras93992a92017-05-24 18:03:56 -070045 return s;
46}
47
Dave Barach68b0fb02017-02-28 15:15:56 -050048/**
49 * Format stream session as per the following format
50 *
51 * verbose:
52 * "Connection", "Rx fifo", "Tx fifo", "Session Index"
53 * non-verbose:
54 * "Connection"
55 */
56u8 *
57format_stream_session (u8 * s, va_list * args)
58{
59 stream_session_t *ss = va_arg (*args, stream_session_t *);
60 int verbose = va_arg (*args, int);
61 transport_proto_vft_t *tp_vft;
62 u8 *str = 0;
Florin Coras561af9b2017-12-09 10:19:43 -080063 tp_vft = transport_protocol_get_vft (session_get_transport_proto (ss));
Dave Barach68b0fb02017-02-28 15:15:56 -050064
Florin Coras68810622017-07-24 17:40:28 -070065 if (verbose == 1 && ss->session_state >= SESSION_STATE_ACCEPTING)
Florin Corasbb292f42017-05-19 09:49:19 -070066 str = format (0, "%-10u%-10u%-10lld",
67 svm_fifo_max_dequeue (ss->server_rx_fifo),
68 svm_fifo_max_enqueue (ss->server_tx_fifo),
Florin Coras5c9083d2018-04-13 06:39:07 -070069 session_get_index (ss));
Dave Barach68b0fb02017-02-28 15:15:56 -050070
Florin Coras3cbc04b2017-10-02 00:18:51 -070071 if (ss->session_state >= SESSION_STATE_ACCEPTING)
Dave Barach68b0fb02017-02-28 15:15:56 -050072 {
Florin Corasbb292f42017-05-19 09:49:19 -070073 s = format (s, "%U", tp_vft->format_connection, ss->connection_index,
74 ss->thread_index, verbose);
75 if (verbose == 1)
76 s = format (s, "%v", str);
Florin Coras93992a92017-05-24 18:03:56 -070077 if (verbose > 1)
Florin Coras6534b7a2017-07-18 05:38:03 -040078 s = format (s, "%U", format_stream_session_fifos, ss, verbose);
Dave Barach68b0fb02017-02-28 15:15:56 -050079 }
80 else if (ss->session_state == SESSION_STATE_LISTENING)
81 {
82 s = format (s, "%-40U%v", tp_vft->format_listener, ss->connection_index,
83 str);
Florin Coras7fb0fe12018-04-09 09:24:52 -070084 if (verbose > 1)
85 s = format (s, "\n%U", format_stream_session_fifos, ss, verbose);
Dave Barach68b0fb02017-02-28 15:15:56 -050086 }
Florin Corasbb292f42017-05-19 09:49:19 -070087 else if (ss->session_state == SESSION_STATE_CONNECTING)
Dave Barach68b0fb02017-02-28 15:15:56 -050088 {
Florin Corasbb292f42017-05-19 09:49:19 -070089 s = format (s, "%-40U%v", tp_vft->format_half_open,
90 ss->connection_index, str);
Dave Barach68b0fb02017-02-28 15:15:56 -050091 }
Dave Barach68b0fb02017-02-28 15:15:56 -050092 else
93 {
Florin Corase04c2992017-03-01 08:17:34 -080094 clib_warning ("Session in state: %d!", ss->session_state);
Dave Barach68b0fb02017-02-28 15:15:56 -050095 }
Dave Barach68b0fb02017-02-28 15:15:56 -050096 vec_free (str);
97
98 return s;
99}
100
Florin Coras3eb50622017-07-13 01:24:57 -0400101uword
102unformat_stream_session_id (unformat_input_t * input, va_list * args)
103{
104 u8 *proto = va_arg (*args, u8 *);
105 ip46_address_t *lcl = va_arg (*args, ip46_address_t *);
106 ip46_address_t *rmt = va_arg (*args, ip46_address_t *);
107 u16 *lcl_port = va_arg (*args, u16 *);
108 u16 *rmt_port = va_arg (*args, u16 *);
109 u8 *is_ip4 = va_arg (*args, u8 *);
110 u8 tuple_is_set = 0;
111
112 memset (lcl, 0, sizeof (*lcl));
113 memset (rmt, 0, sizeof (*rmt));
114
115 if (unformat (input, "tcp"))
116 {
117 *proto = TRANSPORT_PROTO_TCP;
118 }
119 if (unformat (input, "udp"))
120 {
121 *proto = TRANSPORT_PROTO_UDP;
122 }
Dave Barachb7f1faa2017-08-29 11:43:37 -0400123 if (unformat (input, "%U:%d->%U:%d", unformat_ip4_address, &lcl->ip4,
124 lcl_port, unformat_ip4_address, &rmt->ip4, rmt_port))
Florin Coras3eb50622017-07-13 01:24:57 -0400125 {
126 *is_ip4 = 1;
127 tuple_is_set = 1;
128 }
129 else if (unformat (input, "%U:%d->%U:%d", unformat_ip6_address, &lcl->ip6,
130 lcl_port, unformat_ip6_address, &rmt->ip6, rmt_port))
131 {
132 *is_ip4 = 0;
133 tuple_is_set = 1;
134 }
Florin Coras3eb50622017-07-13 01:24:57 -0400135
Chris Lukeb2bcad62017-09-18 08:51:22 -0400136 return tuple_is_set;
Florin Coras3eb50622017-07-13 01:24:57 -0400137}
138
139uword
140unformat_stream_session (unformat_input_t * input, va_list * args)
141{
142 stream_session_t **result = va_arg (*args, stream_session_t **);
143 stream_session_t *s;
144 u8 proto = ~0;
145 ip46_address_t lcl, rmt;
Florin Corascea194d2017-10-02 00:18:51 -0700146 u32 lcl_port = 0, rmt_port = 0, fib_index = 0;
147 u8 is_ip4 = 0;
Florin Coras3eb50622017-07-13 01:24:57 -0400148
Chris Lukeb2bcad62017-09-18 08:51:22 -0400149 if (!unformat (input, "%U", unformat_stream_session_id, &proto, &lcl, &rmt,
150 &lcl_port, &rmt_port, &is_ip4))
Florin Coras3eb50622017-07-13 01:24:57 -0400151 return 0;
152
Florin Coras3eb50622017-07-13 01:24:57 -0400153 if (is_ip4)
Florin Coras3cbc04b2017-10-02 00:18:51 -0700154 s = session_lookup_safe4 (fib_index, &lcl.ip4, &rmt.ip4,
155 clib_host_to_net_u16 (lcl_port),
156 clib_host_to_net_u16 (rmt_port), proto);
Florin Coras3eb50622017-07-13 01:24:57 -0400157 else
Florin Coras3cbc04b2017-10-02 00:18:51 -0700158 s = session_lookup_safe6 (fib_index, &lcl.ip6, &rmt.ip6,
159 clib_host_to_net_u16 (lcl_port),
160 clib_host_to_net_u16 (rmt_port), proto);
Florin Coras3eb50622017-07-13 01:24:57 -0400161 if (s)
162 {
163 *result = s;
Florin Coras3cbc04b2017-10-02 00:18:51 -0700164 session_pool_remove_peeker (s->thread_index);
Florin Coras3eb50622017-07-13 01:24:57 -0400165 return 1;
166 }
167 return 0;
168}
169
170uword
171unformat_transport_connection (unformat_input_t * input, va_list * args)
172{
173 transport_connection_t **result = va_arg (*args, transport_connection_t **);
174 u32 suggested_proto = va_arg (*args, u32);
175 transport_connection_t *tc;
176 u8 proto = ~0;
177 ip46_address_t lcl, rmt;
Florin Corascea194d2017-10-02 00:18:51 -0700178 u32 lcl_port = 0, rmt_port = 0, fib_index = 0;
179 u8 is_ip4 = 0;
Florin Coras3eb50622017-07-13 01:24:57 -0400180
Chris Lukeb2bcad62017-09-18 08:51:22 -0400181 if (!unformat (input, "%U", unformat_stream_session_id, &proto, &lcl, &rmt,
182 &lcl_port, &rmt_port, &is_ip4))
Florin Coras3eb50622017-07-13 01:24:57 -0400183 return 0;
184
Florin Coras3eb50622017-07-13 01:24:57 -0400185 proto = (proto == (u8) ~ 0) ? suggested_proto : proto;
186 if (proto == (u8) ~ 0)
187 return 0;
Florin Coras3eb50622017-07-13 01:24:57 -0400188 if (is_ip4)
Florin Corascea194d2017-10-02 00:18:51 -0700189 tc = session_lookup_connection4 (fib_index, &lcl.ip4, &rmt.ip4,
190 clib_host_to_net_u16 (lcl_port),
191 clib_host_to_net_u16 (rmt_port), proto);
Florin Coras3eb50622017-07-13 01:24:57 -0400192 else
Florin Corascea194d2017-10-02 00:18:51 -0700193 tc = session_lookup_connection6 (fib_index, &lcl.ip6, &rmt.ip6,
194 clib_host_to_net_u16 (lcl_port),
195 clib_host_to_net_u16 (rmt_port), proto);
Florin Coras3eb50622017-07-13 01:24:57 -0400196
197 if (tc)
198 {
199 *result = tc;
200 return 1;
201 }
202 return 0;
203}
204
Dave Barach68b0fb02017-02-28 15:15:56 -0500205static clib_error_t *
206show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
207 vlib_cli_command_t * cmd)
208{
209 session_manager_main_t *smm = &session_manager_main;
Florin Corasdbd44562017-11-09 19:30:17 -0800210 u8 *str = 0, one_session = 0, do_listeners = 0, sst, *app_name;
Dave Barach68b0fb02017-02-28 15:15:56 -0500211 int verbose = 0, i;
Florin Corasdbd44562017-11-09 19:30:17 -0800212 stream_session_t *pool, *s;
213 u32 transport_proto = ~0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500214
Florin Corase04c2992017-03-01 08:17:34 -0800215 if (!smm->is_enabled)
216 {
flyingeagle23e2125062017-04-20 20:01:14 +0800217 return clib_error_return (0, "session layer is not enabled");
Florin Corase04c2992017-03-01 08:17:34 -0800218 }
219
Dave Barach68b0fb02017-02-28 15:15:56 -0500220 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
221 {
Florin Corasbb292f42017-05-19 09:49:19 -0700222 if (unformat (input, "verbose %d", &verbose))
223 ;
224 else if (unformat (input, "verbose"))
Dave Barach68b0fb02017-02-28 15:15:56 -0500225 verbose = 1;
Florin Corasdbd44562017-11-09 19:30:17 -0800226 else if (unformat (input, "listeners %U", unformat_transport_proto,
227 &transport_proto))
228 do_listeners = 1;
Florin Coras3eb50622017-07-13 01:24:57 -0400229 else if (unformat (input, "%U", unformat_stream_session, &s))
Dave Barach2c25a622017-06-26 11:35:07 -0400230 {
231 one_session = 1;
Dave Barach2c25a622017-06-26 11:35:07 -0400232 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500233 else
Florin Coras3eb50622017-07-13 01:24:57 -0400234 return clib_error_return (0, "unknown input `%U'",
235 format_unformat_error, input);
Dave Barach68b0fb02017-02-28 15:15:56 -0500236 }
237
Dave Barach2c25a622017-06-26 11:35:07 -0400238 if (one_session)
239 {
Florin Coras6534b7a2017-07-18 05:38:03 -0400240 vlib_cli_output (vm, "%U", format_stream_session, s, 3);
Dave Barach2c25a622017-06-26 11:35:07 -0400241 return 0;
242 }
243
Florin Corasdbd44562017-11-09 19:30:17 -0800244 if (do_listeners)
245 {
246 sst = session_type_from_proto_and_ip (transport_proto, 1);
Florin Coras5c9083d2018-04-13 06:39:07 -0700247 vlib_cli_output (vm, "%-40s%-24s%-10s", "Listener", "App", "S-idx");
248 /* *INDENT-OFF* */
249 pool_foreach (s, smm->sessions[0], ({
250 if (s->session_state != SESSION_STATE_LISTENING
251 || s->session_type != sst)
252 continue;
Florin Coras15531972018-08-12 23:50:53 -0700253 app_name = application_name_from_index (s->app_wrk_index);
Florin Coras5c9083d2018-04-13 06:39:07 -0700254 vlib_cli_output (vm, "%U%-25v%-10u", format_stream_session, s, 1,
255 app_name, s->session_index);
256 vec_free (app_name);
257 }));
258 /* *INDENT-ON* */
Florin Corasdbd44562017-11-09 19:30:17 -0800259 return 0;
260 }
261
Dave Barach68b0fb02017-02-28 15:15:56 -0500262 for (i = 0; i < vec_len (smm->sessions); i++)
263 {
264 u32 once_per_pool;
265 pool = smm->sessions[i];
266
267 once_per_pool = 1;
268
269 if (pool_elts (pool))
270 {
271
272 vlib_cli_output (vm, "Thread %d: %d active sessions",
273 i, pool_elts (pool));
274 if (verbose)
275 {
Florin Corasbb292f42017-05-19 09:49:19 -0700276 if (once_per_pool && verbose == 1)
Dave Barach68b0fb02017-02-28 15:15:56 -0500277 {
Florin Corasc87c91d2017-08-16 19:55:49 -0700278 str = format (str, "%-50s%-15s%-10s%-10s%-10s",
279 "Connection", "State", "Rx-f", "Tx-f",
280 "S-idx");
Dave Barach68b0fb02017-02-28 15:15:56 -0500281 vlib_cli_output (vm, "%v", str);
282 vec_reset_length (str);
283 once_per_pool = 0;
284 }
285
286 /* *INDENT-OFF* */
287 pool_foreach (s, pool,
288 ({
Florin Corasbb292f42017-05-19 09:49:19 -0700289 vec_reset_length (str);
290 str = format (str, "%U", format_stream_session, s, verbose);
Florin Corasbb292f42017-05-19 09:49:19 -0700291 vlib_cli_output (vm, "%v", str);
Dave Barach68b0fb02017-02-28 15:15:56 -0500292 }));
293 /* *INDENT-ON* */
294 }
295 }
296 else
297 vlib_cli_output (vm, "Thread %d: no active sessions", i);
Dave Barach2c25a622017-06-26 11:35:07 -0400298 vec_reset_length (str);
Dave Barach68b0fb02017-02-28 15:15:56 -0500299 }
300 vec_free (str);
301
302 return 0;
303}
304
Florin Corase04c2992017-03-01 08:17:34 -0800305/* *INDENT-OFF* */
Florin Coras66b11312017-07-31 17:18:03 -0700306VLIB_CLI_COMMAND (vlib_cli_show_session_command) =
Dave Barach68b0fb02017-02-28 15:15:56 -0500307{
Florin Corase04c2992017-03-01 08:17:34 -0800308 .path = "show session",
rootc9d1c5b2017-08-15 12:58:31 -0400309 .short_help = "show session [verbose [nnn]]",
Florin Corase04c2992017-03-01 08:17:34 -0800310 .function = show_session_command_fn,
311};
312/* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -0500313
Dave Barach2c25a622017-06-26 11:35:07 -0400314static int
315clear_session (stream_session_t * s)
316{
Florin Coras15531972018-08-12 23:50:53 -0700317 app_worker_t *server_wrk = app_worker_get (s->app_wrk_index);
318 application_t *server = application_get (server_wrk->app_index);
Dave Barach2c25a622017-06-26 11:35:07 -0400319 server->cb_fns.session_disconnect_callback (s);
320 return 0;
321}
322
Dave Barach68b0fb02017-02-28 15:15:56 -0500323static clib_error_t *
324clear_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
325 vlib_cli_command_t * cmd)
326{
327 session_manager_main_t *smm = &session_manager_main;
Dave Barach2c25a622017-06-26 11:35:07 -0400328 u32 thread_index = 0, clear_all = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500329 u32 session_index = ~0;
Dave Barach2c25a622017-06-26 11:35:07 -0400330 stream_session_t **pool, *session;
Dave Barach68b0fb02017-02-28 15:15:56 -0500331
Florin Corase04c2992017-03-01 08:17:34 -0800332 if (!smm->is_enabled)
333 {
flyingeagle23e2125062017-04-20 20:01:14 +0800334 return clib_error_return (0, "session layer is not enabled");
Florin Corase04c2992017-03-01 08:17:34 -0800335 }
336
Dave Barach68b0fb02017-02-28 15:15:56 -0500337 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
338 {
339 if (unformat (input, "thread %d", &thread_index))
340 ;
341 else if (unformat (input, "session %d", &session_index))
342 ;
Dave Barach2c25a622017-06-26 11:35:07 -0400343 else if (unformat (input, "all"))
344 clear_all = 1;
Dave Barach68b0fb02017-02-28 15:15:56 -0500345 else
346 return clib_error_return (0, "unknown input `%U'",
347 format_unformat_error, input);
348 }
349
Dave Barach2c25a622017-06-26 11:35:07 -0400350 if (!clear_all && session_index == ~0)
Dave Barach68b0fb02017-02-28 15:15:56 -0500351 return clib_error_return (0, "session <nn> required, but not set.");
352
Dave Barach2c25a622017-06-26 11:35:07 -0400353 if (session_index != ~0)
354 {
Florin Coras3cbc04b2017-10-02 00:18:51 -0700355 session = session_get_if_valid (session_index, thread_index);
Dave Barach2c25a622017-06-26 11:35:07 -0400356 if (!session)
357 return clib_error_return (0, "no session %d on thread %d",
358 session_index, thread_index);
359 clear_session (session);
360 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500361
Dave Barach2c25a622017-06-26 11:35:07 -0400362 if (clear_all)
363 {
364 /* *INDENT-OFF* */
365 vec_foreach (pool, smm->sessions)
366 {
367 pool_foreach(session, *pool, ({
368 clear_session (session);
369 }));
370 };
371 /* *INDENT-ON* */
372 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500373
374 return 0;
375}
376
Florin Corase04c2992017-03-01 08:17:34 -0800377/* *INDENT-OFF* */
378VLIB_CLI_COMMAND (clear_session_command, static) =
Dave Barach68b0fb02017-02-28 15:15:56 -0500379{
Florin Corase04c2992017-03-01 08:17:34 -0800380 .path = "clear session",
381 .short_help = "clear session thread <thread> session <index>",
382 .function = clear_session_command_fn,
383};
384/* *INDENT-ON* */
385
386static clib_error_t *
Florin Coras3eb50622017-07-13 01:24:57 -0400387show_session_fifo_trace_command_fn (vlib_main_t * vm,
388 unformat_input_t * input,
389 vlib_cli_command_t * cmd)
390{
391 stream_session_t *s = 0;
392 u8 is_rx = 0, *str = 0;
393
394 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
395 {
396 if (unformat (input, "%U", unformat_stream_session, &s))
397 ;
398 else if (unformat (input, "rx"))
399 is_rx = 1;
400 else if (unformat (input, "tx"))
401 is_rx = 0;
402 else
403 return clib_error_return (0, "unknown input `%U'",
404 format_unformat_error, input);
405 }
406
407 if (!SVM_FIFO_TRACE)
408 {
409 vlib_cli_output (vm, "fifo tracing not enabled");
410 return 0;
411 }
412
413 if (!s)
414 {
415 vlib_cli_output (vm, "could not find session");
416 return 0;
417 }
418
419 str = is_rx ?
420 svm_fifo_dump_trace (str, s->server_rx_fifo) :
421 svm_fifo_dump_trace (str, s->server_tx_fifo);
422
423 vlib_cli_output (vm, "%v", str);
424 return 0;
425}
426
427/* *INDENT-OFF* */
428VLIB_CLI_COMMAND (show_session_fifo_trace_command, static) =
429{
430 .path = "show session fifo trace",
431 .short_help = "show session fifo trace <session>",
432 .function = show_session_fifo_trace_command_fn,
433};
434/* *INDENT-ON* */
435
436static clib_error_t *
437session_replay_fifo_command_fn (vlib_main_t * vm, unformat_input_t * input,
438 vlib_cli_command_t * cmd)
439{
440 stream_session_t *s = 0;
441 u8 is_rx = 0, *str = 0;
442
443 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
444 {
445 if (unformat (input, "%U", unformat_stream_session, &s))
446 ;
447 else if (unformat (input, "rx"))
448 is_rx = 1;
449 else
450 return clib_error_return (0, "unknown input `%U'",
451 format_unformat_error, input);
452 }
453
454 if (!SVM_FIFO_TRACE)
455 {
456 vlib_cli_output (vm, "fifo tracing not enabled");
457 return 0;
458 }
459
460 if (!s)
461 {
462 vlib_cli_output (vm, "could not find session");
463 return 0;
464 }
465
466 str = is_rx ?
467 svm_fifo_replay (str, s->server_rx_fifo, 0, 1) :
468 svm_fifo_replay (str, s->server_tx_fifo, 0, 1);
469
470 vlib_cli_output (vm, "%v", str);
471 return 0;
472}
473
474/* *INDENT-OFF* */
475VLIB_CLI_COMMAND (session_replay_fifo_trace_command, static) =
476{
477 .path = "session replay fifo",
478 .short_help = "session replay fifo <session>",
479 .function = session_replay_fifo_command_fn,
480};
481/* *INDENT-ON* */
482
483static clib_error_t *
Florin Corase04c2992017-03-01 08:17:34 -0800484session_enable_disable_fn (vlib_main_t * vm, unformat_input_t * input,
485 vlib_cli_command_t * cmd)
486{
Dave Wallace8af20542017-10-26 03:29:30 -0400487 unformat_input_t _line_input, *line_input = &_line_input;
Florin Corase04c2992017-03-01 08:17:34 -0800488 u8 is_en = 1;
Dave Wallace8af20542017-10-26 03:29:30 -0400489 clib_error_t *error;
Florin Corase04c2992017-03-01 08:17:34 -0800490
Dave Wallace8af20542017-10-26 03:29:30 -0400491 if (!unformat_user (input, unformat_line_input, line_input))
Swarup Nayak82d8ec22017-12-04 11:54:43 +0530492 return clib_error_return (0, "expected enable | disable");
Dave Wallace8af20542017-10-26 03:29:30 -0400493
494 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Florin Corase04c2992017-03-01 08:17:34 -0800495 {
Dave Wallace8af20542017-10-26 03:29:30 -0400496 if (unformat (line_input, "enable"))
Florin Corase04c2992017-03-01 08:17:34 -0800497 is_en = 1;
Dave Wallace8af20542017-10-26 03:29:30 -0400498 else if (unformat (line_input, "disable"))
Florin Corase04c2992017-03-01 08:17:34 -0800499 is_en = 0;
500 else
Dave Wallace8af20542017-10-26 03:29:30 -0400501 {
502 error = clib_error_return (0, "unknown input `%U'",
503 format_unformat_error, line_input);
504 unformat_free (line_input);
505 return error;
506 }
Florin Corase04c2992017-03-01 08:17:34 -0800507 }
508
Dave Wallace8af20542017-10-26 03:29:30 -0400509 unformat_free (line_input);
Florin Corase04c2992017-03-01 08:17:34 -0800510 return vnet_session_enable_disable (vm, is_en);
511}
512
513/* *INDENT-OFF* */
514VLIB_CLI_COMMAND (session_enable_disable_command, static) =
515{
516 .path = "session",
517 .short_help = "session [enable|disable]",
518 .function = session_enable_disable_fn,
519};
520/* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -0500521
522/*
523 * fd.io coding-style-patch-verification: ON
524 *
525 * Local Variables:
526 * eval: (c-set-style "gnu")
527 * End:
528 */