summaryrefslogtreecommitdiffstats
path: root/hicn-plugin/src/udp_tunnels/udp_decap_node.c
blob: 84e4e5234235dda7ea0d2112ef03b9b370860b99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
/*
 * Copyright (c) 2020-2021 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <vnet/fib/fib_table.h>

#include "udp_tunnel.h"
#include "../mgmt.h"
#include "../hicn.h"
#include "../strategy_dpo_ctx.h"

vlib_node_registration_t udp_decap_node;

static char *udp_decap_error_strings[] = {
#define _(sym, string) string,
  foreach_hicnfwd_error
#undef _
};

/* Trace context struct */
typedef enum
{
  UDP4_DECAP_NEXT_LOOKUP_IP4,
  UDP4_DECAP_NEXT_LOOKUP_IP6,
  UDP4_DECAP_N_NEXT,
} udp4_decap_next_t;

typedef enum
{
  UDP6_DECAP_NEXT_LOOKUP_IP4,
  UDP6_DECAP_NEXT_LOOKUP_IP6,
  UDP6_DECAP_N_NEXT,
} udp6_decap_next_t;

typedef struct udp4_decap_trace_t_
{
  ip4_header_t ip;
  udp_header_t udp;
} udp4_decap_trace_t;

typedef struct udp6_decap_trace_t_
{
  ip6_header_t ip;
  udp_header_t udp;
} udp6_decap_trace_t;

typedef struct udp_decap_trace_t_
{
  union
  {
    udp4_decap_trace_t udp4;
    udp6_decap_trace_t udp6;
  };

  u8 isv6;
  u8 ishicn;
} udp_decap_trace_t;

static u8 *
format_udp_decap_trace (u8 *s, va_list *args)
{
  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
  udp_decap_trace_t *t;

  t = va_arg (*args, udp_decap_trace_t *);

  if (t->isv6)
    {
      s = format (s, "%U\n  %U \n %s", format_ip4_header, &t->udp6.ip,
		  sizeof (t->udp6.ip), format_udp_header, &t->udp6.udp,
		  sizeof (t->udp6.udp), t->ishicn ? "hICN udp tunnel" : "");
    }
  else
    {
      s = format (s, "%U\n  %U \n %s", format_ip4_header, &t->udp4.ip,
		  sizeof (t->udp4.ip), format_udp_header, &t->udp4.udp,
		  sizeof (t->udp4.udp), t->ishicn ? "hICN udp tunnel" : "");
    }
  return (s);
}

static_always_inline void
udp_decap_trace_buffer (vlib_main_t *vm, vlib_node_runtime_t *node, u8 isv6,
			vlib_buffer_t *b)
{
  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
		     (b->flags & VLIB_BUFFER_IS_TRACED)))
    {
      udp_decap_trace_t *t = vlib_add_trace (vm, node, b, sizeof (*t));
      t->isv6 = isv6;
      hicn_buffer_t *hb = hicn_get_buffer (b);

      if (isv6)
	{
	  clib_memcpy (&(t->udp6.udp),
		       vlib_buffer_get_current (b) + sizeof (ip6_header_t),
		       sizeof (udp_header_t));
	  clib_memcpy (&(t->udp6.ip), vlib_buffer_get_current (b),
		       sizeof (ip6_header_t));
	  t->ishicn =
	    hb->flags & hb->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL;
	}
      else
	{
	  clib_memcpy (&(t->udp4.udp),
		       vlib_buffer_get_current (b) + sizeof (ip4_header_t),
		       sizeof (udp_header_t));
	  clib_memcpy (&(t->udp4.ip), vlib_buffer_get_current (b),
		       sizeof (ip4_header_t));
	  t->ishicn = hb->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL;
	}
    }
}

