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>
21 VNET_FEATURE_ARC_INIT (ip6_punt) =
23 .arc_name = "ip6-punt",
24 .start_nodes = VNET_FEATURES ("ip6-punt"),
27 VNET_FEATURE_ARC_INIT (ip6_drop) =
29 .arc_name = "ip6-drop",
30 .start_nodes = VNET_FEATURES ("ip6-drop", "ip6-not-enabled"),
33 extern ip_punt_policer_t ip6_punt_policer_cfg;
35 #ifndef CLIB_MARCH_VARIANT
36 ip_punt_policer_t ip6_punt_policer_cfg;
37 #endif /* CLIB_MARCH_VARIANT */
39 static char *ip6_punt_policer_handoff_error_strings[] = { "congestion drop" };
41 VLIB_NODE_FN (ip6_punt_policer_handoff_node)
42 (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
44 return policer_handoff (vm, node, frame, ip6_punt_policer_cfg.fq_index,
45 ip6_punt_policer_cfg.policer_index);
48 VLIB_REGISTER_NODE (ip6_punt_policer_handoff_node) = {
49 .name = "ip6-punt-policer-handoff",
50 .vector_size = sizeof (u32),
51 .format_trace = format_policer_handoff_trace,
52 .type = VLIB_NODE_TYPE_INTERNAL,
53 .n_errors = ARRAY_LEN(ip6_punt_policer_handoff_error_strings),
54 .error_strings = ip6_punt_policer_handoff_error_strings,
62 static char *ip6_punt_policer_error_strings[] = {
63 #define _(sym,string) string,
64 foreach_ip_punt_policer_error
68 VLIB_NODE_FN (ip6_punt_policer_node) (vlib_main_t * vm,
69 vlib_node_runtime_t * node,
72 return (ip_punt_policer (vm, node, frame,
73 vnet_feat_arc_ip6_punt.feature_arc_index,
74 ip6_punt_policer_cfg.policer_index));
79 VLIB_REGISTER_NODE (ip6_punt_policer_node) = {
80 .name = "ip6-punt-policer",
81 .vector_size = sizeof (u32),
82 .n_next_nodes = IP_PUNT_POLICER_N_NEXT,
83 .format_trace = format_ip_punt_policer_trace,
84 .n_errors = ARRAY_LEN(ip6_punt_policer_error_strings),
85 .error_strings = ip6_punt_policer_error_strings,
87 /* edit / add dispositions here */
89 [IP_PUNT_POLICER_NEXT_DROP] = "ip6-drop",
90 [IP_PUNT_POLICER_NEXT_HANDOFF] = "ip6-punt-policer-handoff",
94 VNET_FEATURE_INIT (ip6_punt_policer_node, static) = {
95 .arc_name = "ip6-punt",
96 .node_name = "ip6-punt-policer",
97 .runs_before = VNET_FEATURES("ip6-punt-redirect")
100 VLIB_NODE_FN (ip6_drop_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
101 vlib_frame_t * frame)
103 if (node->flags & VLIB_NODE_FLAG_TRACE)
104 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
106 return ip_drop_or_punt (vm, node, frame,
107 vnet_feat_arc_ip6_drop.feature_arc_index);
111 VLIB_NODE_FN (ip6_not_enabled_node) (vlib_main_t * vm,
112 vlib_node_runtime_t * node,
113 vlib_frame_t * frame)
115 if (node->flags & VLIB_NODE_FLAG_TRACE)
116 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
118 return ip_drop_or_punt (vm, node, frame,
119 vnet_feat_arc_ip6_drop.feature_arc_index);
123 VLIB_NODE_FN (ip6_punt_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
124 vlib_frame_t * frame)
126 if (node->flags & VLIB_NODE_FLAG_TRACE)
127 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
129 return ip_drop_or_punt (vm, node, frame,
130 vnet_feat_arc_ip6_punt.feature_arc_index);
133 VLIB_REGISTER_NODE (ip6_drop_node) =
136 .vector_size = sizeof (u32),
137 .format_trace = format_ip6_forward_next_trace,
144 VLIB_REGISTER_NODE (ip6_not_enabled_node) = {
145 .name = "ip6-not-enabled",
146 .vector_size = sizeof (u32),
147 .format_trace = format_ip6_forward_next_trace,
148 .sibling_of = "ip6-drop",
151 VLIB_REGISTER_NODE (ip6_punt_node) =
154 .vector_size = sizeof (u32),
155 .format_trace = format_ip6_forward_next_trace,
162 VNET_FEATURE_INIT (ip6_punt_end_of_arc, static) = {
163 .arc_name = "ip6-punt",
164 .node_name = "error-punt",
165 .runs_before = 0, /* not before any other features */
168 VNET_FEATURE_INIT (ip6_drop_end_of_arc, static) = {
169 .arc_name = "ip6-drop",
170 .node_name = "error-drop",
171 .runs_before = 0, /* not before any other features */
174 #ifndef CLIB_MARCH_VARIANT
176 ip6_punt_policer_add_del (u8 is_add, u32 policer_index)
178 ip6_punt_policer_cfg.policer_index = policer_index;
180 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-policer",
183 #endif /* CLIB_MARCH_VARIANT */
185 static clib_error_t *
186 ip6_punt_police_cmd (vlib_main_t * vm,
187 unformat_input_t * main_input,
188 vlib_cli_command_t * cmd)
190 unformat_input_t _line_input, *line_input = &_line_input;
191 clib_error_t *error = 0;
197 if (!unformat_user (main_input, unformat_line_input, line_input))
200 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
202 if (unformat (line_input, "%d", &policer_index))
204 else if (unformat (line_input, "del"))
206 else if (unformat (line_input, "add"))
210 error = unformat_parse_error (line_input);
215 if (is_add && ~0 == policer_index)
217 error = clib_error_return (0, "expected policer index `%U'",
218 format_unformat_error, line_input);
224 ip6_punt_policer_add_del(is_add, policer_index);
227 unformat_free (line_input);
234 * @cliexcmd{set ip punt policer <INDEX>}
236 VLIB_CLI_COMMAND (ip6_punt_policer_command, static) =
238 .path = "ip6 punt policer",
239 .function = ip6_punt_police_cmd,
240 .short_help = "ip6 punt policer [add|del] <index>",
244 #define foreach_ip6_punt_redirect_error \
245 _(DROP, "ip6 punt redirect drop")
249 #define _(sym,str) IP6_PUNT_REDIRECT_ERROR_##sym,
250 foreach_ip6_punt_redirect_error
252 IP6_PUNT_REDIRECT_N_ERROR,
253 } ip6_punt_redirect_error_t;
255 static char *ip6_punt_redirect_error_strings[] = {
256 #define _(sym,string) string,
257 foreach_ip6_punt_redirect_error
261 VLIB_NODE_FN (ip6_punt_redirect_node) (vlib_main_t * vm,
262 vlib_node_runtime_t * node,
263 vlib_frame_t * frame)
265 return (ip_punt_redirect (vm, node, frame,
266 vnet_feat_arc_ip6_punt.feature_arc_index,
270 VLIB_REGISTER_NODE (ip6_punt_redirect_node) = {
271 .name = "ip6-punt-redirect",
272 .vector_size = sizeof (u32),
273 .n_next_nodes = IP_PUNT_REDIRECT_N_NEXT,
274 .format_trace = format_ip_punt_redirect_trace,
275 .n_errors = ARRAY_LEN(ip6_punt_redirect_error_strings),
276 .error_strings = ip6_punt_redirect_error_strings,
278 /* edit / add dispositions here */
280 [IP_PUNT_REDIRECT_NEXT_DROP] = "ip6-drop",
281 [IP_PUNT_REDIRECT_NEXT_TX] = "ip6-rewrite",
282 [IP_PUNT_REDIRECT_NEXT_ARP] = "ip6-discover-neighbor",
286 VNET_FEATURE_INIT (ip6_punt_redirect_node, static) = {
287 .arc_name = "ip6-punt",
288 .node_name = "ip6-punt-redirect",
289 .runs_before = VNET_FEATURES("error-punt")
292 #ifndef CLIB_MARCH_VARIANT
294 static u32 ip6_punt_redirect_enable_counts;
297 ip6_punt_redirect_add_paths (u32 rx_sw_if_index,
298 const fib_route_path_t *rpaths)
300 ip_punt_redirect_add (FIB_PROTOCOL_IP6,
302 FIB_FORW_CHAIN_TYPE_UNICAST_IP6, rpaths);
304 if (1 == ++ip6_punt_redirect_enable_counts)
305 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 1, 0, 0);
309 ip6_punt_redirect_del (u32 rx_sw_if_index)
311 ASSERT (ip6_punt_redirect_enable_counts);
312 if (0 == --ip6_punt_redirect_enable_counts)
313 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 0, 0, 0);
315 ip_punt_redirect_del (FIB_PROTOCOL_IP6, rx_sw_if_index);
317 #endif /* CLIB_MARCH_VARIANT */
319 static clib_error_t *
320 ip6_punt_redirect_cmd (vlib_main_t * vm,
321 unformat_input_t * main_input,
322 vlib_cli_command_t * cmd)
324 unformat_input_t _line_input, *line_input = &_line_input;
325 fib_route_path_t *rpaths = NULL, rpath;
326 dpo_proto_t payload_proto = DPO_PROTO_IP6;
327 clib_error_t *error = 0;
328 u32 rx_sw_if_index = ~0;
333 vnm = vnet_get_main ();
335 if (!unformat_user (main_input, unformat_line_input, line_input))
338 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
340 if (unformat (line_input, "del"))
342 else if (unformat (line_input, "add"))
344 else if (unformat (line_input, "rx all"))
346 else if (unformat (line_input, "rx %U",
347 unformat_vnet_sw_interface, vnm, &rx_sw_if_index))
349 else if (unformat (line_input, "via %U",
350 unformat_fib_route_path, &rpath, &payload_proto))
351 vec_add1 (rpaths, rpath);
354 error = unformat_parse_error (line_input);
359 if (~0 == rx_sw_if_index)
361 error = unformat_parse_error (line_input);
367 if (vec_len (rpaths))
368 ip6_punt_redirect_add_paths (rx_sw_if_index, rpaths);
372 ip6_punt_redirect_del (rx_sw_if_index);
377 unformat_free (line_input);
384 * @cliexcmd{set ip punt policer <INDEX>}
386 VLIB_CLI_COMMAND (ip6_punt_redirect_command, static) =
388 .path = "ip6 punt redirect",
389 .function = ip6_punt_redirect_cmd,
390 .short_help = "ip6 punt redirect [add|del] rx [<interface>|all] via [<nh>] <tx_interface>",
393 #ifndef CLIB_MARCH_VARIANT
395 #endif /* CLIB_MARCH_VARIANT */
397 static clib_error_t *
398 ip6_punt_redirect_show_cmd (vlib_main_t * vm,
399 unformat_input_t * main_input,
400 vlib_cli_command_t * cmd)
402 vlib_cli_output (vm, "%U", format_ip_punt_redirect, FIB_PROTOCOL_IP6);
410 * @cliexcmd{set ip punt policer <INDEX>}
412 VLIB_CLI_COMMAND (show_ip6_punt_redirect_command, static) =
414 .path = "show ip6 punt redirect",
415 .function = ip6_punt_redirect_show_cmd,
416 .short_help = "show ip6 punt redirect",
421 * fd.io coding-style-patch-verification: ON
424 * eval: (c-set-style "gnu")