2 * Copyright (c) 2015 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 <vnet/ip/ip.h>
17 #include <vnet/ip/ip_punt_drop.h>
18 #include <vnet/policer/policer.h>
19 #include <vnet/policer/police_inlines.h>
22 VNET_FEATURE_ARC_INIT (ip6_punt) =
24 .arc_name = "ip6-punt",
25 .start_nodes = VNET_FEATURES ("ip6-punt"),
28 VNET_FEATURE_ARC_INIT (ip6_drop) =
30 .arc_name = "ip6-drop",
31 .start_nodes = VNET_FEATURES ("ip6-drop", "ip6-not-enabled"),
35 ip_punt_policer_t ip6_punt_policer_cfg;
37 static char *ip6_punt_policer_error_strings[] = {
38 #define _(sym,string) string,
39 foreach_ip_punt_policer_error
44 ip6_punt_policer (vlib_main_t * vm,
45 vlib_node_runtime_t * node, vlib_frame_t * frame)
47 return (ip_punt_policer (vm, node, frame,
48 vnet_feat_arc_ip6_punt.feature_arc_index,
49 ip6_punt_policer_cfg.policer_index));
55 VLIB_REGISTER_NODE (ip6_punt_policer_node, static) = {
56 .function = ip6_punt_policer,
57 .name = "ip6-punt-policer",
58 .vector_size = sizeof (u32),
59 .n_next_nodes = IP_PUNT_POLICER_N_NEXT,
60 .format_trace = format_ip_punt_policer_trace,
61 .n_errors = ARRAY_LEN(ip6_punt_policer_error_strings),
62 .error_strings = ip6_punt_policer_error_strings,
64 /* edit / add dispositions here */
66 [IP_PUNT_POLICER_NEXT_DROP] = "ip6-drop",
70 VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_policer_node,
73 VNET_FEATURE_INIT (ip6_punt_policer_node, static) = {
74 .arc_name = "ip6-punt",
75 .node_name = "ip6-punt-policer",
76 .runs_before = VNET_FEATURES("ip6-punt-redirect")
81 ip6_drop (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
83 if (node->flags & VLIB_NODE_FLAG_TRACE)
84 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
86 return ip_drop_or_punt (vm, node, frame,
87 vnet_feat_arc_ip6_drop.feature_arc_index);
92 ip6_not_enabled (vlib_main_t * vm,
93 vlib_node_runtime_t * node, vlib_frame_t * frame)
95 if (node->flags & VLIB_NODE_FLAG_TRACE)
96 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
98 return ip_drop_or_punt (vm, node, frame,
99 vnet_feat_arc_ip6_drop.feature_arc_index);
104 ip6_punt (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
106 if (node->flags & VLIB_NODE_FLAG_TRACE)
107 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
109 return ip_drop_or_punt (vm, node, frame,
110 vnet_feat_arc_ip6_punt.feature_arc_index);
114 VLIB_REGISTER_NODE (ip6_drop_node, static) =
116 .function = ip6_drop,
118 .vector_size = sizeof (u32),
119 .format_trace = format_ip6_forward_next_trace,
126 VLIB_NODE_FUNCTION_MULTIARCH (ip6_drop_node, ip6_drop);
128 VLIB_REGISTER_NODE (ip6_not_enabled_node, static) =
130 .function = ip6_not_enabled,
131 .name = "ip6-not-enabled",
132 .vector_size = sizeof (u32),
133 .format_trace = format_ip6_forward_next_trace,
140 VLIB_NODE_FUNCTION_MULTIARCH (ip6_not_enabled_node, ip6_not_enabled);
142 VLIB_REGISTER_NODE (ip6_punt_node, static) =
144 .function = ip6_punt,
146 .vector_size = sizeof (u32),
147 .format_trace = format_ip6_forward_next_trace,
154 VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_node, ip6_punt);
156 VNET_FEATURE_INIT (ip6_punt_end_of_arc, static) = {
157 .arc_name = "ip6-punt",
158 .node_name = "error-punt",
159 .runs_before = 0, /* not before any other features */
162 VNET_FEATURE_INIT (ip6_drop_end_of_arc, static) = {
163 .arc_name = "ip6-drop",
164 .node_name = "error-drop",
165 .runs_before = 0, /* not before any other features */
170 ip6_punt_policer_add_del (u8 is_add, u32 policer_index)
172 ip6_punt_policer_cfg.policer_index = policer_index;
174 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-policer",
178 static clib_error_t *
179 ip6_punt_police_cmd (vlib_main_t * vm,
180 unformat_input_t * main_input,
181 vlib_cli_command_t * cmd)
183 unformat_input_t _line_input, *line_input = &_line_input;
184 clib_error_t *error = 0;
190 if (!unformat_user (main_input, unformat_line_input, line_input))
193 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
195 if (unformat (line_input, "%d", &policer_index))
197 else if (unformat (line_input, "del"))
199 else if (unformat (line_input, "add"))
203 error = unformat_parse_error (line_input);
208 if (is_add && ~0 == policer_index)
210 error = clib_error_return (0, "expected policer index `%U'",
211 format_unformat_error, line_input);
217 ip6_punt_policer_add_del(is_add, policer_index);
220 unformat_free (line_input);
227 * @cliexcmd{set ip punt policer <INDEX>}
230 VLIB_CLI_COMMAND (ip6_punt_policer_command, static) =
232 .path = "ip6 punt policer",
233 .function = ip6_punt_police_cmd,
234 .short_help = "ip6 punt policer [add|del] <index>",
238 ip_punt_redirect_t ip6_punt_redirect_cfg = {
239 .any_rx_sw_if_index = {
240 .tx_sw_if_index = ~0,
241 .adj_index = ADJ_INDEX_INVALID,
246 #define foreach_ip6_punt_redirect_error \
247 _(DROP, "ip6 punt redirect drop")
251 #define _(sym,str) IP6_PUNT_REDIRECT_ERROR_##sym,
252 foreach_ip6_punt_redirect_error
254 IP6_PUNT_REDIRECT_N_ERROR,
255 } ip6_punt_redirect_error_t;
257 static char *ip6_punt_redirect_error_strings[] = {
258 #define _(sym,string) string,
259 foreach_ip6_punt_redirect_error
264 ip6_punt_redirect (vlib_main_t * vm,
265 vlib_node_runtime_t * node, vlib_frame_t * frame)
267 return (ip_punt_redirect (vm, node, frame,
268 vnet_feat_arc_ip6_punt.feature_arc_index,
269 &ip6_punt_redirect_cfg));
273 VLIB_REGISTER_NODE (ip6_punt_redirect_node, static) = {
274 .function = ip6_punt_redirect,
275 .name = "ip6-punt-redirect",
276 .vector_size = sizeof (u32),
277 .n_next_nodes = IP_PUNT_REDIRECT_N_NEXT,
278 .format_trace = format_ip_punt_redirect_trace,
279 .n_errors = ARRAY_LEN(ip6_punt_redirect_error_strings),
280 .error_strings = ip6_punt_redirect_error_strings,
282 /* edit / add dispositions here */
284 [IP_PUNT_REDIRECT_NEXT_DROP] = "ip6-drop",
285 [IP_PUNT_REDIRECT_NEXT_TX] = "ip6-rewrite",
286 [IP_PUNT_REDIRECT_NEXT_ARP] = "ip6-discover-neighbor",
290 VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_redirect_node,
293 VNET_FEATURE_INIT (ip6_punt_redirect_node, static) = {
294 .arc_name = "ip6-punt",
295 .node_name = "ip6-punt-redirect",
296 .runs_before = VNET_FEATURES("error-punt")
301 ip6_punt_redirect_add (u32 rx_sw_if_index,
302 u32 tx_sw_if_index, ip46_address_t * nh)
304 ip_punt_redirect_rx_t rx = {
305 .tx_sw_if_index = tx_sw_if_index,
309 ip_punt_redirect_add (&ip6_punt_redirect_cfg,
310 rx_sw_if_index, &rx, FIB_PROTOCOL_IP6, VNET_LINK_IP6);
312 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 1, 0, 0);
316 ip6_punt_redirect_del (u32 rx_sw_if_index)
318 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 0, 0, 0);
320 ip_punt_redirect_del (&ip6_punt_redirect_cfg, rx_sw_if_index);
323 static clib_error_t *
324 ip6_punt_redirect_cmd (vlib_main_t * vm,
325 unformat_input_t * main_input,
326 vlib_cli_command_t * cmd)
328 unformat_input_t _line_input, *line_input = &_line_input;
329 clib_error_t *error = 0;
330 u32 rx_sw_if_index = 0;
331 u32 tx_sw_if_index = 0;
337 vnm = vnet_get_main ();
339 if (!unformat_user (main_input, unformat_line_input, line_input))
342 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
344 if (unformat (line_input, "del"))
346 else if (unformat (line_input, "add"))
348 else if (unformat (line_input, "rx all"))
350 else if (unformat (line_input, "rx %U",
351 unformat_vnet_sw_interface, vnm, &rx_sw_if_index))
353 else if (unformat (line_input, "via %U %U",
354 unformat_ip6_address,
356 unformat_vnet_sw_interface, vnm, &tx_sw_if_index))
358 else if (unformat (line_input, "via %U",
359 unformat_vnet_sw_interface, vnm, &tx_sw_if_index))
360 memset (&nh, 0, sizeof (nh));
363 error = unformat_parse_error (line_input);
370 if (rx_sw_if_index && tx_sw_if_index)
372 ip6_punt_redirect_add (rx_sw_if_index, tx_sw_if_index, &nh);
379 ip6_punt_redirect_del (rx_sw_if_index);
384 unformat_free (line_input);
391 * @cliexcmd{set ip punt policer <INDEX>}
394 VLIB_CLI_COMMAND (ip6_punt_redirect_command, static) =
396 .path = "ip6 punt redirect",
397 .function = ip6_punt_redirect_cmd,
398 .short_help = "ip6 punt redirect [add|del] rx [<interface>|all] via [<nh>] <tx_interface>",
402 static clib_error_t *
403 ip6_punt_redirect_show_cmd (vlib_main_t * vm,
404 unformat_input_t * main_input,
405 vlib_cli_command_t * cmd)
407 vlib_cli_output (vm, "%U", format_ip_punt_redirect, &ip6_punt_redirect_cfg);
415 * @cliexcmd{set ip punt policer <INDEX>}
418 VLIB_CLI_COMMAND (show_ip6_punt_redirect_command, static) =
420 .path = "show ip6 punt redirect",
421 .function = ip6_punt_redirect_show_cmd,
422 .short_help = "show ip6 punt redirect",
428 * fd.io coding-style-patch-verification: ON
431 * eval: (c-set-style "gnu")