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