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> |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 22 | #include <vnet/fib/fib_table.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 23 | |
| 24 | #include <vnet/ipsec/ipsec.h> |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 25 | #include <vnet/ipsec/ipsec_tun.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | |
| 27 | u8 * |
| 28 | format_ipsec_policy_action (u8 * s, va_list * args) |
| 29 | { |
| 30 | u32 i = va_arg (*args, u32); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 31 | char *t = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | |
| 33 | switch (i) |
| 34 | { |
| 35 | #define _(v,f,str) case IPSEC_POLICY_ACTION_##f: t = str; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 36 | foreach_ipsec_policy_action |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 37 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 38 | default: |
| 39 | s = format (s, "unknown"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 40 | } |
| 41 | s = format (s, "%s", t); |
| 42 | return s; |
| 43 | } |
| 44 | |
Neale Ranns | 9f231d4 | 2019-03-19 10:06:00 +0000 | [diff] [blame] | 45 | u8 * |
| 46 | format_ipsec_policy_type (u8 * s, va_list * args) |
| 47 | { |
| 48 | u32 i = va_arg (*args, u32); |
| 49 | char *t = 0; |
| 50 | |
| 51 | switch (i) |
| 52 | { |
| 53 | #define _(f,str) case IPSEC_SPD_POLICY_##f: t = str; break; |
| 54 | foreach_ipsec_spd_policy_type |
| 55 | #undef _ |
| 56 | default: |
| 57 | s = format (s, "unknown"); |
| 58 | } |
| 59 | s = format (s, "%s", t); |
| 60 | return s; |
| 61 | } |
| 62 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | uword |
| 64 | unformat_ipsec_policy_action (unformat_input_t * input, va_list * args) |
| 65 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 66 | u32 *r = va_arg (*args, u32 *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 68 | if (0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 69 | #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f; |
| 70 | foreach_ipsec_policy_action |
| 71 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 72 | else |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | return 0; |
| 74 | return 1; |
| 75 | } |
| 76 | |
| 77 | u8 * |
| 78 | format_ipsec_crypto_alg (u8 * s, va_list * args) |
| 79 | { |
| 80 | u32 i = va_arg (*args, u32); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 81 | u8 *t = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 82 | |
| 83 | switch (i) |
| 84 | { |
| 85 | #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 86 | foreach_ipsec_crypto_alg |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 88 | default: |
| 89 | s = format (s, "unknown"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 90 | } |
| 91 | s = format (s, "%s", t); |
| 92 | return s; |
| 93 | } |
| 94 | |
| 95 | uword |
| 96 | unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args) |
| 97 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 98 | u32 *r = va_arg (*args, u32 *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 100 | if (0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f; |
| 102 | foreach_ipsec_crypto_alg |
| 103 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 104 | else |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | return 0; |
| 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | u8 * |
| 110 | format_ipsec_integ_alg (u8 * s, va_list * args) |
| 111 | { |
| 112 | u32 i = va_arg (*args, u32); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 113 | u8 *t = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 114 | |
| 115 | switch (i) |
| 116 | { |
| 117 | #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 118 | foreach_ipsec_integ_alg |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 120 | default: |
| 121 | s = format (s, "unknown"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 122 | } |
| 123 | s = format (s, "%s", t); |
| 124 | return s; |
| 125 | } |
| 126 | |
| 127 | uword |
| 128 | unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args) |
| 129 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 130 | u32 *r = va_arg (*args, u32 *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 131 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 132 | if (0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 133 | #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f; |
| 134 | foreach_ipsec_integ_alg |
| 135 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 136 | else |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 137 | return 0; |
| 138 | return 1; |
| 139 | } |
| 140 | |
| 141 | u8 * |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 142 | format_ipsec_replay_window (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | { |
| 144 | u64 w = va_arg (*args, u64); |
| 145 | u8 i; |
| 146 | |
| 147 | for (i = 0; i < 64; i++) |
| 148 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 149 | s = format (s, "%u", w & (1ULL << i) ? 1 : 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | return s; |
| 153 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 154 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 155 | u8 * |
| 156 | format_ipsec_policy (u8 * s, va_list * args) |
| 157 | { |
| 158 | u32 pi = va_arg (*args, u32); |
Guillaume Solignac | 5f08ab6 | 2019-05-20 15:58:46 +0200 | [diff] [blame] | 159 | ip46_type_t ip_type = IP46_TYPE_IP4; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 160 | ipsec_main_t *im = &ipsec_main; |
| 161 | ipsec_policy_t *p; |
| 162 | vlib_counter_t counts; |
| 163 | |
| 164 | p = pool_elt_at_index (im->policies, pi); |
| 165 | |
Neale Ranns | 9f231d4 | 2019-03-19 10:06:00 +0000 | [diff] [blame] | 166 | s = format (s, " [%d] priority %d action %U type %U protocol ", |
| 167 | pi, p->priority, |
| 168 | format_ipsec_policy_action, p->policy, |
| 169 | format_ipsec_policy_type, p->type); |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 170 | if (p->protocol) |
| 171 | { |
| 172 | s = format (s, "%U", format_ip_protocol, p->protocol); |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | s = format (s, "any"); |
| 177 | } |
| 178 | if (p->policy == IPSEC_POLICY_ACTION_PROTECT) |
| 179 | { |
| 180 | s = format (s, " sa %u", p->sa_id); |
| 181 | } |
Guillaume Solignac | 5f08ab6 | 2019-05-20 15:58:46 +0200 | [diff] [blame] | 182 | if (p->is_ipv6) |
| 183 | { |
| 184 | ip_type = IP46_TYPE_IP6; |
| 185 | } |
Neale Ranns | 231c469 | 2019-03-18 17:11:28 +0000 | [diff] [blame] | 186 | |
| 187 | s = format (s, "\n local addr range %U - %U port range %u - %u", |
Guillaume Solignac | 5f08ab6 | 2019-05-20 15:58:46 +0200 | [diff] [blame] | 188 | format_ip46_address, &p->laddr.start, ip_type, |
| 189 | format_ip46_address, &p->laddr.stop, ip_type, |
Neale Ranns | a4d2431 | 2019-07-10 13:46:21 +0000 | [diff] [blame] | 190 | p->lport.start, p->lport.stop); |
Neale Ranns | 231c469 | 2019-03-18 17:11:28 +0000 | [diff] [blame] | 191 | s = format (s, "\n remote addr range %U - %U port range %u - %u", |
Guillaume Solignac | 5f08ab6 | 2019-05-20 15:58:46 +0200 | [diff] [blame] | 192 | format_ip46_address, &p->raddr.start, ip_type, |
| 193 | format_ip46_address, &p->raddr.stop, ip_type, |
Neale Ranns | a4d2431 | 2019-07-10 13:46:21 +0000 | [diff] [blame] | 194 | p->rport.start, p->rport.stop); |
Neale Ranns | 231c469 | 2019-03-18 17:11:28 +0000 | [diff] [blame] | 195 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 196 | vlib_get_combined_counter (&ipsec_spd_policy_counters, pi, &counts); |
| 197 | s = format (s, "\n packets %u bytes %u", counts.packets, counts.bytes); |
| 198 | |
| 199 | return (s); |
| 200 | } |
| 201 | |
| 202 | u8 * |
| 203 | format_ipsec_spd (u8 * s, va_list * args) |
| 204 | { |
| 205 | u32 si = va_arg (*args, u32); |
| 206 | ipsec_main_t *im = &ipsec_main; |
| 207 | ipsec_spd_t *spd; |
| 208 | u32 *i; |
| 209 | |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 210 | if (pool_is_free_index (im->spds, si)) |
| 211 | { |
| 212 | s = format (s, "No such SPD index: %d", si); |
| 213 | goto done; |
| 214 | } |
| 215 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 216 | spd = pool_elt_at_index (im->spds, si); |
| 217 | |
| 218 | s = format (s, "spd %u", spd->id); |
| 219 | |
| 220 | #define _(v, n) \ |
| 221 | s = format (s, "\n %s:", n); \ |
| 222 | vec_foreach(i, spd->policies[IPSEC_SPD_POLICY_##v]) \ |
| 223 | { \ |
| 224 | s = format (s, "\n %U", format_ipsec_policy, *i); \ |
| 225 | } |
| 226 | foreach_ipsec_spd_policy_type; |
| 227 | #undef _ |
| 228 | |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 229 | done: |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 230 | return (s); |
| 231 | } |
| 232 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 233 | u8 * |
| 234 | format_ipsec_key (u8 * s, va_list * args) |
| 235 | { |
| 236 | ipsec_key_t *key = va_arg (*args, ipsec_key_t *); |
| 237 | |
| 238 | return (format (s, "%U", format_hex_bytes, key->data, key->len)); |
| 239 | } |
| 240 | |
| 241 | uword |
| 242 | unformat_ipsec_key (unformat_input_t * input, va_list * args) |
| 243 | { |
| 244 | ipsec_key_t *key = va_arg (*args, ipsec_key_t *); |
| 245 | u8 *data; |
| 246 | |
| 247 | if (unformat (input, "%U", unformat_hex_string, &data)) |
| 248 | { |
| 249 | ipsec_mk_key (key, data, vec_len (data)); |
| 250 | vec_free (data); |
| 251 | } |
| 252 | else |
| 253 | return 0; |
| 254 | return 1; |
| 255 | } |
| 256 | |
| 257 | u8 * |
Neale Ranns | e524d45 | 2019-02-19 15:22:46 +0000 | [diff] [blame] | 258 | format_ipsec_sa_flags (u8 * s, va_list * args) |
| 259 | { |
| 260 | ipsec_sa_flags_t flags = va_arg (*args, int); |
| 261 | |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 262 | #define _(v, f, str) if (flags & IPSEC_SA_FLAG_##f) s = format(s, "%s ", str); |
Neale Ranns | e524d45 | 2019-02-19 15:22:46 +0000 | [diff] [blame] | 263 | foreach_ipsec_sa_flags |
| 264 | #undef _ |
| 265 | return (s); |
| 266 | } |
| 267 | |
| 268 | u8 * |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 269 | format_ipsec_sa (u8 * s, va_list * args) |
| 270 | { |
| 271 | u32 sai = va_arg (*args, u32); |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 272 | ipsec_format_flags_t flags = va_arg (*args, ipsec_format_flags_t); |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 273 | ipsec_main_t *im = &ipsec_main; |
Neale Ranns | eba31ec | 2019-02-17 18:04:27 +0000 | [diff] [blame] | 274 | vlib_counter_t counts; |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 275 | u32 tx_table_id; |
| 276 | ipsec_sa_t *sa; |
| 277 | |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 278 | if (pool_is_free_index (im->sad, sai)) |
| 279 | { |
| 280 | s = format (s, "No such SA index: %d", sai); |
| 281 | goto done; |
| 282 | } |
| 283 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 284 | sa = pool_elt_at_index (im->sad, sai); |
| 285 | |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 286 | s = format (s, "[%d] sa %u (0x%x) spi %u (0x%08x) protocol:%s flags:[%U]", |
Neale Ranns | 495d7ff | 2019-07-12 09:15:26 +0000 | [diff] [blame] | 287 | sai, sa->id, sa->id, sa->spi, sa->spi, |
Neale Ranns | e524d45 | 2019-02-19 15:22:46 +0000 | [diff] [blame] | 288 | sa->protocol ? "esp" : "ah", format_ipsec_sa_flags, sa->flags); |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 289 | |
| 290 | if (!(flags & IPSEC_FORMAT_DETAIL)) |
| 291 | goto done; |
| 292 | |
Neale Ranns | 495d7ff | 2019-07-12 09:15:26 +0000 | [diff] [blame] | 293 | s = format (s, "\n locks %d", sa->node.fn_locks); |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 294 | s = format (s, "\n salt 0x%x", clib_net_to_host_u32 (sa->salt)); |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 295 | s = format (s, "\n thread-indices [encrypt:%d decrypt:%d]", |
| 296 | sa->encrypt_thread_index, sa->decrypt_thread_index); |
Neale Ranns | 00a4420 | 2019-03-21 16:36:28 +0000 | [diff] [blame] | 297 | s = format (s, "\n seq %u seq-hi %u", sa->seq, sa->seq_hi); |
| 298 | s = format (s, "\n last-seq %u last-seq-hi %u window %U", |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 299 | sa->last_seq, sa->last_seq_hi, |
| 300 | format_ipsec_replay_window, sa->replay_window); |
Neale Ranns | b64cd2c | 2019-04-16 16:21:57 -0700 | [diff] [blame] | 301 | s = format (s, "\n crypto alg %U", |
| 302 | format_ipsec_crypto_alg, sa->crypto_alg); |
Christian E. Hopps | 01d61e7 | 2019-09-27 14:43:22 -0400 | [diff] [blame] | 303 | if (sa->crypto_alg && (flags & IPSEC_FORMAT_INSECURE)) |
Neale Ranns | b64cd2c | 2019-04-16 16:21:57 -0700 | [diff] [blame] | 304 | s = format (s, " key %U", format_ipsec_key, &sa->crypto_key); |
Christian E. Hopps | 01d61e7 | 2019-09-27 14:43:22 -0400 | [diff] [blame] | 305 | else |
| 306 | s = format (s, " key [redacted]"); |
Neale Ranns | b64cd2c | 2019-04-16 16:21:57 -0700 | [diff] [blame] | 307 | s = format (s, "\n integrity alg %U", |
| 308 | format_ipsec_integ_alg, sa->integ_alg); |
Christian E. Hopps | 01d61e7 | 2019-09-27 14:43:22 -0400 | [diff] [blame] | 309 | if (sa->integ_alg && (flags & IPSEC_FORMAT_INSECURE)) |
Neale Ranns | b64cd2c | 2019-04-16 16:21:57 -0700 | [diff] [blame] | 310 | s = format (s, " key %U", format_ipsec_key, &sa->integ_key); |
Christian E. Hopps | 01d61e7 | 2019-09-27 14:43:22 -0400 | [diff] [blame] | 311 | else |
| 312 | s = format (s, " key [redacted]"); |
Neale Ranns | abc5660 | 2020-04-01 09:45:23 +0000 | [diff] [blame] | 313 | s = format (s, "\n UDP:[src:%d dst:%d]", |
| 314 | clib_host_to_net_u16 (sa->udp_hdr.src_port), |
| 315 | clib_host_to_net_u16 (sa->udp_hdr.dst_port)); |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 316 | |
Neale Ranns | eba31ec | 2019-02-17 18:04:27 +0000 | [diff] [blame] | 317 | vlib_get_combined_counter (&ipsec_sa_counters, sai, &counts); |
| 318 | s = format (s, "\n packets %u bytes %u", counts.packets, counts.bytes); |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 319 | |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 320 | if (ipsec_sa_is_set_IS_TUNNEL (sa)) |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 321 | { |
| 322 | tx_table_id = fib_table_get_table_id (sa->tx_fib_index, |
| 323 | FIB_PROTOCOL_IP4); |
| 324 | s = format (s, "\n table-ID %d tunnel src %U dst %U", |
| 325 | tx_table_id, |
| 326 | format_ip46_address, &sa->tunnel_src_addr, IP46_TYPE_ANY, |
| 327 | format_ip46_address, &sa->tunnel_dst_addr, IP46_TYPE_ANY); |
Neale Ranns | 2b5ba95 | 2019-04-02 10:15:40 +0000 | [diff] [blame] | 328 | if (!ipsec_sa_is_set_IS_INBOUND (sa)) |
| 329 | { |
| 330 | s = |
| 331 | format (s, "\n resovle via fib-entry: %d", |
| 332 | sa->fib_entry_index); |
| 333 | s = format (s, "\n stacked on:"); |
Neale Ranns | 72f2a3a | 2019-06-17 15:43:38 +0000 | [diff] [blame] | 334 | s = format (s, "\n %U", format_dpo_id, &sa->dpo, 6); |
Neale Ranns | 2b5ba95 | 2019-04-02 10:15:40 +0000 | [diff] [blame] | 335 | } |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Neale Ranns | b294f10 | 2019-04-03 13:17:50 +0000 | [diff] [blame] | 338 | done: |
| 339 | return (s); |
| 340 | } |
| 341 | |
| 342 | u8 * |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 343 | format_ipsec_tun_protect_index (u8 * s, va_list * args) |
| 344 | { |
| 345 | u32 itpi = va_arg (*args, index_t); |
| 346 | ipsec_tun_protect_t *itp; |
| 347 | |
| 348 | if (pool_is_free_index (ipsec_tun_protect_pool, itpi)) |
| 349 | return (format (s, "No such tunnel index: %d", itpi)); |
| 350 | |
| 351 | itp = pool_elt_at_index (ipsec_tun_protect_pool, itpi); |
| 352 | |
| 353 | return (format (s, "%U", format_ipsec_tun_protect, itp)); |
| 354 | } |
| 355 | |
Neale Ranns | dd4ccf2 | 2020-06-30 07:47:14 +0000 | [diff] [blame^] | 356 | u8 * |
| 357 | format_ipsec_tun_protect_flags (u8 * s, va_list * args) |
| 358 | { |
| 359 | ipsec_protect_flags_t flags = va_arg (*args, int); |
| 360 | |
| 361 | if (IPSEC_PROTECT_NONE == flags) |
| 362 | s = format (s, "none"); |
| 363 | #define _(a,b,c) \ |
| 364 | else if (flags & IPSEC_PROTECT_##a) \ |
| 365 | s = format (s, "%s", c); \ |
| 366 | foreach_ipsec_protect_flags |
| 367 | #undef _ |
| 368 | |
| 369 | return (s); |
| 370 | } |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 371 | |
| 372 | u8 * |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 373 | format_ipsec_tun_protect (u8 * s, va_list * args) |
| 374 | { |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 375 | ipsec_tun_protect_t *itp = va_arg (*args, ipsec_tun_protect_t *); |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 376 | u32 sai; |
| 377 | |
Neale Ranns | dd4ccf2 | 2020-06-30 07:47:14 +0000 | [diff] [blame^] | 378 | s = format (s, "%U flags:[%U]", format_vnet_sw_if_index_name, |
| 379 | vnet_get_main (), itp->itp_sw_if_index, |
| 380 | format_ipsec_tun_protect_flags, itp->itp_flags); |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 381 | if (!ip_address_is_zero (itp->itp_key)) |
| 382 | s = format (s, ": %U", format_ip_address, itp->itp_key); |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 383 | s = format (s, "\n output-sa:"); |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 384 | s = format (s, "\n %U", format_ipsec_sa, itp->itp_out_sa, |
| 385 | IPSEC_FORMAT_BRIEF); |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 386 | |
| 387 | s = format (s, "\n input-sa:"); |
| 388 | /* *INDENT-OFF* */ |
| 389 | FOR_EACH_IPSEC_PROTECT_INPUT_SAI(itp, sai, |
| 390 | ({ |
| 391 | s = format (s, "\n %U", format_ipsec_sa, sai, IPSEC_FORMAT_BRIEF); |
| 392 | })); |
| 393 | /* *INDENT-ON* */ |
| 394 | |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 395 | return (s); |
| 396 | } |
| 397 | |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 398 | u8 * |
| 399 | format_ipsec4_tunnel_key (u8 * s, va_list * args) |
| 400 | { |
| 401 | ipsec4_tunnel_key_t *key = va_arg (*args, ipsec4_tunnel_key_t *); |
| 402 | |
| 403 | s = format (s, "remote:%U spi:%u (0x%08x)", |
| 404 | format_ip4_address, &key->remote_ip, |
| 405 | clib_net_to_host_u32 (key->spi), |
| 406 | clib_net_to_host_u32 (key->spi)); |
| 407 | |
| 408 | return (s); |
| 409 | } |
| 410 | |
| 411 | u8 * |
| 412 | format_ipsec6_tunnel_key (u8 * s, va_list * args) |
| 413 | { |
| 414 | ipsec6_tunnel_key_t *key = va_arg (*args, ipsec6_tunnel_key_t *); |
| 415 | |
| 416 | s = format (s, "remote:%U spi:%u (0x%08x)", |
| 417 | format_ip6_address, &key->remote_ip, |
| 418 | clib_net_to_host_u32 (key->spi), |
| 419 | clib_net_to_host_u32 (key->spi)); |
| 420 | |
| 421 | return (s); |
| 422 | } |
| 423 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 424 | /* |
| 425 | * fd.io coding-style-patch-verification: ON |
| 426 | * |
| 427 | * Local Variables: |
| 428 | * eval: (c-set-style "gnu") |
| 429 | * End: |
| 430 | */ |