Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 | #include <vlib/vlib.h> |
| 16 | #include <vnet/vnet.h> |
| 17 | #include <vnet/pg/pg.h> |
| 18 | #include <vppinfra/error.h> |
| 19 | |
| 20 | #include <vnet/ip/ip.h> |
| 21 | |
| 22 | #include <vppinfra/hash.h> |
| 23 | #include <vppinfra/error.h> |
| 24 | #include <vppinfra/elog.h> |
| 25 | |
| 26 | #include <vnet/ip/ip6_hop_by_hop.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 27 | #include <vnet/fib/ip6_fib.h> |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 28 | #include <vnet/classify/vnet_classify.h> |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 29 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 30 | /** |
| 31 | * @file |
| 32 | * @brief In-band OAM (iOAM). |
| 33 | * |
| 34 | * In-band OAM (iOAM) is an implementation study to record operational |
| 35 | * information in the packet while the packet traverses a path between |
| 36 | * two points in the network. |
| 37 | * |
| 38 | * VPP can function as in-band OAM encapsulating, transit and |
| 39 | * decapsulating node. In this version of VPP in-band OAM data is |
| 40 | * transported as options in an IPv6 hop-by-hop extension header. Hence |
| 41 | * in-band OAM can be enabled for IPv6 traffic. |
| 42 | */ |
| 43 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 44 | ip6_hop_by_hop_ioam_main_t ip6_hop_by_hop_ioam_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 45 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 46 | #define foreach_ip6_hbyh_ioam_input_next \ |
| 47 | _(IP6_REWRITE, "ip6-rewrite") \ |
| 48 | _(IP6_LOOKUP, "ip6-lookup") \ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 49 | _(DROP, "error-drop") |
rangan | f5bf6dd | 2016-04-15 17:31:46 +0530 | [diff] [blame] | 50 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 51 | typedef enum |
| 52 | { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 53 | #define _(s,n) IP6_HBYH_IOAM_INPUT_NEXT_##s, |
| 54 | foreach_ip6_hbyh_ioam_input_next |
rangan | f5bf6dd | 2016-04-15 17:31:46 +0530 | [diff] [blame] | 55 | #undef _ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 56 | IP6_HBYH_IOAM_INPUT_N_NEXT, |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 57 | } ip6_hbyh_ioam_input_next_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 59 | static uword |
| 60 | unformat_opaque_ioam (unformat_input_t * input, va_list * args) |
| 61 | { |
| 62 | u64 *opaquep = va_arg (*args, u64 *); |
| 63 | u8 *flow_name = NULL; |
| 64 | uword ret = 0; |
| 65 | |
| 66 | if (unformat (input, "ioam-encap %s", &flow_name)) |
| 67 | { |
| 68 | *opaquep = ioam_flow_add (1, flow_name); |
| 69 | ret = 1; |
| 70 | } |
| 71 | else if (unformat (input, "ioam-decap %s", &flow_name)) |
| 72 | { |
| 73 | *opaquep = ioam_flow_add (0, flow_name); |
| 74 | ret = 1; |
| 75 | } |
| 76 | |
| 77 | vec_free (flow_name); |
| 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | u8 * |
| 82 | get_flow_name_from_flow_ctx (u32 flow_ctx) |
| 83 | { |
| 84 | flow_data_t *flow = NULL; |
| 85 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
| 86 | u32 index; |
| 87 | |
| 88 | index = IOAM_MASK_DECAP_BIT (flow_ctx); |
| 89 | |
| 90 | if (pool_is_free_index (hm->flows, index)) |
| 91 | return NULL; |
| 92 | |
| 93 | flow = pool_elt_at_index (hm->flows, index); |
| 94 | return (flow->flow_name); |
| 95 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 96 | |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 97 | /* The main h-b-h tracer will be invoked, no need to do much here */ |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 98 | int |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 99 | ip6_hbh_add_register_option (u8 option, |
| 100 | u8 size, |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 101 | int rewrite_options (u8 * rewrite_string, |
| 102 | u8 * rewrite_size)) |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 103 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 104 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 106 | ASSERT (option < ARRAY_LEN (hm->add_options)); |
| 107 | |
| 108 | /* Already registered */ |
| 109 | if (hm->add_options[option]) |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 110 | return (-1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 112 | hm->add_options[option] = rewrite_options; |
| 113 | hm->options_size[option] = size; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 114 | |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 115 | return (0); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 116 | } |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 117 | |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 118 | int |
| 119 | ip6_hbh_add_unregister_option (u8 option) |
| 120 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 121 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 122 | |
| 123 | ASSERT (option < ARRAY_LEN (hm->add_options)); |
| 124 | |
| 125 | /* Not registered */ |
| 126 | if (!hm->add_options[option]) |
| 127 | return (-1); |
| 128 | |
| 129 | hm->add_options[option] = NULL; |
| 130 | hm->options_size[option] = 0; |
| 131 | return (0); |
| 132 | } |
| 133 | |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 134 | /* Config handler registration */ |
| 135 | int |
| 136 | ip6_hbh_config_handler_register (u8 option, |
| 137 | int config_handler (void *data, u8 disable)) |
| 138 | { |
| 139 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
| 140 | |
| 141 | ASSERT (option < ARRAY_LEN (hm->config_handler)); |
| 142 | |
| 143 | /* Already registered */ |
| 144 | if (hm->config_handler[option]) |
| 145 | return (VNET_API_ERROR_INVALID_REGISTRATION); |
| 146 | |
| 147 | hm->config_handler[option] = config_handler; |
| 148 | |
| 149 | return (0); |
| 150 | } |
| 151 | |
| 152 | int |
| 153 | ip6_hbh_config_handler_unregister (u8 option) |
| 154 | { |
| 155 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
| 156 | |
| 157 | ASSERT (option < ARRAY_LEN (hm->config_handler)); |
| 158 | |
| 159 | /* Not registered */ |
| 160 | if (!hm->config_handler[option]) |
| 161 | return (VNET_API_ERROR_INVALID_REGISTRATION); |
| 162 | |
| 163 | hm->config_handler[option] = NULL; |
| 164 | return (0); |
| 165 | } |
| 166 | |
| 167 | /* Flow handler registration */ |
| 168 | int |
| 169 | ip6_hbh_flow_handler_register (u8 option, |
| 170 | u32 ioam_flow_handler (u32 flow_ctx, u8 add)) |
| 171 | { |
| 172 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
| 173 | |
| 174 | ASSERT (option < ARRAY_LEN (hm->flow_handler)); |
| 175 | |
| 176 | /* Already registered */ |
| 177 | if (hm->flow_handler[option]) |
| 178 | return (VNET_API_ERROR_INVALID_REGISTRATION); |
| 179 | |
| 180 | hm->flow_handler[option] = ioam_flow_handler; |
| 181 | |
| 182 | return (0); |
| 183 | } |
| 184 | |
| 185 | int |
| 186 | ip6_hbh_flow_handler_unregister (u8 option) |
| 187 | { |
| 188 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
| 189 | |
| 190 | ASSERT (option < ARRAY_LEN (hm->flow_handler)); |
| 191 | |
| 192 | /* Not registered */ |
| 193 | if (!hm->flow_handler[option]) |
| 194 | return (VNET_API_ERROR_INVALID_REGISTRATION); |
| 195 | |
| 196 | hm->flow_handler[option] = NULL; |
| 197 | return (0); |
| 198 | } |
| 199 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 200 | typedef struct |
| 201 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 202 | u32 next_index; |
| 203 | } ip6_add_hop_by_hop_trace_t; |
| 204 | |
| 205 | /* packet trace format function */ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 206 | static u8 * |
| 207 | format_ip6_add_hop_by_hop_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 208 | { |
| 209 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 210 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 211 | ip6_add_hop_by_hop_trace_t *t = va_arg (*args, |
| 212 | ip6_add_hop_by_hop_trace_t *); |
| 213 | |
| 214 | s = format (s, "IP6_ADD_HOP_BY_HOP: next index %d", t->next_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 215 | return s; |
| 216 | } |
| 217 | |
| 218 | vlib_node_registration_t ip6_add_hop_by_hop_node; |
| 219 | |
| 220 | #define foreach_ip6_add_hop_by_hop_error \ |
| 221 | _(PROCESSED, "Pkts w/ added ip6 hop-by-hop options") |
| 222 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 223 | typedef enum |
| 224 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 225 | #define _(sym,str) IP6_ADD_HOP_BY_HOP_ERROR_##sym, |
| 226 | foreach_ip6_add_hop_by_hop_error |
| 227 | #undef _ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 228 | IP6_ADD_HOP_BY_HOP_N_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 229 | } ip6_add_hop_by_hop_error_t; |
| 230 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 231 | static char *ip6_add_hop_by_hop_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 232 | #define _(sym,string) string, |
| 233 | foreach_ip6_add_hop_by_hop_error |
| 234 | #undef _ |
| 235 | }; |
| 236 | |
| 237 | static uword |
| 238 | ip6_add_hop_by_hop_node_fn (vlib_main_t * vm, |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 239 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 241 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
| 242 | u32 n_left_from, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 243 | ip_lookup_next_t next_index; |
| 244 | u32 processed = 0; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 245 | u8 *rewrite = hm->rewrite; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 246 | u32 rewrite_length = vec_len (rewrite); |
| 247 | |
| 248 | from = vlib_frame_vector_args (frame); |
| 249 | n_left_from = frame->n_vectors; |
| 250 | next_index = node->cached_next_index; |
| 251 | |
| 252 | while (n_left_from > 0) |
| 253 | { |
| 254 | u32 n_left_to_next; |
| 255 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 256 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 257 | while (n_left_from >= 4 && n_left_to_next >= 2) |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 258 | { |
| 259 | u32 bi0, bi1; |
| 260 | vlib_buffer_t *b0, *b1; |
| 261 | u32 next0, next1; |
| 262 | ip6_header_t *ip0, *ip1; |
| 263 | ip6_hop_by_hop_header_t *hbh0, *hbh1; |
| 264 | u64 *copy_src0, *copy_dst0, *copy_src1, *copy_dst1; |
| 265 | u16 new_l0, new_l1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 266 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 267 | /* Prefetch next iteration. */ |
| 268 | { |
| 269 | vlib_buffer_t *p2, *p3; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 270 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 271 | p2 = vlib_get_buffer (vm, from[2]); |
| 272 | p3 = vlib_get_buffer (vm, from[3]); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 273 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 274 | vlib_prefetch_buffer_header (p2, LOAD); |
| 275 | vlib_prefetch_buffer_header (p3, LOAD); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 276 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 277 | CLIB_PREFETCH (p2->data - rewrite_length, |
| 278 | 2 * CLIB_CACHE_LINE_BYTES, STORE); |
| 279 | CLIB_PREFETCH (p3->data - rewrite_length, |
| 280 | 2 * CLIB_CACHE_LINE_BYTES, STORE); |
| 281 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 282 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 283 | /* speculatively enqueue b0 and b1 to the current next frame */ |
| 284 | to_next[0] = bi0 = from[0]; |
| 285 | to_next[1] = bi1 = from[1]; |
| 286 | from += 2; |
| 287 | to_next += 2; |
| 288 | n_left_from -= 2; |
| 289 | n_left_to_next -= 2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 290 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 291 | b0 = vlib_get_buffer (vm, bi0); |
| 292 | b1 = vlib_get_buffer (vm, bi1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 293 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 294 | /* $$$$$ Dual loop: process 2 x packets here $$$$$ */ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 295 | ip0 = vlib_buffer_get_current (b0); |
| 296 | ip1 = vlib_buffer_get_current (b1); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 297 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 298 | /* Copy the ip header left by the required amount */ |
| 299 | copy_dst0 = (u64 *) (((u8 *) ip0) - rewrite_length); |
| 300 | copy_dst1 = (u64 *) (((u8 *) ip1) - rewrite_length); |
| 301 | copy_src0 = (u64 *) ip0; |
| 302 | copy_src1 = (u64 *) ip1; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 303 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 304 | copy_dst0[0] = copy_src0[0]; |
| 305 | copy_dst0[1] = copy_src0[1]; |
| 306 | copy_dst0[2] = copy_src0[2]; |
| 307 | copy_dst0[3] = copy_src0[3]; |
| 308 | copy_dst0[4] = copy_src0[4]; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 309 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 310 | copy_dst1[0] = copy_src1[0]; |
| 311 | copy_dst1[1] = copy_src1[1]; |
| 312 | copy_dst1[2] = copy_src1[2]; |
| 313 | copy_dst1[3] = copy_src1[3]; |
| 314 | copy_dst1[4] = copy_src1[4]; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 315 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 316 | vlib_buffer_advance (b0, -(word) rewrite_length); |
| 317 | vlib_buffer_advance (b1, -(word) rewrite_length); |
| 318 | ip0 = vlib_buffer_get_current (b0); |
| 319 | ip1 = vlib_buffer_get_current (b1); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 320 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 321 | hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1); |
| 322 | hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1); |
| 323 | /* $$$ tune, rewrite_length is a multiple of 8 */ |
| 324 | clib_memcpy (hbh0, rewrite, rewrite_length); |
| 325 | clib_memcpy (hbh1, rewrite, rewrite_length); |
| 326 | /* Patch the protocol chain, insert the h-b-h (type 0) header */ |
| 327 | hbh0->protocol = ip0->protocol; |
| 328 | hbh1->protocol = ip1->protocol; |
| 329 | ip0->protocol = 0; |
| 330 | ip1->protocol = 0; |
| 331 | new_l0 = |
| 332 | clib_net_to_host_u16 (ip0->payload_length) + rewrite_length; |
| 333 | new_l1 = |
| 334 | clib_net_to_host_u16 (ip1->payload_length) + rewrite_length; |
| 335 | ip0->payload_length = clib_host_to_net_u16 (new_l0); |
| 336 | ip1->payload_length = clib_host_to_net_u16 (new_l1); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 337 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 338 | /* Populate the (first) h-b-h list elt */ |
| 339 | next0 = IP6_HBYH_IOAM_INPUT_NEXT_IP6_LOOKUP; |
| 340 | next1 = IP6_HBYH_IOAM_INPUT_NEXT_IP6_LOOKUP; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 341 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 342 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 343 | /* $$$$$ End of processing 2 x packets $$$$$ */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 344 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 345 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE))) |
| 346 | { |
| 347 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 348 | { |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 349 | ip6_add_hop_by_hop_trace_t *t = |
| 350 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 351 | t->next_index = next0; |
| 352 | } |
| 353 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 354 | { |
| 355 | ip6_add_hop_by_hop_trace_t *t = |
| 356 | vlib_add_trace (vm, node, b1, sizeof (*t)); |
| 357 | t->next_index = next1; |
| 358 | } |
| 359 | } |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 360 | processed += 2; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 361 | /* verify speculative enqueues, maybe switch current next frame */ |
| 362 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 363 | to_next, n_left_to_next, |
| 364 | bi0, bi1, next0, next1); |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 365 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 366 | while (n_left_from > 0 && n_left_to_next > 0) |
| 367 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 368 | u32 bi0; |
| 369 | vlib_buffer_t *b0; |
| 370 | u32 next0; |
| 371 | ip6_header_t *ip0; |
| 372 | ip6_hop_by_hop_header_t *hbh0; |
| 373 | u64 *copy_src0, *copy_dst0; |
| 374 | u16 new_l0; |
| 375 | |
| 376 | /* speculatively enqueue b0 to the current next frame */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 377 | bi0 = from[0]; |
| 378 | to_next[0] = bi0; |
| 379 | from += 1; |
| 380 | to_next += 1; |
| 381 | n_left_from -= 1; |
| 382 | n_left_to_next -= 1; |
| 383 | |
| 384 | b0 = vlib_get_buffer (vm, bi0); |
| 385 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 386 | ip0 = vlib_buffer_get_current (b0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 387 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 388 | /* Copy the ip header left by the required amount */ |
| 389 | copy_dst0 = (u64 *) (((u8 *) ip0) - rewrite_length); |
| 390 | copy_src0 = (u64 *) ip0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 391 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 392 | copy_dst0[0] = copy_src0[0]; |
| 393 | copy_dst0[1] = copy_src0[1]; |
| 394 | copy_dst0[2] = copy_src0[2]; |
| 395 | copy_dst0[3] = copy_src0[3]; |
| 396 | copy_dst0[4] = copy_src0[4]; |
| 397 | vlib_buffer_advance (b0, -(word) rewrite_length); |
| 398 | ip0 = vlib_buffer_get_current (b0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 399 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 400 | hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1); |
| 401 | /* $$$ tune, rewrite_length is a multiple of 8 */ |
| 402 | clib_memcpy (hbh0, rewrite, rewrite_length); |
| 403 | /* Patch the protocol chain, insert the h-b-h (type 0) header */ |
| 404 | hbh0->protocol = ip0->protocol; |
| 405 | ip0->protocol = 0; |
| 406 | new_l0 = |
| 407 | clib_net_to_host_u16 (ip0->payload_length) + rewrite_length; |
| 408 | ip0->payload_length = clib_host_to_net_u16 (new_l0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 409 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 410 | /* Populate the (first) h-b-h list elt */ |
| 411 | next0 = IP6_HBYH_IOAM_INPUT_NEXT_IP6_LOOKUP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 412 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 413 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) |
| 414 | && (b0->flags & VLIB_BUFFER_IS_TRACED))) |
| 415 | { |
| 416 | ip6_add_hop_by_hop_trace_t *t = |
| 417 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 418 | t->next_index = next0; |
| 419 | } |
| 420 | |
| 421 | processed++; |
| 422 | |
| 423 | /* verify speculative enqueue, maybe switch current next frame */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 424 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 425 | to_next, n_left_to_next, |
| 426 | bi0, next0); |
| 427 | } |
| 428 | |
| 429 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 430 | } |
| 431 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 432 | vlib_node_increment_counter (vm, ip6_add_hop_by_hop_node.index, |
| 433 | IP6_ADD_HOP_BY_HOP_ERROR_PROCESSED, processed); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 434 | return frame->n_vectors; |
| 435 | } |
| 436 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 437 | /* *INDENT-OFF* */ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 438 | VLIB_REGISTER_NODE (ip6_add_hop_by_hop_node) = /* *INDENT-OFF* */ |
| 439 | { |
| 440 | .function = ip6_add_hop_by_hop_node_fn,.name = |
| 441 | "ip6-add-hop-by-hop",.vector_size = sizeof (u32),.format_trace = |
| 442 | format_ip6_add_hop_by_hop_trace,.type = |
| 443 | VLIB_NODE_TYPE_INTERNAL,.n_errors = |
| 444 | ARRAY_LEN (ip6_add_hop_by_hop_error_strings),.error_strings = |
| 445 | ip6_add_hop_by_hop_error_strings, |
| 446 | /* See ip/lookup.h */ |
| 447 | .n_next_nodes = IP6_HBYH_IOAM_INPUT_N_NEXT,.next_nodes = |
| 448 | { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 449 | #define _(s,n) [IP6_HBYH_IOAM_INPUT_NEXT_##s] = n, |
| 450 | foreach_ip6_hbyh_ioam_input_next |
rangan | f5bf6dd | 2016-04-15 17:31:46 +0530 | [diff] [blame] | 451 | #undef _ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 452 | } |
| 453 | ,}; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 454 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 455 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 456 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 457 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 458 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_add_hop_by_hop_node, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 459 | ip6_add_hop_by_hop_node_fn); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 460 | /* The main h-b-h tracer was already invoked, no need to do much here */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 461 | typedef struct |
| 462 | { |
| 463 | u32 next_index; |
| 464 | } ip6_pop_hop_by_hop_trace_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 465 | |
| 466 | /* packet trace format function */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 467 | static u8 * |
| 468 | format_ip6_pop_hop_by_hop_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 469 | { |
| 470 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 471 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 472 | ip6_pop_hop_by_hop_trace_t *t = |
| 473 | va_arg (*args, ip6_pop_hop_by_hop_trace_t *); |
| 474 | |
| 475 | s = format (s, "IP6_POP_HOP_BY_HOP: next index %d", t->next_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 476 | return s; |
| 477 | } |
| 478 | |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 479 | int |
| 480 | ip6_hbh_pop_register_option (u8 option, |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 481 | int options (vlib_buffer_t * b, |
| 482 | ip6_header_t * ip, |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 483 | ip6_hop_by_hop_option_t * opt)) |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 484 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 485 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 486 | |
| 487 | ASSERT (option < ARRAY_LEN (hm->pop_options)); |
| 488 | |
| 489 | /* Already registered */ |
| 490 | if (hm->pop_options[option]) |
| 491 | return (-1); |
| 492 | |
| 493 | hm->pop_options[option] = options; |
| 494 | |
| 495 | return (0); |
| 496 | } |
| 497 | |
| 498 | int |
| 499 | ip6_hbh_pop_unregister_option (u8 option) |
| 500 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 501 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 502 | |
| 503 | ASSERT (option < ARRAY_LEN (hm->pop_options)); |
| 504 | |
| 505 | /* Not registered */ |
| 506 | if (!hm->pop_options[option]) |
| 507 | return (-1); |
| 508 | |
| 509 | hm->pop_options[option] = NULL; |
| 510 | return (0); |
| 511 | } |
| 512 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 513 | vlib_node_registration_t ip6_pop_hop_by_hop_node; |
| 514 | |
| 515 | #define foreach_ip6_pop_hop_by_hop_error \ |
| 516 | _(PROCESSED, "Pkts w/ removed ip6 hop-by-hop options") \ |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 517 | _(NO_HOHO, "Pkts w/ no ip6 hop-by-hop options") \ |
| 518 | _(OPTION_FAILED, "ip6 pop hop-by-hop failed to process") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 519 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 520 | typedef enum |
| 521 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 522 | #define _(sym,str) IP6_POP_HOP_BY_HOP_ERROR_##sym, |
| 523 | foreach_ip6_pop_hop_by_hop_error |
| 524 | #undef _ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 525 | IP6_POP_HOP_BY_HOP_N_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 526 | } ip6_pop_hop_by_hop_error_t; |
| 527 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 528 | static char *ip6_pop_hop_by_hop_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 529 | #define _(sym,string) string, |
| 530 | foreach_ip6_pop_hop_by_hop_error |
| 531 | #undef _ |
| 532 | }; |
| 533 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 534 | static inline void |
| 535 | ioam_pop_hop_by_hop_processing (vlib_main_t * vm, |
| 536 | ip6_header_t * ip0, |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 537 | ip6_hop_by_hop_header_t * hbh0, |
| 538 | vlib_buffer_t * b) |
Shwetha Bhandari | 05866a1 | 2016-05-04 08:12:57 +0200 | [diff] [blame] | 539 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 540 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
Shwetha Bhandari | 05866a1 | 2016-05-04 08:12:57 +0200 | [diff] [blame] | 541 | ip6_hop_by_hop_option_t *opt0, *limit0; |
Shwetha Bhandari | 05866a1 | 2016-05-04 08:12:57 +0200 | [diff] [blame] | 542 | u8 type0; |
Shwetha Bhandari | 05866a1 | 2016-05-04 08:12:57 +0200 | [diff] [blame] | 543 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 544 | if (!hbh0 || !ip0) |
| 545 | return; |
Shwetha Bhandari | 05866a1 | 2016-05-04 08:12:57 +0200 | [diff] [blame] | 546 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 547 | opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1); |
Shwetha Bhandari | 05866a1 | 2016-05-04 08:12:57 +0200 | [diff] [blame] | 548 | limit0 = (ip6_hop_by_hop_option_t *) |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 549 | ((u8 *) hbh0 + ((hbh0->length + 1) << 3)); |
Shwetha Bhandari | 05866a1 | 2016-05-04 08:12:57 +0200 | [diff] [blame] | 550 | |
| 551 | /* Scan the set of h-b-h options, process ones that we understand */ |
| 552 | while (opt0 < limit0) |
| 553 | { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 554 | type0 = opt0->type; |
Shwetha Bhandari | 05866a1 | 2016-05-04 08:12:57 +0200 | [diff] [blame] | 555 | switch (type0) |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 556 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 557 | case 0: /* Pad1 */ |
| 558 | opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1; |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 559 | continue; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 560 | case 1: /* PadN */ |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 561 | break; |
| 562 | default: |
| 563 | if (hm->pop_options[type0]) |
| 564 | { |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 565 | if ((*hm->pop_options[type0]) (b, ip0, opt0) < 0) |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 566 | { |
| 567 | vlib_node_increment_counter (vm, |
| 568 | ip6_pop_hop_by_hop_node.index, |
| 569 | IP6_POP_HOP_BY_HOP_ERROR_OPTION_FAILED, |
| 570 | 1); |
| 571 | } |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 572 | } |
| 573 | } |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 574 | opt0 = |
| 575 | (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length + |
| 576 | sizeof (ip6_hop_by_hop_option_t)); |
Shwetha Bhandari | 05866a1 | 2016-05-04 08:12:57 +0200 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 580 | static uword |
| 581 | ip6_pop_hop_by_hop_node_fn (vlib_main_t * vm, |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 582 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 583 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 584 | ip6_main_t *im = &ip6_main; |
| 585 | ip_lookup_main_t *lm = &im->lookup_main; |
| 586 | u32 n_left_from, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 587 | ip_lookup_next_t next_index; |
| 588 | u32 processed = 0; |
| 589 | u32 no_header = 0; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 590 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 591 | from = vlib_frame_vector_args (frame); |
| 592 | n_left_from = frame->n_vectors; |
| 593 | next_index = node->cached_next_index; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 594 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 595 | while (n_left_from > 0) |
| 596 | { |
| 597 | u32 n_left_to_next; |
| 598 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 599 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 600 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 601 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 602 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 603 | u32 bi0, bi1; |
| 604 | vlib_buffer_t *b0, *b1; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 605 | u32 next0, next1; |
| 606 | u32 adj_index0, adj_index1; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 607 | ip6_header_t *ip0, *ip1; |
| 608 | ip_adjacency_t *adj0, *adj1; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 609 | ip6_hop_by_hop_header_t *hbh0, *hbh1; |
| 610 | u64 *copy_dst0, *copy_src0, *copy_dst1, *copy_src1; |
| 611 | u16 new_l0, new_l1; |
| 612 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 613 | /* Prefetch next iteration. */ |
| 614 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 615 | vlib_buffer_t *p2, *p3; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 616 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 617 | p2 = vlib_get_buffer (vm, from[2]); |
| 618 | p3 = vlib_get_buffer (vm, from[3]); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 619 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 620 | vlib_prefetch_buffer_header (p2, LOAD); |
| 621 | vlib_prefetch_buffer_header (p3, LOAD); |
| 622 | |
| 623 | CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 624 | CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 625 | } |
| 626 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 627 | /* speculatively enqueue b0 and b1 to the current next frame */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 628 | to_next[0] = bi0 = from[0]; |
| 629 | to_next[1] = bi1 = from[1]; |
| 630 | from += 2; |
| 631 | to_next += 2; |
| 632 | n_left_from -= 2; |
| 633 | n_left_to_next -= 2; |
| 634 | |
| 635 | b0 = vlib_get_buffer (vm, bi0); |
| 636 | b1 = vlib_get_buffer (vm, bi1); |
| 637 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 638 | /* $$$$$ Dual loop: process 2 x packets here $$$$$ */ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 639 | ip0 = vlib_buffer_get_current (b0); |
| 640 | ip1 = vlib_buffer_get_current (b1); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 641 | adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; |
| 642 | adj_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX]; |
| 643 | adj0 = ip_get_adjacency (lm, adj_index0); |
| 644 | adj1 = ip_get_adjacency (lm, adj_index1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 645 | |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 646 | next0 = adj0->lookup_next_index; |
| 647 | next1 = adj1->lookup_next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 648 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 649 | hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1); |
| 650 | hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 651 | |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 652 | ioam_pop_hop_by_hop_processing (vm, ip0, hbh0, b0); |
| 653 | ioam_pop_hop_by_hop_processing (vm, ip1, hbh1, b1); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 654 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 655 | vlib_buffer_advance (b0, (hbh0->length + 1) << 3); |
| 656 | vlib_buffer_advance (b1, (hbh1->length + 1) << 3); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 657 | |
| 658 | new_l0 = clib_net_to_host_u16 (ip0->payload_length) - |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 659 | ((hbh0->length + 1) << 3); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 660 | new_l1 = clib_net_to_host_u16 (ip1->payload_length) - |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 661 | ((hbh1->length + 1) << 3); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 662 | |
| 663 | ip0->payload_length = clib_host_to_net_u16 (new_l0); |
| 664 | ip1->payload_length = clib_host_to_net_u16 (new_l1); |
| 665 | |
| 666 | ip0->protocol = hbh0->protocol; |
| 667 | ip1->protocol = hbh1->protocol; |
| 668 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 669 | copy_src0 = (u64 *) ip0; |
| 670 | copy_src1 = (u64 *) ip1; |
| 671 | copy_dst0 = copy_src0 + (hbh0->length + 1); |
| 672 | copy_dst0[4] = copy_src0[4]; |
| 673 | copy_dst0[3] = copy_src0[3]; |
| 674 | copy_dst0[2] = copy_src0[2]; |
| 675 | copy_dst0[1] = copy_src0[1]; |
| 676 | copy_dst0[0] = copy_src0[0]; |
| 677 | copy_dst1 = copy_src1 + (hbh1->length + 1); |
| 678 | copy_dst1[4] = copy_src1[4]; |
| 679 | copy_dst1[3] = copy_src1[3]; |
| 680 | copy_dst1[2] = copy_src1[2]; |
| 681 | copy_dst1[1] = copy_src1[1]; |
| 682 | copy_dst1[0] = copy_src1[0]; |
| 683 | processed += 2; |
| 684 | /* $$$$$ End of processing 2 x packets $$$$$ */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 685 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 686 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE))) |
| 687 | { |
| 688 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 689 | { |
| 690 | ip6_pop_hop_by_hop_trace_t *t = |
| 691 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 692 | t->next_index = next0; |
| 693 | } |
| 694 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 695 | { |
| 696 | ip6_pop_hop_by_hop_trace_t *t = |
| 697 | vlib_add_trace (vm, node, b1, sizeof (*t)); |
| 698 | t->next_index = next1; |
| 699 | } |
| 700 | } |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 701 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 702 | /* verify speculative enqueues, maybe switch current next frame */ |
| 703 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 704 | to_next, n_left_to_next, |
| 705 | bi0, bi1, next0, next1); |
| 706 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 707 | |
| 708 | while (n_left_from > 0 && n_left_to_next > 0) |
| 709 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 710 | u32 bi0; |
| 711 | vlib_buffer_t *b0; |
| 712 | u32 next0; |
| 713 | u32 adj_index0; |
| 714 | ip6_header_t *ip0; |
| 715 | ip_adjacency_t *adj0; |
| 716 | ip6_hop_by_hop_header_t *hbh0; |
| 717 | u64 *copy_dst0, *copy_src0; |
| 718 | u16 new_l0; |
| 719 | |
| 720 | /* speculatively enqueue b0 to the current next frame */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 721 | bi0 = from[0]; |
| 722 | to_next[0] = bi0; |
| 723 | from += 1; |
| 724 | to_next += 1; |
| 725 | n_left_from -= 1; |
| 726 | n_left_to_next -= 1; |
| 727 | |
| 728 | b0 = vlib_get_buffer (vm, bi0); |
| 729 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 730 | ip0 = vlib_buffer_get_current (b0); |
| 731 | adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; |
| 732 | adj0 = ip_get_adjacency (lm, adj_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 733 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 734 | /* Default use the next_index from the adjacency. */ |
| 735 | next0 = adj0->lookup_next_index; |
| 736 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 737 | /* Perfectly normal to end up here w/ out h-b-h header */ |
| 738 | hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1); |
| 739 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 740 | /* TODO:Temporarily doing it here.. do this validation in end_of_path_cb */ |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 741 | ioam_pop_hop_by_hop_processing (vm, ip0, hbh0, b0); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 742 | /* Pop the trace data */ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 743 | vlib_buffer_advance (b0, (hbh0->length + 1) << 3); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 744 | new_l0 = clib_net_to_host_u16 (ip0->payload_length) - |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 745 | ((hbh0->length + 1) << 3); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 746 | ip0->payload_length = clib_host_to_net_u16 (new_l0); |
| 747 | ip0->protocol = hbh0->protocol; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 748 | copy_src0 = (u64 *) ip0; |
| 749 | copy_dst0 = copy_src0 + (hbh0->length + 1); |
| 750 | copy_dst0[4] = copy_src0[4]; |
| 751 | copy_dst0[3] = copy_src0[3]; |
| 752 | copy_dst0[2] = copy_src0[2]; |
| 753 | copy_dst0[1] = copy_src0[1]; |
| 754 | copy_dst0[0] = copy_src0[0]; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 755 | processed++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 756 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 757 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) |
| 758 | && (b0->flags & VLIB_BUFFER_IS_TRACED))) |
| 759 | { |
| 760 | ip6_pop_hop_by_hop_trace_t *t = |
| 761 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 762 | t->next_index = next0; |
| 763 | } |
| 764 | |
| 765 | /* verify speculative enqueue, maybe switch current next frame */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 766 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 767 | to_next, n_left_to_next, |
| 768 | bi0, next0); |
| 769 | } |
| 770 | |
| 771 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 772 | } |
| 773 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 774 | vlib_node_increment_counter (vm, ip6_pop_hop_by_hop_node.index, |
| 775 | IP6_POP_HOP_BY_HOP_ERROR_PROCESSED, processed); |
| 776 | vlib_node_increment_counter (vm, ip6_pop_hop_by_hop_node.index, |
| 777 | IP6_POP_HOP_BY_HOP_ERROR_NO_HOHO, no_header); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 778 | return frame->n_vectors; |
| 779 | } |
| 780 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 781 | /* *INDENT-OFF* */ |
| 782 | VLIB_REGISTER_NODE (ip6_pop_hop_by_hop_node) = |
| 783 | { |
| 784 | .function = ip6_pop_hop_by_hop_node_fn,.name = |
| 785 | "ip6-pop-hop-by-hop",.vector_size = sizeof (u32),.format_trace = |
| 786 | format_ip6_pop_hop_by_hop_trace,.type = |
| 787 | VLIB_NODE_TYPE_INTERNAL,.sibling_of = "ip6-lookup",.n_errors = |
| 788 | ARRAY_LEN (ip6_pop_hop_by_hop_error_strings),.error_strings = |
| 789 | ip6_pop_hop_by_hop_error_strings, |
| 790 | /* See ip/lookup.h */ |
| 791 | .n_next_nodes = 0,}; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 792 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 793 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 794 | |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 795 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_pop_hop_by_hop_node, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 796 | ip6_pop_hop_by_hop_node_fn); |
| 797 | static clib_error_t * |
| 798 | ip6_hop_by_hop_ioam_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 799 | { |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 800 | clib_error_t *error; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 801 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 802 | |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 803 | if ((error = vlib_call_init_function (vm, ip_main_init))) |
| 804 | return (error); |
| 805 | |
| 806 | if ((error = vlib_call_init_function (vm, ip6_lookup_init))) |
| 807 | return error; |
| 808 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 809 | hm->vlib_main = vm; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 810 | hm->vnet_main = vnet_get_main (); |
| 811 | hm->unix_time_0 = (u32) time (0); /* Store starting time */ |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 812 | hm->vlib_time_0 = vlib_time_now (vm); |
| 813 | hm->ioam_flag = IOAM_HBYH_MOD; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 814 | memset (hm->add_options, 0, sizeof (hm->add_options)); |
| 815 | memset (hm->pop_options, 0, sizeof (hm->pop_options)); |
| 816 | memset (hm->options_size, 0, sizeof (hm->options_size)); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 817 | |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 818 | vnet_classify_register_unformat_opaque_index_fn (unformat_opaque_ioam); |
| 819 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 820 | return (0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 823 | VLIB_INIT_FUNCTION (ip6_hop_by_hop_ioam_init); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 824 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 825 | int |
| 826 | ip6_ioam_set_rewrite (u8 ** rwp, int has_trace_option, |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 827 | int has_pot_option, int has_seqno_option) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 828 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 829 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 830 | u8 *rewrite = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 831 | u32 size, rnd_size; |
| 832 | ip6_hop_by_hop_header_t *hbh; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 833 | u8 *current; |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 834 | u8 *trace_data_size = NULL; |
| 835 | u8 *pot_data_size = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 836 | |
| 837 | vec_free (*rwp); |
| 838 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 839 | if (has_trace_option == 0 && has_pot_option == 0) |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 840 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 841 | |
| 842 | /* Work out how much space we need */ |
| 843 | size = sizeof (ip6_hop_by_hop_header_t); |
| 844 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 845 | //if (has_trace_option && hm->get_sizeof_options[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST] != 0) |
| 846 | if (has_trace_option |
| 847 | && hm->options_size[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST] != 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 848 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 849 | size += hm->options_size[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 850 | } |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 851 | if (has_pot_option |
| 852 | && hm->add_options[HBH_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT] != 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 853 | { |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 854 | size += hm->options_size[HBH_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 855 | } |
| 856 | |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 857 | if (has_seqno_option) |
| 858 | { |
| 859 | size += hm->options_size[HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE]; |
| 860 | } |
| 861 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 862 | /* Round to a multiple of 8 octets */ |
| 863 | rnd_size = (size + 7) & ~7; |
| 864 | |
| 865 | /* allocate it, zero-fill / pad by construction */ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 866 | vec_validate (rewrite, rnd_size - 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 867 | |
| 868 | hbh = (ip6_hop_by_hop_header_t *) rewrite; |
| 869 | /* Length of header in 8 octet units, not incl first 8 octets */ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 870 | hbh->length = (rnd_size >> 3) - 1; |
| 871 | current = (u8 *) (hbh + 1); |
| 872 | |
| 873 | if (has_trace_option |
| 874 | && hm->add_options[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST] != 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 875 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 876 | if (0 != (hm->options_size[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST])) |
| 877 | { |
| 878 | trace_data_size = |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 879 | &hm->options_size[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST]; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 880 | if (0 == |
| 881 | hm->add_options[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST] (current, |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 882 | trace_data_size)) |
| 883 | current += *trace_data_size; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 884 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 885 | } |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 886 | if (has_pot_option |
| 887 | && hm->add_options[HBH_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT] != 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 888 | { |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 889 | pot_data_size = |
| 890 | &hm->options_size[HBH_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT]; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 891 | if (0 == |
| 892 | hm->add_options[HBH_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT] (current, |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 893 | pot_data_size)) |
| 894 | current += *pot_data_size; |
| 895 | } |
| 896 | |
| 897 | if (has_seqno_option && |
| 898 | (hm->add_options[HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE] != 0)) |
| 899 | { |
| 900 | if (0 == hm->add_options[HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE] (current, |
| 901 | & |
| 902 | (hm->options_size |
| 903 | [HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE]))) |
| 904 | current += hm->options_size[HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 905 | } |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 906 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 907 | *rwp = rewrite; |
| 908 | return 0; |
| 909 | } |
| 910 | |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 911 | clib_error_t * |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 912 | clear_ioam_rewrite_fn (void) |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 913 | { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 914 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 915 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 916 | vec_free (hm->rewrite); |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 917 | hm->rewrite = 0; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 918 | hm->has_trace_option = 0; |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 919 | hm->has_pot_option = 0; |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 920 | hm->has_seqno_option = 0; |
| 921 | hm->has_analyse_option = 0; |
| 922 | if (hm->config_handler[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST]) |
| 923 | hm->config_handler[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST] (NULL, 1); |
| 924 | |
| 925 | if (hm->config_handler[HBH_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT]) |
| 926 | hm->config_handler[HBH_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT] (NULL, 1); |
| 927 | |
| 928 | if (hm->config_handler[HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE]) |
| 929 | { |
| 930 | hm->config_handler[HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE] ((void *) |
| 931 | &hm->has_analyse_option, |
| 932 | 1); |
| 933 | } |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 934 | |
| 935 | return 0; |
| 936 | } |
Shwetha | 20a64f5 | 2016-03-25 10:55:01 +0000 | [diff] [blame] | 937 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 938 | clib_error_t * |
| 939 | clear_ioam_rewrite_command_fn (vlib_main_t * vm, |
| 940 | unformat_input_t * input, |
| 941 | vlib_cli_command_t * cmd) |
Shwetha | 20a64f5 | 2016-03-25 10:55:01 +0000 | [diff] [blame] | 942 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 943 | return (clear_ioam_rewrite_fn ()); |
Shwetha | 20a64f5 | 2016-03-25 10:55:01 +0000 | [diff] [blame] | 944 | } |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 945 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 946 | /*? |
| 947 | * This command clears all the In-band OAM (iOAM) features enabled by |
| 948 | * the '<em>set ioam rewrite</em>' command. Use '<em>show ioam summary</em>' to |
| 949 | * verify the configured settings cleared. |
| 950 | * |
| 951 | * @cliexpar |
| 952 | * Example of how to clear iOAM features: |
| 953 | * @cliexcmd{clear ioam rewrite} |
| 954 | ?*/ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 955 | /* *INDENT-OFF* */ |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 956 | VLIB_CLI_COMMAND (ip6_clear_ioam_rewrite_cmd, static) = { |
| 957 | .path = "clear ioam rewrite", |
| 958 | .short_help = "clear ioam rewrite", |
| 959 | .function = clear_ioam_rewrite_command_fn, |
| 960 | }; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 961 | /* *INDENT-ON* */ |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 962 | |
| 963 | clib_error_t * |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 964 | ip6_ioam_enable (int has_trace_option, int has_pot_option, |
| 965 | int has_seqno_option, int has_analyse_option) |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 966 | { |
| 967 | int rv; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 968 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 969 | rv = ip6_ioam_set_rewrite (&hm->rewrite, has_trace_option, |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 970 | has_pot_option, has_seqno_option); |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 971 | |
| 972 | switch (rv) |
| 973 | { |
| 974 | case 0: |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 975 | if (has_trace_option) |
| 976 | { |
| 977 | hm->has_trace_option = has_trace_option; |
| 978 | if (hm->config_handler[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST]) |
| 979 | hm->config_handler[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST] (NULL, |
| 980 | 0); |
| 981 | } |
| 982 | |
| 983 | if (has_pot_option) |
| 984 | { |
| 985 | hm->has_pot_option = has_pot_option; |
| 986 | if (hm->config_handler[HBH_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT]) |
| 987 | hm->config_handler[HBH_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT] (NULL, |
| 988 | 0); |
| 989 | } |
| 990 | hm->has_analyse_option = has_analyse_option; |
| 991 | if (has_seqno_option) |
| 992 | { |
| 993 | hm->has_seqno_option = has_seqno_option; |
| 994 | if (hm->config_handler[HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE]) |
| 995 | { |
| 996 | hm->config_handler[HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE] ((void *) |
| 997 | &has_analyse_option, |
| 998 | 0); |
| 999 | } |
| 1000 | } |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1001 | break; |
| 1002 | |
| 1003 | default: |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1004 | return clib_error_return_code (0, rv, 0, |
| 1005 | "ip6_ioam_set_rewrite returned %d", rv); |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1012 | static clib_error_t * |
rangan | 2375fbd | 2016-03-04 22:23:25 +0530 | [diff] [blame] | 1013 | ip6_set_ioam_rewrite_command_fn (vlib_main_t * vm, |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1014 | unformat_input_t * input, |
| 1015 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1016 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1017 | int has_trace_option = 0; |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 1018 | int has_pot_option = 0; |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 1019 | int has_seqno_option = 0; |
| 1020 | int has_analyse_option = 0; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1021 | clib_error_t *rv = 0; |
| 1022 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1023 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 1024 | { |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1025 | if (unformat (input, "trace")) |
| 1026 | has_trace_option = 1; |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 1027 | else if (unformat (input, "pot")) |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1028 | has_pot_option = 1; |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 1029 | else if (unformat (input, "seqno")) |
| 1030 | has_seqno_option = 1; |
| 1031 | else if (unformat (input, "analyse")) |
| 1032 | has_analyse_option = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1033 | else |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1034 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1035 | } |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1036 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1037 | |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 1038 | rv = ip6_ioam_enable (has_trace_option, has_pot_option, |
| 1039 | has_seqno_option, has_analyse_option); |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1040 | |
| 1041 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1044 | /*? |
| 1045 | * This command is used to enable In-band OAM (iOAM) features on IPv6. |
| 1046 | * '<em>trace</em>' is used to enable iOAM trace feature. '<em>pot</em>' is used to |
| 1047 | * enable the Proof Of Transit feature. '<em>ppc</em>' is used to indicate the |
| 1048 | * Per Packet Counter feature for Edge to Edge processing. '<em>ppc</em>' is |
| 1049 | * used to indicate if this node is an '<em>encap</em>' node (iOAM edge node |
| 1050 | * where packet enters iOAM domain), a '<em>decap</em>' node (iOAM edge node |
| 1051 | * where packet leaves iOAM domain) or '<em>none</em>' (iOAM node where packet |
| 1052 | * is in-transit through the iOAM domain). '<em>ppc</em>' can only be set if |
| 1053 | * '<em>trace</em>' or '<em>pot</em>' is enabled. |
| 1054 | * |
| 1055 | * Use '<em>clear ioam rewrite</em>' to disable all features enabled by this |
| 1056 | * command. Use '<em>show ioam summary</em>' to verify the configured settings. |
| 1057 | * |
| 1058 | * @cliexpar |
| 1059 | * Example of how to enable trace and pot with ppc set to encap: |
| 1060 | * @cliexcmd{set ioam rewrite trace pot ppc encap} |
| 1061 | ?*/ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1062 | /* *INDENT-OFF* */ |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1063 | VLIB_CLI_COMMAND (ip6_set_ioam_rewrite_cmd, static) = { |
| 1064 | .path = "set ioam rewrite", |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 1065 | .short_help = "set ioam [trace] [pot] [seqno] [analyse]", |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1066 | .function = ip6_set_ioam_rewrite_command_fn, |
| 1067 | }; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1068 | /* *INDENT-ON* */ |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1069 | |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1070 | static clib_error_t * |
| 1071 | ip6_show_ioam_summary_cmd_fn (vlib_main_t * vm, |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1072 | unformat_input_t * input, |
| 1073 | vlib_cli_command_t * cmd) |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1074 | { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 1075 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1076 | u8 *s = 0; |
| 1077 | |
| 1078 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1079 | if (!is_zero_ip6_address (&hm->adj)) |
| 1080 | { |
| 1081 | s = format (s, " REWRITE FLOW CONFIGS - \n"); |
| 1082 | s = format (s, " Destination Address : %U\n", |
| 1083 | format_ip6_address, &hm->adj, sizeof (ip6_address_t)); |
| 1084 | s = |
| 1085 | format (s, " Flow operation : %d (%s)\n", |
| 1086 | hm->ioam_flag, |
| 1087 | (hm->ioam_flag == |
| 1088 | IOAM_HBYH_ADD) ? "Add" : ((hm->ioam_flag == |
| 1089 | IOAM_HBYH_MOD) ? "Mod" : "Pop")); |
| 1090 | } |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1091 | else |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1092 | { |
| 1093 | s = format (s, " REWRITE FLOW CONFIGS - Not configured\n"); |
| 1094 | } |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1095 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1096 | |
| 1097 | s = format (s, " TRACE OPTION - %d (%s)\n", |
| 1098 | hm->has_trace_option, |
| 1099 | (hm->has_trace_option ? "Enabled" : "Disabled")); |
| 1100 | if (hm->has_trace_option) |
| 1101 | s = |
| 1102 | format (s, |
| 1103 | "Try 'show ioam trace and show ioam-trace profile' for more information\n"); |
| 1104 | |
| 1105 | |
| 1106 | s = format (s, " POT OPTION - %d (%s)\n", |
| 1107 | hm->has_pot_option, |
| 1108 | (hm->has_pot_option ? "Enabled" : "Disabled")); |
Shwetha | 85b528e | 2016-06-15 16:34:16 +0100 | [diff] [blame] | 1109 | if (hm->has_pot_option) |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1110 | s = |
| 1111 | format (s, |
| 1112 | "Try 'show ioam pot and show pot profile' for more information\n"); |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1113 | |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 1114 | s = format (s, " EDGE TO EDGE - SeqNo OPTION - %d (%s)\n", |
| 1115 | hm->has_seqno_option, |
| 1116 | hm->has_seqno_option ? "Enabled" : "Disabled"); |
| 1117 | if (hm->has_seqno_option) |
| 1118 | s = format (s, "Try 'show ioam e2e' for more information\n"); |
| 1119 | |
| 1120 | s = format (s, " iOAM Analyse OPTION - %d (%s)\n", |
| 1121 | hm->has_analyse_option, |
| 1122 | hm->has_analyse_option ? "Enabled" : "Disabled"); |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1123 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1124 | vlib_cli_output (vm, "%v", s); |
| 1125 | vec_free (s); |
rangan | 4f81085 | 2016-03-18 03:31:17 +0530 | [diff] [blame] | 1126 | return 0; |
| 1127 | } |
| 1128 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1129 | /*? |
| 1130 | * This command displays the current configuration data for In-band |
| 1131 | * OAM (iOAM). |
| 1132 | * |
| 1133 | * @cliexpar |
| 1134 | * Example to show the iOAM configuration: |
| 1135 | * @cliexstart{show ioam summary} |
| 1136 | * REWRITE FLOW CONFIGS - |
| 1137 | * Destination Address : ff02::1 |
| 1138 | * Flow operation : 2 (Pop) |
| 1139 | * TRACE OPTION - 1 (Enabled) |
| 1140 | * Try 'show ioam trace and show ioam-trace profile' for more information |
| 1141 | * POT OPTION - 1 (Enabled) |
| 1142 | * Try 'show ioam pot and show pot profile' for more information |
| 1143 | * EDGE TO EDGE - PPC OPTION - 1 (Encap) |
| 1144 | * @cliexend |
| 1145 | ?*/ |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1146 | /* *INDENT-OFF* */ |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1147 | VLIB_CLI_COMMAND (ip6_show_ioam_run_cmd, static) = { |
| 1148 | .path = "show ioam summary", |
| 1149 | .short_help = "show ioam summary", |
| 1150 | .function = ip6_show_ioam_summary_cmd_fn, |
| 1151 | }; |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1152 | /* *INDENT-ON* */ |
| 1153 | |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1154 | void |
| 1155 | vnet_register_ioam_end_of_path_callback (void *cb) |
| 1156 | { |
| 1157 | ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1158 | |
| 1159 | hm->ioam_end_of_path_cb = cb; |
| 1160 | } |
Vengada Govindan | 07d2f84 | 2016-08-25 10:34:34 -0700 | [diff] [blame] | 1161 | |
| 1162 | /* |
| 1163 | * fd.io coding-style-patch-verification: ON |
| 1164 | * |
| 1165 | * Local Variables: |
| 1166 | * eval: (c-set-style "gnu") |
| 1167 | * End: |
| 1168 | */ |