Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sr_replicate.c: ipv6 segment routing replicator for multicast |
| 3 | * |
| 4 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
Keith Burns (alagalah) | ff07b87 | 2016-08-06 08:55:57 -0700 | [diff] [blame^] | 17 | /** |
| 18 | * @file |
| 19 | * @brief Functions for replicating packets across SR tunnels. |
| 20 | * |
| 21 | * Leverages rte_pktmbuf_clone() so there is no memcpy for |
| 22 | * invariant parts of the packet. |
| 23 | * |
| 24 | * @note Currently requires DPDK |
| 25 | */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 26 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 27 | #if DPDK > 0 /* Cannot run replicate without DPDK */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 28 | #include <vlib/vlib.h> |
| 29 | #include <vnet/vnet.h> |
| 30 | #include <vnet/pg/pg.h> |
| 31 | #include <vnet/sr/sr.h> |
| 32 | #include <vnet/devices/dpdk/dpdk.h> |
| 33 | #include <vnet/dpdk_replication.h> |
| 34 | #include <vnet/ip/ip.h> |
| 35 | |
| 36 | #include <vppinfra/hash.h> |
| 37 | #include <vppinfra/error.h> |
| 38 | #include <vppinfra/elog.h> |
| 39 | |
Keith Burns (alagalah) | ff07b87 | 2016-08-06 08:55:57 -0700 | [diff] [blame^] | 40 | /** |
| 41 | * @brief sr_replicate state. |
| 42 | * |
| 43 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 44 | typedef struct |
| 45 | { |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 46 | /* convenience */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 47 | vlib_main_t *vlib_main; |
| 48 | vnet_main_t *vnet_main; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 49 | } sr_replicate_main_t; |
| 50 | |
| 51 | sr_replicate_main_t sr_replicate_main; |
| 52 | |
Keith Burns (alagalah) | ff07b87 | 2016-08-06 08:55:57 -0700 | [diff] [blame^] | 53 | /** |
| 54 | * @brief Information to display in packet trace. |
| 55 | * |
| 56 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 57 | typedef struct |
| 58 | { |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 59 | ip6_address_t src, dst; |
| 60 | u16 length; |
| 61 | u32 next_index; |
| 62 | u32 tunnel_index; |
| 63 | u8 sr[256]; |
| 64 | } sr_replicate_trace_t; |
| 65 | |
Keith Burns (alagalah) | ff07b87 | 2016-08-06 08:55:57 -0700 | [diff] [blame^] | 66 | /** |
| 67 | * @brief packet trace format function. |
| 68 | * |
| 69 | * @param *s u8 used for string output |
| 70 | * @param *args va_list structured input to va_arg to output @ref sr_replicate_trace_t |
| 71 | * @return *s u8 - formatted trace output |
| 72 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 73 | static u8 * |
| 74 | format_sr_replicate_trace (u8 * s, va_list * args) |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 75 | { |
| 76 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 77 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 78 | sr_replicate_trace_t *t = va_arg (*args, sr_replicate_trace_t *); |
| 79 | ip6_main_t *im = &ip6_main; |
| 80 | ip6_sr_main_t *sm = &sr_main; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 81 | ip6_sr_tunnel_t *tun = pool_elt_at_index (sm->tunnels, t->tunnel_index); |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 82 | ip6_fib_t *rx_fib, *tx_fib; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 83 | |
| 84 | rx_fib = find_ip6_fib_by_table_index_or_id (im, tun->rx_fib_index, |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 85 | IP6_ROUTE_FLAG_FIB_INDEX); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 86 | |
| 87 | tx_fib = find_ip6_fib_by_table_index_or_id (im, tun->tx_fib_index, |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 88 | IP6_ROUTE_FLAG_FIB_INDEX); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 89 | |
| 90 | s = format |
| 91 | (s, "SR-REPLICATE: next %s ip6 src %U dst %U len %u\n" |
| 92 | " rx-fib-id %d tx-fib-id %d\n%U", |
| 93 | "ip6-lookup", |
| 94 | format_ip6_address, &t->src, |
| 95 | format_ip6_address, &t->dst, t->length, |
| 96 | rx_fib->table_id, tx_fib->table_id, |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 97 | format_ip6_sr_header, t->sr, 0 /* print_hmac */ ); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 98 | return s; |
| 99 | |
| 100 | } |
| 101 | |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 102 | #define foreach_sr_replicate_error \ |
| 103 | _(REPLICATED, "sr packets replicated") \ |
| 104 | _(NO_BUFFERS, "error allocating buffers for replicas") \ |
| 105 | _(NO_REPLICAS, "no replicas were needed") \ |
| 106 | _(NO_BUFFER_DROPS, "sr no buffer drops") |
| 107 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 108 | typedef enum |
| 109 | { |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 110 | #define _(sym,str) SR_REPLICATE_ERROR_##sym, |
| 111 | foreach_sr_replicate_error |
| 112 | #undef _ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 113 | SR_REPLICATE_N_ERROR, |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 114 | } sr_replicate_error_t; |
| 115 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 116 | static char *sr_replicate_error_strings[] = { |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 117 | #define _(sym,string) string, |
| 118 | foreach_sr_replicate_error |
| 119 | #undef _ |
| 120 | }; |
| 121 | |
Keith Burns (alagalah) | ff07b87 | 2016-08-06 08:55:57 -0700 | [diff] [blame^] | 122 | /** |
| 123 | * @brief Defines next-nodes for packet processing. |
| 124 | * |
| 125 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 126 | typedef enum |
| 127 | { |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 128 | SR_REPLICATE_NEXT_IP6_LOOKUP, |
| 129 | SR_REPLICATE_N_NEXT, |
| 130 | } sr_replicate_next_t; |
| 131 | |
Keith Burns (alagalah) | ff07b87 | 2016-08-06 08:55:57 -0700 | [diff] [blame^] | 132 | /** |
| 133 | * @brief Single loop packet replicator. |
| 134 | * |
| 135 | * @node sr-replicate |
| 136 | * @param vm vlib_main_t |
| 137 | * @return frame->n_vectors uword |
| 138 | */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 139 | static uword |
| 140 | sr_replicate_node_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 141 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 142 | { |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 143 | u32 n_left_from, *from, *to_next; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 144 | sr_replicate_next_t next_index; |
| 145 | int pkts_replicated = 0; |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 146 | ip6_sr_main_t *sm = &sr_main; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 147 | int no_buffer_drops = 0; |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 148 | vlib_buffer_free_list_t *fl; |
| 149 | unsigned socket_id = rte_socket_id (); |
| 150 | vlib_buffer_main_t *bm = vm->buffer_main; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 151 | |
| 152 | from = vlib_frame_vector_args (frame); |
| 153 | n_left_from = frame->n_vectors; |
| 154 | next_index = node->cached_next_index; |
| 155 | |
| 156 | fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); |
| 157 | |
| 158 | while (n_left_from > 0) |
| 159 | { |
| 160 | u32 n_left_to_next; |
| 161 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 162 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 163 | |
| 164 | while (n_left_from > 0 && n_left_to_next > 0) |
| 165 | { |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 166 | u32 bi0, hdr_bi0; |
| 167 | vlib_buffer_t *b0, *orig_b0; |
| 168 | struct rte_mbuf *orig_mb0 = 0, *hdr_mb0 = 0, *clone0 = 0; |
| 169 | struct rte_mbuf **hdr_vec = 0, **rte_mbuf_vec = 0; |
| 170 | ip6_sr_policy_t *pol0 = 0; |
| 171 | ip6_sr_tunnel_t *t0 = 0; |
| 172 | ip6_sr_header_t *hdr_sr0 = 0; |
| 173 | ip6_header_t *ip0 = 0, *hdr_ip0 = 0; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 174 | int num_replicas = 0; |
| 175 | int i; |
| 176 | |
| 177 | bi0 = from[0]; |
| 178 | |
| 179 | b0 = vlib_get_buffer (vm, bi0); |
| 180 | orig_b0 = b0; |
| 181 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 182 | pol0 = pool_elt_at_index (sm->policies, |
| 183 | vnet_buffer (b0)->ip.save_protocol); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 184 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 185 | ip0 = vlib_buffer_get_current (b0); |
| 186 | /* Skip forward to the punch-in point */ |
| 187 | vlib_buffer_advance (b0, sizeof (*ip0)); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 188 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 189 | orig_mb0 = rte_mbuf_from_vlib_buffer (b0); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 190 | |
| 191 | i16 delta0 = vlib_buffer_length_in_chain (vm, orig_b0) |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 192 | - (i16) orig_mb0->pkt_len; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 193 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 194 | u16 new_data_len0 = (u16) ((i16) orig_mb0->data_len + delta0); |
| 195 | u16 new_pkt_len0 = (u16) ((i16) orig_mb0->pkt_len + delta0); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 196 | |
| 197 | orig_mb0->data_len = new_data_len0; |
| 198 | orig_mb0->pkt_len = new_pkt_len0; |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 199 | orig_mb0->data_off = |
| 200 | (u16) (RTE_PKTMBUF_HEADROOM + b0->current_data); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 201 | |
| 202 | /* |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 203 | Before entering loop determine if we can allocate: |
| 204 | - all the new HEADER RTE_MBUFs and assign them to a vector |
| 205 | - all the clones |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 206 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 207 | if successful, then iterate over vectors of resources |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 208 | |
| 209 | */ |
| 210 | num_replicas = vec_len (pol0->tunnel_indices); |
| 211 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 212 | if (PREDICT_FALSE (num_replicas == 0)) |
| 213 | { |
| 214 | b0->error = node->errors[SR_REPLICATE_ERROR_NO_REPLICAS]; |
| 215 | goto do_trace0; |
| 216 | } |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 217 | |
| 218 | vec_reset_length (hdr_vec); |
| 219 | vec_reset_length (rte_mbuf_vec); |
| 220 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 221 | for (i = 0; i < num_replicas; i++) |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 222 | { |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 223 | hdr_mb0 = rte_pktmbuf_alloc (bm->pktmbuf_pools[socket_id]); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 224 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 225 | if (i < (num_replicas - 1)) |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 226 | /* Not the last tunnel to process */ |
| 227 | clone0 = rte_pktmbuf_clone |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 228 | (orig_mb0, bm->pktmbuf_pools[socket_id]); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 229 | else |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 230 | /* Last tunnel to process, use original MB */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 231 | clone0 = orig_mb0; |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 232 | |
| 233 | |
| 234 | if (PREDICT_FALSE (!clone0 || !hdr_mb0)) |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 235 | { |
| 236 | b0->error = node->errors[SR_REPLICATE_ERROR_NO_BUFFERS]; |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 237 | |
| 238 | vec_foreach_index (i, rte_mbuf_vec) |
| 239 | { |
| 240 | rte_pktmbuf_free (rte_mbuf_vec[i]); |
| 241 | } |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 242 | vec_free (rte_mbuf_vec); |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 243 | |
| 244 | vec_foreach_index (i, hdr_vec) |
| 245 | { |
| 246 | rte_pktmbuf_free (hdr_vec[i]); |
| 247 | } |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 248 | vec_free (hdr_vec); |
| 249 | |
| 250 | goto do_trace0; |
| 251 | } |
| 252 | |
| 253 | vec_add1 (hdr_vec, hdr_mb0); |
| 254 | vec_add1 (rte_mbuf_vec, clone0); |
| 255 | |
| 256 | } |
| 257 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 258 | for (i = 0; i < num_replicas; i++) |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 259 | { |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 260 | vlib_buffer_t *hdr_b0; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 261 | |
| 262 | t0 = vec_elt_at_index (sm->tunnels, pol0->tunnel_indices[i]); |
| 263 | |
| 264 | /* Our replicas */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 265 | hdr_mb0 = hdr_vec[i]; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 266 | clone0 = rte_mbuf_vec[i]; |
| 267 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 268 | hdr_mb0->data_len = sizeof (*ip0) + vec_len (t0->rewrite); |
| 269 | hdr_mb0->pkt_len = hdr_mb0->data_len + |
| 270 | vlib_buffer_length_in_chain (vm, orig_b0); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 271 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 272 | hdr_b0 = vlib_buffer_from_rte_mbuf (hdr_mb0); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 273 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 274 | vlib_buffer_init_for_free_list (hdr_b0, fl); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 275 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 276 | memcpy (hdr_b0->data, ip0, sizeof (*ip0)); |
| 277 | memcpy (hdr_b0->data + sizeof (*ip0), t0->rewrite, |
| 278 | vec_len (t0->rewrite)); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 279 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 280 | hdr_b0->current_data = 0; |
| 281 | hdr_b0->current_length = sizeof (*ip0) + vec_len (t0->rewrite); |
| 282 | hdr_b0->flags = orig_b0->flags | VLIB_BUFFER_NEXT_PRESENT; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 283 | |
| 284 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 285 | hdr_b0->total_length_not_including_first_buffer = |
| 286 | hdr_mb0->pkt_len - hdr_b0->current_length; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 287 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 288 | hdr_ip0 = (ip6_header_t *) hdr_b0->data; |
| 289 | hdr_ip0->payload_length = |
| 290 | clib_host_to_net_u16 (hdr_mb0->data_len); |
| 291 | hdr_sr0 = (ip6_sr_header_t *) (hdr_ip0 + 1); |
| 292 | hdr_sr0->protocol = hdr_ip0->protocol; |
| 293 | hdr_ip0->protocol = 43; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 294 | |
| 295 | /* Rewrite the ip6 dst address */ |
| 296 | hdr_ip0->dst_address.as_u64[0] = t0->first_hop.as_u64[0]; |
| 297 | hdr_ip0->dst_address.as_u64[1] = t0->first_hop.as_u64[1]; |
| 298 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 299 | sr_fix_hmac (sm, hdr_ip0, hdr_sr0); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 300 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 301 | /* prepend new header to invariant piece */ |
| 302 | hdr_mb0->next = clone0; |
| 303 | hdr_b0->next_buffer = |
| 304 | vlib_get_buffer_index (vm, |
| 305 | vlib_buffer_from_rte_mbuf (clone0)); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 306 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 307 | /* update header's fields */ |
| 308 | hdr_mb0->pkt_len = |
| 309 | (uint16_t) (hdr_mb0->data_len + clone0->pkt_len); |
| 310 | hdr_mb0->nb_segs = (uint8_t) (clone0->nb_segs + 1); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 311 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 312 | /* copy metadata from source packet */ |
| 313 | hdr_mb0->port = clone0->port; |
| 314 | hdr_mb0->vlan_tci = clone0->vlan_tci; |
| 315 | hdr_mb0->vlan_tci_outer = clone0->vlan_tci_outer; |
| 316 | hdr_mb0->tx_offload = clone0->tx_offload; |
| 317 | hdr_mb0->hash = clone0->hash; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 318 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 319 | hdr_mb0->ol_flags = clone0->ol_flags; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 320 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 321 | __rte_mbuf_sanity_check (hdr_mb0, 1); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 322 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 323 | hdr_bi0 = vlib_get_buffer_index (vm, hdr_b0); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 324 | |
| 325 | to_next[0] = hdr_bi0; |
| 326 | to_next += 1; |
| 327 | n_left_to_next -= 1; |
| 328 | |
| 329 | if (n_left_to_next == 0) |
| 330 | { |
| 331 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 332 | vlib_get_next_frame (vm, node, next_index, |
| 333 | to_next, n_left_to_next); |
| 334 | |
| 335 | } |
| 336 | pkts_replicated++; |
| 337 | } |
| 338 | |
| 339 | from += 1; |
| 340 | n_left_from -= 1; |
| 341 | |
| 342 | do_trace0: |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 343 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 344 | { |
| 345 | sr_replicate_trace_t *tr = vlib_add_trace (vm, node, |
| 346 | b0, sizeof (*tr)); |
| 347 | tr->tunnel_index = t0 - sm->tunnels; |
| 348 | tr->length = 0; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 349 | if (hdr_ip0) |
| 350 | { |
| 351 | memcpy (tr->src.as_u8, hdr_ip0->src_address.as_u8, |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 352 | sizeof (tr->src.as_u8)); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 353 | memcpy (tr->dst.as_u8, hdr_ip0->dst_address.as_u8, |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 354 | sizeof (tr->dst.as_u8)); |
| 355 | if (hdr_ip0->payload_length) |
| 356 | tr->length = clib_net_to_host_u16 |
| 357 | (hdr_ip0->payload_length); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 358 | } |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 359 | tr->next_index = next_index; |
| 360 | memcpy (tr->sr, hdr_sr0, sizeof (tr->sr)); |
| 361 | } |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 362 | |
| 363 | } |
| 364 | |
| 365 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 366 | } |
| 367 | |
| 368 | vlib_node_increment_counter (vm, sr_replicate_node.index, |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 369 | SR_REPLICATE_ERROR_REPLICATED, |
| 370 | pkts_replicated); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 371 | |
| 372 | vlib_node_increment_counter (vm, sr_replicate_node.index, |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 373 | SR_REPLICATE_ERROR_NO_BUFFER_DROPS, |
| 374 | no_buffer_drops); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 375 | |
| 376 | return frame->n_vectors; |
| 377 | } |
| 378 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 379 | /* *INDENT-OFF* */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 380 | VLIB_REGISTER_NODE (sr_replicate_node) = { |
| 381 | .function = sr_replicate_node_fn, |
| 382 | .name = "sr-replicate", |
| 383 | .vector_size = sizeof (u32), |
| 384 | .format_trace = format_sr_replicate_trace, |
| 385 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 386 | |
| 387 | .n_errors = ARRAY_LEN(sr_replicate_error_strings), |
| 388 | .error_strings = sr_replicate_error_strings, |
| 389 | |
| 390 | .n_next_nodes = SR_REPLICATE_N_NEXT, |
| 391 | |
| 392 | .next_nodes = { |
| 393 | [SR_REPLICATE_NEXT_IP6_LOOKUP] = "ip6-lookup", |
| 394 | }, |
| 395 | }; |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 396 | /* *INDENT-ON* */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 397 | |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 398 | VLIB_NODE_FUNCTION_MULTIARCH (sr_replicate_node, sr_replicate_node_fn) |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 399 | clib_error_t *sr_replicate_init (vlib_main_t * vm) |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 400 | { |
| 401 | sr_replicate_main_t *msm = &sr_replicate_main; |
| 402 | |
| 403 | msm->vlib_main = vm; |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 404 | msm->vnet_main = vnet_get_main (); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 409 | VLIB_INIT_FUNCTION (sr_replicate_init); |
Keith Burns (alagalah) | 21c33bb | 2016-05-02 13:13:46 -0700 | [diff] [blame] | 410 | |
| 411 | #endif /* DPDK */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 412 | |
| 413 | /* |
| 414 | * fd.io coding-style-patch-verification: ON |
| 415 | * |
| 416 | * Local Variables: |
| 417 | * eval: (c-set-style "gnu") |
| 418 | * End: |
| 419 | */ |