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> |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 26 | #include <vnet/ip/ip_types_api.h> |
Pierre Pfister | 4c422f9 | 2018-12-10 11:19:08 +0100 | [diff] [blame] | 27 | #include <vnet/fib/fib.h> |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 28 | |
| 29 | #include <vnet/vnet_msg_enum.h> |
| 30 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 31 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 32 | #include <vnet/ipsec/ipsec.h> |
| 33 | #include <vnet/ipsec/ikev2.h> |
| 34 | #endif /* IPSEC */ |
| 35 | |
| 36 | #define vl_typedefs /* define message structures */ |
| 37 | #include <vnet/vnet_all_api_h.h> |
| 38 | #undef vl_typedefs |
| 39 | |
| 40 | #define vl_endianfun /* define message structures */ |
| 41 | #include <vnet/vnet_all_api_h.h> |
| 42 | #undef vl_endianfun |
| 43 | |
| 44 | /* instantiate all the print functions we know about */ |
| 45 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 46 | #define vl_printfun |
| 47 | #include <vnet/vnet_all_api_h.h> |
| 48 | #undef vl_printfun |
| 49 | |
| 50 | #include <vlibapi/api_helper_macros.h> |
| 51 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 52 | #define foreach_vpe_api_msg \ |
| 53 | _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \ |
| 54 | _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \ |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 55 | _(IPSEC_SPD_ENTRY_ADD_DEL, ipsec_spd_entry_add_del) \ |
| 56 | _(IPSEC_SAD_ENTRY_ADD_DEL, ipsec_sad_entry_add_del) \ |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 57 | _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \ |
| 58 | _(IPSEC_SA_DUMP, ipsec_sa_dump) \ |
| 59 | _(IPSEC_SPDS_DUMP, ipsec_spds_dump) \ |
| 60 | _(IPSEC_SPD_DUMP, ipsec_spd_dump) \ |
| 61 | _(IPSEC_SPD_INTERFACE_DUMP, ipsec_spd_interface_dump) \ |
| 62 | _(IPSEC_TUNNEL_IF_ADD_DEL, ipsec_tunnel_if_add_del) \ |
| 63 | _(IPSEC_TUNNEL_IF_SET_KEY, ipsec_tunnel_if_set_key) \ |
| 64 | _(IPSEC_TUNNEL_IF_SET_SA, ipsec_tunnel_if_set_sa) \ |
| 65 | _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \ |
| 66 | _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \ |
| 67 | _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \ |
| 68 | _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \ |
| 69 | _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \ |
| 70 | _(IKEV2_SET_RESPONDER, ikev2_set_responder) \ |
| 71 | _(IKEV2_SET_IKE_TRANSFORMS, ikev2_set_ike_transforms) \ |
| 72 | _(IKEV2_SET_ESP_TRANSFORMS, ikev2_set_esp_transforms) \ |
| 73 | _(IKEV2_SET_SA_LIFETIME, ikev2_set_sa_lifetime) \ |
| 74 | _(IKEV2_INITIATE_SA_INIT, ikev2_initiate_sa_init) \ |
| 75 | _(IKEV2_INITIATE_DEL_IKE_SA, ikev2_initiate_del_ike_sa) \ |
| 76 | _(IKEV2_INITIATE_DEL_CHILD_SA, ikev2_initiate_del_child_sa) \ |
| 77 | _(IKEV2_INITIATE_REKEY_CHILD_SA, ikev2_initiate_rekey_child_sa) \ |
| 78 | _(IPSEC_SELECT_BACKEND, ipsec_select_backend) \ |
| 79 | _(IPSEC_BACKEND_DUMP, ipsec_backend_dump) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 80 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 81 | static void |
| 82 | vl_api_ipsec_spd_add_del_t_handler (vl_api_ipsec_spd_add_del_t * mp) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 83 | { |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 84 | #if WITH_LIBSSL == 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 85 | clib_warning ("unimplemented"); |
| 86 | #else |
| 87 | |
| 88 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 89 | vl_api_ipsec_spd_add_del_reply_t *rmp; |
| 90 | int rv; |
| 91 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 92 | 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] | 93 | |
| 94 | REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY); |
| 95 | #endif |
| 96 | } |
| 97 | |
| 98 | static void vl_api_ipsec_interface_add_del_spd_t_handler |
| 99 | (vl_api_ipsec_interface_add_del_spd_t * mp) |
| 100 | { |
| 101 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 102 | vl_api_ipsec_interface_add_del_spd_reply_t *rmp; |
| 103 | int rv; |
| 104 | u32 sw_if_index __attribute__ ((unused)); |
| 105 | u32 spd_id __attribute__ ((unused)); |
| 106 | |
| 107 | sw_if_index = ntohl (mp->sw_if_index); |
| 108 | spd_id = ntohl (mp->spd_id); |
| 109 | |
| 110 | VALIDATE_SW_IF_INDEX (mp); |
| 111 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 112 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 113 | rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add); |
| 114 | #else |
| 115 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 116 | #endif |
| 117 | |
| 118 | BAD_SW_IF_INDEX_LABEL; |
| 119 | |
| 120 | REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY); |
| 121 | } |
| 122 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 123 | static int |
| 124 | ipsec_spd_action_decode (vl_api_ipsec_spd_action_t in, |
| 125 | ipsec_policy_action_t * out) |
| 126 | { |
| 127 | in = clib_net_to_host_u32 (in); |
| 128 | |
| 129 | switch (in) |
| 130 | { |
| 131 | #define _(v,f,s) case IPSEC_API_SPD_ACTION_##f: \ |
| 132 | *out = IPSEC_POLICY_ACTION_##f; \ |
| 133 | return (0); |
| 134 | foreach_ipsec_policy_action |
| 135 | #undef _ |
| 136 | } |
| 137 | return (VNET_API_ERROR_UNIMPLEMENTED); |
| 138 | } |
| 139 | |
| 140 | static void vl_api_ipsec_spd_entry_add_del_t_handler |
| 141 | (vl_api_ipsec_spd_entry_add_del_t * mp) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 142 | { |
| 143 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 144 | vl_api_ipsec_spd_entry_add_del_reply_t *rmp; |
| 145 | ip46_type_t itype; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame^] | 146 | u32 stat_index; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 147 | int rv; |
| 148 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 149 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 150 | ipsec_policy_t p; |
| 151 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 152 | clib_memset (&p, 0, sizeof (p)); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 153 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 154 | p.id = ntohl (mp->entry.spd_id); |
| 155 | p.priority = ntohl (mp->entry.priority); |
| 156 | p.is_outbound = mp->entry.is_outbound; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 157 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 158 | itype = ip_address_decode (&mp->entry.remote_address_start, &p.raddr.start); |
| 159 | ip_address_decode (&mp->entry.remote_address_stop, &p.raddr.stop); |
| 160 | ip_address_decode (&mp->entry.local_address_start, &p.laddr.start); |
| 161 | ip_address_decode (&mp->entry.local_address_stop, &p.laddr.stop); |
| 162 | |
| 163 | p.is_ipv6 = (itype == IP46_TYPE_IP6); |
| 164 | |
| 165 | p.protocol = mp->entry.protocol; |
| 166 | p.rport.start = ntohs (mp->entry.remote_port_start); |
| 167 | p.rport.stop = ntohs (mp->entry.remote_port_stop); |
| 168 | p.lport.start = ntohs (mp->entry.local_port_start); |
| 169 | p.lport.stop = ntohs (mp->entry.local_port_stop); |
| 170 | |
| 171 | rv = ipsec_spd_action_decode (mp->entry.policy, &p.policy); |
| 172 | |
| 173 | if (rv) |
| 174 | goto out; |
| 175 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 176 | /* policy action resolve unsupported */ |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 177 | if (p.policy == IPSEC_POLICY_ACTION_RESOLVE) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 178 | { |
| 179 | clib_warning ("unsupported action: 'resolve'"); |
| 180 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 181 | goto out; |
| 182 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 183 | p.sa_id = ntohl (mp->entry.sa_id); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 184 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame^] | 185 | rv = ipsec_add_del_policy (vm, &p, mp->is_add, &stat_index); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 186 | if (rv) |
| 187 | goto out; |
| 188 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 189 | #else |
| 190 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 191 | goto out; |
| 192 | #endif |
| 193 | |
| 194 | out: |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame^] | 195 | /* *INDENT-OFF* */ |
| 196 | REPLY_MACRO2 (VL_API_IPSEC_SPD_ENTRY_ADD_DEL_REPLY, |
| 197 | ({ |
| 198 | rmp->stat_index = ntohl(stat_index); |
| 199 | })); |
| 200 | /* *INDENT-ON* */ |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 203 | static int |
| 204 | ipsec_proto_decode (vl_api_ipsec_proto_t in, ipsec_protocol_t * out) |
| 205 | { |
| 206 | in = clib_net_to_host_u32 (in); |
| 207 | |
| 208 | switch (in) |
| 209 | { |
| 210 | case IPSEC_API_PROTO_ESP: |
| 211 | *out = IPSEC_PROTOCOL_ESP; |
| 212 | return (0); |
| 213 | case IPSEC_API_PROTO_AH: |
| 214 | *out = IPSEC_PROTOCOL_AH; |
| 215 | return (0); |
| 216 | } |
| 217 | return (VNET_API_ERROR_UNIMPLEMENTED); |
| 218 | } |
| 219 | |
| 220 | static int |
| 221 | ipsec_crypto_algo_decode (vl_api_ipsec_crypto_alg_t in, |
| 222 | ipsec_crypto_alg_t * out) |
| 223 | { |
| 224 | in = clib_net_to_host_u32 (in); |
| 225 | |
| 226 | switch (in) |
| 227 | { |
| 228 | #define _(v,f,s) case IPSEC_API_CRYPTO_ALG_##f: \ |
| 229 | *out = IPSEC_CRYPTO_ALG_##f; \ |
| 230 | return (0); |
| 231 | foreach_ipsec_crypto_alg |
| 232 | #undef _ |
| 233 | } |
| 234 | return (VNET_API_ERROR_UNIMPLEMENTED); |
| 235 | } |
| 236 | |
| 237 | static int |
| 238 | ipsec_integ_algo_decode (vl_api_ipsec_integ_alg_t in, ipsec_integ_alg_t * out) |
| 239 | { |
| 240 | in = clib_net_to_host_u32 (in); |
| 241 | |
| 242 | switch (in) |
| 243 | { |
| 244 | #define _(v,f,s) case IPSEC_API_INTEG_ALG_##f: \ |
| 245 | *out = IPSEC_INTEG_ALG_##f; \ |
| 246 | return (0); |
| 247 | foreach_ipsec_integ_alg |
| 248 | #undef _ |
| 249 | } |
| 250 | return (VNET_API_ERROR_UNIMPLEMENTED); |
| 251 | } |
| 252 | |
| 253 | static void |
| 254 | vl_api_ipsec_key_decode (const vl_api_key_t * key, u8 * len, u8 out[128]) |
| 255 | { |
| 256 | *len = key->length; |
| 257 | clib_memcpy (out, key->data, key->length); |
| 258 | } |
| 259 | |
| 260 | static void |
| 261 | vl_api_ipsec_sad_flags_decode (vl_api_ipsec_sad_flags_t in, ipsec_sa_t * sa) |
| 262 | { |
| 263 | in = clib_net_to_host_u32 (in); |
| 264 | |
| 265 | if (in & IPSEC_API_SAD_FLAG_USE_EXTENDED_SEQ_NUM) |
| 266 | sa->use_esn = 1; |
| 267 | if (in & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY) |
| 268 | sa->use_anti_replay = 1; |
| 269 | if (in & IPSEC_API_SAD_FLAG_IS_TUNNEL) |
| 270 | sa->is_tunnel = 1; |
| 271 | if (in & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6) |
| 272 | sa->is_tunnel_ip6 = 1; |
| 273 | if (in & IPSEC_API_SAD_FLAG_UDP_ENCAP) |
| 274 | sa->udp_encap = 1; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | static void vl_api_ipsec_sad_entry_add_del_t_handler |
| 279 | (vl_api_ipsec_sad_entry_add_del_t * mp) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 280 | { |
| 281 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 282 | vl_api_ipsec_sad_entry_add_del_reply_t *rmp; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 283 | int rv; |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 284 | #if WITH_LIBSSL > 0 |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 285 | ipsec_main_t *im = &ipsec_main; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 286 | ipsec_sa_t sa; |
| 287 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 288 | clib_memset (&sa, 0, sizeof (sa)); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 289 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 290 | sa.id = ntohl (mp->entry.sad_id); |
| 291 | sa.spi = ntohl (mp->entry.spi); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 292 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 293 | rv = ipsec_proto_decode (mp->entry.protocol, &sa.protocol); |
| 294 | |
| 295 | if (rv) |
| 296 | goto out; |
| 297 | |
| 298 | rv = ipsec_crypto_algo_decode (mp->entry.crypto_algorithm, &sa.crypto_alg); |
| 299 | |
| 300 | if (rv) |
| 301 | goto out; |
| 302 | |
| 303 | rv = ipsec_integ_algo_decode (mp->entry.integrity_algorithm, &sa.integ_alg); |
| 304 | |
| 305 | if (rv) |
| 306 | goto out; |
| 307 | |
| 308 | vl_api_ipsec_key_decode (&mp->entry.crypto_key, |
| 309 | &sa.crypto_key_len, sa.crypto_key); |
| 310 | vl_api_ipsec_key_decode (&mp->entry.integrity_key, |
| 311 | &sa.integ_key_len, sa.integ_key); |
| 312 | |
| 313 | vl_api_ipsec_sad_flags_decode (mp->entry.flags, &sa); |
| 314 | |
| 315 | if (sa.is_tunnel_ip6 || sa.is_tunnel) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 316 | { |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 317 | ip_address_decode (&mp->entry.tunnel_src, &sa.tunnel_src_addr); |
| 318 | ip_address_decode (&mp->entry.tunnel_dst, &sa.tunnel_dst_addr); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 319 | } |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 320 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 321 | clib_error_t *err = ipsec_check_support_cb (im, &sa); |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 322 | if (err) |
| 323 | { |
| 324 | clib_warning ("%s", err->what); |
| 325 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 326 | goto out; |
| 327 | } |
| 328 | |
Radu Nicolau | 717de09 | 2018-08-03 10:37:24 +0100 | [diff] [blame] | 329 | rv = ipsec_add_del_sa (vm, &sa, mp->is_add); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 330 | #else |
| 331 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 332 | goto out; |
| 333 | #endif |
| 334 | |
| 335 | out: |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 336 | REPLY_MACRO (VL_API_IPSEC_SAD_ENTRY_ADD_DEL_REPLY); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static void |
Matus Fabian | a9a0b2c | 2018-10-02 01:13:25 -0700 | [diff] [blame] | 340 | send_ipsec_spds_details (ipsec_spd_t * spd, vl_api_registration_t * reg, |
| 341 | u32 context) |
| 342 | { |
| 343 | vl_api_ipsec_spds_details_t *mp; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame^] | 344 | u32 n_policies = 0; |
Matus Fabian | a9a0b2c | 2018-10-02 01:13:25 -0700 | [diff] [blame] | 345 | |
| 346 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 347 | clib_memset (mp, 0, sizeof (*mp)); |
Matus Fabian | a9a0b2c | 2018-10-02 01:13:25 -0700 | [diff] [blame] | 348 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPDS_DETAILS); |
| 349 | mp->context = context; |
| 350 | |
| 351 | mp->spd_id = htonl (spd->id); |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame^] | 352 | #define _(s, n) n_policies += vec_len (spd->policies[IPSEC_SPD_POLICY_##s]); |
| 353 | foreach_ipsec_spd_policy_type |
| 354 | #undef _ |
| 355 | mp->npolicies = htonl (n_policies); |
Matus Fabian | a9a0b2c | 2018-10-02 01:13:25 -0700 | [diff] [blame] | 356 | |
| 357 | vl_api_send_msg (reg, (u8 *) mp); |
| 358 | } |
| 359 | |
| 360 | static void |
| 361 | vl_api_ipsec_spds_dump_t_handler (vl_api_ipsec_spds_dump_t * mp) |
| 362 | { |
| 363 | vl_api_registration_t *reg; |
| 364 | ipsec_main_t *im = &ipsec_main; |
| 365 | ipsec_spd_t *spd; |
| 366 | #if WITH_LIBSSL > 0 |
| 367 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 368 | if (!reg) |
| 369 | return; |
| 370 | |
| 371 | /* *INDENT-OFF* */ |
| 372 | pool_foreach (spd, im->spds, ({ |
| 373 | send_ipsec_spds_details (spd, reg, mp->context); |
| 374 | })); |
| 375 | /* *INDENT-ON* */ |
| 376 | #else |
| 377 | clib_warning ("unimplemented"); |
| 378 | #endif |
| 379 | } |
| 380 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 381 | vl_api_ipsec_spd_action_t |
| 382 | ipsec_spd_action_encode (ipsec_policy_action_t in) |
| 383 | { |
| 384 | vl_api_ipsec_spd_action_t out = IPSEC_API_SPD_ACTION_BYPASS; |
| 385 | |
| 386 | switch (in) |
| 387 | { |
| 388 | #define _(v,f,s) case IPSEC_POLICY_ACTION_##f: \ |
| 389 | out = IPSEC_API_SPD_ACTION_##f; \ |
| 390 | break; |
| 391 | foreach_ipsec_policy_action |
| 392 | #undef _ |
| 393 | } |
| 394 | return (clib_host_to_net_u32 (out)); |
| 395 | } |
| 396 | |
Matus Fabian | a9a0b2c | 2018-10-02 01:13:25 -0700 | [diff] [blame] | 397 | static void |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 398 | send_ipsec_spd_details (ipsec_policy_t * p, vl_api_registration_t * reg, |
| 399 | u32 context) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 400 | { |
| 401 | vl_api_ipsec_spd_details_t *mp; |
| 402 | |
| 403 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 404 | clib_memset (mp, 0, sizeof (*mp)); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 405 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS); |
| 406 | mp->context = context; |
| 407 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 408 | mp->entry.spd_id = htonl (p->id); |
| 409 | mp->entry.priority = htonl (p->priority); |
| 410 | mp->entry.is_outbound = p->is_outbound; |
| 411 | |
| 412 | ip_address_encode (&p->laddr.start, IP46_TYPE_ANY, |
| 413 | &mp->entry.local_address_start); |
| 414 | ip_address_encode (&p->laddr.stop, IP46_TYPE_ANY, |
| 415 | &mp->entry.local_address_stop); |
| 416 | ip_address_encode (&p->raddr.start, IP46_TYPE_ANY, |
| 417 | &mp->entry.remote_address_start); |
| 418 | ip_address_encode (&p->raddr.stop, IP46_TYPE_ANY, |
| 419 | &mp->entry.remote_address_stop); |
| 420 | mp->entry.local_port_start = htons (p->lport.start); |
| 421 | mp->entry.local_port_stop = htons (p->lport.stop); |
| 422 | mp->entry.remote_port_start = htons (p->rport.start); |
| 423 | mp->entry.remote_port_stop = htons (p->rport.stop); |
| 424 | mp->entry.protocol = p->protocol; |
| 425 | mp->entry.policy = ipsec_spd_action_encode (p->policy); |
| 426 | mp->entry.sa_id = htonl (p->sa_id); |
| 427 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 428 | vl_api_send_msg (reg, (u8 *) mp); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static void |
| 432 | vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp) |
| 433 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 434 | vl_api_registration_t *reg; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 435 | ipsec_main_t *im = &ipsec_main; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame^] | 436 | ipsec_spd_policy_t ptype; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 437 | ipsec_policy_t *policy; |
| 438 | ipsec_spd_t *spd; |
| 439 | uword *p; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame^] | 440 | u32 spd_index, *ii; |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 441 | #if WITH_LIBSSL > 0 |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 442 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 443 | if (!reg) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 444 | return; |
| 445 | |
| 446 | p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id)); |
| 447 | if (!p) |
| 448 | return; |
| 449 | |
| 450 | spd_index = p[0]; |
| 451 | spd = pool_elt_at_index (im->spds, spd_index); |
| 452 | |
| 453 | /* *INDENT-OFF* */ |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame^] | 454 | FOR_EACH_IPSEC_SPD_POLICY_TYPE(ptype) { |
| 455 | vec_foreach(ii, spd->policies[ptype]) |
| 456 | { |
| 457 | policy = pool_elt_at_index(im->policies, *ii); |
| 458 | |
| 459 | if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id) |
| 460 | send_ipsec_spd_details (policy, reg, mp->context); |
| 461 | } |
| 462 | } |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 463 | /* *INDENT-ON* */ |
| 464 | #else |
| 465 | clib_warning ("unimplemented"); |
| 466 | #endif |
| 467 | } |
| 468 | |
| 469 | static void |
Filip Varga | 871bca9 | 2018-11-02 13:51:44 +0100 | [diff] [blame] | 470 | send_ipsec_spd_interface_details (vl_api_registration_t * reg, u32 spd_index, |
| 471 | u32 sw_if_index, u32 context) |
| 472 | { |
| 473 | vl_api_ipsec_spd_interface_details_t *mp; |
| 474 | |
| 475 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 476 | clib_memset (mp, 0, sizeof (*mp)); |
| 477 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_INTERFACE_DETAILS); |
| 478 | mp->context = context; |
| 479 | |
| 480 | mp->spd_index = htonl (spd_index); |
| 481 | mp->sw_if_index = htonl (sw_if_index); |
| 482 | |
| 483 | vl_api_send_msg (reg, (u8 *) mp); |
| 484 | } |
| 485 | |
| 486 | static void |
| 487 | vl_api_ipsec_spd_interface_dump_t_handler (vl_api_ipsec_spd_interface_dump_t * |
| 488 | mp) |
| 489 | { |
| 490 | ipsec_main_t *im = &ipsec_main; |
| 491 | vl_api_registration_t *reg; |
| 492 | u32 k, v, spd_index; |
| 493 | |
| 494 | #if WITH_LIBSSL > 0 |
| 495 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 496 | if (!reg) |
| 497 | return; |
| 498 | |
| 499 | if (mp->spd_index_valid) |
| 500 | { |
| 501 | spd_index = ntohl (mp->spd_index); |
| 502 | /* *INDENT-OFF* */ |
| 503 | hash_foreach(k, v, im->spd_index_by_sw_if_index, ({ |
| 504 | if (v == spd_index) |
| 505 | send_ipsec_spd_interface_details(reg, v, k, mp->context); |
| 506 | })); |
| 507 | /* *INDENT-ON* */ |
| 508 | } |
| 509 | else |
| 510 | { |
| 511 | /* *INDENT-OFF* */ |
| 512 | hash_foreach(k, v, im->spd_index_by_sw_if_index, ({ |
| 513 | send_ipsec_spd_interface_details(reg, v, k, mp->context); |
| 514 | })); |
| 515 | /* *INDENT-ON* */ |
| 516 | } |
| 517 | |
| 518 | #else |
| 519 | clib_warning ("unimplemented"); |
| 520 | #endif |
| 521 | } |
| 522 | |
| 523 | static void |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 524 | vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp) |
| 525 | { |
| 526 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 527 | vl_api_ipsec_sa_set_key_reply_t *rmp; |
| 528 | int rv; |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 529 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 530 | ipsec_sa_t sa; |
| 531 | sa.id = ntohl (mp->sa_id); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 532 | |
| 533 | vl_api_ipsec_key_decode (&mp->crypto_key, |
| 534 | &sa.crypto_key_len, sa.crypto_key); |
| 535 | vl_api_ipsec_key_decode (&mp->integrity_key, |
| 536 | &sa.integ_key_len, sa.integ_key); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 537 | |
| 538 | rv = ipsec_set_sa_key (vm, &sa); |
| 539 | #else |
| 540 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 541 | #endif |
| 542 | |
| 543 | REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY); |
| 544 | } |
| 545 | |
| 546 | static void |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 547 | vl_api_ipsec_tunnel_if_add_del_t_handler (vl_api_ipsec_tunnel_if_add_del_t * |
| 548 | mp) |
| 549 | { |
| 550 | vl_api_ipsec_tunnel_if_add_del_reply_t *rmp; |
Matthew Smith | e04d09d | 2017-05-14 21:47:18 -0500 | [diff] [blame] | 551 | ipsec_main_t *im = &ipsec_main; |
| 552 | vnet_main_t *vnm = im->vnet_main; |
| 553 | u32 sw_if_index = ~0; |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 554 | int rv; |
| 555 | |
| 556 | #if WITH_LIBSSL > 0 |
| 557 | ipsec_add_del_tunnel_args_t tun; |
| 558 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 559 | clib_memset (&tun, 0, sizeof (ipsec_add_del_tunnel_args_t)); |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 560 | |
| 561 | tun.is_add = mp->is_add; |
| 562 | tun.esn = mp->esn; |
| 563 | tun.anti_replay = mp->anti_replay; |
| 564 | tun.local_spi = ntohl (mp->local_spi); |
| 565 | tun.remote_spi = ntohl (mp->remote_spi); |
| 566 | tun.crypto_alg = mp->crypto_alg; |
| 567 | tun.local_crypto_key_len = mp->local_crypto_key_len; |
| 568 | tun.remote_crypto_key_len = mp->remote_crypto_key_len; |
| 569 | tun.integ_alg = mp->integ_alg; |
| 570 | tun.local_integ_key_len = mp->local_integ_key_len; |
| 571 | tun.remote_integ_key_len = mp->remote_integ_key_len; |
Filip Tehlar | b4a7a7d | 2018-11-30 07:27:27 -0800 | [diff] [blame] | 572 | tun.udp_encap = mp->udp_encap; |
Pierre Pfister | 4c422f9 | 2018-12-10 11:19:08 +0100 | [diff] [blame] | 573 | tun.tx_table_id = ntohl (mp->tx_table_id); |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 574 | memcpy (&tun.local_ip, mp->local_ip, 4); |
| 575 | memcpy (&tun.remote_ip, mp->remote_ip, 4); |
| 576 | memcpy (&tun.local_crypto_key, &mp->local_crypto_key, |
| 577 | mp->local_crypto_key_len); |
| 578 | memcpy (&tun.remote_crypto_key, &mp->remote_crypto_key, |
| 579 | mp->remote_crypto_key_len); |
| 580 | memcpy (&tun.local_integ_key, &mp->local_integ_key, |
| 581 | mp->local_integ_key_len); |
| 582 | memcpy (&tun.remote_integ_key, &mp->remote_integ_key, |
| 583 | mp->remote_integ_key_len); |
Matthew Smith | 8e1039a | 2018-04-12 07:32:56 -0500 | [diff] [blame] | 584 | tun.renumber = mp->renumber; |
| 585 | tun.show_instance = ntohl (mp->show_instance); |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 586 | |
Matthew Smith | e04d09d | 2017-05-14 21:47:18 -0500 | [diff] [blame] | 587 | rv = ipsec_add_del_tunnel_if_internal (vnm, &tun, &sw_if_index); |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 588 | |
| 589 | #else |
| 590 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 591 | #endif |
| 592 | |
Matthew Smith | e04d09d | 2017-05-14 21:47:18 -0500 | [diff] [blame] | 593 | REPLY_MACRO2 (VL_API_IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ( |
| 594 | { |
| 595 | rmp->sw_if_index = |
| 596 | htonl (sw_if_index); |
| 597 | })); |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 598 | } |
| 599 | |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 600 | static void |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 601 | send_ipsec_sa_details (ipsec_sa_t * sa, vl_api_registration_t * reg, |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 602 | u32 context, u32 sw_if_index) |
| 603 | { |
| 604 | vl_api_ipsec_sa_details_t *mp; |
| 605 | |
| 606 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 607 | clib_memset (mp, 0, sizeof (*mp)); |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 608 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_SA_DETAILS); |
| 609 | mp->context = context; |
| 610 | |
| 611 | mp->sa_id = htonl (sa->id); |
| 612 | mp->sw_if_index = htonl (sw_if_index); |
| 613 | |
| 614 | mp->spi = htonl (sa->spi); |
| 615 | mp->protocol = sa->protocol; |
| 616 | |
| 617 | mp->crypto_alg = sa->crypto_alg; |
| 618 | mp->crypto_key_len = sa->crypto_key_len; |
| 619 | memcpy (mp->crypto_key, sa->crypto_key, sa->crypto_key_len); |
| 620 | |
| 621 | mp->integ_alg = sa->integ_alg; |
| 622 | mp->integ_key_len = sa->integ_key_len; |
| 623 | memcpy (mp->integ_key, sa->integ_key, sa->integ_key_len); |
| 624 | |
| 625 | mp->use_esn = sa->use_esn; |
| 626 | mp->use_anti_replay = sa->use_anti_replay; |
| 627 | |
| 628 | mp->is_tunnel = sa->is_tunnel; |
| 629 | mp->is_tunnel_ip6 = sa->is_tunnel_ip6; |
| 630 | |
| 631 | if (sa->is_tunnel) |
| 632 | { |
| 633 | if (sa->is_tunnel_ip6) |
| 634 | { |
| 635 | memcpy (mp->tunnel_src_addr, &sa->tunnel_src_addr.ip6, 16); |
| 636 | memcpy (mp->tunnel_dst_addr, &sa->tunnel_dst_addr.ip6, 16); |
| 637 | } |
| 638 | else |
| 639 | { |
| 640 | memcpy (mp->tunnel_src_addr, &sa->tunnel_src_addr.ip4, 4); |
| 641 | memcpy (mp->tunnel_dst_addr, &sa->tunnel_dst_addr.ip4, 4); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | mp->salt = clib_host_to_net_u32 (sa->salt); |
| 646 | mp->seq_outbound = clib_host_to_net_u64 (((u64) sa->seq)); |
| 647 | mp->last_seq_inbound = clib_host_to_net_u64 (((u64) sa->last_seq)); |
| 648 | if (sa->use_esn) |
| 649 | { |
| 650 | mp->seq_outbound |= (u64) (clib_host_to_net_u32 (sa->seq_hi)); |
| 651 | mp->last_seq_inbound |= (u64) (clib_host_to_net_u32 (sa->last_seq_hi)); |
| 652 | } |
| 653 | if (sa->use_anti_replay) |
| 654 | mp->replay_window = clib_host_to_net_u64 (sa->replay_window); |
| 655 | mp->total_data_size = clib_host_to_net_u64 (sa->total_data_size); |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 656 | mp->udp_encap = sa->udp_encap; |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 657 | |
Pierre Pfister | 4c422f9 | 2018-12-10 11:19:08 +0100 | [diff] [blame] | 658 | mp->tx_table_id = |
| 659 | htonl (fib_table_get_table_id (sa->tx_fib_index, FIB_PROTOCOL_IP4)); |
| 660 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 661 | vl_api_send_msg (reg, (u8 *) mp); |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | |
| 665 | static void |
| 666 | vl_api_ipsec_sa_dump_t_handler (vl_api_ipsec_sa_dump_t * mp) |
| 667 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 668 | vl_api_registration_t *reg; |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 669 | ipsec_main_t *im = &ipsec_main; |
| 670 | vnet_main_t *vnm = im->vnet_main; |
| 671 | ipsec_sa_t *sa; |
| 672 | ipsec_tunnel_if_t *t; |
| 673 | u32 *sa_index_to_tun_if_index = 0; |
| 674 | |
| 675 | #if WITH_LIBSSL > 0 |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 676 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 677 | if (!reg || pool_elts (im->sad) == 0) |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 678 | return; |
| 679 | |
| 680 | vec_validate_init_empty (sa_index_to_tun_if_index, vec_len (im->sad) - 1, |
| 681 | ~0); |
| 682 | |
| 683 | /* *INDENT-OFF* */ |
| 684 | pool_foreach (t, im->tunnel_interfaces, |
| 685 | ({ |
| 686 | vnet_hw_interface_t *hi; |
| 687 | u32 sw_if_index = ~0; |
| 688 | |
| 689 | hi = vnet_get_hw_interface (vnm, t->hw_if_index); |
| 690 | sw_if_index = hi->sw_if_index; |
| 691 | sa_index_to_tun_if_index[t->input_sa_index] = sw_if_index; |
| 692 | sa_index_to_tun_if_index[t->output_sa_index] = sw_if_index; |
| 693 | })); |
| 694 | |
| 695 | pool_foreach (sa, im->sad, |
| 696 | ({ |
| 697 | if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == sa->id) |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 698 | send_ipsec_sa_details (sa, reg, mp->context, |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 699 | sa_index_to_tun_if_index[sa - im->sad]); |
| 700 | })); |
| 701 | /* *INDENT-ON* */ |
| 702 | |
| 703 | vec_free (sa_index_to_tun_if_index); |
| 704 | #else |
| 705 | clib_warning ("unimplemented"); |
| 706 | #endif |
| 707 | } |
| 708 | |
Matthew Smith | e04d09d | 2017-05-14 21:47:18 -0500 | [diff] [blame] | 709 | |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 710 | static void |
Matthew Smith | 75d8560 | 2017-10-05 19:03:05 -0500 | [diff] [blame] | 711 | vl_api_ipsec_tunnel_if_set_key_t_handler (vl_api_ipsec_tunnel_if_set_key_t * |
| 712 | mp) |
| 713 | { |
| 714 | vl_api_ipsec_tunnel_if_set_key_reply_t *rmp; |
| 715 | ipsec_main_t *im = &ipsec_main; |
| 716 | vnet_main_t *vnm = im->vnet_main; |
| 717 | vnet_sw_interface_t *sw; |
| 718 | u8 *key = 0; |
| 719 | int rv; |
| 720 | |
| 721 | #if WITH_LIBSSL > 0 |
| 722 | sw = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index)); |
| 723 | |
| 724 | switch (mp->key_type) |
| 725 | { |
| 726 | case IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO: |
| 727 | case IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO: |
| 728 | if (mp->alg < IPSEC_CRYPTO_ALG_AES_CBC_128 || |
Dave Barach | a8d4764 | 2018-07-13 11:22:23 -0400 | [diff] [blame] | 729 | mp->alg >= IPSEC_CRYPTO_N_ALG) |
Matthew Smith | 75d8560 | 2017-10-05 19:03:05 -0500 | [diff] [blame] | 730 | { |
| 731 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 732 | goto out; |
| 733 | } |
| 734 | break; |
| 735 | case IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG: |
| 736 | case IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG: |
Dave Barach | a8d4764 | 2018-07-13 11:22:23 -0400 | [diff] [blame] | 737 | if (mp->alg >= IPSEC_INTEG_N_ALG) |
Matthew Smith | 75d8560 | 2017-10-05 19:03:05 -0500 | [diff] [blame] | 738 | { |
| 739 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 740 | goto out; |
| 741 | } |
| 742 | break; |
| 743 | case IPSEC_IF_SET_KEY_TYPE_NONE: |
| 744 | default: |
| 745 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 746 | goto out; |
| 747 | break; |
| 748 | } |
| 749 | |
| 750 | key = vec_new (u8, mp->key_len); |
| 751 | clib_memcpy (key, mp->key, mp->key_len); |
| 752 | |
| 753 | rv = ipsec_set_interface_key (vnm, sw->hw_if_index, mp->key_type, mp->alg, |
| 754 | key); |
| 755 | vec_free (key); |
| 756 | #else |
| 757 | clib_warning ("unimplemented"); |
| 758 | #endif |
| 759 | |
| 760 | out: |
| 761 | REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_KEY_REPLY); |
| 762 | } |
| 763 | |
| 764 | |
| 765 | static void |
Matthew Smith | ca514fd | 2017-10-12 12:06:59 -0500 | [diff] [blame] | 766 | vl_api_ipsec_tunnel_if_set_sa_t_handler (vl_api_ipsec_tunnel_if_set_sa_t * mp) |
| 767 | { |
| 768 | vl_api_ipsec_tunnel_if_set_sa_reply_t *rmp; |
| 769 | ipsec_main_t *im = &ipsec_main; |
| 770 | vnet_main_t *vnm = im->vnet_main; |
| 771 | vnet_sw_interface_t *sw; |
| 772 | int rv; |
| 773 | |
| 774 | #if WITH_LIBSSL > 0 |
| 775 | sw = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index)); |
| 776 | |
| 777 | rv = ipsec_set_interface_sa (vnm, sw->hw_if_index, ntohl (mp->sa_id), |
| 778 | mp->is_outbound); |
| 779 | #else |
| 780 | clib_warning ("unimplemented"); |
| 781 | #endif |
| 782 | |
| 783 | REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_SA_REPLY); |
| 784 | } |
| 785 | |
| 786 | |
| 787 | static void |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 788 | vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp) |
| 789 | { |
| 790 | vl_api_ikev2_profile_add_del_reply_t *rmp; |
| 791 | int rv = 0; |
| 792 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 793 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 794 | vlib_main_t *vm = vlib_get_main (); |
| 795 | clib_error_t *error; |
| 796 | u8 *tmp = format (0, "%s", mp->name); |
| 797 | error = ikev2_add_del_profile (vm, tmp, mp->is_add); |
| 798 | vec_free (tmp); |
| 799 | if (error) |
| 800 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 801 | #else |
| 802 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 803 | #endif |
| 804 | |
| 805 | REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY); |
| 806 | } |
| 807 | |
| 808 | static void |
| 809 | vl_api_ikev2_profile_set_auth_t_handler |
| 810 | (vl_api_ikev2_profile_set_auth_t * mp) |
| 811 | { |
| 812 | vl_api_ikev2_profile_set_auth_reply_t *rmp; |
| 813 | int rv = 0; |
| 814 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 815 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 816 | vlib_main_t *vm = vlib_get_main (); |
| 817 | clib_error_t *error; |
Michal Cmarada | e67c1d8 | 2019-01-18 12:51:08 +0100 | [diff] [blame] | 818 | int data_len = ntohl (mp->data_len); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 819 | u8 *tmp = format (0, "%s", mp->name); |
Michal Cmarada | e67c1d8 | 2019-01-18 12:51:08 +0100 | [diff] [blame] | 820 | u8 *data = vec_new (u8, data_len); |
| 821 | clib_memcpy (data, mp->data, data_len); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 822 | error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex); |
| 823 | vec_free (tmp); |
| 824 | vec_free (data); |
| 825 | if (error) |
| 826 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 827 | #else |
| 828 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 829 | #endif |
| 830 | |
| 831 | REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY); |
| 832 | } |
| 833 | |
| 834 | static void |
| 835 | vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp) |
| 836 | { |
| 837 | vl_api_ikev2_profile_add_del_reply_t *rmp; |
| 838 | int rv = 0; |
| 839 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 840 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 841 | vlib_main_t *vm = vlib_get_main (); |
| 842 | clib_error_t *error; |
| 843 | u8 *tmp = format (0, "%s", mp->name); |
Michal Cmarada | e67c1d8 | 2019-01-18 12:51:08 +0100 | [diff] [blame] | 844 | int data_len = ntohl (mp->data_len); |
| 845 | u8 *data = vec_new (u8, data_len); |
| 846 | clib_memcpy (data, mp->data, data_len); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 847 | error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local); |
| 848 | vec_free (tmp); |
| 849 | vec_free (data); |
| 850 | if (error) |
| 851 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 852 | #else |
| 853 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 854 | #endif |
| 855 | |
| 856 | REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY); |
| 857 | } |
| 858 | |
| 859 | static void |
| 860 | vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp) |
| 861 | { |
| 862 | vl_api_ikev2_profile_set_ts_reply_t *rmp; |
| 863 | int rv = 0; |
| 864 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 865 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 866 | vlib_main_t *vm = vlib_get_main (); |
| 867 | clib_error_t *error; |
| 868 | u8 *tmp = format (0, "%s", mp->name); |
| 869 | error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port, |
| 870 | mp->end_port, (ip4_address_t) mp->start_addr, |
| 871 | (ip4_address_t) mp->end_addr, mp->is_local); |
| 872 | vec_free (tmp); |
| 873 | if (error) |
| 874 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 875 | #else |
| 876 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 877 | #endif |
| 878 | |
| 879 | REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY); |
| 880 | } |
| 881 | |
| 882 | static void |
| 883 | vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp) |
| 884 | { |
| 885 | vl_api_ikev2_profile_set_ts_reply_t *rmp; |
| 886 | int rv = 0; |
| 887 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 888 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 889 | vlib_main_t *vm = vlib_get_main (); |
| 890 | clib_error_t *error; |
| 891 | |
| 892 | error = ikev2_set_local_key (vm, mp->key_file); |
| 893 | if (error) |
| 894 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 895 | #else |
| 896 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 897 | #endif |
| 898 | |
| 899 | REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY); |
| 900 | } |
| 901 | |
Radu Nicolau | cb33dc2 | 2017-02-16 16:49:46 +0000 | [diff] [blame] | 902 | static void |
| 903 | vl_api_ikev2_set_responder_t_handler (vl_api_ikev2_set_responder_t * mp) |
| 904 | { |
| 905 | vl_api_ikev2_set_responder_reply_t *rmp; |
| 906 | int rv = 0; |
| 907 | |
| 908 | #if WITH_LIBSSL > 0 |
| 909 | vlib_main_t *vm = vlib_get_main (); |
| 910 | clib_error_t *error; |
| 911 | |
| 912 | u8 *tmp = format (0, "%s", mp->name); |
| 913 | ip4_address_t ip4; |
| 914 | clib_memcpy (&ip4, mp->address, sizeof (ip4)); |
| 915 | |
| 916 | error = ikev2_set_profile_responder (vm, tmp, mp->sw_if_index, ip4); |
| 917 | vec_free (tmp); |
| 918 | if (error) |
| 919 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 920 | #else |
| 921 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 922 | #endif |
| 923 | |
| 924 | REPLY_MACRO (VL_API_IKEV2_SET_RESPONDER_REPLY); |
| 925 | } |
| 926 | |
| 927 | static void |
| 928 | vl_api_ikev2_set_ike_transforms_t_handler (vl_api_ikev2_set_ike_transforms_t * |
| 929 | mp) |
| 930 | { |
| 931 | vl_api_ikev2_set_ike_transforms_reply_t *rmp; |
| 932 | int rv = 0; |
| 933 | |
| 934 | #if WITH_LIBSSL > 0 |
| 935 | vlib_main_t *vm = vlib_get_main (); |
| 936 | clib_error_t *error; |
| 937 | |
| 938 | u8 *tmp = format (0, "%s", mp->name); |
| 939 | |
| 940 | error = |
| 941 | ikev2_set_profile_ike_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg, |
| 942 | mp->dh_group, mp->crypto_key_size); |
| 943 | vec_free (tmp); |
| 944 | if (error) |
| 945 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 946 | #else |
| 947 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 948 | #endif |
| 949 | |
| 950 | REPLY_MACRO (VL_API_IKEV2_SET_IKE_TRANSFORMS_REPLY); |
| 951 | } |
| 952 | |
| 953 | static void |
| 954 | vl_api_ikev2_set_esp_transforms_t_handler (vl_api_ikev2_set_esp_transforms_t * |
| 955 | mp) |
| 956 | { |
| 957 | vl_api_ikev2_set_esp_transforms_reply_t *rmp; |
| 958 | int rv = 0; |
| 959 | |
| 960 | #if WITH_LIBSSL > 0 |
| 961 | vlib_main_t *vm = vlib_get_main (); |
| 962 | clib_error_t *error; |
| 963 | |
| 964 | u8 *tmp = format (0, "%s", mp->name); |
| 965 | |
| 966 | error = |
| 967 | ikev2_set_profile_esp_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg, |
| 968 | mp->dh_group, mp->crypto_key_size); |
| 969 | vec_free (tmp); |
| 970 | if (error) |
| 971 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 972 | #else |
| 973 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 974 | #endif |
| 975 | |
| 976 | REPLY_MACRO (VL_API_IKEV2_SET_ESP_TRANSFORMS_REPLY); |
| 977 | } |
| 978 | |
| 979 | static void |
| 980 | vl_api_ikev2_set_sa_lifetime_t_handler (vl_api_ikev2_set_sa_lifetime_t * mp) |
| 981 | { |
| 982 | vl_api_ikev2_set_sa_lifetime_reply_t *rmp; |
| 983 | int rv = 0; |
| 984 | |
| 985 | #if WITH_LIBSSL > 0 |
| 986 | vlib_main_t *vm = vlib_get_main (); |
| 987 | clib_error_t *error; |
| 988 | |
| 989 | u8 *tmp = format (0, "%s", mp->name); |
| 990 | |
| 991 | error = |
| 992 | ikev2_set_profile_sa_lifetime (vm, tmp, mp->lifetime, mp->lifetime_jitter, |
| 993 | mp->handover, mp->lifetime_maxdata); |
| 994 | vec_free (tmp); |
| 995 | if (error) |
| 996 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 997 | #else |
| 998 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 999 | #endif |
| 1000 | |
| 1001 | REPLY_MACRO (VL_API_IKEV2_SET_SA_LIFETIME_REPLY); |
| 1002 | } |
| 1003 | |
| 1004 | static void |
| 1005 | vl_api_ikev2_initiate_sa_init_t_handler (vl_api_ikev2_initiate_sa_init_t * mp) |
| 1006 | { |
| 1007 | vl_api_ikev2_initiate_sa_init_reply_t *rmp; |
| 1008 | int rv = 0; |
| 1009 | |
| 1010 | #if WITH_LIBSSL > 0 |
| 1011 | vlib_main_t *vm = vlib_get_main (); |
| 1012 | clib_error_t *error; |
| 1013 | |
| 1014 | u8 *tmp = format (0, "%s", mp->name); |
| 1015 | |
| 1016 | error = ikev2_initiate_sa_init (vm, tmp); |
| 1017 | vec_free (tmp); |
| 1018 | if (error) |
| 1019 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1020 | #else |
| 1021 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 1022 | #endif |
| 1023 | |
| 1024 | REPLY_MACRO (VL_API_IKEV2_INITIATE_SA_INIT_REPLY); |
| 1025 | } |
| 1026 | |
| 1027 | static void |
| 1028 | vl_api_ikev2_initiate_del_ike_sa_t_handler (vl_api_ikev2_initiate_del_ike_sa_t |
| 1029 | * mp) |
| 1030 | { |
| 1031 | vl_api_ikev2_initiate_del_ike_sa_reply_t *rmp; |
| 1032 | int rv = 0; |
| 1033 | |
| 1034 | #if WITH_LIBSSL > 0 |
| 1035 | vlib_main_t *vm = vlib_get_main (); |
| 1036 | clib_error_t *error; |
| 1037 | |
| 1038 | error = ikev2_initiate_delete_ike_sa (vm, mp->ispi); |
| 1039 | if (error) |
| 1040 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1041 | #else |
| 1042 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 1043 | #endif |
| 1044 | |
| 1045 | REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_IKE_SA_REPLY); |
| 1046 | } |
| 1047 | |
| 1048 | static void |
| 1049 | vl_api_ikev2_initiate_del_child_sa_t_handler |
| 1050 | (vl_api_ikev2_initiate_del_child_sa_t * mp) |
| 1051 | { |
| 1052 | vl_api_ikev2_initiate_del_child_sa_reply_t *rmp; |
| 1053 | int rv = 0; |
| 1054 | |
| 1055 | #if WITH_LIBSSL > 0 |
| 1056 | vlib_main_t *vm = vlib_get_main (); |
| 1057 | clib_error_t *error; |
| 1058 | |
| 1059 | error = ikev2_initiate_delete_child_sa (vm, mp->ispi); |
| 1060 | if (error) |
| 1061 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1062 | #else |
| 1063 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 1064 | #endif |
| 1065 | |
| 1066 | REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_CHILD_SA_REPLY); |
| 1067 | } |
| 1068 | |
| 1069 | static void |
| 1070 | vl_api_ikev2_initiate_rekey_child_sa_t_handler |
| 1071 | (vl_api_ikev2_initiate_rekey_child_sa_t * mp) |
| 1072 | { |
| 1073 | vl_api_ikev2_initiate_rekey_child_sa_reply_t *rmp; |
| 1074 | int rv = 0; |
| 1075 | |
| 1076 | #if WITH_LIBSSL > 0 |
| 1077 | vlib_main_t *vm = vlib_get_main (); |
| 1078 | clib_error_t *error; |
| 1079 | |
| 1080 | error = ikev2_initiate_rekey_child_sa (vm, mp->ispi); |
| 1081 | if (error) |
| 1082 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1083 | #else |
| 1084 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 1085 | #endif |
| 1086 | |
| 1087 | REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY); |
| 1088 | } |
| 1089 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 1090 | /* |
| 1091 | * ipsec_api_hookup |
| 1092 | * Add vpe's API message handlers to the table. |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 1093 | * vlib has already mapped shared memory and |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 1094 | * added the client registration handlers. |
| 1095 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 1096 | */ |
| 1097 | #define vl_msg_name_crc_list |
| 1098 | #include <vnet/vnet_all_api_h.h> |
| 1099 | #undef vl_msg_name_crc_list |
| 1100 | |
| 1101 | static void |
| 1102 | setup_message_id_table (api_main_t * am) |
| 1103 | { |
| 1104 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 1105 | foreach_vl_msg_name_crc_ipsec; |
| 1106 | #undef _ |
| 1107 | } |
| 1108 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 1109 | static void |
| 1110 | vl_api_ipsec_backend_dump_t_handler (vl_api_ipsec_backend_dump_t * mp) |
| 1111 | { |
| 1112 | vl_api_registration_t *rp; |
| 1113 | ipsec_main_t *im = &ipsec_main; |
| 1114 | u32 context = mp->context; |
| 1115 | |
| 1116 | rp = vl_api_client_index_to_registration (mp->client_index); |
| 1117 | |
| 1118 | if (rp == 0) |
| 1119 | { |
| 1120 | clib_warning ("Client %d AWOL", mp->client_index); |
| 1121 | return; |
| 1122 | } |
| 1123 | |
| 1124 | ipsec_ah_backend_t *ab; |
| 1125 | ipsec_esp_backend_t *eb; |
| 1126 | /* *INDENT-OFF* */ |
| 1127 | pool_foreach (ab, im->ah_backends, { |
| 1128 | vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1129 | clib_memset (mp, 0, sizeof (*mp)); |
| 1130 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS); |
| 1131 | mp->context = context; |
| 1132 | snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (ab->name), |
| 1133 | ab->name); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1134 | mp->protocol = ntohl (IPSEC_API_PROTO_AH); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 1135 | mp->index = ab - im->ah_backends; |
| 1136 | mp->active = mp->index == im->ah_current_backend ? 1 : 0; |
| 1137 | vl_api_send_msg (rp, (u8 *)mp); |
| 1138 | }); |
| 1139 | pool_foreach (eb, im->esp_backends, { |
| 1140 | vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1141 | clib_memset (mp, 0, sizeof (*mp)); |
| 1142 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS); |
| 1143 | mp->context = context; |
| 1144 | snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (eb->name), |
| 1145 | eb->name); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1146 | mp->protocol = ntohl (IPSEC_API_PROTO_ESP); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 1147 | mp->index = eb - im->esp_backends; |
| 1148 | mp->active = mp->index == im->esp_current_backend ? 1 : 0; |
| 1149 | vl_api_send_msg (rp, (u8 *)mp); |
| 1150 | }); |
| 1151 | /* *INDENT-ON* */ |
| 1152 | } |
| 1153 | |
| 1154 | static void |
| 1155 | vl_api_ipsec_select_backend_t_handler (vl_api_ipsec_select_backend_t * mp) |
| 1156 | { |
| 1157 | ipsec_main_t *im = &ipsec_main; |
| 1158 | vl_api_ipsec_select_backend_reply_t *rmp; |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1159 | ipsec_protocol_t protocol; |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 1160 | int rv = 0; |
| 1161 | if (pool_elts (im->sad) > 0) |
| 1162 | { |
| 1163 | rv = VNET_API_ERROR_INSTANCE_IN_USE; |
| 1164 | goto done; |
| 1165 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1166 | |
| 1167 | rv = ipsec_proto_decode (mp->protocol, &protocol); |
| 1168 | |
| 1169 | if (rv) |
| 1170 | goto done; |
| 1171 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 1172 | #if WITH_LIBSSL > 0 |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1173 | switch (protocol) |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 1174 | { |
| 1175 | case IPSEC_PROTOCOL_ESP: |
| 1176 | if (pool_is_free_index (im->esp_backends, mp->index)) |
| 1177 | { |
| 1178 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1179 | break; |
| 1180 | } |
| 1181 | ipsec_select_esp_backend (im, mp->index); |
| 1182 | break; |
| 1183 | case IPSEC_PROTOCOL_AH: |
| 1184 | if (pool_is_free_index (im->ah_backends, mp->index)) |
| 1185 | { |
| 1186 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1187 | break; |
| 1188 | } |
| 1189 | ipsec_select_ah_backend (im, mp->index); |
| 1190 | break; |
| 1191 | default: |
| 1192 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1193 | break; |
| 1194 | } |
| 1195 | #else |
| 1196 | clib_warning ("unimplemented"); /* FIXME */ |
| 1197 | #endif |
| 1198 | done: |
| 1199 | REPLY_MACRO (VL_API_IPSEC_SELECT_BACKEND_REPLY); |
| 1200 | } |
| 1201 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 1202 | static clib_error_t * |
| 1203 | ipsec_api_hookup (vlib_main_t * vm) |
| 1204 | { |
| 1205 | api_main_t *am = &api_main; |
| 1206 | |
| 1207 | #define _(N,n) \ |
| 1208 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 1209 | vl_api_##n##_t_handler, \ |
| 1210 | vl_noop_handler, \ |
| 1211 | vl_api_##n##_t_endian, \ |
| 1212 | vl_api_##n##_t_print, \ |
| 1213 | sizeof(vl_api_##n##_t), 1); |
| 1214 | foreach_vpe_api_msg; |
| 1215 | #undef _ |
| 1216 | |
| 1217 | /* |
| 1218 | * Set up the (msg_name, crc, message-id) table |
| 1219 | */ |
| 1220 | setup_message_id_table (am); |
| 1221 | |
| 1222 | return 0; |
| 1223 | } |
| 1224 | |
| 1225 | VLIB_API_INIT_FUNCTION (ipsec_api_hookup); |
| 1226 | |
| 1227 | /* |
| 1228 | * fd.io coding-style-patch-verification: ON |
| 1229 | * |
| 1230 | * Local Variables: |
| 1231 | * eval: (c-set-style "gnu") |
| 1232 | * End: |
| 1233 | */ |