2 * Copyright (c) 2016 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 <vlib/vlib.h>
17 #include <vppinfra/error.h>
18 #include <vnet/feature/feature.h>
20 #include <vnet/span/span.h>
23 span_add_delete_entry (vlib_main_t * vm,
24 u32 src_sw_if_index, u32 dst_sw_if_index, u8 is_add)
26 span_main_t *sm = &span_main;
28 if ((src_sw_if_index == ~0) || (dst_sw_if_index == ~0 && is_add)
29 || (src_sw_if_index == dst_sw_if_index))
30 return VNET_API_ERROR_INVALID_INTERFACE;
32 vnet_sw_interface_t *sw =
33 vnet_get_sw_interface (sm->vnet_main, src_sw_if_index);
35 vec_validate_aligned (sm->dst_by_src_sw_if_index, sw->sw_if_index,
36 CLIB_CACHE_LINE_BYTES);
37 sm->dst_by_src_sw_if_index[sw->sw_if_index] = is_add ? dst_sw_if_index : 0;
38 vnet_feature_enable_disable ("device-input", "span-input",
39 sw->sw_if_index, is_add, 0, 0);
44 set_interface_span_command_fn (vlib_main_t * vm,
45 unformat_input_t * input,
46 vlib_cli_command_t * cmd)
48 span_main_t *sm = &span_main;
49 u32 src_sw_if_index = ~0;
50 u32 dst_sw_if_index = ~0;
53 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
55 if (unformat (input, "%U", unformat_vnet_sw_interface,
56 sm->vnet_main, &src_sw_if_index))
58 else if (unformat (input, "destination %U", unformat_vnet_sw_interface,
59 sm->vnet_main, &dst_sw_if_index))
61 else if (unformat (input, "disable"))
68 span_add_delete_entry (vm, src_sw_if_index, dst_sw_if_index, is_add);
69 if (rv == VNET_API_ERROR_INVALID_INTERFACE)
70 return clib_error_return (0, "Invalid interface");
75 VLIB_CLI_COMMAND (set_interface_span_command, static) = {
76 .path = "set interface span",
77 .short_help = "set interface span <if-name> [disable | destination <if-name>]",
78 .function = set_interface_span_command_fn,
83 show_interfaces_span_command_fn (vlib_main_t * vm,
84 unformat_input_t * input,
85 vlib_cli_command_t * cmd)
88 span_main_t *sm = &span_main;
89 vnet_main_t *vnm = &vnet_main;
90 u32 src_sw_if_index = 0, *dst_sw_if_index;
93 vec_foreach (dst_sw_if_index, sm->dst_by_src_sw_if_index)
95 if (*dst_sw_if_index > 0) // && *dst_sw_if_index != ~0)
100 "SPAN source interface to destination interface table");
103 vlib_cli_output (vm, "%32U => %-32U",
104 format_vnet_sw_if_index_name, vnm, src_sw_if_index,
105 format_vnet_sw_if_index_name, vnm, *dst_sw_if_index);
113 VLIB_CLI_COMMAND (show_interfaces_span_command, static) = {
114 .path = "show interfaces span",
115 .short_help = "Shows SPAN mirror table",
116 .function = show_interfaces_span_command_fn,
120 static clib_error_t *
121 span_init (vlib_main_t * vm)
123 span_main_t *sm = &span_main;
126 sm->vnet_main = vnet_get_main ();
131 VLIB_INIT_FUNCTION (span_init);
134 * fd.io coding-style-patch-verification: ON
137 * eval: (c-set-style "gnu")