Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #include <vlib/vlib.h> |
| 16 | #include <vnet/vnet.h> |
| 17 | #include <vnet/pg/pg.h> |
| 18 | #include <vppinfra/error.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame^] | 19 | #include <vnet/udp/udp.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | #include <vnet/ipsec/ikev2.h> |
| 21 | #include <vnet/ipsec/ikev2_priv.h> |
| 22 | |
| 23 | u8 * |
| 24 | format_ikev2_id_type_and_data (u8 * s, va_list * args) |
| 25 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 26 | ikev2_id_t *id = va_arg (*args, ikev2_id_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 28 | if (id->type == 0 || vec_len (id->data) == 0) |
| 29 | return format (s, "none"); |
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 | s = format (s, "%U", format_ikev2_id_type, id->type); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | |
| 33 | if (id->type == IKEV2_ID_TYPE_ID_FQDN || |
| 34 | id->type == IKEV2_ID_TYPE_ID_RFC822_ADDR) |
| 35 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 36 | s = format (s, " %v", id->data); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 37 | } |
| 38 | else |
| 39 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 40 | s = |
| 41 | format (s, " %U", format_hex_bytes, &id->data, |
| 42 | (uword) (vec_len (id->data))); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | return s; |
| 46 | } |
| 47 | |
| 48 | |
| 49 | static clib_error_t * |
| 50 | show_ikev2_sa_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 51 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 53 | ikev2_main_t *km = &ikev2_main; |
| 54 | ikev2_main_per_thread_data_t *tkm; |
| 55 | ikev2_sa_t *sa; |
| 56 | ikev2_ts_t *ts; |
| 57 | ikev2_child_sa_t *child; |
| 58 | ikev2_sa_transform_t *tr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 59 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 60 | vec_foreach (tkm, km->per_thread_data) |
| 61 | { |
| 62 | /* *INDENT-OFF* */ |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 63 | pool_foreach (sa, tkm->sas, ({ |
| 64 | u8 * s = 0; |
| 65 | vlib_cli_output(vm, " iip %U ispi %lx rip %U rspi %lx", |
| 66 | format_ip4_address, &sa->iaddr, sa->ispi, |
| 67 | format_ip4_address, &sa->raddr, sa->rspi); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 68 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 69 | tr = ikev2_sa_get_td_for_type(sa->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR); |
| 70 | s = format(s, "%U ", format_ikev2_sa_transform, tr); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 71 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 72 | tr = ikev2_sa_get_td_for_type(sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF); |
| 73 | s = format(s, "%U ", format_ikev2_sa_transform, tr); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 74 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 75 | tr = ikev2_sa_get_td_for_type(sa->r_proposals, IKEV2_TRANSFORM_TYPE_INTEG); |
| 76 | s = format(s, "%U ", format_ikev2_sa_transform, tr); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 77 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 78 | tr = ikev2_sa_get_td_for_type(sa->r_proposals, IKEV2_TRANSFORM_TYPE_DH); |
| 79 | s = format(s, "%U ", format_ikev2_sa_transform, tr); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 80 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 81 | vlib_cli_output(vm, " %v", s); |
| 82 | vec_free(s); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 83 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 84 | vlib_cli_output(vm, " nonce i:%U\n r:%U", |
| 85 | format_hex_bytes, sa->i_nonce, vec_len(sa->i_nonce), |
| 86 | format_hex_bytes, sa->r_nonce, vec_len(sa->r_nonce)); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 87 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 88 | vlib_cli_output(vm, " SK_d %U", |
| 89 | format_hex_bytes, sa->sk_d, vec_len(sa->sk_d)); |
| 90 | vlib_cli_output(vm, " SK_a i:%U\n r:%U", |
| 91 | format_hex_bytes, sa->sk_ai, vec_len(sa->sk_ai), |
| 92 | format_hex_bytes, sa->sk_ar, vec_len(sa->sk_ar)); |
| 93 | vlib_cli_output(vm, " SK_e i:%U\n r:%U", |
| 94 | format_hex_bytes, sa->sk_ei, vec_len(sa->sk_ei), |
| 95 | format_hex_bytes, sa->sk_er, vec_len(sa->sk_er)); |
| 96 | vlib_cli_output(vm, " SK_p i:%U\n r:%U", |
| 97 | format_hex_bytes, sa->sk_pi, vec_len(sa->sk_pi), |
| 98 | format_hex_bytes, sa->sk_pr, vec_len(sa->sk_pr)); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 99 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 100 | vlib_cli_output(vm, " identifier (i) %U", |
| 101 | format_ikev2_id_type_and_data, &sa->i_id); |
| 102 | vlib_cli_output(vm, " identifier (r) %U", |
| 103 | format_ikev2_id_type_and_data, &sa->r_id); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 104 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 105 | vec_foreach(child, sa->childs) |
| 106 | { |
| 107 | vlib_cli_output(vm, " child sa %u:", child - sa->childs); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 108 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 109 | tr = ikev2_sa_get_td_for_type(child->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR); |
| 110 | s = format(s, "%U ", format_ikev2_sa_transform, tr); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 111 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 112 | tr = ikev2_sa_get_td_for_type(child->r_proposals, IKEV2_TRANSFORM_TYPE_INTEG); |
| 113 | s = format(s, "%U ", format_ikev2_sa_transform, tr); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 114 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 115 | tr = ikev2_sa_get_td_for_type(child->r_proposals, IKEV2_TRANSFORM_TYPE_ESN); |
| 116 | s = format(s, "%U ", format_ikev2_sa_transform, tr); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 117 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 118 | vlib_cli_output(vm, " %v", s); |
| 119 | vec_free(s); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 120 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 121 | vlib_cli_output(vm, " spi(i) %lx spi(r) %lx", |
| 122 | child->i_proposals ? child->i_proposals[0].spi : 0, |
| 123 | child->r_proposals ? child->r_proposals[0].spi : 0); |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 124 | |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 125 | vlib_cli_output(vm, " SK_e i:%U\n r:%U", |
| 126 | format_hex_bytes, child->sk_ei, vec_len(child->sk_ei), |
| 127 | format_hex_bytes, child->sk_er, vec_len(child->sk_er)); |
| 128 | vlib_cli_output(vm, " SK_a i:%U\n r:%U", |
| 129 | format_hex_bytes, child->sk_ai, vec_len(child->sk_ai), |
| 130 | format_hex_bytes, child->sk_ar, vec_len(child->sk_ar)); |
| 131 | vlib_cli_output(vm, " traffic selectors (i):"); |
| 132 | vec_foreach(ts, child->tsi) |
| 133 | { |
| 134 | vlib_cli_output(vm, " %u type %u protocol_id %u addr " |
| 135 | "%U - %U port %u - %u", |
| 136 | ts - child->tsi, |
| 137 | ts->ts_type, ts->protocol_id, |
| 138 | format_ip4_address, &ts->start_addr, |
| 139 | format_ip4_address, &ts->end_addr, |
| 140 | clib_net_to_host_u16( ts->start_port), |
| 141 | clib_net_to_host_u16( ts->end_port)); |
| 142 | } |
| 143 | vlib_cli_output(vm, " traffic selectors (r):"); |
| 144 | vec_foreach(ts, child->tsr) |
| 145 | { |
| 146 | vlib_cli_output(vm, " %u type %u protocol_id %u addr " |
| 147 | "%U - %U port %u - %u", |
| 148 | ts - child->tsr, |
| 149 | ts->ts_type, ts->protocol_id, |
| 150 | format_ip4_address, &ts->start_addr, |
| 151 | format_ip4_address, &ts->end_addr, |
| 152 | clib_net_to_host_u16( ts->start_port), |
| 153 | clib_net_to_host_u16( ts->end_port)); |
| 154 | } |
| 155 | } |
| 156 | vlib_cli_output(vm, ""); |
| 157 | })); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 158 | /* *INDENT-ON* */ |
Matthew Smith | 2838a23 | 2016-06-21 16:05:09 -0500 | [diff] [blame] | 159 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 160 | return 0; |
| 161 | } |
| 162 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 163 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 164 | VLIB_CLI_COMMAND (show_ikev2_sa_command, static) = { |
| 165 | .path = "show ikev2 sa", |
| 166 | .short_help = "show ikev2 sa", |
| 167 | .function = show_ikev2_sa_command_fn, |
| 168 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 169 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 170 | |
| 171 | static clib_error_t * |
| 172 | ikev2_profile_add_del_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 173 | unformat_input_t * input, |
| 174 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | { |
Radu Nicolau | cb33dc2 | 2017-02-16 16:49:46 +0000 | [diff] [blame] | 176 | vnet_main_t *vnm = vnet_get_main (); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 177 | unformat_input_t _line_input, *line_input = &_line_input; |
| 178 | u8 *name = 0; |
| 179 | clib_error_t *r = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 180 | u32 id_type; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 181 | u8 *data = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 182 | u32 tmp1, tmp2, tmp3; |
Radu Nicolau | cb33dc2 | 2017-02-16 16:49:46 +0000 | [diff] [blame] | 183 | u64 tmp4, tmp5; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 184 | ip4_address_t ip4; |
| 185 | ip4_address_t end_addr; |
Radu Nicolau | cb33dc2 | 2017-02-16 16:49:46 +0000 | [diff] [blame] | 186 | u32 responder_sw_if_index = (u32) ~ 0; |
| 187 | ip4_address_t responder_ip4; |
| 188 | ikev2_transform_encr_type_t crypto_alg; |
| 189 | ikev2_transform_integ_type_t integ_alg; |
| 190 | ikev2_transform_dh_type_t dh_type; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 191 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 192 | const char *valid_chars = "a-zA-Z0-9_"; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 194 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 195 | return 0; |
| 196 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 197 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 198 | { |
| 199 | if (unformat (line_input, "add %U", unformat_token, valid_chars, &name)) |
| 200 | { |
| 201 | r = ikev2_add_del_profile (vm, name, 1); |
| 202 | goto done; |
| 203 | } |
| 204 | else |
| 205 | if (unformat |
| 206 | (line_input, "del %U", unformat_token, valid_chars, &name)) |
| 207 | { |
| 208 | r = ikev2_add_del_profile (vm, name, 0); |
| 209 | goto done; |
| 210 | } |
| 211 | else if (unformat (line_input, "set %U auth shared-key-mic string %v", |
| 212 | unformat_token, valid_chars, &name, &data)) |
| 213 | { |
| 214 | r = |
| 215 | ikev2_set_profile_auth (vm, name, |
| 216 | IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data, |
| 217 | 0); |
| 218 | goto done; |
| 219 | } |
| 220 | else if (unformat (line_input, "set %U auth shared-key-mic hex %U", |
| 221 | unformat_token, valid_chars, &name, |
| 222 | unformat_hex_string, &data)) |
| 223 | { |
| 224 | r = |
| 225 | ikev2_set_profile_auth (vm, name, |
| 226 | IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data, |
| 227 | 1); |
| 228 | goto done; |
| 229 | } |
| 230 | else if (unformat (line_input, "set %U auth rsa-sig cert-file %v", |
| 231 | unformat_token, valid_chars, &name, &data)) |
| 232 | { |
| 233 | r = |
| 234 | ikev2_set_profile_auth (vm, name, IKEV2_AUTH_METHOD_RSA_SIG, data, |
| 235 | 0); |
| 236 | goto done; |
| 237 | } |
| 238 | else if (unformat (line_input, "set %U id local %U %U", |
| 239 | unformat_token, valid_chars, &name, |
| 240 | unformat_ikev2_id_type, &id_type, |
| 241 | unformat_ip4_address, &ip4)) |
| 242 | { |
| 243 | data = vec_new (u8, 4); |
| 244 | clib_memcpy (data, ip4.as_u8, 4); |
| 245 | r = |
| 246 | ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1); |
| 247 | goto done; |
| 248 | } |
| 249 | else if (unformat (line_input, "set %U id local %U 0x%U", |
| 250 | unformat_token, valid_chars, &name, |
| 251 | unformat_ikev2_id_type, &id_type, |
| 252 | unformat_hex_string, &data)) |
| 253 | { |
| 254 | r = |
| 255 | ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1); |
| 256 | goto done; |
| 257 | } |
| 258 | else if (unformat (line_input, "set %U id local %U %v", |
| 259 | unformat_token, valid_chars, &name, |
| 260 | unformat_ikev2_id_type, &id_type, &data)) |
| 261 | { |
| 262 | r = |
| 263 | ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1); |
| 264 | goto done; |
| 265 | } |
| 266 | else if (unformat (line_input, "set %U id remote %U %U", |
| 267 | unformat_token, valid_chars, &name, |
| 268 | unformat_ikev2_id_type, &id_type, |
| 269 | unformat_ip4_address, &ip4)) |
| 270 | { |
| 271 | data = vec_new (u8, 4); |
| 272 | clib_memcpy (data, ip4.as_u8, 4); |
Ed Warnicke | 853e720 | 2016-08-12 11:42:26 -0700 | [diff] [blame] | 273 | r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */ |
| 274 | 0); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 275 | goto done; |
| 276 | } |
| 277 | else if (unformat (line_input, "set %U id remote %U 0x%U", |
| 278 | unformat_token, valid_chars, &name, |
| 279 | unformat_ikev2_id_type, &id_type, |
| 280 | unformat_hex_string, &data)) |
| 281 | { |
Ed Warnicke | 853e720 | 2016-08-12 11:42:26 -0700 | [diff] [blame] | 282 | r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */ |
| 283 | 0); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 284 | goto done; |
| 285 | } |
| 286 | else if (unformat (line_input, "set %U id remote %U %v", |
| 287 | unformat_token, valid_chars, &name, |
| 288 | unformat_ikev2_id_type, &id_type, &data)) |
| 289 | { |
Ed Warnicke | 853e720 | 2016-08-12 11:42:26 -0700 | [diff] [blame] | 290 | r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */ |
| 291 | 0); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 292 | goto done; |
| 293 | } |
| 294 | else if (unformat (line_input, "set %U traffic-selector local " |
| 295 | "ip-range %U - %U port-range %u - %u protocol %u", |
| 296 | unformat_token, valid_chars, &name, |
| 297 | unformat_ip4_address, &ip4, |
| 298 | unformat_ip4_address, &end_addr, |
| 299 | &tmp1, &tmp2, &tmp3)) |
| 300 | { |
| 301 | r = |
| 302 | ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2, |
| 303 | ip4, end_addr, /*local */ 1); |
| 304 | goto done; |
| 305 | } |
| 306 | else if (unformat (line_input, "set %U traffic-selector remote " |
| 307 | "ip-range %U - %U port-range %u - %u protocol %u", |
| 308 | unformat_token, valid_chars, &name, |
| 309 | unformat_ip4_address, &ip4, |
| 310 | unformat_ip4_address, &end_addr, |
| 311 | &tmp1, &tmp2, &tmp3)) |
| 312 | { |
| 313 | r = |
| 314 | ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2, |
| 315 | ip4, end_addr, /*remote */ 0); |
| 316 | goto done; |
| 317 | } |
Radu Nicolau | cb33dc2 | 2017-02-16 16:49:46 +0000 | [diff] [blame] | 318 | else if (unformat (line_input, "set %U responder %U %U", |
| 319 | unformat_token, valid_chars, &name, |
| 320 | unformat_vnet_sw_interface, vnm, |
| 321 | &responder_sw_if_index, unformat_ip4_address, |
| 322 | &responder_ip4)) |
| 323 | { |
| 324 | r = |
| 325 | ikev2_set_profile_responder (vm, name, responder_sw_if_index, |
| 326 | responder_ip4); |
| 327 | goto done; |
| 328 | } |
| 329 | else |
| 330 | if (unformat |
| 331 | (line_input, |
| 332 | "set %U ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U", |
| 333 | unformat_token, valid_chars, &name, |
| 334 | unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1, |
| 335 | unformat_ikev2_transform_integ_type, &integ_alg, |
| 336 | unformat_ikev2_transform_dh_type, &dh_type)) |
| 337 | { |
| 338 | r = |
| 339 | ikev2_set_profile_ike_transforms (vm, name, crypto_alg, integ_alg, |
| 340 | dh_type, tmp1); |
| 341 | goto done; |
| 342 | } |
| 343 | else |
| 344 | if (unformat |
| 345 | (line_input, |
| 346 | "set %U esp-crypto-alg %U %u esp-integ-alg %U esp-dh %U", |
| 347 | unformat_token, valid_chars, &name, |
| 348 | unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1, |
| 349 | unformat_ikev2_transform_integ_type, &integ_alg, |
| 350 | unformat_ikev2_transform_dh_type, &dh_type)) |
| 351 | { |
| 352 | r = |
| 353 | ikev2_set_profile_esp_transforms (vm, name, crypto_alg, integ_alg, |
| 354 | dh_type, tmp1); |
| 355 | goto done; |
| 356 | } |
| 357 | else if (unformat (line_input, "set %U sa-lifetime %lu %u %u %lu", |
| 358 | unformat_token, valid_chars, &name, |
| 359 | &tmp4, &tmp1, &tmp2, &tmp5)) |
| 360 | { |
| 361 | r = |
| 362 | ikev2_set_profile_sa_lifetime (vm, name, tmp4, tmp1, tmp2, tmp5); |
| 363 | goto done; |
| 364 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 365 | else |
| 366 | break; |
| 367 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 368 | |
| 369 | r = clib_error_return (0, "parse error: '%U'", |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 370 | format_unformat_error, line_input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 371 | |
| 372 | done: |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 373 | vec_free (name); |
| 374 | vec_free (data); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 375 | unformat_free (line_input); |
| 376 | return r; |
| 377 | } |
| 378 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 379 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | VLIB_CLI_COMMAND (ikev2_profile_add_del_command, static) = { |
| 381 | .path = "ikev2 profile", |
| 382 | .short_help = |
| 383 | "ikev2 profile [add|del] <id>\n" |
| 384 | "ikev2 profile set <id> auth [rsa-sig|shared-key-mic] [cert-file|string|hex]" |
| 385 | " <data>\n" |
| 386 | "ikev2 profile set <id> id <local|remote> <type> <data>\n" |
| 387 | "ikev2 profile set <id> traffic-selector <local|remote> ip-range " |
| 388 | "<start-addr> - <end-addr> port-range <start-port> - <end-port> " |
Radu Nicolau | cb33dc2 | 2017-02-16 16:49:46 +0000 | [diff] [blame] | 389 | "protocol <protocol-number>\n" |
| 390 | "ikev2 profile set <id> responder <interface> <addr>\n" |
| 391 | "ikev2 profile set <id> ike-crypto-alg <crypto alg> <key size> ike-integ-alg <integ alg> ike-dh <dh type>\n" |
| 392 | "ikev2 profile set <id> esp-crypto-alg <crypto alg> <key size> esp-integ-alg <integ alg> esp-dh <dh type>\n" |
| 393 | "ikev2 profile set <id> sa-lifetime <seconds> <jitter> <handover> <max bytes>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 394 | .function = ikev2_profile_add_del_command_fn, |
| 395 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 396 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 397 | |
| 398 | static clib_error_t * |
| 399 | show_ikev2_profile_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 400 | unformat_input_t * input, |
| 401 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 402 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 403 | ikev2_main_t *km = &ikev2_main; |
| 404 | ikev2_profile_t *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 405 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 406 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 407 | pool_foreach (p, km->profiles, ({ |
| 408 | vlib_cli_output(vm, "profile %v", p->name); |
| 409 | |
| 410 | if (p->auth.data) |
| 411 | { |
| 412 | if (p->auth.hex) |
| 413 | vlib_cli_output(vm, " auth-method %U auth data 0x%U", |
| 414 | format_ikev2_auth_method, p->auth.method, |
| 415 | format_hex_bytes, p->auth.data, vec_len(p->auth.data)); |
| 416 | else |
| 417 | vlib_cli_output(vm, " auth-method %U auth data %v", |
| 418 | format_ikev2_auth_method, p->auth.method, p->auth.data); |
| 419 | } |
| 420 | |
| 421 | if (p->loc_id.data) |
| 422 | { |
| 423 | if (p->loc_id.type == IKEV2_ID_TYPE_ID_IPV4_ADDR) |
| 424 | vlib_cli_output(vm, " local id-type %U data %U", |
| 425 | format_ikev2_id_type, p->loc_id.type, |
| 426 | format_ip4_address, p->loc_id.data); |
| 427 | else if (p->loc_id.type == IKEV2_ID_TYPE_ID_KEY_ID) |
| 428 | vlib_cli_output(vm, " local id-type %U data 0x%U", |
| 429 | format_ikev2_id_type, p->loc_id.type, |
| 430 | format_hex_bytes, p->loc_id.data, |
| 431 | vec_len(p->loc_id.data)); |
| 432 | else |
| 433 | vlib_cli_output(vm, " local id-type %U data %v", |
| 434 | format_ikev2_id_type, p->loc_id.type, p->loc_id.data); |
| 435 | } |
| 436 | |
| 437 | if (p->rem_id.data) |
| 438 | { |
| 439 | if (p->rem_id.type == IKEV2_ID_TYPE_ID_IPV4_ADDR) |
| 440 | vlib_cli_output(vm, " remote id-type %U data %U", |
| 441 | format_ikev2_id_type, p->rem_id.type, |
| 442 | format_ip4_address, p->rem_id.data); |
| 443 | else if (p->rem_id.type == IKEV2_ID_TYPE_ID_KEY_ID) |
| 444 | vlib_cli_output(vm, " remote id-type %U data 0x%U", |
| 445 | format_ikev2_id_type, p->rem_id.type, |
| 446 | format_hex_bytes, p->rem_id.data, |
| 447 | vec_len(p->rem_id.data)); |
| 448 | else |
| 449 | vlib_cli_output(vm, " remote id-type %U data %v", |
| 450 | format_ikev2_id_type, p->rem_id.type, p->rem_id.data); |
| 451 | } |
| 452 | |
| 453 | if (p->loc_ts.end_addr.as_u32) |
| 454 | vlib_cli_output(vm, " local traffic-selector addr %U - %U port %u - %u" |
| 455 | " protocol %u", |
| 456 | format_ip4_address, &p->loc_ts.start_addr, |
| 457 | format_ip4_address, &p->loc_ts.end_addr, |
| 458 | p->loc_ts.start_port, p->loc_ts.end_port, |
| 459 | p->loc_ts.protocol_id); |
| 460 | |
| 461 | if (p->rem_ts.end_addr.as_u32) |
| 462 | vlib_cli_output(vm, " remote traffic-selector addr %U - %U port %u - %u" |
| 463 | " protocol %u", |
| 464 | format_ip4_address, &p->rem_ts.start_addr, |
| 465 | format_ip4_address, &p->rem_ts.end_addr, |
| 466 | p->rem_ts.start_port, p->rem_ts.end_port, |
| 467 | p->rem_ts.protocol_id); |
| 468 | })); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 469 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 474 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 475 | VLIB_CLI_COMMAND (show_ikev2_profile_command, static) = { |
| 476 | .path = "show ikev2 profile", |
| 477 | .short_help = "show ikev2 profile", |
| 478 | .function = show_ikev2_profile_command_fn, |
| 479 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 480 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 481 | |
| 482 | static clib_error_t * |
| 483 | set_ikev2_local_key_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 484 | unformat_input_t * input, |
| 485 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 486 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 487 | unformat_input_t _line_input, *line_input = &_line_input; |
| 488 | clib_error_t *r = 0; |
| 489 | u8 *data = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 490 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 491 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 492 | return 0; |
| 493 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 494 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 495 | { |
Matus Fabian | 698b952 | 2016-09-13 23:15:56 -0700 | [diff] [blame] | 496 | if (unformat (line_input, "%s", &data)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 497 | { |
| 498 | r = ikev2_set_local_key (vm, data); |
| 499 | goto done; |
| 500 | } |
| 501 | else |
| 502 | break; |
| 503 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 504 | |
| 505 | r = clib_error_return (0, "parse error: '%U'", |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 506 | format_unformat_error, line_input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 507 | |
| 508 | done: |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 509 | vec_free (data); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 510 | unformat_free (line_input); |
| 511 | return r; |
| 512 | } |
| 513 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 514 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 515 | VLIB_CLI_COMMAND (set_ikev2_local_key_command, static) = { |
| 516 | .path = "set ikev2 local key", |
| 517 | .short_help = |
| 518 | "set ikev2 local key <file>", |
| 519 | .function = set_ikev2_local_key_command_fn, |
| 520 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 521 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 522 | |
Radu Nicolau | cb33dc2 | 2017-02-16 16:49:46 +0000 | [diff] [blame] | 523 | |
| 524 | static clib_error_t * |
| 525 | ikev2_initiate_command_fn (vlib_main_t * vm, |
| 526 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 527 | { |
| 528 | unformat_input_t _line_input, *line_input = &_line_input; |
| 529 | clib_error_t *r = 0; |
| 530 | u8 *name = 0; |
| 531 | u32 tmp1; |
| 532 | u64 tmp2; |
| 533 | |
| 534 | const char *valid_chars = "a-zA-Z0-9_"; |
| 535 | |
| 536 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 537 | return 0; |
| 538 | |
| 539 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 540 | { |
| 541 | if (unformat |
| 542 | (line_input, "sa-init %U", unformat_token, valid_chars, &name)) |
| 543 | { |
| 544 | r = ikev2_initiate_sa_init (vm, name); |
| 545 | goto done; |
| 546 | } |
| 547 | else if (unformat (line_input, "del-child-sa %x", &tmp1)) |
| 548 | { |
| 549 | r = ikev2_initiate_delete_child_sa (vm, tmp1); |
| 550 | goto done; |
| 551 | } |
| 552 | else if (unformat (line_input, "del-sa %lx", &tmp2)) |
| 553 | { |
| 554 | r = ikev2_initiate_delete_ike_sa (vm, tmp2); |
| 555 | goto done; |
| 556 | } |
| 557 | else if (unformat (line_input, "rekey-child-sa %x", &tmp1)) |
| 558 | { |
| 559 | r = ikev2_initiate_rekey_child_sa (vm, tmp1); |
| 560 | goto done; |
| 561 | } |
| 562 | else |
| 563 | break; |
| 564 | } |
| 565 | |
| 566 | r = clib_error_return (0, "parse error: '%U'", |
| 567 | format_unformat_error, line_input); |
| 568 | |
| 569 | done: |
| 570 | vec_free (name); |
| 571 | unformat_free (line_input); |
| 572 | return r; |
| 573 | } |
| 574 | |
| 575 | /* *INDENT-OFF* */ |
| 576 | VLIB_CLI_COMMAND (ikev2_initiate_command, static) = { |
| 577 | .path = "ikev2 initiate", |
| 578 | .short_help = |
| 579 | "ikev2 initiate sa-init <profile id>\n" |
| 580 | "ikev2 initiate del-child-sa <child sa ispi>\n" |
| 581 | "ikev2 initiate del-sa <sa ispi>\n" |
| 582 | "ikev2 initiate rekey-child-sa <profile id> <child sa ispi>\n", |
| 583 | .function = ikev2_initiate_command_fn, |
| 584 | }; |
| 585 | /* *INDENT-ON* */ |
| 586 | |
| 587 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 588 | clib_error_t * |
| 589 | ikev2_cli_init (vlib_main_t * vm) |
| 590 | { |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | VLIB_INIT_FUNCTION (ikev2_cli_init); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 595 | |
| 596 | /* |
| 597 | * fd.io coding-style-patch-verification: ON |
| 598 | * |
| 599 | * Local Variables: |
| 600 | * eval: (c-set-style "gnu") |
| 601 | * End: |
| 602 | */ |