FD.io VPP  v16.06
Vector Packet Processing
ikev2_format.c
Go to the documentation of this file.
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 
24 u8 * format_ikev2_sa_transform(u8 * s, va_list * args)
25 {
26  ikev2_sa_transform_t * tr = va_arg (*args, ikev2_sa_transform_t *);
27 
28  if (!tr)
29  return s;
30 
32  return s;
33 
34  s = format(s,"%U:", format_ikev2_transform_type, tr->type);
35 
36  switch (tr->type)
37  {
38  case IKEV2_TRANSFORM_TYPE_ENCR:
40  break;
41  case IKEV2_TRANSFORM_TYPE_PRF:
43  break;
44  case IKEV2_TRANSFORM_TYPE_INTEG:
46  break;
47  case IKEV2_TRANSFORM_TYPE_DH:
49  break;
50  case IKEV2_TRANSFORM_TYPE_ESN:
52  break;
53  default:
54  break;
55  }
56 
57  if (tr->type == IKEV2_TRANSFORM_TYPE_ENCR &&
58  tr->encr_type == IKEV2_TRANSFORM_ENCR_TYPE_AES_CBC && tr->key_len)
59  s = format(s, "-%u", tr->key_len * 8);
60  else if (vec_len(tr->attrs) == 4 && tr->attrs[0] == 0x80 && tr->attrs[1] == 0x0e)
61  s = format(s, "-%u", tr->attrs[2] * 256 + tr->attrs[3]);
62  else if (vec_len(tr->attrs))
63  s = format(s, "(unknown attr %U)", format_hex_bytes,
64  tr->attrs, vec_len(tr->attrs));
65 
66  return s;
67 }
68 
69 #define MACRO_FORMAT(lc) \
70 u8 * format_ikev2_##lc (u8 * s, va_list * args) \
71 { \
72  u32 i = va_arg (*args, u32); \
73  char * t = 0; \
74  switch (i) { \
75  foreach_ikev2_##lc \
76  default: \
77  return format (s, "unknown (%u)", i); \
78  } \
79  s = format (s, "%s", t); \
80  return s; \
81 }
82 
83 #define MACRO_UNFORMAT(lc) \
84 uword \
85 unformat_ikev2_##lc (unformat_input_t * input, \
86  va_list * args) \
87 { \
88  u32 * r = va_arg (*args, u32 *); \
89  if (0) ; \
90  foreach_ikev2_##lc \
91  else \
92  return 0; \
93  return 1; \
94 }
95 
96 #define _(v,f,str) case IKEV2_AUTH_METHOD_##f: t = str; break;
97 MACRO_FORMAT(auth_method)
98 #undef _
99 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_AUTH_METHOD_##f;
100 MACRO_UNFORMAT(auth_method)
101 #undef _
102 
103 #define _(v,f,str) case IKEV2_TRANSFORM_TYPE_##f: t = str; break;
104 MACRO_FORMAT(transform_type)
105 #undef _
106 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_TYPE_##f;
107 MACRO_UNFORMAT(transform_type)
108 #undef _
109 
110 #define _(v,f) case IKEV2_NOTIFY_MSG_##f: t = #f; break;
111 MACRO_FORMAT(notify_msg_type)
112 #undef _
113 
114 #define _(v,f,str) case IKEV2_ID_TYPE_##f: t = str; break;
115 MACRO_FORMAT(id_type)
116 #undef _
117 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_ID_TYPE_##f;
118 MACRO_UNFORMAT(id_type)
119 #undef _
120 
121 #define _(v,f,str) case IKEV2_TRANSFORM_ENCR_TYPE_##f: t = str; break;
122 MACRO_FORMAT(transform_encr_type)
123 #undef _
124 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_ENCR_TYPE_##f;
125 MACRO_UNFORMAT(transform_encr_type)
126 #undef _
127 
128 #define _(v,f,str) case IKEV2_TRANSFORM_PRF_TYPE_##f: t = str; break;
129 MACRO_FORMAT(transform_prf_type)
130 #undef _
131 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_PRF_TYPE_##f;
132 MACRO_UNFORMAT(transform_prf_type)
133 #undef _
134 
135 #define _(v,f,str) case IKEV2_TRANSFORM_INTEG_TYPE_##f: t = str; break;
136 MACRO_FORMAT(transform_integ_type)
137 #undef _
138 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_INTEG_TYPE_##f;
139 MACRO_UNFORMAT(transform_integ_type)
140 #undef _
141 
142 #define _(v,f,str) case IKEV2_TRANSFORM_DH_TYPE_##f: t = str; break;
143 MACRO_FORMAT(transform_dh_type)
144 #undef _
145 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_DH_TYPE_##f;
146 MACRO_UNFORMAT(transform_dh_type)
147 #undef _
148 
149 #define _(v,f,str) case IKEV2_TRANSFORM_ESN_TYPE_##f: t = str; break;
150 MACRO_FORMAT(transform_esn_type)
151 #undef _
152 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_ESN_TYPE_##f;
153 MACRO_UNFORMAT(transform_esn_type)
154 #undef _
155 
ikev2_transform_type_t type
Definition: ikev2_priv.h:65
ikev2_transform_esn_type_t esn_type
Definition: ikev2_priv.h:72
u8 * format_ikev2_sa_transform(u8 *s, va_list *args)
Definition: ikev2_format.c:24
u8 * format_hex_bytes(u8 *s, va_list *va)
Definition: std-formats.c:79
#define MACRO_FORMAT(lc)
Definition: ikev2_format.c:69
u8 * format_ikev2_transform_prf_type(u8 *s, va_list *args)
ikev2_transform_dh_type_t dh_type
Definition: ikev2_priv.h:71
u8 * format_ikev2_transform_encr_type(u8 *s, va_list *args)
u8 * format_ikev2_transform_type(u8 *s, va_list *args)
u8 * format(u8 *s, char *fmt,...)
Definition: format.c:405
u8 * format_ikev2_transform_dh_type(u8 *s, va_list *args)
u8 * format_ikev2_transform_integ_type(u8 *s, va_list *args)
ikev2_transform_encr_type_t encr_type
Definition: ikev2_priv.h:68
ikev2_transform_integ_type_t integ_type
Definition: ikev2_priv.h:70
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
u8 * format_ikev2_transform_esn_type(u8 *s, va_list *args)
ikev2_transform_prf_type_t prf_type
Definition: ikev2_priv.h:69
#define MACRO_UNFORMAT(lc)
Definition: ikev2_format.c:83