Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * ipsec_api.c - ipsec api |
| 4 | * |
| 5 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | *------------------------------------------------------------------ |
| 18 | */ |
| 19 | |
| 20 | #include <vnet/vnet.h> |
| 21 | #include <vlibmemory/api.h> |
| 22 | |
| 23 | #include <vnet/interface.h> |
| 24 | #include <vnet/api_errno.h> |
| 25 | #include <vnet/ip/ip.h> |
| 26 | |
| 27 | #include <vnet/vnet_msg_enum.h> |
| 28 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 29 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 30 | #include <vnet/ipsec/ipsec.h> |
| 31 | #include <vnet/ipsec/ikev2.h> |
| 32 | #endif /* IPSEC */ |
| 33 | |
| 34 | #define vl_typedefs /* define message structures */ |
| 35 | #include <vnet/vnet_all_api_h.h> |
| 36 | #undef vl_typedefs |
| 37 | |
| 38 | #define vl_endianfun /* define message structures */ |
| 39 | #include <vnet/vnet_all_api_h.h> |
| 40 | #undef vl_endianfun |
| 41 | |
| 42 | /* instantiate all the print functions we know about */ |
| 43 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 44 | #define vl_printfun |
| 45 | #include <vnet/vnet_all_api_h.h> |
| 46 | #undef vl_printfun |
| 47 | |
| 48 | #include <vlibapi/api_helper_macros.h> |
| 49 | |
| 50 | #define foreach_vpe_api_msg \ |
| 51 | _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \ |
| 52 | _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \ |
| 53 | _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \ |
| 54 | _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \ |
| 55 | _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \ |
| 56 | _(IPSEC_SPD_DUMP, ipsec_spd_dump) \ |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 57 | _(IPSEC_TUNNEL_IF_ADD_DEL, ipsec_tunnel_if_add_del) \ |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 58 | _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \ |
| 59 | _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \ |
| 60 | _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \ |
| 61 | _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \ |
Radu Nicolau | cb33dc2 | 2017-02-16 16:49:46 +0000 | [diff] [blame] | 62 | _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \ |
| 63 | _(IKEV2_SET_RESPONDER, ikev2_set_responder) \ |
| 64 | _(IKEV2_SET_IKE_TRANSFORMS, ikev2_set_ike_transforms) \ |
| 65 | _(IKEV2_SET_ESP_TRANSFORMS, ikev2_set_esp_transforms) \ |
| 66 | _(IKEV2_SET_SA_LIFETIME, ikev2_set_sa_lifetime) \ |
| 67 | _(IKEV2_INITIATE_SA_INIT, ikev2_initiate_sa_init) \ |
| 68 | _(IKEV2_INITIATE_DEL_IKE_SA, ikev2_initiate_del_ike_sa) \ |
| 69 | _(IKEV2_INITIATE_DEL_CHILD_SA, ikev2_initiate_del_child_sa) \ |
| 70 | _(IKEV2_INITIATE_REKEY_CHILD_SA, ikev2_initiate_rekey_child_sa) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 71 | |
| 72 | static void vl_api_ipsec_spd_add_del_t_handler |
| 73 | (vl_api_ipsec_spd_add_del_t * mp) |
| 74 | { |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 75 | #if WITH_LIBSSL == 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 76 | clib_warning ("unimplemented"); |
| 77 | #else |
| 78 | |
| 79 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 80 | vl_api_ipsec_spd_add_del_reply_t *rmp; |
| 81 | int rv; |
| 82 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 83 | rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 84 | |
| 85 | REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY); |
| 86 | #endif |
| 87 | } |
| 88 | |
| 89 | static void vl_api_ipsec_interface_add_del_spd_t_handler |
| 90 | (vl_api_ipsec_interface_add_del_spd_t * mp) |
| 91 | { |
| 92 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 93 | vl_api_ipsec_interface_add_del_spd_reply_t *rmp; |
| 94 | int rv; |
| 95 | u32 sw_if_index __attribute__ ((unused)); |
| 96 | u32 spd_id __attribute__ ((unused)); |
| 97 | |
| 98 | sw_if_index = ntohl (mp->sw_if_index); |
| 99 | spd_id = ntohl (mp->spd_id); |
| 100 | |
| 101 | VALIDATE_SW_IF_INDEX (mp); |
| 102 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 103 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 104 | rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add); |
| 105 | #else |
| 106 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 107 | #endif |
| 108 | |
| 109 | BAD_SW_IF_INDEX_LABEL; |
| 110 | |
| 111 | REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY); |
| 112 | } |
| 113 | |
| 114 | static void vl_api_ipsec_spd_add_del_entry_t_handler |
| 115 | (vl_api_ipsec_spd_add_del_entry_t * mp) |
| 116 | { |
| 117 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 118 | vl_api_ipsec_spd_add_del_entry_reply_t *rmp; |
| 119 | int rv; |
| 120 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 121 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 122 | ipsec_policy_t p; |
| 123 | |
| 124 | memset (&p, 0, sizeof (p)); |
| 125 | |
| 126 | p.id = ntohl (mp->spd_id); |
| 127 | p.priority = ntohl (mp->priority); |
| 128 | p.is_outbound = mp->is_outbound; |
| 129 | p.is_ipv6 = mp->is_ipv6; |
| 130 | |
| 131 | if (mp->is_ipv6 || mp->is_ip_any) |
| 132 | { |
| 133 | clib_memcpy (&p.raddr.start, mp->remote_address_start, 16); |
| 134 | clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16); |
| 135 | clib_memcpy (&p.laddr.start, mp->local_address_start, 16); |
| 136 | clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4); |
| 141 | clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4); |
| 142 | clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4); |
| 143 | clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4); |
| 144 | } |
| 145 | p.protocol = mp->protocol; |
| 146 | p.rport.start = ntohs (mp->remote_port_start); |
| 147 | p.rport.stop = ntohs (mp->remote_port_stop); |
| 148 | p.lport.start = ntohs (mp->local_port_start); |
| 149 | p.lport.stop = ntohs (mp->local_port_stop); |
| 150 | /* policy action resolve unsupported */ |
| 151 | if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) |
| 152 | { |
| 153 | clib_warning ("unsupported action: 'resolve'"); |
| 154 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 155 | goto out; |
| 156 | } |
| 157 | p.policy = mp->policy; |
| 158 | p.sa_id = ntohl (mp->sa_id); |
| 159 | |
| 160 | rv = ipsec_add_del_policy (vm, &p, mp->is_add); |
| 161 | if (rv) |
| 162 | goto out; |
| 163 | |
| 164 | if (mp->is_ip_any) |
| 165 | { |
| 166 | p.is_ipv6 = 1; |
| 167 | rv = ipsec_add_del_policy (vm, &p, mp->is_add); |
| 168 | } |
| 169 | #else |
| 170 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 171 | goto out; |
| 172 | #endif |
| 173 | |
| 174 | out: |
| 175 | REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY); |
| 176 | } |
| 177 | |
| 178 | static void vl_api_ipsec_sad_add_del_entry_t_handler |
| 179 | (vl_api_ipsec_sad_add_del_entry_t * mp) |
| 180 | { |
| 181 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 182 | vl_api_ipsec_sad_add_del_entry_reply_t *rmp; |
| 183 | int rv; |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 184 | #if WITH_LIBSSL > 0 |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 185 | ipsec_main_t *im = &ipsec_main; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 186 | ipsec_sa_t sa; |
| 187 | |
| 188 | memset (&sa, 0, sizeof (sa)); |
| 189 | |
| 190 | sa.id = ntohl (mp->sad_id); |
| 191 | sa.spi = ntohl (mp->spi); |
| 192 | /* security protocol AH unsupported */ |
| 193 | if (mp->protocol == IPSEC_PROTOCOL_AH) |
| 194 | { |
| 195 | clib_warning ("unsupported security protocol 'AH'"); |
| 196 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 197 | goto out; |
| 198 | } |
| 199 | sa.protocol = mp->protocol; |
| 200 | /* check for unsupported crypto-alg */ |
| 201 | if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 || |
| 202 | mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG) |
| 203 | { |
| 204 | clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg, |
| 205 | mp->crypto_algorithm); |
| 206 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 207 | goto out; |
| 208 | } |
| 209 | sa.crypto_alg = mp->crypto_algorithm; |
| 210 | sa.crypto_key_len = mp->crypto_key_length; |
| 211 | clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key)); |
| 212 | /* check for unsupported integ-alg */ |
Pavel Kotucek | 78053e1 | 2017-03-10 10:03:59 +0100 | [diff] [blame] | 213 | if (mp->integrity_algorithm >= IPSEC_INTEG_N_ALG) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 214 | { |
| 215 | clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg, |
| 216 | mp->integrity_algorithm); |
| 217 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 218 | goto out; |
| 219 | } |
| 220 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 221 | sa.integ_alg = mp->integrity_algorithm; |
| 222 | sa.integ_key_len = mp->integrity_key_length; |
| 223 | clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key)); |
| 224 | sa.use_esn = mp->use_extended_sequence_number; |
| 225 | sa.is_tunnel = mp->is_tunnel; |
| 226 | sa.is_tunnel_ip6 = mp->is_tunnel_ipv6; |
| 227 | if (sa.is_tunnel_ip6) |
| 228 | { |
| 229 | clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16); |
| 230 | clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16); |
| 231 | } |
| 232 | else |
| 233 | { |
| 234 | clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4); |
| 235 | clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4); |
| 236 | } |
| 237 | |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 238 | ASSERT (im->cb.check_support_cb); |
| 239 | clib_error_t *err = im->cb.check_support_cb (&sa); |
| 240 | if (err) |
| 241 | { |
| 242 | clib_warning ("%s", err->what); |
| 243 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 244 | goto out; |
| 245 | } |
| 246 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 247 | rv = ipsec_add_del_sa (vm, &sa, mp->is_add); |
| 248 | #else |
| 249 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 250 | goto out; |
| 251 | #endif |
| 252 | |
| 253 | out: |
| 254 | REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY); |
| 255 | } |
| 256 | |
| 257 | static void |
| 258 | send_ipsec_spd_details (ipsec_policy_t * p, unix_shared_memory_queue_t * q, |
| 259 | u32 context) |
| 260 | { |
| 261 | vl_api_ipsec_spd_details_t *mp; |
| 262 | |
| 263 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 264 | memset (mp, 0, sizeof (*mp)); |
| 265 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS); |
| 266 | mp->context = context; |
| 267 | |
| 268 | mp->spd_id = htonl (p->id); |
| 269 | mp->priority = htonl (p->priority); |
| 270 | mp->is_outbound = p->is_outbound; |
| 271 | mp->is_ipv6 = p->is_ipv6; |
| 272 | if (p->is_ipv6) |
| 273 | { |
| 274 | memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16); |
| 275 | memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16); |
| 276 | memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16); |
| 277 | memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16); |
| 278 | } |
| 279 | else |
| 280 | { |
| 281 | memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4); |
| 282 | memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4); |
| 283 | memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4); |
| 284 | memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4); |
| 285 | } |
| 286 | mp->local_start_port = htons (p->lport.start); |
| 287 | mp->local_stop_port = htons (p->lport.stop); |
| 288 | mp->remote_start_port = htons (p->rport.start); |
| 289 | mp->remote_stop_port = htons (p->rport.stop); |
| 290 | mp->protocol = p->protocol; |
| 291 | mp->policy = p->policy; |
| 292 | mp->sa_id = htonl (p->sa_id); |
| 293 | mp->bytes = clib_host_to_net_u64 (p->counter.bytes); |
| 294 | mp->packets = clib_host_to_net_u64 (p->counter.packets); |
| 295 | |
| 296 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 297 | } |
| 298 | |
| 299 | static void |
| 300 | vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp) |
| 301 | { |
| 302 | unix_shared_memory_queue_t *q; |
| 303 | ipsec_main_t *im = &ipsec_main; |
| 304 | ipsec_policy_t *policy; |
| 305 | ipsec_spd_t *spd; |
| 306 | uword *p; |
| 307 | u32 spd_index; |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 308 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 309 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 310 | if (q == 0) |
| 311 | return; |
| 312 | |
| 313 | p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id)); |
| 314 | if (!p) |
| 315 | return; |
| 316 | |
| 317 | spd_index = p[0]; |
| 318 | spd = pool_elt_at_index (im->spds, spd_index); |
| 319 | |
| 320 | /* *INDENT-OFF* */ |
| 321 | pool_foreach (policy, spd->policies, |
| 322 | ({ |
| 323 | if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id) |
| 324 | send_ipsec_spd_details (policy, q, |
| 325 | mp->context);} |
| 326 | )); |
| 327 | /* *INDENT-ON* */ |
| 328 | #else |
| 329 | clib_warning ("unimplemented"); |
| 330 | #endif |
| 331 | } |
| 332 | |
| 333 | static void |
| 334 | vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp) |
| 335 | { |
| 336 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 337 | vl_api_ipsec_sa_set_key_reply_t *rmp; |
| 338 | int rv; |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 339 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 340 | ipsec_sa_t sa; |
| 341 | sa.id = ntohl (mp->sa_id); |
| 342 | sa.crypto_key_len = mp->crypto_key_length; |
| 343 | clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key)); |
| 344 | sa.integ_key_len = mp->integrity_key_length; |
| 345 | clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key)); |
| 346 | |
| 347 | rv = ipsec_set_sa_key (vm, &sa); |
| 348 | #else |
| 349 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 350 | #endif |
| 351 | |
| 352 | REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY); |
| 353 | } |
| 354 | |
| 355 | static void |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 356 | vl_api_ipsec_tunnel_if_add_del_t_handler (vl_api_ipsec_tunnel_if_add_del_t * |
| 357 | mp) |
| 358 | { |
| 359 | vl_api_ipsec_tunnel_if_add_del_reply_t *rmp; |
| 360 | int rv; |
| 361 | |
| 362 | #if WITH_LIBSSL > 0 |
| 363 | ipsec_add_del_tunnel_args_t tun; |
| 364 | |
| 365 | memset (&tun, 0, sizeof (ipsec_add_del_tunnel_args_t)); |
| 366 | |
| 367 | tun.is_add = mp->is_add; |
| 368 | tun.esn = mp->esn; |
| 369 | tun.anti_replay = mp->anti_replay; |
| 370 | tun.local_spi = ntohl (mp->local_spi); |
| 371 | tun.remote_spi = ntohl (mp->remote_spi); |
| 372 | tun.crypto_alg = mp->crypto_alg; |
| 373 | tun.local_crypto_key_len = mp->local_crypto_key_len; |
| 374 | tun.remote_crypto_key_len = mp->remote_crypto_key_len; |
| 375 | tun.integ_alg = mp->integ_alg; |
| 376 | tun.local_integ_key_len = mp->local_integ_key_len; |
| 377 | tun.remote_integ_key_len = mp->remote_integ_key_len; |
| 378 | memcpy (&tun.local_ip, mp->local_ip, 4); |
| 379 | memcpy (&tun.remote_ip, mp->remote_ip, 4); |
| 380 | memcpy (&tun.local_crypto_key, &mp->local_crypto_key, |
| 381 | mp->local_crypto_key_len); |
| 382 | memcpy (&tun.remote_crypto_key, &mp->remote_crypto_key, |
| 383 | mp->remote_crypto_key_len); |
| 384 | memcpy (&tun.local_integ_key, &mp->local_integ_key, |
| 385 | mp->local_integ_key_len); |
| 386 | memcpy (&tun.remote_integ_key, &mp->remote_integ_key, |
| 387 | mp->remote_integ_key_len); |
| 388 | |
| 389 | rv = ipsec_add_del_tunnel_if (&tun); |
| 390 | |
| 391 | #else |
| 392 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 393 | #endif |
| 394 | |
| 395 | REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_ADD_DEL_REPLY); |
| 396 | } |
| 397 | |
| 398 | static void |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 399 | vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp) |
| 400 | { |
| 401 | vl_api_ikev2_profile_add_del_reply_t *rmp; |
| 402 | int rv = 0; |
| 403 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 404 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 405 | vlib_main_t *vm = vlib_get_main (); |
| 406 | clib_error_t *error; |
| 407 | u8 *tmp = format (0, "%s", mp->name); |
| 408 | error = ikev2_add_del_profile (vm, tmp, mp->is_add); |
| 409 | vec_free (tmp); |
| 410 | if (error) |
| 411 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 412 | #else |
| 413 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 414 | #endif |
| 415 | |
| 416 | REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY); |
| 417 | } |
| 418 | |
| 419 | static void |
| 420 | vl_api_ikev2_profile_set_auth_t_handler |
| 421 | (vl_api_ikev2_profile_set_auth_t * mp) |
| 422 | { |
| 423 | vl_api_ikev2_profile_set_auth_reply_t *rmp; |
| 424 | int rv = 0; |
| 425 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 426 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 427 | vlib_main_t *vm = vlib_get_main (); |
| 428 | clib_error_t *error; |
| 429 | u8 *tmp = format (0, "%s", mp->name); |
| 430 | u8 *data = vec_new (u8, mp->data_len); |
| 431 | clib_memcpy (data, mp->data, mp->data_len); |
| 432 | error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex); |
| 433 | vec_free (tmp); |
| 434 | vec_free (data); |
| 435 | if (error) |
| 436 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 437 | #else |
| 438 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 439 | #endif |
| 440 | |
| 441 | REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY); |
| 442 | } |
| 443 | |
| 444 | static void |
| 445 | vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp) |
| 446 | { |
| 447 | vl_api_ikev2_profile_add_del_reply_t *rmp; |
| 448 | int rv = 0; |
| 449 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 450 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 451 | vlib_main_t *vm = vlib_get_main (); |
| 452 | clib_error_t *error; |
| 453 | u8 *tmp = format (0, "%s", mp->name); |
| 454 | u8 *data = vec_new (u8, mp->data_len); |
| 455 | clib_memcpy (data, mp->data, mp->data_len); |
| 456 | error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local); |
| 457 | vec_free (tmp); |
| 458 | vec_free (data); |
| 459 | if (error) |
| 460 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 461 | #else |
| 462 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 463 | #endif |
| 464 | |
| 465 | REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY); |
| 466 | } |
| 467 | |
| 468 | static void |
| 469 | vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp) |
| 470 | { |
| 471 | vl_api_ikev2_profile_set_ts_reply_t *rmp; |
| 472 | int rv = 0; |
| 473 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 474 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 475 | vlib_main_t *vm = vlib_get_main (); |
| 476 | clib_error_t *error; |
| 477 | u8 *tmp = format (0, "%s", mp->name); |
| 478 | error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port, |
| 479 | mp->end_port, (ip4_address_t) mp->start_addr, |
| 480 | (ip4_address_t) mp->end_addr, mp->is_local); |
| 481 | vec_free (tmp); |
| 482 | if (error) |
| 483 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 484 | #else |
| 485 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 486 | #endif |
| 487 | |
| 488 | REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY); |
| 489 | } |
| 490 | |
| 491 | static void |
| 492 | vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp) |
| 493 | { |
| 494 | vl_api_ikev2_profile_set_ts_reply_t *rmp; |
| 495 | int rv = 0; |
| 496 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 497 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 498 | vlib_main_t *vm = vlib_get_main (); |
| 499 | clib_error_t *error; |
| 500 | |
| 501 | error = ikev2_set_local_key (vm, mp->key_file); |
| 502 | if (error) |
| 503 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 504 | #else |
| 505 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 506 | #endif |
| 507 | |
| 508 | REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY); |
| 509 | } |
| 510 | |
Radu Nicolau | cb33dc2 | 2017-02-16 16:49:46 +0000 | [diff] [blame] | 511 | static void |
| 512 | vl_api_ikev2_set_responder_t_handler (vl_api_ikev2_set_responder_t * mp) |
| 513 | { |
| 514 | vl_api_ikev2_set_responder_reply_t *rmp; |
| 515 | int rv = 0; |
| 516 | |
| 517 | #if WITH_LIBSSL > 0 |
| 518 | vlib_main_t *vm = vlib_get_main (); |
| 519 | clib_error_t *error; |
| 520 | |
| 521 | u8 *tmp = format (0, "%s", mp->name); |
| 522 | ip4_address_t ip4; |
| 523 | clib_memcpy (&ip4, mp->address, sizeof (ip4)); |
| 524 | |
| 525 | error = ikev2_set_profile_responder (vm, tmp, mp->sw_if_index, ip4); |
| 526 | vec_free (tmp); |
| 527 | if (error) |
| 528 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 529 | #else |
| 530 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 531 | #endif |
| 532 | |
| 533 | REPLY_MACRO (VL_API_IKEV2_SET_RESPONDER_REPLY); |
| 534 | } |
| 535 | |
| 536 | static void |
| 537 | vl_api_ikev2_set_ike_transforms_t_handler (vl_api_ikev2_set_ike_transforms_t * |
| 538 | mp) |
| 539 | { |
| 540 | vl_api_ikev2_set_ike_transforms_reply_t *rmp; |
| 541 | int rv = 0; |
| 542 | |
| 543 | #if WITH_LIBSSL > 0 |
| 544 | vlib_main_t *vm = vlib_get_main (); |
| 545 | clib_error_t *error; |
| 546 | |
| 547 | u8 *tmp = format (0, "%s", mp->name); |
| 548 | |
| 549 | error = |
| 550 | ikev2_set_profile_ike_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg, |
| 551 | mp->dh_group, mp->crypto_key_size); |
| 552 | vec_free (tmp); |
| 553 | if (error) |
| 554 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 555 | #else |
| 556 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 557 | #endif |
| 558 | |
| 559 | REPLY_MACRO (VL_API_IKEV2_SET_IKE_TRANSFORMS_REPLY); |
| 560 | } |
| 561 | |
| 562 | static void |
| 563 | vl_api_ikev2_set_esp_transforms_t_handler (vl_api_ikev2_set_esp_transforms_t * |
| 564 | mp) |
| 565 | { |
| 566 | vl_api_ikev2_set_esp_transforms_reply_t *rmp; |
| 567 | int rv = 0; |
| 568 | |
| 569 | #if WITH_LIBSSL > 0 |
| 570 | vlib_main_t *vm = vlib_get_main (); |
| 571 | clib_error_t *error; |
| 572 | |
| 573 | u8 *tmp = format (0, "%s", mp->name); |
| 574 | |
| 575 | error = |
| 576 | ikev2_set_profile_esp_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg, |
| 577 | mp->dh_group, mp->crypto_key_size); |
| 578 | vec_free (tmp); |
| 579 | if (error) |
| 580 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 581 | #else |
| 582 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 583 | #endif |
| 584 | |
| 585 | REPLY_MACRO (VL_API_IKEV2_SET_ESP_TRANSFORMS_REPLY); |
| 586 | } |
| 587 | |
| 588 | static void |
| 589 | vl_api_ikev2_set_sa_lifetime_t_handler (vl_api_ikev2_set_sa_lifetime_t * mp) |
| 590 | { |
| 591 | vl_api_ikev2_set_sa_lifetime_reply_t *rmp; |
| 592 | int rv = 0; |
| 593 | |
| 594 | #if WITH_LIBSSL > 0 |
| 595 | vlib_main_t *vm = vlib_get_main (); |
| 596 | clib_error_t *error; |
| 597 | |
| 598 | u8 *tmp = format (0, "%s", mp->name); |
| 599 | |
| 600 | error = |
| 601 | ikev2_set_profile_sa_lifetime (vm, tmp, mp->lifetime, mp->lifetime_jitter, |
| 602 | mp->handover, mp->lifetime_maxdata); |
| 603 | vec_free (tmp); |
| 604 | if (error) |
| 605 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 606 | #else |
| 607 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 608 | #endif |
| 609 | |
| 610 | REPLY_MACRO (VL_API_IKEV2_SET_SA_LIFETIME_REPLY); |
| 611 | } |
| 612 | |
| 613 | static void |
| 614 | vl_api_ikev2_initiate_sa_init_t_handler (vl_api_ikev2_initiate_sa_init_t * mp) |
| 615 | { |
| 616 | vl_api_ikev2_initiate_sa_init_reply_t *rmp; |
| 617 | int rv = 0; |
| 618 | |
| 619 | #if WITH_LIBSSL > 0 |
| 620 | vlib_main_t *vm = vlib_get_main (); |
| 621 | clib_error_t *error; |
| 622 | |
| 623 | u8 *tmp = format (0, "%s", mp->name); |
| 624 | |
| 625 | error = ikev2_initiate_sa_init (vm, tmp); |
| 626 | vec_free (tmp); |
| 627 | if (error) |
| 628 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 629 | #else |
| 630 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 631 | #endif |
| 632 | |
| 633 | REPLY_MACRO (VL_API_IKEV2_INITIATE_SA_INIT_REPLY); |
| 634 | } |
| 635 | |
| 636 | static void |
| 637 | vl_api_ikev2_initiate_del_ike_sa_t_handler (vl_api_ikev2_initiate_del_ike_sa_t |
| 638 | * mp) |
| 639 | { |
| 640 | vl_api_ikev2_initiate_del_ike_sa_reply_t *rmp; |
| 641 | int rv = 0; |
| 642 | |
| 643 | #if WITH_LIBSSL > 0 |
| 644 | vlib_main_t *vm = vlib_get_main (); |
| 645 | clib_error_t *error; |
| 646 | |
| 647 | error = ikev2_initiate_delete_ike_sa (vm, mp->ispi); |
| 648 | if (error) |
| 649 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 650 | #else |
| 651 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 652 | #endif |
| 653 | |
| 654 | REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_IKE_SA_REPLY); |
| 655 | } |
| 656 | |
| 657 | static void |
| 658 | vl_api_ikev2_initiate_del_child_sa_t_handler |
| 659 | (vl_api_ikev2_initiate_del_child_sa_t * mp) |
| 660 | { |
| 661 | vl_api_ikev2_initiate_del_child_sa_reply_t *rmp; |
| 662 | int rv = 0; |
| 663 | |
| 664 | #if WITH_LIBSSL > 0 |
| 665 | vlib_main_t *vm = vlib_get_main (); |
| 666 | clib_error_t *error; |
| 667 | |
| 668 | error = ikev2_initiate_delete_child_sa (vm, mp->ispi); |
| 669 | if (error) |
| 670 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 671 | #else |
| 672 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 673 | #endif |
| 674 | |
| 675 | REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_CHILD_SA_REPLY); |
| 676 | } |
| 677 | |
| 678 | static void |
| 679 | vl_api_ikev2_initiate_rekey_child_sa_t_handler |
| 680 | (vl_api_ikev2_initiate_rekey_child_sa_t * mp) |
| 681 | { |
| 682 | vl_api_ikev2_initiate_rekey_child_sa_reply_t *rmp; |
| 683 | int rv = 0; |
| 684 | |
| 685 | #if WITH_LIBSSL > 0 |
| 686 | vlib_main_t *vm = vlib_get_main (); |
| 687 | clib_error_t *error; |
| 688 | |
| 689 | error = ikev2_initiate_rekey_child_sa (vm, mp->ispi); |
| 690 | if (error) |
| 691 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 692 | #else |
| 693 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 694 | #endif |
| 695 | |
| 696 | REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY); |
| 697 | } |
| 698 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 699 | /* |
| 700 | * ipsec_api_hookup |
| 701 | * Add vpe's API message handlers to the table. |
| 702 | * vlib has alread mapped shared memory and |
| 703 | * added the client registration handlers. |
| 704 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 705 | */ |
| 706 | #define vl_msg_name_crc_list |
| 707 | #include <vnet/vnet_all_api_h.h> |
| 708 | #undef vl_msg_name_crc_list |
| 709 | |
| 710 | static void |
| 711 | setup_message_id_table (api_main_t * am) |
| 712 | { |
| 713 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 714 | foreach_vl_msg_name_crc_ipsec; |
| 715 | #undef _ |
| 716 | } |
| 717 | |
| 718 | static clib_error_t * |
| 719 | ipsec_api_hookup (vlib_main_t * vm) |
| 720 | { |
| 721 | api_main_t *am = &api_main; |
| 722 | |
| 723 | #define _(N,n) \ |
| 724 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 725 | vl_api_##n##_t_handler, \ |
| 726 | vl_noop_handler, \ |
| 727 | vl_api_##n##_t_endian, \ |
| 728 | vl_api_##n##_t_print, \ |
| 729 | sizeof(vl_api_##n##_t), 1); |
| 730 | foreach_vpe_api_msg; |
| 731 | #undef _ |
| 732 | |
| 733 | /* |
| 734 | * Set up the (msg_name, crc, message-id) table |
| 735 | */ |
| 736 | setup_message_id_table (am); |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | VLIB_API_INIT_FUNCTION (ipsec_api_hookup); |
| 742 | |
| 743 | /* |
| 744 | * fd.io coding-style-patch-verification: ON |
| 745 | * |
| 746 | * Local Variables: |
| 747 | * eval: (c-set-style "gnu") |
| 748 | * End: |
| 749 | */ |