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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
31 ipip_main_t ipip_main;
33 /* Packet trace structure */
43 format_ipip_tx_trace (u8 * s, va_list * args)
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 *);
50 format (s, "IPIP: tunnel %d len %d src %U dst %U", t->tunnel_id,
51 t->length, format_ip46_address, &t->src, IP46_TYPE_ANY,
52 format_ip46_address, &t->dst, IP46_TYPE_ANY);
57 ipip_build_rewrite (vnet_main_t * vnm, u32 sw_if_index,
58 vnet_link_t link_type, const void *dst_address)
60 const ip46_address_t *dst;
67 t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index);
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;
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);
91 ip4->protocol = IP_PROTOCOL_IPV6;
94 ip4->protocol = IP_PROTOCOL_IP_IN_IP;
97 ip4->protocol = IP_PROTOCOL_MPLS_IN_IP;
102 ip4->checksum = ip4_header_checksum (ip4);
105 case IPIP_TRANSPORT_IP6:
106 vec_validate (rewrite, sizeof (*ip6) - 1);
107 ip6 = (ip6_header_t *) rewrite;
108 ip6->ip_version_traffic_class_and_flow_label =
109 clib_host_to_net_u32 (6 << 28);
111 /* fixup ip6 header length and protocol after-the-fact */
112 ip6->src_address.as_u64[0] = t->tunnel_src.ip6.as_u64[0];
113 ip6->src_address.as_u64[1] = t->tunnel_src.ip6.as_u64[1];
114 ip6->dst_address.as_u64[0] = dst->ip6.as_u64[0];
115 ip6->dst_address.as_u64[1] = dst->ip6.as_u64[1];
116 if (!(t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
117 ip6_set_dscp_network_order (ip6, t->dscp);
122 ip6->protocol = IP_PROTOCOL_IPV6;
125 ip6->protocol = IP_PROTOCOL_IP_IN_IP;
128 ip6->protocol = IP_PROTOCOL_MPLS_IN_IP;
139 ipip64_fixup (vlib_main_t * vm, const ip_adjacency_t * adj, vlib_buffer_t * b,
142 tunnel_encap_decap_flags_t flags;
145 flags = pointer_to_uword (data);
147 ip4 = vlib_buffer_get_current (b);
148 ip4->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b));
149 tunnel_encap_fixup_6o4 (flags, ((ip6_header_t *) (ip4 + 1)), ip4);
151 ip4->checksum = ip4_header_checksum (ip4);
155 ipip44_fixup (vlib_main_t * vm, const ip_adjacency_t * adj, vlib_buffer_t * b,
158 tunnel_encap_decap_flags_t flags;
161 flags = pointer_to_uword (data);
163 ip4 = vlib_buffer_get_current (b);
164 ip4->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b));
165 tunnel_encap_fixup_4o4 (flags, ip4 + 1, ip4);
167 ip4->checksum = ip4_header_checksum (ip4);
171 ipip46_fixup (vlib_main_t * vm, const ip_adjacency_t * adj, vlib_buffer_t * b,
174 tunnel_encap_decap_flags_t flags;
177 flags = pointer_to_uword (data);
179 /* Must set locally originated otherwise we're not allowed to
180 fragment the packet later */
181 b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
183 ip6 = vlib_buffer_get_current (b);
184 ip6->payload_length =
185 clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b) -
187 tunnel_encap_fixup_4o6 (flags, b, ((ip4_header_t *) (ip6 + 1)), ip6);
191 ipip66_fixup (vlib_main_t * vm,
192 const ip_adjacency_t * adj, vlib_buffer_t * b, const void *data)
194 tunnel_encap_decap_flags_t flags;
197 flags = pointer_to_uword (data);
199 /* Must set locally originated otherwise we're not allowed to
200 fragment the packet later */
201 b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
203 ip6 = vlib_buffer_get_current (b);
204 ip6->payload_length =
205 clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b) -
207 tunnel_encap_fixup_6o6 (flags, ip6 + 1, ip6);
211 ipipm6_fixup (vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b,
214 tunnel_encap_decap_flags_t flags;
217 flags = pointer_to_uword (data);
219 /* Must set locally originated otherwise we're not allowed to
220 fragment the packet later and we'll get an unwanted hop-limt
222 b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
224 ip6 = vlib_buffer_get_current (b);
225 ip6->payload_length =
226 clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b) - sizeof (*ip6));
227 tunnel_encap_fixup_mplso6 (flags, b, (mpls_unicast_header_t *) (ip6 + 1),
232 ipipm4_fixup (vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b,
235 tunnel_encap_decap_flags_t flags;
238 flags = pointer_to_uword (data);
240 /* Must set locally originated otherwise we'll do a TTL decrement
241 * during ip4-rewrite */
242 b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
244 ip4 = vlib_buffer_get_current (b);
246 clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b) - sizeof (*ip4));
247 tunnel_encap_fixup_mplso4 (flags, (mpls_unicast_header_t *) (ip4 + 1), ip4);
248 ip4->checksum = ip4_header_checksum (ip4);
252 ipip_tunnel_stack (adj_index_t ai)
259 sw_if_index = adj->rewrite_header.sw_if_index;
261 t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index);
265 if ((vnet_hw_interface_get_flags (vnet_get_main (), t->hw_if_index) &
266 VNET_HW_INTERFACE_FLAG_LINK_UP) == 0)
268 adj_midchain_delegate_unstack (ai);
273 .fp_len = t->transport == IPIP_TRANSPORT_IP6 ? 128 : 32,
274 .fp_proto = (t->transport == IPIP_TRANSPORT_IP6 ?
277 .fp_addr = t->tunnel_dst
280 adj_midchain_delegate_stack (ai, t->fib_index, &dst);
285 ipip_adj_walk_cb (adj_index_t ai, void *ctx)
287 ipip_tunnel_stack (ai);
289 return (ADJ_WALK_RC_CONTINUE);
293 ipip_tunnel_restack (ipip_tunnel_t * gt)
295 fib_protocol_t proto;
298 * walk all the adjacencies on th IPIP interface and restack them
300 FOR_EACH_FIB_IP_PROTOCOL (proto)
302 adj_nbr_walk (gt->sw_if_index, proto, ipip_adj_walk_cb, NULL);
306 static adj_midchain_fixup_t
307 ipip_get_fixup (const ipip_tunnel_t * t, vnet_link_t lt, adj_flags_t * aflags)
309 if (t->transport == IPIP_TRANSPORT_IP6 && lt == VNET_LINK_IP6)
310 return (ipip66_fixup);
311 if (t->transport == IPIP_TRANSPORT_IP6 && lt == VNET_LINK_IP4)
312 return (ipip46_fixup);
313 if (t->transport == IPIP_TRANSPORT_IP6 && lt == VNET_LINK_MPLS)
314 return (ipipm6_fixup);
315 if (t->transport == IPIP_TRANSPORT_IP4 && lt == VNET_LINK_IP6)
316 return (ipip64_fixup);
317 if (t->transport == IPIP_TRANSPORT_IP4 && lt == VNET_LINK_MPLS)
318 return (ipipm4_fixup);
319 if (t->transport == IPIP_TRANSPORT_IP4 && lt == VNET_LINK_IP4)
321 *aflags = *aflags | ADJ_FLAG_MIDCHAIN_FIXUP_IP4O4_HDR;
322 return (ipip44_fixup);
326 return (ipip44_fixup);
330 ipip_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
332 adj_midchain_fixup_t fixup;
337 t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index);
342 * the user has not requested that the load-balancing be based on
343 * a flow hash of the inner packet. so use the stacking to choose
346 if (!(t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_INNER_HASH))
347 af |= ADJ_FLAG_MIDCHAIN_IP_STACK;
349 fixup = ipip_get_fixup (t, adj_get_link_type (ai), &af);
350 adj_nbr_midchain_update_rewrite
352 uword_to_pointer (t->flags, void *), af,
353 ipip_build_rewrite (vnm, sw_if_index,
354 adj_get_link_type (ai), &t->tunnel_dst));
355 ipip_tunnel_stack (ai);
358 typedef struct mipip_walk_ctx_t_
360 const ipip_tunnel_t *t;
361 const teib_entry_t *ne;
365 mipip_mk_complete_walk (adj_index_t ai, void *data)
367 adj_midchain_fixup_t fixup;
368 mipip_walk_ctx_t *ctx = data;
372 fixup = ipip_get_fixup (ctx->t, adj_get_link_type (ai), &af);
375 * the user has not requested that the load-balancing be based on
376 * a flow hash of the inner packet. so use the stacking to choose
379 if (!(ctx->t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_INNER_HASH))
380 af |= ADJ_FLAG_MIDCHAIN_IP_STACK;
382 adj_nbr_midchain_update_rewrite
384 uword_to_pointer (ctx->t->flags, void *),
385 af, ipip_build_rewrite (vnet_get_main (),
387 adj_get_link_type (ai),
388 &teib_entry_get_nh (ctx->ne)->fp_addr));
390 teib_entry_adj_stack (ctx->ne, ai);
392 return (ADJ_WALK_RC_CONTINUE);
396 mipip_mk_incomplete_walk (adj_index_t ai, void *data)
398 adj_midchain_fixup_t fixup;
399 ipip_tunnel_t *t = data;
403 fixup = ipip_get_fixup (t, adj_get_link_type (ai), &af);
405 adj_nbr_midchain_update_rewrite (ai, fixup, NULL, ADJ_FLAG_NONE, NULL);
407 adj_midchain_delegate_unstack (ai);
409 return (ADJ_WALK_RC_CONTINUE);
413 mipip_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
415 ipip_main_t *gm = &ipip_main;
416 adj_midchain_fixup_t fixup;
425 ti = gm->tunnel_index_by_sw_if_index[sw_if_index];
426 t = pool_elt_at_index (gm->tunnels, ti);
428 ne = teib_entry_find_46 (sw_if_index,
429 adj->ia_nh_proto, &adj->sub_type.nbr.next_hop);
433 // no TEIB entry to provide the next-hop
434 fixup = ipip_get_fixup (t, adj_get_link_type (ai), &af);
435 adj_nbr_midchain_update_rewrite
436 (ai, fixup, uword_to_pointer (t->flags, void *), ADJ_FLAG_NONE, NULL);
440 mipip_walk_ctx_t ctx = {
444 adj_nbr_walk_nh (sw_if_index,
446 &adj->sub_type.nbr.next_hop, mipip_mk_complete_walk, &ctx);
450 format_ipip_tunnel_name (u8 * s, va_list * args)
452 u32 dev_instance = va_arg (*args, u32);
453 ipip_main_t *gm = &ipip_main;
456 if (dev_instance >= vec_len (gm->tunnels))
457 return format (s, "<improperly-referenced>");
459 t = pool_elt_at_index (gm->tunnels, dev_instance);
460 return format (s, "ipip%d", t->user_instance);
464 format_ipip_device (u8 * s, va_list * args)
466 u32 dev_instance = va_arg (*args, u32);
467 CLIB_UNUSED (int verbose) = va_arg (*args, int);
469 s = format (s, "IPIP tunnel: id %d\n", dev_instance);
473 static clib_error_t *
474 ipip_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
476 vnet_hw_interface_t *hi;
479 hi = vnet_get_hw_interface (vnm, hw_if_index);
481 t = ipip_tunnel_db_find_by_sw_if_index (hi->sw_if_index);
485 if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
486 vnet_hw_interface_set_flags (vnm, hw_if_index,
487 VNET_HW_INTERFACE_FLAG_LINK_UP);
489 vnet_hw_interface_set_flags (vnm, hw_if_index, 0 /* down */ );
491 ipip_tunnel_restack (t);
493 return /* no error */ 0;
497 ipip_tunnel_desc (u32 sw_if_index,
498 ip46_address_t * src, ip46_address_t * dst, u8 * is_l2)
502 t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index);
506 *src = t->tunnel_src;
507 *dst = t->tunnel_dst;
513 VNET_DEVICE_CLASS(ipip_device_class) = {
514 .name = "IPIP tunnel device",
515 .format_device_name = format_ipip_tunnel_name,
516 .format_device = format_ipip_device,
517 .format_tx_trace = format_ipip_tx_trace,
518 .admin_up_down_function = ipip_interface_admin_up_down,
519 .ip_tun_desc = ipip_tunnel_desc,
525 VNET_HW_INTERFACE_CLASS(ipip_hw_interface_class) = {
527 //.format_header = format_ipip_header_with_length,
528 //.unformat_header = unformat_ipip_header,
529 .build_rewrite = ipip_build_rewrite,
530 .update_adjacency = ipip_update_adj,
531 .flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
534 VNET_HW_INTERFACE_CLASS(mipip_hw_interface_class) = {
536 //.format_header = format_ipip_header_with_length,
537 //.unformat_header = unformat_ipip_header,
538 .build_rewrite = ipip_build_rewrite,
539 .update_adjacency = mipip_update_adj,
540 .flags = VNET_HW_INTERFACE_CLASS_FLAG_NBMA,
544 ipip_tunnel_db_find (const ipip_tunnel_key_t * key)
546 ipip_main_t *gm = &ipip_main;
549 p = hash_get_mem (gm->tunnel_by_key, key);
552 return (pool_elt_at_index (gm->tunnels, p[0]));
556 ipip_tunnel_db_find_by_sw_if_index (u32 sw_if_index)
558 ipip_main_t *gm = &ipip_main;
559 if (vec_len (gm->tunnel_index_by_sw_if_index) <= sw_if_index)
561 u32 ti = gm->tunnel_index_by_sw_if_index[sw_if_index];
564 return pool_elt_at_index (gm->tunnels, ti);
568 ipip_tunnel_db_add (ipip_tunnel_t * t, const ipip_tunnel_key_t * key)
570 ipip_main_t *gm = &ipip_main;
572 hash_set_mem_alloc (&gm->tunnel_by_key, key, t->dev_instance);
576 ipip_tunnel_db_remove (ipip_tunnel_t * t, const ipip_tunnel_key_t * key)
578 ipip_main_t *gm = &ipip_main;
580 hash_unset_mem_free (&gm->tunnel_by_key, key);
584 ipip_mk_key_i (ipip_transport_t transport,
586 const ip46_address_t * src,
587 const ip46_address_t * dst,
588 u32 fib_index, ipip_tunnel_key_t * key)
590 key->transport = transport;
594 key->fib_index = fib_index;
599 ipip_mk_key (const ipip_tunnel_t * t, ipip_tunnel_key_t * key)
601 ipip_mk_key_i (t->transport, t->mode,
602 &t->tunnel_src, &t->tunnel_dst, t->fib_index, key);
606 ipip_teib_mk_key (const ipip_tunnel_t * t,
607 const teib_entry_t * ne, ipip_tunnel_key_t * key)
609 const fib_prefix_t *nh;
611 nh = teib_entry_get_nh (ne);
613 /* construct the key using mode P2P so it can be found in the DP */
614 ipip_mk_key_i (t->transport, IPIP_MODE_P2P,
615 &t->tunnel_src, &nh->fp_addr,
616 teib_entry_get_fib_index (ne), key);
620 ipip_teib_entry_added (const teib_entry_t * ne)
622 ipip_main_t *gm = &ipip_main;
623 const ip_address_t *nh;
624 ipip_tunnel_key_t key;
629 sw_if_index = teib_entry_get_sw_if_index (ne);
630 if (vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index)
633 t_idx = gm->tunnel_index_by_sw_if_index[sw_if_index];
635 if (INDEX_INVALID == t_idx)
638 t = pool_elt_at_index (gm->tunnels, t_idx);
640 ipip_teib_mk_key (t, ne, &key);
641 ipip_tunnel_db_add (t, &key);
643 // update the rewrites for each of the adjacencies for this next-hop
644 mipip_walk_ctx_t ctx = {
648 nh = teib_entry_get_peer (ne);
649 adj_nbr_walk_nh (teib_entry_get_sw_if_index (ne),
650 (AF_IP4 == ip_addr_version (nh) ?
653 &ip_addr_46 (nh), mipip_mk_complete_walk, &ctx);
657 ipip_teib_entry_deleted (const teib_entry_t * ne)
659 ipip_main_t *gm = &ipip_main;
660 const ip_address_t *nh;
661 ipip_tunnel_key_t key;
666 sw_if_index = teib_entry_get_sw_if_index (ne);
667 if (vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index)
670 t_idx = gm->tunnel_index_by_sw_if_index[sw_if_index];
672 if (INDEX_INVALID == t_idx)
675 t = pool_elt_at_index (gm->tunnels, t_idx);
677 ipip_teib_mk_key (t, ne, &key);
678 ipip_tunnel_db_remove (t, &key);
680 nh = teib_entry_get_peer (ne);
682 /* make all the adjacencies incomplete */
683 adj_nbr_walk_nh (teib_entry_get_sw_if_index (ne),
684 (AF_IP4 == ip_addr_version (nh) ?
687 &ip_addr_46 (nh), mipip_mk_incomplete_walk, t);
691 ipip_tunnel_delete_teib_walk (index_t nei, void *ctx)
693 ipip_tunnel_t *t = ctx;
694 ipip_tunnel_key_t key;
696 ipip_teib_mk_key (t, teib_entry_get (nei), &key);
697 ipip_tunnel_db_remove (t, &key);
699 return (WALK_CONTINUE);
703 ipip_tunnel_add_teib_walk (index_t nei, void *ctx)
705 ipip_tunnel_t *t = ctx;
706 ipip_tunnel_key_t key;
708 ipip_teib_mk_key (t, teib_entry_get (nei), &key);
709 ipip_tunnel_db_add (t, &key);
711 return (WALK_CONTINUE);
715 ipip_add_tunnel (ipip_transport_t transport,
716 u32 instance, ip46_address_t * src, ip46_address_t * dst,
717 u32 fib_index, tunnel_encap_decap_flags_t flags,
718 ip_dscp_t dscp, tunnel_mode_t tmode, u32 * sw_if_indexp)
720 ipip_main_t *gm = &ipip_main;
721 vnet_main_t *vnm = gm->vnet_main;
723 vnet_hw_interface_t *hi;
724 u32 hw_if_index, sw_if_index;
725 ipip_tunnel_key_t key;
728 if (tmode == TUNNEL_MODE_MP && !ip46_address_is_zero (dst))
729 return (VNET_API_ERROR_INVALID_DST_ADDRESS);
731 mode = (tmode == TUNNEL_MODE_P2P ? IPIP_MODE_P2P : IPIP_MODE_P2MP);
732 ipip_mk_key_i (transport, mode, src, dst, fib_index, &key);
734 t = ipip_tunnel_db_find (&key);
738 sw_if_indexp[0] = t->sw_if_index;
739 return VNET_API_ERROR_IF_ALREADY_EXISTS;
742 pool_get_aligned (gm->tunnels, t, CLIB_CACHE_LINE_BYTES);
743 clib_memset (t, 0, sizeof (*t));
745 /* Reconcile the real dev_instance and a possible requested instance */
746 u32 t_idx = t - gm->tunnels; /* tunnel index (or instance) */
747 u32 u_idx = instance; /* user specified instance */
750 if (hash_get (gm->instance_used, u_idx))
752 pool_put (gm->tunnels, t);
753 return VNET_API_ERROR_INSTANCE_IN_USE;
755 hash_set (gm->instance_used, u_idx, 1);
757 t->dev_instance = t_idx; /* actual */
758 t->user_instance = u_idx; /* name */
760 hw_if_index = vnet_register_interface (vnm, ipip_device_class.index, t_idx,
761 (mode == IPIP_MODE_P2P ?
762 ipip_hw_interface_class.index :
763 mipip_hw_interface_class.index),
766 hi = vnet_get_hw_interface (vnm, hw_if_index);
767 sw_if_index = hi->sw_if_index;
770 t->hw_if_index = hw_if_index;
771 t->fib_index = fib_index;
772 t->sw_if_index = sw_if_index;
775 t->transport = transport;
777 vec_validate_init_empty (gm->tunnel_index_by_sw_if_index, sw_if_index, ~0);
778 gm->tunnel_index_by_sw_if_index[sw_if_index] = t_idx;
780 if (t->transport == IPIP_TRANSPORT_IP4)
781 hi->frame_overhead = sizeof (ip4_header_t);
783 hi->frame_overhead = sizeof (ip6_header_t);
785 hi->min_frame_size = hi->frame_overhead + 64;
787 /* Standard default ipip MTU. */
788 vnet_sw_interface_set_mtu (vnm, sw_if_index, 9000);
789 vnet_set_interface_l3_output_node (gm->vlib_main, sw_if_index,
790 (u8 *) "tunnel-output");
792 t->tunnel_src = *src;
793 t->tunnel_dst = *dst;
795 ipip_tunnel_db_add (t, &key);
797 if (t->mode == IPIP_MODE_P2MP)
798 teib_walk_itf (t->sw_if_index, ipip_tunnel_add_teib_walk, t);
801 *sw_if_indexp = sw_if_index;
803 if (t->transport == IPIP_TRANSPORT_IP6 && !gm->ip6_protocol_registered)
805 ip6_register_protocol (IP_PROTOCOL_IP_IN_IP, ipip6_input_node.index);
806 ip6_register_protocol (IP_PROTOCOL_MPLS_IN_IP, ipip6_input_node.index);
807 ip6_register_protocol (IP_PROTOCOL_IPV6, ipip6_input_node.index);
808 gm->ip6_protocol_registered = true;
810 else if (t->transport == IPIP_TRANSPORT_IP4 && !gm->ip4_protocol_registered)
812 ip4_register_protocol (IP_PROTOCOL_IP_IN_IP, ipip4_input_node.index);
813 ip4_register_protocol (IP_PROTOCOL_MPLS_IN_IP, ipip4_input_node.index);
814 ip4_register_protocol (IP_PROTOCOL_IPV6, ipip4_input_node.index);
815 gm->ip4_protocol_registered = true;
821 ipip_del_tunnel (u32 sw_if_index)
823 ipip_main_t *gm = &ipip_main;
824 vnet_main_t *vnm = gm->vnet_main;
826 ipip_tunnel_key_t key;
828 t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index);
830 return VNET_API_ERROR_NO_SUCH_ENTRY;
832 if (t->mode == IPIP_MODE_P2MP)
833 teib_walk_itf (t->sw_if_index, ipip_tunnel_delete_teib_walk, t);
835 vnet_sw_interface_set_flags (vnm, sw_if_index, 0 /* down */ );
836 vnet_reset_interface_l3_output_node (gm->vlib_main, t->sw_if_index);
837 gm->tunnel_index_by_sw_if_index[sw_if_index] = ~0;
838 vnet_delete_hw_interface (vnm, t->hw_if_index);
839 hash_unset (gm->instance_used, t->user_instance);
841 ipip_mk_key (t, &key);
842 ipip_tunnel_db_remove (t, &key);
843 pool_put (gm->tunnels, t);
848 const static teib_vft_t ipip_teib_vft = {
849 .nv_added = ipip_teib_entry_added,
850 .nv_deleted = ipip_teib_entry_deleted,
853 static clib_error_t *
854 ipip_init (vlib_main_t * vm)
856 ipip_main_t *gm = &ipip_main;
858 clib_memset (gm, 0, sizeof (gm[0]));
860 gm->vnet_main = vnet_get_main ();
862 hash_create_mem (0, sizeof (ipip_tunnel_key_t), sizeof (uword));
864 teib_register (&ipip_teib_vft);
869 VLIB_INIT_FUNCTION (ipip_init);
872 * fd.io coding-style-patch-verification: ON
875 * eval: (c-set-style "gnu")