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_error_strings[] = {
42 #define _(sym,string) string,
43 foreach_ip_punt_policer_error
47 VLIB_NODE_FN (ip6_punt_policer_node) (vlib_main_t * vm,
48 vlib_node_runtime_t * node,
51 return (ip_punt_policer (vm, node, frame,
52 vnet_feat_arc_ip6_punt.feature_arc_index,
53 ip6_punt_policer_cfg.policer_index));
59 VLIB_REGISTER_NODE (ip6_punt_policer_node) = {
60 .name = "ip6-punt-policer",
61 .vector_size = sizeof (u32),
62 .n_next_nodes = IP_PUNT_POLICER_N_NEXT,
63 .format_trace = format_ip_punt_policer_trace,
64 .n_errors = ARRAY_LEN(ip6_punt_policer_error_strings),
65 .error_strings = ip6_punt_policer_error_strings,
67 /* edit / add dispositions here */
69 [IP_PUNT_POLICER_NEXT_DROP] = "ip6-drop",
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")
80 VLIB_NODE_FN (ip6_drop_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
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);
91 VLIB_NODE_FN (ip6_not_enabled_node) (vlib_main_t * vm,
92 vlib_node_runtime_t * node,
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);
103 VLIB_NODE_FN (ip6_punt_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
104 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) =
117 .vector_size = sizeof (u32),
118 .format_trace = format_ip6_forward_next_trace,
125 VLIB_REGISTER_NODE (ip6_not_enabled_node) =
127 .name = "ip6-not-enabled",
128 .vector_size = sizeof (u32),
129 .format_trace = format_ip6_forward_next_trace,
136 VLIB_REGISTER_NODE (ip6_punt_node) =
139 .vector_size = sizeof (u32),
140 .format_trace = format_ip6_forward_next_trace,
147 VNET_FEATURE_INIT (ip6_punt_end_of_arc, static) = {
148 .arc_name = "ip6-punt",
149 .node_name = "error-punt",
150 .runs_before = 0, /* not before any other features */
153 VNET_FEATURE_INIT (ip6_drop_end_of_arc, static) = {
154 .arc_name = "ip6-drop",
155 .node_name = "error-drop",
156 .runs_before = 0, /* not before any other features */
160 #ifndef CLIB_MARCH_VARIANT
162 ip6_punt_policer_add_del (u8 is_add, u32 policer_index)
164 ip6_punt_policer_cfg.policer_index = policer_index;
166 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-policer",
169 #endif /* CLIB_MARCH_VARIANT */
171 static clib_error_t *
172 ip6_punt_police_cmd (vlib_main_t * vm,
173 unformat_input_t * main_input,
174 vlib_cli_command_t * cmd)
176 unformat_input_t _line_input, *line_input = &_line_input;
177 clib_error_t *error = 0;
183 if (!unformat_user (main_input, unformat_line_input, line_input))
186 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
188 if (unformat (line_input, "%d", &policer_index))
190 else if (unformat (line_input, "del"))
192 else if (unformat (line_input, "add"))
196 error = unformat_parse_error (line_input);
201 if (is_add && ~0 == policer_index)
203 error = clib_error_return (0, "expected policer index `%U'",
204 format_unformat_error, line_input);
210 ip6_punt_policer_add_del(is_add, policer_index);
213 unformat_free (line_input);
220 * @cliexcmd{set ip punt policer <INDEX>}
223 VLIB_CLI_COMMAND (ip6_punt_policer_command, static) =
225 .path = "ip6 punt policer",
226 .function = ip6_punt_police_cmd,
227 .short_help = "ip6 punt policer [add|del] <index>",
232 #define foreach_ip6_punt_redirect_error \
233 _(DROP, "ip6 punt redirect drop")
237 #define _(sym,str) IP6_PUNT_REDIRECT_ERROR_##sym,
238 foreach_ip6_punt_redirect_error
240 IP6_PUNT_REDIRECT_N_ERROR,
241 } ip6_punt_redirect_error_t;
243 static char *ip6_punt_redirect_error_strings[] = {
244 #define _(sym,string) string,
245 foreach_ip6_punt_redirect_error
249 VLIB_NODE_FN (ip6_punt_redirect_node) (vlib_main_t * vm,
250 vlib_node_runtime_t * node,
251 vlib_frame_t * frame)
253 return (ip_punt_redirect (vm, node, frame,
254 vnet_feat_arc_ip6_punt.feature_arc_index,
259 VLIB_REGISTER_NODE (ip6_punt_redirect_node) = {
260 .name = "ip6-punt-redirect",
261 .vector_size = sizeof (u32),
262 .n_next_nodes = IP_PUNT_REDIRECT_N_NEXT,
263 .format_trace = format_ip_punt_redirect_trace,
264 .n_errors = ARRAY_LEN(ip6_punt_redirect_error_strings),
265 .error_strings = ip6_punt_redirect_error_strings,
267 /* edit / add dispositions here */
269 [IP_PUNT_REDIRECT_NEXT_DROP] = "ip6-drop",
270 [IP_PUNT_REDIRECT_NEXT_TX] = "ip6-rewrite",
271 [IP_PUNT_REDIRECT_NEXT_ARP] = "ip6-discover-neighbor",
275 VNET_FEATURE_INIT (ip6_punt_redirect_node, static) = {
276 .arc_name = "ip6-punt",
277 .node_name = "ip6-punt-redirect",
278 .runs_before = VNET_FEATURES("error-punt")
282 #ifndef CLIB_MARCH_VARIANT
285 ip6_punt_redirect_add (u32 rx_sw_if_index,
286 u32 tx_sw_if_index, ip46_address_t * nh)
289 fib_route_path_t *rpaths = NULL, rpath = {
290 .frp_proto = DPO_PROTO_IP6,
292 .frp_sw_if_index = tx_sw_if_index,
297 vec_add1 (rpaths, rpath);
299 ip6_punt_redirect_add_paths (rx_sw_if_index, rpaths);
305 ip6_punt_redirect_add_paths (u32 rx_sw_if_index, fib_route_path_t * rpaths)
307 ip_punt_redirect_add (FIB_PROTOCOL_IP6,
309 FIB_FORW_CHAIN_TYPE_UNICAST_IP6, rpaths);
311 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 1, 0, 0);
315 ip6_punt_redirect_del (u32 rx_sw_if_index)
317 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 0, 0, 0);
319 ip_punt_redirect_del (FIB_PROTOCOL_IP6, rx_sw_if_index);
321 #endif /* CLIB_MARCH_VARIANT */
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 fib_route_path_t *rpaths = NULL, rpath;
330 dpo_proto_t payload_proto;
331 clib_error_t *error = 0;
332 u32 rx_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",
354 unformat_fib_route_path, &rpath, &payload_proto))
355 vec_add1 (rpaths, rpath);
358 error = unformat_parse_error (line_input);
363 if (~0 == rx_sw_if_index)
365 error = unformat_parse_error (line_input);
371 if (vec_len (rpaths))
372 ip6_punt_redirect_add_paths (rx_sw_if_index, rpaths);
376 ip6_punt_redirect_del (rx_sw_if_index);
380 unformat_free (line_input);
387 * @cliexcmd{set ip punt policer <INDEX>}
390 VLIB_CLI_COMMAND (ip6_punt_redirect_command, static) =
392 .path = "ip6 punt redirect",
393 .function = ip6_punt_redirect_cmd,
394 .short_help = "ip6 punt redirect [add|del] rx [<interface>|all] via [<nh>] <tx_interface>",
398 #ifndef CLIB_MARCH_VARIANT
400 #endif /* CLIB_MARCH_VARIANT */
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, FIB_PROTOCOL_IP6);
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")