Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 15 | #ifndef __IPSEC_H__ |
| 16 | #define __IPSEC_H__ |
| 17 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 18 | #include <vnet/ip/ip.h> |
| 19 | #include <vnet/feature/feature.h> |
| 20 | |
Matus Fabian | 694265d | 2016-08-10 01:55:36 -0700 | [diff] [blame] | 21 | #define IPSEC_FLAG_IPSEC_GRE_TUNNEL (1 << 0) |
| 22 | |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame^] | 23 | #define foreach_ipsec_output_next \ |
| 24 | _ (DROP, "error-drop") \ |
| 25 | _ (ESP4_ENCRYPT, "esp4-encrypt") \ |
| 26 | _ (AH4_ENCRYPT, "ah4-encrypt") \ |
| 27 | _ (ESP6_ENCRYPT, "esp6-encrypt") \ |
| 28 | _ (AH6_ENCRYPT, "ah6-encrypt") |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 29 | |
| 30 | #define _(v, s) IPSEC_OUTPUT_NEXT_##v, |
| 31 | typedef enum |
| 32 | { |
| 33 | foreach_ipsec_output_next |
| 34 | #undef _ |
| 35 | IPSEC_OUTPUT_N_NEXT, |
| 36 | } ipsec_output_next_t; |
| 37 | |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame^] | 38 | #define foreach_ipsec_input_next \ |
| 39 | _ (DROP, "error-drop") \ |
| 40 | _ (ESP4_DECRYPT, "esp4-decrypt") \ |
| 41 | _ (AH4_DECRYPT, "ah4-decrypt") \ |
| 42 | _ (ESP6_DECRYPT, "esp6-decrypt") \ |
| 43 | _ (AH6_DECRYPT, "ah6-decrypt") |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 44 | |
| 45 | #define _(v, s) IPSEC_INPUT_NEXT_##v, |
| 46 | typedef enum |
| 47 | { |
| 48 | foreach_ipsec_input_next |
| 49 | #undef _ |
| 50 | IPSEC_INPUT_N_NEXT, |
| 51 | } ipsec_input_next_t; |
| 52 | |
| 53 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | #define foreach_ipsec_policy_action \ |
| 55 | _(0, BYPASS, "bypass") \ |
| 56 | _(1, DISCARD, "discard") \ |
| 57 | _(2, RESOLVE, "resolve") \ |
| 58 | _(3, PROTECT, "protect") |
| 59 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 60 | typedef enum |
| 61 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 62 | #define _(v,f,s) IPSEC_POLICY_ACTION_##f = v, |
| 63 | foreach_ipsec_policy_action |
| 64 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 65 | IPSEC_POLICY_N_ACTION, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 66 | } ipsec_policy_action_t; |
| 67 | |
Radu Nicolau | 6929ea9 | 2016-11-29 11:00:30 +0000 | [diff] [blame] | 68 | #define foreach_ipsec_crypto_alg \ |
| 69 | _(0, NONE, "none") \ |
| 70 | _(1, AES_CBC_128, "aes-cbc-128") \ |
| 71 | _(2, AES_CBC_192, "aes-cbc-192") \ |
| 72 | _(3, AES_CBC_256, "aes-cbc-256") \ |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 73 | _(4, AES_CTR_128, "aes-ctr-128") \ |
| 74 | _(5, AES_CTR_192, "aes-ctr-192") \ |
| 75 | _(6, AES_CTR_256, "aes-ctr-256") \ |
| 76 | _(7, AES_GCM_128, "aes-gcm-128") \ |
| 77 | _(8, AES_GCM_192, "aes-gcm-192") \ |
“mukeshyadav1984” | 72454dd | 2017-11-28 10:52:34 -0800 | [diff] [blame] | 78 | _(9, AES_GCM_256, "aes-gcm-256") \ |
| 79 | _(10, DES_CBC, "des-cbc") \ |
| 80 | _(11, 3DES_CBC, "3des-cbc") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 81 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 82 | typedef enum |
| 83 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | #define _(v,f,s) IPSEC_CRYPTO_ALG_##f = v, |
| 85 | foreach_ipsec_crypto_alg |
| 86 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 87 | IPSEC_CRYPTO_N_ALG, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 88 | } ipsec_crypto_alg_t; |
| 89 | |
Radu Nicolau | 6929ea9 | 2016-11-29 11:00:30 +0000 | [diff] [blame] | 90 | #define foreach_ipsec_integ_alg \ |
| 91 | _(0, NONE, "none") \ |
| 92 | _(1, MD5_96, "md5-96") /* RFC2403 */ \ |
| 93 | _(2, SHA1_96, "sha1-96") /* RFC2404 */ \ |
| 94 | _(3, SHA_256_96, "sha-256-96") /* draft-ietf-ipsec-ciph-sha-256-00 */ \ |
| 95 | _(4, SHA_256_128, "sha-256-128") /* RFC4868 */ \ |
| 96 | _(5, SHA_384_192, "sha-384-192") /* RFC4868 */ \ |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 97 | _(6, SHA_512_256, "sha-512-256") /* RFC4868 */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 98 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 99 | typedef enum |
| 100 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | #define _(v,f,s) IPSEC_INTEG_ALG_##f = v, |
| 102 | foreach_ipsec_integ_alg |
| 103 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 104 | IPSEC_INTEG_N_ALG, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | } ipsec_integ_alg_t; |
| 106 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 107 | typedef enum |
| 108 | { |
| 109 | IPSEC_PROTOCOL_AH = 0, |
| 110 | IPSEC_PROTOCOL_ESP = 1 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | } ipsec_protocol_t; |
| 112 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 113 | typedef struct |
| 114 | { |
| 115 | u32 id; |
| 116 | u32 spi; |
| 117 | ipsec_protocol_t protocol; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 118 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 119 | ipsec_crypto_alg_t crypto_alg; |
| 120 | u8 crypto_key_len; |
| 121 | u8 crypto_key[128]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 122 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 123 | ipsec_integ_alg_t integ_alg; |
| 124 | u8 integ_key_len; |
| 125 | u8 integ_key[128]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 126 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 127 | u8 use_esn; |
| 128 | u8 use_anti_replay; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 129 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 130 | u8 is_tunnel; |
| 131 | u8 is_tunnel_ip6; |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 132 | u8 udp_encap; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 133 | ip46_address_t tunnel_src_addr; |
| 134 | ip46_address_t tunnel_dst_addr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | |
Radu Nicolau | 6929ea9 | 2016-11-29 11:00:30 +0000 | [diff] [blame] | 136 | u32 salt; |
| 137 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 138 | /* runtime */ |
| 139 | u32 seq; |
| 140 | u32 seq_hi; |
| 141 | u32 last_seq; |
| 142 | u32 last_seq_hi; |
| 143 | u64 replay_window; |
Radu Nicolau | cb33dc2 | 2017-02-16 16:49:46 +0000 | [diff] [blame] | 144 | |
| 145 | /*lifetime data */ |
| 146 | u64 total_data_size; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 147 | } ipsec_sa_t; |
| 148 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 149 | typedef struct |
| 150 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | ip46_address_t start, stop; |
| 152 | } ip46_address_range_t; |
| 153 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 154 | typedef struct |
| 155 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 156 | u16 start, stop; |
| 157 | } port_range_t; |
| 158 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 159 | typedef struct |
| 160 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 161 | u8 is_add; |
| 162 | u8 esn; |
| 163 | u8 anti_replay; |
| 164 | ip4_address_t local_ip, remote_ip; |
| 165 | u32 local_spi; |
| 166 | u32 remote_spi; |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 167 | ipsec_crypto_alg_t crypto_alg; |
| 168 | u8 local_crypto_key_len; |
| 169 | u8 local_crypto_key[128]; |
| 170 | u8 remote_crypto_key_len; |
| 171 | u8 remote_crypto_key[128]; |
| 172 | ipsec_integ_alg_t integ_alg; |
| 173 | u8 local_integ_key_len; |
| 174 | u8 local_integ_key[128]; |
| 175 | u8 remote_integ_key_len; |
| 176 | u8 remote_integ_key[128]; |
Matthew Smith | 8e1039a | 2018-04-12 07:32:56 -0500 | [diff] [blame] | 177 | u8 renumber; |
| 178 | u32 show_instance; |
Radu Nicolau | 717de09 | 2018-08-03 10:37:24 +0100 | [diff] [blame] | 179 | u8 udp_encap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 180 | } ipsec_add_del_tunnel_args_t; |
| 181 | |
Matus Fabian | 694265d | 2016-08-10 01:55:36 -0700 | [diff] [blame] | 182 | typedef struct |
| 183 | { |
| 184 | u8 is_add; |
| 185 | u32 local_sa_id; |
| 186 | u32 remote_sa_id; |
| 187 | ip4_address_t local_ip; |
| 188 | ip4_address_t remote_ip; |
| 189 | } ipsec_add_del_ipsec_gre_tunnel_args_t; |
| 190 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 191 | typedef enum |
| 192 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | IPSEC_IF_SET_KEY_TYPE_NONE, |
| 194 | IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO, |
| 195 | IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO, |
| 196 | IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG, |
| 197 | IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG, |
| 198 | } ipsec_if_set_key_type_t; |
| 199 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 200 | typedef struct |
| 201 | { |
| 202 | u32 id; |
| 203 | i32 priority; |
| 204 | u8 is_outbound; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 205 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 206 | // Selector |
| 207 | u8 is_ipv6; |
| 208 | ip46_address_range_t laddr; |
| 209 | ip46_address_range_t raddr; |
| 210 | u8 protocol; |
| 211 | port_range_t lport; |
| 212 | port_range_t rport; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 213 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 214 | // Policy |
| 215 | u8 policy; |
| 216 | u32 sa_id; |
| 217 | u32 sa_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 218 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 219 | // Counter |
| 220 | vlib_counter_t counter; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 221 | } ipsec_policy_t; |
| 222 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 223 | typedef struct |
| 224 | { |
| 225 | u32 id; |
| 226 | /* pool of policies */ |
| 227 | ipsec_policy_t *policies; |
| 228 | /* vectors of policy indices */ |
| 229 | u32 *ipv4_outbound_policies; |
| 230 | u32 *ipv6_outbound_policies; |
| 231 | u32 *ipv4_inbound_protect_policy_indices; |
| 232 | u32 *ipv4_inbound_policy_discard_and_bypass_indices; |
| 233 | u32 *ipv6_inbound_protect_policy_indices; |
| 234 | u32 *ipv6_inbound_policy_discard_and_bypass_indices; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 235 | } ipsec_spd_t; |
| 236 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 237 | typedef struct |
| 238 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 239 | u32 spd_index; |
| 240 | } ip4_ipsec_config_t; |
| 241 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 242 | typedef struct |
| 243 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 244 | u32 spd_index; |
| 245 | } ip6_ipsec_config_t; |
| 246 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 247 | typedef struct |
| 248 | { |
Dave Barach | eb987d3 | 2018-05-03 08:26:39 -0400 | [diff] [blame] | 249 | /* Required for pool_get_aligned */ |
| 250 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 251 | u32 input_sa_index; |
| 252 | u32 output_sa_index; |
| 253 | u32 hw_if_index; |
Matthew Smith | 8e1039a | 2018-04-12 07:32:56 -0500 | [diff] [blame] | 254 | u32 show_instance; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 255 | } ipsec_tunnel_if_t; |
| 256 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 257 | typedef struct |
| 258 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 259 | clib_error_t *(*add_del_sa_sess_cb) (u32 sa_index, u8 is_add); |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 260 | clib_error_t *(*check_support_cb) (ipsec_sa_t * sa); |
| 261 | } ipsec_main_callbacks_t; |
| 262 | |
| 263 | typedef struct |
| 264 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 265 | /* pool of tunnel instances */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 266 | ipsec_spd_t *spds; |
| 267 | ipsec_sa_t *sad; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 268 | |
| 269 | /* pool of tunnel interfaces */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 270 | ipsec_tunnel_if_t *tunnel_interfaces; |
| 271 | u32 *free_tunnel_if_indices; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 272 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 273 | u32 **empty_buffers; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 274 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 275 | uword *tunnel_index_by_key; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 276 | |
| 277 | /* convenience */ |
| 278 | vlib_main_t *vlib_main; |
| 279 | vnet_main_t *vnet_main; |
| 280 | |
| 281 | /* next node indices */ |
| 282 | u32 feature_next_node_index[32]; |
| 283 | |
| 284 | /* hashes */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 285 | uword *spd_index_by_spd_id; |
| 286 | uword *spd_index_by_sw_if_index; |
| 287 | uword *sa_index_by_sa_id; |
| 288 | uword *ipsec_if_pool_index_by_key; |
Matthew Smith | 8e1039a | 2018-04-12 07:32:56 -0500 | [diff] [blame] | 289 | uword *ipsec_if_real_dev_by_show_dev; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 290 | |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 291 | /* node indices */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 292 | u32 error_drop_node_index; |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame^] | 293 | u32 esp4_encrypt_node_index; |
| 294 | u32 esp4_decrypt_node_index; |
| 295 | u32 ah4_encrypt_node_index; |
| 296 | u32 ah4_decrypt_node_index; |
| 297 | u32 esp6_encrypt_node_index; |
| 298 | u32 esp6_decrypt_node_index; |
| 299 | u32 ah6_encrypt_node_index; |
| 300 | u32 ah6_decrypt_node_index; |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 301 | /* next node indices */ |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame^] | 302 | u32 esp4_encrypt_next_index; |
| 303 | u32 esp4_decrypt_next_index; |
| 304 | u32 ah4_encrypt_next_index; |
| 305 | u32 ah4_decrypt_next_index; |
| 306 | u32 esp6_encrypt_next_index; |
| 307 | u32 esp6_decrypt_next_index; |
| 308 | u32 ah6_encrypt_next_index; |
| 309 | u32 ah6_decrypt_next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 310 | |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 311 | /* callbacks */ |
| 312 | ipsec_main_callbacks_t cb; |
Klement Sekera | ee52d87 | 2018-06-07 19:36:07 +0200 | [diff] [blame] | 313 | |
| 314 | /* helper for sort function */ |
| 315 | ipsec_spd_t *spd_to_sort; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 316 | } ipsec_main_t; |
| 317 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 318 | extern ipsec_main_t ipsec_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 319 | |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame^] | 320 | extern vlib_node_registration_t esp4_encrypt_node; |
| 321 | extern vlib_node_registration_t esp4_decrypt_node; |
| 322 | extern vlib_node_registration_t ah4_encrypt_node; |
| 323 | extern vlib_node_registration_t ah4_decrypt_node; |
| 324 | extern vlib_node_registration_t esp6_encrypt_node; |
| 325 | extern vlib_node_registration_t esp6_decrypt_node; |
| 326 | extern vlib_node_registration_t ah6_encrypt_node; |
| 327 | extern vlib_node_registration_t ah6_decrypt_node; |
Jean-Mickael Guerin | 8941ec2 | 2016-03-04 14:14:21 +0100 | [diff] [blame] | 328 | extern vlib_node_registration_t ipsec_if_input_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 329 | |
| 330 | |
| 331 | /* |
| 332 | * functions |
| 333 | */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 334 | int ipsec_set_interface_spd (vlib_main_t * vm, u32 sw_if_index, u32 spd_id, |
| 335 | int is_add); |
| 336 | int ipsec_add_del_spd (vlib_main_t * vm, u32 spd_id, int is_add); |
| 337 | int ipsec_add_del_policy (vlib_main_t * vm, ipsec_policy_t * policy, |
| 338 | int is_add); |
Radu Nicolau | 717de09 | 2018-08-03 10:37:24 +0100 | [diff] [blame] | 339 | int ipsec_add_del_sa (vlib_main_t * vm, ipsec_sa_t * new_sa, int is_add); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 340 | int ipsec_set_sa_key (vlib_main_t * vm, ipsec_sa_t * sa_update); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 341 | |
Matus Fabian | 694265d | 2016-08-10 01:55:36 -0700 | [diff] [blame] | 342 | u32 ipsec_get_sa_index_by_sa_id (u32 sa_id); |
Matthew Smith | ca514fd | 2017-10-12 12:06:59 -0500 | [diff] [blame] | 343 | u8 ipsec_is_sa_used (u32 sa_index); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 344 | u8 *format_ipsec_policy_action (u8 * s, va_list * args); |
| 345 | u8 *format_ipsec_crypto_alg (u8 * s, va_list * args); |
| 346 | u8 *format_ipsec_integ_alg (u8 * s, va_list * args); |
| 347 | u8 *format_ipsec_replay_window (u8 * s, va_list * args); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 348 | uword unformat_ipsec_policy_action (unformat_input_t * input, va_list * args); |
| 349 | uword unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args); |
| 350 | uword unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args); |
| 351 | |
Matthew Smith | e04d09d | 2017-05-14 21:47:18 -0500 | [diff] [blame] | 352 | int ipsec_add_del_tunnel_if_internal (vnet_main_t * vnm, |
| 353 | ipsec_add_del_tunnel_args_t * args, |
| 354 | u32 * sw_if_index); |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 355 | int ipsec_add_del_tunnel_if (ipsec_add_del_tunnel_args_t * args); |
Matus Fabian | 694265d | 2016-08-10 01:55:36 -0700 | [diff] [blame] | 356 | int ipsec_add_del_ipsec_gre_tunnel (vnet_main_t * vnm, |
| 357 | ipsec_add_del_ipsec_gre_tunnel_args_t * |
| 358 | args); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 359 | int ipsec_set_interface_key (vnet_main_t * vnm, u32 hw_if_index, |
| 360 | ipsec_if_set_key_type_t type, u8 alg, u8 * key); |
Matthew Smith | ca514fd | 2017-10-12 12:06:59 -0500 | [diff] [blame] | 361 | int ipsec_set_interface_sa (vnet_main_t * vnm, u32 hw_if_index, u32 sa_id, |
| 362 | u8 is_outbound); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 363 | |
| 364 | |
| 365 | /* |
| 366 | * inline functions |
| 367 | */ |
| 368 | |
| 369 | always_inline void |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 370 | ipsec_alloc_empty_buffers (vlib_main_t * vm, ipsec_main_t * im) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 371 | { |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 372 | u32 thread_index = vm->thread_index; |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 373 | uword l = vec_len (im->empty_buffers[thread_index]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 374 | uword n_alloc = 0; |
| 375 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 376 | if (PREDICT_FALSE (l < VLIB_FRAME_SIZE)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 377 | { |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 378 | if (!im->empty_buffers[thread_index]) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 379 | { |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 380 | vec_alloc (im->empty_buffers[thread_index], 2 * VLIB_FRAME_SIZE); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 381 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 382 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 383 | n_alloc = vlib_buffer_alloc (vm, im->empty_buffers[thread_index] + l, |
Damjan Marion | 6765549 | 2016-11-15 12:50:28 +0100 | [diff] [blame] | 384 | 2 * VLIB_FRAME_SIZE - l); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 385 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 386 | _vec_len (im->empty_buffers[thread_index]) = l + n_alloc; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
Matus Fabian | 08a6f01 | 2016-11-15 06:08:51 -0800 | [diff] [blame] | 390 | static_always_inline u32 |
| 391 | get_next_output_feature_node_index (vlib_buffer_t * b, |
| 392 | vlib_node_runtime_t * nr) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 393 | { |
Matus Fabian | 08a6f01 | 2016-11-15 06:08:51 -0800 | [diff] [blame] | 394 | u32 next; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 395 | vlib_main_t *vm = vlib_get_main (); |
Matus Fabian | 08a6f01 | 2016-11-15 06:08:51 -0800 | [diff] [blame] | 396 | vlib_node_t *node = vlib_get_node (vm, nr->node_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 397 | |
Damjan Marion | 7d98a12 | 2018-07-19 20:42:08 +0200 | [diff] [blame] | 398 | vnet_feature_next (&next, b); |
Matus Fabian | 08a6f01 | 2016-11-15 06:08:51 -0800 | [diff] [blame] | 399 | return node->next_nodes[next]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 400 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 401 | |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 402 | #endif /* __IPSEC_H__ */ |
| 403 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 404 | /* |
| 405 | * fd.io coding-style-patch-verification: ON |
| 406 | * |
| 407 | * Local Variables: |
| 408 | * eval: (c-set-style "gnu") |
| 409 | * End: |
| 410 | */ |