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.
16 #include <vnet/devices/dpdk/dpdk.h>
19 #define foreach_ipsec_policy_action \
20 _(0, BYPASS, "bypass") \
21 _(1, DISCARD, "discard") \
22 _(2, RESOLVE, "resolve") \
23 _(3, PROTECT, "protect")
26 #define _(v,f,s) IPSEC_POLICY_ACTION_##f = v,
27 foreach_ipsec_policy_action
29 IPSEC_POLICY_N_ACTION,
30 } ipsec_policy_action_t;
32 #define foreach_ipsec_crypto_alg \
34 _(1, AES_CBC_128, "aes-cbc-128") \
35 _(2, AES_CBC_192, "aes-cbc-192") \
36 _(3, AES_CBC_256, "aes-cbc-256")
39 #define _(v,f,s) IPSEC_CRYPTO_ALG_##f = v,
40 foreach_ipsec_crypto_alg
45 #define foreach_ipsec_integ_alg \
47 _(1, MD5_96, "md5-96") /* RFC2403 */ \
48 _(2, SHA1_96, "sha1-96") /* RFC2404 */ \
49 _(3, SHA_256_96, "sha-256-96") /* draft-ietf-ipsec-ciph-sha-256-00 */ \
50 _(4, SHA_256_128, "sha-256-128") /* RFC4868 */ \
51 _(5, SHA_384_192, "sha-384-192") /* RFC4868 */ \
52 _(6, SHA_512_256, "sha-512-256") /* RFC4868 */
55 #define _(v,f,s) IPSEC_INTEG_ALG_##f = v,
56 foreach_ipsec_integ_alg
62 IPSEC_PROTOCOL_AH = 0,
63 IPSEC_PROTOCOL_ESP = 1
69 ipsec_protocol_t protocol;
71 ipsec_crypto_alg_t crypto_alg;
75 ipsec_integ_alg_t integ_alg;
84 ip46_address_t tunnel_src_addr;
85 ip46_address_t tunnel_dst_addr;
96 ip46_address_t start, stop;
97 } ip46_address_range_t;
107 ip4_address_t local_ip, remote_ip;
110 } ipsec_add_del_tunnel_args_t;
113 IPSEC_IF_SET_KEY_TYPE_NONE,
114 IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO,
115 IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO,
116 IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG,
117 IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG,
118 } ipsec_if_set_key_type_t;
127 ip46_address_range_t laddr;
128 ip46_address_range_t raddr;
139 vlib_counter_t counter;
144 /* pool of policies */
145 ipsec_policy_t * policies;
146 /* vectors of policy indices */
147 u32 * ipv4_outbound_policies;
148 u32 * ipv6_outbound_policies;
149 u32 * ipv4_inbound_protect_policy_indices;
150 u32 * ipv4_inbound_policy_discard_and_bypass_indices;
151 u32 * ipv6_inbound_protect_policy_indices;
152 u32 * ipv6_inbound_policy_discard_and_bypass_indices;
157 } ip4_ipsec_config_t;
161 } ip6_ipsec_config_t;
170 /* pool of tunnel instances */
174 /* pool of tunnel interfaces */
175 ipsec_tunnel_if_t * tunnel_interfaces;
176 u32 * free_tunnel_if_indices;
180 uword * tunnel_index_by_key;
183 vlib_main_t *vlib_main;
184 vnet_main_t *vnet_main;
186 /* next node indices */
187 u32 feature_next_node_index[32];
190 uword * spd_index_by_spd_id;
191 uword * spd_index_by_sw_if_index;
192 uword * sa_index_by_sa_id;
193 uword * ipsec_if_pool_index_by_key;
196 u32 error_drop_node_index;
197 u32 ip4_lookup_node_index;
198 u32 esp_encrypt_node_index;
202 ipsec_main_t ipsec_main;
204 extern vlib_node_registration_t esp_encrypt_node;
205 extern vlib_node_registration_t esp_decrypt_node;
206 extern vlib_node_registration_t ipsec_if_output_node;
207 extern vlib_node_registration_t ipsec_if_input_node;
213 int ipsec_set_interface_spd(vlib_main_t * vm, u32 sw_if_index, u32 spd_id, int is_add);
214 int ipsec_add_del_spd(vlib_main_t * vm, u32 spd_id, int is_add);
215 int ipsec_add_del_policy(vlib_main_t * vm, ipsec_policy_t * policy, int is_add);
216 int ipsec_add_del_sa(vlib_main_t * vm, ipsec_sa_t * new_sa, int is_add);
217 int ipsec_set_sa_key(vlib_main_t * vm, ipsec_sa_t * sa_update);
219 u8 * format_ipsec_if_output_trace (u8 * s, va_list * args);
220 u8 * format_ipsec_policy_action (u8 * s, va_list * args);
221 u8 * format_ipsec_crypto_alg (u8 * s, va_list * args);
222 u8 * format_ipsec_integ_alg (u8 * s, va_list * args);
223 u8 * format_ipsec_replay_window(u8 * s, va_list * args);
224 uword unformat_ipsec_policy_action (unformat_input_t * input, va_list * args);
225 uword unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args);
226 uword unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args);
228 u32 ipsec_add_del_tunnel_if (vnet_main_t * vnm, ipsec_add_del_tunnel_args_t * args);
229 int ipsec_set_interface_key(vnet_main_t * vnm, u32 hw_if_index, ipsec_if_set_key_type_t type, u8 alg, u8 * key);
237 ipsec_alloc_empty_buffers(vlib_main_t * vm, ipsec_main_t *im)
240 dpdk_main_t * dm = &dpdk_main;
241 u32 free_list_index = dm->vlib_buffer_free_list_index;
243 u32 free_list_index = VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX;
245 uword l = vec_len (im->empty_buffers);
248 if (PREDICT_FALSE(l < VLIB_FRAME_SIZE))
250 if (!im->empty_buffers) {
251 vec_alloc (im->empty_buffers, 2 * VLIB_FRAME_SIZE );
254 n_alloc = vlib_buffer_alloc_from_free_list (vm, im->empty_buffers + l,
255 2 * VLIB_FRAME_SIZE - l,
258 _vec_len (im->empty_buffers) = l + n_alloc;
262 static_always_inline u32 /* FIXME move to interface???.h */
263 get_next_output_feature_node_index( vnet_main_t * vnm,
266 vlib_main_t * vm = vlib_get_main();
269 intf_output_feat_t next_feature;
271 u8 * node_names[] = {
272 #define _(sym, str) (u8 *) str,
273 foreach_intf_output_feat
277 count_trailing_zeros(next_feature, vnet_buffer(b)->output_features.bitmap);
279 if (next_feature >= INTF_OUTPUT_FEAT_DONE)
281 u32 sw_if_index = vnet_buffer(b)->sw_if_index[VLIB_TX];
282 vnet_hw_interface_t * hw = vnet_get_sup_hw_interface(vnm, sw_if_index);
283 r = hw->output_node_index;
287 vnet_buffer(b)->output_features.bitmap &= ~(1 << next_feature);
289 node = vlib_get_node_by_name(vm, node_names[next_feature]);