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.
15 #ifndef __IPSEC_SPD_SA_H__
16 #define __IPSEC_SPD_SA_H__
18 #include <vlib/vlib.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/fib/fib_node.h>
22 #define foreach_ipsec_crypto_alg \
24 _ (1, AES_CBC_128, "aes-cbc-128") \
25 _ (2, AES_CBC_192, "aes-cbc-192") \
26 _ (3, AES_CBC_256, "aes-cbc-256") \
27 _ (4, AES_CTR_128, "aes-ctr-128") \
28 _ (5, AES_CTR_192, "aes-ctr-192") \
29 _ (6, AES_CTR_256, "aes-ctr-256") \
30 _ (7, AES_GCM_128, "aes-gcm-128") \
31 _ (8, AES_GCM_192, "aes-gcm-192") \
32 _ (9, AES_GCM_256, "aes-gcm-256") \
33 _ (10, DES_CBC, "des-cbc") \
34 _ (11, 3DES_CBC, "3des-cbc")
38 #define _(v, f, s) IPSEC_CRYPTO_ALG_##f = v,
39 foreach_ipsec_crypto_alg
44 #define foreach_ipsec_integ_alg \
46 _ (1, MD5_96, "md5-96") /* RFC2403 */ \
47 _ (2, SHA1_96, "sha1-96") /* RFC2404 */ \
48 _ (3, SHA_256_96, "sha-256-96") /* draft-ietf-ipsec-ciph-sha-256-00 */ \
49 _ (4, SHA_256_128, "sha-256-128") /* RFC4868 */ \
50 _ (5, SHA_384_192, "sha-384-192") /* RFC4868 */ \
51 _ (6, SHA_512_256, "sha-512-256") /* RFC4868 */
55 #define _(v, f, s) IPSEC_INTEG_ALG_##f = v,
56 foreach_ipsec_integ_alg
63 IPSEC_PROTOCOL_AH = 0,
64 IPSEC_PROTOCOL_ESP = 1
67 #define IPSEC_N_PROTOCOLS (IPSEC_PROTOCOL_ESP+1)
69 #define IPSEC_KEY_MAX_LEN 128
70 typedef struct ipsec_key_t_
73 u8 data[IPSEC_KEY_MAX_LEN];
77 * Enable extended sequence numbers
79 * IPsec tunnel mode if non-zero, else transport mode
80 * IPsec tunnel mode is IPv6 if non-zero,
81 * else IPv4 tunnel only valid if is_tunnel is non-zero
82 * enable UDP encapsulation for NAT traversal
84 #define foreach_ipsec_sa_flags \
86 _ (1, USE_EXTENDED_SEQ_NUM, "esn") \
87 _ (2, USE_ANTI_REPLAY, "anti-replay") \
88 _ (4, IS_TUNNEL, "tunnel") \
89 _ (8, IS_TUNNEL_V6, "tunnel-v6") \
90 _ (16, UDP_ENCAP, "udp-encap") \
92 typedef enum ipsec_sad_flags_t_
94 #define _(v, f, s) IPSEC_SA_FLAG_##f = v,
95 foreach_ipsec_sa_flags
105 ipsec_protocol_t protocol;
107 ipsec_crypto_alg_t crypto_alg;
108 ipsec_key_t crypto_key;
110 u8 crypto_block_size;
111 vnet_crypto_op_type_t crypto_enc_op_type;
112 vnet_crypto_op_type_t crypto_dec_op_type;
114 ipsec_integ_alg_t integ_alg;
115 ipsec_key_t integ_key;
116 vnet_crypto_op_type_t integ_op_type;
125 ip46_address_t tunnel_src_addr;
126 ip46_address_t tunnel_dst_addr;
128 fib_node_index_t fib_entry_index;
130 dpo_id_t dpo[IPSEC_N_PROTOCOLS];
145 * SA packet & bytes counters
147 extern vlib_combined_counter_main_t ipsec_sa_counters;
149 extern void ipsec_mk_key (ipsec_key_t * key, const u8 * data, u8 len);
151 extern int ipsec_sa_add (u32 id,
153 ipsec_protocol_t proto,
154 ipsec_crypto_alg_t crypto_alg,
155 const ipsec_key_t * ck,
156 ipsec_integ_alg_t integ_alg,
157 const ipsec_key_t * ik,
158 ipsec_sa_flags_t flags,
160 const ip46_address_t * tunnel_src_addr,
161 const ip46_address_t * tunnel_dst_addr,
163 extern u32 ipsec_sa_del (u32 id);
164 extern void ipsec_sa_stack (ipsec_sa_t * sa);
165 extern void ipsec_sa_set_crypto_alg (ipsec_sa_t * sa,
166 ipsec_crypto_alg_t crypto_alg);
167 extern void ipsec_sa_set_integ_alg (ipsec_sa_t * sa,
168 ipsec_integ_alg_t integ_alg);
170 extern u8 ipsec_is_sa_used (u32 sa_index);
171 extern int ipsec_set_sa_key (u32 id,
172 const ipsec_key_t * ck, const ipsec_key_t * ik);
173 extern u32 ipsec_get_sa_index_by_sa_id (u32 sa_id);
175 typedef walk_rc_t (*ipsec_sa_walk_cb_t) (ipsec_sa_t * sa, void *ctx);
176 extern void ipsec_sa_walk (ipsec_sa_walk_cb_t cd, void *ctx);
178 extern u8 *format_ipsec_crypto_alg (u8 * s, va_list * args);
179 extern u8 *format_ipsec_integ_alg (u8 * s, va_list * args);
180 extern u8 *format_ipsec_sa (u8 * s, va_list * args);
181 extern u8 *format_ipsec_key (u8 * s, va_list * args);
182 extern uword unformat_ipsec_crypto_alg (unformat_input_t * input,
184 extern uword unformat_ipsec_integ_alg (unformat_input_t * input,
186 extern uword unformat_ipsec_key (unformat_input_t * input, va_list * args);
188 #endif /* __IPSEC_SPD_SA_H__ */
191 * fd.io coding-style-patch-verification: ON
194 * eval: (c-set-style "gnu")