static uword
udp4_decap_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node,
		    vlib_frame_t *frame)
{
  u32 n_left_from, *from, *to_next, next_index;

  from = vlib_frame_vector_args (frame);
  n_left_from = frame->n_vectors;
  next_index = node->cached_next_index;

  while (n_left_from > 0)
    {
      u32 n_left_to_next;
      vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);

      /* Dual loop, X2 */
      while (n_left_from >= 8 && n_left_to_next >= 4)
	{
	  vlib_buffer_t *b0, *b1, *b2, *b3;
	  u32 bi0, bi1, bi2, bi3;
	  u32 next0, next1, next2, next3;

	  {
	    vlib_buffer_t *b4, *b5, *b6, *b7;
	    b4 = vlib_get_buffer (vm, from[4]);
	    b5 = vlib_get_buffer (vm, from[5]);
	    b6 = vlib_get_buffer (vm, from[6]);
	    b7 = vlib_get_buffer (vm, from[7]);
	    CLIB_PREFETCH (b4, CLIB_CACHE_LINE_BYTES, STORE);
	    CLIB_PREFETCH (b5, CLIB_CACHE_LINE_BYTES, STORE);
	    CLIB_PREFETCH (b6, CLIB_CACHE_LINE_BYTES, STORE);
	    CLIB_PREFETCH (b7, CLIB_CACHE_LINE_BYTES, STORE);
	  }

	  bi0 = from[0];
	  bi1 = from[1];
	  bi2 = from[2];
	  bi3 = from[3];

	  from += 4;
	  n_left_from -= 4;
	  to_next[0] = bi0;
	  to_next[1] = bi1;
	  to_next[2] = bi2;
	  to_next[3] = bi3;

	  to_next += 4;
	  n_left_to_next -= 4;

	  b0 = vlib_get_buffer (vm, bi0);
	  b1 = vlib_get_buffer (vm, bi1);
	  b2 = vlib_get_buffer (vm, bi2);
	  b3 = vlib_get_buffer (vm, bi3);

	  u8 *ptr0 = vlib_buffer_get_current (b0);
	  u8 *ptr1 = vlib_buffer_get_current (b1);
	  u8 *ptr2 = vlib_buffer_get_current (b2);
	  u8 *ptr3 = vlib_buffer_get_current (b3);
	  u8 v0 = *ptr0 & 0xf0;
	  u8 v1 = *ptr1 & 0xf0;
	  u8 v2 = *ptr2 & 0xf0;
	  u8 v3 = *ptr3 & 0xf0;

	  u8 advance = sizeof (ip4_header_t) + sizeof (udp_header_t);

	  vlib_buffer_advance (b0, -advance);
	  vlib_buffer_advance (b1, -advance);
	  vlib_buffer_advance (b2, -advance);
	  vlib_buffer_advance (b3, -advance);

	  u8 *outer_ptr0 = vlib_buffer_get_current (b0);
	  u8 *outer_ptr1 = vlib_buffer_get_current (b1);
	  u8 *outer_ptr2 = vlib_buffer_get_current (b2);
	  u8 *outer_ptr3 = vlib_buffer_get_current (b3);
	  u8 outer_v0 = *outer_ptr0 & 0xf0;
	  u8 outer_v1 = *outer_ptr1 & 0xf0;
	  u8 outer_v2 = *outer_ptr2 & 0xf0;
	  u8 outer_v3 = *outer_ptr3 & 0xf0;

	  ip46_address_t src0 = { 0 };
	  ip46_address_t src1 = { 0 };
	  ip46_address_t src2 = { 0 };
	  ip46_address_t src3 = { 0 };

	  ip46_address_t dst0 = { 0 };
	  ip46_address_t dst1 = { 0 };
	  ip46_address_t dst2 = { 0 };
	  ip46_address_t dst3 = { 0 };

	  udp_header_t *udp0 = NULL;
	  udp_header_t *udp1 = NULL;
	  udp_header_t *udp2 = NULL;
	  udp_header_t *udp3 = NULL;

	  ip46_address_set_ip4 (&src0,
				&((ip4_header_t *) outer_ptr0)->src_address);
	  ip46_address_set_ip4 (&dst0,
				&((ip4_header_t *) outer_ptr0)->dst_address);
	  udp0 = (udp_header_t *) (outer_ptr0 + sizeof (ip4_header_t));
	  next0 = v0 == 0x40 ? UDP4_DECAP_NEXT_LOOKUP_IP4 :
				     UDP4_DECAP_NEXT_LOOKUP_IP6;

	  ip46_address_set_ip4 (&src1,
				&((ip4_header_t *) outer_ptr1)->src_address);
	  ip46_address_set_ip4 (&dst1,
				&((ip4_header_t *) outer_ptr1)->dst_address);
	  udp1 = (udp_header_t *) (outer_ptr1 + sizeof (ip4_header_t));
	  next1 = v1 == 0x40 ? UDP4_DECAP_NEXT_LOOKUP_IP4 :
				     UDP4_DECAP_NEXT_LOOKUP_IP6;

	  ip46_address_set_ip4 (&src2,
				&((ip4_header_t *) outer_ptr2)->src_address);
	  ip46_address_set_ip4 (&dst2,
				&((ip4_header_t *) outer_ptr2)->dst_address);
	  udp2 = (udp_header_t *) (outer_ptr2 + sizeof (ip4_header_t));
	  next2 = v2 == 0x40 ? UDP4_DECAP_NEXT_LOOKUP_IP4 :
				     UDP4_DECAP_NEXT_LOOKUP_IP6;

	  ip46_address_set_ip4 (&src3,
				&((ip4_header_t *) outer_ptr3)->src_address);
	  ip46_address_set_ip4 (&dst3,
				&((ip4_header_t *) outer_ptr3)->dst_address);
	  udp3 = (udp_header_t *) (outer_ptr3 + sizeof (ip4_header_t));
	  next3 = v3 == 0x40 ? UDP4_DECAP_NEXT_LOOKUP_IP4 :
				     UDP4_DECAP_NEXT_LOOKUP_IP6;

	  hicn_buffer_t *hicnb0, *hicnb1, *hicnb2, *hicnb3;
	  hicnb0 = hicn_get_buffer (b0);
	  hicnb1 = hicn_get_buffer (b1);
	  hicnb2 = hicn_get_buffer (b2);
	  hicnb3 = hicn_get_buffer (b3);

	  /* Udp encap-decap tunnels have dst and src addresses and port
	   * swapped */
	  vnet_buffer (b0)->ip.adj_index[VLIB_RX] =
	    udp_tunnel_get (&dst0, &src0, udp0->dst_port, udp0->src_port);
	  vnet_buffer (b1)->ip.adj_index[VLIB_RX] =
	    udp_tunnel_get (&dst1, &src1, udp1->dst_port, udp1->src_port);
	  vnet_buffer (b2)->ip.adj_index[VLIB_RX] =
	    udp_tunnel_get (&dst2, &src2, udp2->dst_port, udp2->src_port);
	  vnet_buffer (b3)->ip.adj_index[VLIB_RX] =
	    udp_tunnel_get (&dst3, &src3, udp3->dst_port, udp3->src_port);

	  if (vnet_buffer (b0)->ip.adj_index[VLIB_RX] != UDP_TUNNEL_INVALID)
	    hicnb0->flags |=
	      (outer_v0 == 0x40 ? HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL :
					HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL);

	  if (vnet_buffer (b1)->ip.adj_index[VLIB_RX] != UDP_TUNNEL_INVALID)
	    hicnb1->flags |=
	      (outer_v1 == 0x40 ? HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL :
					HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL);

	  if (vnet_buffer (b2)->ip.adj_index[VLIB_RX] != UDP_TUNNEL_INVALID)
	    hicnb2->flags |=
	      (outer_v2 == 0x40 ? HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL :
					HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL);

	  if (vnet_buffer (b3)->ip.adj_index[VLIB_RX] != UDP_TUNNEL_INVALID)
	    hicnb3->flags |=
	      (outer_v3 == 0x40 ? HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL :
					HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL);

	  udp_decap_trace_buffer (vm, node, 1, b0);
	  udp_decap_trace_buffer (vm, node, 1, b1);
	  udp_decap_trace_buffer (vm, node, 1, b2);
	  udp_decap_trace_buffer (vm, node, 1, b3);

	  vlib_buffer_advance (b0, advance);
	  vlib_buffer_advance (b1, advance);
	  vlib_buffer_advance (b2, advance);
	  vlib_buffer_advance (b3, advance);

	  vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
					   n_left_to_next, bi0, bi1, bi2, bi3,
					   next0, next1, next2, next3);
	}

      /* Dual loop, X1 */
      while (n_left_from > 0 && n_left_to_next > 0)
	{
	  vlib_buffer_t *b0;
	  u32 bi0;
	  /* udp_encap_t *udp_tunnel0 = NULL; */
	  u32 next0;

	  if (n_left_from > 1)
	    {
	      vlib_buffer_t *b1;
	      b1 = vlib_get_buffer (vm, from[1]);
	      CLIB_PREFETCH (b1, CLIB_CACHE_LINE_BYTES, STORE);
	    }

	  bi0 = from[0];
	  from += 1;
	  n_left_from -= 1;
	  to_next[0] = bi0;
	  to_next += 1;
	  n_left_to_next -= 1;

	  b0 = vlib_get_buffer (vm, bi0);

	  u8 *ptr0 = vlib_buffer_get_current (b0);
	  u8 v0 = *ptr0 & 0xf0;

	  u8 advance = sizeof (ip4_header_t) + sizeof (udp_header_t);
	  ;

	  vlib_buffer_advance (b0, -advance);

	  u8 *outer_ptr0 = vlib_buffer_get_current (b0);
	  u8 outer_v0 = *outer_ptr0 & 0xf0;

	  ip46_address_t src0 = { 0 };
	  ip46_address_t dst0 = { 0 };
	  udp_header_t *udp0 = NULL;

	  ip46_address_set_ip4 (&src0,
				&((ip4_header_t *) outer_ptr0)->src_address);
	  ip46_address_set_ip4 (&dst0,
				&((ip4_header_t *) outer_ptr0)->dst_address);
	  udp0 = (udp_header_t *) (outer_ptr0 + sizeof (ip4_header_t));
	  next0 = v0 == 0x40 ? UDP4_DECAP_NEXT_LOOKUP_IP4 :
				     UDP4_DECAP_NEXT_LOOKUP_IP6;

	  hicn_buffer_t *hicnb0 = hicn_get_buffer (b0);

	  vnet_buffer (b0)->ip.adj_index[VLIB_RX] =
	    udp_tunnel_get (&dst0, &src0, udp0->dst_port, udp0->src_port);

	  if (vnet_buffer (b0)->ip.adj_index[VLIB_RX] != UDP_TUNNEL_INVALID)
	    hicnb0->flags |=
	      (outer_v0 == 0x40 ? HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL :
					HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL);

	  udp_decap_trace_buffer (vm, node, 1, b0);

	  vlib_buffer_advance (b0, advance);

	  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
					   n_left_to_next, bi0, next0);
	}
      vlib_put_next_frame (vm, node, next_index, n_left_to_next);
    }

  return (frame->n_vectors);
}

