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