FD.io VPP  v21.01.1
Vector Packet Processing
ipip.c
Go to the documentation of this file.
1 /*
2  * ipip.c: ipip
3  *
4  * Copyright (c) 2018 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 aipiped 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  */
17 
18 #include <stddef.h>
19 #include <vnet/adj/adj_midchain.h>
20 #include <vnet/ipip/ipip.h>
21 #include <vnet/vnet.h>
22 #include <vnet/adj/adj_nbr.h>
23 #include <vnet/adj/adj_midchain.h>
24 #include <vnet/fib/ip4_fib.h>
25 #include <vnet/fib/ip6_fib.h>
26 #include <vnet/ip/format.h>
27 #include <vnet/ipip/ipip.h>
28 #include <vnet/teib/teib.h>
29 #include <vnet/tunnel/tunnel_dp.h>
30 
32 
33 /* Packet trace structure */
34 typedef struct
35 {
38  ip46_address_t src;
39  ip46_address_t dst;
41 
42 u8 *
43 format_ipip_tx_trace (u8 * s, va_list * args)
44 {
45  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
46  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
47  ipip_tx_trace_t *t = va_arg (*args, ipip_tx_trace_t *);
48 
49  s =
50  format (s, "IPIP: tunnel %d len %d src %U dst %U", t->tunnel_id,
53  return s;
54 }
55 
56 static u8 *
58  vnet_link_t link_type, const void *dst_address)
59 {
60  const ip46_address_t *dst;
63  u8 *rewrite = NULL;
64  ipip_tunnel_t *t;
65 
66  dst = dst_address;
67  t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index);
68 
69  if (!t)
70  /* not one of ours */
71  return (0);
72 
73  switch (t->transport)
74  {
75  case IPIP_TRANSPORT_IP4:
76  vec_validate (rewrite, sizeof (*ip4) - 1);
77  ip4 = (ip4_header_t *) rewrite;
78  ip4->ip_version_and_header_length = 0x45;
79  ip4->ttl = 64;
80  /* fixup ip4 header length, protocol and checksum after-the-fact */
81  ip4->src_address.as_u32 = t->tunnel_src.ip4.as_u32;
82  ip4->dst_address.as_u32 = dst->ip4.as_u32;
83  if (!(t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
84  ip4_header_set_dscp (ip4, t->dscp);
85  if (t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_SET_DF)
86  ip4_header_set_df (ip4);
87 
88  switch (link_type)
89  {
90  case VNET_LINK_IP6:
91  ip4->protocol = IP_PROTOCOL_IPV6;
92  break;
93  case VNET_LINK_IP4:
94  ip4->protocol = IP_PROTOCOL_IP_IN_IP;
95  break;
96  default:
97  break;
98  }
99  ip4->checksum = ip4_header_checksum (ip4);
100  break;
101 
102  case IPIP_TRANSPORT_IP6:
103  vec_validate (rewrite, sizeof (*ip6) - 1);
104  ip6 = (ip6_header_t *) rewrite;
106  clib_host_to_net_u32 (6 << 28);
107  ip6->hop_limit = 64;
108  /* fixup ip6 header length and protocol after-the-fact */
109  ip6->src_address.as_u64[0] = t->tunnel_src.ip6.as_u64[0];
110  ip6->src_address.as_u64[1] = t->tunnel_src.ip6.as_u64[1];
111  ip6->dst_address.as_u64[0] = dst->ip6.as_u64[0];
112  ip6->dst_address.as_u64[1] = dst->ip6.as_u64[1];
113  if (!(t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
115 
116  switch (link_type)
117  {
118  case VNET_LINK_IP6:
119  ip6->protocol = IP_PROTOCOL_IPV6;
120  break;
121  case VNET_LINK_IP4:
122  ip6->protocol = IP_PROTOCOL_IP_IN_IP;
123  break;
124  default:
125  break;
126  }
127  break;
128  }
129  return (rewrite);
130 }
131 
132 static void
134  const void *data)
135 {
137  ip4_header_t *ip4;
138 
139  flags = pointer_to_uword (data);
140 
141  ip4 = vlib_buffer_get_current (b);
142  ip4->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b));
143  tunnel_encap_fixup_6o4 (flags, ((ip6_header_t *) (ip4 + 1)), ip4);
144 
145  ip4->checksum = ip4_header_checksum (ip4);
146 }
147 
148 static void
150  const void *data)
151 {
153  ip4_header_t *ip4;
154 
155  flags = pointer_to_uword (data);
156 
157  ip4 = vlib_buffer_get_current (b);
158  ip4->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b));
159  tunnel_encap_fixup_4o4 (flags, ip4 + 1, ip4);
160 
161  ip4->checksum = ip4_header_checksum (ip4);
162 }
163 
164 static void
166  const void *data)
167 {
169  ip6_header_t *ip6;
170 
171  flags = pointer_to_uword (data);
172 
173  /* Must set locally originated otherwise we're not allowed to
174  fragment the packet later */
175  b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
176 
177  ip6 = vlib_buffer_get_current (b);
178  ip6->payload_length =
179  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b) -
180  sizeof (*ip6));
181  tunnel_encap_fixup_4o6 (flags, ((ip4_header_t *) (ip6 + 1)), ip6);
182 }
183 
184 static void
186  const ip_adjacency_t * adj, vlib_buffer_t * b, const void *data)
187 {
189  ip6_header_t *ip6;
190 
191  flags = pointer_to_uword (data);
192 
193  /* Must set locally originated otherwise we're not allowed to
194  fragment the packet later */
195  b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
196 
197  ip6 = vlib_buffer_get_current (b);
198  ip6->payload_length =
199  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b) -
200  sizeof (*ip6));
201  tunnel_encap_fixup_6o6 (flags, ip6 + 1, ip6);
202 }
203 
204 static void
206 {
207  ip_adjacency_t *adj;
208  ipip_tunnel_t *t;
210 
211  adj = adj_get (ai);
212  sw_if_index = adj->rewrite_header.sw_if_index;
213 
214  t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index);
215  if (!t)
216  return;
217 
220  {
222  }
223  else
224  {
225  /* *INDENT-OFF* */
226  fib_prefix_t dst = {
227  .fp_len = t->transport == IPIP_TRANSPORT_IP6 ? 128 : 32,
228  .fp_proto = (t->transport == IPIP_TRANSPORT_IP6 ?
231  .fp_addr = t->tunnel_dst
232  };
233  /* *INDENT-ON* */
234 
235  adj_midchain_delegate_stack (ai, t->fib_index, &dst);
236  }
237 }
238 
239 static adj_walk_rc_t
241 {
242  ipip_tunnel_stack (ai);
243 
244  return (ADJ_WALK_RC_CONTINUE);
245 }
246 
247 static void
249 {
251 
252  /*
253  * walk all the adjacencies on th IPIP interface and restack them
254  */
256  {
257  adj_nbr_walk (gt->sw_if_index, proto, ipip_adj_walk_cb, NULL);
258  }
259 }
260 
263 {
264  if (t->transport == IPIP_TRANSPORT_IP6 && lt == VNET_LINK_IP6)
265  return (ipip66_fixup);
266  if (t->transport == IPIP_TRANSPORT_IP6 && lt == VNET_LINK_IP4)
267  return (ipip46_fixup);
268  if (t->transport == IPIP_TRANSPORT_IP4 && lt == VNET_LINK_IP6)
269  return (ipip64_fixup);
270  if (t->transport == IPIP_TRANSPORT_IP4 && lt == VNET_LINK_IP4)
271  {
272  *aflags = *aflags | ADJ_FLAG_MIDCHAIN_FIXUP_IP4O4_HDR;
273  return (ipip44_fixup);
274  }
275 
276  ASSERT (0);
277  return (ipip44_fixup);
278 }
279 
280 void
282 {
283  adj_midchain_fixup_t fixup;
284  ipip_tunnel_t *t;
285  adj_flags_t af;
286 
287  t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index);
288  if (!t)
289  return;
290 
291  if (t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_INNER_HASH)
293  else
295 
298 
299  fixup = ipip_get_fixup (t, adj_get_link_type (ai), &af);
301  (ai, fixup,
302  uword_to_pointer (t->flags, void *), af,
303  ipip_build_rewrite (vnm, sw_if_index,
304  adj_get_link_type (ai), &t->tunnel_dst));
305  ipip_tunnel_stack (ai);
306 }
307 
308 typedef struct mipip_walk_ctx_t_
309 {
310  const ipip_tunnel_t *t;
311  const teib_entry_t *ne;
313 
314 static adj_walk_rc_t
316 {
317  adj_midchain_fixup_t fixup;
319  adj_flags_t af;
320 
321  af = ADJ_FLAG_NONE;
322  fixup = ipip_get_fixup (ctx->t, adj_get_link_type (ai), &af);
323 
324  if (ctx->t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_INNER_HASH)
326  else
328 
330  (ai, fixup,
331  uword_to_pointer (ctx->t->flags, void *),
333  ctx->t->sw_if_index,
334  adj_get_link_type (ai),
335  &teib_entry_get_nh (ctx->ne)->fp_addr));
336 
337  teib_entry_adj_stack (ctx->ne, ai);
338 
339  return (ADJ_WALK_RC_CONTINUE);
340 }
341 
342 static adj_walk_rc_t
344 {
345  adj_midchain_fixup_t fixup;
346  ipip_tunnel_t *t = data;
347  adj_flags_t af;
348 
349  af = ADJ_FLAG_NONE;
350  fixup = ipip_get_fixup (t, adj_get_link_type (ai), &af);
351 
352  adj_nbr_midchain_update_rewrite (ai, fixup, NULL, ADJ_FLAG_NONE, NULL);
353 
355 
356  return (ADJ_WALK_RC_CONTINUE);
357 }
358 
359 void
361 {
363  adj_midchain_fixup_t fixup;
364  ip_adjacency_t *adj;
365  teib_entry_t *ne;
366  ipip_tunnel_t *t;
367  adj_flags_t af;
368  u32 ti;
369 
370  af = ADJ_FLAG_NONE;
371  adj = adj_get (ai);
373  t = pool_elt_at_index (gm->tunnels, ti);
374 
375  ne = teib_entry_find_46 (sw_if_index,
376  adj->ia_nh_proto, &adj->sub_type.nbr.next_hop);
377 
378  if (NULL == ne)
379  {
380  // no TEIB entry to provide the next-hop
381  fixup = ipip_get_fixup (t, adj_get_link_type (ai), &af);
383  (ai, fixup, uword_to_pointer (t->flags, void *), ADJ_FLAG_NONE, NULL);
384  return;
385  }
386 
388  .t = t,
389  .ne = ne
390  };
391  adj_nbr_walk_nh (sw_if_index,
392  adj->ia_nh_proto,
393  &adj->sub_type.nbr.next_hop, mipip_mk_complete_walk, &ctx);
394 }
395 
396 static u8 *
397 format_ipip_tunnel_name (u8 * s, va_list * args)
398 {
399  u32 dev_instance = va_arg (*args, u32);
401  ipip_tunnel_t *t;
402 
403  if (dev_instance >= vec_len (gm->tunnels))
404  return format (s, "<improperly-referenced>");
405 
406  t = pool_elt_at_index (gm->tunnels, dev_instance);
407  return format (s, "ipip%d", t->user_instance);
408 }
409 
410 static u8 *
411 format_ipip_device (u8 * s, va_list * args)
412 {
413  u32 dev_instance = va_arg (*args, u32);
414  CLIB_UNUSED (int verbose) = va_arg (*args, int);
415 
416  s = format (s, "IPIP tunnel: id %d\n", dev_instance);
417  return s;
418 }
419 
420 static clib_error_t *
422 {
424  ipip_tunnel_t *t;
425 
426  hi = vnet_get_hw_interface (vnm, hw_if_index);
427 
429  if (!t)
430  return 0;
431 
433  vnet_hw_interface_set_flags (vnm, hw_if_index,
435  else
436  vnet_hw_interface_set_flags (vnm, hw_if_index, 0 /* down */ );
437 
439 
440  return /* no error */ 0;
441 }
442 
443 static int
445  ip46_address_t * src, ip46_address_t * dst, u8 * is_l2)
446 {
447  ipip_tunnel_t *t;
448 
449  t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index);
450  if (!t)
451  return -1;
452 
453  *src = t->tunnel_src;
454  *dst = t->tunnel_dst;
455  *is_l2 = 0;
456 
457  return (0);
458 }
459 
460 /* *INDENT-OFF* */
461 VNET_DEVICE_CLASS(ipip_device_class) = {
462  .name = "IPIP tunnel device",
463  .format_device_name = format_ipip_tunnel_name,
464  .format_device = format_ipip_device,
465  .format_tx_trace = format_ipip_tx_trace,
466  .admin_up_down_function = ipip_interface_admin_up_down,
467  .ip_tun_desc = ipip_tunnel_desc,
468 #ifdef SOON
469  .clear counter = 0;
470 #endif
471 };
472 
474  .name = "IPIP",
475  //.format_header = format_ipip_header_with_length,
476  //.unformat_header = unformat_ipip_header,
477  .build_rewrite = ipip_build_rewrite,
478  .update_adjacency = ipip_update_adj,
480 };
481 
482 VNET_HW_INTERFACE_CLASS(mipip_hw_interface_class) = {
483  .name = "mIPIP",
484  //.format_header = format_ipip_header_with_length,
485  //.unformat_header = unformat_ipip_header,
486  .build_rewrite = ipip_build_rewrite,
487  .update_adjacency = mipip_update_adj,
489 };
490 /* *INDENT-ON* */
491 
493 ipip_tunnel_db_find (const ipip_tunnel_key_t * key)
494 {
496  uword *p;
497 
498  p = hash_get_mem (gm->tunnel_by_key, key);
499  if (!p)
500  return (NULL);
501  return (pool_elt_at_index (gm->tunnels, p[0]));
502 }
503 
506 {
508  if (vec_len (gm->tunnel_index_by_sw_if_index) <= sw_if_index)
509  return NULL;
511  if (ti == ~0)
512  return NULL;
513  return pool_elt_at_index (gm->tunnels, ti);
514 }
515 
516 void
517 ipip_tunnel_db_add (ipip_tunnel_t * t, const ipip_tunnel_key_t * key)
518 {
520 
522 }
523 
524 void
525 ipip_tunnel_db_remove (ipip_tunnel_t * t, const ipip_tunnel_key_t * key)
526 {
528 
530 }
531 
532 void
533 ipip_mk_key_i (ipip_transport_t transport,
534  ipip_mode_t mode,
535  const ip46_address_t * src,
536  const ip46_address_t * dst,
537  u32 fib_index, ipip_tunnel_key_t * key)
538 {
539  key->transport = transport;
540  key->mode = mode;
541  key->src = *src;
542  key->dst = *dst;
543  key->fib_index = fib_index;
544  key->__pad = 0;;
545 }
546 
547 void
548 ipip_mk_key (const ipip_tunnel_t * t, ipip_tunnel_key_t * key)
549 {
550  ipip_mk_key_i (t->transport, t->mode,
551  &t->tunnel_src, &t->tunnel_dst, t->fib_index, key);
552 }
553 
554 static void
556  const teib_entry_t * ne, ipip_tunnel_key_t * key)
557 {
558  const fib_prefix_t *nh;
559 
560  nh = teib_entry_get_nh (ne);
561 
562  /* construct the key using mode P2P so it can be found in the DP */
564  &t->tunnel_src, &nh->fp_addr,
565  teib_entry_get_fib_index (ne), key);
566 }
567 
568 static void
570 {
572  const ip_address_t *nh;
573  ipip_tunnel_key_t key;
574  ipip_tunnel_t *t;
576  u32 t_idx;
577 
578  sw_if_index = teib_entry_get_sw_if_index (ne);
579  if (vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index)
580  return;
581 
583 
584  if (INDEX_INVALID == t_idx)
585  return;
586 
587  t = pool_elt_at_index (gm->tunnels, t_idx);
588 
589  ipip_teib_mk_key (t, ne, &key);
590  ipip_tunnel_db_add (t, &key);
591 
592  // update the rewrites for each of the adjacencies for this next-hop
594  .t = t,
595  .ne = ne
596  };
597  nh = teib_entry_get_peer (ne);
599  (AF_IP4 == ip_addr_version (nh) ?
602  &ip_addr_46 (nh), mipip_mk_complete_walk, &ctx);
603 }
604 
605 static void
607 {
609  const ip_address_t *nh;
610  ipip_tunnel_key_t key;
611  ipip_tunnel_t *t;
613  u32 t_idx;
614 
615  sw_if_index = teib_entry_get_sw_if_index (ne);
616  if (vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index)
617  return;
618 
620 
621  if (INDEX_INVALID == t_idx)
622  return;
623 
624  t = pool_elt_at_index (gm->tunnels, t_idx);
625 
626  ipip_teib_mk_key (t, ne, &key);
627  ipip_tunnel_db_remove (t, &key);
628 
629  nh = teib_entry_get_peer (ne);
630 
631  /* make all the adjacencies incomplete */
633  (AF_IP4 == ip_addr_version (nh) ?
637 }
638 
639 static walk_rc_t
641 {
642  ipip_tunnel_t *t = ctx;
643  ipip_tunnel_key_t key;
644 
645  ipip_teib_mk_key (t, teib_entry_get (nei), &key);
646  ipip_tunnel_db_remove (t, &key);
647 
648  return (WALK_CONTINUE);
649 }
650 
651 static walk_rc_t
653 {
654  ipip_tunnel_t *t = ctx;
655  ipip_tunnel_key_t key;
656 
657  ipip_teib_mk_key (t, teib_entry_get (nei), &key);
658  ipip_tunnel_db_add (t, &key);
659 
660  return (WALK_CONTINUE);
661 }
662 
663 int
664 ipip_add_tunnel (ipip_transport_t transport,
665  u32 instance, ip46_address_t * src, ip46_address_t * dst,
667  ip_dscp_t dscp, tunnel_mode_t tmode, u32 * sw_if_indexp)
668 {
670  vnet_main_t *vnm = gm->vnet_main;
671  ip4_main_t *im4 = &ip4_main;
672  ip6_main_t *im6 = &ip6_main;
673  ipip_tunnel_t *t;
675  u32 hw_if_index, sw_if_index;
676  ipip_tunnel_key_t key;
677  ipip_mode_t mode;
678 
679  if (tmode == TUNNEL_MODE_MP && !ip46_address_is_zero (dst))
680  return (VNET_API_ERROR_INVALID_DST_ADDRESS);
681 
682  mode = (tmode == TUNNEL_MODE_P2P ? IPIP_MODE_P2P : IPIP_MODE_P2MP);
683  ipip_mk_key_i (transport, mode, src, dst, fib_index, &key);
684 
685  t = ipip_tunnel_db_find (&key);
686  if (t)
687  {
688  if (sw_if_indexp)
689  sw_if_indexp[0] = t->sw_if_index;
690  return VNET_API_ERROR_IF_ALREADY_EXISTS;
691  }
692 
694  clib_memset (t, 0, sizeof (*t));
695 
696  /* Reconcile the real dev_instance and a possible requested instance */
697  u32 t_idx = t - gm->tunnels; /* tunnel index (or instance) */
698  u32 u_idx = instance; /* user specified instance */
699  if (u_idx == ~0)
700  u_idx = t_idx;
701  if (hash_get (gm->instance_used, u_idx))
702  {
703  pool_put (gm->tunnels, t);
704  return VNET_API_ERROR_INSTANCE_IN_USE;
705  }
706  hash_set (gm->instance_used, u_idx, 1);
707 
708  t->dev_instance = t_idx; /* actual */
709  t->user_instance = u_idx; /* name */
710 
711  hw_if_index = vnet_register_interface (vnm, ipip_device_class.index, t_idx,
712  (mode == IPIP_MODE_P2P ?
714  mipip_hw_interface_class.index),
715  t_idx);
716 
717  hi = vnet_get_hw_interface (vnm, hw_if_index);
718  sw_if_index = hi->sw_if_index;
719 
720  t->mode = mode;
721  t->hw_if_index = hw_if_index;
722  t->fib_index = fib_index;
724  t->dscp = dscp;
725  t->flags = flags;
726  t->transport = transport;
727 
730 
731  if (t->transport == IPIP_TRANSPORT_IP4)
732  {
733  vec_validate (im4->fib_index_by_sw_if_index, sw_if_index);
734  hi->min_packet_bytes = 64 + sizeof (ip4_header_t);
735  }
736  else
737  {
738  vec_validate (im6->fib_index_by_sw_if_index, sw_if_index);
739  hi->min_packet_bytes = 64 + sizeof (ip6_header_t);
740  }
741 
742  /* Standard default ipip MTU. */
743  vnet_sw_interface_set_mtu (vnm, sw_if_index, 9000);
744 
745  t->tunnel_src = *src;
746  t->tunnel_dst = *dst;
747 
748  ipip_tunnel_db_add (t, &key);
749 
750  if (t->mode == IPIP_MODE_P2MP)
752 
753  if (sw_if_indexp)
754  *sw_if_indexp = sw_if_index;
755 
757  {
758  ip6_register_protocol (IP_PROTOCOL_IP_IN_IP, ipip6_input_node.index);
759  ip6_register_protocol (IP_PROTOCOL_IPV6, ipip6_input_node.index);
760  gm->ip6_protocol_registered = true;
761  }
763  {
764  ip4_register_protocol (IP_PROTOCOL_IP_IN_IP, ipip4_input_node.index);
765  ip4_register_protocol (IP_PROTOCOL_IPV6, ipip4_input_node.index);
766  gm->ip4_protocol_registered = true;
767  }
768  return 0;
769 }
770 
771 int
773 {
775  vnet_main_t *vnm = gm->vnet_main;
776  ipip_tunnel_t *t;
777  ipip_tunnel_key_t key;
778 
779  t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index);
780  if (t == NULL)
781  return VNET_API_ERROR_NO_SUCH_ENTRY;
782 
783  if (t->mode == IPIP_MODE_P2MP)
785 
786  vnet_sw_interface_set_flags (vnm, sw_if_index, 0 /* down */ );
790 
791  ipip_mk_key (t, &key);
792  ipip_tunnel_db_remove (t, &key);
793  pool_put (gm->tunnels, t);
794 
795  return 0;
796 }
797 
798 const static teib_vft_t ipip_teib_vft = {
800  .nv_deleted = ipip_teib_entry_deleted,
801 };
802 
803 static clib_error_t *
805 {
807 
808  clib_memset (gm, 0, sizeof (gm[0]));
809  gm->vlib_main = vm;
810  gm->vnet_main = vnet_get_main ();
811  gm->tunnel_by_key =
812  hash_create_mem (0, sizeof (ipip_tunnel_key_t), sizeof (uword));
813 
814  teib_register (&ipip_teib_vft);
815 
816  return 0;
817 }
818 
820 
821 /*
822  * fd.io coding-style-patch-verification: ON
823  *
824  * Local Variables:
825  * eval: (c-set-style "gnu")
826  * End:
827  */
ipip_tunnel_t * ipip_tunnel_db_find(const ipip_tunnel_key_t *key)
Definition: ipip.c:493
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:509
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
static adj_walk_rc_t mipip_mk_complete_walk(adj_index_t ai, void *data)
Definition: ipip.c:315
void adj_nbr_walk_nh(u32 sw_if_index, fib_protocol_t adj_nh_proto, const ip46_address_t *nh, adj_walk_cb_t cb, void *ctx)
Walk adjacencies on a link with a given next-hop.
Definition: adj_nbr.c:663
#define hash_set(h, key, value)
Definition: hash.h:255
static int ipip_tunnel_desc(u32 sw_if_index, ip46_address_t *src, ip46_address_t *dst, u8 *is_l2)
Definition: ipip.c:444
#define CLIB_UNUSED(x)
Definition: clib.h:87
#define ip_addr_46(_a)
Definition: ip_types.h:90
static void ipip44_fixup(vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b, const void *data)
Definition: ipip.c:149
teib_entry_t * teib_entry_get(index_t tei)
Definition: teib.c:108
#define hash_unset(h, key)
Definition: hash.h:261
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
void ip6_register_protocol(u32 protocol, u32 node_index)
Definition: ip6_forward.c:1668
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, vnet_sw_interface_flags_t flags)
Definition: interface.c:519
static walk_rc_t ipip_tunnel_delete_teib_walk(index_t nei, void *ctx)
Definition: ipip.c:640
ip4_address_t src_address
Definition: ip4_packet.h:125
A representation of a IPIP tunnel.
Definition: ipip.h:75
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
void vnet_sw_interface_set_mtu(vnet_main_t *vnm, u32 sw_if_index, u32 mtu)
Definition: interface.c:686
vl_api_fib_path_nh_t nh
Definition: fib_types.api:126
ip46_address_t tunnel_src
Definition: ipip.h:82
static clib_error_t * ipip_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: ipip.c:421
u32 length
Definition: ipip.c:37
vnet_hw_interface_class_t ipip_hw_interface_class
void adj_midchain_delegate_stack(adj_index_t ai, u32 fib_index, const fib_prefix_t *pfx)
create/attach a midchain delegate and stack it on the prefix passed
vnet_link_t adj_get_link_type(adj_index_t ai)
Return the link type of the adjacency.
Definition: adj.c:506
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
IP unicast adjacency.
Definition: adj.h:235
a non-broadcast multiple access interface
Definition: interface.h:391
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
vl_api_address_t src
Definition: gre.api:54
void ipip_tunnel_db_add(ipip_tunnel_t *t, const ipip_tunnel_key_t *key)
Definition: ipip.c:517
static u8 * format_ipip_device(u8 *s, va_list *args)
Definition: ipip.c:411
static void ipip_teib_entry_added(const teib_entry_t *ne)
Definition: ipip.c:569
u32 vnet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u32 hw_class_index, u32 hw_instance)
Definition: interface.c:794
vlib_main_t * vm
Definition: in2out_ed.c:1580
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:123
void(* adj_midchain_fixup_t)(vlib_main_t *vm, const struct ip_adjacency_t_ *adj, vlib_buffer_t *b0, const void *data)
A function type for post-rewrite fixups on midchain adjacency.
Definition: adj.h:152
static void ip4_header_set_dscp(ip4_header_t *ip4, ip_dscp_t dscp)
Definition: ip4_packet.h:320
int ipip_add_tunnel(ipip_transport_t transport, u32 instance, ip46_address_t *src, ip46_address_t *dst, u32 fib_index, tunnel_encap_decap_flags_t flags, ip_dscp_t dscp, tunnel_mode_t tmode, u32 *sw_if_indexp)
Definition: ipip.c:664
void ip4_register_protocol(u32 protocol, u32 node_index)
Definition: ip4_forward.c:1894
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
Definition: interface.c:509
#define ip_addr_version(_a)
Definition: ip_types.h:93
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:402
u32 hw_if_index
Definition: ipip.h:85
ip6_address_t src_address
Definition: ip6_packet.h:310
bool ip4_protocol_registered
Definition: ipip.h:117
unsigned char u8
Definition: types.h:56
void ipip_mk_key(const ipip_tunnel_t *t, ipip_tunnel_key_t *key)
Definition: ipip.c:548
u8 data[128]
Definition: ipsec_types.api:90
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
void teib_walk_itf(u32 sw_if_index, teib_walk_cb_t fn, void *ctx)
Definition: teib.c:328
static void ipip64_fixup(vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b, const void *data)
Definition: ipip.c:133
u32 teib_entry_get_fib_index(const teib_entry_t *te)
Definition: teib.c:84
enum walk_rc_t_ walk_rc_t
Walk return code.
void ipip_tunnel_db_remove(ipip_tunnel_t *t, const ipip_tunnel_key_t *key)
Definition: ipip.c:525
const ipip_tunnel_t * t
Definition: ipip.c:310
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:467
struct ip_adjacency_t_::@161::@162 nbr
IP_LOOKUP_NEXT_ARP/IP_LOOKUP_NEXT_REWRITE.
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
u32 user_instance
Definition: ipip.h:88
vl_api_ip6_address_t ip6
Definition: one.api:424
static_always_inline void tunnel_encap_fixup_6o6(tunnel_encap_decap_flags_t flags, const ip6_header_t *inner, ip6_header_t *outer)
Definition: tunnel_dp.h:104
ip4_address_t dst_address
Definition: ip4_packet.h:125
teib_entry_added_t nv_added
Definition: teib.h:74
enum adj_walk_rc_t_ adj_walk_rc_t
return codes from a adjacency walker callback function
description fragment has unexpected format
Definition: map.api:433
static adj_midchain_fixup_t ipip_get_fixup(const ipip_tunnel_t *t, vnet_link_t lt, adj_flags_t *aflags)
Definition: ipip.c:262
void mipip_update_adj(vnet_main_t *vnm, u32 sw_if_index, adj_index_t ai)
Definition: ipip.c:360
static void ipip_tunnel_restack(ipip_tunnel_t *gt)
Definition: ipip.c:248
Aggregate type for a prefix.
Definition: fib_types.h:202
u32 tunnel_id
Definition: ipip.c:36
u32 * tunnel_index_by_sw_if_index
Definition: ipip.h:108
const cJSON *const b
Definition: cJSON.h:255
unsigned int u32
Definition: types.h:88
ip46_address_t dst
Definition: ipip.c:39
vl_api_ip_dscp_t dscp
Definition: dhcp.api:163
static walk_rc_t ipip_tunnel_add_teib_walk(index_t nei, void *ctx)
Definition: ipip.c:652
static_always_inline void tunnel_encap_fixup_4o6(tunnel_encap_decap_flags_t flags, const ip4_header_t *inner, ip6_header_t *outer)
Definition: tunnel_dp.h:114
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:661
#define hash_get(h, key)
Definition: hash.h:249
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
static void ipip_tunnel_stack(adj_index_t ai)
Definition: ipip.c:205
tunnel_encap_decap_flags_t flags
Definition: ipip.h:89
static u8 * ipip_build_rewrite(vnet_main_t *vnm, u32 sw_if_index, vnet_link_t link_type, const void *dst_address)
Definition: ipip.c:57
static uword vnet_hw_interface_get_flags(vnet_main_t *vnm, u32 hw_if_index)
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:225
u32 teib_entry_get_sw_if_index(const teib_entry_t *te)
accessors for the opaque struct
Definition: teib.c:72
vl_api_ip_proto_t proto
Definition: acl_types.api:51
#define gm
Definition: dlmalloc.c:1219
static u8 ip46_address_is_zero(const ip46_address_t *ip46)
Definition: ip46_address.h:87
long ctx[MAX_CONNS]
Definition: main.c:144
ipip_tunnel_t * ipip_tunnel_db_find_by_sw_if_index(u32 sw_if_index)
Definition: ipip.c:505
static void ip4_header_set_df(ip4_header_t *ip4)
Definition: ip4_packet.h:363
static void ipip_teib_entry_deleted(const teib_entry_t *ne)
Definition: ipip.c:606
static void ipip46_fixup(vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b, const void *data)
Definition: ipip.c:165
ipip_tunnel_t * tunnels
Definition: ipip.h:106
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:233
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:301
vl_api_ip4_address_t ip4
Definition: one.api:376
ip6_main_t ip6_main
Definition: ip6_forward.c:2785
vl_api_address_t dst
Definition: gre.api:55
u8 * format_ipip_tx_trace(u8 *s, va_list *args)
Definition: ipip.c:43
enum tunnel_encap_decap_flags_t_ tunnel_encap_decap_flags_t
vl_api_tunnel_mode_t mode
Definition: gre.api:48
static_always_inline void ip6_set_dscp_network_order(ip6_header_t *ip6, ip_dscp_t dscp)
Definition: ip6_packet.h:356
format_function_t format_ip46_address
Definition: ip46_address.h:50
static adj_walk_rc_t ipip_adj_walk_cb(adj_index_t ai, void *ctx)
Definition: ipip.c:240
void teib_entry_adj_stack(const teib_entry_t *te, adj_index_t ai)
Definition: teib.c:102
ip_dscp_t dscp
Definition: ipip.h:90
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:245
VNET_HW_INTERFACE_CLASS(ipip_hw_interface_class)
ipip_main_t ipip_main
Definition: ipip.c:31
Definition: teib.c:33
const ip_address_t * teib_entry_get_peer(const teib_entry_t *te)
Definition: teib.c:90
static u8 * format_ipip_tunnel_name(u8 *s, va_list *args)
Definition: ipip.c:397
void adj_nbr_midchain_update_rewrite(adj_index_t adj_index, adj_midchain_fixup_t fixup, const void *fixup_data, adj_flags_t flags, u8 *rewrite)
adj_nbr_midchain_update_rewrite
Definition: adj_midchain.c:440
vlib_node_registration_t ipip4_input_node
(constructor) VLIB_REGISTER_NODE (ipip4_input_node)
Definition: node.c:252
static_always_inline void tunnel_encap_fixup_4o4(tunnel_encap_decap_flags_t flags, const ip4_header_t *inner, ip4_header_t *outer)
Definition: tunnel_dp.h:24
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
void adj_nbr_walk(u32 sw_if_index, fib_protocol_t adj_nh_proto, adj_walk_cb_t cb, void *ctx)
Walk all adjacencies on a link for a given next-hop protocol.
Definition: adj_nbr.c:571
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1580
void adj_midchain_delegate_unstack(adj_index_t ai)
unstack a midchain delegate (this stacks it on a drop)
static void ipip66_fixup(vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b, const void *data)
Definition: ipip.c:185
static void ipip_teib_mk_key(const ipip_tunnel_t *t, const teib_entry_t *ne, ipip_tunnel_key_t *key)
Definition: ipip.c:555
#define uword_to_pointer(u, type)
Definition: types.h:136
u32 fib_index
Definition: ipip.h:84
#define ASSERT(truth)
ipip_transport_t transport
Definition: ipip.h:81
enum ip_dscp_t_ ip_dscp_t
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
void vnet_delete_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface.c:1011
IPv4 main type.
Definition: ip4.h:107
uword * tunnel_by_key
Definition: ipip.h:107
static void hash_unset_mem_free(uword **h, const void *key)
Definition: hash.h:295
ip46_address_t src
Definition: ipip.c:38
static uword pointer_to_uword(const void *p)
Definition: types.h:131
void ipip_update_adj(vnet_main_t *vnm, u32 sw_if_index, adj_index_t ai)
Definition: ipip.c:281
u32 sw_if_index
Definition: ipip.h:86
vl_api_ip4_address_t hi
Definition: arp.api:37
enum adj_flags_t_ adj_flags_t
Flags on an IP adjacency.
union ip_adjacency_t_::@161 sub_type
typedef key
Definition: ipsec_types.api:86
vlib_node_registration_t ipip6_input_node
(constructor) VLIB_REGISTER_NODE (ipip6_input_node)
Definition: node.c:268
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:297
fib_protocol_t ia_nh_proto
The protocol of the neighbor/peer.
Definition: adj.h:350
u16 payload_length
Definition: ip6_packet.h:301
static_always_inline void tunnel_encap_fixup_6o4(tunnel_encap_decap_flags_t flags, const ip6_header_t *inner, ip4_header_t *outer)
Definition: tunnel_dp.h:72
teib_entry_t * teib_entry_find_46(u32 sw_if_index, fib_protocol_t fproto, const ip46_address_t *peer)
Definition: teib.c:131
vnet_main_t * vnet_main
Definition: ipip.h:112
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 instance
Definition: gre.api:51
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
VLIB buffer representation.
Definition: buffer.h:102
bool ip6_protocol_registered
Definition: ipip.h:118
u64 uword
Definition: types.h:112
ipip_mode_t mode
Definition: ipip.h:80
static clib_error_t * ipip_init(vlib_main_t *vm)
Definition: ipip.c:804
a point 2 point interface
Definition: interface.h:387
struct mipip_walk_ctx_t_ mipip_walk_ctx_t
int ipip_del_tunnel(u32 sw_if_index)
Definition: ipip.c:772
void ipip_mk_key_i(ipip_transport_t transport, ipip_mode_t mode, const ip46_address_t *src, const ip46_address_t *dst, u32 fib_index, ipip_tunnel_key_t *key)
Definition: ipip.c:533
#define FOR_EACH_FIB_IP_PROTOCOL(_item)
Definition: fib_types.h:69
#define hash_get_mem(h, key)
Definition: hash.h:269
u32 dev_instance
Definition: ipip.h:87
const teib_entry_t * ne
Definition: ipip.c:311
static adj_walk_rc_t mipip_mk_incomplete_walk(adj_index_t ai, void *data)
Definition: ipip.c:343
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1105
static void hash_set_mem_alloc(uword **h, const void *key, uword v)
Definition: hash.h:279
u8 ip_version_and_header_length
Definition: ip4_packet.h:93
ip46_address_t tunnel_dst
Definition: ipip.h:83
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:556
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
void teib_register(const teib_vft_t *vft)
Definition: teib.c:408
vlib_main_t * vlib_main
Definition: ipip.h:111
u32 * fib_index_by_sw_if_index
Definition: ip6.h:127
enum tunnel_mode_t_ tunnel_mode_t
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:314
uword * instance_used
Definition: ipip.h:115
VNET_DEVICE_CLASS(ipip_device_class)
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
ip6_address_t dst_address
Definition: ip6_packet.h:310
const fib_prefix_t * teib_entry_get_nh(const teib_entry_t *te)
Definition: teib.c:96