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