2 * ipsec_tun.h : IPSEC tunnel protection
4 * Copyright (c) 2015 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 agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vnet/ipsec/ipsec_tun.h>
19 #include <vnet/ipsec/esp.h>
20 #include <vnet/udp/udp.h>
21 #include <vnet/adj/adj_delegate.h>
22 #include <vnet/adj/adj_midchain.h>
23 #include <vnet/teib/teib.h>
28 vlib_log_class_t ipsec_tun_protect_logger;
31 * Pool of tunnel protection objects
33 ipsec_tun_protect_t *ipsec_tun_protect_pool;
36 * Adj delegate registered type
38 static adj_delegate_type_t ipsec_tun_adj_delegate_type;
41 * Adj index to TX SA mapping
43 index_t *ipsec_tun_protect_sa_by_adj_index;
45 const ip_address_t IP_ADDR_ALL_0 = IP_ADDRESS_V4_ALL_0S;
48 * The DB of all added per-nh tunnel protectiond
50 typedef struct ipsec_tun_protect_itf_db_t_
52 /** A hash table key'd on IP (4 or 6) address */
54 /** If the interface is P2P then there is only one protect
55 * object associated with the auto-adj for each NH proto */
57 } ipsec_tun_protect_itf_db_t;
59 typedef struct ipsec_tun_protect_db_t_
61 /** Per-interface vector */
62 ipsec_tun_protect_itf_db_t *id_itf;
63 } ipsec_tun_protect_db_t;
65 static ipsec_tun_protect_db_t itp_db;
67 const static ipsec_tun_protect_itf_db_t IPSEC_TUN_PROTECT_DEFAULT_DB_ENTRY = {
68 .id_itp = INDEX_INVALID,
71 #define ITP_DBG(_itp, _fmt, _args...) \
73 vlib_log_debug(ipsec_tun_protect_logger, \
75 format_ipsec_tun_protect, \
79 #define ITP_DBG2(_fmt, _args...) \
81 vlib_log_debug(ipsec_tun_protect_logger, \
85 static u32 ipsec_tun_node_regs[N_AF];
88 ipsec_tun_register_nodes (ip_address_family_t af)
90 if (0 == ipsec_tun_node_regs[af]++)
94 ipsec_register_udp_port (UDP_DST_PORT_ipsec);
95 ip4_register_protocol (IP_PROTOCOL_IPSEC_ESP,
96 ipsec4_tun_input_node.index);
99 ip6_register_protocol (IP_PROTOCOL_IPSEC_ESP,
100 ipsec6_tun_input_node.index);
105 ipsec_tun_unregister_nodes (ip_address_family_t af)
107 ASSERT (0 != ipsec_tun_node_regs[af]);
108 if (0 == --ipsec_tun_node_regs[af])
112 ipsec_unregister_udp_port (UDP_DST_PORT_ipsec);
113 ip4_unregister_protocol (IP_PROTOCOL_IPSEC_ESP);
116 ip6_unregister_protocol (IP_PROTOCOL_IPSEC_ESP);
120 static inline const ipsec_tun_protect_t *
121 ipsec_tun_protect_from_const_base (const adj_delegate_t * ad)
125 return (pool_elt_at_index (ipsec_tun_protect_pool, ad->ad_index));
129 ipsec_tun_protect_get_adj_next (const ipsec_tun_protect_t * itp)
136 is_ip4 = ip46_address_is_ip4 (&itp->itp_tun.src);
137 sa = ipsec_sa_get (itp->itp_out_sa);
140 if (sa->crypto_alg == IPSEC_CRYPTO_ALG_NONE &&
141 sa->integ_alg == IPSEC_INTEG_ALG_NONE)
143 im->esp4_no_crypto_tun_node_index :
144 im->esp6_no_crypto_tun_node_index);
145 else if (itp->itp_flags & IPSEC_PROTECT_L2)
147 im->esp4_encrypt_l2_tun_node_index :
148 im->esp6_encrypt_l2_tun_node_index);
151 im->esp4_encrypt_tun_node_index :
152 im->esp6_encrypt_tun_node_index);
158 ipsec_tun_protect_add_adj (adj_index_t ai, const ipsec_tun_protect_t * itp)
160 vec_validate_init_empty (ipsec_tun_protect_sa_by_adj_index, ai,
165 ipsec_tun_protect_sa_by_adj_index[ai] = INDEX_INVALID;
166 adj_nbr_midchain_reset_next_node (ai);
170 ipsec_tun_protect_sa_by_adj_index[ai] = itp->itp_out_sa;
171 adj_nbr_midchain_update_next_node
172 (ai, ipsec_tun_protect_get_adj_next (itp));
177 ipsec_tun_protect_find (u32 sw_if_index, const ip_address_t * nh)
179 ipsec_tun_protect_itf_db_t *idi;
182 if (vec_len (itp_db.id_itf) <= sw_if_index)
183 return INDEX_INVALID;
185 if (vnet_sw_interface_is_p2p (vnet_get_main (), sw_if_index))
186 return (itp_db.id_itf[sw_if_index].id_itp);
188 idi = &itp_db.id_itf[sw_if_index];
189 p = hash_get_mem (idi->id_hash, nh);
193 return INDEX_INVALID;
199 ipsec_tun_protect_rx_db_add (ipsec_main_t * im,
200 const ipsec_tun_protect_t * itp)
202 const ipsec_sa_t *sa;
205 if (ip46_address_is_zero (&itp->itp_crypto.dst))
209 FOR_EACH_IPSEC_PROTECT_INPUT_SAI(itp, sai,
211 sa = ipsec_sa_get (sai);
213 ipsec_tun_lkup_result_t res = {
214 .tun_index = itp - ipsec_tun_protect_pool,
219 * The key is formed from the tunnel's destination
220 * as the packet lookup is done from the packet's source
222 if (ip46_address_is_ip4 (&itp->itp_crypto.dst))
224 ipsec4_tunnel_key_t key = {
225 .remote_ip = itp->itp_crypto.dst.ip4,
226 .spi = clib_host_to_net_u32 (sa->spi),
228 hash_set (im->tun4_protect_by_key, key.as_u64, res.as_u64);
229 ipsec_tun_register_nodes(AF_IP4);
233 ipsec6_tunnel_key_t key = {
234 .remote_ip = itp->itp_crypto.dst.ip6,
235 .spi = clib_host_to_net_u32 (sa->spi),
237 hash_set_mem_alloc (&im->tun6_protect_by_key, &key, res.as_u64);
238 ipsec_tun_register_nodes(AF_IP6);
245 ipsec_tun_protect_adj_add (adj_index_t ai, void *arg)
247 ipsec_tun_protect_t *itp = arg;
248 adj_delegate_add (adj_get (ai), ipsec_tun_adj_delegate_type,
249 itp - ipsec_tun_protect_pool);
250 ipsec_tun_protect_add_adj (ai, itp);
252 return (ADJ_WALK_RC_CONTINUE);
256 ipsec_tun_protect_tx_db_add (ipsec_tun_protect_t * itp)
259 * add the delegate to the adj
261 ipsec_tun_protect_itf_db_t *idi;
262 fib_protocol_t nh_proto;
265 vec_validate_init_empty (itp_db.id_itf,
266 itp->itp_sw_if_index,
267 IPSEC_TUN_PROTECT_DEFAULT_DB_ENTRY);
269 idi = &itp_db.id_itf[itp->itp_sw_if_index];
271 if (vnet_sw_interface_is_p2p (vnet_get_main (), itp->itp_sw_if_index))
273 if (INDEX_INVALID == idi->id_itp)
275 // ipsec_tun_protect_feature_set (itp, 1);
277 idi->id_itp = itp - ipsec_tun_protect_pool;
279 FOR_EACH_FIB_IP_PROTOCOL (nh_proto)
280 adj_nbr_walk (itp->itp_sw_if_index,
281 nh_proto, ipsec_tun_protect_adj_add, itp);
285 if (NULL == idi->id_hash)
288 hash_create_mem (0, sizeof (ip_address_t), sizeof (uword));
290 * enable the encrypt feature for egress if this is the first addition
293 // ipsec_tun_protect_feature_set (itp, 1);
296 hash_set_mem (idi->id_hash, itp->itp_key, itp - ipsec_tun_protect_pool);
299 * walk all the adjs with the same nh on this interface
300 * to associate them with this protection
302 nh_proto = ip_address_to_46 (itp->itp_key, &nh);
304 adj_nbr_walk_nh (itp->itp_sw_if_index,
305 nh_proto, &nh, ipsec_tun_protect_adj_add, itp);
307 ipsec_tun_register_nodes (FIB_PROTOCOL_IP6 == nh_proto ?
313 ipsec_tun_protect_rx_db_remove (ipsec_main_t * im,
314 const ipsec_tun_protect_t * itp)
316 const ipsec_sa_t *sa;
319 FOR_EACH_IPSEC_PROTECT_INPUT_SA(itp, sa,
321 if (ip46_address_is_ip4 (&itp->itp_crypto.dst))
323 ipsec4_tunnel_key_t key = {
324 .remote_ip = itp->itp_crypto.dst.ip4,
325 .spi = clib_host_to_net_u32 (sa->spi),
327 if (hash_get(im->tun4_protect_by_key, key.as_u64))
329 hash_unset (im->tun4_protect_by_key, key.as_u64);
330 ipsec_tun_unregister_nodes(AF_IP4);
335 ipsec6_tunnel_key_t key = {
336 .remote_ip = itp->itp_crypto.dst.ip6,
337 .spi = clib_host_to_net_u32 (sa->spi),
339 if (hash_get_mem(im->tun6_protect_by_key, &key))
341 hash_unset_mem_free (&im->tun6_protect_by_key, &key);
342 ipsec_tun_unregister_nodes(AF_IP6);
350 ipsec_tun_protect_adj_remove (adj_index_t ai, void *arg)
352 adj_delegate_remove (ai, ipsec_tun_adj_delegate_type);
353 ipsec_tun_protect_add_adj (ai, NULL);
355 return (ADJ_WALK_RC_CONTINUE);
359 ipsec_tun_protect_tx_db_remove (ipsec_tun_protect_t * itp)
361 ipsec_tun_protect_itf_db_t *idi;
362 fib_protocol_t nh_proto;
365 nh_proto = ip_address_to_46 (itp->itp_key, &nh);
366 idi = &itp_db.id_itf[itp->itp_sw_if_index];
368 if (vnet_sw_interface_is_p2p (vnet_get_main (), itp->itp_sw_if_index))
370 // ipsec_tun_protect_feature_set (itp, 0);
371 idi->id_itp = INDEX_INVALID;
373 FOR_EACH_FIB_IP_PROTOCOL (nh_proto)
374 adj_nbr_walk (itp->itp_sw_if_index,
375 nh_proto, ipsec_tun_protect_adj_remove, itp);
379 adj_nbr_walk_nh (itp->itp_sw_if_index,
380 nh_proto, &nh, ipsec_tun_protect_adj_remove, itp);
382 hash_unset_mem (idi->id_hash, itp->itp_key);
384 if (0 == hash_elts (idi->id_hash))
386 // ipsec_tun_protect_feature_set (itp, 0);
387 hash_free (idi->id_hash);
390 ipsec_tun_unregister_nodes (FIB_PROTOCOL_IP6 == nh_proto ?
396 ipsec_tun_protect_set_crypto_addr (ipsec_tun_protect_t * itp)
401 FOR_EACH_IPSEC_PROTECT_INPUT_SA(itp, sa,
403 if (ipsec_sa_is_set_IS_TUNNEL (sa))
405 itp->itp_crypto.src = sa->tunnel_dst_addr;
406 itp->itp_crypto.dst = sa->tunnel_src_addr;
407 ipsec_sa_set_IS_PROTECT (sa);
408 itp->itp_flags |= IPSEC_PROTECT_ENCAPED;
412 itp->itp_crypto.src = itp->itp_tun.src;
413 itp->itp_crypto.dst = itp->itp_tun.dst;
414 itp->itp_flags &= ~IPSEC_PROTECT_ENCAPED;
421 ipsec_tun_protect_config (ipsec_main_t * im,
422 ipsec_tun_protect_t * itp, u32 sa_out, u32 * sas_in)
427 itp->itp_n_sa_in = vec_len (sas_in);
428 for (ii = 0; ii < itp->itp_n_sa_in; ii++)
429 itp->itp_in_sas[ii] = sas_in[ii];
430 itp->itp_out_sa = sa_out;
432 ipsec_sa_lock (itp->itp_out_sa);
435 FOR_EACH_IPSEC_PROTECT_INPUT_SAI(itp, sai,
439 ipsec_tun_protect_set_crypto_addr(itp);
443 * add to the DB against each SA
445 ipsec_tun_protect_rx_db_add (im, itp);
446 ipsec_tun_protect_tx_db_add (itp);
448 ITP_DBG (itp, "configured");
452 ipsec_tun_protect_unconfig (ipsec_main_t * im, ipsec_tun_protect_t * itp)
458 FOR_EACH_IPSEC_PROTECT_INPUT_SA(itp, sa,
460 ipsec_sa_unset_IS_PROTECT (sa);
463 ipsec_tun_protect_rx_db_remove (im, itp);
464 ipsec_tun_protect_tx_db_remove (itp);
466 ipsec_sa_unlock(itp->itp_out_sa);
468 FOR_EACH_IPSEC_PROTECT_INPUT_SAI(itp, sai,
470 ipsec_sa_unlock(sai);
473 ITP_DBG (itp, "unconfigured");
477 ipsec_tun_protect_update_one (u32 sw_if_index,
478 const ip_address_t * nh, u32 sa_out, u32 sa_in)
483 vec_add1 (sas_in, sa_in);
484 rv = ipsec_tun_protect_update (sw_if_index, nh, sa_out, sas_in);
490 ipsec_tun_protect_update_out (u32 sw_if_index,
491 const ip_address_t * nh, u32 sa_out)
493 u32 itpi, *sas_in, sai, *saip;
494 ipsec_tun_protect_t *itp;
502 itpi = ipsec_tun_protect_find (sw_if_index, nh);
504 if (INDEX_INVALID == itpi)
506 return (VNET_API_ERROR_INVALID_INTERFACE);
509 itp = pool_elt_at_index (ipsec_tun_protect_pool, itpi);
512 FOR_EACH_IPSEC_PROTECT_INPUT_SAI (itp, sai,
515 vec_add1 (sas_in, sai);
519 sa_out = ipsec_sa_find_and_lock (sa_out);
523 rv = VNET_API_ERROR_INVALID_VALUE;
527 ipsec_tun_protect_unconfig (im, itp);
528 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
530 ipsec_sa_unlock (sa_out);
531 vec_foreach (saip, sas_in) ipsec_sa_unlock (*saip);
539 ipsec_tun_protect_update_in (u32 sw_if_index,
540 const ip_address_t * nh, u32 sa_in)
542 u32 itpi, *sas_in, sa_out;
543 ipsec_tun_protect_t *itp;
550 itpi = ipsec_tun_protect_find (sw_if_index, nh);
552 if (INDEX_INVALID == itpi)
554 return (VNET_API_ERROR_INVALID_INTERFACE);
557 sa_in = ipsec_sa_find_and_lock (sa_in);
561 rv = VNET_API_ERROR_INVALID_VALUE;
564 vec_add1 (sas_in, sa_in);
566 itp = pool_elt_at_index (ipsec_tun_protect_pool, itpi);
567 sa_out = itp->itp_out_sa;
569 ipsec_sa_lock (sa_out);
571 ipsec_tun_protect_unconfig (im, itp);
572 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
574 ipsec_sa_unlock (sa_out);
575 ipsec_sa_unlock (sa_in);
582 ipsec_tun_protect_update_from_teib (ipsec_tun_protect_t * itp,
583 const teib_entry_t * ne)
587 const fib_prefix_t *pfx;
589 pfx = teib_entry_get_nh (ne);
591 ip46_address_copy (&itp->itp_tun.dst, &pfx->fp_addr);
594 ip46_address_reset (&itp->itp_tun.dst);
598 ipsec_tun_protect_update (u32 sw_if_index,
599 const ip_address_t * nh, u32 sa_out, u32 * sas_in)
601 ipsec_tun_protect_t *itp;
606 ITP_DBG2 ("update: %U/%U",
607 format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index,
608 format_ip_address, nh);
610 if (vec_len (sas_in) > ITP_MAX_N_SA_IN)
612 rv = VNET_API_ERROR_LIMIT_EXCEEDED;
620 itpi = ipsec_tun_protect_find (sw_if_index, nh);
622 vec_foreach_index (ii, sas_in)
624 sas_in[ii] = ipsec_sa_find_and_lock (sas_in[ii]);
625 if (~0 == sas_in[ii])
627 rv = VNET_API_ERROR_INVALID_VALUE;
632 sa_out = ipsec_sa_find_and_lock (sa_out);
636 rv = VNET_API_ERROR_INVALID_VALUE;
640 if (INDEX_INVALID == itpi)
642 vnet_device_class_t *dev_class;
643 vnet_hw_interface_t *hi;
647 vnm = vnet_get_main ();
648 hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
649 dev_class = vnet_get_device_class (vnm, hi->dev_class_index);
651 if (NULL == dev_class->ip_tun_desc)
653 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
657 pool_get_zero (ipsec_tun_protect_pool, itp);
659 itp->itp_sw_if_index = sw_if_index;
661 itp->itp_n_sa_in = vec_len (sas_in);
662 for (ii = 0; ii < itp->itp_n_sa_in; ii++)
663 itp->itp_in_sas[ii] = sas_in[ii];
664 itp->itp_out_sa = sa_out;
666 itp->itp_key = clib_mem_alloc (sizeof (*itp->itp_key));
667 ip_address_copy (itp->itp_key, nh);
669 rv = dev_class->ip_tun_desc (sw_if_index,
671 &itp->itp_tun.dst, &is_l2);
676 if (ip46_address_is_zero (&itp->itp_tun.dst))
678 /* tunnel has no destination address, presumably because it's p2mp
679 in which case we use the nh that this is protection for */
682 ip_address_to_46 (nh, &peer);
684 ipsec_tun_protect_update_from_teib
685 (itp, teib_entry_find (sw_if_index, &peer));
689 itp->itp_flags |= IPSEC_PROTECT_L2;
692 * add to the tunnel DB for ingress
693 * - if the SA is in trasnport mode, then the packates will arrivw
694 * with the IP src,dst of the protected tunnel, in which case we can
695 * simply strip the IP header and hand the payload to the protocol
696 * appropriate input handler
697 * - if the SA is in tunnel mode then there are two IP headers present
698 * one for the crytpo tunnel endpoints (described in the SA) and one
699 * for the tunnel endpoints. The outer IP headers in the srriving
700 * packets will have the crypto endpoints. So the DB needs to contain
701 * the crpto endpoint. Once the crypto header is stripped, revealing,
702 * the tunnel-IP we have 2 choices:
703 * 1) do a tunnel lookup based on the revealed header
704 * 2) skip the tunnel lookup and assume that the packet matches the
705 * one that is protected here.
706 * If we did 1) then we would allow our peer to use the SA for tunnel
707 * X to inject traffic onto tunnel Y, this is not good. If we do 2)
708 * then we don't verify that the peer is indeed using SA for tunnel
709 * X and addressing tunnel X. So we take a compromise, once the SA
710 * matches to tunnel X we veriy that the inner IP matches the value
711 * of the tunnel we are protecting, else it's dropped.
713 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
717 /* updating SAs only */
718 itp = pool_elt_at_index (ipsec_tun_protect_pool, itpi);
720 ipsec_tun_protect_unconfig (im, itp);
721 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
724 ipsec_sa_unlock (sa_out);
725 vec_foreach (saip, sas_in) ipsec_sa_unlock (*saip);
733 ipsec_tun_protect_del (u32 sw_if_index, const ip_address_t * nh)
735 ipsec_tun_protect_t *itp;
739 ITP_DBG2 ("delete: %U/%U",
740 format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index,
741 format_ip_address, nh);
747 itpi = ipsec_tun_protect_find (sw_if_index, nh);
749 if (INDEX_INVALID == itpi)
750 return (VNET_API_ERROR_NO_SUCH_ENTRY);
752 itp = ipsec_tun_protect_get (itpi);
753 ipsec_tun_protect_unconfig (im, itp);
755 clib_mem_free (itp->itp_key);
756 pool_put (ipsec_tun_protect_pool, itp);
762 ipsec_tun_protect_walk (ipsec_tun_protect_walk_cb_t fn, void *ctx)
767 pool_foreach_index(itpi, ipsec_tun_protect_pool,
775 ipsec_tun_protect_walk_itf (u32 sw_if_index,
776 ipsec_tun_protect_walk_cb_t fn, void *ctx)
778 ipsec_tun_protect_itf_db_t *idi;
782 if (vec_len (itp_db.id_itf) <= sw_if_index)
785 idi = &itp_db.id_itf[sw_if_index];
788 hash_foreach(key, itpi, idi->id_hash,
793 if (INDEX_INVALID != idi->id_itp)
794 fn (idi->id_itp, ctx);
798 ipsec_tun_protect_adj_delegate_adj_deleted (adj_delegate_t * ad)
800 /* remove our delegate */
801 ipsec_tun_protect_add_adj (ad->ad_adj_index, NULL);
802 adj_delegate_remove (ad->ad_adj_index, ipsec_tun_adj_delegate_type);
806 ipsec_tun_protect_adj_delegate_adj_modified (adj_delegate_t * ad)
808 ipsec_tun_protect_add_adj (ad->ad_adj_index,
809 ipsec_tun_protect_get (ad->ad_index));
813 ipsec_tun_protect_adj_delegate_adj_created (adj_index_t ai)
815 /* add our delegate if there is protection for this neighbour */
816 ip_address_t ip = IP_ADDRESS_V4_ALL_0S;
820 if (!adj_is_midchain (ai))
825 ip_address_from_46 (&adj->sub_type.midchain.next_hop,
826 adj->ia_nh_proto, &ip);
828 itpi = ipsec_tun_protect_find (adj->rewrite_header.sw_if_index, &ip);
830 if (INDEX_INVALID != itpi)
832 const ipsec_tun_protect_t *itp;
834 itp = ipsec_tun_protect_get (itpi);
835 adj_delegate_add (adj_get (ai), ipsec_tun_adj_delegate_type, itpi);
836 ipsec_tun_protect_add_adj (ai, itp);
841 ipsec_tun_protect_adj_delegate_format (const adj_delegate_t * aed, u8 * s)
843 const ipsec_tun_protect_t *itp;
845 itp = ipsec_tun_protect_from_const_base (aed);
846 s = format (s, "ipsec-tun-protect:\n%U", format_ipsec_tun_protect, itp);
852 ipsec_tun_teib_entry_added (const teib_entry_t * ne)
854 const ip46_address_t *peer46;
855 ipsec_tun_protect_t *itp;
859 peer46 = teib_entry_get_peer (ne);
860 ip_address_from_46 (peer46,
861 (ip46_address_is_ip4 (peer46) ?
862 FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6), &peer);
864 itpi = ipsec_tun_protect_find (teib_entry_get_sw_if_index (ne), &peer);
866 if (INDEX_INVALID == itpi)
869 itp = ipsec_tun_protect_get (itpi);
870 ipsec_tun_protect_rx_db_remove (&ipsec_main, itp);
871 ipsec_tun_protect_update_from_teib (itp, ne);
872 ipsec_tun_protect_set_crypto_addr (itp);
873 ipsec_tun_protect_rx_db_add (&ipsec_main, itp);
875 ITP_DBG (itp, "teib-added");
879 ipsec_tun_teib_entry_deleted (const teib_entry_t * ne)
881 const ip46_address_t *peer46;
882 ipsec_tun_protect_t *itp;
886 peer46 = teib_entry_get_peer (ne);
887 ip_address_from_46 (peer46,
888 (ip46_address_is_ip4 (peer46) ?
889 FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6), &peer);
891 itpi = ipsec_tun_protect_find (teib_entry_get_sw_if_index (ne), &peer);
893 if (INDEX_INVALID == itpi)
896 itp = ipsec_tun_protect_get (itpi);
897 ipsec_tun_protect_rx_db_remove (&ipsec_main, itp);
898 ipsec_tun_protect_update_from_teib (itp, NULL);
899 ipsec_tun_protect_set_crypto_addr (itp);
901 ITP_DBG (itp, "teib-removed");
905 * VFT registered with the adjacency delegate
907 const static adj_delegate_vft_t ipsec_tun_adj_delegate_vft = {
908 .adv_adj_deleted = ipsec_tun_protect_adj_delegate_adj_deleted,
909 .adv_adj_created = ipsec_tun_protect_adj_delegate_adj_created,
910 .adv_adj_modified = ipsec_tun_protect_adj_delegate_adj_modified,
911 .adv_format = ipsec_tun_protect_adj_delegate_format,
914 const static teib_vft_t ipsec_tun_teib_vft = {
915 .nv_added = ipsec_tun_teib_entry_added,
916 .nv_deleted = ipsec_tun_teib_entry_deleted,
921 ipsec_tunnel_protect_init (vlib_main_t * vm)
926 im->tun6_protect_by_key = hash_create_mem (0,
927 sizeof (ipsec6_tunnel_key_t),
929 im->tun4_protect_by_key = hash_create (0, sizeof (u64));
931 /* set up feature nodes to drop outbound packets with no crypto alg set */
932 im->esp4_no_crypto_tun_node_index =
933 vlib_get_node_by_name (vm, (u8 *) "esp4-no-crypto")->index;
934 im->esp6_no_crypto_tun_node_index =
935 vlib_get_node_by_name (vm, (u8 *) "esp6-no-crypto")->index;
936 im->esp6_encrypt_l2_tun_node_index =
937 vlib_get_node_by_name (vm, (u8 *) "esp6-encrypt-tun")->index;
938 im->esp4_encrypt_l2_tun_node_index =
939 vlib_get_node_by_name (vm, (u8 *) "esp4-encrypt-tun")->index;
941 ipsec_tun_adj_delegate_type =
942 adj_delegate_register_new_type (&ipsec_tun_adj_delegate_vft);
944 ipsec_tun_protect_logger = vlib_log_register_class ("ipsec", "tun");
946 teib_register (&ipsec_tun_teib_vft);
951 VLIB_INIT_FUNCTION (ipsec_tunnel_protect_init);
955 * fd.io coding-style-patch-verification: ON
958 * eval: (c-set-style "gnu")