blob: 4d7a007f80df00faa84508f7d612dde9e9dfae43 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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)166a9d42016-08-06 11:00:56 -070024u8 *
25format_ikev2_sa_transform (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070026{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070027 ikev2_sa_transform_t *tr = va_arg (*args, ikev2_sa_transform_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070028
29 if (!tr)
30 return s;
31
32 if (tr->type >= IKEV2_TRANSFORM_NUM_TYPES)
33 return s;
34
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070035 s = format (s, "%U:", format_ikev2_transform_type, tr->type);
Ed Warnickecb9cada2015-12-08 15:45:58 -070036
37 switch (tr->type)
38 {
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070039 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 Warnickecb9cada2015-12-08 15:45:58 -070056 }
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)166a9d42016-08-06 11:00:56 -070060 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 Warnickecb9cada2015-12-08 15:45:58 -070067
68 return s;
69}
70
71#define MACRO_FORMAT(lc) \
72u8 * 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) \
86uword \
87unformat_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)166a9d42016-08-06 11:00:56 -070099MACRO_FORMAT (auth_method)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100#undef _
101#define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_AUTH_METHOD_##f;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700102 MACRO_UNFORMAT (auth_method)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700103#undef _
Ed Warnickecb9cada2015-12-08 15:45:58 -0700104#define _(v,f,str) case IKEV2_TRANSFORM_TYPE_##f: t = str; break;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700105 MACRO_FORMAT (transform_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700106#undef _
107#define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_TYPE_##f;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700108 MACRO_UNFORMAT (transform_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109#undef _
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110#define _(v,f) case IKEV2_NOTIFY_MSG_##f: t = #f; break;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700111 MACRO_FORMAT (notify_msg_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700112#undef _
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113#define _(v,f,str) case IKEV2_ID_TYPE_##f: t = str; break;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700114 MACRO_FORMAT (id_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700115#undef _
116#define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_ID_TYPE_##f;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700117 MACRO_UNFORMAT (id_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700118#undef _
Ed Warnickecb9cada2015-12-08 15:45:58 -0700119#define _(v,f,str) case IKEV2_TRANSFORM_ENCR_TYPE_##f: t = str; break;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700120 MACRO_FORMAT (transform_encr_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121#undef _
122#define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_ENCR_TYPE_##f;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700123 MACRO_UNFORMAT (transform_encr_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124#undef _
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125#define _(v,f,str) case IKEV2_TRANSFORM_PRF_TYPE_##f: t = str; break;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700126 MACRO_FORMAT (transform_prf_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700127#undef _
128#define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_PRF_TYPE_##f;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700129 MACRO_UNFORMAT (transform_prf_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130#undef _
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131#define _(v,f,str) case IKEV2_TRANSFORM_INTEG_TYPE_##f: t = str; break;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700132 MACRO_FORMAT (transform_integ_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700133#undef _
134#define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_INTEG_TYPE_##f;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700135 MACRO_UNFORMAT (transform_integ_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700136#undef _
Ed Warnickecb9cada2015-12-08 15:45:58 -0700137#define _(v,f,str) case IKEV2_TRANSFORM_DH_TYPE_##f: t = str; break;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700138 MACRO_FORMAT (transform_dh_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700139#undef _
140#define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_DH_TYPE_##f;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700141 MACRO_UNFORMAT (transform_dh_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700142#undef _
Ed Warnickecb9cada2015-12-08 15:45:58 -0700143#define _(v,f,str) case IKEV2_TRANSFORM_ESN_TYPE_##f: t = str; break;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700144 MACRO_FORMAT (transform_esn_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700145#undef _
146#define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_ESN_TYPE_##f;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700147 MACRO_UNFORMAT (transform_esn_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700148#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700149/*
150 * fd.io coding-style-patch-verification: ON
151 *
152 * Local Variables:
153 * eval: (c-set-style "gnu")
154 * End:
155 */