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 udp_register_dst_port (vlib_get_main (),
96 ipsec4_tun_input_node.index, 1);
97 ip4_register_protocol (IP_PROTOCOL_IPSEC_ESP,
98 ipsec4_tun_input_node.index);
101 ip6_register_protocol (IP_PROTOCOL_IPSEC_ESP,
102 ipsec6_tun_input_node.index);
107 ipsec_tun_unregister_nodes (ip_address_family_t af)
109 ASSERT (0 != ipsec_tun_node_regs[af]);
110 if (0 == --ipsec_tun_node_regs[af])
114 udp_unregister_dst_port (vlib_get_main (), UDP_DST_PORT_ipsec, 1);
115 ip4_unregister_protocol (IP_PROTOCOL_IPSEC_ESP);
118 ip6_unregister_protocol (IP_PROTOCOL_IPSEC_ESP);
122 static inline const ipsec_tun_protect_t *
123 ipsec_tun_protect_from_const_base (const adj_delegate_t * ad)
127 return (pool_elt_at_index (ipsec_tun_protect_pool, ad->ad_index));
131 ipsec_tun_protect_get_adj_next (const ipsec_tun_protect_t * itp)
138 is_ip4 = ip46_address_is_ip4 (&itp->itp_tun.src);
139 sa = ipsec_sa_get (itp->itp_out_sa);
142 if (sa->crypto_alg == IPSEC_CRYPTO_ALG_NONE &&
143 sa->integ_alg == IPSEC_INTEG_ALG_NONE)
145 im->esp4_no_crypto_tun_node_index :
146 im->esp6_no_crypto_tun_node_index);
147 else if (itp->itp_flags & IPSEC_PROTECT_L2)
149 im->esp4_encrypt_l2_tun_node_index :
150 im->esp6_encrypt_l2_tun_node_index);
153 im->esp4_encrypt_tun_node_index :
154 im->esp6_encrypt_tun_node_index);
160 ipsec_tun_protect_add_adj (adj_index_t ai, const ipsec_tun_protect_t * itp)
162 vec_validate_init_empty (ipsec_tun_protect_sa_by_adj_index, ai,
167 ipsec_tun_protect_sa_by_adj_index[ai] = INDEX_INVALID;
168 adj_nbr_midchain_reset_next_node (ai);
172 ipsec_tun_protect_sa_by_adj_index[ai] = itp->itp_out_sa;
173 adj_nbr_midchain_update_next_node
174 (ai, ipsec_tun_protect_get_adj_next (itp));
179 ipsec_tun_protect_find (u32 sw_if_index, const ip_address_t * nh)
181 ipsec_tun_protect_itf_db_t *idi;
184 if (vec_len (itp_db.id_itf) <= sw_if_index)
185 return INDEX_INVALID;
187 if (vnet_sw_interface_is_p2p (vnet_get_main (), sw_if_index))
188 return (itp_db.id_itf[sw_if_index].id_itp);
190 idi = &itp_db.id_itf[sw_if_index];
191 p = hash_get_mem (idi->id_hash, nh);
195 return INDEX_INVALID;
201 ipsec_tun_protect_rx_db_add (ipsec_main_t * im,
202 const ipsec_tun_protect_t * itp)
204 const ipsec_sa_t *sa;
207 if (ip46_address_is_zero (&itp->itp_crypto.dst))
211 FOR_EACH_IPSEC_PROTECT_INPUT_SAI(itp, sai,
213 sa = ipsec_sa_get (sai);
215 ipsec_tun_lkup_result_t res = {
216 .tun_index = itp - ipsec_tun_protect_pool,
221 * The key is formed from the tunnel's destination
222 * as the packet lookup is done from the packet's source
224 if (ip46_address_is_ip4 (&itp->itp_crypto.dst))
226 ipsec4_tunnel_key_t key = {
227 .remote_ip = itp->itp_crypto.dst.ip4,
228 .spi = clib_host_to_net_u32 (sa->spi),
230 hash_set (im->tun4_protect_by_key, key.as_u64, res.as_u64);
231 ipsec_tun_register_nodes(AF_IP4);
235 ipsec6_tunnel_key_t key = {
236 .remote_ip = itp->itp_crypto.dst.ip6,
237 .spi = clib_host_to_net_u32 (sa->spi),
239 hash_set_mem_alloc (&im->tun6_protect_by_key, &key, res.as_u64);
240 ipsec_tun_register_nodes(AF_IP6);
247 ipsec_tun_protect_adj_add (adj_index_t ai, void *arg)
249 ipsec_tun_protect_t *itp = arg;
250 adj_delegate_add (adj_get (ai), ipsec_tun_adj_delegate_type,
251 itp - ipsec_tun_protect_pool);
252 ipsec_tun_protect_add_adj (ai, itp);
254 return (ADJ_WALK_RC_CONTINUE);
258 ipsec_tun_protect_tx_db_add (ipsec_tun_protect_t * itp)
261 * add the delegate to the adj
263 ipsec_tun_protect_itf_db_t *idi;
264 fib_protocol_t nh_proto;
267 vec_validate_init_empty (itp_db.id_itf,
268 itp->itp_sw_if_index,
269 IPSEC_TUN_PROTECT_DEFAULT_DB_ENTRY);
271 idi = &itp_db.id_itf[itp->itp_sw_if_index];
273 if (vnet_sw_interface_is_p2p (vnet_get_main (), itp->itp_sw_if_index))
275 if (INDEX_INVALID == idi->id_itp)
277 // ipsec_tun_protect_feature_set (itp, 1);
279 idi->id_itp = itp - ipsec_tun_protect_pool;
281 FOR_EACH_FIB_IP_PROTOCOL (nh_proto)
282 adj_nbr_walk (itp->itp_sw_if_index,
283 nh_proto, ipsec_tun_protect_adj_add, itp);
287 if (NULL == idi->id_hash)
290 hash_create_mem (0, sizeof (ip_address_t), sizeof (uword));
292 * enable the encrypt feature for egress if this is the first addition
295 // ipsec_tun_protect_feature_set (itp, 1);
298 hash_set_mem (idi->id_hash, itp->itp_key, itp - ipsec_tun_protect_pool);
301 * walk all the adjs with the same nh on this interface
302 * to associate them with this protection
304 nh_proto = ip_address_to_46 (itp->itp_key, &nh);
306 adj_nbr_walk_nh (itp->itp_sw_if_index,
307 nh_proto, &nh, ipsec_tun_protect_adj_add, itp);
309 ipsec_tun_register_nodes (FIB_PROTOCOL_IP6 == nh_proto ?
315 ipsec_tun_protect_rx_db_remove (ipsec_main_t * im,
316 const ipsec_tun_protect_t * itp)
318 const ipsec_sa_t *sa;
321 FOR_EACH_IPSEC_PROTECT_INPUT_SA(itp, sa,
323 if (ip46_address_is_ip4 (&itp->itp_crypto.dst))
325 ipsec4_tunnel_key_t key = {
326 .remote_ip = itp->itp_crypto.dst.ip4,
327 .spi = clib_host_to_net_u32 (sa->spi),
329 if (hash_get(im->tun4_protect_by_key, key.as_u64))
331 hash_unset (im->tun4_protect_by_key, key.as_u64);
332 ipsec_tun_unregister_nodes(AF_IP4);
337 ipsec6_tunnel_key_t key = {
338 .remote_ip = itp->itp_crypto.dst.ip6,
339 .spi = clib_host_to_net_u32 (sa->spi),
341 if (hash_get_mem(im->tun6_protect_by_key, &key))
343 hash_unset_mem_free (&im->tun6_protect_by_key, &key);
344 ipsec_tun_unregister_nodes(AF_IP6);
352 ipsec_tun_protect_adj_remove (adj_index_t ai, void *arg)
354 adj_delegate_remove (ai, ipsec_tun_adj_delegate_type);
355 ipsec_tun_protect_add_adj (ai, NULL);
357 return (ADJ_WALK_RC_CONTINUE);
361 ipsec_tun_protect_tx_db_remove (ipsec_tun_protect_t * itp)
363 ipsec_tun_protect_itf_db_t *idi;
364 fib_protocol_t nh_proto;
367 nh_proto = ip_address_to_46 (itp->itp_key, &nh);
368 idi = &itp_db.id_itf[itp->itp_sw_if_index];
370 if (vnet_sw_interface_is_p2p (vnet_get_main (), itp->itp_sw_if_index))
372 // ipsec_tun_protect_feature_set (itp, 0);
373 idi->id_itp = INDEX_INVALID;
375 FOR_EACH_FIB_IP_PROTOCOL (nh_proto)
376 adj_nbr_walk (itp->itp_sw_if_index,
377 nh_proto, ipsec_tun_protect_adj_remove, itp);
381 adj_nbr_walk_nh (itp->itp_sw_if_index,
382 nh_proto, &nh, ipsec_tun_protect_adj_remove, itp);
384 hash_unset_mem (idi->id_hash, itp->itp_key);
386 if (0 == hash_elts (idi->id_hash))
388 // ipsec_tun_protect_feature_set (itp, 0);
389 hash_free (idi->id_hash);
392 ipsec_tun_unregister_nodes (FIB_PROTOCOL_IP6 == nh_proto ?
398 ipsec_tun_protect_set_crypto_addr (ipsec_tun_protect_t * itp)
403 FOR_EACH_IPSEC_PROTECT_INPUT_SA(itp, sa,
405 if (ipsec_sa_is_set_IS_TUNNEL (sa))
407 itp->itp_crypto.src = sa->tunnel_dst_addr;
408 itp->itp_crypto.dst = sa->tunnel_src_addr;
409 ipsec_sa_set_IS_PROTECT (sa);
410 itp->itp_flags |= IPSEC_PROTECT_ENCAPED;
414 itp->itp_crypto.src = itp->itp_tun.src;
415 itp->itp_crypto.dst = itp->itp_tun.dst;
416 itp->itp_flags &= ~IPSEC_PROTECT_ENCAPED;
423 ipsec_tun_protect_config (ipsec_main_t * im,
424 ipsec_tun_protect_t * itp, u32 sa_out, u32 * sas_in)
429 itp->itp_n_sa_in = vec_len (sas_in);
430 for (ii = 0; ii < itp->itp_n_sa_in; ii++)
431 itp->itp_in_sas[ii] = sas_in[ii];
432 itp->itp_out_sa = sa_out;
434 ipsec_sa_lock (itp->itp_out_sa);
437 FOR_EACH_IPSEC_PROTECT_INPUT_SAI(itp, sai,
441 ipsec_tun_protect_set_crypto_addr(itp);
445 * add to the DB against each SA
447 ipsec_tun_protect_rx_db_add (im, itp);
448 ipsec_tun_protect_tx_db_add (itp);
450 ITP_DBG (itp, "configured");
454 ipsec_tun_protect_unconfig (ipsec_main_t * im, ipsec_tun_protect_t * itp)
460 FOR_EACH_IPSEC_PROTECT_INPUT_SA(itp, sa,
462 ipsec_sa_unset_IS_PROTECT (sa);
465 ipsec_tun_protect_rx_db_remove (im, itp);
466 ipsec_tun_protect_tx_db_remove (itp);
468 ipsec_sa_unlock(itp->itp_out_sa);
470 FOR_EACH_IPSEC_PROTECT_INPUT_SAI(itp, sai,
472 ipsec_sa_unlock(sai);
475 ITP_DBG (itp, "unconfigured");
479 ipsec_tun_protect_update_one (u32 sw_if_index,
480 const ip_address_t * nh, u32 sa_out, u32 sa_in)
485 vec_add1 (sas_in, sa_in);
486 rv = ipsec_tun_protect_update (sw_if_index, nh, sa_out, sas_in);
492 ipsec_tun_protect_update_out (u32 sw_if_index,
493 const ip_address_t * nh, u32 sa_out)
495 u32 itpi, *sas_in, sai, *saip;
496 ipsec_tun_protect_t *itp;
504 itpi = ipsec_tun_protect_find (sw_if_index, nh);
506 if (INDEX_INVALID == itpi)
508 return (VNET_API_ERROR_INVALID_INTERFACE);
511 itp = pool_elt_at_index (ipsec_tun_protect_pool, itpi);
514 FOR_EACH_IPSEC_PROTECT_INPUT_SAI (itp, sai,
517 vec_add1 (sas_in, sai);
521 sa_out = ipsec_sa_find_and_lock (sa_out);
525 rv = VNET_API_ERROR_INVALID_VALUE;
529 ipsec_tun_protect_unconfig (im, itp);
530 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
532 ipsec_sa_unlock (sa_out);
533 vec_foreach (saip, sas_in) ipsec_sa_unlock (*saip);
541 ipsec_tun_protect_update_in (u32 sw_if_index,
542 const ip_address_t * nh, u32 sa_in)
544 u32 itpi, *sas_in, sa_out;
545 ipsec_tun_protect_t *itp;
552 itpi = ipsec_tun_protect_find (sw_if_index, nh);
554 if (INDEX_INVALID == itpi)
556 return (VNET_API_ERROR_INVALID_INTERFACE);
559 sa_in = ipsec_sa_find_and_lock (sa_in);
563 rv = VNET_API_ERROR_INVALID_VALUE;
566 vec_add1 (sas_in, sa_in);
568 itp = pool_elt_at_index (ipsec_tun_protect_pool, itpi);
569 sa_out = itp->itp_out_sa;
571 ipsec_sa_lock (sa_out);
573 ipsec_tun_protect_unconfig (im, itp);
574 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
576 ipsec_sa_unlock (sa_out);
577 ipsec_sa_unlock (sa_in);
584 ipsec_tun_protect_update_from_teib (ipsec_tun_protect_t * itp,
585 const teib_entry_t * ne)
589 const fib_prefix_t *pfx;
591 pfx = teib_entry_get_nh (ne);
593 ip46_address_copy (&itp->itp_tun.dst, &pfx->fp_addr);
596 ip46_address_reset (&itp->itp_tun.dst);
600 ipsec_tun_protect_update (u32 sw_if_index,
601 const ip_address_t * nh, u32 sa_out, u32 * sas_in)
603 ipsec_tun_protect_t *itp;
608 ITP_DBG2 ("update: %U/%U",
609 format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index,
610 format_ip_address, nh);
612 if (vec_len (sas_in) > ITP_MAX_N_SA_IN)
614 rv = VNET_API_ERROR_LIMIT_EXCEEDED;
622 itpi = ipsec_tun_protect_find (sw_if_index, nh);
624 vec_foreach_index (ii, sas_in)
626 sas_in[ii] = ipsec_sa_find_and_lock (sas_in[ii]);
627 if (~0 == sas_in[ii])
629 rv = VNET_API_ERROR_INVALID_VALUE;
634 sa_out = ipsec_sa_find_and_lock (sa_out);
638 rv = VNET_API_ERROR_INVALID_VALUE;
642 if (INDEX_INVALID == itpi)
644 vnet_device_class_t *dev_class;
645 vnet_hw_interface_t *hi;
649 vnm = vnet_get_main ();
650 hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
651 dev_class = vnet_get_device_class (vnm, hi->dev_class_index);
653 if (NULL == dev_class->ip_tun_desc)
655 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
659 pool_get_zero (ipsec_tun_protect_pool, itp);
661 itp->itp_sw_if_index = sw_if_index;
663 itp->itp_n_sa_in = vec_len (sas_in);
664 for (ii = 0; ii < itp->itp_n_sa_in; ii++)
665 itp->itp_in_sas[ii] = sas_in[ii];
666 itp->itp_out_sa = sa_out;
668 itp->itp_key = clib_mem_alloc (sizeof (*itp->itp_key));
669 ip_address_copy (itp->itp_key, nh);
671 rv = dev_class->ip_tun_desc (sw_if_index,
673 &itp->itp_tun.dst, &is_l2);
678 if (ip46_address_is_zero (&itp->itp_tun.dst))
680 /* tunnel has no destination address, presumably because it's p2mp
681 in which case we use the nh that this is protection for */
684 ip_address_to_46 (nh, &peer);
686 ipsec_tun_protect_update_from_teib
687 (itp, teib_entry_find (sw_if_index, &peer));
691 itp->itp_flags |= IPSEC_PROTECT_L2;
694 * add to the tunnel DB for ingress
695 * - if the SA is in trasnport mode, then the packates will arrivw
696 * with the IP src,dst of the protected tunnel, in which case we can
697 * simply strip the IP header and hand the payload to the protocol
698 * appropriate input handler
699 * - if the SA is in tunnel mode then there are two IP headers present
700 * one for the crytpo tunnel endpoints (described in the SA) and one
701 * for the tunnel endpoints. The outer IP headers in the srriving
702 * packets will have the crypto endpoints. So the DB needs to contain
703 * the crpto endpoint. Once the crypto header is stripped, revealing,
704 * the tunnel-IP we have 2 choices:
705 * 1) do a tunnel lookup based on the revealed header
706 * 2) skip the tunnel lookup and assume that the packet matches the
707 * one that is protected here.
708 * If we did 1) then we would allow our peer to use the SA for tunnel
709 * X to inject traffic onto tunnel Y, this is not good. If we do 2)
710 * then we don't verify that the peer is indeed using SA for tunnel
711 * X and addressing tunnel X. So we take a compromise, once the SA
712 * matches to tunnel X we veriy that the inner IP matches the value
713 * of the tunnel we are protecting, else it's dropped.
715 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
719 /* updating SAs only */
720 itp = pool_elt_at_index (ipsec_tun_protect_pool, itpi);
722 ipsec_tun_protect_unconfig (im, itp);
723 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
726 ipsec_sa_unlock (sa_out);
727 vec_foreach (saip, sas_in) ipsec_sa_unlock (*saip);
735 ipsec_tun_protect_del (u32 sw_if_index, const ip_address_t * nh)
737 ipsec_tun_protect_t *itp;
741 ITP_DBG2 ("delete: %U/%U",
742 format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index,
743 format_ip_address, nh);
749 itpi = ipsec_tun_protect_find (sw_if_index, nh);
751 if (INDEX_INVALID == itpi)
752 return (VNET_API_ERROR_NO_SUCH_ENTRY);
754 itp = ipsec_tun_protect_get (itpi);
755 ipsec_tun_protect_unconfig (im, itp);
757 clib_mem_free (itp->itp_key);
758 pool_put (ipsec_tun_protect_pool, itp);
764 ipsec_tun_protect_walk (ipsec_tun_protect_walk_cb_t fn, void *ctx)
769 pool_foreach_index(itpi, ipsec_tun_protect_pool,
777 ipsec_tun_protect_walk_itf (u32 sw_if_index,
778 ipsec_tun_protect_walk_cb_t fn, void *ctx)
780 ipsec_tun_protect_itf_db_t *idi;
784 if (vec_len (itp_db.id_itf) <= sw_if_index)
787 idi = &itp_db.id_itf[sw_if_index];
790 hash_foreach(key, itpi, idi->id_hash,
795 if (INDEX_INVALID != idi->id_itp)
796 fn (idi->id_itp, ctx);
800 ipsec_tun_protect_adj_delegate_adj_deleted (adj_delegate_t * ad)
802 /* remove our delegate */
803 ipsec_tun_protect_add_adj (ad->ad_adj_index, NULL);
804 adj_delegate_remove (ad->ad_adj_index, ipsec_tun_adj_delegate_type);
808 ipsec_tun_protect_adj_delegate_adj_modified (adj_delegate_t * ad)
810 ipsec_tun_protect_add_adj (ad->ad_adj_index,
811 ipsec_tun_protect_get (ad->ad_index));
815 ipsec_tun_protect_adj_delegate_adj_created (adj_index_t ai)
817 /* add our delegate if there is protection for this neighbour */
818 ip_address_t ip = IP_ADDRESS_V4_ALL_0S;
822 if (!adj_is_midchain (ai))
827 ip_address_from_46 (&adj->sub_type.midchain.next_hop,
828 adj->ia_nh_proto, &ip);
830 itpi = ipsec_tun_protect_find (adj->rewrite_header.sw_if_index, &ip);
832 if (INDEX_INVALID != itpi)
834 const ipsec_tun_protect_t *itp;
836 itp = ipsec_tun_protect_get (itpi);
837 adj_delegate_add (adj_get (ai), ipsec_tun_adj_delegate_type, itpi);
838 ipsec_tun_protect_add_adj (ai, itp);
843 ipsec_tun_protect_adj_delegate_format (const adj_delegate_t * aed, u8 * s)
845 const ipsec_tun_protect_t *itp;
847 itp = ipsec_tun_protect_from_const_base (aed);
848 s = format (s, "ipsec-tun-protect:\n%U", format_ipsec_tun_protect, itp);
854 ipsec_tun_teib_entry_added (const teib_entry_t * ne)
856 const ip46_address_t *peer46;
857 ipsec_tun_protect_t *itp;
861 peer46 = teib_entry_get_peer (ne);
862 ip_address_from_46 (peer46,
863 (ip46_address_is_ip4 (peer46) ?
864 FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6), &peer);
866 itpi = ipsec_tun_protect_find (teib_entry_get_sw_if_index (ne), &peer);
868 if (INDEX_INVALID == itpi)
871 itp = ipsec_tun_protect_get (itpi);
872 ipsec_tun_protect_rx_db_remove (&ipsec_main, itp);
873 ipsec_tun_protect_update_from_teib (itp, ne);
874 ipsec_tun_protect_set_crypto_addr (itp);
875 ipsec_tun_protect_rx_db_add (&ipsec_main, itp);
877 ITP_DBG (itp, "teib-added");
881 ipsec_tun_teib_entry_deleted (const teib_entry_t * ne)
883 const ip46_address_t *peer46;
884 ipsec_tun_protect_t *itp;
888 peer46 = teib_entry_get_peer (ne);
889 ip_address_from_46 (peer46,
890 (ip46_address_is_ip4 (peer46) ?
891 FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6), &peer);
893 itpi = ipsec_tun_protect_find (teib_entry_get_sw_if_index (ne), &peer);
895 if (INDEX_INVALID == itpi)
898 itp = ipsec_tun_protect_get (itpi);
899 ipsec_tun_protect_rx_db_remove (&ipsec_main, itp);
900 ipsec_tun_protect_update_from_teib (itp, NULL);
901 ipsec_tun_protect_set_crypto_addr (itp);
903 ITP_DBG (itp, "teib-removed");
907 * VFT registered with the adjacency delegate
909 const static adj_delegate_vft_t ipsec_tun_adj_delegate_vft = {
910 .adv_adj_deleted = ipsec_tun_protect_adj_delegate_adj_deleted,
911 .adv_adj_created = ipsec_tun_protect_adj_delegate_adj_created,
912 .adv_adj_modified = ipsec_tun_protect_adj_delegate_adj_modified,
913 .adv_format = ipsec_tun_protect_adj_delegate_format,
916 const static teib_vft_t ipsec_tun_teib_vft = {
917 .nv_added = ipsec_tun_teib_entry_added,
918 .nv_deleted = ipsec_tun_teib_entry_deleted,
923 ipsec_tunnel_protect_init (vlib_main_t * vm)
928 im->tun6_protect_by_key = hash_create_mem (0,
929 sizeof (ipsec6_tunnel_key_t),
931 im->tun4_protect_by_key = hash_create (0, sizeof (u64));
933 /* set up feature nodes to drop outbound packets with no crypto alg set */
934 im->esp4_no_crypto_tun_node_index =
935 vlib_get_node_by_name (vm, (u8 *) "esp4-no-crypto")->index;
936 im->esp6_no_crypto_tun_node_index =
937 vlib_get_node_by_name (vm, (u8 *) "esp6-no-crypto")->index;
938 im->esp6_encrypt_l2_tun_node_index =
939 vlib_get_node_by_name (vm, (u8 *) "esp6-encrypt-tun")->index;
940 im->esp4_encrypt_l2_tun_node_index =
941 vlib_get_node_by_name (vm, (u8 *) "esp4-encrypt-tun")->index;
943 ipsec_tun_adj_delegate_type =
944 adj_delegate_register_new_type (&ipsec_tun_adj_delegate_vft);
946 ipsec_tun_protect_logger = vlib_log_register_class ("ipsec", "tun");
948 teib_register (&ipsec_tun_teib_vft);
953 VLIB_INIT_FUNCTION (ipsec_tunnel_protect_init);
957 * fd.io coding-style-patch-verification: ON
960 * eval: (c-set-style "gnu")