FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gtpu_encap.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Intel and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <vppinfra/error.h>
16 #include <vppinfra/hash.h>
17 #include <vnet/vnet.h>
18 #include <vnet/ip/ip.h>
19 #include <vnet/ethernet/ethernet.h>
20 #include <gtpu/gtpu.h>
21 
22 /* Statistics (not all errors) */
23 #define foreach_gtpu_encap_error \
24 _(ENCAPSULATED, "good packets encapsulated")
25 
26 static char * gtpu_encap_error_strings[] = {
27 #define _(sym,string) string,
29 #undef _
30 };
31 
32 typedef enum {
33 #define _(sym,str) GTPU_ENCAP_ERROR_##sym,
35 #undef _
38 
39 #define foreach_gtpu_encap_next \
40 _(DROP, "error-drop") \
41 _(IP4_LOOKUP, "ip4-lookup") \
42 _(IP6_LOOKUP, "ip6-lookup")
43 
44 typedef enum {
50 
51 
52 #define foreach_fixed_header4_offset \
53  _(0) _(1) _(2) _(3)
54 
55 #define foreach_fixed_header6_offset \
56  _(0) _(1) _(2) _(3) _(4) _(5) _(6)
57 
62  u32 is_ip4)
63 {
64  u32 n_left_from, next_index, * from, * to_next;
65  gtpu_main_t * gtm = &gtpu_main;
66  vnet_main_t * vnm = gtm->vnet_main;
68  u32 pkts_encapsulated = 0;
69  u16 old_l0 = 0, old_l1 = 0, old_l2 = 0, old_l3 = 0;
71  u32 stats_sw_if_index, stats_n_packets, stats_n_bytes;
72  u32 sw_if_index0 = 0, sw_if_index1 = 0, sw_if_index2 = 0, sw_if_index3 = 0;
73  u32 next0 = 0, next1 = 0, next2 = 0, next3 = 0;
74  vnet_hw_interface_t * hi0, * hi1, * hi2, * hi3;
75  gtpu_tunnel_t * t0 = NULL, * t1 = NULL, * t2 = NULL, * t3 = NULL;
76 
78  n_left_from = from_frame->n_vectors;
79 
80  next_index = node->cached_next_index;
81  stats_sw_if_index = node->runtime_data[0];
82  stats_n_packets = stats_n_bytes = 0;
83 
84  while (n_left_from > 0)
85  {
86  u32 n_left_to_next;
87 
89  to_next, n_left_to_next);
90 
91  while (n_left_from >= 8 && n_left_to_next >= 4)
92  {
93  u32 bi0, bi1, bi2, bi3;
94  vlib_buffer_t * b0, * b1, * b2, * b3;
95  u32 flow_hash0, flow_hash1, flow_hash2, flow_hash3;
96  u32 len0, len1, len2, len3;
97  ip4_header_t * ip4_0, * ip4_1, * ip4_2, * ip4_3;
98  ip6_header_t * ip6_0, * ip6_1, * ip6_2, * ip6_3;
99  udp_header_t * udp0, * udp1, * udp2, * udp3;
100  gtpu_header_t * gtpu0, * gtpu1, * gtpu2, * gtpu3;
101  u64 * copy_src0, * copy_dst0;
102  u64 * copy_src1, * copy_dst1;
103  u64 * copy_src2, * copy_dst2;
104  u64 * copy_src3, * copy_dst3;
105  u32 * copy_src_last0, * copy_dst_last0;
106  u32 * copy_src_last1, * copy_dst_last1;
107  u32 * copy_src_last2, * copy_dst_last2;
108  u32 * copy_src_last3, * copy_dst_last3;
109  u16 new_l0, new_l1, new_l2, new_l3;
110  ip_csum_t sum0, sum1, sum2, sum3;
111 
112  /* Prefetch next iteration. */
113  {
114  vlib_buffer_t * p4, * p5, * p6, * p7;
115 
116  p4 = vlib_get_buffer (vm, from[4]);
117  p5 = vlib_get_buffer (vm, from[5]);
118  p6 = vlib_get_buffer (vm, from[6]);
119  p7 = vlib_get_buffer (vm, from[7]);
120 
121  vlib_prefetch_buffer_header (p4, LOAD);
122  vlib_prefetch_buffer_header (p5, LOAD);
123  vlib_prefetch_buffer_header (p6, LOAD);
124  vlib_prefetch_buffer_header (p7, LOAD);
125 
130  }
131 
132  bi0 = from[0];
133  bi1 = from[1];
134  bi2 = from[2];
135  bi3 = from[3];
136  to_next[0] = bi0;
137  to_next[1] = bi1;
138  to_next[2] = bi2;
139  to_next[3] = bi3;
140  from += 4;
141  to_next += 4;
142  n_left_to_next -= 4;
143  n_left_from -= 4;
144 
145  b0 = vlib_get_buffer (vm, bi0);
146  b1 = vlib_get_buffer (vm, bi1);
147  b2 = vlib_get_buffer (vm, bi2);
148  b3 = vlib_get_buffer (vm, bi3);
149 
150  flow_hash0 = vnet_l2_compute_flow_hash (b0);
151  flow_hash1 = vnet_l2_compute_flow_hash (b1);
152  flow_hash2 = vnet_l2_compute_flow_hash (b2);
153  flow_hash3 = vnet_l2_compute_flow_hash (b3);
154 
155  /* Get next node index and adj index from tunnel next_dpo */
156  sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_TX];
157  sw_if_index1 = vnet_buffer(b1)->sw_if_index[VLIB_TX];
158  sw_if_index2 = vnet_buffer(b2)->sw_if_index[VLIB_TX];
159  sw_if_index3 = vnet_buffer(b3)->sw_if_index[VLIB_TX];
160  hi0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
161  hi1 = vnet_get_sup_hw_interface (vnm, sw_if_index1);
162  hi2 = vnet_get_sup_hw_interface (vnm, sw_if_index2);
163  hi3 = vnet_get_sup_hw_interface (vnm, sw_if_index3);
164  t0 = &gtm->tunnels[hi0->dev_instance];
165  t1 = &gtm->tunnels[hi1->dev_instance];
166  t2 = &gtm->tunnels[hi2->dev_instance];
167  t3 = &gtm->tunnels[hi3->dev_instance];
168 
169  /* Note: change to always set next0 if it may be set to drop */
170  next0 = t0->next_dpo.dpoi_next_node;
171  vnet_buffer(b0)->ip.adj_index[VLIB_TX] = t0->next_dpo.dpoi_index;
172  next1 = t1->next_dpo.dpoi_next_node;
173  vnet_buffer(b1)->ip.adj_index[VLIB_TX] = t1->next_dpo.dpoi_index;
174  next2 = t2->next_dpo.dpoi_next_node;
175  vnet_buffer(b2)->ip.adj_index[VLIB_TX] = t2->next_dpo.dpoi_index;
176  next3 = t3->next_dpo.dpoi_next_node;
177  vnet_buffer(b3)->ip.adj_index[VLIB_TX] = t3->next_dpo.dpoi_index;
178 
179  /* Apply the rewrite string. $$$$ vnet_rewrite? */
180  vlib_buffer_advance (b0, -(word)_vec_len(t0->rewrite));
181  vlib_buffer_advance (b1, -(word)_vec_len(t1->rewrite));
182  vlib_buffer_advance (b2, -(word)_vec_len(t2->rewrite));
183  vlib_buffer_advance (b3, -(word)_vec_len(t3->rewrite));
184 
185  if (is_ip4)
186  {
187  ip4_0 = vlib_buffer_get_current(b0);
188  ip4_1 = vlib_buffer_get_current(b1);
189  ip4_2 = vlib_buffer_get_current(b2);
190  ip4_3 = vlib_buffer_get_current(b3);
191 
192  /* Copy the fixed header */
193  copy_dst0 = (u64 *) ip4_0;
194  copy_src0 = (u64 *) t0->rewrite;
195  copy_dst1 = (u64 *) ip4_1;
196  copy_src1 = (u64 *) t1->rewrite;
197  copy_dst2 = (u64 *) ip4_2;
198  copy_src2 = (u64 *) t2->rewrite;
199  copy_dst3 = (u64 *) ip4_3;
200  copy_src3 = (u64 *) t3->rewrite;
201 
202  /* Copy first 32 octets 8-bytes at a time */
203 #define _(offs) copy_dst0[offs] = copy_src0[offs];
205 #undef _
206 #define _(offs) copy_dst1[offs] = copy_src1[offs];
208 #undef _
209 #define _(offs) copy_dst2[offs] = copy_src2[offs];
211 #undef _
212 #define _(offs) copy_dst3[offs] = copy_src3[offs];
214 #undef _
215  /* Last 4 octets. Hopefully gcc will be our friend */
216  copy_dst_last0 = (u32 *)(&copy_dst0[4]);
217  copy_src_last0 = (u32 *)(&copy_src0[4]);
218  copy_dst_last0[0] = copy_src_last0[0];
219  copy_dst_last1 = (u32 *)(&copy_dst1[4]);
220  copy_src_last1 = (u32 *)(&copy_src1[4]);
221  copy_dst_last1[0] = copy_src_last1[0];
222  copy_dst_last2 = (u32 *)(&copy_dst2[4]);
223  copy_src_last2 = (u32 *)(&copy_src2[4]);
224  copy_dst_last2[0] = copy_src_last2[0];
225  copy_dst_last3 = (u32 *)(&copy_dst3[4]);
226  copy_src_last3 = (u32 *)(&copy_src3[4]);
227  copy_dst_last3[0] = copy_src_last3[0];
228 
229  /* Fix the IP4 checksum and length */
230  sum0 = ip4_0->checksum;
231  new_l0 = /* old_l0 always 0, see the rewrite setup */
232  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
233  sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
234  length /* changed member */);
235  ip4_0->checksum = ip_csum_fold (sum0);
236  ip4_0->length = new_l0;
237  sum1 = ip4_1->checksum;
238  new_l1 = /* old_l1 always 0, see the rewrite setup */
239  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b1));
240  sum1 = ip_csum_update (sum1, old_l1, new_l1, ip4_header_t,
241  length /* changed member */);
242  ip4_1->checksum = ip_csum_fold (sum1);
243  ip4_1->length = new_l1;
244  sum2 = ip4_2->checksum;
245  new_l2 = /* old_l0 always 0, see the rewrite setup */
246  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b2));
247  sum2 = ip_csum_update (sum2, old_l2, new_l2, ip4_header_t,
248  length /* changed member */);
249  ip4_2->checksum = ip_csum_fold (sum2);
250  ip4_2->length = new_l2;
251  sum3 = ip4_3->checksum;
252  new_l3 = /* old_l1 always 0, see the rewrite setup */
253  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b3));
254  sum3 = ip_csum_update (sum3, old_l3, new_l3, ip4_header_t,
255  length /* changed member */);
256  ip4_3->checksum = ip_csum_fold (sum3);
257  ip4_3->length = new_l3;
258 
259  /* Fix UDP length and set source port */
260  udp0 = (udp_header_t *)(ip4_0+1);
261  new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b0)
262  - sizeof (*ip4_0));
263  udp0->length = new_l0;
264  udp0->src_port = flow_hash0;
265  udp1 = (udp_header_t *)(ip4_1+1);
266  new_l1 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b1)
267  - sizeof (*ip4_1));
268  udp1->length = new_l1;
269  udp1->src_port = flow_hash1;
270  udp2 = (udp_header_t *)(ip4_2+1);
271  new_l2 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b2)
272  - sizeof (*ip4_2));
273  udp2->length = new_l2;
274  udp2->src_port = flow_hash2;
275  udp3 = (udp_header_t *)(ip4_3+1);
276  new_l3 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b3)
277  - sizeof (*ip4_3));
278  udp3->length = new_l3;
279  udp3->src_port = flow_hash3;
280 
281  /* Fix GTPU length */
282  gtpu0 = (gtpu_header_t *)(udp0+1);
283  new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b0)
284  - sizeof (*ip4_0) - sizeof(*udp0)
285  - GTPU_V1_HDR_LEN);
286  gtpu0->length = new_l0;
287  gtpu1 = (gtpu_header_t *)(udp1+1);
288  new_l1 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b1)
289  - sizeof (*ip4_1) - sizeof(*udp1)
290  - GTPU_V1_HDR_LEN);
291  gtpu1->length = new_l1;
292  gtpu2 = (gtpu_header_t *)(udp2+1);
293  new_l2 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b2)
294  - sizeof (*ip4_2) - sizeof(*udp2)
295  - GTPU_V1_HDR_LEN);
296  gtpu2->length = new_l2;
297  gtpu3 = (gtpu_header_t *)(udp3+1);
298  new_l3 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b3)
299  - sizeof (*ip4_3) - sizeof(*udp3)
300  - GTPU_V1_HDR_LEN);
301  gtpu3->length = new_l3;
302  }
303  else /* ipv6 */
304  {
305  int bogus = 0;
306 
307  ip6_0 = vlib_buffer_get_current(b0);
308  ip6_1 = vlib_buffer_get_current(b1);
309  ip6_2 = vlib_buffer_get_current(b2);
310  ip6_3 = vlib_buffer_get_current(b3);
311 
312  /* Copy the fixed header */
313  copy_dst0 = (u64 *) ip6_0;
314  copy_src0 = (u64 *) t0->rewrite;
315  copy_dst1 = (u64 *) ip6_1;
316  copy_src1 = (u64 *) t1->rewrite;
317  copy_dst2 = (u64 *) ip6_2;
318  copy_src2 = (u64 *) t2->rewrite;
319  copy_dst3 = (u64 *) ip6_3;
320  copy_src3 = (u64 *) t3->rewrite;
321  /* Copy first 56 (ip6) octets 8-bytes at a time */
322 #define _(offs) copy_dst0[offs] = copy_src0[offs];
324 #undef _
325 #define _(offs) copy_dst1[offs] = copy_src1[offs];
327 #undef _
328 #define _(offs) copy_dst2[offs] = copy_src2[offs];
330 #undef _
331 #define _(offs) copy_dst3[offs] = copy_src3[offs];
333 #undef _
334  /* Fix IP6 payload length */
335  new_l0 =
336  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)
337  - sizeof(*ip6_0));
338  ip6_0->payload_length = new_l0;
339  new_l1 =
340  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b1)
341  - sizeof(*ip6_1));
342  ip6_1->payload_length = new_l1;
343  new_l2 =
344  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b2)
345  - sizeof(*ip6_2));
346  ip6_2->payload_length = new_l2;
347  new_l3 =
348  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b3)
349  - sizeof(*ip6_3));
350  ip6_3->payload_length = new_l3;
351 
352  /* Fix UDP length and set source port */
353  udp0 = (udp_header_t *)(ip6_0+1);
354  udp0->length = new_l0;
355  udp0->src_port = flow_hash0;
356  udp1 = (udp_header_t *)(ip6_1+1);
357  udp1->length = new_l1;
358  udp1->src_port = flow_hash1;
359  udp2 = (udp_header_t *)(ip6_2+1);
360  udp2->length = new_l2;
361  udp2->src_port = flow_hash2;
362  udp3 = (udp_header_t *)(ip6_3+1);
363  udp3->length = new_l3;
364  udp3->src_port = flow_hash3;
365 
366  /* Fix GTPU length */
367  gtpu0 = (gtpu_header_t *)(udp0+1);
368  new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b0)
369  - sizeof (*ip6_0) - sizeof(*udp0)
370  - GTPU_V1_HDR_LEN);
371  gtpu0->length = new_l0;
372  gtpu1 = (gtpu_header_t *)(udp1+1);
373  new_l1 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b1)
374  - sizeof (*ip6_1) - sizeof(*udp1)
375  - GTPU_V1_HDR_LEN);
376  gtpu1->length = new_l1;
377  gtpu2 = (gtpu_header_t *)(udp2+1);
378  new_l2 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b2)
379  - sizeof (*ip6_2) - sizeof(*udp2)
380  - GTPU_V1_HDR_LEN);
381  gtpu2->length = new_l2;
382  gtpu3 = (gtpu_header_t *)(udp3+1);
383  new_l3 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b3)
384  - sizeof (*ip6_3) - sizeof(*udp3)
385  - GTPU_V1_HDR_LEN);
386  gtpu3->length = new_l3;
387 
388  /* IPv6 UDP checksum is mandatory */
390  ip6_0, &bogus);
391  if (udp0->checksum == 0)
392  udp0->checksum = 0xffff;
394  ip6_1, &bogus);
395  if (udp1->checksum == 0)
396  udp1->checksum = 0xffff;
398  ip6_2, &bogus);
399  if (udp2->checksum == 0)
400  udp2->checksum = 0xffff;
402  ip6_3, &bogus);
403  if (udp3->checksum == 0)
404  udp3->checksum = 0xffff;
405 
406  }
407 
408  pkts_encapsulated += 4;
409  len0 = vlib_buffer_length_in_chain (vm, b0);
410  len1 = vlib_buffer_length_in_chain (vm, b1);
411  len2 = vlib_buffer_length_in_chain (vm, b2);
412  len3 = vlib_buffer_length_in_chain (vm, b3);
413  stats_n_packets += 4;
414  stats_n_bytes += len0 + len1 + len2 + len3;
415 
416  /* save inner packet flow_hash for load-balance node */
417  vnet_buffer (b0)->ip.flow_hash = flow_hash0;
418  vnet_buffer (b1)->ip.flow_hash = flow_hash1;
419  vnet_buffer (b2)->ip.flow_hash = flow_hash2;
420  vnet_buffer (b3)->ip.flow_hash = flow_hash3;
421 
422  /* Batch stats increment on the same gtpu tunnel so counter is not
423  incremented per packet. Note stats are still incremented for deleted
424  and admin-down tunnel where packets are dropped. It is not worthwhile
425  to check for this rare case and affect normal path performance. */
426  if (PREDICT_FALSE ((sw_if_index0 != stats_sw_if_index) ||
427  (sw_if_index1 != stats_sw_if_index) ||
428  (sw_if_index2 != stats_sw_if_index) ||
429  (sw_if_index3 != stats_sw_if_index) ))
430  {
431  stats_n_packets -= 4;
432  stats_n_bytes -= len0 + len1 + len2 + len3;
433  if ( (sw_if_index0 == sw_if_index1 ) &&
434  (sw_if_index1 == sw_if_index2 ) &&
435  (sw_if_index2 == sw_if_index3 ) )
436  {
437  if (stats_n_packets)
440  thread_index, stats_sw_if_index,
441  stats_n_packets, stats_n_bytes);
442  stats_sw_if_index = sw_if_index0;
443  stats_n_packets = 4;
444  stats_n_bytes = len0 + len1 + len2 + len3;
445  }
446  else
447  {
450  thread_index, sw_if_index0, 1, len0);
453  thread_index, sw_if_index1, 1, len1);
456  thread_index, sw_if_index2, 1, len2);
459  thread_index, sw_if_index3, 1, len3);
460  }
461  }
462 
463  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
464  {
465  gtpu_encap_trace_t *tr =
466  vlib_add_trace (vm, node, b0, sizeof (*tr));
467  tr->tunnel_index = t0 - gtm->tunnels;
468  tr->tteid = t0->tteid;
469  }
470 
471  if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED))
472  {
473  gtpu_encap_trace_t *tr =
474  vlib_add_trace (vm, node, b1, sizeof (*tr));
475  tr->tunnel_index = t1 - gtm->tunnels;
476  tr->tteid = t1->tteid;
477  }
478 
479  if (PREDICT_FALSE(b2->flags & VLIB_BUFFER_IS_TRACED))
480  {
481  gtpu_encap_trace_t *tr =
482  vlib_add_trace (vm, node, b2, sizeof (*tr));
483  tr->tunnel_index = t2 - gtm->tunnels;
484  tr->tteid = t2->tteid;
485  }
486 
487  if (PREDICT_FALSE(b3->flags & VLIB_BUFFER_IS_TRACED))
488  {
489  gtpu_encap_trace_t *tr =
490  vlib_add_trace (vm, node, b3, sizeof (*tr));
491  tr->tunnel_index = t3 - gtm->tunnels;
492  tr->tteid = t3->tteid;
493  }
494 
496  to_next, n_left_to_next,
497  bi0, bi1, bi2, bi3,
498  next0, next1, next2, next3);
499  }
500 
501  while (n_left_from > 0 && n_left_to_next > 0)
502  {
503  u32 bi0;
504  vlib_buffer_t * b0;
505  u32 flow_hash0;
506  u32 len0;
507  ip4_header_t * ip4_0;
508  ip6_header_t * ip6_0;
509  udp_header_t * udp0;
510  gtpu_header_t * gtpu0;
511  u64 * copy_src0, * copy_dst0;
512  u32 * copy_src_last0, * copy_dst_last0;
513  u16 new_l0;
514  ip_csum_t sum0;
515 
516  bi0 = from[0];
517  to_next[0] = bi0;
518  from += 1;
519  to_next += 1;
520  n_left_from -= 1;
521  n_left_to_next -= 1;
522 
523  b0 = vlib_get_buffer (vm, bi0);
524 
525  flow_hash0 = vnet_l2_compute_flow_hash(b0);
526 
527  /* Get next node index and adj index from tunnel next_dpo */
528  sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_TX];
529  hi0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
530  t0 = &gtm->tunnels[hi0->dev_instance];
531  /* Note: change to always set next0 if it may be set to drop */
532  next0 = t0->next_dpo.dpoi_next_node;
533  vnet_buffer(b0)->ip.adj_index[VLIB_TX] = t0->next_dpo.dpoi_index;
534 
535  /* Apply the rewrite string. $$$$ vnet_rewrite? */
536  vlib_buffer_advance (b0, -(word)_vec_len(t0->rewrite));
537 
538  if (is_ip4)
539  {
540  ip4_0 = vlib_buffer_get_current(b0);
541 
542  /* Copy the fixed header */
543  copy_dst0 = (u64 *) ip4_0;
544  copy_src0 = (u64 *) t0->rewrite;
545  /* Copy first 32 octets 8-bytes at a time */
546 #define _(offs) copy_dst0[offs] = copy_src0[offs];
548 #undef _
549  /* Last 4 octets. Hopefully gcc will be our friend */
550  copy_dst_last0 = (u32 *)(&copy_dst0[4]);
551  copy_src_last0 = (u32 *)(&copy_src0[4]);
552  copy_dst_last0[0] = copy_src_last0[0];
553 
554  /* Fix the IP4 checksum and length */
555  sum0 = ip4_0->checksum;
556  new_l0 = /* old_l0 always 0, see the rewrite setup */
557  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
558  sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
559  length /* changed member */);
560  ip4_0->checksum = ip_csum_fold (sum0);
561  ip4_0->length = new_l0;
562 
563  /* Fix UDP length and set source port */
564  udp0 = (udp_header_t *)(ip4_0+1);
565  new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b0)
566  - sizeof (*ip4_0));
567  udp0->length = new_l0;
568  udp0->src_port = flow_hash0;
569 
570  /* Fix GTPU length */
571  gtpu0 = (gtpu_header_t *)(udp0+1);
572  new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b0)
573  - sizeof (*ip4_0) - sizeof(*udp0)
574  - GTPU_V1_HDR_LEN);
575  gtpu0->length = new_l0;
576  }
577 
578  else /* ip6 path */
579  {
580  int bogus = 0;
581 
582  ip6_0 = vlib_buffer_get_current(b0);
583  /* Copy the fixed header */
584  copy_dst0 = (u64 *) ip6_0;
585  copy_src0 = (u64 *) t0->rewrite;
586  /* Copy first 56 (ip6) octets 8-bytes at a time */
587 #define _(offs) copy_dst0[offs] = copy_src0[offs];
589 #undef _
590  /* Fix IP6 payload length */
591  new_l0 =
592  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)
593  - sizeof(*ip6_0));
594  ip6_0->payload_length = new_l0;
595 
596  /* Fix UDP length and set source port */
597  udp0 = (udp_header_t *)(ip6_0+1);
598  udp0->length = new_l0;
599  udp0->src_port = flow_hash0;
600 
601  /* Fix GTPU length */
602  gtpu0 = (gtpu_header_t *)(udp0+1);
603  new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b0)
604  - sizeof (*ip4_0) - sizeof(*udp0)
605  - GTPU_V1_HDR_LEN);
606  gtpu0->length = new_l0;
607 
608  /* IPv6 UDP checksum is mandatory */
610  ip6_0, &bogus);
611  if (udp0->checksum == 0)
612  udp0->checksum = 0xffff;
613  }
614 
615  pkts_encapsulated ++;
616  len0 = vlib_buffer_length_in_chain (vm, b0);
617  stats_n_packets += 1;
618  stats_n_bytes += len0;
619 
620  /* save inner packet flow_hash for load-balance node */
621  vnet_buffer (b0)->ip.flow_hash = flow_hash0;
622 
623  /* Batch stats increment on the same gtpu tunnel so counter is not
624  incremented per packet. Note stats are still incremented for deleted
625  and admin-down tunnel where packets are dropped. It is not worthwhile
626  to check for this rare case and affect normal path performance. */
627  if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index))
628  {
629  stats_n_packets -= 1;
630  stats_n_bytes -= len0;
631  if (stats_n_packets)
634  thread_index, stats_sw_if_index,
635  stats_n_packets, stats_n_bytes);
636  stats_n_packets = 1;
637  stats_n_bytes = len0;
638  stats_sw_if_index = sw_if_index0;
639  }
640 
641  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
642  {
643  gtpu_encap_trace_t *tr =
644  vlib_add_trace (vm, node, b0, sizeof (*tr));
645  tr->tunnel_index = t0 - gtm->tunnels;
646  tr->tteid = t0->tteid;
647  }
649  to_next, n_left_to_next,
650  bi0, next0);
651  }
652 
653  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
654  }
655 
656  /* Do we still need this now that tunnel tx stats is kept? */
657  vlib_node_increment_counter (vm, node->node_index,
658  GTPU_ENCAP_ERROR_ENCAPSULATED,
659  pkts_encapsulated);
660 
661  /* Increment any remaining batch stats */
662  if (stats_n_packets)
663  {
666  thread_index, stats_sw_if_index, stats_n_packets, stats_n_bytes);
667  node->runtime_data[0] = stats_sw_if_index;
668  }
669 
670  return from_frame->n_vectors;
671 }
672 
676 {
677  return gtpu_encap_inline (vm, node, from_frame, /* is_ip4 */ 1);
678 }
679 
683 {
684  return gtpu_encap_inline (vm, node, from_frame, /* is_ip4 */ 0);
685 }
686 
688  .name = "gtpu4-encap",
689  .vector_size = sizeof (u32),
690  .format_trace = format_gtpu_encap_trace,
692  .n_errors = ARRAY_LEN(gtpu_encap_error_strings),
693  .error_strings = gtpu_encap_error_strings,
694  .n_next_nodes = GTPU_ENCAP_N_NEXT,
695  .next_nodes = {
696 #define _(s,n) [GTPU_ENCAP_NEXT_##s] = n,
698 #undef _
699  },
700 };
701 
703  .name = "gtpu6-encap",
704  .vector_size = sizeof (u32),
705  .format_trace = format_gtpu_encap_trace,
707  .n_errors = ARRAY_LEN(gtpu_encap_error_strings),
708  .error_strings = gtpu_encap_error_strings,
709  .n_next_nodes = GTPU_ENCAP_N_NEXT,
710  .next_nodes = {
711 #define _(s,n) [GTPU_ENCAP_NEXT_##s] = n,
713 #undef _
714  },
715 };
716 
dpo_id_t_::dpoi_next_node
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:186
im
vnet_interface_main_t * im
Definition: interface_output.c:415
udp_header_t::src_port
u16 src_port
Definition: udp_packet.h:48
udp_header_t::length
u16 length
Definition: udp_packet.h:51
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
gtpu_encap_trace_t::tteid
u32 tteid
Definition: gtpu.h:276
vlib_prefetch_buffer_header
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:231
foreach_gtpu_encap_next
#define foreach_gtpu_encap_next
Definition: gtpu_encap.c:39
ip6_tcp_udp_icmp_compute_checksum
u16 ip6_tcp_udp_icmp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip6_header_t *ip0, int *bogus_lengthp)
Definition: ip6_forward.c:1096
gtpu.h
VNET_INTERFACE_COUNTER_TX
@ VNET_INTERFACE_COUNTER_TX
Definition: interface.h:919
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
gtpu_main_t
Definition: gtpu.h:205
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
gtpu_main_t::vnet_main
vnet_main_t * vnet_main
Definition: gtpu.h:237
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
gtpu_tunnel_t::rewrite
u8 * rewrite
Definition: gtpu.h:134
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
vnet_interface_main_t
Definition: interface.h:990
vlib_validate_buffer_enqueue_x4
#define vlib_validate_buffer_enqueue_x4(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, bi2, bi3, next0, next1, next2, next3)
Finish enqueueing four buffers forward in the graph.
Definition: buffer_node.h:140
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
from_frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
GTPU_ENCAP_N_NEXT
@ GTPU_ENCAP_N_NEXT
Definition: gtpu_encap.c:48
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
vlib_frame_t
Definition: node.h:372
vlib_buffer_length_in_chain
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:433
gtpu4_encap_node
vlib_node_registration_t gtpu4_encap_node
(constructor) VLIB_REGISTER_NODE (gtpu4_encap_node)
Definition: gtpu_encap.c:687
udp_header_t
Definition: udp_packet.h:45
ip4_header_t
Definition: ip4_packet.h:87
ethernet.h
ip4_header_t::length
u16 length
Definition: ip4_packet.h:99
gtpu_encap_trace_t::tunnel_index
u32 tunnel_index
Definition: gtpu.h:275
CLIB_PREFETCH
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:76
hash.h
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
error.h
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
gtpu_encap_trace_t
Definition: gtpu.h:273
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
GTPU_ENCAP_NEXT_DROP
@ GTPU_ENCAP_NEXT_DROP
Definition: gtpu_encap.c:45
gtpu6_encap_node
vlib_node_registration_t gtpu6_encap_node
(constructor) VLIB_REGISTER_NODE (gtpu6_encap_node)
Definition: gtpu_encap.c:702
format_gtpu_encap_trace
u8 * format_gtpu_encap_trace(u8 *s, va_list *args)
Definition: gtpu.c:52
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:187
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
GTPU_V1_HDR_LEN
#define GTPU_V1_HDR_LEN
Definition: gtpu.h:67
gtpu_header_t
Definition: mobile.h:90
uword
u64 uword
Definition: types.h:112
gtpu_header_t::length
u16 length
Definition: mobile.h:94
foreach_fixed_header4_offset
#define foreach_fixed_header4_offset
Definition: gtpu_encap.c:52
vlib_node_increment_counter
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
gtpu_encap_error_strings
static char * gtpu_encap_error_strings[]
Definition: gtpu_encap.c:26
ip4_header_t::checksum
u16 checksum
Definition: ip4_packet.h:118
gtpu_tunnel_t::next_dpo
dpo_id_t next_dpo
Definition: gtpu.h:137
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:58
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vnet_interface_main_t::combined_sw_if_counters
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:1024
udp_header_t::checksum
u16 checksum
Definition: udp_packet.h:55
gtpu_encap_error_t
gtpu_encap_error_t
Definition: gtpu_encap.c:32
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vlib_validate_buffer_enqueue_x1
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
u64
unsigned long u64
Definition: types.h:89
foreach_fixed_header6_offset
#define foreach_fixed_header6_offset
Definition: gtpu_encap.c:55
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
ip.h
u32
unsigned int u32
Definition: types.h:88
vnet_get_sup_hw_interface
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:92
gtpu_encap_next_t
gtpu_encap_next_t
Definition: gtpu_encap.c:44
gtpu_tunnel_t::tteid
u32 tteid
Definition: gtpu.h:141
GTPU_ENCAP_N_ERROR
@ GTPU_ENCAP_N_ERROR
Definition: gtpu_encap.c:36
gtpu_tunnel_t
Definition: gtpu.h:128
ip6_header_t
Definition: ip6_packet.h:294
length
char const int length
Definition: cJSON.h:163
gtpu_encap_inline
static uword gtpu_encap_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, u32 is_ip4)
Definition: gtpu_encap.c:59
vlib_main_t
Definition: main.h:102
ip_csum_update
#define ip_csum_update(sum, old, new, type, field)
Definition: ip_packet.h:295
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
ip_csum_t
uword ip_csum_t
Definition: ip_packet.h:245
vlib_buffer_t::data
u8 data[]
Packet data.
Definition: buffer.h:204
word
i64 word
Definition: types.h:111
gtpu_main
gtpu_main_t gtpu_main
Definition: gtpu.c:36
gtpu_main_t::tunnels
gtpu_tunnel_t * tunnels
Definition: gtpu.h:208
vnet.h
ip6_header_t::payload_length
u16 payload_length
Definition: ip6_packet.h:301
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
vlib_get_next_frame
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:395
ip_csum_fold
static u16 ip_csum_fold(ip_csum_t c)
Definition: ip_packet.h:301
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
GTPU_ENCAP_NEXT_IP6_LOOKUP
@ GTPU_ENCAP_NEXT_IP6_LOOKUP
Definition: gtpu_encap.c:47
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vnet_main_t::interface_main
vnet_interface_main_t interface_main
Definition: vnet.h:81
vlib_increment_combined_counter
vlib_increment_combined_counter(ccm, ti, sw_if_index, n_buffers, n_bytes)
foreach_gtpu_encap_error
#define foreach_gtpu_encap_error
Definition: gtpu_encap.c:23
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
GTPU_ENCAP_NEXT_IP4_LOOKUP
@ GTPU_ENCAP_NEXT_IP4_LOOKUP
Definition: gtpu_encap.c:46
vnet_l2_compute_flow_hash
static u32 vnet_l2_compute_flow_hash(vlib_buffer_t *b)
Definition: l2_input.h:342
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169