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.h>
21 typedef CLIB_PACKED(struct {
23 * Key fields: remote ip and spi on incoming packet
24 * all fields in NET byte order
28 ip4_address_t remote_ip;
33 }) ipsec4_tunnel_key_t;
37 typedef CLIB_PACKED(struct {
39 * Key fields: remote ip and spi on incoming packet
40 * all fields in NET byte order
42 ip6_address_t remote_ip;
44 }) ipsec6_tunnel_key_t;
47 extern u8 *format_ipsec4_tunnel_key (u8 * s, va_list * args);
48 extern u8 *format_ipsec6_tunnel_key (u8 * s, va_list * args);
50 typedef enum ipsec_protect_flags_t_
52 IPSEC_PROTECT_L2 = (1 << 0),
53 IPSEC_PROTECT_ENCAPED = (1 << 1),
54 } __clib_packed ipsec_protect_flags_t;
56 typedef struct ipsec_ep_t_
62 #define ITP_MAX_N_SA_IN 4
64 typedef struct ipsec_tun_protect_t_
66 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
69 /* not using a vector since we want the memory inline
72 index_t itp_in_sas[ITP_MAX_N_SA_IN];
76 ipsec_ep_t itp_crypto;
78 ipsec_protect_flags_t itp_flags;
82 ip_address_t *itp_key;
84 } ipsec_tun_protect_t;
86 #define FOR_EACH_IPSEC_PROTECT_INPUT_SAI(_itp, _sai, body) \
89 for (__ii = 0; __ii < _itp->itp_n_sa_in; __ii++) { \
90 _sai = itp->itp_in_sas[__ii]; \
94 #define FOR_EACH_IPSEC_PROTECT_INPUT_SA(_itp, _sa, body) \
97 for (__ii = 0; __ii < _itp->itp_n_sa_in; __ii++) { \
98 _sa = ipsec_sa_get(itp->itp_in_sas[__ii]); \
103 extern int ipsec_tun_protect_update_one (u32 sw_if_index,
104 const ip_address_t * nh,
105 u32 sa_out, u32 sa_in);
106 extern int ipsec_tun_protect_update (u32 sw_if_index,
107 const ip_address_t * nh,
108 u32 sa_out, u32 * sa_ins);
109 extern int ipsec_tun_protect_update_in (u32 sw_if_index,
110 const ip_address_t * nh, u32 sa_in);
111 extern int ipsec_tun_protect_update_out (u32 sw_if_index,
112 const ip_address_t * nh, u32 sa_out);
114 extern int ipsec_tun_protect_del (u32 sw_if_index, const ip_address_t * nh);
116 typedef walk_rc_t (*ipsec_tun_protect_walk_cb_t) (index_t itpi, void *arg);
117 extern void ipsec_tun_protect_walk (ipsec_tun_protect_walk_cb_t fn,
119 extern void ipsec_tun_protect_walk_itf (u32 sw_if_index,
120 ipsec_tun_protect_walk_cb_t fn,
123 extern u8 *format_ipsec_tun_protect (u8 * s, va_list * args);
124 extern u8 *format_ipsec_tun_protect_index (u8 * s, va_list * args);
126 extern void ipsec_tun_register_nodes (ip_address_family_t af);
127 extern void ipsec_tun_unregister_nodes (ip_address_family_t af);
130 extern vlib_node_registration_t ipsec4_tun_input_node;
131 extern vlib_node_registration_t ipsec6_tun_input_node;
136 extern ipsec_tun_protect_t *ipsec_tun_protect_pool;
138 typedef struct ipsec_tun_lkup_result_t_
149 } ipsec_tun_lkup_result_t;
151 always_inline ipsec_tun_protect_t *
152 ipsec_tun_protect_get (u32 index)
154 return (pool_elt_at_index (ipsec_tun_protect_pool, index));
157 extern index_t *ipsec_tun_protect_sa_by_adj_index;
158 always_inline index_t
159 ipsec_tun_protect_get_sa_out (adj_index_t ai)
161 ASSERT (vec_len (ipsec_tun_protect_sa_by_adj_index) > ai);
162 ASSERT (INDEX_INVALID != ipsec_tun_protect_sa_by_adj_index[ai]);
164 return (ipsec_tun_protect_sa_by_adj_index[ai]);
168 * fd.io coding-style-patch-verification: ON
171 * eval: (c-set-style "gnu")