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"),
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_punt (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
94 if (node->flags & VLIB_NODE_FLAG_TRACE)
95 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
97 return ip_drop_or_punt (vm, node, frame,
98 vnet_feat_arc_ip6_punt.feature_arc_index);
102 VLIB_REGISTER_NODE (ip6_drop_node, static) =
104 .function = ip6_drop,
106 .vector_size = sizeof (u32),
107 .format_trace = format_ip6_forward_next_trace,
114 VLIB_NODE_FUNCTION_MULTIARCH (ip6_drop_node, ip6_drop);
116 VLIB_REGISTER_NODE (ip6_punt_node, static) =
118 .function = ip6_punt,
120 .vector_size = sizeof (u32),
121 .format_trace = format_ip6_forward_next_trace,
128 VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_node, ip6_punt);
130 VNET_FEATURE_INIT (ip6_punt_end_of_arc, static) = {
131 .arc_name = "ip6-punt",
132 .node_name = "error-punt",
133 .runs_before = 0, /* not before any other features */
136 VNET_FEATURE_INIT (ip6_drop_end_of_arc, static) = {
137 .arc_name = "ip6-drop",
138 .node_name = "error-drop",
139 .runs_before = 0, /* not before any other features */
144 ip6_punt_policer_add_del (u8 is_add, u32 policer_index)
146 ip6_punt_policer_cfg.policer_index = policer_index;
148 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-policer",
152 static clib_error_t *
153 ip6_punt_police_cmd (vlib_main_t * vm,
154 unformat_input_t * main_input,
155 vlib_cli_command_t * cmd)
157 unformat_input_t _line_input, *line_input = &_line_input;
158 clib_error_t *error = 0;
164 if (!unformat_user (main_input, unformat_line_input, line_input))
167 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
169 if (unformat (line_input, "%d", &policer_index))
171 else if (unformat (line_input, "del"))
173 else if (unformat (line_input, "add"))
177 error = unformat_parse_error (line_input);
182 if (is_add && ~0 == policer_index)
184 error = clib_error_return (0, "expected policer index `%U'",
185 format_unformat_error, line_input);
191 ip6_punt_policer_add_del(is_add, policer_index);
194 unformat_free (line_input);
201 * @cliexcmd{set ip punt policer <INDEX>}
204 VLIB_CLI_COMMAND (ip6_punt_policer_command, static) =
206 .path = "ip6 punt policer",
207 .function = ip6_punt_police_cmd,
208 .short_help = "ip6 punt policer [add|del] <index>",
212 ip_punt_redirect_t ip6_punt_redirect_cfg = {
213 .any_rx_sw_if_index = {
214 .tx_sw_if_index = ~0,
219 #define foreach_ip6_punt_redirect_error \
220 _(DROP, "ip6 punt redirect drop")
224 #define _(sym,str) IP6_PUNT_REDIRECT_ERROR_##sym,
225 foreach_ip6_punt_redirect_error
227 IP6_PUNT_REDIRECT_N_ERROR,
228 } ip6_punt_redirect_error_t;
230 static char *ip6_punt_redirect_error_strings[] = {
231 #define _(sym,string) string,
232 foreach_ip6_punt_redirect_error
237 ip6_punt_redirect (vlib_main_t * vm,
238 vlib_node_runtime_t * node, vlib_frame_t * frame)
240 return (ip_punt_redirect (vm, node, frame,
241 vnet_feat_arc_ip6_punt.feature_arc_index,
242 &ip6_punt_redirect_cfg));
246 VLIB_REGISTER_NODE (ip6_punt_redirect_node, static) = {
247 .function = ip6_punt_redirect,
248 .name = "ip6-punt-redirect",
249 .vector_size = sizeof (u32),
250 .n_next_nodes = IP_PUNT_REDIRECT_N_NEXT,
251 .format_trace = format_ip_punt_redirect_trace,
252 .n_errors = ARRAY_LEN(ip6_punt_redirect_error_strings),
253 .error_strings = ip6_punt_redirect_error_strings,
255 /* edit / add dispositions here */
257 [IP_PUNT_REDIRECT_NEXT_DROP] = "ip6-drop",
258 [IP_PUNT_REDIRECT_NEXT_TX] = "ip6-rewrite",
259 [IP_PUNT_REDIRECT_NEXT_ARP] = "ip6-discover-neighbor",
263 VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_redirect_node,
266 VNET_FEATURE_INIT (ip6_punt_redirect_node, static) = {
267 .arc_name = "ip6-punt",
268 .node_name = "ip6-punt-redirect",
269 .runs_before = VNET_FEATURES("error-punt")
274 ip6_punt_redirect_add (u32 rx_sw_if_index,
275 u32 tx_sw_if_index, ip46_address_t * nh)
277 ip_punt_redirect_rx_t rx = {
278 .tx_sw_if_index = tx_sw_if_index,
282 ip_punt_redirect_add (&ip6_punt_redirect_cfg,
283 rx_sw_if_index, &rx, FIB_PROTOCOL_IP6, VNET_LINK_IP6);
285 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 1, 0, 0);
289 ip6_punt_redirect_del (u32 rx_sw_if_index)
291 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 0, 0, 0);
293 ip_punt_redirect_del (&ip6_punt_redirect_cfg, rx_sw_if_index);
296 static clib_error_t *
297 ip6_punt_redirect_cmd (vlib_main_t * vm,
298 unformat_input_t * main_input,
299 vlib_cli_command_t * cmd)
301 unformat_input_t _line_input, *line_input = &_line_input;
302 clib_error_t *error = 0;
310 vnm = vnet_get_main ();
312 if (!unformat_user (main_input, unformat_line_input, line_input))
315 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
317 if (unformat (line_input, "del"))
319 else if (unformat (line_input, "add"))
321 else if (unformat (line_input, "rx all"))
323 else if (unformat (line_input, "rx %U",
324 unformat_vnet_sw_interface, vnm, &rx_sw_if_index))
326 else if (unformat (line_input, "via %U %U",
327 unformat_ip6_address,
329 unformat_vnet_sw_interface, vnm, &tx_sw_if_index))
331 else if (unformat (line_input, "via %U",
332 unformat_vnet_sw_interface, vnm, &tx_sw_if_index))
333 memset (&nh, 0, sizeof (nh));
336 error = unformat_parse_error (line_input);
342 ip6_punt_redirect_add (rx_sw_if_index, tx_sw_if_index, &nh);
344 ip6_punt_redirect_del (rx_sw_if_index);
347 unformat_free (line_input);
354 * @cliexcmd{set ip punt policer <INDEX>}
357 VLIB_CLI_COMMAND (ip6_punt_redirect_command, static) =
359 .path = "ip6 punt redirect",
360 .function = ip6_punt_redirect_cmd,
361 .short_help = "ip6 punt redirect [add|del] rx [<interface>|all] via [<nh>] <tx_interface>",
365 static clib_error_t *
366 ip6_punt_redirect_show_cmd (vlib_main_t * vm,
367 unformat_input_t * main_input,
368 vlib_cli_command_t * cmd)
370 vlib_cli_output (vm, "%U", format_ip_punt_redirect, &ip6_punt_redirect_cfg);
378 * @cliexcmd{set ip punt policer <INDEX>}
381 VLIB_CLI_COMMAND (show_ip6_punt_redirect_command, static) =
383 .path = "show ip6 punt redirect",
384 .function = ip6_punt_redirect_show_cmd,
385 .short_help = "show ip6 punt redirect [add|del] rx [<interface>|all] via [<nh>] <tx_interface>",
391 * fd.io coding-style-patch-verification: ON
394 * eval: (c-set-style "gnu")