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>",
230 extern ip_punt_redirect_t ip6_punt_redirect_cfg;
232 #ifndef CLIB_MARCH_VARIANT
233 ip_punt_redirect_t ip6_punt_redirect_cfg = {
234 .any_rx_sw_if_index = {
235 .tx_sw_if_index = ~0,
236 .adj_index = ADJ_INDEX_INVALID,
239 #endif /* CLIB_MARCH_VARIANT */
242 #define foreach_ip6_punt_redirect_error \
243 _(DROP, "ip6 punt redirect drop")
247 #define _(sym,str) IP6_PUNT_REDIRECT_ERROR_##sym,
248 foreach_ip6_punt_redirect_error
250 IP6_PUNT_REDIRECT_N_ERROR,
251 } ip6_punt_redirect_error_t;
253 static char *ip6_punt_redirect_error_strings[] = {
254 #define _(sym,string) string,
255 foreach_ip6_punt_redirect_error
259 VLIB_NODE_FN (ip6_punt_redirect_node) (vlib_main_t * vm,
260 vlib_node_runtime_t * node,
261 vlib_frame_t * frame)
263 return (ip_punt_redirect (vm, node, frame,
264 vnet_feat_arc_ip6_punt.feature_arc_index,
265 &ip6_punt_redirect_cfg));
269 VLIB_REGISTER_NODE (ip6_punt_redirect_node) = {
270 .name = "ip6-punt-redirect",
271 .vector_size = sizeof (u32),
272 .n_next_nodes = IP_PUNT_REDIRECT_N_NEXT,
273 .format_trace = format_ip_punt_redirect_trace,
274 .n_errors = ARRAY_LEN(ip6_punt_redirect_error_strings),
275 .error_strings = ip6_punt_redirect_error_strings,
277 /* edit / add dispositions here */
279 [IP_PUNT_REDIRECT_NEXT_DROP] = "ip6-drop",
280 [IP_PUNT_REDIRECT_NEXT_TX] = "ip6-rewrite",
281 [IP_PUNT_REDIRECT_NEXT_ARP] = "ip6-discover-neighbor",
285 VNET_FEATURE_INIT (ip6_punt_redirect_node, static) = {
286 .arc_name = "ip6-punt",
287 .node_name = "ip6-punt-redirect",
288 .runs_before = VNET_FEATURES("error-punt")
292 #ifndef CLIB_MARCH_VARIANT
294 ip6_punt_redirect_add (u32 rx_sw_if_index,
295 u32 tx_sw_if_index, ip46_address_t * nh)
297 ip_punt_redirect_rx_t rx = {
298 .tx_sw_if_index = tx_sw_if_index,
302 ip_punt_redirect_add (&ip6_punt_redirect_cfg,
303 rx_sw_if_index, &rx, FIB_PROTOCOL_IP6, VNET_LINK_IP6);
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 vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 0, 0, 0);
313 ip_punt_redirect_del (&ip6_punt_redirect_cfg, rx_sw_if_index);
315 #endif /* CLIB_MARCH_VARIANT */
317 static clib_error_t *
318 ip6_punt_redirect_cmd (vlib_main_t * vm,
319 unformat_input_t * main_input,
320 vlib_cli_command_t * cmd)
322 unformat_input_t _line_input, *line_input = &_line_input;
323 clib_error_t *error = 0;
324 u32 rx_sw_if_index = 0;
325 u32 tx_sw_if_index = 0;
331 vnm = vnet_get_main ();
333 if (!unformat_user (main_input, unformat_line_input, line_input))
336 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
338 if (unformat (line_input, "del"))
340 else if (unformat (line_input, "add"))
342 else if (unformat (line_input, "rx all"))
344 else if (unformat (line_input, "rx %U",
345 unformat_vnet_sw_interface, vnm, &rx_sw_if_index))
347 else if (unformat (line_input, "via %U %U",
348 unformat_ip6_address,
350 unformat_vnet_sw_interface, vnm, &tx_sw_if_index))
352 else if (unformat (line_input, "via %U",
353 unformat_vnet_sw_interface, vnm, &tx_sw_if_index))
354 clib_memset (&nh, 0, sizeof (nh));
357 error = unformat_parse_error (line_input);
364 if (rx_sw_if_index && tx_sw_if_index)
366 ip6_punt_redirect_add (rx_sw_if_index, tx_sw_if_index, &nh);
373 ip6_punt_redirect_del (rx_sw_if_index);
378 unformat_free (line_input);
385 * @cliexcmd{set ip punt policer <INDEX>}
388 VLIB_CLI_COMMAND (ip6_punt_redirect_command, static) =
390 .path = "ip6 punt redirect",
391 .function = ip6_punt_redirect_cmd,
392 .short_help = "ip6 punt redirect [add|del] rx [<interface>|all] via [<nh>] <tx_interface>",
396 #ifndef CLIB_MARCH_VARIANT
397 ip_punt_redirect_detail_t *
398 ip6_punt_redirect_entries (u32 sw_if_index)
400 ip_punt_redirect_rx_t *pr;
401 ip_punt_redirect_detail_t *prs = 0;
404 vec_foreach_index (rx_sw_if_index,
405 ip6_punt_redirect_cfg.redirect_by_rx_sw_if_index)
407 if (sw_if_index == ~0 || sw_if_index == rx_sw_if_index)
410 &ip6_punt_redirect_cfg.redirect_by_rx_sw_if_index[rx_sw_if_index];
411 if (NULL != pr && ~0 != pr->tx_sw_if_index)
413 ip_punt_redirect_detail_t detail = {.rx_sw_if_index =
417 vec_add1 (prs, detail);
421 if (~0 != ip6_punt_redirect_cfg.any_rx_sw_if_index.tx_sw_if_index)
423 pr = &ip6_punt_redirect_cfg.any_rx_sw_if_index;
426 ip_punt_redirect_detail_t detail = {.rx_sw_if_index =
430 vec_add1 (prs, detail);
436 #endif /* CLIB_MARCH_VARIANT */
438 static clib_error_t *
439 ip6_punt_redirect_show_cmd (vlib_main_t * vm,
440 unformat_input_t * main_input,
441 vlib_cli_command_t * cmd)
443 vlib_cli_output (vm, "%U", format_ip_punt_redirect, &ip6_punt_redirect_cfg);
451 * @cliexcmd{set ip punt policer <INDEX>}
454 VLIB_CLI_COMMAND (show_ip6_punt_redirect_command, static) =
456 .path = "show ip6 punt redirect",
457 .function = ip6_punt_redirect_show_cmd,
458 .short_help = "show ip6 punt redirect",
464 * fd.io coding-style-patch-verification: ON
467 * eval: (c-set-style "gnu")