2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 #define IPSEC_FLAG_IPSEC_GRE_TUNNEL (1 << 0)
20 #define foreach_ipsec_policy_action \
21 _(0, BYPASS, "bypass") \
22 _(1, DISCARD, "discard") \
23 _(2, RESOLVE, "resolve") \
24 _(3, PROTECT, "protect")
28 #define _(v,f,s) IPSEC_POLICY_ACTION_##f = v,
29 foreach_ipsec_policy_action
31 IPSEC_POLICY_N_ACTION,
32 } ipsec_policy_action_t;
34 #define foreach_ipsec_crypto_alg \
36 _(1, AES_CBC_128, "aes-cbc-128") \
37 _(2, AES_CBC_192, "aes-cbc-192") \
38 _(3, AES_CBC_256, "aes-cbc-256")
42 #define _(v,f,s) IPSEC_CRYPTO_ALG_##f = v,
43 foreach_ipsec_crypto_alg
48 #define foreach_ipsec_integ_alg \
50 _(1, MD5_96, "md5-96") /* RFC2403 */ \
51 _(2, SHA1_96, "sha1-96") /* RFC2404 */ \
52 _(3, SHA_256_96, "sha-256-96") /* draft-ietf-ipsec-ciph-sha-256-00 */ \
53 _(4, SHA_256_128, "sha-256-128") /* RFC4868 */ \
54 _(5, SHA_384_192, "sha-384-192") /* RFC4868 */ \
55 _(6, SHA_512_256, "sha-512-256") /* RFC4868 */
59 #define _(v,f,s) IPSEC_INTEG_ALG_##f = v,
60 foreach_ipsec_integ_alg
67 IPSEC_PROTOCOL_AH = 0,
68 IPSEC_PROTOCOL_ESP = 1
75 ipsec_protocol_t protocol;
77 ipsec_crypto_alg_t crypto_alg;
81 ipsec_integ_alg_t integ_alg;
90 ip46_address_t tunnel_src_addr;
91 ip46_address_t tunnel_dst_addr;
103 ip46_address_t start, stop;
104 } ip46_address_range_t;
116 ip4_address_t local_ip, remote_ip;
119 ipsec_crypto_alg_t crypto_alg;
120 u8 local_crypto_key_len;
121 u8 local_crypto_key[128];
122 u8 remote_crypto_key_len;
123 u8 remote_crypto_key[128];
124 ipsec_integ_alg_t integ_alg;
125 u8 local_integ_key_len;
126 u8 local_integ_key[128];
127 u8 remote_integ_key_len;
128 u8 remote_integ_key[128];
129 } ipsec_add_del_tunnel_args_t;
136 ip4_address_t local_ip;
137 ip4_address_t remote_ip;
138 } ipsec_add_del_ipsec_gre_tunnel_args_t;
142 IPSEC_IF_SET_KEY_TYPE_NONE,
143 IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO,
144 IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO,
145 IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG,
146 IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG,
147 } ipsec_if_set_key_type_t;
157 ip46_address_range_t laddr;
158 ip46_address_range_t raddr;
169 vlib_counter_t counter;
175 /* pool of policies */
176 ipsec_policy_t *policies;
177 /* vectors of policy indices */
178 u32 *ipv4_outbound_policies;
179 u32 *ipv6_outbound_policies;
180 u32 *ipv4_inbound_protect_policy_indices;
181 u32 *ipv4_inbound_policy_discard_and_bypass_indices;
182 u32 *ipv6_inbound_protect_policy_indices;
183 u32 *ipv6_inbound_policy_discard_and_bypass_indices;
189 } ip4_ipsec_config_t;
194 } ip6_ipsec_config_t;
205 /* pool of tunnel instances */
209 /* pool of tunnel interfaces */
210 ipsec_tunnel_if_t *tunnel_interfaces;
211 u32 *free_tunnel_if_indices;
215 uword *tunnel_index_by_key;
218 vlib_main_t *vlib_main;
219 vnet_main_t *vnet_main;
221 /* next node indices */
222 u32 feature_next_node_index[32];
225 uword *spd_index_by_spd_id;
226 uword *spd_index_by_sw_if_index;
227 uword *sa_index_by_sa_id;
228 uword *ipsec_if_pool_index_by_key;
231 u32 error_drop_node_index;
232 u32 ip4_lookup_node_index;
233 u32 esp_encrypt_node_index;
237 ipsec_main_t ipsec_main;
239 extern vlib_node_registration_t esp_encrypt_node;
240 extern vlib_node_registration_t esp_decrypt_node;
241 extern vlib_node_registration_t ipsec_if_output_node;
242 extern vlib_node_registration_t ipsec_if_input_node;
248 int ipsec_set_interface_spd (vlib_main_t * vm, u32 sw_if_index, u32 spd_id,
250 int ipsec_add_del_spd (vlib_main_t * vm, u32 spd_id, int is_add);
251 int ipsec_add_del_policy (vlib_main_t * vm, ipsec_policy_t * policy,
253 int ipsec_add_del_sa (vlib_main_t * vm, ipsec_sa_t * new_sa, int is_add);
254 int ipsec_set_sa_key (vlib_main_t * vm, ipsec_sa_t * sa_update);
256 u32 ipsec_get_sa_index_by_sa_id (u32 sa_id);
257 u8 *format_ipsec_if_output_trace (u8 * s, va_list * args);
258 u8 *format_ipsec_policy_action (u8 * s, va_list * args);
259 u8 *format_ipsec_crypto_alg (u8 * s, va_list * args);
260 u8 *format_ipsec_integ_alg (u8 * s, va_list * args);
261 u8 *format_ipsec_replay_window (u8 * s, va_list * args);
262 uword unformat_ipsec_policy_action (unformat_input_t * input, va_list * args);
263 uword unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args);
264 uword unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args);
266 /*u32 ipsec_add_del_tunnel_if (vnet_main_t * vnm, ipsec_add_del_tunnel_args_t * args); */
267 int ipsec_add_del_tunnel_if (ipsec_add_del_tunnel_args_t * args);
268 int ipsec_add_del_ipsec_gre_tunnel (vnet_main_t * vnm,
269 ipsec_add_del_ipsec_gre_tunnel_args_t *
271 int ipsec_set_interface_key (vnet_main_t * vnm, u32 hw_if_index,
272 ipsec_if_set_key_type_t type, u8 alg, u8 * key);
280 ipsec_alloc_empty_buffers (vlib_main_t * vm, ipsec_main_t * im)
282 u32 cpu_index = os_get_cpu_number ();
283 uword l = vec_len (im->empty_buffers[cpu_index]);
286 if (PREDICT_FALSE (l < VLIB_FRAME_SIZE))
288 if (!im->empty_buffers[cpu_index])
290 vec_alloc (im->empty_buffers[cpu_index], 2 * VLIB_FRAME_SIZE);
293 n_alloc = vlib_buffer_alloc (vm, im->empty_buffers[cpu_index] + l,
294 2 * VLIB_FRAME_SIZE - l);
296 _vec_len (im->empty_buffers[cpu_index]) = l + n_alloc;
300 static_always_inline u32
301 get_next_output_feature_node_index (vlib_buffer_t * b,
302 vlib_node_runtime_t * nr)
305 u32 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_TX];
306 vlib_main_t *vm = vlib_get_main ();
307 vlib_node_t *node = vlib_get_node (vm, nr->node_index);
309 vnet_feature_next (sw_if_index, &next, b);
310 return node->next_nodes[next];
313 #endif /* __IPSEC_H__ */
316 * fd.io coding-style-patch-verification: ON
319 * eval: (c-set-style "gnu")