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/teib/teib.h>
27 vlib_log_class_t ipsec_tun_protect_logger;
30 * Pool of tunnel protection objects
32 ipsec_tun_protect_t *ipsec_tun_protect_pool;
35 * Adj delegate registered type
37 static adj_delegate_type_t ipsec_tun_adj_delegate_type;
40 * Adj index to TX SA mapping
42 index_t *ipsec_tun_protect_sa_by_adj_index;
44 const ip_address_t IP_ADDR_ALL_0 = IP_ADDRESS_V4_ALL_0S;
47 * The DB of all added per-nh tunnel protectiond
49 typedef struct ipsec_tun_protect_itf_db_t_
51 /** A hash table key'd on IP (4 or 6) address */
53 /** If the interface is P2P then there is only one protect
54 * object associated with the auto-adj for each NH proto */
56 } ipsec_tun_protect_itf_db_t;
58 typedef struct ipsec_tun_protect_db_t_
60 /** Per-interface vector */
61 ipsec_tun_protect_itf_db_t *id_itf;
62 } ipsec_tun_protect_db_t;
64 static ipsec_tun_protect_db_t itp_db;
66 const static ipsec_tun_protect_itf_db_t IPSEC_TUN_PROTECT_DEFAULT_DB_ENTRY = {
67 .id_itp = INDEX_INVALID,
70 #define ITP_DBG(_itp, _fmt, _args...) \
72 vlib_log_debug(ipsec_tun_protect_logger, \
74 format_ipsec_tun_protect, \
78 #define ITP_DBG2(_fmt, _args...) \
80 vlib_log_debug(ipsec_tun_protect_logger, \
85 ipsec_tun_protect_add_adj (adj_index_t ai, index_t sai)
87 vec_validate_init_empty (ipsec_tun_protect_sa_by_adj_index, ai,
90 ipsec_tun_protect_sa_by_adj_index[ai] = sai;
93 static inline const ipsec_tun_protect_t *
94 ipsec_tun_protect_from_const_base (const adj_delegate_t * ad)
98 return (pool_elt_at_index (ipsec_tun_protect_pool, ad->ad_index));
102 ipsec_tun_protect_feature_set (ipsec_tun_protect_t * itp, u8 enable)
104 ITP_DBG2 ("%s on %U", (enable ? "enable" : "disable"),
105 format_vnet_sw_if_index_name, vnet_get_main (),
106 itp->itp_sw_if_index);
108 if (itp->itp_flags & IPSEC_PROTECT_L2)
110 /* l2-GRE only supported by the vnet ipsec code */
111 vnet_feature_enable_disable ("ethernet-output",
112 (ip46_address_is_ip4 (&itp->itp_tun.src) ?
115 itp->itp_sw_if_index, enable, NULL, 0);
124 sai = itp->itp_out_sa;
125 sa = ipsec_sa_get (sai);
127 if (sa->crypto_alg == IPSEC_CRYPTO_ALG_NONE &&
128 sa->integ_alg == IPSEC_INTEG_ALG_NONE)
130 fi4 = im->esp4_no_crypto_tun_feature_index;
131 fi6 = im->esp6_no_crypto_tun_feature_index;
135 if (ip46_address_is_ip4 (&itp->itp_tun.src))
137 /* tunnel destination is v4 so we need the Xo4 indexes */
138 fi4 = im->esp44_encrypt_tun_feature_index;
139 fi6 = im->esp64_encrypt_tun_feature_index;
143 /* tunnel destination is v6 so we need the Xo6 indexes */
144 fi4 = im->esp46_encrypt_tun_feature_index;
145 fi6 = im->esp66_encrypt_tun_feature_index;
149 vnet_feature_enable_disable_with_index
150 (vnet_get_feature_arc_index ("ip4-output"),
151 fi4, itp->itp_sw_if_index, enable, NULL, 0);
152 vnet_feature_enable_disable_with_index
153 (vnet_get_feature_arc_index ("ip6-output"),
154 fi6, itp->itp_sw_if_index, enable, NULL, 0);
159 ipsec_tun_protect_find (u32 sw_if_index, const ip_address_t * nh)
161 ipsec_tun_protect_itf_db_t *idi;
164 if (vec_len (itp_db.id_itf) <= sw_if_index)
165 return INDEX_INVALID;
167 if (vnet_sw_interface_is_p2p (vnet_get_main (), sw_if_index))
168 return (itp_db.id_itf[sw_if_index].id_itp);
170 idi = &itp_db.id_itf[sw_if_index];
171 p = hash_get_mem (idi->id_hash, nh);
175 return INDEX_INVALID;
181 ipsec_tun_protect_rx_db_add (ipsec_main_t * im,
182 const ipsec_tun_protect_t * itp)
184 const ipsec_sa_t *sa;
187 if (ip46_address_is_zero (&itp->itp_crypto.dst))
191 FOR_EACH_IPSEC_PROTECT_INPUT_SAI(itp, sai,
193 sa = ipsec_sa_get (sai);
195 ipsec_tun_lkup_result_t res = {
196 .tun_index = itp - ipsec_tun_protect_pool,
201 * The key is formed from the tunnel's destination
202 * as the packet lookup is done from the packet's source
204 if (ip46_address_is_ip4 (&itp->itp_crypto.dst))
206 ipsec4_tunnel_key_t key = {
207 .remote_ip = itp->itp_crypto.dst.ip4,
208 .spi = clib_host_to_net_u32 (sa->spi),
210 hash_set (im->tun4_protect_by_key, key.as_u64, res.as_u64);
211 if (1 == hash_elts(im->tun4_protect_by_key))
213 udp_register_dst_port (vlib_get_main(),
215 ipsec4_tun_input_node.index, 1);
216 ip4_register_protocol (IP_PROTOCOL_IPSEC_ESP,
217 ipsec4_tun_input_node.index);
222 ipsec6_tunnel_key_t key = {
223 .remote_ip = itp->itp_crypto.dst.ip6,
224 .spi = clib_host_to_net_u32 (sa->spi),
226 hash_set_mem_alloc (&im->tun6_protect_by_key, &key, res.as_u64);
228 if (1 == hash_elts (im->tun6_protect_by_key))
229 ip6_register_protocol (IP_PROTOCOL_IPSEC_ESP,
230 ipsec6_tun_input_node.index);
237 ipsec_tun_protect_adj_add (adj_index_t ai, void *arg)
239 ipsec_tun_protect_t *itp = arg;
240 adj_delegate_add (adj_get (ai), ipsec_tun_adj_delegate_type,
241 itp - ipsec_tun_protect_pool);
242 ipsec_tun_protect_add_adj (ai, itp->itp_out_sa);
244 return (ADJ_WALK_RC_CONTINUE);
248 ipsec_tun_protect_tx_db_add (ipsec_tun_protect_t * itp)
251 * add the delegate to the adj
253 ipsec_tun_protect_itf_db_t *idi;
254 fib_protocol_t nh_proto;
257 vec_validate_init_empty (itp_db.id_itf,
258 itp->itp_sw_if_index,
259 IPSEC_TUN_PROTECT_DEFAULT_DB_ENTRY);
261 idi = &itp_db.id_itf[itp->itp_sw_if_index];
263 if (vnet_sw_interface_is_p2p (vnet_get_main (), itp->itp_sw_if_index))
265 if (INDEX_INVALID == idi->id_itp)
267 ipsec_tun_protect_feature_set (itp, 1);
269 idi->id_itp = itp - ipsec_tun_protect_pool;
271 FOR_EACH_FIB_IP_PROTOCOL (nh_proto)
272 adj_nbr_walk (itp->itp_sw_if_index,
273 nh_proto, ipsec_tun_protect_adj_add, itp);
277 if (NULL == idi->id_hash)
280 hash_create_mem (0, sizeof (ip_address_t), sizeof (uword));
282 * enable the encrypt feature for egress if this is the first addition
285 ipsec_tun_protect_feature_set (itp, 1);
288 hash_set_mem (idi->id_hash, itp->itp_key, itp - ipsec_tun_protect_pool);
291 * walk all the adjs with the same nh on this interface
292 * to associate them with this protection
294 nh_proto = ip_address_to_46 (itp->itp_key, &nh);
296 adj_nbr_walk_nh (itp->itp_sw_if_index,
297 nh_proto, &nh, ipsec_tun_protect_adj_add, itp);
302 ipsec_tun_protect_rx_db_remove (ipsec_main_t * im,
303 const ipsec_tun_protect_t * itp)
305 const ipsec_sa_t *sa;
308 FOR_EACH_IPSEC_PROTECT_INPUT_SA(itp, sa,
310 if (ip46_address_is_ip4 (&itp->itp_crypto.dst))
312 ipsec4_tunnel_key_t key = {
313 .remote_ip = itp->itp_crypto.dst.ip4,
314 .spi = clib_host_to_net_u32 (sa->spi),
316 hash_unset (im->tun4_protect_by_key, key.as_u64);
317 if (0 == hash_elts(im->tun4_protect_by_key))
318 udp_unregister_dst_port (vlib_get_main(),
324 ipsec6_tunnel_key_t key = {
325 .remote_ip = itp->itp_crypto.dst.ip6,
326 .spi = clib_host_to_net_u32 (sa->spi),
328 hash_unset_mem_free (&im->tun6_protect_by_key, &key);
335 ipsec_tun_protect_adj_remove (adj_index_t ai, void *arg)
337 adj_delegate_remove (ai, ipsec_tun_adj_delegate_type);
338 ipsec_tun_protect_add_adj (ai, INDEX_INVALID);
340 return (ADJ_WALK_RC_CONTINUE);
344 ipsec_tun_protect_tx_db_remove (ipsec_tun_protect_t * itp)
346 ipsec_tun_protect_itf_db_t *idi;
347 fib_protocol_t nh_proto;
350 nh_proto = ip_address_to_46 (itp->itp_key, &nh);
351 idi = &itp_db.id_itf[itp->itp_sw_if_index];
353 if (vnet_sw_interface_is_p2p (vnet_get_main (), itp->itp_sw_if_index))
355 ipsec_tun_protect_feature_set (itp, 0);
356 idi->id_itp = INDEX_INVALID;
358 FOR_EACH_FIB_IP_PROTOCOL (nh_proto)
359 adj_nbr_walk (itp->itp_sw_if_index,
360 nh_proto, ipsec_tun_protect_adj_remove, itp);
364 adj_nbr_walk_nh (itp->itp_sw_if_index,
365 nh_proto, &nh, ipsec_tun_protect_adj_remove, itp);
367 hash_unset_mem (idi->id_hash, itp->itp_key);
369 if (0 == hash_elts (idi->id_hash))
371 ipsec_tun_protect_feature_set (itp, 0);
372 hash_free (idi->id_hash);
379 ipsec_tun_protect_set_crypto_addr (ipsec_tun_protect_t * itp)
384 FOR_EACH_IPSEC_PROTECT_INPUT_SA(itp, sa,
386 if (ipsec_sa_is_set_IS_TUNNEL (sa))
388 itp->itp_crypto.src = sa->tunnel_dst_addr;
389 itp->itp_crypto.dst = sa->tunnel_src_addr;
390 ipsec_sa_set_IS_PROTECT (sa);
391 itp->itp_flags |= IPSEC_PROTECT_ENCAPED;
395 itp->itp_crypto.src = itp->itp_tun.src;
396 itp->itp_crypto.dst = itp->itp_tun.dst;
397 itp->itp_flags &= ~IPSEC_PROTECT_ENCAPED;
404 ipsec_tun_protect_config (ipsec_main_t * im,
405 ipsec_tun_protect_t * itp, u32 sa_out, u32 * sas_in)
410 itp->itp_n_sa_in = vec_len (sas_in);
411 for (ii = 0; ii < itp->itp_n_sa_in; ii++)
412 itp->itp_in_sas[ii] = sas_in[ii];
413 itp->itp_out_sa = sa_out;
415 ipsec_sa_lock (itp->itp_out_sa);
418 FOR_EACH_IPSEC_PROTECT_INPUT_SAI(itp, sai,
422 ipsec_tun_protect_set_crypto_addr(itp);
426 * add to the DB against each SA
428 ipsec_tun_protect_rx_db_add (im, itp);
429 ipsec_tun_protect_tx_db_add (itp);
431 ITP_DBG (itp, "configured");
435 ipsec_tun_protect_unconfig (ipsec_main_t * im, ipsec_tun_protect_t * itp)
441 FOR_EACH_IPSEC_PROTECT_INPUT_SA(itp, sa,
443 ipsec_sa_unset_IS_PROTECT (sa);
446 ipsec_tun_protect_rx_db_remove (im, itp);
447 ipsec_tun_protect_tx_db_remove (itp);
449 ipsec_sa_unlock(itp->itp_out_sa);
451 FOR_EACH_IPSEC_PROTECT_INPUT_SAI(itp, sai,
453 ipsec_sa_unlock(sai);
456 ITP_DBG (itp, "unconfigured");
460 ipsec_tun_protect_update_one (u32 sw_if_index,
461 const ip_address_t * nh, u32 sa_out, u32 sa_in)
466 vec_add1 (sas_in, sa_in);
467 rv = ipsec_tun_protect_update (sw_if_index, nh, sa_out, sas_in);
473 ipsec_tun_protect_update_out (u32 sw_if_index,
474 const ip_address_t * nh, u32 sa_out)
476 u32 itpi, *sas_in, sai, *saip;
477 ipsec_tun_protect_t *itp;
485 itpi = ipsec_tun_protect_find (sw_if_index, nh);
487 if (INDEX_INVALID == itpi)
489 return (VNET_API_ERROR_INVALID_INTERFACE);
492 itp = pool_elt_at_index (ipsec_tun_protect_pool, itpi);
495 FOR_EACH_IPSEC_PROTECT_INPUT_SAI (itp, sai,
498 vec_add1 (sas_in, sai);
502 sa_out = ipsec_sa_find_and_lock (sa_out);
506 rv = VNET_API_ERROR_INVALID_VALUE;
510 ipsec_tun_protect_unconfig (im, itp);
511 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
513 ipsec_sa_unlock (sa_out);
514 vec_foreach (saip, sas_in) ipsec_sa_unlock (*saip);
522 ipsec_tun_protect_update_in (u32 sw_if_index,
523 const ip_address_t * nh, u32 sa_in)
525 u32 itpi, *sas_in, sa_out;
526 ipsec_tun_protect_t *itp;
533 itpi = ipsec_tun_protect_find (sw_if_index, nh);
535 if (INDEX_INVALID == itpi)
537 return (VNET_API_ERROR_INVALID_INTERFACE);
540 sa_in = ipsec_sa_find_and_lock (sa_in);
544 rv = VNET_API_ERROR_INVALID_VALUE;
547 vec_add1 (sas_in, sa_in);
549 itp = pool_elt_at_index (ipsec_tun_protect_pool, itpi);
550 sa_out = itp->itp_out_sa;
552 ipsec_sa_lock (sa_out);
554 ipsec_tun_protect_unconfig (im, itp);
555 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
557 ipsec_sa_unlock (sa_out);
558 ipsec_sa_unlock (sa_in);
565 ipsec_tun_protect_update_from_teib (ipsec_tun_protect_t * itp,
566 const teib_entry_t * ne)
570 const fib_prefix_t *pfx;
572 pfx = teib_entry_get_nh (ne);
574 ip46_address_copy (&itp->itp_tun.dst, &pfx->fp_addr);
577 ip46_address_reset (&itp->itp_tun.dst);
581 ipsec_tun_protect_update (u32 sw_if_index,
582 const ip_address_t * nh, u32 sa_out, u32 * sas_in)
584 ipsec_tun_protect_t *itp;
589 ITP_DBG2 ("update: %U/%U",
590 format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index,
591 format_ip_address, nh);
597 itpi = ipsec_tun_protect_find (sw_if_index, nh);
599 vec_foreach_index (ii, sas_in)
601 sas_in[ii] = ipsec_sa_find_and_lock (sas_in[ii]);
602 if (~0 == sas_in[ii])
604 rv = VNET_API_ERROR_INVALID_VALUE;
609 sa_out = ipsec_sa_find_and_lock (sa_out);
613 rv = VNET_API_ERROR_INVALID_VALUE;
617 if (INDEX_INVALID == itpi)
619 vnet_device_class_t *dev_class;
620 vnet_hw_interface_t *hi;
624 vnm = vnet_get_main ();
625 hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
626 dev_class = vnet_get_device_class (vnm, hi->dev_class_index);
628 if (NULL == dev_class->ip_tun_desc)
630 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
634 pool_get_zero (ipsec_tun_protect_pool, itp);
636 itp->itp_sw_if_index = sw_if_index;
638 itp->itp_n_sa_in = vec_len (sas_in);
639 for (ii = 0; ii < itp->itp_n_sa_in; ii++)
640 itp->itp_in_sas[ii] = sas_in[ii];
641 itp->itp_out_sa = sa_out;
643 itp->itp_key = clib_mem_alloc (sizeof (*itp->itp_key));
644 ip_address_copy (itp->itp_key, nh);
646 rv = dev_class->ip_tun_desc (sw_if_index,
648 &itp->itp_tun.dst, &is_l2);
653 if (ip46_address_is_zero (&itp->itp_tun.dst))
655 /* tunnel has no destination address, presumably because it's p2mp
656 in which case we use the nh that this is protection for */
659 ip_address_to_46 (nh, &peer);
661 ipsec_tun_protect_update_from_teib
662 (itp, teib_entry_find (sw_if_index, &peer));
666 itp->itp_flags |= IPSEC_PROTECT_L2;
669 * add to the tunnel DB for ingress
670 * - if the SA is in trasnport mode, then the packates will arrivw
671 * with the IP src,dst of the protected tunnel, in which case we can
672 * simply strip the IP header and hand the payload to the protocol
673 * appropriate input handler
674 * - if the SA is in tunnel mode then there are two IP headers present
675 * one for the crytpo tunnel endpoints (described in the SA) and one
676 * for the tunnel endpoints. The outer IP headers in the srriving
677 * packets will have the crypto endpoints. So the DB needs to contain
678 * the crpto endpoint. Once the crypto header is stripped, revealing,
679 * the tunnel-IP we have 2 choices:
680 * 1) do a tunnel lookup based on the revealed header
681 * 2) skip the tunnel lookup and assume that the packet matches the
682 * one that is protected here.
683 * If we did 1) then we would allow our peer to use the SA for tunnel
684 * X to inject traffic onto tunnel Y, this is not good. If we do 2)
685 * then we don't verify that the peer is indeed using SA for tunnel
686 * X and addressing tunnel X. So we take a compromise, once the SA
687 * matches to tunnel X we veriy that the inner IP matches the value
688 * of the tunnel we are protecting, else it's dropped.
690 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
694 /* updating SAs only */
695 itp = pool_elt_at_index (ipsec_tun_protect_pool, itpi);
697 ipsec_tun_protect_unconfig (im, itp);
698 ipsec_tun_protect_config (im, itp, sa_out, sas_in);
701 ipsec_sa_unlock (sa_out);
702 vec_foreach (saip, sas_in) ipsec_sa_unlock (*saip);
710 ipsec_tun_protect_del (u32 sw_if_index, const ip_address_t * nh)
712 ipsec_tun_protect_t *itp;
716 ITP_DBG2 ("delete: %U/%U",
717 format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index,
718 format_ip_address, nh);
724 itpi = ipsec_tun_protect_find (sw_if_index, nh);
726 if (INDEX_INVALID == itpi)
727 return (VNET_API_ERROR_NO_SUCH_ENTRY);
729 itp = ipsec_tun_protect_get (itpi);
730 ipsec_tun_protect_unconfig (im, itp);
732 clib_mem_free (itp->itp_key);
733 pool_put (ipsec_tun_protect_pool, itp);
735 if (0 == hash_elts (im->tun4_protect_by_key))
736 ip4_unregister_protocol (IP_PROTOCOL_IPSEC_ESP);
737 if (0 == hash_elts (im->tun6_protect_by_key))
738 ip6_unregister_protocol (IP_PROTOCOL_IPSEC_ESP);
744 ipsec_tun_protect_walk (ipsec_tun_protect_walk_cb_t fn, void *ctx)
749 pool_foreach_index(itpi, ipsec_tun_protect_pool,
757 ipsec_tun_protect_walk_itf (u32 sw_if_index,
758 ipsec_tun_protect_walk_cb_t fn, void *ctx)
760 ipsec_tun_protect_itf_db_t *idi;
764 if (vec_len (itp_db.id_itf) <= sw_if_index)
767 idi = &itp_db.id_itf[sw_if_index];
770 hash_foreach(key, itpi, idi->id_hash,
775 if (INDEX_INVALID != idi->id_itp)
776 fn (idi->id_itp, ctx);
780 ipsec_tun_protect_adj_delegate_adj_deleted (adj_delegate_t * ad)
782 /* remove our delegate */
783 adj_delegate_remove (ad->ad_adj_index, ipsec_tun_adj_delegate_type);
784 ipsec_tun_protect_add_adj (ad->ad_adj_index, INDEX_INVALID);
788 ipsec_tun_protect_adj_delegate_adj_created (adj_index_t ai)
790 /* add our delegate if there is protection for this neighbour */
791 ip_address_t ip = IP_ADDRESS_V4_ALL_0S;
797 if (adj->lookup_next_index != IP_LOOKUP_NEXT_MIDCHAIN)
800 ip_address_from_46 (&adj->sub_type.midchain.next_hop,
801 adj->ia_nh_proto, &ip);
803 itpi = ipsec_tun_protect_find (adj->rewrite_header.sw_if_index, &ip);
805 if (INDEX_INVALID != itpi)
807 const ipsec_tun_protect_t *itp;
809 itp = ipsec_tun_protect_get (itpi);
810 adj_delegate_add (adj_get (ai), ipsec_tun_adj_delegate_type, itpi);
811 ipsec_tun_protect_add_adj (ai, itp->itp_out_sa);
816 ipsec_tun_protect_adj_delegate_format (const adj_delegate_t * aed, u8 * s)
818 const ipsec_tun_protect_t *itp;
820 itp = ipsec_tun_protect_from_const_base (aed);
821 s = format (s, "ipsec-tun-protect:\n%U", format_ipsec_tun_protect, itp);
827 ipsec_tun_teib_entry_added (const teib_entry_t * ne)
829 const ip46_address_t *peer46;
830 ipsec_tun_protect_t *itp;
834 peer46 = teib_entry_get_peer (ne);
835 ip_address_from_46 (peer46,
836 (ip46_address_is_ip4 (peer46) ?
837 FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6), &peer);
839 itpi = ipsec_tun_protect_find (teib_entry_get_sw_if_index (ne), &peer);
841 if (INDEX_INVALID == itpi)
844 itp = ipsec_tun_protect_get (itpi);
845 ipsec_tun_protect_rx_db_remove (&ipsec_main, itp);
846 ipsec_tun_protect_update_from_teib (itp, ne);
847 ipsec_tun_protect_set_crypto_addr (itp);
848 ipsec_tun_protect_rx_db_add (&ipsec_main, itp);
850 ITP_DBG (itp, "teib-added");
854 ipsec_tun_teib_entry_deleted (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, NULL);
874 ipsec_tun_protect_set_crypto_addr (itp);
876 ITP_DBG (itp, "teib-removed");
880 * VFT registered with the adjacency delegate
882 const static adj_delegate_vft_t ipsec_tun_adj_delegate_vft = {
883 .adv_adj_deleted = ipsec_tun_protect_adj_delegate_adj_deleted,
884 .adv_adj_created = ipsec_tun_protect_adj_delegate_adj_created,
885 .adv_format = ipsec_tun_protect_adj_delegate_format,
888 const static teib_vft_t ipsec_tun_teib_vft = {
889 .nv_added = ipsec_tun_teib_entry_added,
890 .nv_deleted = ipsec_tun_teib_entry_deleted,
894 ipsec_tunnel_protect_init (vlib_main_t * vm)
899 im->tun6_protect_by_key = hash_create_mem (0,
900 sizeof (ipsec6_tunnel_key_t),
902 im->tun4_protect_by_key = hash_create (0, sizeof (u64));
904 /* set up feature nodes to drop outbound packets with no crypto alg set */
905 ipsec_add_feature ("ip4-output", "esp4-no-crypto",
906 &im->esp4_no_crypto_tun_feature_index);
907 ipsec_add_feature ("ip6-output", "esp6-no-crypto",
908 &im->esp6_no_crypto_tun_feature_index);
910 ipsec_tun_adj_delegate_type =
911 adj_delegate_register_new_type (&ipsec_tun_adj_delegate_vft);
913 ipsec_tun_protect_logger = vlib_log_register_class ("ipsec", "tun");
915 teib_register (&ipsec_tun_teib_vft);
920 VLIB_INIT_FUNCTION (ipsec_tunnel_protect_init);
924 * fd.io coding-style-patch-verification: ON
927 * eval: (c-set-style "gnu")