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 <vnet/vnet.h> |
| 16 | #include <vnet/api_errno.h> |
| 17 | #include <vnet/ip/ip.h> |
| 18 | #include <vnet/interface.h> |
| 19 | |
| 20 | #include <vnet/ipsec/ipsec.h> |
| 21 | #include <vnet/ipsec/ikev2.h> |
| 22 | #include <vnet/ipsec/ikev2_priv.h> |
| 23 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 24 | u8 * |
| 25 | format_ikev2_sa_transform (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 27 | ikev2_sa_transform_t *tr = va_arg (*args, ikev2_sa_transform_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 28 | |
| 29 | if (!tr) |
| 30 | return s; |
| 31 | |
| 32 | if (tr->type >= IKEV2_TRANSFORM_NUM_TYPES) |
| 33 | return s; |
| 34 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 35 | s = format (s, "%U:", format_ikev2_transform_type, tr->type); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 36 | |
| 37 | switch (tr->type) |
| 38 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 39 | case IKEV2_TRANSFORM_TYPE_ENCR: |
| 40 | s = format (s, "%U", format_ikev2_transform_encr_type, tr->encr_type); |
| 41 | break; |
| 42 | case IKEV2_TRANSFORM_TYPE_PRF: |
| 43 | s = format (s, "%U", format_ikev2_transform_prf_type, tr->prf_type); |
| 44 | break; |
| 45 | case IKEV2_TRANSFORM_TYPE_INTEG: |
| 46 | s = format (s, "%U", format_ikev2_transform_integ_type, tr->integ_type); |
| 47 | break; |
| 48 | case IKEV2_TRANSFORM_TYPE_DH: |
| 49 | s = format (s, "%U", format_ikev2_transform_dh_type, tr->dh_type); |
| 50 | break; |
| 51 | case IKEV2_TRANSFORM_TYPE_ESN: |
| 52 | s = format (s, "%U", format_ikev2_transform_esn_type, tr->esn_type); |
| 53 | break; |
| 54 | default: |
| 55 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | if (tr->type == IKEV2_TRANSFORM_TYPE_ENCR && |
| 59 | tr->encr_type == IKEV2_TRANSFORM_ENCR_TYPE_AES_CBC && tr->key_len) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 60 | s = format (s, "-%u", tr->key_len * 8); |
| 61 | else if (vec_len (tr->attrs) == 4 && tr->attrs[0] == 0x80 |
| 62 | && tr->attrs[1] == 0x0e) |
| 63 | s = format (s, "-%u", tr->attrs[2] * 256 + tr->attrs[3]); |
| 64 | else if (vec_len (tr->attrs)) |
| 65 | s = format (s, "(unknown attr %U)", format_hex_bytes, |
| 66 | tr->attrs, vec_len (tr->attrs)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | |
| 68 | return s; |
| 69 | } |
| 70 | |
| 71 | #define MACRO_FORMAT(lc) \ |
| 72 | u8 * format_ikev2_##lc (u8 * s, va_list * args) \ |
| 73 | { \ |
| 74 | u32 i = va_arg (*args, u32); \ |
| 75 | char * t = 0; \ |
| 76 | switch (i) { \ |
| 77 | foreach_ikev2_##lc \ |
| 78 | default: \ |
| 79 | return format (s, "unknown (%u)", i); \ |
| 80 | } \ |
| 81 | s = format (s, "%s", t); \ |
| 82 | return s; \ |
| 83 | } |
| 84 | |
| 85 | #define MACRO_UNFORMAT(lc) \ |
| 86 | uword \ |
| 87 | unformat_ikev2_##lc (unformat_input_t * input, \ |
| 88 | va_list * args) \ |
| 89 | { \ |
| 90 | u32 * r = va_arg (*args, u32 *); \ |
| 91 | if (0) ; \ |
| 92 | foreach_ikev2_##lc \ |
| 93 | else \ |
| 94 | return 0; \ |
| 95 | return 1; \ |
| 96 | } |
| 97 | |
| 98 | #define _(v,f,str) case IKEV2_AUTH_METHOD_##f: t = str; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 99 | MACRO_FORMAT (auth_method) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 100 | #undef _ |
| 101 | #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_AUTH_METHOD_##f; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 102 | MACRO_UNFORMAT (auth_method) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 103 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 104 | #define _(v,f,str) case IKEV2_TRANSFORM_TYPE_##f: t = str; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 105 | MACRO_FORMAT (transform_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 106 | #undef _ |
| 107 | #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_TYPE_##f; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 108 | MACRO_UNFORMAT (transform_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 109 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 110 | #define _(v,f) case IKEV2_NOTIFY_MSG_##f: t = #f; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 111 | MACRO_FORMAT (notify_msg_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 112 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | #define _(v,f,str) case IKEV2_ID_TYPE_##f: t = str; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 114 | MACRO_FORMAT (id_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 115 | #undef _ |
| 116 | #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_ID_TYPE_##f; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 117 | MACRO_UNFORMAT (id_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 118 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | #define _(v,f,str) case IKEV2_TRANSFORM_ENCR_TYPE_##f: t = str; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 120 | MACRO_FORMAT (transform_encr_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | #undef _ |
| 122 | #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_ENCR_TYPE_##f; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 123 | MACRO_UNFORMAT (transform_encr_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 125 | #define _(v,f,str) case IKEV2_TRANSFORM_PRF_TYPE_##f: t = str; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 126 | MACRO_FORMAT (transform_prf_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 127 | #undef _ |
| 128 | #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_PRF_TYPE_##f; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 129 | MACRO_UNFORMAT (transform_prf_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 131 | #define _(v,f,str) case IKEV2_TRANSFORM_INTEG_TYPE_##f: t = str; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 132 | MACRO_FORMAT (transform_integ_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 133 | #undef _ |
| 134 | #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_INTEG_TYPE_##f; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 135 | MACRO_UNFORMAT (transform_integ_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 136 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 137 | #define _(v,f,str) case IKEV2_TRANSFORM_DH_TYPE_##f: t = str; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 138 | MACRO_FORMAT (transform_dh_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 139 | #undef _ |
| 140 | #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_DH_TYPE_##f; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 141 | MACRO_UNFORMAT (transform_dh_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | #define _(v,f,str) case IKEV2_TRANSFORM_ESN_TYPE_##f: t = str; break; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 144 | MACRO_FORMAT (transform_esn_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 145 | #undef _ |
| 146 | #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_ESN_TYPE_##f; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 147 | MACRO_UNFORMAT (transform_esn_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 148 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 149 | /* |
| 150 | * fd.io coding-style-patch-verification: ON |
| 151 | * |
| 152 | * Local Variables: |
| 153 | * eval: (c-set-style "gnu") |
| 154 | * End: |
| 155 | */ |