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> |
Prashant Maheshwari | dbf68c9 | 2019-11-14 12:42:59 +0530 | [diff] [blame] | 27 | #include <vnet/ipsec/ipsec_types_api.h> |
Pierre Pfister | 4c422f9 | 2018-12-10 11:19:08 +0100 | [diff] [blame] | 28 | #include <vnet/fib/fib.h> |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 29 | #include <vnet/ipip/ipip.h> |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 30 | |
| 31 | #include <vnet/vnet_msg_enum.h> |
| 32 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 33 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 34 | #include <vnet/ipsec/ipsec.h> |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 35 | #include <vnet/ipsec/ipsec_tun.h> |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 36 | #endif /* IPSEC */ |
| 37 | |
| 38 | #define vl_typedefs /* define message structures */ |
| 39 | #include <vnet/vnet_all_api_h.h> |
| 40 | #undef vl_typedefs |
| 41 | |
| 42 | #define vl_endianfun /* define message structures */ |
| 43 | #include <vnet/vnet_all_api_h.h> |
| 44 | #undef vl_endianfun |
| 45 | |
| 46 | /* instantiate all the print functions we know about */ |
| 47 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 48 | #define vl_printfun |
| 49 | #include <vnet/vnet_all_api_h.h> |
| 50 | #undef vl_printfun |
| 51 | |
| 52 | #include <vlibapi/api_helper_macros.h> |
| 53 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 54 | #define foreach_vpe_api_msg \ |
| 55 | _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \ |
| 56 | _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \ |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 57 | _(IPSEC_SPD_ENTRY_ADD_DEL, ipsec_spd_entry_add_del) \ |
| 58 | _(IPSEC_SAD_ENTRY_ADD_DEL, ipsec_sad_entry_add_del) \ |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 59 | _(IPSEC_SA_DUMP, ipsec_sa_dump) \ |
| 60 | _(IPSEC_SPDS_DUMP, ipsec_spds_dump) \ |
| 61 | _(IPSEC_SPD_DUMP, ipsec_spd_dump) \ |
| 62 | _(IPSEC_SPD_INTERFACE_DUMP, ipsec_spd_interface_dump) \ |
| 63 | _(IPSEC_TUNNEL_IF_ADD_DEL, ipsec_tunnel_if_add_del) \ |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 64 | _(IPSEC_TUNNEL_IF_SET_SA, ipsec_tunnel_if_set_sa) \ |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 65 | _(IPSEC_SELECT_BACKEND, ipsec_select_backend) \ |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 66 | _(IPSEC_BACKEND_DUMP, ipsec_backend_dump) \ |
| 67 | _(IPSEC_TUNNEL_PROTECT_UPDATE, ipsec_tunnel_protect_update) \ |
| 68 | _(IPSEC_TUNNEL_PROTECT_DEL, ipsec_tunnel_protect_del) \ |
| 69 | _(IPSEC_TUNNEL_PROTECT_DUMP, ipsec_tunnel_protect_dump) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 70 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 71 | static void |
| 72 | 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] | 73 | { |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 74 | #if WITH_LIBSSL == 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 75 | clib_warning ("unimplemented"); |
| 76 | #else |
| 77 | |
| 78 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 79 | vl_api_ipsec_spd_add_del_reply_t *rmp; |
| 80 | int rv; |
| 81 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 82 | 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] | 83 | |
| 84 | REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY); |
| 85 | #endif |
| 86 | } |
| 87 | |
| 88 | static void vl_api_ipsec_interface_add_del_spd_t_handler |
| 89 | (vl_api_ipsec_interface_add_del_spd_t * mp) |
| 90 | { |
| 91 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 92 | vl_api_ipsec_interface_add_del_spd_reply_t *rmp; |
| 93 | int rv; |
| 94 | u32 sw_if_index __attribute__ ((unused)); |
| 95 | u32 spd_id __attribute__ ((unused)); |
| 96 | |
| 97 | sw_if_index = ntohl (mp->sw_if_index); |
| 98 | spd_id = ntohl (mp->spd_id); |
| 99 | |
| 100 | VALIDATE_SW_IF_INDEX (mp); |
| 101 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 102 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 103 | rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add); |
| 104 | #else |
| 105 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 106 | #endif |
| 107 | |
| 108 | BAD_SW_IF_INDEX_LABEL; |
| 109 | |
| 110 | REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY); |
| 111 | } |
| 112 | |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 113 | static void vl_api_ipsec_tunnel_protect_update_t_handler |
| 114 | (vl_api_ipsec_tunnel_protect_update_t * mp) |
| 115 | { |
| 116 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 117 | vl_api_ipsec_tunnel_protect_update_reply_t *rmp; |
| 118 | u32 sw_if_index, ii, *sa_ins = NULL; |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 119 | ip_address_t nh; |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 120 | int rv; |
| 121 | |
| 122 | sw_if_index = ntohl (mp->tunnel.sw_if_index); |
| 123 | |
| 124 | VALIDATE_SW_IF_INDEX (&(mp->tunnel)); |
| 125 | |
| 126 | #if WITH_LIBSSL > 0 |
| 127 | |
| 128 | for (ii = 0; ii < mp->tunnel.n_sa_in; ii++) |
| 129 | vec_add1 (sa_ins, ntohl (mp->tunnel.sa_in[ii])); |
| 130 | |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 131 | ip_address_decode2 (&mp->tunnel.nh, &nh); |
| 132 | |
| 133 | rv = ipsec_tun_protect_update (sw_if_index, &nh, |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 134 | ntohl (mp->tunnel.sa_out), sa_ins); |
| 135 | #else |
| 136 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 137 | #endif |
| 138 | |
| 139 | BAD_SW_IF_INDEX_LABEL; |
| 140 | |
| 141 | REPLY_MACRO (VL_API_IPSEC_TUNNEL_PROTECT_UPDATE_REPLY); |
| 142 | } |
| 143 | |
| 144 | static void vl_api_ipsec_tunnel_protect_del_t_handler |
| 145 | (vl_api_ipsec_tunnel_protect_del_t * mp) |
| 146 | { |
| 147 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
| 148 | vl_api_ipsec_tunnel_protect_del_reply_t *rmp; |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 149 | ip_address_t nh; |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 150 | u32 sw_if_index; |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 151 | int rv; |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 152 | |
| 153 | sw_if_index = ntohl (mp->sw_if_index); |
| 154 | |
| 155 | VALIDATE_SW_IF_INDEX (mp); |
| 156 | |
| 157 | #if WITH_LIBSSL > 0 |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 158 | ip_address_decode2 (&mp->nh, &nh); |
| 159 | rv = ipsec_tun_protect_del (sw_if_index, &nh); |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 160 | #else |
| 161 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 162 | #endif |
| 163 | |
| 164 | BAD_SW_IF_INDEX_LABEL; |
| 165 | |
| 166 | REPLY_MACRO (VL_API_IPSEC_TUNNEL_PROTECT_DEL_REPLY); |
| 167 | } |
| 168 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 169 | typedef struct ipsec_dump_walk_ctx_t_ |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 170 | { |
| 171 | vl_api_registration_t *reg; |
| 172 | u32 context; |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 173 | } ipsec_dump_walk_ctx_t; |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 174 | |
| 175 | static walk_rc_t |
| 176 | send_ipsec_tunnel_protect_details (index_t itpi, void *arg) |
| 177 | { |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 178 | ipsec_dump_walk_ctx_t *ctx = arg; |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 179 | vl_api_ipsec_tunnel_protect_details_t *mp; |
| 180 | ipsec_tun_protect_t *itp; |
Matthew Smith | 5cee0bc | 2020-03-31 09:52:17 -0500 | [diff] [blame] | 181 | u32 ii = 0; |
| 182 | ipsec_sa_t *sa; |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 183 | |
| 184 | itp = ipsec_tun_protect_get (itpi); |
| 185 | |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 186 | mp = vl_msg_api_alloc (sizeof (*mp) + (sizeof (u32) * itp->itp_n_sa_in)); |
| 187 | clib_memset (mp, 0, sizeof (*mp)); |
| 188 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_TUNNEL_PROTECT_DETAILS); |
| 189 | mp->context = ctx->context; |
| 190 | |
| 191 | mp->tun.sw_if_index = htonl (itp->itp_sw_if_index); |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 192 | ip_address_encode2 (itp->itp_key, &mp->tun.nh); |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 193 | |
Matthew Smith | 5cee0bc | 2020-03-31 09:52:17 -0500 | [diff] [blame] | 194 | sa = ipsec_sa_get (itp->itp_out_sa); |
| 195 | mp->tun.sa_out = htonl (sa->id); |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 196 | mp->tun.n_sa_in = itp->itp_n_sa_in; |
| 197 | /* *INDENT-OFF* */ |
Matthew Smith | 5cee0bc | 2020-03-31 09:52:17 -0500 | [diff] [blame] | 198 | FOR_EACH_IPSEC_PROTECT_INPUT_SA(itp, sa, |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 199 | ({ |
Matthew Smith | 5cee0bc | 2020-03-31 09:52:17 -0500 | [diff] [blame] | 200 | mp->tun.sa_in[ii++] = htonl (sa->id); |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 201 | })); |
| 202 | /* *INDENT-ON* */ |
| 203 | |
| 204 | vl_api_send_msg (ctx->reg, (u8 *) mp); |
| 205 | |
| 206 | return (WALK_CONTINUE); |
| 207 | } |
| 208 | |
| 209 | static void |
| 210 | vl_api_ipsec_tunnel_protect_dump_t_handler (vl_api_ipsec_tunnel_protect_dump_t |
| 211 | * mp) |
| 212 | { |
| 213 | vl_api_registration_t *reg; |
| 214 | u32 sw_if_index; |
| 215 | |
| 216 | #if WITH_LIBSSL > 0 |
| 217 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 218 | if (!reg) |
| 219 | return; |
| 220 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 221 | ipsec_dump_walk_ctx_t ctx = { |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 222 | .reg = reg, |
| 223 | .context = mp->context, |
| 224 | }; |
| 225 | |
| 226 | sw_if_index = ntohl (mp->sw_if_index); |
| 227 | |
| 228 | if (~0 == sw_if_index) |
| 229 | { |
| 230 | ipsec_tun_protect_walk (send_ipsec_tunnel_protect_details, &ctx); |
| 231 | } |
| 232 | else |
| 233 | { |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 234 | ipsec_tun_protect_walk_itf (sw_if_index, |
| 235 | send_ipsec_tunnel_protect_details, &ctx); |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 236 | } |
| 237 | #else |
| 238 | clib_warning ("unimplemented"); |
| 239 | #endif |
| 240 | } |
| 241 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 242 | static int |
| 243 | ipsec_spd_action_decode (vl_api_ipsec_spd_action_t in, |
| 244 | ipsec_policy_action_t * out) |
| 245 | { |
| 246 | in = clib_net_to_host_u32 (in); |
| 247 | |
| 248 | switch (in) |
| 249 | { |
| 250 | #define _(v,f,s) case IPSEC_API_SPD_ACTION_##f: \ |
| 251 | *out = IPSEC_POLICY_ACTION_##f; \ |
| 252 | return (0); |
| 253 | foreach_ipsec_policy_action |
| 254 | #undef _ |
| 255 | } |
| 256 | return (VNET_API_ERROR_UNIMPLEMENTED); |
| 257 | } |
| 258 | |
| 259 | static void vl_api_ipsec_spd_entry_add_del_t_handler |
| 260 | (vl_api_ipsec_spd_entry_add_del_t * mp) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 261 | { |
| 262 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 263 | vl_api_ipsec_spd_entry_add_del_reply_t *rmp; |
| 264 | ip46_type_t itype; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 265 | u32 stat_index; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 266 | int rv; |
| 267 | |
Neale Ranns | 8c2dd1b | 2019-02-19 08:27:34 -0800 | [diff] [blame] | 268 | stat_index = ~0; |
| 269 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 270 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 271 | ipsec_policy_t p; |
| 272 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 273 | clib_memset (&p, 0, sizeof (p)); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 274 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 275 | p.id = ntohl (mp->entry.spd_id); |
| 276 | p.priority = ntohl (mp->entry.priority); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 277 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 278 | itype = ip_address_decode (&mp->entry.remote_address_start, &p.raddr.start); |
| 279 | ip_address_decode (&mp->entry.remote_address_stop, &p.raddr.stop); |
| 280 | ip_address_decode (&mp->entry.local_address_start, &p.laddr.start); |
| 281 | ip_address_decode (&mp->entry.local_address_stop, &p.laddr.stop); |
| 282 | |
| 283 | p.is_ipv6 = (itype == IP46_TYPE_IP6); |
| 284 | |
| 285 | p.protocol = mp->entry.protocol; |
Neale Ranns | a4d2431 | 2019-07-10 13:46:21 +0000 | [diff] [blame] | 286 | p.rport.start = ntohs (mp->entry.remote_port_start); |
| 287 | p.rport.stop = ntohs (mp->entry.remote_port_stop); |
| 288 | p.lport.start = ntohs (mp->entry.local_port_start); |
| 289 | p.lport.stop = ntohs (mp->entry.local_port_stop); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 290 | |
| 291 | rv = ipsec_spd_action_decode (mp->entry.policy, &p.policy); |
| 292 | |
| 293 | if (rv) |
| 294 | goto out; |
| 295 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 296 | /* policy action resolve unsupported */ |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 297 | if (p.policy == IPSEC_POLICY_ACTION_RESOLVE) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 298 | { |
| 299 | clib_warning ("unsupported action: 'resolve'"); |
| 300 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 301 | goto out; |
| 302 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 303 | p.sa_id = ntohl (mp->entry.sa_id); |
Neale Ranns | 9f231d4 | 2019-03-19 10:06:00 +0000 | [diff] [blame] | 304 | rv = |
| 305 | ipsec_policy_mk_type (mp->entry.is_outbound, p.is_ipv6, p.policy, |
| 306 | &p.type); |
| 307 | if (rv) |
| 308 | goto out; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 309 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 310 | rv = ipsec_add_del_policy (vm, &p, mp->is_add, &stat_index); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 311 | if (rv) |
| 312 | goto out; |
| 313 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 314 | #else |
| 315 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 316 | goto out; |
| 317 | #endif |
| 318 | |
| 319 | out: |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 320 | /* *INDENT-OFF* */ |
| 321 | REPLY_MACRO2 (VL_API_IPSEC_SPD_ENTRY_ADD_DEL_REPLY, |
| 322 | ({ |
| 323 | rmp->stat_index = ntohl(stat_index); |
| 324 | })); |
| 325 | /* *INDENT-ON* */ |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 328 | static void vl_api_ipsec_sad_entry_add_del_t_handler |
| 329 | (vl_api_ipsec_sad_entry_add_del_t * mp) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 330 | { |
| 331 | vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main (); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 332 | vl_api_ipsec_sad_entry_add_del_reply_t *rmp; |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 333 | ip46_address_t tun_src = { }, tun_dst = |
| 334 | { |
| 335 | }; |
| 336 | ipsec_key_t crypto_key, integ_key; |
| 337 | ipsec_crypto_alg_t crypto_alg; |
| 338 | ipsec_integ_alg_t integ_alg; |
| 339 | ipsec_protocol_t proto; |
| 340 | ipsec_sa_flags_t flags; |
Dave Barach | a5160d7 | 2019-03-13 15:29:15 -0400 | [diff] [blame] | 341 | u32 id, spi, sa_index = ~0; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 342 | int rv; |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 343 | |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 344 | #if WITH_LIBSSL > 0 |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 345 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 346 | id = ntohl (mp->entry.sad_id); |
| 347 | spi = ntohl (mp->entry.spi); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 348 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 349 | rv = ipsec_proto_decode (mp->entry.protocol, &proto); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 350 | |
| 351 | if (rv) |
| 352 | goto out; |
| 353 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 354 | rv = ipsec_crypto_algo_decode (mp->entry.crypto_algorithm, &crypto_alg); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 355 | |
| 356 | if (rv) |
| 357 | goto out; |
| 358 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 359 | rv = ipsec_integ_algo_decode (mp->entry.integrity_algorithm, &integ_alg); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 360 | |
| 361 | if (rv) |
| 362 | goto out; |
| 363 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 364 | ipsec_key_decode (&mp->entry.crypto_key, &crypto_key); |
| 365 | ipsec_key_decode (&mp->entry.integrity_key, &integ_key); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 366 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 367 | flags = ipsec_sa_flags_decode (mp->entry.flags); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 368 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 369 | ip_address_decode (&mp->entry.tunnel_src, &tun_src); |
| 370 | ip_address_decode (&mp->entry.tunnel_dst, &tun_dst); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 371 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 372 | if (mp->is_add) |
Neale Ranns | 495d7ff | 2019-07-12 09:15:26 +0000 | [diff] [blame] | 373 | rv = ipsec_sa_add_and_lock (id, spi, proto, |
| 374 | crypto_alg, &crypto_key, |
| 375 | integ_alg, &integ_key, flags, |
| 376 | 0, mp->entry.salt, &tun_src, &tun_dst, |
Neale Ranns | abc5660 | 2020-04-01 09:45:23 +0000 | [diff] [blame] | 377 | &sa_index, htons (mp->entry.udp_src_port), |
| 378 | htons (mp->entry.udp_dst_port)); |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 379 | else |
Neale Ranns | 495d7ff | 2019-07-12 09:15:26 +0000 | [diff] [blame] | 380 | rv = ipsec_sa_unlock_id (id); |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 381 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 382 | #else |
| 383 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 384 | #endif |
| 385 | |
| 386 | out: |
Neale Ranns | eba31ec | 2019-02-17 18:04:27 +0000 | [diff] [blame] | 387 | /* *INDENT-OFF* */ |
| 388 | REPLY_MACRO2 (VL_API_IPSEC_SAD_ENTRY_ADD_DEL_REPLY, |
| 389 | { |
| 390 | rmp->stat_index = htonl (sa_index); |
| 391 | }); |
| 392 | /* *INDENT-ON* */ |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static void |
Matus Fabian | a9a0b2c | 2018-10-02 01:13:25 -0700 | [diff] [blame] | 396 | send_ipsec_spds_details (ipsec_spd_t * spd, vl_api_registration_t * reg, |
| 397 | u32 context) |
| 398 | { |
| 399 | vl_api_ipsec_spds_details_t *mp; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 400 | u32 n_policies = 0; |
Matus Fabian | a9a0b2c | 2018-10-02 01:13:25 -0700 | [diff] [blame] | 401 | |
| 402 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 403 | clib_memset (mp, 0, sizeof (*mp)); |
Matus Fabian | a9a0b2c | 2018-10-02 01:13:25 -0700 | [diff] [blame] | 404 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPDS_DETAILS); |
| 405 | mp->context = context; |
| 406 | |
| 407 | mp->spd_id = htonl (spd->id); |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 408 | #define _(s, n) n_policies += vec_len (spd->policies[IPSEC_SPD_POLICY_##s]); |
| 409 | foreach_ipsec_spd_policy_type |
| 410 | #undef _ |
| 411 | mp->npolicies = htonl (n_policies); |
Matus Fabian | a9a0b2c | 2018-10-02 01:13:25 -0700 | [diff] [blame] | 412 | |
| 413 | vl_api_send_msg (reg, (u8 *) mp); |
| 414 | } |
| 415 | |
| 416 | static void |
| 417 | vl_api_ipsec_spds_dump_t_handler (vl_api_ipsec_spds_dump_t * mp) |
| 418 | { |
| 419 | vl_api_registration_t *reg; |
| 420 | ipsec_main_t *im = &ipsec_main; |
| 421 | ipsec_spd_t *spd; |
| 422 | #if WITH_LIBSSL > 0 |
| 423 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 424 | if (!reg) |
| 425 | return; |
| 426 | |
| 427 | /* *INDENT-OFF* */ |
| 428 | pool_foreach (spd, im->spds, ({ |
| 429 | send_ipsec_spds_details (spd, reg, mp->context); |
| 430 | })); |
| 431 | /* *INDENT-ON* */ |
| 432 | #else |
| 433 | clib_warning ("unimplemented"); |
| 434 | #endif |
| 435 | } |
| 436 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 437 | vl_api_ipsec_spd_action_t |
| 438 | ipsec_spd_action_encode (ipsec_policy_action_t in) |
| 439 | { |
| 440 | vl_api_ipsec_spd_action_t out = IPSEC_API_SPD_ACTION_BYPASS; |
| 441 | |
| 442 | switch (in) |
| 443 | { |
| 444 | #define _(v,f,s) case IPSEC_POLICY_ACTION_##f: \ |
| 445 | out = IPSEC_API_SPD_ACTION_##f; \ |
| 446 | break; |
| 447 | foreach_ipsec_policy_action |
| 448 | #undef _ |
| 449 | } |
| 450 | return (clib_host_to_net_u32 (out)); |
| 451 | } |
| 452 | |
Matus Fabian | a9a0b2c | 2018-10-02 01:13:25 -0700 | [diff] [blame] | 453 | static void |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 454 | send_ipsec_spd_details (ipsec_policy_t * p, vl_api_registration_t * reg, |
| 455 | u32 context) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 456 | { |
| 457 | vl_api_ipsec_spd_details_t *mp; |
| 458 | |
| 459 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 460 | clib_memset (mp, 0, sizeof (*mp)); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 461 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS); |
| 462 | mp->context = context; |
| 463 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 464 | mp->entry.spd_id = htonl (p->id); |
| 465 | mp->entry.priority = htonl (p->priority); |
Neale Ranns | 9f231d4 | 2019-03-19 10:06:00 +0000 | [diff] [blame] | 466 | mp->entry.is_outbound = ((p->type == IPSEC_SPD_POLICY_IP6_OUTBOUND) || |
| 467 | (p->type == IPSEC_SPD_POLICY_IP4_OUTBOUND)); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 468 | |
| 469 | ip_address_encode (&p->laddr.start, IP46_TYPE_ANY, |
| 470 | &mp->entry.local_address_start); |
| 471 | ip_address_encode (&p->laddr.stop, IP46_TYPE_ANY, |
| 472 | &mp->entry.local_address_stop); |
| 473 | ip_address_encode (&p->raddr.start, IP46_TYPE_ANY, |
| 474 | &mp->entry.remote_address_start); |
| 475 | ip_address_encode (&p->raddr.stop, IP46_TYPE_ANY, |
| 476 | &mp->entry.remote_address_stop); |
Neale Ranns | a4d2431 | 2019-07-10 13:46:21 +0000 | [diff] [blame] | 477 | mp->entry.local_port_start = htons (p->lport.start); |
| 478 | mp->entry.local_port_stop = htons (p->lport.stop); |
| 479 | mp->entry.remote_port_start = htons (p->rport.start); |
| 480 | mp->entry.remote_port_stop = htons (p->rport.stop); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 481 | mp->entry.protocol = p->protocol; |
| 482 | mp->entry.policy = ipsec_spd_action_encode (p->policy); |
| 483 | mp->entry.sa_id = htonl (p->sa_id); |
| 484 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 485 | vl_api_send_msg (reg, (u8 *) mp); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static void |
| 489 | vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp) |
| 490 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 491 | vl_api_registration_t *reg; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 492 | ipsec_main_t *im = &ipsec_main; |
Neale Ranns | 9f231d4 | 2019-03-19 10:06:00 +0000 | [diff] [blame] | 493 | ipsec_spd_policy_type_t ptype; |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 494 | ipsec_policy_t *policy; |
| 495 | ipsec_spd_t *spd; |
| 496 | uword *p; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 497 | u32 spd_index, *ii; |
Damjan Marion | a9a951f | 2017-01-16 22:06:10 +0100 | [diff] [blame] | 498 | #if WITH_LIBSSL > 0 |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 499 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 500 | if (!reg) |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 501 | return; |
| 502 | |
| 503 | p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id)); |
| 504 | if (!p) |
| 505 | return; |
| 506 | |
| 507 | spd_index = p[0]; |
| 508 | spd = pool_elt_at_index (im->spds, spd_index); |
| 509 | |
| 510 | /* *INDENT-OFF* */ |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 511 | FOR_EACH_IPSEC_SPD_POLICY_TYPE(ptype) { |
| 512 | vec_foreach(ii, spd->policies[ptype]) |
| 513 | { |
| 514 | policy = pool_elt_at_index(im->policies, *ii); |
| 515 | |
| 516 | if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id) |
| 517 | send_ipsec_spd_details (policy, reg, mp->context); |
| 518 | } |
| 519 | } |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 520 | /* *INDENT-ON* */ |
| 521 | #else |
| 522 | clib_warning ("unimplemented"); |
| 523 | #endif |
| 524 | } |
| 525 | |
| 526 | static void |
Filip Varga | 871bca9 | 2018-11-02 13:51:44 +0100 | [diff] [blame] | 527 | send_ipsec_spd_interface_details (vl_api_registration_t * reg, u32 spd_index, |
| 528 | u32 sw_if_index, u32 context) |
| 529 | { |
| 530 | vl_api_ipsec_spd_interface_details_t *mp; |
| 531 | |
| 532 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 533 | clib_memset (mp, 0, sizeof (*mp)); |
| 534 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_INTERFACE_DETAILS); |
| 535 | mp->context = context; |
| 536 | |
| 537 | mp->spd_index = htonl (spd_index); |
| 538 | mp->sw_if_index = htonl (sw_if_index); |
| 539 | |
| 540 | vl_api_send_msg (reg, (u8 *) mp); |
| 541 | } |
| 542 | |
| 543 | static void |
| 544 | vl_api_ipsec_spd_interface_dump_t_handler (vl_api_ipsec_spd_interface_dump_t * |
| 545 | mp) |
| 546 | { |
| 547 | ipsec_main_t *im = &ipsec_main; |
| 548 | vl_api_registration_t *reg; |
| 549 | u32 k, v, spd_index; |
| 550 | |
| 551 | #if WITH_LIBSSL > 0 |
| 552 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 553 | if (!reg) |
| 554 | return; |
| 555 | |
| 556 | if (mp->spd_index_valid) |
| 557 | { |
| 558 | spd_index = ntohl (mp->spd_index); |
| 559 | /* *INDENT-OFF* */ |
| 560 | hash_foreach(k, v, im->spd_index_by_sw_if_index, ({ |
| 561 | if (v == spd_index) |
| 562 | send_ipsec_spd_interface_details(reg, v, k, mp->context); |
| 563 | })); |
| 564 | /* *INDENT-ON* */ |
| 565 | } |
| 566 | else |
| 567 | { |
| 568 | /* *INDENT-OFF* */ |
| 569 | hash_foreach(k, v, im->spd_index_by_sw_if_index, ({ |
| 570 | send_ipsec_spd_interface_details(reg, v, k, mp->context); |
| 571 | })); |
| 572 | /* *INDENT-ON* */ |
| 573 | } |
| 574 | |
| 575 | #else |
| 576 | clib_warning ("unimplemented"); |
| 577 | #endif |
| 578 | } |
| 579 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 580 | static u32 |
| 581 | ipsec_tun_mk_input_sa_id (u32 ti) |
| 582 | { |
| 583 | return (0x80000000 | ti); |
| 584 | } |
| 585 | |
| 586 | static u32 |
| 587 | ipsec_tun_mk_output_sa_id (u32 ti) |
| 588 | { |
| 589 | return (0xc0000000 | ti); |
| 590 | } |
| 591 | |
Filip Varga | 871bca9 | 2018-11-02 13:51:44 +0100 | [diff] [blame] | 592 | static void |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 593 | vl_api_ipsec_tunnel_if_add_del_t_handler (vl_api_ipsec_tunnel_if_add_del_t * |
| 594 | mp) |
| 595 | { |
| 596 | vl_api_ipsec_tunnel_if_add_del_reply_t *rmp; |
Matthew Smith | e04d09d | 2017-05-14 21:47:18 -0500 | [diff] [blame] | 597 | u32 sw_if_index = ~0; |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 598 | int rv; |
| 599 | |
| 600 | #if WITH_LIBSSL > 0 |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 601 | ip46_address_t local_ip = ip46_address_initializer; |
| 602 | ip46_address_t remote_ip = ip46_address_initializer; |
| 603 | ipsec_key_t crypto_key, integ_key; |
| 604 | ipsec_sa_flags_t flags; |
| 605 | ip46_type_t local_ip_type, remote_ip_type; |
| 606 | ipip_transport_t transport; |
| 607 | u32 fib_index; |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 608 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 609 | local_ip_type = ip_address_decode (&mp->local_ip, &local_ip); |
| 610 | remote_ip_type = ip_address_decode (&mp->remote_ip, &remote_ip); |
| 611 | transport = (IP46_TYPE_IP6 == local_ip_type ? |
| 612 | IPIP_TRANSPORT_IP6 : IPIP_TRANSPORT_IP4); |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 613 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 614 | if (local_ip_type != remote_ip_type) |
| 615 | { |
| 616 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 617 | goto done; |
| 618 | } |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 619 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 620 | flags = IPSEC_SA_FLAG_NONE; |
| 621 | |
| 622 | if (mp->udp_encap) |
| 623 | flags |= IPSEC_SA_FLAG_UDP_ENCAP; |
| 624 | if (mp->esn) |
| 625 | flags |= IPSEC_SA_FLAG_USE_ESN; |
| 626 | if (mp->anti_replay) |
| 627 | flags |= IPSEC_SA_FLAG_USE_ANTI_REPLAY; |
| 628 | |
| 629 | ipsec_mk_key (&crypto_key, mp->remote_crypto_key, |
| 630 | mp->remote_crypto_key_len); |
| 631 | ipsec_mk_key (&integ_key, mp->remote_integ_key, mp->remote_integ_key_len); |
| 632 | ipsec_mk_key (&crypto_key, mp->local_crypto_key, mp->local_crypto_key_len); |
| 633 | ipsec_mk_key (&integ_key, mp->local_integ_key, mp->local_integ_key_len); |
| 634 | |
| 635 | fib_index = |
| 636 | fib_table_find (fib_proto_from_ip46 (local_ip_type), |
| 637 | ntohl (mp->tx_table_id)); |
| 638 | |
| 639 | if (~0 == fib_index) |
| 640 | { |
| 641 | rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 642 | goto done; |
| 643 | } |
| 644 | |
| 645 | if (mp->is_add) |
| 646 | { |
| 647 | // remote = input, local = output |
| 648 | /* create an ip-ip tunnel, then the two SA, then bind them */ |
| 649 | rv = ipip_add_tunnel (transport, |
Neale Ranns | a548d13 | 2019-11-20 08:34:58 +0000 | [diff] [blame] | 650 | (mp->renumber ? ntohl (mp->show_instance) : ~0), |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 651 | &local_ip, |
Neale Ranns | 9534696 | 2019-11-25 13:04:44 +0000 | [diff] [blame] | 652 | &remote_ip, fib_index, |
Neale Ranns | 59ff918 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 653 | TUNNEL_ENCAP_DECAP_FLAG_NONE, IP_DSCP_CS0, |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 654 | TUNNEL_MODE_P2P, &sw_if_index); |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 655 | |
| 656 | if (rv) |
| 657 | goto done; |
| 658 | |
| 659 | rv = ipsec_sa_add_and_lock (ipsec_tun_mk_input_sa_id (sw_if_index), |
| 660 | ntohl (mp->remote_spi), |
| 661 | IPSEC_PROTOCOL_ESP, |
| 662 | mp->crypto_alg, |
| 663 | &crypto_key, |
| 664 | mp->integ_alg, |
| 665 | &integ_key, |
| 666 | (flags | IPSEC_SA_FLAG_IS_INBOUND), |
| 667 | ntohl (mp->tx_table_id), |
Filip Tehlar | e5d3491 | 2020-03-02 15:17:37 +0000 | [diff] [blame] | 668 | mp->salt, &remote_ip, &local_ip, NULL, |
Neale Ranns | abc5660 | 2020-04-01 09:45:23 +0000 | [diff] [blame] | 669 | IPSEC_UDP_PORT_NONE, IPSEC_UDP_PORT_NONE); |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 670 | |
| 671 | if (rv) |
| 672 | goto done; |
| 673 | |
| 674 | rv = ipsec_sa_add_and_lock (ipsec_tun_mk_output_sa_id (sw_if_index), |
| 675 | ntohl (mp->local_spi), |
| 676 | IPSEC_PROTOCOL_ESP, |
| 677 | mp->crypto_alg, |
| 678 | &crypto_key, |
| 679 | mp->integ_alg, |
| 680 | &integ_key, |
| 681 | flags, |
| 682 | ntohl (mp->tx_table_id), |
Filip Tehlar | e5d3491 | 2020-03-02 15:17:37 +0000 | [diff] [blame] | 683 | mp->salt, &local_ip, &remote_ip, NULL, |
Neale Ranns | abc5660 | 2020-04-01 09:45:23 +0000 | [diff] [blame] | 684 | IPSEC_UDP_PORT_NONE, IPSEC_UDP_PORT_NONE); |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 685 | |
| 686 | if (rv) |
| 687 | goto done; |
| 688 | |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 689 | rv = ipsec_tun_protect_update_one (sw_if_index, NULL, |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 690 | ipsec_tun_mk_output_sa_id |
| 691 | (sw_if_index), |
| 692 | ipsec_tun_mk_input_sa_id |
| 693 | (sw_if_index)); |
| 694 | if (rv) |
| 695 | goto done; |
| 696 | |
| 697 | /* the SAs are locked as a result of being used for proection, |
| 698 | * they cannot be removed from the API, since they cannot be refered |
| 699 | * to by the API. unlock them now, so that if the tunnel is rekeyed |
| 700 | * they-ll disapper |
| 701 | */ |
| 702 | ipsec_sa_unlock_id (ipsec_tun_mk_input_sa_id (sw_if_index)); |
| 703 | ipsec_sa_unlock_id (ipsec_tun_mk_output_sa_id (sw_if_index)); |
| 704 | } |
| 705 | else |
| 706 | { |
Neale Ranns | d14fccd | 2019-11-15 15:03:27 +0000 | [diff] [blame] | 707 | /* *INDENT-OFF* */ |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 708 | ipip_tunnel_key_t key = { |
| 709 | .transport = transport, |
| 710 | .fib_index = fib_index, |
| 711 | .src = local_ip, |
| 712 | .dst = remote_ip |
| 713 | }; |
Neale Ranns | d14fccd | 2019-11-15 15:03:27 +0000 | [diff] [blame] | 714 | /* *INDENT-ON* */ |
| 715 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 716 | ipip_tunnel_t *t = ipip_tunnel_db_find (&key); |
| 717 | |
Neale Ranns | d14fccd | 2019-11-15 15:03:27 +0000 | [diff] [blame] | 718 | if (NULL != t) |
| 719 | { |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 720 | rv = ipsec_tun_protect_del (t->sw_if_index, NULL); |
Neale Ranns | d14fccd | 2019-11-15 15:03:27 +0000 | [diff] [blame] | 721 | ipip_del_tunnel (t->sw_if_index); |
| 722 | } |
| 723 | else |
| 724 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 725 | } |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 726 | |
| 727 | #else |
| 728 | rv = VNET_API_ERROR_UNIMPLEMENTED; |
| 729 | #endif |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 730 | done: |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 731 | /* *INDENT-OFF* */ |
| 732 | REPLY_MACRO2 (VL_API_IPSEC_TUNNEL_IF_ADD_DEL_REPLY, |
| 733 | ({ |
| 734 | rmp->sw_if_index = htonl (sw_if_index); |
| 735 | })); |
| 736 | /* *INDENT-ON* */ |
Matthew Smith | b0972cb | 2017-05-02 16:20:41 -0500 | [diff] [blame] | 737 | } |
| 738 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 739 | typedef struct ipsec_sa_dump_match_ctx_t_ |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 740 | { |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 741 | index_t sai; |
| 742 | u32 sw_if_index; |
| 743 | } ipsec_sa_dump_match_ctx_t; |
| 744 | |
| 745 | static walk_rc_t |
| 746 | ipsec_sa_dump_match_sa (index_t itpi, void *arg) |
| 747 | { |
| 748 | ipsec_sa_dump_match_ctx_t *ctx = arg; |
| 749 | ipsec_tun_protect_t *itp; |
| 750 | index_t sai; |
| 751 | |
| 752 | itp = ipsec_tun_protect_get (itpi); |
| 753 | |
| 754 | if (itp->itp_out_sa == ctx->sai) |
| 755 | { |
| 756 | ctx->sw_if_index = itp->itp_sw_if_index; |
| 757 | return (WALK_STOP); |
| 758 | } |
| 759 | /* *INDENT-OFF* */ |
| 760 | FOR_EACH_IPSEC_PROTECT_INPUT_SAI (itp, sai, |
| 761 | ({ |
| 762 | if (sai == ctx->sai) |
| 763 | { |
| 764 | ctx->sw_if_index = itp->itp_sw_if_index; |
| 765 | return (WALK_STOP); |
| 766 | } |
| 767 | })); |
| 768 | /* *INDENT-OFF* */ |
| 769 | |
| 770 | return (WALK_CONTINUE); |
| 771 | } |
| 772 | |
| 773 | static walk_rc_t |
| 774 | send_ipsec_sa_details (ipsec_sa_t * sa, void *arg) |
| 775 | { |
| 776 | ipsec_dump_walk_ctx_t *ctx = arg; |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 777 | vl_api_ipsec_sa_details_t *mp; |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 778 | ipsec_main_t *im = &ipsec_main; |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 779 | |
| 780 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 781 | clib_memset (mp, 0, sizeof (*mp)); |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 782 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_SA_DETAILS); |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 783 | mp->context = ctx->context; |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 784 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 785 | mp->entry.sad_id = htonl (sa->id); |
| 786 | mp->entry.spi = htonl (sa->spi); |
| 787 | mp->entry.protocol = ipsec_proto_encode (sa->protocol); |
| 788 | mp->entry.tx_table_id = |
| 789 | htonl (fib_table_get_table_id (sa->tx_fib_index, FIB_PROTOCOL_IP4)); |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 790 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 791 | mp->entry.crypto_algorithm = ipsec_crypto_algo_encode (sa->crypto_alg); |
| 792 | ipsec_key_encode (&sa->crypto_key, &mp->entry.crypto_key); |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 793 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 794 | mp->entry.integrity_algorithm = ipsec_integ_algo_encode (sa->integ_alg); |
| 795 | ipsec_key_encode (&sa->integ_key, &mp->entry.integrity_key); |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 796 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 797 | mp->entry.flags = ipsec_sad_flags_encode (sa); |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 798 | mp->entry.salt = clib_host_to_net_u32 (sa->salt); |
| 799 | |
| 800 | if (ipsec_sa_is_set_IS_PROTECT (sa)) |
| 801 | { |
| 802 | ipsec_sa_dump_match_ctx_t ctx = { |
| 803 | .sai = sa - im->sad, |
| 804 | .sw_if_index = ~0, |
| 805 | }; |
| 806 | ipsec_tun_protect_walk (ipsec_sa_dump_match_sa, &ctx); |
| 807 | |
| 808 | mp->sw_if_index = htonl (ctx.sw_if_index); |
| 809 | } |
| 810 | else |
| 811 | mp->sw_if_index = ~0; |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 812 | |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 813 | if (ipsec_sa_is_set_IS_TUNNEL (sa)) |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 814 | { |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 815 | ip_address_encode (&sa->tunnel_src_addr, IP46_TYPE_ANY, |
| 816 | &mp->entry.tunnel_src); |
| 817 | ip_address_encode (&sa->tunnel_dst_addr, IP46_TYPE_ANY, |
| 818 | &mp->entry.tunnel_dst); |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 819 | } |
Neale Ranns | abc5660 | 2020-04-01 09:45:23 +0000 | [diff] [blame] | 820 | if (ipsec_sa_is_set_UDP_ENCAP (sa)) |
| 821 | { |
| 822 | mp->entry.udp_src_port = sa->udp_hdr.src_port; |
| 823 | mp->entry.udp_dst_port = sa->udp_hdr.dst_port; |
| 824 | } |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 825 | |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 826 | mp->seq_outbound = clib_host_to_net_u64 (((u64) sa->seq)); |
| 827 | mp->last_seq_inbound = clib_host_to_net_u64 (((u64) sa->last_seq)); |
Damjan Marion | 1e3aa5e | 2019-03-28 10:58:59 +0100 | [diff] [blame] | 828 | if (ipsec_sa_is_set_USE_ESN (sa)) |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 829 | { |
| 830 | mp->seq_outbound |= (u64) (clib_host_to_net_u32 (sa->seq_hi)); |
| 831 | mp->last_seq_inbound |= (u64) (clib_host_to_net_u32 (sa->last_seq_hi)); |
| 832 | } |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 833 | if (ipsec_sa_is_set_USE_ANTI_REPLAY (sa)) |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 834 | mp->replay_window = clib_host_to_net_u64 (sa->replay_window); |
Pierre Pfister | 4c422f9 | 2018-12-10 11:19:08 +0100 | [diff] [blame] | 835 | |
Matthew Smith | 48d32b4 | 2020-04-02 07:45:49 -0500 | [diff] [blame] | 836 | mp->stat_index = clib_host_to_net_u32 (sa->stat_index); |
| 837 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 838 | vl_api_send_msg (ctx->reg, (u8 *) mp); |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 839 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 840 | return (WALK_CONTINUE); |
| 841 | } |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 842 | |
| 843 | static void |
| 844 | vl_api_ipsec_sa_dump_t_handler (vl_api_ipsec_sa_dump_t * mp) |
| 845 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 846 | vl_api_registration_t *reg; |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 847 | |
| 848 | #if WITH_LIBSSL > 0 |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 849 | reg = vl_api_client_index_to_registration (mp->client_index); |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 850 | if (!reg) |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 851 | return; |
| 852 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 853 | ipsec_dump_walk_ctx_t ctx = { |
| 854 | .reg = reg, |
| 855 | .context = mp->context, |
| 856 | }; |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 857 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 858 | ipsec_sa_walk (send_ipsec_sa_details, &ctx); |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 859 | |
Matthew Smith | 2802953 | 2017-09-26 13:33:44 -0500 | [diff] [blame] | 860 | #else |
| 861 | clib_warning ("unimplemented"); |
| 862 | #endif |
| 863 | } |
| 864 | |
Matthew Smith | 75d8560 | 2017-10-05 19:03:05 -0500 | [diff] [blame] | 865 | static void |
Matthew Smith | ca514fd | 2017-10-12 12:06:59 -0500 | [diff] [blame] | 866 | vl_api_ipsec_tunnel_if_set_sa_t_handler (vl_api_ipsec_tunnel_if_set_sa_t * mp) |
| 867 | { |
| 868 | vl_api_ipsec_tunnel_if_set_sa_reply_t *rmp; |
Matthew Smith | ca514fd | 2017-10-12 12:06:59 -0500 | [diff] [blame] | 869 | int rv; |
| 870 | |
| 871 | #if WITH_LIBSSL > 0 |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 872 | VALIDATE_SW_IF_INDEX(mp); |
Matthew Smith | ca514fd | 2017-10-12 12:06:59 -0500 | [diff] [blame] | 873 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 874 | if (mp->is_outbound) |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 875 | rv = ipsec_tun_protect_update_out (ntohl (mp->sw_if_index), NULL, |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 876 | ntohl (mp->sa_id)); |
| 877 | else |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 878 | rv = ipsec_tun_protect_update_in (ntohl (mp->sw_if_index), NULL, |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 879 | ntohl (mp->sa_id)); |
| 880 | |
Matthew Smith | ca514fd | 2017-10-12 12:06:59 -0500 | [diff] [blame] | 881 | #else |
| 882 | clib_warning ("unimplemented"); |
| 883 | #endif |
| 884 | |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 885 | BAD_SW_IF_INDEX_LABEL; |
| 886 | |
Matthew Smith | ca514fd | 2017-10-12 12:06:59 -0500 | [diff] [blame] | 887 | REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_SA_REPLY); |
| 888 | } |
| 889 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 890 | static void |
| 891 | vl_api_ipsec_backend_dump_t_handler (vl_api_ipsec_backend_dump_t * mp) |
| 892 | { |
| 893 | vl_api_registration_t *rp; |
| 894 | ipsec_main_t *im = &ipsec_main; |
| 895 | u32 context = mp->context; |
| 896 | |
| 897 | rp = vl_api_client_index_to_registration (mp->client_index); |
| 898 | |
| 899 | if (rp == 0) |
| 900 | { |
| 901 | clib_warning ("Client %d AWOL", mp->client_index); |
| 902 | return; |
| 903 | } |
| 904 | |
| 905 | ipsec_ah_backend_t *ab; |
| 906 | ipsec_esp_backend_t *eb; |
| 907 | /* *INDENT-OFF* */ |
| 908 | pool_foreach (ab, im->ah_backends, { |
| 909 | vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp)); |
| 910 | clib_memset (mp, 0, sizeof (*mp)); |
| 911 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS); |
| 912 | mp->context = context; |
| 913 | snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (ab->name), |
| 914 | ab->name); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 915 | mp->protocol = ntohl (IPSEC_API_PROTO_AH); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 916 | mp->index = ab - im->ah_backends; |
| 917 | mp->active = mp->index == im->ah_current_backend ? 1 : 0; |
| 918 | vl_api_send_msg (rp, (u8 *)mp); |
| 919 | }); |
| 920 | pool_foreach (eb, im->esp_backends, { |
| 921 | vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp)); |
| 922 | clib_memset (mp, 0, sizeof (*mp)); |
| 923 | mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS); |
| 924 | mp->context = context; |
| 925 | snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (eb->name), |
| 926 | eb->name); |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 927 | mp->protocol = ntohl (IPSEC_API_PROTO_ESP); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 928 | mp->index = eb - im->esp_backends; |
| 929 | mp->active = mp->index == im->esp_current_backend ? 1 : 0; |
| 930 | vl_api_send_msg (rp, (u8 *)mp); |
| 931 | }); |
| 932 | /* *INDENT-ON* */ |
| 933 | } |
| 934 | |
| 935 | static void |
| 936 | vl_api_ipsec_select_backend_t_handler (vl_api_ipsec_select_backend_t * mp) |
| 937 | { |
| 938 | ipsec_main_t *im = &ipsec_main; |
| 939 | vl_api_ipsec_select_backend_reply_t *rmp; |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 940 | ipsec_protocol_t protocol; |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 941 | int rv = 0; |
| 942 | if (pool_elts (im->sad) > 0) |
| 943 | { |
| 944 | rv = VNET_API_ERROR_INSTANCE_IN_USE; |
| 945 | goto done; |
| 946 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 947 | |
| 948 | rv = ipsec_proto_decode (mp->protocol, &protocol); |
| 949 | |
| 950 | if (rv) |
| 951 | goto done; |
| 952 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 953 | #if WITH_LIBSSL > 0 |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 954 | switch (protocol) |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 955 | { |
| 956 | case IPSEC_PROTOCOL_ESP: |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 957 | rv = ipsec_select_esp_backend (im, mp->index); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 958 | break; |
| 959 | case IPSEC_PROTOCOL_AH: |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 960 | rv = ipsec_select_ah_backend (im, mp->index); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 961 | break; |
| 962 | default: |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 963 | rv = VNET_API_ERROR_INVALID_PROTOCOL; |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 964 | break; |
| 965 | } |
| 966 | #else |
| 967 | clib_warning ("unimplemented"); /* FIXME */ |
| 968 | #endif |
| 969 | done: |
| 970 | REPLY_MACRO (VL_API_IPSEC_SELECT_BACKEND_REPLY); |
| 971 | } |
| 972 | |
Neale Ranns | 7c44d78 | 2019-02-25 10:28:29 +0000 | [diff] [blame] | 973 | /* |
| 974 | * ipsec_api_hookup |
| 975 | * Add vpe's API message handlers to the table. |
| 976 | * vlib has already mapped shared memory and |
| 977 | * added the client registration handlers. |
| 978 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 979 | */ |
| 980 | #define vl_msg_name_crc_list |
| 981 | #include <vnet/vnet_all_api_h.h> |
| 982 | #undef vl_msg_name_crc_list |
| 983 | |
| 984 | static void |
| 985 | setup_message_id_table (api_main_t * am) |
| 986 | { |
| 987 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 988 | foreach_vl_msg_name_crc_ipsec; |
| 989 | #undef _ |
| 990 | } |
| 991 | |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 992 | static clib_error_t * |
| 993 | ipsec_api_hookup (vlib_main_t * vm) |
| 994 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 995 | api_main_t *am = vlibapi_get_main (); |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 996 | |
| 997 | #define _(N,n) \ |
| 998 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 999 | vl_api_##n##_t_handler, \ |
| 1000 | vl_noop_handler, \ |
| 1001 | vl_api_##n##_t_endian, \ |
| 1002 | vl_api_##n##_t_print, \ |
| 1003 | sizeof(vl_api_##n##_t), 1); |
| 1004 | foreach_vpe_api_msg; |
| 1005 | #undef _ |
| 1006 | |
| 1007 | /* |
Pavel Kotucek | 9c7ef03 | 2016-12-21 07:46:45 +0100 | [diff] [blame] | 1008 | * Set up the (msg_name, crc, message-id) table |
| 1009 | */ |
| 1010 | setup_message_id_table (am); |
| 1011 | |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | VLIB_API_INIT_FUNCTION (ipsec_api_hookup); |
| 1016 | |
| 1017 | /* |
| 1018 | * fd.io coding-style-patch-verification: ON |
| 1019 | * |
| 1020 | * Local Variables: |
| 1021 | * eval: (c-set-style "gnu") |
| 1022 | * End: |
| 1023 | */ |