FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
ipsec_types_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 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 
16 
18 #include <vlibapi/api_types.h>
19 
20 int
21 ipsec_proto_decode (vl_api_ipsec_proto_t in, ipsec_protocol_t * out)
22 {
23  in = clib_net_to_host_u32 (in);
24 
25  switch (in)
26  {
28  *out = IPSEC_PROTOCOL_ESP;
29  return (0);
30  case IPSEC_API_PROTO_AH:
31  *out = IPSEC_PROTOCOL_AH;
32  return (0);
33  }
34  return (VNET_API_ERROR_INVALID_PROTOCOL);
35 }
36 
37 vl_api_ipsec_proto_t
38 ipsec_proto_encode (ipsec_protocol_t p)
39 {
40  switch (p)
41  {
42  case IPSEC_PROTOCOL_ESP:
43  return clib_host_to_net_u32 (IPSEC_API_PROTO_ESP);
44  case IPSEC_PROTOCOL_AH:
45  return clib_host_to_net_u32 (IPSEC_API_PROTO_AH);
46  }
47  return (VNET_API_ERROR_UNIMPLEMENTED);
48 }
49 
50 int
51 ipsec_crypto_algo_decode (vl_api_ipsec_crypto_alg_t in,
52  ipsec_crypto_alg_t * out)
53 {
54  in = clib_net_to_host_u32 (in);
55 
56  switch (in)
57  {
58 #define _(v,f,s) case IPSEC_API_CRYPTO_ALG_##f: \
59  *out = IPSEC_CRYPTO_ALG_##f; \
60  return (0);
62 #undef _
63  }
64  return (VNET_API_ERROR_INVALID_ALGORITHM);
65 }
66 
67 vl_api_ipsec_crypto_alg_t
68 ipsec_crypto_algo_encode (ipsec_crypto_alg_t c)
69 {
70  switch (c)
71  {
72 #define _(v,f,s) case IPSEC_CRYPTO_ALG_##f: \
73  return clib_host_to_net_u32(IPSEC_API_CRYPTO_ALG_##f);
75 #undef _
76  case IPSEC_CRYPTO_N_ALG:
77  break;
78  }
79  ASSERT (0);
80  return (VNET_API_ERROR_UNIMPLEMENTED);
81 }
82 
83 int
84 ipsec_integ_algo_decode (vl_api_ipsec_integ_alg_t in, ipsec_integ_alg_t * out)
85 {
86  in = clib_net_to_host_u32 (in);
87 
88  switch (in)
89  {
90 #define _(v,f,s) case IPSEC_API_INTEG_ALG_##f: \
91  *out = IPSEC_INTEG_ALG_##f; \
92  return (0);
94 #undef _
95  }
96  return (VNET_API_ERROR_INVALID_ALGORITHM);
97 }
98 
99 vl_api_ipsec_integ_alg_t
100 ipsec_integ_algo_encode (ipsec_integ_alg_t i)
101 {
102  switch (i)
103  {
104 #define _(v,f,s) case IPSEC_INTEG_ALG_##f: \
105  return (clib_host_to_net_u32(IPSEC_API_INTEG_ALG_##f));
107 #undef _
108  case IPSEC_INTEG_N_ALG:
109  break;
110  }
111  ASSERT (0);
112  return (VNET_API_ERROR_UNIMPLEMENTED);
113 }
114 
115 void
116 ipsec_key_decode (const vl_api_key_t * key, ipsec_key_t * out)
117 {
118  ipsec_mk_key (out, key->data, key->length);
119 }
120 
121 void
122 ipsec_key_encode (const ipsec_key_t * in, vl_api_key_t * out)
123 {
124  out->length = in->len;
125  clib_memcpy (out->data, in->data, out->length);
126 }
127 
129 ipsec_sa_flags_decode (vl_api_ipsec_sad_flags_t in)
130 {
131  ipsec_sa_flags_t flags = IPSEC_SA_FLAG_NONE;
132  in = clib_net_to_host_u32 (in);
133 
135  flags |= IPSEC_SA_FLAG_USE_ESN;
137  flags |= IPSEC_SA_FLAG_USE_ANTI_REPLAY;
139  flags |= IPSEC_SA_FLAG_IS_TUNNEL;
141  flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
143  flags |= IPSEC_SA_FLAG_UDP_ENCAP;
145  flags |= IPSEC_SA_FLAG_IS_INBOUND;
146  if (in & IPSEC_API_SAD_FLAG_ASYNC)
147  flags |= IPSEC_SA_FLAG_IS_ASYNC;
148 
149  return (flags);
150 }
151 
152 vl_api_ipsec_sad_flags_t
154 {
155  vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
156 
157  if (ipsec_sa_is_set_USE_ESN (sa))
159  if (ipsec_sa_is_set_USE_ANTI_REPLAY (sa))
161  if (ipsec_sa_is_set_IS_TUNNEL (sa))
163  if (ipsec_sa_is_set_IS_TUNNEL_V6 (sa))
165  if (ipsec_sa_is_set_UDP_ENCAP (sa))
167  if (ipsec_sa_is_set_IS_INBOUND (sa))
169  if (ipsec_sa_is_set_IS_ASYNC (sa))
171 
172  return clib_host_to_net_u32 (flags);
173 }
174 
175 /*
176  * fd.io coding-style-patch-verification: ON
177  *
178  * Local Variables:
179  * eval: (c-set-style "gnu")
180  * End:
181  */
ipsec_integ_algo_decode
int ipsec_integ_algo_decode(vl_api_ipsec_integ_alg_t in, ipsec_integ_alg_t *out)
Definition: ipsec_types_api.c:84
IPSEC_API_SAD_FLAG_ASYNC
@ IPSEC_API_SAD_FLAG_ASYNC
Definition: ipsec_types.api:81
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY
@ IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY
Definition: ipsec_types.api:67
api_types.h
ipsec_key_encode
void ipsec_key_encode(const ipsec_key_t *in, vl_api_key_t *out)
Definition: ipsec_types_api.c:122
ipsec_proto_encode
vl_api_ipsec_proto_t ipsec_proto_encode(ipsec_protocol_t p)
Definition: ipsec_types_api.c:38
IPSEC_PROTOCOL_ESP
@ IPSEC_PROTOCOL_ESP
Definition: ipsec_sa.h:76
key
typedef key
Definition: ipsec_types.api:91
ipsec_key_decode
void ipsec_key_decode(const vl_api_key_t *key, ipsec_key_t *out)
Definition: ipsec_types_api.c:116
ipsec_key_t_::data
u8 data[IPSEC_KEY_MAX_LEN]
Definition: ipsec_sa.h:83
IPSEC_API_SAD_FLAG_IS_INBOUND
@ IPSEC_API_SAD_FLAG_IS_INBOUND
Definition: ipsec_types.api:79
ipsec_sa_flags_t
enum ipsec_sad_flags_t_ ipsec_sa_flags_t
IPSEC_API_SAD_FLAG_USE_ESN
@ IPSEC_API_SAD_FLAG_USE_ESN
Definition: ipsec_types.api:65
foreach_ipsec_integ_alg
#define foreach_ipsec_integ_alg
Definition: ipsec_sa.h:56
IPSEC_API_SAD_FLAG_UDP_ENCAP
@ IPSEC_API_SAD_FLAG_UDP_ENCAP
Definition: ipsec_types.api:77
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
IPSEC_API_SAD_FLAG_NONE
@ IPSEC_API_SAD_FLAG_NONE
Definition: ipsec_types.api:63
IPSEC_API_SAD_FLAG_IS_TUNNEL
@ IPSEC_API_SAD_FLAG_IS_TUNNEL
Definition: ipsec_types.api:69
ipsec_key_t_
Definition: ipsec_sa.h:80
IPSEC_CRYPTO_N_ALG
@ IPSEC_CRYPTO_N_ALG
Definition: ipsec_sa.h:43
ipsec_sa_t
Definition: ipsec_sa.h:116
ipsec_mk_key
void ipsec_mk_key(ipsec_key_t *key, const u8 *data, u8 len)
Definition: ipsec_sa.c:57
ipsec_key_t_::len
u8 len
Definition: ipsec_sa.h:82
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
IPSEC_API_PROTO_AH
@ IPSEC_API_PROTO_AH
Definition: ipsec_types.api:87
ipsec_proto_decode
int ipsec_proto_decode(vl_api_ipsec_proto_t in, ipsec_protocol_t *out)
Encode/decode function from/to API to internal types.
Definition: ipsec_types_api.c:21
IPSEC_PROTOCOL_AH
@ IPSEC_PROTOCOL_AH
Definition: ipsec_sa.h:75
ipsec_sad_flags_encode
vl_api_ipsec_sad_flags_t ipsec_sad_flags_encode(const ipsec_sa_t *sa)
Definition: ipsec_types_api.c:153
ipsec_types_api.h
IPSEC_API_PROTO_ESP
@ IPSEC_API_PROTO_ESP
Definition: ipsec_types.api:86
i
int i
Definition: flowhash_template.h:376
IPSEC_INTEG_N_ALG
@ IPSEC_INTEG_N_ALG
Definition: ipsec_sa.h:70
ipsec_crypto_algo_encode
vl_api_ipsec_crypto_alg_t ipsec_crypto_algo_encode(ipsec_crypto_alg_t c)
Definition: ipsec_types_api.c:68
foreach_ipsec_crypto_alg
#define foreach_ipsec_crypto_alg
Definition: ipsec_sa.h:24
IPSEC_API_SAD_FLAG_IS_TUNNEL_V6
@ IPSEC_API_SAD_FLAG_IS_TUNNEL_V6
Definition: ipsec_types.api:75
ipsec_crypto_algo_decode
int ipsec_crypto_algo_decode(vl_api_ipsec_crypto_alg_t in, ipsec_crypto_alg_t *out)
Definition: ipsec_types_api.c:51
ipsec_integ_algo_encode
vl_api_ipsec_integ_alg_t ipsec_integ_algo_encode(ipsec_integ_alg_t i)
Definition: ipsec_types_api.c:100
ipsec_sa_flags_decode
ipsec_sa_flags_t ipsec_sa_flags_decode(vl_api_ipsec_sad_flags_t in)
Definition: ipsec_types_api.c:129
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105