Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * decap.c : IPSec tunnel support |
| 3 | * |
| 4 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <vnet/vnet.h> |
| 19 | #include <vnet/api_errno.h> |
| 20 | #include <vnet/ip/ip.h> |
| 21 | #include <vnet/interface.h> |
Pierre Pfister | 4c422f9 | 2018-12-10 11:19:08 +0100 | [diff] [blame] | 22 | #include <vnet/fib/fib.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 23 | |
| 24 | #include <vnet/ipsec/ipsec.h> |
| 25 | |
| 26 | static clib_error_t * |
| 27 | set_interface_spd_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 28 | unformat_input_t * input, |
| 29 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 30 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 31 | unformat_input_t _line_input, *line_input = &_line_input; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | ipsec_main_t *im = &ipsec_main; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 33 | u32 sw_if_index = (u32) ~ 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 34 | u32 spd_id; |
| 35 | int is_add = 1; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 36 | clib_error_t *error = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 37 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 38 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 39 | return 0; |
| 40 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 41 | if (unformat |
| 42 | (line_input, "%U %u", unformat_vnet_sw_interface, im->vnet_main, |
| 43 | &sw_if_index, &spd_id)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 44 | ; |
| 45 | else if (unformat (line_input, "del")) |
| 46 | is_add = 0; |
| 47 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 48 | { |
| 49 | error = clib_error_return (0, "parse error: '%U'", |
| 50 | format_unformat_error, line_input); |
| 51 | goto done; |
| 52 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 53 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 54 | ipsec_set_interface_spd (vm, sw_if_index, spd_id, is_add); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 56 | done: |
| 57 | unformat_free (line_input); |
| 58 | |
| 59 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 62 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | VLIB_CLI_COMMAND (set_interface_spd_command, static) = { |
| 64 | .path = "set interface ipsec spd", |
| 65 | .short_help = |
| 66 | "set interface ipsec spd <int> <id>", |
| 67 | .function = set_interface_spd_command_fn, |
| 68 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 69 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 70 | |
| 71 | static clib_error_t * |
| 72 | ipsec_sa_add_del_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 73 | unformat_input_t * input, |
| 74 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 76 | unformat_input_t _line_input, *line_input = &_line_input; |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 77 | ip46_address_t tun_src = { }, tun_dst = |
| 78 | { |
| 79 | }; |
| 80 | ipsec_crypto_alg_t crypto_alg; |
| 81 | ipsec_integ_alg_t integ_alg; |
| 82 | ipsec_protocol_t proto; |
| 83 | ipsec_sa_flags_t flags; |
| 84 | clib_error_t *error; |
Kingwel Xie | d3d1205 | 2019-03-07 06:34:30 -0500 | [diff] [blame] | 85 | ipsec_key_t ck = { 0 }; |
| 86 | ipsec_key_t ik = { 0 }; |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 87 | u32 id, spi, salt; |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 88 | int is_add, rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 89 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 90 | error = NULL; |
| 91 | is_add = 0; |
| 92 | flags = IPSEC_SA_FLAG_NONE; |
| 93 | proto = IPSEC_PROTOCOL_ESP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 95 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 96 | return 0; |
| 97 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 98 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 99 | { |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 100 | if (unformat (line_input, "add %u", &id)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 101 | is_add = 1; |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 102 | else if (unformat (line_input, "del %u", &id)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 103 | is_add = 0; |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 104 | else if (unformat (line_input, "spi %u", &spi)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 105 | ; |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 106 | else if (unformat (line_input, "salt %u", &salt)) |
| 107 | ; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 108 | else if (unformat (line_input, "esp")) |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 109 | proto = IPSEC_PROTOCOL_ESP; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 110 | else if (unformat (line_input, "ah")) |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 111 | proto = IPSEC_PROTOCOL_AH; |
| 112 | else if (unformat (line_input, "crypto-key %U", |
| 113 | unformat_ipsec_key, &ck)) |
| 114 | ; |
| 115 | else if (unformat (line_input, "crypto-alg %U", |
| 116 | unformat_ipsec_crypto_alg, &crypto_alg)) |
| 117 | ; |
| 118 | else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik)) |
| 119 | ; |
| 120 | else if (unformat (line_input, "integ-alg %U", |
| 121 | unformat_ipsec_integ_alg, &integ_alg)) |
| 122 | ; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 123 | else if (unformat (line_input, "tunnel-src %U", |
Kingwel Xie | 72b3bce | 2019-02-12 06:45:08 -0500 | [diff] [blame] | 124 | unformat_ip46_address, &tun_src, IP46_TYPE_ANY)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 125 | { |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 126 | flags |= IPSEC_SA_FLAG_IS_TUNNEL; |
| 127 | if (!ip46_address_is_ip4 (&tun_src)) |
| 128 | flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 129 | } |
| 130 | else if (unformat (line_input, "tunnel-dst %U", |
Kingwel Xie | 72b3bce | 2019-02-12 06:45:08 -0500 | [diff] [blame] | 131 | unformat_ip46_address, &tun_dst, IP46_TYPE_ANY)) |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 132 | ; |
Radu Nicolau | 717de09 | 2018-08-03 10:37:24 +0100 | [diff] [blame] | 133 | else if (unformat (line_input, "udp-encap")) |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 134 | flags |= IPSEC_SA_FLAG_UDP_ENCAP; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 135 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 136 | { |
| 137 | error = clib_error_return (0, "parse error: '%U'", |
| 138 | format_unformat_error, line_input); |
| 139 | goto done; |
| 140 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 141 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 143 | if (is_add) |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 144 | rv = ipsec_sa_add (id, spi, proto, crypto_alg, |
| 145 | &ck, integ_alg, &ik, flags, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 146 | 0, clib_host_to_net_u32 (salt), |
| 147 | &tun_src, &tun_dst, NULL); |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 148 | else |
| 149 | rv = ipsec_sa_del (id); |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 150 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 151 | if (rv) |
| 152 | clib_error_return (0, "failed"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 153 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 154 | done: |
| 155 | unformat_free (line_input); |
| 156 | |
| 157 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 160 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 161 | VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = { |
| 162 | .path = "ipsec sa", |
| 163 | .short_help = |
| 164 | "ipsec sa [add|del]", |
| 165 | .function = ipsec_sa_add_del_command_fn, |
| 166 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 167 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 168 | |
| 169 | static clib_error_t * |
| 170 | ipsec_spd_add_del_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 171 | unformat_input_t * input, |
| 172 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 173 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 174 | unformat_input_t _line_input, *line_input = &_line_input; |
Damjan Marion | 3f54b18 | 2016-08-16 11:27:02 +0200 | [diff] [blame] | 175 | u32 spd_id = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 176 | int is_add = ~0; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 177 | clib_error_t *error = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 178 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 179 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 180 | return 0; |
| 181 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 182 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 183 | { |
| 184 | if (unformat (line_input, "add")) |
| 185 | is_add = 1; |
| 186 | else if (unformat (line_input, "del")) |
| 187 | is_add = 0; |
| 188 | else if (unformat (line_input, "%u", &spd_id)) |
| 189 | ; |
| 190 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 191 | { |
| 192 | error = clib_error_return (0, "parse error: '%U'", |
| 193 | format_unformat_error, line_input); |
| 194 | goto done; |
| 195 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 196 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 197 | |
Damjan Marion | 3f54b18 | 2016-08-16 11:27:02 +0200 | [diff] [blame] | 198 | if (spd_id == ~0) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 199 | { |
| 200 | error = clib_error_return (0, "please specify SPD ID"); |
| 201 | goto done; |
| 202 | } |
Damjan Marion | 3f54b18 | 2016-08-16 11:27:02 +0200 | [diff] [blame] | 203 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 204 | ipsec_add_del_spd (vm, spd_id, is_add); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 205 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 206 | done: |
| 207 | unformat_free (line_input); |
| 208 | |
| 209 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 212 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 213 | VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = { |
| 214 | .path = "ipsec spd", |
| 215 | .short_help = |
| 216 | "ipsec spd [add|del] <id>", |
| 217 | .function = ipsec_spd_add_del_command_fn, |
| 218 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 219 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 220 | |
| 221 | |
| 222 | static clib_error_t * |
| 223 | ipsec_policy_add_del_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 224 | unformat_input_t * input, |
| 225 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 226 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 227 | unformat_input_t _line_input, *line_input = &_line_input; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | ipsec_policy_t p; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 229 | int rv, is_add = 0; |
| 230 | u32 tmp, tmp2, stat_index; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 231 | clib_error_t *error = NULL; |
Neale Ranns | 9f231d4 | 2019-03-19 10:06:00 +0000 | [diff] [blame] | 232 | u32 is_outbound; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 234 | clib_memset (&p, 0, sizeof (p)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 235 | p.lport.stop = p.rport.stop = ~0; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 236 | p.laddr.stop.ip4.as_u32 = p.raddr.stop.ip4.as_u32 = (u32) ~ 0; |
| 237 | p.laddr.stop.ip6.as_u64[0] = p.laddr.stop.ip6.as_u64[1] = (u64) ~ 0; |
| 238 | p.raddr.stop.ip6.as_u64[0] = p.raddr.stop.ip6.as_u64[1] = (u64) ~ 0; |
Neale Ranns | 9f231d4 | 2019-03-19 10:06:00 +0000 | [diff] [blame] | 239 | is_outbound = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 241 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 242 | return 0; |
| 243 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 244 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 245 | { |
| 246 | if (unformat (line_input, "add")) |
| 247 | is_add = 1; |
| 248 | else if (unformat (line_input, "del")) |
| 249 | is_add = 0; |
| 250 | else if (unformat (line_input, "spd %u", &p.id)) |
| 251 | ; |
| 252 | else if (unformat (line_input, "inbound")) |
Neale Ranns | 9f231d4 | 2019-03-19 10:06:00 +0000 | [diff] [blame] | 253 | is_outbound = 0; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 254 | else if (unformat (line_input, "outbound")) |
Neale Ranns | 9f231d4 | 2019-03-19 10:06:00 +0000 | [diff] [blame] | 255 | is_outbound = 1; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 256 | else if (unformat (line_input, "priority %d", &p.priority)) |
| 257 | ; |
| 258 | else if (unformat (line_input, "protocol %u", &tmp)) |
| 259 | p.protocol = (u8) tmp; |
| 260 | else |
| 261 | if (unformat |
| 262 | (line_input, "action %U", unformat_ipsec_policy_action, |
| 263 | &p.policy)) |
| 264 | { |
| 265 | if (p.policy == IPSEC_POLICY_ACTION_RESOLVE) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 266 | { |
| 267 | error = clib_error_return (0, "unsupported action: 'resolve'"); |
| 268 | goto done; |
| 269 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 270 | } |
| 271 | else if (unformat (line_input, "sa %u", &p.sa_id)) |
| 272 | ; |
| 273 | else if (unformat (line_input, "local-ip-range %U - %U", |
| 274 | unformat_ip4_address, &p.laddr.start.ip4, |
| 275 | unformat_ip4_address, &p.laddr.stop.ip4)) |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 276 | ; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 277 | else if (unformat (line_input, "remote-ip-range %U - %U", |
| 278 | unformat_ip4_address, &p.raddr.start.ip4, |
| 279 | unformat_ip4_address, &p.raddr.stop.ip4)) |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 280 | ; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 281 | else if (unformat (line_input, "local-ip-range %U - %U", |
| 282 | unformat_ip6_address, &p.laddr.start.ip6, |
| 283 | unformat_ip6_address, &p.laddr.stop.ip6)) |
| 284 | { |
| 285 | p.is_ipv6 = 1; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 286 | } |
| 287 | else if (unformat (line_input, "remote-ip-range %U - %U", |
| 288 | unformat_ip6_address, &p.raddr.start.ip6, |
| 289 | unformat_ip6_address, &p.raddr.stop.ip6)) |
| 290 | { |
| 291 | p.is_ipv6 = 1; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 292 | } |
| 293 | else if (unformat (line_input, "local-port-range %u - %u", &tmp, &tmp2)) |
| 294 | { |
| 295 | p.lport.start = tmp; |
| 296 | p.lport.stop = tmp2; |
Neale Ranns | 231c469 | 2019-03-18 17:11:28 +0000 | [diff] [blame] | 297 | p.lport.start = clib_host_to_net_u16 (p.lport.start); |
| 298 | p.lport.stop = clib_host_to_net_u16 (p.lport.stop); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 299 | } |
| 300 | else |
| 301 | if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2)) |
| 302 | { |
| 303 | p.rport.start = tmp; |
| 304 | p.rport.stop = tmp2; |
Neale Ranns | 231c469 | 2019-03-18 17:11:28 +0000 | [diff] [blame] | 305 | p.rport.start = clib_host_to_net_u16 (p.rport.start); |
| 306 | p.rport.stop = clib_host_to_net_u16 (p.rport.stop); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 307 | } |
| 308 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 309 | { |
| 310 | error = clib_error_return (0, "parse error: '%U'", |
| 311 | format_unformat_error, line_input); |
| 312 | goto done; |
| 313 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 314 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 315 | |
Neale Ranns | 9f231d4 | 2019-03-19 10:06:00 +0000 | [diff] [blame] | 316 | rv = ipsec_policy_mk_type (is_outbound, p.is_ipv6, p.policy, &p.type); |
| 317 | |
| 318 | if (rv) |
| 319 | { |
| 320 | error = clib_error_return (0, "unsupported policy type for:", |
| 321 | " outboud:%s %s action:%U", |
| 322 | (is_outbound ? "yes" : "no"), |
| 323 | (p.is_ipv6 ? "IPv4" : "IPv6"), |
| 324 | format_ipsec_policy_action, p.policy); |
| 325 | goto done; |
| 326 | } |
| 327 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 328 | rv = ipsec_add_del_policy (vm, &p, is_add, &stat_index); |
| 329 | |
| 330 | if (!rv) |
| 331 | vlib_cli_output (vm, "policy-index:%d", stat_index); |
| 332 | else |
| 333 | vlib_cli_output (vm, "error:%d", rv); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 334 | |
| 335 | done: |
| 336 | unformat_free (line_input); |
| 337 | |
| 338 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 341 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 342 | VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = { |
| 343 | .path = "ipsec policy", |
| 344 | .short_help = |
| 345 | "ipsec policy [add|del] spd <id> priority <n> ", |
| 346 | .function = ipsec_policy_add_del_command_fn, |
| 347 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 348 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 349 | |
| 350 | static clib_error_t * |
| 351 | set_ipsec_sa_key_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 352 | unformat_input_t * input, |
| 353 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 354 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 355 | unformat_input_t _line_input, *line_input = &_line_input; |
Neale Ranns | 0224514 | 2019-05-13 23:07:43 -0700 | [diff] [blame] | 356 | ipsec_key_t ck = { }, ik = |
| 357 | { |
| 358 | }; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 359 | clib_error_t *error = NULL; |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 360 | u32 id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 361 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 362 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 363 | return 0; |
| 364 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 365 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 366 | { |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 367 | if (unformat (line_input, "%u", &id)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 368 | ; |
| 369 | else |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 370 | if (unformat (line_input, "crypto-key %U", unformat_ipsec_key, &ck)) |
| 371 | ; |
| 372 | else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik)) |
| 373 | ; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 374 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 375 | { |
| 376 | error = clib_error_return (0, "parse error: '%U'", |
| 377 | format_unformat_error, line_input); |
| 378 | goto done; |
| 379 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 380 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 381 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 382 | ipsec_set_sa_key (id, &ck, &ik); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 383 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 384 | done: |
| 385 | unformat_free (line_input); |
| 386 | |
| 387 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 390 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 391 | VLIB_CLI_COMMAND (set_ipsec_sa_key_command, static) = { |
| 392 | .path = "set ipsec sa", |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 393 | .short_help = "set ipsec sa <id> crypto-key <key> integ-key <key>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 394 | .function = set_ipsec_sa_key_command_fn, |
| 395 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 396 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 397 | |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 398 | static void |
| 399 | ipsec_sa_show_all (vlib_main_t * vm, ipsec_main_t * im) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 400 | { |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 401 | u32 sai; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 402 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 403 | /* *INDENT-OFF* */ |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 404 | pool_foreach_index (sai, im->sad, ({ |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 405 | vlib_cli_output(vm, "%U", format_ipsec_sa, sai, IPSEC_FORMAT_BRIEF); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 406 | })); |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 407 | /* *INDENT-ON* */ |
| 408 | } |
| 409 | |
| 410 | static void |
| 411 | ipsec_spd_show_all (vlib_main_t * vm, ipsec_main_t * im) |
| 412 | { |
| 413 | u32 spdi; |
| 414 | |
| 415 | /* *INDENT-OFF* */ |
| 416 | pool_foreach_index (spdi, im->spds, ({ |
| 417 | vlib_cli_output(vm, "%U", format_ipsec_spd, spdi); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 418 | })); |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 419 | /* *INDENT-ON* */ |
| 420 | } |
| 421 | |
| 422 | static void |
| 423 | ipsec_spd_bindings_show_all (vlib_main_t * vm, ipsec_main_t * im) |
| 424 | { |
| 425 | u32 spd_id, sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 426 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 427 | vlib_cli_output (vm, "SPD Bindings:"); |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 428 | |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 429 | /* *INDENT-OFF* */ |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 430 | hash_foreach(sw_if_index, spd_id, im->spd_index_by_sw_if_index, ({ |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 431 | vlib_cli_output (vm, " %d -> %U", spd_id, |
| 432 | format_vnet_sw_if_index_name, im->vnet_main, |
| 433 | sw_if_index); |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 434 | })); |
| 435 | /* *INDENT-ON* */ |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 436 | } |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 437 | |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 438 | static void |
| 439 | ipsec_tunnel_show_all (vlib_main_t * vm, ipsec_main_t * im) |
| 440 | { |
| 441 | u32 ti; |
| 442 | |
| 443 | vlib_cli_output (vm, "Tunnel interfaces"); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 444 | /* *INDENT-OFF* */ |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 445 | pool_foreach_index (ti, im->tunnel_interfaces, ({ |
| 446 | vlib_cli_output(vm, " %U", format_ipsec_tunnel, ti); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 447 | })); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 448 | /* *INDENT-ON* */ |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | static clib_error_t * |
| 452 | show_ipsec_command_fn (vlib_main_t * vm, |
| 453 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 454 | { |
| 455 | ipsec_main_t *im = &ipsec_main; |
| 456 | |
| 457 | ipsec_sa_show_all (vm, im); |
| 458 | ipsec_spd_show_all (vm, im); |
| 459 | ipsec_spd_bindings_show_all (vm, im); |
| 460 | ipsec_tunnel_show_all (vm, im); |
| 461 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 462 | return 0; |
| 463 | } |
| 464 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 465 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 466 | VLIB_CLI_COMMAND (show_ipsec_command, static) = { |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 467 | .path = "show ipsec all", |
| 468 | .short_help = "show ipsec all", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 469 | .function = show_ipsec_command_fn, |
| 470 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 471 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 472 | |
| 473 | static clib_error_t * |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 474 | show_ipsec_sa_command_fn (vlib_main_t * vm, |
| 475 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 476 | { |
| 477 | ipsec_main_t *im = &ipsec_main; |
| 478 | u32 sai = ~0; |
| 479 | |
| 480 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 481 | { |
| 482 | if (unformat (input, "%u", &sai)) |
| 483 | ; |
| 484 | else |
| 485 | break; |
| 486 | } |
| 487 | |
| 488 | if (~0 == sai) |
| 489 | ipsec_sa_show_all (vm, im); |
| 490 | else |
| 491 | vlib_cli_output (vm, "%U", format_ipsec_sa, sai, IPSEC_FORMAT_DETAIL); |
| 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | /* *INDENT-OFF* */ |
| 497 | VLIB_CLI_COMMAND (show_ipsec_sa_command, static) = { |
| 498 | .path = "show ipsec sa", |
| 499 | .short_help = "show ipsec sa [index]", |
| 500 | .function = show_ipsec_sa_command_fn, |
| 501 | }; |
| 502 | /* *INDENT-ON* */ |
| 503 | |
| 504 | static clib_error_t * |
| 505 | show_ipsec_spd_command_fn (vlib_main_t * vm, |
| 506 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 507 | { |
| 508 | ipsec_main_t *im = &ipsec_main; |
| 509 | u8 show_bindings = 0; |
| 510 | u32 spdi = ~0; |
| 511 | |
| 512 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 513 | { |
| 514 | if (unformat (input, "%u", &spdi)) |
| 515 | ; |
| 516 | else if (unformat (input, "bindings")) |
| 517 | show_bindings = 1; |
| 518 | else |
| 519 | break; |
| 520 | } |
| 521 | |
| 522 | if (show_bindings) |
| 523 | ipsec_spd_bindings_show_all (vm, im); |
| 524 | else if (~0 != spdi) |
| 525 | vlib_cli_output (vm, "%U", format_ipsec_spd, spdi); |
| 526 | else |
| 527 | ipsec_spd_show_all (vm, im); |
| 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | /* *INDENT-OFF* */ |
| 533 | VLIB_CLI_COMMAND (show_ipsec_spd_command, static) = { |
| 534 | .path = "show ipsec spd", |
| 535 | .short_help = "show ipsec spd [index]", |
| 536 | .function = show_ipsec_spd_command_fn, |
| 537 | }; |
| 538 | /* *INDENT-ON* */ |
| 539 | |
| 540 | static clib_error_t * |
| 541 | show_ipsec_tunnel_command_fn (vlib_main_t * vm, |
| 542 | unformat_input_t * input, |
| 543 | vlib_cli_command_t * cmd) |
| 544 | { |
| 545 | ipsec_main_t *im = &ipsec_main; |
| 546 | u32 ti = ~0; |
| 547 | |
| 548 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 549 | { |
| 550 | if (unformat (input, "%u", &ti)) |
| 551 | ; |
| 552 | else |
| 553 | break; |
| 554 | } |
| 555 | |
| 556 | if (~0 != ti) |
| 557 | vlib_cli_output (vm, "%U", format_ipsec_tunnel, ti); |
| 558 | else |
| 559 | ipsec_tunnel_show_all (vm, im); |
| 560 | |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | /* *INDENT-OFF* */ |
| 565 | VLIB_CLI_COMMAND (show_ipsec_tunnel_command, static) = { |
| 566 | .path = "show ipsec tunnel", |
| 567 | .short_help = "show ipsec tunnel [index]", |
| 568 | .function = show_ipsec_tunnel_command_fn, |
| 569 | }; |
| 570 | /* *INDENT-ON* */ |
| 571 | |
| 572 | static clib_error_t * |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 573 | ipsec_show_backends_command_fn (vlib_main_t * vm, |
| 574 | unformat_input_t * input, |
| 575 | vlib_cli_command_t * cmd) |
| 576 | { |
| 577 | ipsec_main_t *im = &ipsec_main; |
| 578 | u32 verbose = 0; |
| 579 | |
| 580 | (void) unformat (input, "verbose %u", &verbose); |
| 581 | |
| 582 | vlib_cli_output (vm, "IPsec AH backends available:"); |
| 583 | u8 *s = format (NULL, "%=25s %=25s %=10s\n", "Name", "Index", "Active"); |
| 584 | ipsec_ah_backend_t *ab; |
| 585 | /* *INDENT-OFF* */ |
| 586 | pool_foreach (ab, im->ah_backends, { |
| 587 | s = format (s, "%=25s %=25u %=10s\n", ab->name, ab - im->ah_backends, |
| 588 | ab - im->ah_backends == im->ah_current_backend ? "yes" : "no"); |
| 589 | if (verbose) { |
| 590 | vlib_node_t *n; |
| 591 | n = vlib_get_node (vm, ab->ah4_encrypt_node_index); |
| 592 | s = format (s, " enc4 %s (next %d)\n", n->name, ab->ah4_encrypt_next_index); |
| 593 | n = vlib_get_node (vm, ab->ah4_decrypt_node_index); |
| 594 | s = format (s, " dec4 %s (next %d)\n", n->name, ab->ah4_decrypt_next_index); |
| 595 | n = vlib_get_node (vm, ab->ah6_encrypt_node_index); |
| 596 | s = format (s, " enc6 %s (next %d)\n", n->name, ab->ah6_encrypt_next_index); |
| 597 | n = vlib_get_node (vm, ab->ah6_decrypt_node_index); |
| 598 | s = format (s, " dec6 %s (next %d)\n", n->name, ab->ah6_decrypt_next_index); |
| 599 | } |
| 600 | }); |
| 601 | /* *INDENT-ON* */ |
| 602 | vlib_cli_output (vm, "%v", s); |
| 603 | _vec_len (s) = 0; |
| 604 | vlib_cli_output (vm, "IPsec ESP backends available:"); |
| 605 | s = format (s, "%=25s %=25s %=10s\n", "Name", "Index", "Active"); |
| 606 | ipsec_esp_backend_t *eb; |
| 607 | /* *INDENT-OFF* */ |
| 608 | pool_foreach (eb, im->esp_backends, { |
| 609 | s = format (s, "%=25s %=25u %=10s\n", eb->name, eb - im->esp_backends, |
| 610 | eb - im->esp_backends == im->esp_current_backend ? "yes" |
| 611 | : "no"); |
| 612 | if (verbose) { |
| 613 | vlib_node_t *n; |
| 614 | n = vlib_get_node (vm, eb->esp4_encrypt_node_index); |
| 615 | s = format (s, " enc4 %s (next %d)\n", n->name, eb->esp4_encrypt_next_index); |
| 616 | n = vlib_get_node (vm, eb->esp4_decrypt_node_index); |
| 617 | s = format (s, " dec4 %s (next %d)\n", n->name, eb->esp4_decrypt_next_index); |
| 618 | n = vlib_get_node (vm, eb->esp6_encrypt_node_index); |
| 619 | s = format (s, " enc6 %s (next %d)\n", n->name, eb->esp6_encrypt_next_index); |
| 620 | n = vlib_get_node (vm, eb->esp6_decrypt_node_index); |
| 621 | s = format (s, " dec6 %s (next %d)\n", n->name, eb->esp6_decrypt_next_index); |
| 622 | } |
| 623 | }); |
| 624 | /* *INDENT-ON* */ |
| 625 | vlib_cli_output (vm, "%v", s); |
| 626 | |
| 627 | vec_free (s); |
| 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | /* *INDENT-OFF* */ |
| 632 | VLIB_CLI_COMMAND (ipsec_show_backends_command, static) = { |
| 633 | .path = "show ipsec backends", |
| 634 | .short_help = "show ipsec backends", |
| 635 | .function = ipsec_show_backends_command_fn, |
| 636 | }; |
| 637 | /* *INDENT-ON* */ |
| 638 | |
| 639 | static clib_error_t * |
| 640 | ipsec_select_backend_command_fn (vlib_main_t * vm, |
| 641 | unformat_input_t * input, |
| 642 | vlib_cli_command_t * cmd) |
| 643 | { |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 644 | unformat_input_t _line_input, *line_input = &_line_input; |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 645 | ipsec_main_t *im = &ipsec_main; |
| 646 | clib_error_t *error; |
| 647 | u32 backend_index; |
| 648 | |
| 649 | error = ipsec_rsc_in_use (im); |
| 650 | |
| 651 | if (error) |
| 652 | return error; |
| 653 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 654 | /* Get a line of input. */ |
| 655 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 656 | return 0; |
| 657 | |
| 658 | if (unformat (line_input, "ah")) |
| 659 | { |
| 660 | if (unformat (line_input, "%u", &backend_index)) |
| 661 | { |
| 662 | if (ipsec_select_ah_backend (im, backend_index) < 0) |
| 663 | { |
| 664 | return clib_error_return (0, "Invalid AH backend index `%u'", |
| 665 | backend_index); |
| 666 | } |
| 667 | } |
| 668 | else |
| 669 | { |
| 670 | return clib_error_return (0, "Invalid backend index `%U'", |
| 671 | format_unformat_error, line_input); |
| 672 | } |
| 673 | } |
| 674 | else if (unformat (line_input, "esp")) |
| 675 | { |
| 676 | if (unformat (line_input, "%u", &backend_index)) |
| 677 | { |
| 678 | if (ipsec_select_esp_backend (im, backend_index) < 0) |
| 679 | { |
| 680 | return clib_error_return (0, "Invalid ESP backend index `%u'", |
| 681 | backend_index); |
| 682 | } |
| 683 | } |
| 684 | else |
| 685 | { |
| 686 | return clib_error_return (0, "Invalid backend index `%U'", |
| 687 | format_unformat_error, line_input); |
| 688 | } |
| 689 | } |
| 690 | else |
| 691 | { |
| 692 | return clib_error_return (0, "Unknown input `%U'", |
| 693 | format_unformat_error, line_input); |
| 694 | } |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | /* *INDENT-OFF* */ |
| 700 | VLIB_CLI_COMMAND (ipsec_select_backend_command, static) = { |
| 701 | .path = "ipsec select backend", |
| 702 | .short_help = "ipsec select backend <ah|esp> <backend index>", |
| 703 | .function = ipsec_select_backend_command_fn, |
| 704 | }; |
| 705 | |
| 706 | /* *INDENT-ON* */ |
| 707 | |
| 708 | static clib_error_t * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 709 | clear_ipsec_counters_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 710 | unformat_input_t * input, |
| 711 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 712 | { |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 713 | vlib_clear_combined_counters (&ipsec_spd_policy_counters); |
Neale Ranns | eba31ec | 2019-02-17 18:04:27 +0000 | [diff] [blame] | 714 | vlib_clear_combined_counters (&ipsec_sa_counters); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 715 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 716 | return (NULL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 719 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 720 | VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = { |
| 721 | .path = "clear ipsec counters", |
| 722 | .short_help = "clear ipsec counters", |
| 723 | .function = clear_ipsec_counters_command_fn, |
| 724 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 725 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 726 | |
| 727 | static clib_error_t * |
| 728 | create_ipsec_tunnel_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 729 | unformat_input_t * input, |
| 730 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 731 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 732 | unformat_input_t _line_input, *line_input = &_line_input; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 733 | ipsec_add_del_tunnel_args_t a; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 734 | int rv; |
| 735 | u32 num_m_args = 0; |
Kingwel Xie | 72b3bce | 2019-02-12 06:45:08 -0500 | [diff] [blame] | 736 | u8 ipv4_set = 0; |
| 737 | u8 ipv6_set = 0; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 738 | clib_error_t *error = NULL; |
Kingwel Xie | d3d1205 | 2019-03-07 06:34:30 -0500 | [diff] [blame] | 739 | ipsec_key_t rck = { 0 }; |
| 740 | ipsec_key_t lck = { 0 }; |
| 741 | ipsec_key_t lik = { 0 }; |
| 742 | ipsec_key_t rik = { 0 }; |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 743 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 744 | clib_memset (&a, 0, sizeof (a)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 745 | a.is_add = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 746 | |
| 747 | /* Get a line of input. */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 748 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 749 | return 0; |
| 750 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 751 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 752 | { |
| 753 | if (unformat |
Kingwel Xie | 72b3bce | 2019-02-12 06:45:08 -0500 | [diff] [blame] | 754 | (line_input, "local-ip %U", unformat_ip46_address, &a.local_ip, |
| 755 | IP46_TYPE_ANY)) |
| 756 | { |
| 757 | ip46_address_is_ip4 (&a.local_ip) ? (ipv4_set = 1) : (ipv6_set = 1); |
| 758 | num_m_args++; |
| 759 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 760 | else |
| 761 | if (unformat |
Kingwel Xie | 72b3bce | 2019-02-12 06:45:08 -0500 | [diff] [blame] | 762 | (line_input, "remote-ip %U", unformat_ip46_address, &a.remote_ip, |
| 763 | IP46_TYPE_ANY)) |
| 764 | { |
| 765 | ip46_address_is_ip4 (&a.remote_ip) ? (ipv4_set = 1) : (ipv6_set = |
| 766 | 1); |
| 767 | num_m_args++; |
| 768 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 769 | else if (unformat (line_input, "local-spi %u", &a.local_spi)) |
| 770 | num_m_args++; |
| 771 | else if (unformat (line_input, "remote-spi %u", &a.remote_spi)) |
| 772 | num_m_args++; |
Matthew Smith | 8e1039a | 2018-04-12 07:32:56 -0500 | [diff] [blame] | 773 | else if (unformat (line_input, "instance %u", &a.show_instance)) |
| 774 | a.renumber = 1; |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 775 | else if (unformat (line_input, "salt 0x%x", &a.salt)) |
| 776 | ; |
Radu Nicolau | 717de09 | 2018-08-03 10:37:24 +0100 | [diff] [blame] | 777 | else if (unformat (line_input, "udp-encap")) |
| 778 | a.udp_encap = 1; |
Kingwel Xie | 2baf942 | 2019-02-04 02:07:06 -0800 | [diff] [blame] | 779 | else if (unformat (line_input, "use-esn")) |
| 780 | a.esn = 1; |
| 781 | else if (unformat (line_input, "use-anti-replay")) |
| 782 | a.anti_replay = 1; |
Pierre Pfister | 4c422f9 | 2018-12-10 11:19:08 +0100 | [diff] [blame] | 783 | else if (unformat (line_input, "tx-table %u", &a.tx_table_id)) |
| 784 | ; |
Neale Ranns | fd06084 | 2019-03-04 13:44:42 +0000 | [diff] [blame] | 785 | else |
| 786 | if (unformat |
| 787 | (line_input, "local-crypto-key %U", unformat_ipsec_key, &lck)) |
| 788 | ; |
| 789 | else |
| 790 | if (unformat |
| 791 | (line_input, "remote-crypto-key %U", unformat_ipsec_key, &rck)) |
| 792 | ; |
| 793 | else if (unformat (line_input, "crypto-alg %U", |
| 794 | unformat_ipsec_crypto_alg, &a.crypto_alg)) |
| 795 | ; |
| 796 | else |
| 797 | if (unformat |
| 798 | (line_input, "local-integ-key %U", unformat_ipsec_key, &lik)) |
| 799 | ; |
| 800 | else |
| 801 | if (unformat |
Simon Zhang | e8e950a | 2019-04-23 23:04:07 +0800 | [diff] [blame] | 802 | (line_input, "remote-integ-key %U", unformat_ipsec_key, &rik)) |
Neale Ranns | fd06084 | 2019-03-04 13:44:42 +0000 | [diff] [blame] | 803 | ; |
| 804 | else if (unformat (line_input, "integ-alg %U", |
| 805 | unformat_ipsec_integ_alg, &a.integ_alg)) |
| 806 | ; |
Kingwel Xie | 2baf942 | 2019-02-04 02:07:06 -0800 | [diff] [blame] | 807 | else if (unformat (line_input, "del")) |
| 808 | a.is_add = 0; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 809 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 810 | { |
| 811 | error = clib_error_return (0, "unknown input `%U'", |
| 812 | format_unformat_error, line_input); |
| 813 | goto done; |
| 814 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 815 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 816 | |
| 817 | if (num_m_args < 4) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 818 | { |
| 819 | error = clib_error_return (0, "mandatory argument(s) missing"); |
| 820 | goto done; |
| 821 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 822 | |
Kingwel Xie | 72b3bce | 2019-02-12 06:45:08 -0500 | [diff] [blame] | 823 | if (ipv4_set && ipv6_set) |
| 824 | return clib_error_return (0, "both IPv4 and IPv6 addresses specified"); |
| 825 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 826 | a.is_ip6 = ipv6_set; |
| 827 | |
Neale Ranns | fd06084 | 2019-03-04 13:44:42 +0000 | [diff] [blame] | 828 | clib_memcpy (a.local_crypto_key, lck.data, lck.len); |
| 829 | a.local_crypto_key_len = lck.len; |
| 830 | clib_memcpy (a.remote_crypto_key, rck.data, rck.len); |
| 831 | a.remote_crypto_key_len = rck.len; |
| 832 | |
Kingwel Xie | d3d1205 | 2019-03-07 06:34:30 -0500 | [diff] [blame] | 833 | clib_memcpy (a.local_integ_key, lik.data, lik.len); |
Neale Ranns | fd06084 | 2019-03-04 13:44:42 +0000 | [diff] [blame] | 834 | a.local_integ_key_len = lck.len; |
Kingwel Xie | d3d1205 | 2019-03-07 06:34:30 -0500 | [diff] [blame] | 835 | clib_memcpy (a.remote_integ_key, rik.data, rik.len); |
Neale Ranns | fd06084 | 2019-03-04 13:44:42 +0000 | [diff] [blame] | 836 | a.remote_integ_key_len = rck.len; |
| 837 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 838 | rv = ipsec_add_del_tunnel_if (&a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 839 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 840 | switch (rv) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 841 | { |
| 842 | case 0: |
| 843 | break; |
| 844 | case VNET_API_ERROR_INVALID_VALUE: |
| 845 | if (a.is_add) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 846 | error = clib_error_return (0, |
| 847 | "IPSec tunnel interface already exists..."); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 848 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 849 | error = clib_error_return (0, "IPSec tunnel interface not exists..."); |
| 850 | goto done; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 851 | default: |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 852 | error = clib_error_return (0, "ipsec_register_interface returned %d", |
| 853 | rv); |
| 854 | goto done; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 857 | done: |
| 858 | unformat_free (line_input); |
| 859 | |
| 860 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 863 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 864 | VLIB_CLI_COMMAND (create_ipsec_tunnel_command, static) = { |
| 865 | .path = "create ipsec tunnel", |
Pierre Pfister | 4c422f9 | 2018-12-10 11:19:08 +0100 | [diff] [blame] | 866 | .short_help = "create ipsec tunnel local-ip <addr> local-spi <spi> " |
Kingwel Xie | 2baf942 | 2019-02-04 02:07:06 -0800 | [diff] [blame] | 867 | "remote-ip <addr> remote-spi <spi> [instance <inst_num>] [udp-encap] [use-esn] [use-anti-replay] " |
Pierre Pfister | 4c422f9 | 2018-12-10 11:19:08 +0100 | [diff] [blame] | 868 | "[tx-table <table-id>]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 869 | .function = create_ipsec_tunnel_command_fn, |
| 870 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 871 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 872 | |
| 873 | static clib_error_t * |
| 874 | set_interface_key_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 875 | unformat_input_t * input, |
| 876 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 877 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 878 | unformat_input_t _line_input, *line_input = &_line_input; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 879 | ipsec_main_t *im = &ipsec_main; |
| 880 | ipsec_if_set_key_type_t type = IPSEC_IF_SET_KEY_TYPE_NONE; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 881 | u32 hw_if_index = (u32) ~ 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 882 | u32 alg; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 883 | u8 *key = 0; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 884 | clib_error_t *error = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 885 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 886 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 887 | return 0; |
| 888 | |
| 889 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 890 | { |
| 891 | if (unformat (line_input, "%U", |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 892 | unformat_vnet_hw_interface, im->vnet_main, &hw_if_index)) |
| 893 | ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 894 | else |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 895 | if (unformat |
| 896 | (line_input, "local crypto %U", unformat_ipsec_crypto_alg, &alg)) |
| 897 | type = IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO; |
| 898 | else |
| 899 | if (unformat |
| 900 | (line_input, "remote crypto %U", unformat_ipsec_crypto_alg, &alg)) |
| 901 | type = IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO; |
| 902 | else |
| 903 | if (unformat |
| 904 | (line_input, "local integ %U", unformat_ipsec_integ_alg, &alg)) |
| 905 | type = IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG; |
| 906 | else |
| 907 | if (unformat |
| 908 | (line_input, "remote integ %U", unformat_ipsec_integ_alg, &alg)) |
| 909 | type = IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG; |
| 910 | else if (unformat (line_input, "%U", unformat_hex_string, &key)) |
| 911 | ; |
| 912 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 913 | { |
| 914 | error = clib_error_return (0, "parse error: '%U'", |
| 915 | format_unformat_error, line_input); |
| 916 | goto done; |
| 917 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 920 | if (type == IPSEC_IF_SET_KEY_TYPE_NONE) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 921 | { |
| 922 | error = clib_error_return (0, "unknown key type"); |
| 923 | goto done; |
| 924 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 925 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 926 | if (alg > 0 && vec_len (key) == 0) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 927 | { |
| 928 | error = clib_error_return (0, "key is not specified"); |
| 929 | goto done; |
| 930 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 931 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 932 | if (hw_if_index == (u32) ~ 0) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 933 | { |
| 934 | error = clib_error_return (0, "interface not specified"); |
| 935 | goto done; |
| 936 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 937 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 938 | ipsec_set_interface_key (im->vnet_main, hw_if_index, type, alg, key); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 939 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 940 | done: |
| 941 | vec_free (key); |
| 942 | unformat_free (line_input); |
| 943 | |
| 944 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 947 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 948 | VLIB_CLI_COMMAND (set_interface_key_command, static) = { |
| 949 | .path = "set interface ipsec key", |
| 950 | .short_help = |
| 951 | "set interface ipsec key <int> <local|remote> <crypto|integ> <key type> <key>", |
| 952 | .function = set_interface_key_command_fn, |
| 953 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 954 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 955 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 956 | clib_error_t * |
| 957 | ipsec_cli_init (vlib_main_t * vm) |
| 958 | { |
| 959 | return 0; |
| 960 | } |
| 961 | |
| 962 | VLIB_INIT_FUNCTION (ipsec_cli_init); |
| 963 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 964 | |
| 965 | /* |
| 966 | * fd.io coding-style-patch-verification: ON |
| 967 | * |
| 968 | * Local Variables: |
| 969 | * eval: (c-set-style "gnu") |
| 970 | * End: |
| 971 | */ |