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