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> |
| 19 | #include <vnet/ip/udp.h> |
| 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 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 176 | unformat_input_t _line_input, *line_input = &_line_input; |
| 177 | u8 *name = 0; |
| 178 | clib_error_t *r = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | u32 id_type; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 180 | u8 *data = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | u32 tmp1, tmp2, tmp3; |
| 182 | ip4_address_t ip4; |
| 183 | ip4_address_t end_addr; |
| 184 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 185 | const char *valid_chars = "a-zA-Z0-9_"; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 186 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 187 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 188 | return 0; |
| 189 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 190 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 191 | { |
| 192 | if (unformat (line_input, "add %U", unformat_token, valid_chars, &name)) |
| 193 | { |
| 194 | r = ikev2_add_del_profile (vm, name, 1); |
| 195 | goto done; |
| 196 | } |
| 197 | else |
| 198 | if (unformat |
| 199 | (line_input, "del %U", unformat_token, valid_chars, &name)) |
| 200 | { |
| 201 | r = ikev2_add_del_profile (vm, name, 0); |
| 202 | goto done; |
| 203 | } |
| 204 | else if (unformat (line_input, "set %U auth shared-key-mic string %v", |
| 205 | unformat_token, valid_chars, &name, &data)) |
| 206 | { |
| 207 | r = |
| 208 | ikev2_set_profile_auth (vm, name, |
| 209 | IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data, |
| 210 | 0); |
| 211 | goto done; |
| 212 | } |
| 213 | else if (unformat (line_input, "set %U auth shared-key-mic hex %U", |
| 214 | unformat_token, valid_chars, &name, |
| 215 | unformat_hex_string, &data)) |
| 216 | { |
| 217 | r = |
| 218 | ikev2_set_profile_auth (vm, name, |
| 219 | IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data, |
| 220 | 1); |
| 221 | goto done; |
| 222 | } |
| 223 | else if (unformat (line_input, "set %U auth rsa-sig cert-file %v", |
| 224 | unformat_token, valid_chars, &name, &data)) |
| 225 | { |
| 226 | r = |
| 227 | ikev2_set_profile_auth (vm, name, IKEV2_AUTH_METHOD_RSA_SIG, data, |
| 228 | 0); |
| 229 | goto done; |
| 230 | } |
| 231 | else if (unformat (line_input, "set %U id local %U %U", |
| 232 | unformat_token, valid_chars, &name, |
| 233 | unformat_ikev2_id_type, &id_type, |
| 234 | unformat_ip4_address, &ip4)) |
| 235 | { |
| 236 | data = vec_new (u8, 4); |
| 237 | clib_memcpy (data, ip4.as_u8, 4); |
| 238 | r = |
| 239 | ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1); |
| 240 | goto done; |
| 241 | } |
| 242 | else if (unformat (line_input, "set %U id local %U 0x%U", |
| 243 | unformat_token, valid_chars, &name, |
| 244 | unformat_ikev2_id_type, &id_type, |
| 245 | unformat_hex_string, &data)) |
| 246 | { |
| 247 | r = |
| 248 | ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1); |
| 249 | goto done; |
| 250 | } |
| 251 | else if (unformat (line_input, "set %U id local %U %v", |
| 252 | unformat_token, valid_chars, &name, |
| 253 | unformat_ikev2_id_type, &id_type, &data)) |
| 254 | { |
| 255 | r = |
| 256 | ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1); |
| 257 | goto done; |
| 258 | } |
| 259 | else if (unformat (line_input, "set %U id remote %U %U", |
| 260 | unformat_token, valid_chars, &name, |
| 261 | unformat_ikev2_id_type, &id_type, |
| 262 | unformat_ip4_address, &ip4)) |
| 263 | { |
| 264 | data = vec_new (u8, 4); |
| 265 | clib_memcpy (data, ip4.as_u8, 4); |
Ed Warnicke | 853e720 | 2016-08-12 11:42:26 -0700 | [diff] [blame] | 266 | r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */ |
| 267 | 0); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 268 | goto done; |
| 269 | } |
| 270 | else if (unformat (line_input, "set %U id remote %U 0x%U", |
| 271 | unformat_token, valid_chars, &name, |
| 272 | unformat_ikev2_id_type, &id_type, |
| 273 | unformat_hex_string, &data)) |
| 274 | { |
Ed Warnicke | 853e720 | 2016-08-12 11:42:26 -0700 | [diff] [blame] | 275 | r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */ |
| 276 | 0); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 277 | goto done; |
| 278 | } |
| 279 | else if (unformat (line_input, "set %U id remote %U %v", |
| 280 | unformat_token, valid_chars, &name, |
| 281 | unformat_ikev2_id_type, &id_type, &data)) |
| 282 | { |
Ed Warnicke | 853e720 | 2016-08-12 11:42:26 -0700 | [diff] [blame] | 283 | r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */ |
| 284 | 0); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 285 | goto done; |
| 286 | } |
| 287 | else if (unformat (line_input, "set %U traffic-selector local " |
| 288 | "ip-range %U - %U port-range %u - %u protocol %u", |
| 289 | unformat_token, valid_chars, &name, |
| 290 | unformat_ip4_address, &ip4, |
| 291 | unformat_ip4_address, &end_addr, |
| 292 | &tmp1, &tmp2, &tmp3)) |
| 293 | { |
| 294 | r = |
| 295 | ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2, |
| 296 | ip4, end_addr, /*local */ 1); |
| 297 | goto done; |
| 298 | } |
| 299 | else if (unformat (line_input, "set %U traffic-selector remote " |
| 300 | "ip-range %U - %U port-range %u - %u protocol %u", |
| 301 | unformat_token, valid_chars, &name, |
| 302 | unformat_ip4_address, &ip4, |
| 303 | unformat_ip4_address, &end_addr, |
| 304 | &tmp1, &tmp2, &tmp3)) |
| 305 | { |
| 306 | r = |
| 307 | ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2, |
| 308 | ip4, end_addr, /*remote */ 0); |
| 309 | goto done; |
| 310 | } |
| 311 | else |
| 312 | break; |
| 313 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 314 | |
| 315 | r = clib_error_return (0, "parse error: '%U'", |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 316 | format_unformat_error, line_input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 317 | |
| 318 | done: |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 319 | vec_free (name); |
| 320 | vec_free (data); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 321 | unformat_free (line_input); |
| 322 | return r; |
| 323 | } |
| 324 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 325 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 326 | VLIB_CLI_COMMAND (ikev2_profile_add_del_command, static) = { |
| 327 | .path = "ikev2 profile", |
| 328 | .short_help = |
| 329 | "ikev2 profile [add|del] <id>\n" |
| 330 | "ikev2 profile set <id> auth [rsa-sig|shared-key-mic] [cert-file|string|hex]" |
| 331 | " <data>\n" |
| 332 | "ikev2 profile set <id> id <local|remote> <type> <data>\n" |
| 333 | "ikev2 profile set <id> traffic-selector <local|remote> ip-range " |
| 334 | "<start-addr> - <end-addr> port-range <start-port> - <end-port> " |
| 335 | "protocol <protocol-number>", |
| 336 | .function = ikev2_profile_add_del_command_fn, |
| 337 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 338 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 339 | |
| 340 | static clib_error_t * |
| 341 | show_ikev2_profile_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 342 | unformat_input_t * input, |
| 343 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 344 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 345 | ikev2_main_t *km = &ikev2_main; |
| 346 | ikev2_profile_t *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 347 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 348 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 349 | pool_foreach (p, km->profiles, ({ |
| 350 | vlib_cli_output(vm, "profile %v", p->name); |
| 351 | |
| 352 | if (p->auth.data) |
| 353 | { |
| 354 | if (p->auth.hex) |
| 355 | vlib_cli_output(vm, " auth-method %U auth data 0x%U", |
| 356 | format_ikev2_auth_method, p->auth.method, |
| 357 | format_hex_bytes, p->auth.data, vec_len(p->auth.data)); |
| 358 | else |
| 359 | vlib_cli_output(vm, " auth-method %U auth data %v", |
| 360 | format_ikev2_auth_method, p->auth.method, p->auth.data); |
| 361 | } |
| 362 | |
| 363 | if (p->loc_id.data) |
| 364 | { |
| 365 | if (p->loc_id.type == IKEV2_ID_TYPE_ID_IPV4_ADDR) |
| 366 | vlib_cli_output(vm, " local id-type %U data %U", |
| 367 | format_ikev2_id_type, p->loc_id.type, |
| 368 | format_ip4_address, p->loc_id.data); |
| 369 | else if (p->loc_id.type == IKEV2_ID_TYPE_ID_KEY_ID) |
| 370 | vlib_cli_output(vm, " local id-type %U data 0x%U", |
| 371 | format_ikev2_id_type, p->loc_id.type, |
| 372 | format_hex_bytes, p->loc_id.data, |
| 373 | vec_len(p->loc_id.data)); |
| 374 | else |
| 375 | vlib_cli_output(vm, " local id-type %U data %v", |
| 376 | format_ikev2_id_type, p->loc_id.type, p->loc_id.data); |
| 377 | } |
| 378 | |
| 379 | if (p->rem_id.data) |
| 380 | { |
| 381 | if (p->rem_id.type == IKEV2_ID_TYPE_ID_IPV4_ADDR) |
| 382 | vlib_cli_output(vm, " remote id-type %U data %U", |
| 383 | format_ikev2_id_type, p->rem_id.type, |
| 384 | format_ip4_address, p->rem_id.data); |
| 385 | else if (p->rem_id.type == IKEV2_ID_TYPE_ID_KEY_ID) |
| 386 | vlib_cli_output(vm, " remote id-type %U data 0x%U", |
| 387 | format_ikev2_id_type, p->rem_id.type, |
| 388 | format_hex_bytes, p->rem_id.data, |
| 389 | vec_len(p->rem_id.data)); |
| 390 | else |
| 391 | vlib_cli_output(vm, " remote id-type %U data %v", |
| 392 | format_ikev2_id_type, p->rem_id.type, p->rem_id.data); |
| 393 | } |
| 394 | |
| 395 | if (p->loc_ts.end_addr.as_u32) |
| 396 | vlib_cli_output(vm, " local traffic-selector addr %U - %U port %u - %u" |
| 397 | " protocol %u", |
| 398 | format_ip4_address, &p->loc_ts.start_addr, |
| 399 | format_ip4_address, &p->loc_ts.end_addr, |
| 400 | p->loc_ts.start_port, p->loc_ts.end_port, |
| 401 | p->loc_ts.protocol_id); |
| 402 | |
| 403 | if (p->rem_ts.end_addr.as_u32) |
| 404 | vlib_cli_output(vm, " remote traffic-selector addr %U - %U port %u - %u" |
| 405 | " protocol %u", |
| 406 | format_ip4_address, &p->rem_ts.start_addr, |
| 407 | format_ip4_address, &p->rem_ts.end_addr, |
| 408 | p->rem_ts.start_port, p->rem_ts.end_port, |
| 409 | p->rem_ts.protocol_id); |
| 410 | })); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 411 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 416 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 417 | VLIB_CLI_COMMAND (show_ikev2_profile_command, static) = { |
| 418 | .path = "show ikev2 profile", |
| 419 | .short_help = "show ikev2 profile", |
| 420 | .function = show_ikev2_profile_command_fn, |
| 421 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 422 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 423 | |
| 424 | static clib_error_t * |
| 425 | set_ikev2_local_key_command_fn (vlib_main_t * vm, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 426 | unformat_input_t * input, |
| 427 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 428 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 429 | unformat_input_t _line_input, *line_input = &_line_input; |
| 430 | clib_error_t *r = 0; |
| 431 | u8 *data = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 432 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 433 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 434 | return 0; |
| 435 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 436 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 437 | { |
Matus Fabian | 698b952 | 2016-09-13 23:15:56 -0700 | [diff] [blame] | 438 | if (unformat (line_input, "%s", &data)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 439 | { |
| 440 | r = ikev2_set_local_key (vm, data); |
| 441 | goto done; |
| 442 | } |
| 443 | else |
| 444 | break; |
| 445 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 446 | |
| 447 | r = clib_error_return (0, "parse error: '%U'", |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 448 | format_unformat_error, line_input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 449 | |
| 450 | done: |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 451 | vec_free (data); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 452 | unformat_free (line_input); |
| 453 | return r; |
| 454 | } |
| 455 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 456 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 457 | VLIB_CLI_COMMAND (set_ikev2_local_key_command, static) = { |
| 458 | .path = "set ikev2 local key", |
| 459 | .short_help = |
| 460 | "set ikev2 local key <file>", |
| 461 | .function = set_ikev2_local_key_command_fn, |
| 462 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 463 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 464 | |
| 465 | clib_error_t * |
| 466 | ikev2_cli_init (vlib_main_t * vm) |
| 467 | { |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | VLIB_INIT_FUNCTION (ikev2_cli_init); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 472 | |
| 473 | /* |
| 474 | * fd.io coding-style-patch-verification: ON |
| 475 | * |
| 476 | * Local Variables: |
| 477 | * eval: (c-set-style "gnu") |
| 478 | * End: |
| 479 | */ |