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 | |
Matus Fabian | 694265d | 2016-08-10 01:55:36 -0700 | [diff] [blame] | 18 | #define IPSEC_FLAG_IPSEC_GRE_TUNNEL (1 << 0) |
| 19 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | #define foreach_ipsec_policy_action \ |
| 21 | _(0, BYPASS, "bypass") \ |
| 22 | _(1, DISCARD, "discard") \ |
| 23 | _(2, RESOLVE, "resolve") \ |
| 24 | _(3, PROTECT, "protect") |
| 25 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 26 | typedef enum |
| 27 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 28 | #define _(v,f,s) IPSEC_POLICY_ACTION_##f = v, |
| 29 | foreach_ipsec_policy_action |
| 30 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 31 | IPSEC_POLICY_N_ACTION, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | } ipsec_policy_action_t; |
| 33 | |
Radu Nicolau | 6929ea9 | 2016-11-29 11:00:30 +0000 | [diff] [blame^] | 34 | #if DPDK_CRYPTO==1 |
| 35 | #define foreach_ipsec_crypto_alg \ |
| 36 | _(0, NONE, "none") \ |
| 37 | _(1, AES_CBC_128, "aes-cbc-128") \ |
| 38 | _(2, AES_CBC_192, "aes-cbc-192") \ |
| 39 | _(3, AES_CBC_256, "aes-cbc-256") \ |
| 40 | _(4, AES_GCM_128, "aes-gcm-128") |
| 41 | #else |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 42 | #define foreach_ipsec_crypto_alg \ |
| 43 | _(0, NONE, "none") \ |
| 44 | _(1, AES_CBC_128, "aes-cbc-128") \ |
| 45 | _(2, AES_CBC_192, "aes-cbc-192") \ |
| 46 | _(3, AES_CBC_256, "aes-cbc-256") |
Radu Nicolau | 6929ea9 | 2016-11-29 11:00:30 +0000 | [diff] [blame^] | 47 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 49 | typedef enum |
| 50 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | #define _(v,f,s) IPSEC_CRYPTO_ALG_##f = v, |
| 52 | foreach_ipsec_crypto_alg |
| 53 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 54 | IPSEC_CRYPTO_N_ALG, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | } ipsec_crypto_alg_t; |
| 56 | |
Radu Nicolau | 6929ea9 | 2016-11-29 11:00:30 +0000 | [diff] [blame^] | 57 | #if DPDK_CRYPTO==1 |
| 58 | #define foreach_ipsec_integ_alg \ |
| 59 | _(0, NONE, "none") \ |
| 60 | _(1, MD5_96, "md5-96") /* RFC2403 */ \ |
| 61 | _(2, SHA1_96, "sha1-96") /* RFC2404 */ \ |
| 62 | _(3, SHA_256_96, "sha-256-96") /* draft-ietf-ipsec-ciph-sha-256-00 */ \ |
| 63 | _(4, SHA_256_128, "sha-256-128") /* RFC4868 */ \ |
| 64 | _(5, SHA_384_192, "sha-384-192") /* RFC4868 */ \ |
| 65 | _(6, SHA_512_256, "sha-512-256") /* RFC4868 */ \ |
| 66 | _(7, AES_GCM_128, "aes-gcm-128") |
| 67 | #else |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | #define foreach_ipsec_integ_alg \ |
| 69 | _(0, NONE, "none") \ |
| 70 | _(1, MD5_96, "md5-96") /* RFC2403 */ \ |
| 71 | _(2, SHA1_96, "sha1-96") /* RFC2404 */ \ |
| 72 | _(3, SHA_256_96, "sha-256-96") /* draft-ietf-ipsec-ciph-sha-256-00 */ \ |
| 73 | _(4, SHA_256_128, "sha-256-128") /* RFC4868 */ \ |
| 74 | _(5, SHA_384_192, "sha-384-192") /* RFC4868 */ \ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 75 | _(6, SHA_512_256, "sha-512-256") /* RFC4868 */ |
Radu Nicolau | 6929ea9 | 2016-11-29 11:00:30 +0000 | [diff] [blame^] | 76 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 78 | typedef enum |
| 79 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | #define _(v,f,s) IPSEC_INTEG_ALG_##f = v, |
| 81 | foreach_ipsec_integ_alg |
| 82 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 83 | IPSEC_INTEG_N_ALG, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | } ipsec_integ_alg_t; |
| 85 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 86 | typedef enum |
| 87 | { |
| 88 | IPSEC_PROTOCOL_AH = 0, |
| 89 | IPSEC_PROTOCOL_ESP = 1 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 90 | } ipsec_protocol_t; |
| 91 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 92 | typedef struct |
| 93 | { |
| 94 | u32 id; |
| 95 | u32 spi; |
| 96 | ipsec_protocol_t protocol; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 97 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 98 | ipsec_crypto_alg_t crypto_alg; |
| 99 | u8 crypto_key_len; |
| 100 | u8 crypto_key[128]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 102 | ipsec_integ_alg_t integ_alg; |
| 103 | u8 integ_key_len; |
| 104 | u8 integ_key[128]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 106 | u8 use_esn; |
| 107 | u8 use_anti_replay; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 108 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 109 | u8 is_tunnel; |
| 110 | u8 is_tunnel_ip6; |
| 111 | ip46_address_t tunnel_src_addr; |
| 112 | ip46_address_t tunnel_dst_addr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | |
Radu Nicolau | 6929ea9 | 2016-11-29 11:00:30 +0000 | [diff] [blame^] | 114 | u32 salt; |
| 115 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 116 | /* runtime */ |
| 117 | u32 seq; |
| 118 | u32 seq_hi; |
| 119 | u32 last_seq; |
| 120 | u32 last_seq_hi; |
| 121 | u64 replay_window; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 122 | } ipsec_sa_t; |
| 123 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 124 | typedef struct |
| 125 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 126 | ip46_address_t start, stop; |
| 127 | } ip46_address_range_t; |
| 128 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 129 | typedef struct |
| 130 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 131 | u16 start, stop; |
| 132 | } port_range_t; |
| 133 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 134 | typedef struct |
| 135 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 136 | u8 is_add; |
| 137 | u8 esn; |
| 138 | u8 anti_replay; |
| 139 | ip4_address_t local_ip, remote_ip; |
| 140 | u32 local_spi; |
| 141 | u32 remote_spi; |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 142 | ipsec_crypto_alg_t crypto_alg; |
| 143 | u8 local_crypto_key_len; |
| 144 | u8 local_crypto_key[128]; |
| 145 | u8 remote_crypto_key_len; |
| 146 | u8 remote_crypto_key[128]; |
| 147 | ipsec_integ_alg_t integ_alg; |
| 148 | u8 local_integ_key_len; |
| 149 | u8 local_integ_key[128]; |
| 150 | u8 remote_integ_key_len; |
| 151 | u8 remote_integ_key[128]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 152 | } ipsec_add_del_tunnel_args_t; |
| 153 | |
Matus Fabian | 694265d | 2016-08-10 01:55:36 -0700 | [diff] [blame] | 154 | typedef struct |
| 155 | { |
| 156 | u8 is_add; |
| 157 | u32 local_sa_id; |
| 158 | u32 remote_sa_id; |
| 159 | ip4_address_t local_ip; |
| 160 | ip4_address_t remote_ip; |
| 161 | } ipsec_add_del_ipsec_gre_tunnel_args_t; |
| 162 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 163 | typedef enum |
| 164 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 165 | IPSEC_IF_SET_KEY_TYPE_NONE, |
| 166 | IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO, |
| 167 | IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO, |
| 168 | IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG, |
| 169 | IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG, |
| 170 | } ipsec_if_set_key_type_t; |
| 171 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 172 | typedef struct |
| 173 | { |
| 174 | u32 id; |
| 175 | i32 priority; |
| 176 | u8 is_outbound; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 177 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 178 | // Selector |
| 179 | u8 is_ipv6; |
| 180 | ip46_address_range_t laddr; |
| 181 | ip46_address_range_t raddr; |
| 182 | u8 protocol; |
| 183 | port_range_t lport; |
| 184 | port_range_t rport; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 185 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 186 | // Policy |
| 187 | u8 policy; |
| 188 | u32 sa_id; |
| 189 | u32 sa_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 190 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 191 | // Counter |
| 192 | vlib_counter_t counter; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | } ipsec_policy_t; |
| 194 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 195 | typedef struct |
| 196 | { |
| 197 | u32 id; |
| 198 | /* pool of policies */ |
| 199 | ipsec_policy_t *policies; |
| 200 | /* vectors of policy indices */ |
| 201 | u32 *ipv4_outbound_policies; |
| 202 | u32 *ipv6_outbound_policies; |
| 203 | u32 *ipv4_inbound_protect_policy_indices; |
| 204 | u32 *ipv4_inbound_policy_discard_and_bypass_indices; |
| 205 | u32 *ipv6_inbound_protect_policy_indices; |
| 206 | u32 *ipv6_inbound_policy_discard_and_bypass_indices; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 207 | } ipsec_spd_t; |
| 208 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 209 | typedef struct |
| 210 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 211 | u32 spd_index; |
| 212 | } ip4_ipsec_config_t; |
| 213 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 214 | typedef struct |
| 215 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 216 | u32 spd_index; |
| 217 | } ip6_ipsec_config_t; |
| 218 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 219 | typedef struct |
| 220 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 221 | u32 input_sa_index; |
| 222 | u32 output_sa_index; |
| 223 | u32 hw_if_index; |
| 224 | } ipsec_tunnel_if_t; |
| 225 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 226 | typedef struct |
| 227 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | /* pool of tunnel instances */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 229 | ipsec_spd_t *spds; |
| 230 | ipsec_sa_t *sad; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 231 | |
| 232 | /* pool of tunnel interfaces */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 233 | ipsec_tunnel_if_t *tunnel_interfaces; |
| 234 | u32 *free_tunnel_if_indices; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 235 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 236 | u32 **empty_buffers; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 237 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 238 | uword *tunnel_index_by_key; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 239 | |
| 240 | /* convenience */ |
| 241 | vlib_main_t *vlib_main; |
| 242 | vnet_main_t *vnet_main; |
| 243 | |
| 244 | /* next node indices */ |
| 245 | u32 feature_next_node_index[32]; |
| 246 | |
| 247 | /* hashes */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 248 | uword *spd_index_by_spd_id; |
| 249 | uword *spd_index_by_sw_if_index; |
| 250 | uword *sa_index_by_sa_id; |
| 251 | uword *ipsec_if_pool_index_by_key; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 252 | |
| 253 | /* node indexes */ |
| 254 | u32 error_drop_node_index; |
| 255 | u32 ip4_lookup_node_index; |
| 256 | u32 esp_encrypt_node_index; |
| 257 | |
| 258 | } ipsec_main_t; |
| 259 | |
| 260 | ipsec_main_t ipsec_main; |
| 261 | |
Jean-Mickael Guerin | 8941ec2 | 2016-03-04 14:14:21 +0100 | [diff] [blame] | 262 | extern vlib_node_registration_t esp_encrypt_node; |
| 263 | extern vlib_node_registration_t esp_decrypt_node; |
| 264 | extern vlib_node_registration_t ipsec_if_output_node; |
| 265 | extern vlib_node_registration_t ipsec_if_input_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 266 | |
| 267 | |
| 268 | /* |
| 269 | * functions |
| 270 | */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 271 | int ipsec_set_interface_spd (vlib_main_t * vm, u32 sw_if_index, u32 spd_id, |
| 272 | int is_add); |
| 273 | int ipsec_add_del_spd (vlib_main_t * vm, u32 spd_id, int is_add); |
| 274 | int ipsec_add_del_policy (vlib_main_t * vm, ipsec_policy_t * policy, |
| 275 | int is_add); |
| 276 | int ipsec_add_del_sa (vlib_main_t * vm, ipsec_sa_t * new_sa, int is_add); |
| 277 | 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] | 278 | |
Matus Fabian | 694265d | 2016-08-10 01:55:36 -0700 | [diff] [blame] | 279 | u32 ipsec_get_sa_index_by_sa_id (u32 sa_id); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 280 | u8 *format_ipsec_if_output_trace (u8 * s, va_list * args); |
| 281 | u8 *format_ipsec_policy_action (u8 * s, va_list * args); |
| 282 | u8 *format_ipsec_crypto_alg (u8 * s, va_list * args); |
| 283 | u8 *format_ipsec_integ_alg (u8 * s, va_list * args); |
| 284 | u8 *format_ipsec_replay_window (u8 * s, va_list * args); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 285 | uword unformat_ipsec_policy_action (unformat_input_t * input, va_list * args); |
| 286 | uword unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args); |
| 287 | uword unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args); |
| 288 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 289 | /*u32 ipsec_add_del_tunnel_if (vnet_main_t * vnm, ipsec_add_del_tunnel_args_t * args); */ |
| 290 | 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] | 291 | int ipsec_add_del_ipsec_gre_tunnel (vnet_main_t * vnm, |
| 292 | ipsec_add_del_ipsec_gre_tunnel_args_t * |
| 293 | args); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 294 | int ipsec_set_interface_key (vnet_main_t * vnm, u32 hw_if_index, |
| 295 | ipsec_if_set_key_type_t type, u8 alg, u8 * key); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 296 | |
| 297 | |
| 298 | /* |
| 299 | * inline functions |
| 300 | */ |
| 301 | |
| 302 | always_inline void |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 303 | ipsec_alloc_empty_buffers (vlib_main_t * vm, ipsec_main_t * im) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 304 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 305 | u32 cpu_index = os_get_cpu_number (); |
Matthew Smith | 29d8510 | 2016-05-01 14:52:08 -0500 | [diff] [blame] | 306 | uword l = vec_len (im->empty_buffers[cpu_index]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 307 | uword n_alloc = 0; |
| 308 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 309 | if (PREDICT_FALSE (l < VLIB_FRAME_SIZE)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 310 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 311 | if (!im->empty_buffers[cpu_index]) |
| 312 | { |
| 313 | vec_alloc (im->empty_buffers[cpu_index], 2 * VLIB_FRAME_SIZE); |
| 314 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 315 | |
Damjan Marion | 6765549 | 2016-11-15 12:50:28 +0100 | [diff] [blame] | 316 | n_alloc = vlib_buffer_alloc (vm, im->empty_buffers[cpu_index] + l, |
| 317 | 2 * VLIB_FRAME_SIZE - l); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 318 | |
Matthew Smith | 29d8510 | 2016-05-01 14:52:08 -0500 | [diff] [blame] | 319 | _vec_len (im->empty_buffers[cpu_index]) = l + n_alloc; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
Matus Fabian | 08a6f01 | 2016-11-15 06:08:51 -0800 | [diff] [blame] | 323 | static_always_inline u32 |
| 324 | get_next_output_feature_node_index (vlib_buffer_t * b, |
| 325 | vlib_node_runtime_t * nr) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 326 | { |
Matus Fabian | 08a6f01 | 2016-11-15 06:08:51 -0800 | [diff] [blame] | 327 | u32 next; |
| 328 | u32 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_TX]; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 329 | vlib_main_t *vm = vlib_get_main (); |
Matus Fabian | 08a6f01 | 2016-11-15 06:08:51 -0800 | [diff] [blame] | 330 | vlib_node_t *node = vlib_get_node (vm, nr->node_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 331 | |
Matus Fabian | 08a6f01 | 2016-11-15 06:08:51 -0800 | [diff] [blame] | 332 | vnet_feature_next (sw_if_index, &next, b); |
| 333 | return node->next_nodes[next]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 334 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 335 | |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 336 | #endif /* __IPSEC_H__ */ |
| 337 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 338 | /* |
| 339 | * fd.io coding-style-patch-verification: ON |
| 340 | * |
| 341 | * Local Variables: |
| 342 | * eval: (c-set-style "gnu") |
| 343 | * End: |
| 344 | */ |