blob: fa5a68c31c2e8423a56740a93e7b83170bc0bef1 [file] [log] [blame]
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -07001/*
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)ff07b872016-08-06 08:55:57 -070017/**
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)52fc44d2016-03-25 09:38:50 -070026
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070027#if DPDK > 0 /* Cannot run replicate without DPDK */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070028#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>
Damjan Marion878c6092017-01-04 13:19:27 +010033#include <vnet/devices/dpdk/dpdk_priv.h>
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070034#include <vnet/ip/ip.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010035#include <vnet/fib/ip6_fib.h>
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070036
37#include <vppinfra/hash.h>
38#include <vppinfra/error.h>
39#include <vppinfra/elog.h>
40
Keith Burns (alagalah)ff07b872016-08-06 08:55:57 -070041/**
42 * @brief sr_replicate state.
43 *
44*/
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070045typedef struct
46{
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070047 /* convenience */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070048 vlib_main_t *vlib_main;
49 vnet_main_t *vnet_main;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070050} sr_replicate_main_t;
51
52sr_replicate_main_t sr_replicate_main;
53
Keith Burns (alagalah)ff07b872016-08-06 08:55:57 -070054/**
55 * @brief Information to display in packet trace.
56 *
57*/
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070058typedef struct
59{
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070060 ip6_address_t src, dst;
61 u16 length;
62 u32 next_index;
63 u32 tunnel_index;
64 u8 sr[256];
65} sr_replicate_trace_t;
66
Keith Burns (alagalah)ff07b872016-08-06 08:55:57 -070067/**
68 * @brief packet trace format function.
69 *
70 * @param *s u8 used for string output
71 * @param *args va_list structured input to va_arg to output @ref sr_replicate_trace_t
72 * @return *s u8 - formatted trace output
73*/
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070074static u8 *
75format_sr_replicate_trace (u8 * s, va_list * args)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070076{
77 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
78 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070079 sr_replicate_trace_t *t = va_arg (*args, sr_replicate_trace_t *);
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070080 ip6_sr_main_t *sm = &sr_main;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070081 ip6_sr_tunnel_t *tun = pool_elt_at_index (sm->tunnels, t->tunnel_index);
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070082 ip6_fib_t *rx_fib, *tx_fib;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070083
Neale Ranns0bfe5d82016-08-25 15:29:12 +010084 rx_fib = ip6_fib_get (tun->rx_fib_index);
85 tx_fib = ip6_fib_get (tun->tx_fib_index);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070086
87 s = format
88 (s, "SR-REPLICATE: next %s ip6 src %U dst %U len %u\n"
89 " rx-fib-id %d tx-fib-id %d\n%U",
90 "ip6-lookup",
91 format_ip6_address, &t->src,
92 format_ip6_address, &t->dst, t->length,
93 rx_fib->table_id, tx_fib->table_id,
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070094 format_ip6_sr_header, t->sr, 0 /* print_hmac */ );
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070095 return s;
96
97}
98
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070099#define foreach_sr_replicate_error \
100_(REPLICATED, "sr packets replicated") \
101_(NO_BUFFERS, "error allocating buffers for replicas") \
102_(NO_REPLICAS, "no replicas were needed") \
103_(NO_BUFFER_DROPS, "sr no buffer drops")
104
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700105/**
106 * @brief Struct for SR replicate errors
107 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700108typedef enum
109{
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700110#define _(sym,str) SR_REPLICATE_ERROR_##sym,
111 foreach_sr_replicate_error
112#undef _
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700113 SR_REPLICATE_N_ERROR,
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700114} sr_replicate_error_t;
115
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700116/**
117 * @brief Error strings for SR replicate
118 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700119static char *sr_replicate_error_strings[] = {
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700120#define _(sym,string) string,
121 foreach_sr_replicate_error
122#undef _
123};
124
Keith Burns (alagalah)ff07b872016-08-06 08:55:57 -0700125/**
126 * @brief Defines next-nodes for packet processing.
127 *
128*/
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700129typedef enum
130{
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700131 SR_REPLICATE_NEXT_IP6_LOOKUP,
132 SR_REPLICATE_N_NEXT,
133} sr_replicate_next_t;
134
Keith Burns (alagalah)ff07b872016-08-06 08:55:57 -0700135/**
136 * @brief Single loop packet replicator.
137 *
138 * @node sr-replicate
139 * @param vm vlib_main_t
140 * @return frame->n_vectors uword
141*/
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700142static uword
143sr_replicate_node_fn (vlib_main_t * vm,
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700144 vlib_node_runtime_t * node, vlib_frame_t * frame)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700145{
Damjan Marion878c6092017-01-04 13:19:27 +0100146 dpdk_main_t *dm = &dpdk_main;
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700147 u32 n_left_from, *from, *to_next;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700148 sr_replicate_next_t next_index;
149 int pkts_replicated = 0;
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700150 ip6_sr_main_t *sm = &sr_main;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700151 int no_buffer_drops = 0;
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700152 vlib_buffer_free_list_t *fl;
153 unsigned socket_id = rte_socket_id ();
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700154
155 from = vlib_frame_vector_args (frame);
156 n_left_from = frame->n_vectors;
157 next_index = node->cached_next_index;
158
159 fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
160
161 while (n_left_from > 0)
162 {
163 u32 n_left_to_next;
164
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700165 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700166
167 while (n_left_from > 0 && n_left_to_next > 0)
168 {
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700169 u32 bi0, hdr_bi0;
170 vlib_buffer_t *b0, *orig_b0;
171 struct rte_mbuf *orig_mb0 = 0, *hdr_mb0 = 0, *clone0 = 0;
172 struct rte_mbuf **hdr_vec = 0, **rte_mbuf_vec = 0;
173 ip6_sr_policy_t *pol0 = 0;
174 ip6_sr_tunnel_t *t0 = 0;
175 ip6_sr_header_t *hdr_sr0 = 0;
176 ip6_header_t *ip0 = 0, *hdr_ip0 = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700177 int num_replicas = 0;
178 int i;
Shwethab78292e2016-09-13 11:51:00 +0100179 u32 len_bytes = sizeof (ip6_header_t);
180 u8 next_hdr, ip_next_hdr = IPPROTO_IPV6_ROUTE;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700181
182 bi0 = from[0];
183
184 b0 = vlib_get_buffer (vm, bi0);
185 orig_b0 = b0;
186
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700187 pol0 = pool_elt_at_index (sm->policies,
188 vnet_buffer (b0)->ip.save_protocol);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700189
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700190 ip0 = vlib_buffer_get_current (b0);
191 /* Skip forward to the punch-in point */
192 vlib_buffer_advance (b0, sizeof (*ip0));
Shwethab78292e2016-09-13 11:51:00 +0100193 next_hdr = ip0->protocol;
194
195 /* HBH must immediately follow ipv6 header */
196 if (PREDICT_FALSE
197 (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
198 {
199 ip6_hop_by_hop_ext_t *ext_hdr =
200 (ip6_hop_by_hop_ext_t *) ip6_next_header (ip0);
201 u32 ext_hdr_len = 0;
202 ext_hdr_len = ip6_ext_header_len ((ip6_ext_header_t *) ext_hdr);
203 len_bytes += ext_hdr_len;
204 next_hdr = ext_hdr->next_hdr;
205 ext_hdr->next_hdr = IPPROTO_IPV6_ROUTE;
206 ip_next_hdr = IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS;
207 /* Skip forward to the punch-in point */
208 vlib_buffer_advance (b0, ext_hdr_len);
209
210 }
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700211
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700212 orig_mb0 = rte_mbuf_from_vlib_buffer (b0);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700213
214 i16 delta0 = vlib_buffer_length_in_chain (vm, orig_b0)
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700215 - (i16) orig_mb0->pkt_len;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700216
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700217 u16 new_data_len0 = (u16) ((i16) orig_mb0->data_len + delta0);
218 u16 new_pkt_len0 = (u16) ((i16) orig_mb0->pkt_len + delta0);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700219
220 orig_mb0->data_len = new_data_len0;
221 orig_mb0->pkt_len = new_pkt_len0;
Shwethab78292e2016-09-13 11:51:00 +0100222 orig_mb0->data_off += (u16) (b0->current_data);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700223
224 /*
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700225 Before entering loop determine if we can allocate:
226 - all the new HEADER RTE_MBUFs and assign them to a vector
227 - all the clones
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700228
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700229 if successful, then iterate over vectors of resources
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700230
231 */
232 num_replicas = vec_len (pol0->tunnel_indices);
233
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700234 if (PREDICT_FALSE (num_replicas == 0))
235 {
236 b0->error = node->errors[SR_REPLICATE_ERROR_NO_REPLICAS];
237 goto do_trace0;
238 }
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700239
240 vec_reset_length (hdr_vec);
241 vec_reset_length (rte_mbuf_vec);
242
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700243 for (i = 0; i < num_replicas; i++)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700244 {
Shwethab78292e2016-09-13 11:51:00 +0100245 uint8_t nb_seg;
246 struct rte_mbuf *clone0i;
247 vlib_buffer_t *clone0_c, *clone_b0;
248
249 t0 = vec_elt_at_index (sm->tunnels, pol0->tunnel_indices[i]);
Damjan Marion878c6092017-01-04 13:19:27 +0100250 hdr_mb0 = rte_pktmbuf_alloc (dm->pktmbuf_pools[socket_id]);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700251
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700252 if (i < (num_replicas - 1))
Shwethab78292e2016-09-13 11:51:00 +0100253 {
254 /* Not the last tunnel to process */
255 clone0 = rte_pktmbuf_clone
Damjan Marion878c6092017-01-04 13:19:27 +0100256 (orig_mb0, dm->pktmbuf_pools[socket_id]);
Dave Barachbd6462e2016-12-16 09:20:04 -0500257 if (clone0 == 0)
258 goto clone_fail;
Shwethab78292e2016-09-13 11:51:00 +0100259 nb_seg = 0;
260 clone0i = clone0;
261 clone0_c = NULL;
262 while ((clone0->nb_segs >= 1) && (nb_seg < clone0->nb_segs))
263 {
264
265 clone_b0 = vlib_buffer_from_rte_mbuf (clone0i);
266 vlib_buffer_init_for_free_list (clone_b0, fl);
267
268 ASSERT ((clone_b0->flags & VLIB_BUFFER_NEXT_PRESENT) ==
269 0);
270 ASSERT (clone_b0->current_data == 0);
271
272 clone_b0->current_data =
273 (clone0i->buf_addr + clone0i->data_off) -
274 (void *) clone_b0->data;
275
276 clone_b0->current_length = clone0i->data_len;
277 if (PREDICT_FALSE (clone0_c != NULL))
278 {
279 clone0_c->flags |= VLIB_BUFFER_NEXT_PRESENT;
280 clone0_c->next_buffer =
281 vlib_get_buffer_index (vm, clone_b0);
282 }
283 clone0_c = clone_b0;
284 clone0i = clone0i->next;
285 nb_seg++;
286 }
287 }
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700288 else
Shwethab78292e2016-09-13 11:51:00 +0100289 /* First tunnel to process, use original MB */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700290 clone0 = orig_mb0;
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700291
292
293 if (PREDICT_FALSE (!clone0 || !hdr_mb0))
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700294 {
Dave Barachbd6462e2016-12-16 09:20:04 -0500295 clone_fail:
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700296 b0->error = node->errors[SR_REPLICATE_ERROR_NO_BUFFERS];
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700297
298 vec_foreach_index (i, rte_mbuf_vec)
299 {
300 rte_pktmbuf_free (rte_mbuf_vec[i]);
301 }
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700302 vec_free (rte_mbuf_vec);
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700303
304 vec_foreach_index (i, hdr_vec)
305 {
306 rte_pktmbuf_free (hdr_vec[i]);
307 }
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700308 vec_free (hdr_vec);
309
310 goto do_trace0;
311 }
312
313 vec_add1 (hdr_vec, hdr_mb0);
314 vec_add1 (rte_mbuf_vec, clone0);
315
316 }
317
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700318 for (i = 0; i < num_replicas; i++)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700319 {
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700320 vlib_buffer_t *hdr_b0;
Shwethab78292e2016-09-13 11:51:00 +0100321 u16 new_l0 = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700322
323 t0 = vec_elt_at_index (sm->tunnels, pol0->tunnel_indices[i]);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700324 /* Our replicas */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700325 hdr_mb0 = hdr_vec[i];
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700326 clone0 = rte_mbuf_vec[i];
327
Shwethab78292e2016-09-13 11:51:00 +0100328 hdr_mb0->data_len = len_bytes + vec_len (t0->rewrite);
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700329 hdr_mb0->pkt_len = hdr_mb0->data_len +
330 vlib_buffer_length_in_chain (vm, orig_b0);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700331
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700332 hdr_b0 = vlib_buffer_from_rte_mbuf (hdr_mb0);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700333
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700334 vlib_buffer_init_for_free_list (hdr_b0, fl);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700335
Shwethab78292e2016-09-13 11:51:00 +0100336 memcpy (hdr_b0->data, ip0, len_bytes);
337 memcpy (hdr_b0->data + len_bytes, t0->rewrite,
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700338 vec_len (t0->rewrite));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700339
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700340 hdr_b0->current_data = 0;
Shwethab78292e2016-09-13 11:51:00 +0100341 hdr_b0->current_length = len_bytes + vec_len (t0->rewrite);
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700342 hdr_b0->flags = orig_b0->flags | VLIB_BUFFER_NEXT_PRESENT;
Shwethab78292e2016-09-13 11:51:00 +0100343 hdr_b0->trace_index = orig_b0->trace_index;
344 vnet_buffer (hdr_b0)->l2_classify.opaque_index = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700345
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700346 hdr_b0->total_length_not_including_first_buffer =
347 hdr_mb0->pkt_len - hdr_b0->current_length;
Shwethab78292e2016-09-13 11:51:00 +0100348 vnet_buffer (hdr_b0)->sw_if_index[VLIB_TX] = t0->tx_fib_index;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700349
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700350 hdr_ip0 = (ip6_header_t *) hdr_b0->data;
Shwethab78292e2016-09-13 11:51:00 +0100351 new_l0 = clib_net_to_host_u16 (ip0->payload_length) +
352 vec_len (t0->rewrite);
353 hdr_ip0->payload_length = clib_host_to_net_u16 (new_l0);
354 hdr_sr0 = (ip6_sr_header_t *) ((u8 *) hdr_ip0 + len_bytes);
355 /* $$$ tune */
356 clib_memcpy (hdr_sr0, t0->rewrite, vec_len (t0->rewrite));
357 hdr_sr0->protocol = next_hdr;
358 hdr_ip0->protocol = ip_next_hdr;
359
360 /* Copy dst address into the DA slot in the segment list */
361 clib_memcpy (hdr_sr0->segments, ip0->dst_address.as_u64,
362 sizeof (ip6_address_t));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700363
364 /* Rewrite the ip6 dst address */
365 hdr_ip0->dst_address.as_u64[0] = t0->first_hop.as_u64[0];
366 hdr_ip0->dst_address.as_u64[1] = t0->first_hop.as_u64[1];
367
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700368 sr_fix_hmac (sm, hdr_ip0, hdr_sr0);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700369
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700370 /* prepend new header to invariant piece */
371 hdr_mb0->next = clone0;
372 hdr_b0->next_buffer =
373 vlib_get_buffer_index (vm,
374 vlib_buffer_from_rte_mbuf (clone0));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700375
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700376 /* update header's fields */
377 hdr_mb0->pkt_len =
378 (uint16_t) (hdr_mb0->data_len + clone0->pkt_len);
379 hdr_mb0->nb_segs = (uint8_t) (clone0->nb_segs + 1);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700380
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700381 /* copy metadata from source packet */
382 hdr_mb0->port = clone0->port;
383 hdr_mb0->vlan_tci = clone0->vlan_tci;
384 hdr_mb0->vlan_tci_outer = clone0->vlan_tci_outer;
385 hdr_mb0->tx_offload = clone0->tx_offload;
386 hdr_mb0->hash = clone0->hash;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700387
Shwethab78292e2016-09-13 11:51:00 +0100388 hdr_mb0->ol_flags = clone0->ol_flags & ~(IND_ATTACHED_MBUF);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700389
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700390 __rte_mbuf_sanity_check (hdr_mb0, 1);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700391
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700392 hdr_bi0 = vlib_get_buffer_index (vm, hdr_b0);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700393
394 to_next[0] = hdr_bi0;
395 to_next += 1;
396 n_left_to_next -= 1;
397
398 if (n_left_to_next == 0)
399 {
400 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
401 vlib_get_next_frame (vm, node, next_index,
402 to_next, n_left_to_next);
403
404 }
405 pkts_replicated++;
406 }
407
408 from += 1;
409 n_left_from -= 1;
410
411 do_trace0:
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700412 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
413 {
414 sr_replicate_trace_t *tr = vlib_add_trace (vm, node,
415 b0, sizeof (*tr));
416 tr->tunnel_index = t0 - sm->tunnels;
417 tr->length = 0;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700418 if (hdr_ip0)
419 {
420 memcpy (tr->src.as_u8, hdr_ip0->src_address.as_u8,
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700421 sizeof (tr->src.as_u8));
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700422 memcpy (tr->dst.as_u8, hdr_ip0->dst_address.as_u8,
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700423 sizeof (tr->dst.as_u8));
424 if (hdr_ip0->payload_length)
425 tr->length = clib_net_to_host_u16
426 (hdr_ip0->payload_length);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700427 }
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700428 tr->next_index = next_index;
Ed Warnicke853e7202016-08-12 11:42:26 -0700429 if (hdr_sr0)
430 memcpy (tr->sr, hdr_sr0, sizeof (tr->sr));
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700431 }
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700432
433 }
434
435 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
436 }
437
438 vlib_node_increment_counter (vm, sr_replicate_node.index,
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700439 SR_REPLICATE_ERROR_REPLICATED,
440 pkts_replicated);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700441
442 vlib_node_increment_counter (vm, sr_replicate_node.index,
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700443 SR_REPLICATE_ERROR_NO_BUFFER_DROPS,
444 no_buffer_drops);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700445
446 return frame->n_vectors;
447}
448
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700449/* *INDENT-OFF* */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700450VLIB_REGISTER_NODE (sr_replicate_node) = {
451 .function = sr_replicate_node_fn,
452 .name = "sr-replicate",
453 .vector_size = sizeof (u32),
454 .format_trace = format_sr_replicate_trace,
455 .type = VLIB_NODE_TYPE_INTERNAL,
456
457 .n_errors = ARRAY_LEN(sr_replicate_error_strings),
458 .error_strings = sr_replicate_error_strings,
459
460 .n_next_nodes = SR_REPLICATE_N_NEXT,
461
462 .next_nodes = {
463 [SR_REPLICATE_NEXT_IP6_LOOKUP] = "ip6-lookup",
464 },
465};
466
Damjan Marion1c80e832016-05-11 23:07:18 +0200467VLIB_NODE_FUNCTION_MULTIARCH (sr_replicate_node, sr_replicate_node_fn)
Damjan Marione33b9e02016-10-17 12:51:18 +0200468/* *INDENT-ON* */
469
470clib_error_t *
471sr_replicate_init (vlib_main_t * vm)
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700472{
473 sr_replicate_main_t *msm = &sr_replicate_main;
474
475 msm->vlib_main = vm;
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700476 msm->vnet_main = vnet_get_main ();
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700477
478 return 0;
479}
480
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700481VLIB_INIT_FUNCTION (sr_replicate_init);
Keith Burns (alagalah)21c33bb2016-05-02 13:13:46 -0700482
483#endif /* DPDK */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700484
485/*
486 * fd.io coding-style-patch-verification: ON
487 *
488 * Local Variables:
489 * eval: (c-set-style "gnu")
490 * End:
491 */