Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1 | /* |
| 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: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 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. |
| 14 | */ |
| 15 | |
| 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> |
| 20 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 21 | VNET_FEATURE_ARC_INIT (ip4_punt) = |
| 22 | { |
| 23 | .arc_name = "ip4-punt", |
| 24 | .start_nodes = VNET_FEATURES ("ip4-punt"), |
| 25 | }; |
| 26 | |
| 27 | VNET_FEATURE_ARC_INIT (ip4_drop) = |
| 28 | { |
| 29 | .arc_name = "ip4-drop", |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 30 | .start_nodes = VNET_FEATURES ("ip4-drop", "ip4-not-enabled"), |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 31 | }; |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 32 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 33 | extern ip_punt_policer_t ip4_punt_policer_cfg; |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 34 | |
| 35 | #ifndef CLIB_MARCH_VARIANT |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 36 | u8 * |
| 37 | format_ip_punt_policer_trace (u8 * s, va_list * args) |
| 38 | { |
| 39 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 40 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 41 | ip_punt_policer_trace_t *t = va_arg (*args, ip_punt_policer_trace_t *); |
| 42 | |
| 43 | s = format (s, "policer_index %d next %d", t->policer_index, t->next); |
| 44 | return s; |
| 45 | } |
| 46 | |
| 47 | ip_punt_policer_t ip4_punt_policer_cfg = { |
| 48 | .policer_index = ~0, |
| 49 | }; |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 50 | #endif /* CLIB_MARCH_VARIANT */ |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 51 | |
Brian Russell | 1b2e16a | 2021-01-21 14:44:09 +0000 | [diff] [blame] | 52 | static char *ip4_punt_policer_handoff_error_strings[] = { "congestion drop" }; |
| 53 | |
| 54 | VLIB_NODE_FN (ip4_punt_policer_handoff_node) |
| 55 | (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) |
| 56 | { |
| 57 | return policer_handoff (vm, node, frame, ip4_punt_policer_cfg.fq_index, |
| 58 | ip4_punt_policer_cfg.policer_index); |
| 59 | } |
| 60 | |
| 61 | VLIB_REGISTER_NODE (ip4_punt_policer_handoff_node) = { |
| 62 | .name = "ip4-punt-policer-handoff", |
| 63 | .vector_size = sizeof (u32), |
| 64 | .format_trace = format_policer_handoff_trace, |
| 65 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 66 | .n_errors = ARRAY_LEN(ip4_punt_policer_handoff_error_strings), |
| 67 | .error_strings = ip4_punt_policer_handoff_error_strings, |
| 68 | |
| 69 | .n_next_nodes = 1, |
| 70 | .next_nodes = { |
| 71 | [0] = "error-drop", |
| 72 | }, |
| 73 | }; |
| 74 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 75 | static char *ip4_punt_policer_error_strings[] = { |
| 76 | #define _(sym,string) string, |
| 77 | foreach_ip_punt_policer_error |
| 78 | #undef _ |
| 79 | }; |
| 80 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 81 | VLIB_NODE_FN (ip4_punt_policer_node) (vlib_main_t * vm, |
| 82 | vlib_node_runtime_t * node, |
| 83 | vlib_frame_t * frame) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 84 | { |
| 85 | return (ip_punt_policer (vm, node, frame, |
| 86 | vnet_feat_arc_ip4_punt.feature_arc_index, |
| 87 | ip4_punt_policer_cfg.policer_index)); |
| 88 | } |
| 89 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 90 | VLIB_REGISTER_NODE (ip4_punt_policer_node) = { |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 91 | .name = "ip4-punt-policer", |
| 92 | .vector_size = sizeof (u32), |
| 93 | .n_next_nodes = IP_PUNT_POLICER_N_NEXT, |
| 94 | .format_trace = format_ip_punt_policer_trace, |
| 95 | .n_errors = ARRAY_LEN(ip4_punt_policer_error_strings), |
| 96 | .error_strings = ip4_punt_policer_error_strings, |
| 97 | |
| 98 | .next_nodes = { |
| 99 | [IP_PUNT_POLICER_NEXT_DROP] = "ip4-drop", |
Brian Russell | 1b2e16a | 2021-01-21 14:44:09 +0000 | [diff] [blame] | 100 | [IP_PUNT_POLICER_NEXT_HANDOFF] = "ip4-punt-policer-handoff", |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 101 | }, |
| 102 | }; |
| 103 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 104 | VNET_FEATURE_INIT (ip4_punt_policer_node) = { |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 105 | .arc_name = "ip4-punt", |
| 106 | .node_name = "ip4-punt-policer", |
| 107 | .runs_before = VNET_FEATURES("ip4-punt-redirect"), |
| 108 | }; |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 109 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 110 | |
| 111 | #define foreach_ip4_punt_redirect_error \ |
| 112 | _(DROP, "ip4 punt redirect drop") |
| 113 | |
| 114 | typedef enum |
| 115 | { |
| 116 | #define _(sym,str) IP4_PUNT_REDIRECT_ERROR_##sym, |
| 117 | foreach_ip4_punt_redirect_error |
| 118 | #undef _ |
| 119 | IP4_PUNT_REDIRECT_N_ERROR, |
| 120 | } ip4_punt_redirect_error_t; |
| 121 | |
| 122 | static char *ip4_punt_redirect_error_strings[] = { |
| 123 | #define _(sym,string) string, |
| 124 | foreach_ip4_punt_redirect_error |
| 125 | #undef _ |
| 126 | }; |
| 127 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 128 | VLIB_NODE_FN (ip4_punt_redirect_node) (vlib_main_t * vm, |
| 129 | vlib_node_runtime_t * node, |
| 130 | vlib_frame_t * frame) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 131 | { |
| 132 | return (ip_punt_redirect (vm, node, frame, |
| 133 | vnet_feat_arc_ip4_punt.feature_arc_index, |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 134 | FIB_PROTOCOL_IP4)); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 137 | VLIB_REGISTER_NODE (ip4_punt_redirect_node) = { |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 138 | .name = "ip4-punt-redirect", |
| 139 | .vector_size = sizeof (u32), |
| 140 | .n_next_nodes = IP_PUNT_REDIRECT_N_NEXT, |
| 141 | .format_trace = format_ip_punt_redirect_trace, |
| 142 | .n_errors = ARRAY_LEN(ip4_punt_redirect_error_strings), |
| 143 | .error_strings = ip4_punt_redirect_error_strings, |
| 144 | |
| 145 | /* edit / add dispositions here */ |
| 146 | .next_nodes = { |
| 147 | [IP_PUNT_REDIRECT_NEXT_DROP] = "ip4-drop", |
| 148 | [IP_PUNT_REDIRECT_NEXT_TX] = "ip4-rewrite", |
| 149 | [IP_PUNT_REDIRECT_NEXT_ARP] = "ip4-arp", |
| 150 | }, |
| 151 | }; |
| 152 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 153 | VNET_FEATURE_INIT (ip4_punt_redirect_node, static) = { |
| 154 | .arc_name = "ip4-punt", |
| 155 | .node_name = "ip4-punt-redirect", |
| 156 | .runs_before = VNET_FEATURES("error-punt"), |
| 157 | }; |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 158 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 159 | VLIB_NODE_FN (ip4_drop_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 160 | vlib_frame_t * frame) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 161 | { |
| 162 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 163 | ip4_forward_next_trace (vm, node, frame, VLIB_TX); |
| 164 | |
| 165 | return ip_drop_or_punt (vm, node, frame, |
| 166 | vnet_feat_arc_ip4_drop.feature_arc_index); |
| 167 | |
| 168 | } |
| 169 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 170 | VLIB_NODE_FN (ip4_not_enabled_node) (vlib_main_t * vm, |
| 171 | vlib_node_runtime_t * node, |
| 172 | vlib_frame_t * frame) |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 173 | { |
| 174 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 175 | ip4_forward_next_trace (vm, node, frame, VLIB_TX); |
| 176 | |
| 177 | return ip_drop_or_punt (vm, node, frame, |
| 178 | vnet_feat_arc_ip4_drop.feature_arc_index); |
| 179 | } |
| 180 | |
| 181 | static uword |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 182 | ip4_punt (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 183 | { |
| 184 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 185 | ip4_forward_next_trace (vm, node, frame, VLIB_TX); |
| 186 | |
| 187 | return ip_drop_or_punt (vm, node, frame, |
| 188 | vnet_feat_arc_ip4_punt.feature_arc_index); |
| 189 | } |
| 190 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 191 | VLIB_REGISTER_NODE (ip4_drop_node) = |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 192 | { |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 193 | .name = "ip4-drop", |
| 194 | .vector_size = sizeof (u32), |
| 195 | .format_trace = format_ip4_forward_next_trace, |
| 196 | .n_next_nodes = 1, |
| 197 | .next_nodes = { |
| 198 | [0] = "error-drop", |
| 199 | }, |
| 200 | }; |
| 201 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 202 | VLIB_REGISTER_NODE (ip4_not_enabled_node) = |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 203 | { |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 204 | .name = "ip4-not-enabled", |
| 205 | .vector_size = sizeof (u32), |
| 206 | .format_trace = format_ip4_forward_next_trace, |
Neale Ranns | 6bcc6a4 | 2019-10-15 15:47:55 +0000 | [diff] [blame] | 207 | .sibling_of = "ip4-drop", |
Neale Ranns | 8269d3d | 2018-01-30 09:02:20 -0800 | [diff] [blame] | 208 | }; |
| 209 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 210 | VLIB_REGISTER_NODE (ip4_punt_node) = |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 211 | { |
| 212 | .function = ip4_punt, |
| 213 | .name = "ip4-punt", |
| 214 | .vector_size = sizeof (u32), |
| 215 | .format_trace = format_ip4_forward_next_trace, |
| 216 | .n_next_nodes = 1, |
| 217 | .next_nodes = { |
| 218 | [0] = "error-punt", |
| 219 | }, |
| 220 | }; |
| 221 | |
| 222 | VNET_FEATURE_INIT (ip4_punt_end_of_arc, static) = { |
| 223 | .arc_name = "ip4-punt", |
| 224 | .node_name = "error-punt", |
| 225 | .runs_before = 0, /* not before any other features */ |
| 226 | }; |
| 227 | |
| 228 | VNET_FEATURE_INIT (ip4_drop_end_of_arc, static) = { |
| 229 | .arc_name = "ip4-drop", |
| 230 | .node_name = "error-drop", |
| 231 | .runs_before = 0, /* not before any other features */ |
| 232 | }; |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 233 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 234 | #ifndef CLIB_MARCH_VARIANT |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 235 | void |
| 236 | ip4_punt_policer_add_del (u8 is_add, u32 policer_index) |
| 237 | { |
| 238 | ip4_punt_policer_cfg.policer_index = policer_index; |
| 239 | |
| 240 | vnet_feature_enable_disable ("ip4-punt", "ip4-punt-policer", |
| 241 | 0, is_add, 0, 0); |
| 242 | } |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 243 | #endif /* CLIB_MARCH_VARIANT */ |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 244 | |
| 245 | static clib_error_t * |
| 246 | ip4_punt_police_cmd (vlib_main_t * vm, |
| 247 | unformat_input_t * main_input, |
| 248 | vlib_cli_command_t * cmd) |
| 249 | { |
| 250 | unformat_input_t _line_input, *line_input = &_line_input; |
| 251 | clib_error_t *error = 0; |
| 252 | u32 policer_index; |
| 253 | u8 is_add = 1; |
| 254 | |
| 255 | policer_index = ~0; |
| 256 | |
| 257 | if (!unformat_user (main_input, unformat_line_input, line_input)) |
| 258 | return 0; |
| 259 | |
| 260 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 261 | { |
| 262 | if (unformat (line_input, "%d", &policer_index)) |
| 263 | ; |
| 264 | else if (unformat (line_input, "del")) |
| 265 | is_add = 0; |
| 266 | else if (unformat (line_input, "add")) |
| 267 | is_add = 1; |
| 268 | else |
| 269 | { |
| 270 | error = unformat_parse_error (line_input); |
| 271 | goto done; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | if (is_add && ~0 == policer_index) |
| 276 | { |
| 277 | error = clib_error_return (0, "expected policer index `%U'", |
| 278 | format_unformat_error, line_input); |
| 279 | goto done; |
| 280 | } |
| 281 | if (!is_add) |
| 282 | policer_index = ~0; |
| 283 | |
| 284 | ip4_punt_policer_add_del(is_add, policer_index); |
| 285 | |
| 286 | done: |
| 287 | unformat_free (line_input); |
| 288 | return (error); |
| 289 | } |
| 290 | |
| 291 | /*? |
| 292 | * |
| 293 | * @cliexpar |
| 294 | * @cliexcmd{set ip punt policer <INDEX>} |
| 295 | ?*/ |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 296 | VLIB_CLI_COMMAND (ip4_punt_policer_command, static) = |
| 297 | { |
| 298 | .path = "ip punt policer", |
| 299 | .function = ip4_punt_police_cmd, |
| 300 | .short_help = "ip punt policer [add|del] <index>", |
| 301 | }; |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 302 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 303 | #ifndef CLIB_MARCH_VARIANT |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 304 | |
Neale Ranns | 80af13d | 2022-03-25 08:51:58 +0000 | [diff] [blame] | 305 | static u32 ip4_punt_redirect_enable_counts; |
| 306 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 307 | void |
Nathan Skrzypczak | 2a1783f | 2021-08-10 15:05:29 +0200 | [diff] [blame] | 308 | ip4_punt_redirect_add_paths (u32 rx_sw_if_index, |
| 309 | const fib_route_path_t *rpaths) |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 310 | { |
| 311 | ip_punt_redirect_add (FIB_PROTOCOL_IP4, |
| 312 | rx_sw_if_index, |
| 313 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, rpaths); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 314 | |
Neale Ranns | 80af13d | 2022-03-25 08:51:58 +0000 | [diff] [blame] | 315 | if (1 == ++ip4_punt_redirect_enable_counts) |
| 316 | vnet_feature_enable_disable ("ip4-punt", "ip4-punt-redirect", 0, 1, 0, 0); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void |
| 320 | ip4_punt_redirect_del (u32 rx_sw_if_index) |
| 321 | { |
Neale Ranns | 80af13d | 2022-03-25 08:51:58 +0000 | [diff] [blame] | 322 | ASSERT (ip4_punt_redirect_enable_counts); |
| 323 | if (0 == --ip4_punt_redirect_enable_counts) |
| 324 | vnet_feature_enable_disable ("ip4-punt", "ip4-punt-redirect", 0, 0, 0, 0); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 325 | |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 326 | ip_punt_redirect_del (FIB_PROTOCOL_IP4, rx_sw_if_index); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 327 | } |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 328 | #endif /* CLIB_MARCH_VARIANT */ |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 329 | |
| 330 | static clib_error_t * |
| 331 | ip4_punt_redirect_cmd (vlib_main_t * vm, |
| 332 | unformat_input_t * main_input, |
| 333 | vlib_cli_command_t * cmd) |
| 334 | { |
| 335 | unformat_input_t _line_input, *line_input = &_line_input; |
Benoît Ganne | 41a54f6 | 2021-08-05 15:06:36 +0200 | [diff] [blame] | 336 | fib_route_path_t *rpaths = NULL, rpath; |
| 337 | dpo_proto_t payload_proto = DPO_PROTO_IP4; |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 338 | clib_error_t *error = 0; |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 339 | u32 rx_sw_if_index = ~0; |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 340 | vnet_main_t *vnm; |
| 341 | u8 is_add; |
| 342 | |
| 343 | is_add = 1; |
| 344 | vnm = vnet_get_main (); |
| 345 | |
| 346 | if (!unformat_user (main_input, unformat_line_input, line_input)) |
| 347 | return 0; |
| 348 | |
| 349 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 350 | { |
| 351 | if (unformat (line_input, "del")) |
| 352 | is_add = 0; |
| 353 | else if (unformat (line_input, "add")) |
| 354 | is_add = 1; |
| 355 | else if (unformat (line_input, "rx all")) |
Benoît Ganne | 41a54f6 | 2021-08-05 15:06:36 +0200 | [diff] [blame] | 356 | rx_sw_if_index = 0; |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 357 | else if (unformat (line_input, "rx %U", |
| 358 | unformat_vnet_sw_interface, vnm, &rx_sw_if_index)) |
| 359 | ; |
Benoît Ganne | 41a54f6 | 2021-08-05 15:06:36 +0200 | [diff] [blame] | 360 | else if (unformat (line_input, "via %U", unformat_fib_route_path, &rpath, |
| 361 | &payload_proto)) |
| 362 | vec_add1 (rpaths, rpath); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 363 | else |
| 364 | { |
| 365 | error = unformat_parse_error (line_input); |
| 366 | goto done; |
| 367 | } |
| 368 | } |
| 369 | |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 370 | if (~0 == rx_sw_if_index) |
| 371 | { |
| 372 | error = unformat_parse_error (line_input); |
| 373 | goto done; |
| 374 | } |
| 375 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 376 | if (is_add) |
Swarup Nayak | ecf844c | 2017-12-11 13:52:44 +0530 | [diff] [blame] | 377 | { |
Benoît Ganne | 41a54f6 | 2021-08-05 15:06:36 +0200 | [diff] [blame] | 378 | if (vec_len (rpaths)) |
| 379 | ip4_punt_redirect_add_paths (rx_sw_if_index, rpaths); |
Swarup Nayak | ecf844c | 2017-12-11 13:52:44 +0530 | [diff] [blame] | 380 | } |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 381 | else |
Swarup Nayak | ecf844c | 2017-12-11 13:52:44 +0530 | [diff] [blame] | 382 | { |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 383 | ip4_punt_redirect_del (rx_sw_if_index); |
Swarup Nayak | ecf844c | 2017-12-11 13:52:44 +0530 | [diff] [blame] | 384 | } |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 385 | |
| 386 | done: |
Benoît Ganne | 41a54f6 | 2021-08-05 15:06:36 +0200 | [diff] [blame] | 387 | vec_free (rpaths); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 388 | unformat_free (line_input); |
| 389 | return (error); |
| 390 | } |
| 391 | |
| 392 | /*? |
| 393 | * |
| 394 | * @cliexpar |
| 395 | * @cliexcmd{set ip punt policer} |
| 396 | ?*/ |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 397 | VLIB_CLI_COMMAND (ip4_punt_redirect_command, static) = |
| 398 | { |
| 399 | .path = "ip punt redirect", |
| 400 | .function = ip4_punt_redirect_cmd, |
| 401 | .short_help = "ip punt redirect [add|del] rx [<interface>|all] via [<nh>] <tx_interface>", |
| 402 | }; |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 403 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 404 | static clib_error_t * |
| 405 | ip4_punt_redirect_show_cmd (vlib_main_t * vm, |
| 406 | unformat_input_t * main_input, |
| 407 | vlib_cli_command_t * cmd) |
| 408 | { |
Neale Ranns | 9220775 | 2019-06-03 13:21:40 +0000 | [diff] [blame] | 409 | vlib_cli_output (vm, "%U", format_ip_punt_redirect, FIB_PROTOCOL_IP4); |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 410 | |
| 411 | return (NULL); |
| 412 | } |
| 413 | |
| 414 | /*? |
| 415 | * |
| 416 | * @cliexpar |
| 417 | * @cliexcmd{set ip punt redierect} |
| 418 | ?*/ |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 419 | VLIB_CLI_COMMAND (show_ip4_punt_redirect_command, static) = |
| 420 | { |
| 421 | .path = "show ip punt redirect", |
| 422 | .function = ip4_punt_redirect_show_cmd, |
Swarup Nayak | a3611a7 | 2017-12-06 18:55:43 +0530 | [diff] [blame] | 423 | .short_help = "show ip punt redirect", |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 424 | .is_mp_safe = 1, |
| 425 | }; |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 426 | |
| 427 | /* |
| 428 | * fd.io coding-style-patch-verification: ON |
| 429 | * |
| 430 | * Local Variables: |
| 431 | * eval: (c-set-style "gnu") |
| 432 | * End: |
| 433 | */ |