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 extern ip_punt_policer_t ip6_punt_policer_cfg;
37 #ifndef CLIB_MARCH_VARIANT
38 ip_punt_policer_t ip6_punt_policer_cfg;
39 #endif /* CLIB_MARCH_VARIANT */
41 static char *ip6_punt_policer_handoff_error_strings[] = { "congestion drop" };
43 VLIB_NODE_FN (ip6_punt_policer_handoff_node)
44 (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
46 return policer_handoff (vm, node, frame, ip6_punt_policer_cfg.fq_index,
47 ip6_punt_policer_cfg.policer_index);
50 VLIB_REGISTER_NODE (ip6_punt_policer_handoff_node) = {
51 .name = "ip6-punt-policer-handoff",
52 .vector_size = sizeof (u32),
53 .format_trace = format_policer_handoff_trace,
54 .type = VLIB_NODE_TYPE_INTERNAL,
55 .n_errors = ARRAY_LEN(ip6_punt_policer_handoff_error_strings),
56 .error_strings = ip6_punt_policer_handoff_error_strings,
64 static char *ip6_punt_policer_error_strings[] = {
65 #define _(sym,string) string,
66 foreach_ip_punt_policer_error
70 VLIB_NODE_FN (ip6_punt_policer_node) (vlib_main_t * vm,
71 vlib_node_runtime_t * node,
74 return (ip_punt_policer (vm, node, frame,
75 vnet_feat_arc_ip6_punt.feature_arc_index,
76 ip6_punt_policer_cfg.policer_index));
82 VLIB_REGISTER_NODE (ip6_punt_policer_node) = {
83 .name = "ip6-punt-policer",
84 .vector_size = sizeof (u32),
85 .n_next_nodes = IP_PUNT_POLICER_N_NEXT,
86 .format_trace = format_ip_punt_policer_trace,
87 .n_errors = ARRAY_LEN(ip6_punt_policer_error_strings),
88 .error_strings = ip6_punt_policer_error_strings,
90 /* edit / add dispositions here */
92 [IP_PUNT_POLICER_NEXT_DROP] = "ip6-drop",
93 [IP_PUNT_POLICER_NEXT_HANDOFF] = "ip6-punt-policer-handoff",
97 VNET_FEATURE_INIT (ip6_punt_policer_node, static) = {
98 .arc_name = "ip6-punt",
99 .node_name = "ip6-punt-policer",
100 .runs_before = VNET_FEATURES("ip6-punt-redirect")
104 VLIB_NODE_FN (ip6_drop_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
105 vlib_frame_t * frame)
107 if (node->flags & VLIB_NODE_FLAG_TRACE)
108 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
110 return ip_drop_or_punt (vm, node, frame,
111 vnet_feat_arc_ip6_drop.feature_arc_index);
115 VLIB_NODE_FN (ip6_not_enabled_node) (vlib_main_t * vm,
116 vlib_node_runtime_t * node,
117 vlib_frame_t * frame)
119 if (node->flags & VLIB_NODE_FLAG_TRACE)
120 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
122 return ip_drop_or_punt (vm, node, frame,
123 vnet_feat_arc_ip6_drop.feature_arc_index);
127 VLIB_NODE_FN (ip6_punt_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
128 vlib_frame_t * frame)
130 if (node->flags & VLIB_NODE_FLAG_TRACE)
131 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
133 return ip_drop_or_punt (vm, node, frame,
134 vnet_feat_arc_ip6_punt.feature_arc_index);
138 VLIB_REGISTER_NODE (ip6_drop_node) =
141 .vector_size = sizeof (u32),
142 .format_trace = format_ip6_forward_next_trace,
149 VLIB_REGISTER_NODE (ip6_not_enabled_node) = {
150 .name = "ip6-not-enabled",
151 .vector_size = sizeof (u32),
152 .format_trace = format_ip6_forward_next_trace,
153 .sibling_of = "ip6-drop",
156 VLIB_REGISTER_NODE (ip6_punt_node) =
159 .vector_size = sizeof (u32),
160 .format_trace = format_ip6_forward_next_trace,
167 VNET_FEATURE_INIT (ip6_punt_end_of_arc, static) = {
168 .arc_name = "ip6-punt",
169 .node_name = "error-punt",
170 .runs_before = 0, /* not before any other features */
173 VNET_FEATURE_INIT (ip6_drop_end_of_arc, static) = {
174 .arc_name = "ip6-drop",
175 .node_name = "error-drop",
176 .runs_before = 0, /* not before any other features */
180 #ifndef CLIB_MARCH_VARIANT
182 ip6_punt_policer_add_del (u8 is_add, u32 policer_index)
184 ip6_punt_policer_cfg.policer_index = policer_index;
186 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-policer",
189 #endif /* CLIB_MARCH_VARIANT */
191 static clib_error_t *
192 ip6_punt_police_cmd (vlib_main_t * vm,
193 unformat_input_t * main_input,
194 vlib_cli_command_t * cmd)
196 unformat_input_t _line_input, *line_input = &_line_input;
197 clib_error_t *error = 0;
203 if (!unformat_user (main_input, unformat_line_input, line_input))
206 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
208 if (unformat (line_input, "%d", &policer_index))
210 else if (unformat (line_input, "del"))
212 else if (unformat (line_input, "add"))
216 error = unformat_parse_error (line_input);
221 if (is_add && ~0 == policer_index)
223 error = clib_error_return (0, "expected policer index `%U'",
224 format_unformat_error, line_input);
230 ip6_punt_policer_add_del(is_add, policer_index);
233 unformat_free (line_input);
240 * @cliexcmd{set ip punt policer <INDEX>}
243 VLIB_CLI_COMMAND (ip6_punt_policer_command, static) =
245 .path = "ip6 punt policer",
246 .function = ip6_punt_police_cmd,
247 .short_help = "ip6 punt policer [add|del] <index>",
252 #define foreach_ip6_punt_redirect_error \
253 _(DROP, "ip6 punt redirect drop")
257 #define _(sym,str) IP6_PUNT_REDIRECT_ERROR_##sym,
258 foreach_ip6_punt_redirect_error
260 IP6_PUNT_REDIRECT_N_ERROR,
261 } ip6_punt_redirect_error_t;
263 static char *ip6_punt_redirect_error_strings[] = {
264 #define _(sym,string) string,
265 foreach_ip6_punt_redirect_error
269 VLIB_NODE_FN (ip6_punt_redirect_node) (vlib_main_t * vm,
270 vlib_node_runtime_t * node,
271 vlib_frame_t * frame)
273 return (ip_punt_redirect (vm, node, frame,
274 vnet_feat_arc_ip6_punt.feature_arc_index,
279 VLIB_REGISTER_NODE (ip6_punt_redirect_node) = {
280 .name = "ip6-punt-redirect",
281 .vector_size = sizeof (u32),
282 .n_next_nodes = IP_PUNT_REDIRECT_N_NEXT,
283 .format_trace = format_ip_punt_redirect_trace,
284 .n_errors = ARRAY_LEN(ip6_punt_redirect_error_strings),
285 .error_strings = ip6_punt_redirect_error_strings,
287 /* edit / add dispositions here */
289 [IP_PUNT_REDIRECT_NEXT_DROP] = "ip6-drop",
290 [IP_PUNT_REDIRECT_NEXT_TX] = "ip6-rewrite",
291 [IP_PUNT_REDIRECT_NEXT_ARP] = "ip6-discover-neighbor",
295 VNET_FEATURE_INIT (ip6_punt_redirect_node, static) = {
296 .arc_name = "ip6-punt",
297 .node_name = "ip6-punt-redirect",
298 .runs_before = VNET_FEATURES("error-punt")
302 #ifndef CLIB_MARCH_VARIANT
305 ip6_punt_redirect_add_paths (u32 rx_sw_if_index,
306 const fib_route_path_t *rpaths)
308 ip_punt_redirect_add (FIB_PROTOCOL_IP6,
310 FIB_FORW_CHAIN_TYPE_UNICAST_IP6, rpaths);
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 (FIB_PROTOCOL_IP6, rx_sw_if_index);
322 #endif /* CLIB_MARCH_VARIANT */
324 static clib_error_t *
325 ip6_punt_redirect_cmd (vlib_main_t * vm,
326 unformat_input_t * main_input,
327 vlib_cli_command_t * cmd)
329 unformat_input_t _line_input, *line_input = &_line_input;
330 fib_route_path_t *rpaths = NULL, rpath;
331 dpo_proto_t payload_proto = DPO_PROTO_IP6;
332 clib_error_t *error = 0;
333 u32 rx_sw_if_index = ~0;
338 vnm = vnet_get_main ();
340 if (!unformat_user (main_input, unformat_line_input, line_input))
343 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
345 if (unformat (line_input, "del"))
347 else if (unformat (line_input, "add"))
349 else if (unformat (line_input, "rx all"))
351 else if (unformat (line_input, "rx %U",
352 unformat_vnet_sw_interface, vnm, &rx_sw_if_index))
354 else if (unformat (line_input, "via %U",
355 unformat_fib_route_path, &rpath, &payload_proto))
356 vec_add1 (rpaths, rpath);
359 error = unformat_parse_error (line_input);
364 if (~0 == rx_sw_if_index)
366 error = unformat_parse_error (line_input);
372 if (vec_len (rpaths))
373 ip6_punt_redirect_add_paths (rx_sw_if_index, rpaths);
377 ip6_punt_redirect_del (rx_sw_if_index);
382 unformat_free (line_input);
389 * @cliexcmd{set ip punt policer <INDEX>}
392 VLIB_CLI_COMMAND (ip6_punt_redirect_command, static) =
394 .path = "ip6 punt redirect",
395 .function = ip6_punt_redirect_cmd,
396 .short_help = "ip6 punt redirect [add|del] rx [<interface>|all] via [<nh>] <tx_interface>",
400 #ifndef CLIB_MARCH_VARIANT
402 #endif /* CLIB_MARCH_VARIANT */
404 static clib_error_t *
405 ip6_punt_redirect_show_cmd (vlib_main_t * vm,
406 unformat_input_t * main_input,
407 vlib_cli_command_t * cmd)
409 vlib_cli_output (vm, "%U", format_ip_punt_redirect, FIB_PROTOCOL_IP6);
417 * @cliexcmd{set ip punt policer <INDEX>}
420 VLIB_CLI_COMMAND (show_ip6_punt_redirect_command, static) =
422 .path = "show ip6 punt redirect",
423 .function = ip6_punt_redirect_show_cmd,
424 .short_help = "show ip6 punt redirect",
430 * fd.io coding-style-patch-verification: ON
433 * eval: (c-set-style "gnu")