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