/*
 * Node registration for the interest forwarder node
 */
VLIB_REGISTER_NODE (udp4_decap_node) = {
  .function = udp4_decap_node_fn,
  .name = "udp4-decap",
  .vector_size = sizeof (u32),
  .format_trace = format_udp_decap_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,
  .n_errors = ARRAY_LEN (udp_decap_error_strings),
  .error_strings = udp_decap_error_strings,
  .n_next_nodes = UDP4_DECAP_N_NEXT,
  /* edit / add dispositions here */
  .next_nodes = { [UDP4_DECAP_NEXT_LOOKUP_IP4] = "ip4-lookup",
		  [UDP4_DECAP_NEXT_LOOKUP_IP6] = "ip6-lookup" },
};

static uword
udp6_decap_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node,
		    vlib_frame_t *frame)
{
  u32 n_left_from, *from, *to_next, next_index;

  from = vlib_frame_vector_args (frame);
  n_left_from = frame->n_vectors;
  next_index = node->cached_next_index;

  while (n_left_from > 0)
    {
      u32 n_left_to_next;
      vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);

      /* Dual loop, X2 */
      while (n_left_from >= 8 && n_left_to_next >= 4)
	{
	  vlib_buffer_t *b0, *b1, *b2, *b3;
	  u32 bi0, bi1, bi2, bi3;
	  u32 next0, next1, next2, next3;

	  {
	    vlib_buffer_t *b4, *b5, *b6, *b7;
	    b4 = vlib_get_buffer (vm, from[4]);
	    b5 = vlib_get_buffer (vm, from[5]);
	    b6 = vlib_get_buffer (vm, from[6]);
	    b7 = vlib_get_buffer (vm, from[7]);
	    CLIB_PREFETCH (b4, CLIB_CACHE_LINE_BYTES, STORE);
	    CLIB_PREFETCH (b5, CLIB_CACHE_LINE_BYTES, STORE);
	    CLIB_PREFETCH (b6, CLIB_CACHE_LINE_BYTES, STORE);
	    CLIB_PREFETCH (b7, CLIB_CACHE_LINE_BYTES, STORE);
	  }

	  bi0 = from[0];
	  bi1 = from[1];
	  bi2 = from[2];
	  bi3 = from[3];

	  from += 4;
	  n_left_from -= 4;
	  to_next[0] = bi0;
	  to_next[1] = bi1;
	  to_next[2] = bi2;
	  to_next[3] = bi3;

	  to_next += 4;
	  n_left_to_next -= 4;

	  b0 = vlib_get_buffer (vm, bi0);
	  b1 = vlib_get_buffer (vm, bi1);
	  b2 = vlib_get_buffer (vm, bi2);
	  b3 = vlib_get_buffer (vm, bi3);

	  u8 *ptr0 = vlib_buffer_get_current (b0);
	  u8 *ptr1 = vlib_buffer_get_current (b1);
	  u8 *ptr2 = vlib_buffer_get_current (b2);
	  u8 *ptr3 = vlib_buffer_get_current (b3);
	  u8 v0 = *ptr0 & 0xf0;
	  u8 v1 = *ptr1 & 0xf0;
	  u8 v2 = *ptr2 & 0xf0;
	  u8 v3 = *ptr3 & 0xf0;

	  u8 advance = sizeof (ip6_header_t) + sizeof (udp_header_t);

	  vlib_buffer_advance (b0, -advance);
	  vlib_buffer_advance (b1, -advance);
	  vlib_buffer_advance (b2, -advance);
	  vlib_buffer_advance (b3, -advance);

	  u8 *outer_ptr0 = vlib_buffer_get_current (b0);
	  u8 *outer_ptr1 = vlib_buffer_get_current (b1);
	  u8 *outer_ptr2 = vlib_buffer_get_current (b2);
	  u8 *outer_ptr3 = vlib_buffer_get_current (b3);
	  u8 outer_v0 = *outer_ptr0 & 0xf0;
	  u8 outer_v1 = *outer_ptr1 & 0xf0;
	  u8 outer_v2 = *outer_ptr2 & 0xf0;
	  u8 outer_v3 = *outer_ptr3 & 0xf0;

	  ip46_address_t src0 = { 0 };
	  ip46_address_t src1 = { 0 };
	  ip46_address_t src2 = { 0 };
	  ip46_address_t src3 = { 0 };

	  ip46_address_t dst0 = { 0 };
	  ip46_address_t dst1 = { 0 };
	  ip46_address_t dst2 = { 0 };
	  ip46_address_t dst3 = { 0 };

	  udp_header_t *udp0 = NULL;
	  udp_header_t *udp1 = NULL;
	  udp_header_t *udp2 = NULL;
	  udp_header_t *udp3 = NULL;

	  ip46_address_set_ip6 (&src0,
				&((ip6_header_t *) outer_ptr0)->src_address);
	  ip46_address_set_ip6 (&dst0,
				&((ip6_header_t *) outer_ptr0)->dst_address);
	  udp0 = (udp_header_t *) (outer_ptr0 + sizeof (ip6_header_t));
	  next0 = v0 == 0x40 ? UDP6_DECAP_NEXT_LOOKUP_IP4 :
				     UDP6_DECAP_NEXT_LOOKUP_IP6;

	  ip46_address_set_ip6 (&src1,
				&((ip6_header_t *) outer_ptr1)->src_address);
	  ip46_address_set_ip6 (&dst1,
				&((ip6_header_t *) outer_ptr1)->dst_address);
	  udp1 = (udp_header_t *) (outer_ptr1 + sizeof (ip6_header_t));
	  next1 = v1 == 0x40 ? UDP6_DECAP_NEXT_LOOKUP_IP4 :
				     UDP6_DECAP_NEXT_LOOKUP_IP6;

	  ip46_address_set_ip6 (&src2,
				&((ip6_header_t *) outer_ptr2)->src_address);
	  ip46_address_set_ip6 (&dst2,
				&((ip6_header_t *) outer_ptr2)->dst_address);
	  udp2 = (udp_header_t *) (outer_ptr2 + sizeof (ip6_header_t));
	  next2 = v2 == 0x40 ? UDP6_DECAP_NEXT_LOOKUP_IP4 :
				     UDP6_DECAP_NEXT_LOOKUP_IP6;

	  ip46_address_set_ip6 (&src3,
				&((ip6_header_t *) outer_ptr3)->src_address);
	  ip46_address_set_ip6 (&dst3,
				&((ip6_header_t *) outer_ptr3)->dst_address);
	  udp3 = (udp_header_t *) (outer_ptr3 + sizeof (ip6_header_t));
	  next3 = v3 == 0x40 ? UDP6_DECAP_NEXT_LOOKUP_IP4 :
				     UDP6_DECAP_NEXT_LOOKUP_IP6;

	  hicn_buffer_t *hicnb0, *hicnb1, *hicnb2, *hicnb3;
	  hicnb0 = hicn_get_buffer (b0);
	  hicnb1 = hicn_get_buffer (b1);
	  hicnb2 = hicn_get_buffer (b2);
	  hicnb3 = hicn_get_buffer (b3);

	  /* Udp encap-decap tunnels have dst and src addresses and port
	   * swapped */
	  vnet_buffer (b0)->ip.adj_index[VLIB_RX] =
	    udp_tunnel_get (&dst0, &src0, udp0->dst_port, udp0->src_port);
	  vnet_buffer (b1)->ip.adj_index[VLIB_RX] =
	    udp_tunnel_get (&dst1, &src1, udp1->dst_port, udp1->src_port);
	  vnet_buffer (b2)->ip.adj_index[VLIB_RX] =
	    udp_tunnel_get (&dst2, &src2, udp2->dst_port, udp2->src_port);
	  vnet_buffer (b3)->ip.adj_index[VLIB_RX] =
	    udp_tunnel_get (&dst3, &src3, udp3->dst_port, udp3->src_port);

	  if (vnet_buffer (b0)->ip.adj_index[VLIB_RX] != UDP_TUNNEL_INVALID)
	    hicnb0->flags |=
	      (outer_v0 == 0x40 ? HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL :
					HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL);

	  if (vnet_buffer (b1)->ip.adj_index[VLIB_RX] != UDP_TUNNEL_INVALID)
	    hicnb1->flags |=
	      (outer_v1 == 0x40 ? HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL :
					HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL);

	  if (vnet_buffer (b2)->ip.adj_index[VLIB_RX] != UDP_TUNNEL_INVALID)
	    hicnb2->flags |=
	      (outer_v2 == 0x40 ? HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL :
					HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL);

	  if (vnet_buffer (b3)->ip.adj_index[VLIB_RX] != UDP_TUNNEL_INVALID)
	    hicnb3->flags |=
	      (outer_v3 == 0x40 ? HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL :
					HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL);

	  udp_decap_trace_buffer (vm, node, 0, b0);
	  udp_decap_trace_buffer (vm, node, 0, b1);
	  udp_decap_trace_buffer (vm, node, 0, b2);
	  udp_decap_trace_buffer (vm, node, 0, b3);

	  vlib_buffer_advance (b0, advance);
	  vlib_buffer_advance (b1, advance);
	  vlib_buffer_advance (b2, advance);
	  vlib_buffer_advance (b3, advance);

	  vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
					   n_left_to_next, bi0, bi1, bi2, bi3,
					   next0, next1, next2, next3);
	}

      /* Dual loop, X1 */
      while (n_left_from > 0 && n_left_to_next > 0)
	{
	  vlib_buffer_t *b0;
	  u32 bi0;
	  /* udp_encap_t *udp_tunnel0 = NULL; */
	  u32 next0;

	  if (n_left_from > 1)
	    {
	      vlib_buffer_t *b1;
	      b1 = vlib_get_buffer (vm, from[1]);
	      CLIB_PREFETCH (b1, CLIB_CACHE_LINE_BYTES, STORE);
	    }

	  bi0 = from[0];
	  from += 1;
	  n_left_from -= 1;
	  to_next[0] = bi0;
	  to_next += 1;
	  n_left_to_next -= 1;

	  b0 = vlib_get_buffer (vm, bi0);

	  u8 *ptr0 = vlib_buffer_get_current (b0);
	  u8 v0 = *ptr0 & 0xf0;

	  u8 advance = sizeof (ip6_header_t) + sizeof (udp_header_t);

	  vlib_buffer_advance (b0, -advance);

	  u8 *outer_ptr0 = vlib_buffer_get_current (b0);
	  u8 outer_v0 = *outer_ptr0 & 0xf0;

	  ip46_address_t src0 = { 0 };
	  ip46_address_t dst0 = { 0 };
	  udp_header_t *udp0 = NULL;

	  ip46_address_set_ip6 (&src0,
				&((ip6_header_t *) outer_ptr0)->src_address);
	  ip46_address_set_ip6 (&dst0,
				&((ip6_header_t *) outer_ptr0)->dst_address);
	  udp0 = (udp_header_t *) (outer_ptr0 + sizeof (ip6_header_t));
	  next0 = v0 == 0x40 ? UDP6_DECAP_NEXT_LOOKUP_IP4 :
				     UDP6_DECAP_NEXT_LOOKUP_IP6;

	  hicn_buffer_t *hicnb0 = hicn_get_buffer (b0);

	  vnet_buffer (b0)->ip.adj_index[VLIB_RX] =
	    udp_tunnel_get (&dst0, &src0, udp0->dst_port, udp0->src_port);

	  if (vnet_buffer (b0)->ip.adj_index[VLIB_RX] != UDP_TUNNEL_INVALID)
	    hicnb0->flags |=
	      (outer_v0 == 0x40 ? HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL :
					HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL);

	  udp_decap_trace_buffer (vm, node, 0, b0);

	  vlib_buffer_advance (b0, advance);

	  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
					   n_left_to_next, bi0, next0);
	}
      vlib_put_next_frame (vm, node, next_index, n_left_to_next);
    }

  return (frame->n_vectors);
}

/*
 * Node registration for the interest forwarder node
 */
VLIB_REGISTER_NODE (udp6_decap_node) = {
  .function = udp6_decap_node_fn,
  .name = "udp6-decap",
  .vector_size = sizeof (u32),
  .format_trace = format_udp_decap_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,
  .n_errors = ARRAY_LEN (udp_decap_error_strings),
  .error_strings = udp_decap_error_strings,
  .n_next_nodes = UDP6_DECAP_N_NEXT,
  /* edit / add dispositions here */
  .next_nodes = { [UDP6_DECAP_NEXT_LOOKUP_IP4] = "ip4-lookup",
		  [UDP6_DECAP_NEXT_LOOKUP_IP6] = "ip6-lookup" },
};

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */