FD.io VPP  v21.10.1-2-g0a485f517
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 <plugins/ikev2/ikev2.h>
23 
24 u8 *
25 format_ikev2_sa_transform (u8 * s, va_list * args)
26 {
27  ikev2_sa_transform_t *tr = va_arg (*args, ikev2_sa_transform_t *);
28 
29  if (!tr)
30  return s;
31 
33  return s;
34 
35  s = format (s, "%U:", format_ikev2_transform_type, tr->type);
36 
37  switch (tr->type)
38  {
39  case IKEV2_TRANSFORM_TYPE_ENCR:
41  break;
42  case IKEV2_TRANSFORM_TYPE_PRF:
44  break;
45  case IKEV2_TRANSFORM_TYPE_INTEG:
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:
53  break;
54  default:
55  break;
56  }
57 
58  if (tr->type == IKEV2_TRANSFORM_TYPE_ENCR &&
59  tr->encr_type == IKEV2_TRANSFORM_ENCR_TYPE_AES_CBC && tr->key_len)
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));
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;
99 MACRO_FORMAT (auth_method)
100 #undef _
101 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_AUTH_METHOD_##f;
102  MACRO_UNFORMAT (auth_method)
103 #undef _
104 #define _(v,f,str) case IKEV2_TRANSFORM_TYPE_##f: t = str; break;
105  MACRO_FORMAT (transform_type)
106 #undef _
107 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_TYPE_##f;
108  MACRO_UNFORMAT (transform_type)
109 #undef _
110 #define _(v,f) case IKEV2_NOTIFY_MSG_##f: t = #f; break;
111  MACRO_FORMAT (notify_msg_type)
112 #undef _
113 #define _(v,f,str) case IKEV2_ID_TYPE_##f: t = str; break;
114  MACRO_FORMAT (id_type)
115 #undef _
116 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_ID_TYPE_##f;
117  MACRO_UNFORMAT (id_type)
118 #undef _
119 #define _(v,f,str) case IKEV2_TRANSFORM_ENCR_TYPE_##f: t = str; break;
120  MACRO_FORMAT (transform_encr_type)
121 #undef _
122 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_ENCR_TYPE_##f;
123  MACRO_UNFORMAT (transform_encr_type)
124 #undef _
125 #define _(v,f,str) case IKEV2_TRANSFORM_PRF_TYPE_##f: t = str; break;
126  MACRO_FORMAT (transform_prf_type)
127 #undef _
128 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_PRF_TYPE_##f;
129  MACRO_UNFORMAT (transform_prf_type)
130 #undef _
131 #define _(v,f,str) case IKEV2_TRANSFORM_INTEG_TYPE_##f: t = str; break;
132  MACRO_FORMAT (transform_integ_type)
133 #undef _
134 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_INTEG_TYPE_##f;
135  MACRO_UNFORMAT (transform_integ_type)
136 #undef _
137 #define _(v,f,str) case IKEV2_TRANSFORM_DH_TYPE_##f: t = str; break;
138  MACRO_FORMAT (transform_dh_type)
139 #undef _
140 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_DH_TYPE_##f;
141  MACRO_UNFORMAT (transform_dh_type)
142 #undef _
143 #define _(v,f,str) case IKEV2_TRANSFORM_ESN_TYPE_##f: t = str; break;
144  MACRO_FORMAT (transform_esn_type)
145 #undef _
146 #define _(v,f,str) else if (unformat (input, str)) *r = IKEV2_TRANSFORM_ESN_TYPE_##f;
147  MACRO_UNFORMAT (transform_esn_type)
148 #undef _
149 /*
150  * fd.io coding-style-patch-verification: ON
151  *
152  * Local Variables:
153  * eval: (c-set-style "gnu")
154  * End:
155  */
ipsec.h
ikev2_sa_transform_t::encr_type
ikev2_transform_encr_type_t encr_type
Definition: ikev2_priv.h:219
ikev2_sa_transform_t::dh_type
ikev2_transform_dh_type_t dh_type
Definition: ikev2_priv.h:222
ikev2_sa_transform_t::integ_type
ikev2_transform_integ_type_t integ_type
Definition: ikev2_priv.h:221
MACRO_UNFORMAT
#define MACRO_UNFORMAT(lc)
Definition: ikev2_format.c:85
format_hex_bytes
u8 * format_hex_bytes(u8 *s, va_list *va)
Definition: std-formats.c:84
format_ikev2_transform_prf_type
u8 * format_ikev2_transform_prf_type(u8 *s, va_list *args)
ikev2_sa_transform_t
Definition: ikev2_priv.h:213
ikev2_priv.h
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
format_ikev2_transform_type
u8 * format_ikev2_transform_type(u8 *s, va_list *args)
format_ikev2_sa_transform
u8 * format_ikev2_sa_transform(u8 *s, va_list *args)
Definition: ikev2_format.c:25
format_ikev2_transform_dh_type
u8 * format_ikev2_transform_dh_type(u8 *s, va_list *args)
ikev2_sa_transform_t::attrs
u8 * attrs
Definition: ikev2_priv.h:225
format_ikev2_transform_integ_type
u8 * format_ikev2_transform_integ_type(u8 *s, va_list *args)
interface.h
ikev2.h
format_ikev2_transform_esn_type
u8 * format_ikev2_transform_esn_type(u8 *s, va_list *args)
MACRO_FORMAT
#define MACRO_FORMAT(lc)
Definition: ikev2_format.c:71
ikev2_sa_transform_t::esn_type
ikev2_transform_esn_type_t esn_type
Definition: ikev2_priv.h:223
format
description fragment has unexpected format
Definition: map.api:433
ikev2_sa_transform_t::key_len
u16 key_len
Definition: ikev2_priv.h:226
ip.h
IKEV2_TRANSFORM_NUM_TYPES
@ IKEV2_TRANSFORM_NUM_TYPES
Definition: ikev2.h:222
ikev2_sa_transform_t::type
ikev2_transform_type_t type
Definition: ikev2_priv.h:215
ikev2_sa_transform_t::prf_type
ikev2_transform_prf_type_t prf_type
Definition: ikev2_priv.h:220
u8
unsigned char u8
Definition: types.h:56
format_ikev2_transform_encr_type
u8 * format_ikev2_transform_encr_type(u8 *s, va_list *args)
vnet.h
api_errno.h