blob: 2601f51038a3432b21b26c8a2b7fd8d3cb0e8873 [file] [log] [blame]
Neale Ranns999c8ee2019-02-01 03:31:24 -08001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15#ifndef __IPSEC_SPD_SA_H__
16#define __IPSEC_SPD_SA_H__
17
18#include <vlib/vlib.h>
19#include <vnet/ip/ip.h>
Neale Ranns8d7c5022019-02-06 01:41:05 -080020#include <vnet/fib/fib_node.h>
Neale Ranns999c8ee2019-02-01 03:31:24 -080021
22#define foreach_ipsec_crypto_alg \
23 _ (0, NONE, "none") \
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")
35
36typedef enum
37{
38#define _(v, f, s) IPSEC_CRYPTO_ALG_##f = v,
39 foreach_ipsec_crypto_alg
40#undef _
41 IPSEC_CRYPTO_N_ALG,
42} ipsec_crypto_alg_t;
43
44#define foreach_ipsec_integ_alg \
45 _ (0, NONE, "none") \
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 */
52
53typedef enum
54{
55#define _(v, f, s) IPSEC_INTEG_ALG_##f = v,
56 foreach_ipsec_integ_alg
57#undef _
58 IPSEC_INTEG_N_ALG,
59} ipsec_integ_alg_t;
60
61typedef enum
62{
63 IPSEC_PROTOCOL_AH = 0,
64 IPSEC_PROTOCOL_ESP = 1
65} ipsec_protocol_t;
66
Neale Ranns8d7c5022019-02-06 01:41:05 -080067#define IPSEC_N_PROTOCOLS (IPSEC_PROTOCOL_ESP+1)
68
69#define IPSEC_KEY_MAX_LEN 128
70typedef struct ipsec_key_t_
71{
72 u8 len;
73 u8 data[IPSEC_KEY_MAX_LEN];
74} ipsec_key_t;
75
76/*
77 * Enable extended sequence numbers
78 * Enable Anti-replay
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
83 */
84#define foreach_ipsec_sa_flags \
85 _ (0, NONE, "none") \
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") \
91
92typedef enum ipsec_sad_flags_t_
93{
94#define _(v, f, s) IPSEC_SA_FLAG_##f = v,
95 foreach_ipsec_sa_flags
96#undef _
97} ipsec_sa_flags_t;
98
Neale Ranns999c8ee2019-02-01 03:31:24 -080099typedef struct
100{
Neale Ranns8d7c5022019-02-06 01:41:05 -0800101 fib_node_t node;
Neale Ranns999c8ee2019-02-01 03:31:24 -0800102 u32 id;
103 u32 spi;
Neale Rannseba31ec2019-02-17 18:04:27 +0000104 u32 stat_index;
Neale Ranns999c8ee2019-02-01 03:31:24 -0800105 ipsec_protocol_t protocol;
106
107 ipsec_crypto_alg_t crypto_alg;
Neale Ranns8d7c5022019-02-06 01:41:05 -0800108 ipsec_key_t crypto_key;
Neale Ranns999c8ee2019-02-01 03:31:24 -0800109
110 ipsec_integ_alg_t integ_alg;
Neale Ranns8d7c5022019-02-06 01:41:05 -0800111 ipsec_key_t integ_key;
Neale Ranns999c8ee2019-02-01 03:31:24 -0800112
113 u8 use_esn;
114 u8 use_anti_replay;
115
116 u8 is_tunnel;
117 u8 is_tunnel_ip6;
118 u8 udp_encap;
119 ip46_address_t tunnel_src_addr;
120 ip46_address_t tunnel_dst_addr;
121
Neale Ranns8d7c5022019-02-06 01:41:05 -0800122 fib_node_index_t fib_entry_index;
123 u32 sibling;
124 dpo_id_t dpo[IPSEC_N_PROTOCOLS];
125
Neale Ranns999c8ee2019-02-01 03:31:24 -0800126 u32 tx_fib_index;
127 u32 salt;
128
129 /* runtime */
130 u32 seq;
131 u32 seq_hi;
132 u32 last_seq;
133 u32 last_seq_hi;
134 u64 replay_window;
Neale Ranns999c8ee2019-02-01 03:31:24 -0800135} ipsec_sa_t;
136
Neale Rannseba31ec2019-02-17 18:04:27 +0000137/**
138 * @brief
139 * SA packet & bytes counters
140 */
141extern vlib_combined_counter_main_t ipsec_sa_counters;
142
Neale Ranns8d7c5022019-02-06 01:41:05 -0800143extern void ipsec_mk_key (ipsec_key_t * key, const u8 * data, u8 len);
144
145extern int ipsec_sa_add (u32 id,
146 u32 spi,
147 ipsec_protocol_t proto,
148 ipsec_crypto_alg_t crypto_alg,
149 const ipsec_key_t * ck,
150 ipsec_integ_alg_t integ_alg,
151 const ipsec_key_t * ik,
152 ipsec_sa_flags_t flags,
153 u32 tx_table_id,
154 const ip46_address_t * tunnel_src_addr,
155 const ip46_address_t * tunnel_dst_addr,
156 u32 * sa_index);
157extern u32 ipsec_sa_del (u32 id);
Neale Rannsb4cfd552019-02-13 02:08:06 -0800158extern void ipsec_sa_stack (ipsec_sa_t * sa);
Neale Ranns8d7c5022019-02-06 01:41:05 -0800159
Neale Ranns999c8ee2019-02-01 03:31:24 -0800160extern u8 ipsec_is_sa_used (u32 sa_index);
Neale Ranns8d7c5022019-02-06 01:41:05 -0800161extern int ipsec_set_sa_key (u32 id,
162 const ipsec_key_t * ck, const ipsec_key_t * ik);
Neale Ranns999c8ee2019-02-01 03:31:24 -0800163extern u32 ipsec_get_sa_index_by_sa_id (u32 sa_id);
164
Neale Rannsb4cfd552019-02-13 02:08:06 -0800165typedef walk_rc_t (*ipsec_sa_walk_cb_t) (ipsec_sa_t * sa, void *ctx);
166extern void ipsec_sa_walk (ipsec_sa_walk_cb_t cd, void *ctx);
167
Neale Ranns999c8ee2019-02-01 03:31:24 -0800168extern u8 *format_ipsec_crypto_alg (u8 * s, va_list * args);
169extern u8 *format_ipsec_integ_alg (u8 * s, va_list * args);
Neale Ranns8d7c5022019-02-06 01:41:05 -0800170extern u8 *format_ipsec_sa (u8 * s, va_list * args);
171extern u8 *format_ipsec_key (u8 * s, va_list * args);
Neale Ranns999c8ee2019-02-01 03:31:24 -0800172extern uword unformat_ipsec_crypto_alg (unformat_input_t * input,
173 va_list * args);
174extern uword unformat_ipsec_integ_alg (unformat_input_t * input,
175 va_list * args);
Neale Ranns8d7c5022019-02-06 01:41:05 -0800176extern uword unformat_ipsec_key (unformat_input_t * input, va_list * args);
Neale Ranns999c8ee2019-02-01 03:31:24 -0800177
178#endif /* __IPSEC_SPD_SA_H__ */
179
180/*
181 * fd.io coding-style-patch-verification: ON
182 *
183 * Local Variables:
184 * eval: (c-set-style "gnu")
185 * End:
186 */