FD.io VPP  v20.05.1-6-gf53edbc3b
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 #define vl_typedefs /* define message structures */
21 #include <vnet/vnet_all_api_h.h>
22 #undef vl_typedefs
23 
24 int
25 ipsec_proto_decode (vl_api_ipsec_proto_t in, ipsec_protocol_t * out)
26 {
27  in = clib_net_to_host_u32 (in);
28 
29  switch (in)
30  {
32  *out = IPSEC_PROTOCOL_ESP;
33  return (0);
34  case IPSEC_API_PROTO_AH:
35  *out = IPSEC_PROTOCOL_AH;
36  return (0);
37  }
38  return (VNET_API_ERROR_INVALID_PROTOCOL);
39 }
40 
41 vl_api_ipsec_proto_t
43 {
44  switch (p)
45  {
46  case IPSEC_PROTOCOL_ESP:
47  return clib_host_to_net_u32 (IPSEC_API_PROTO_ESP);
48  case IPSEC_PROTOCOL_AH:
49  return clib_host_to_net_u32 (IPSEC_API_PROTO_AH);
50  }
51  return (VNET_API_ERROR_UNIMPLEMENTED);
52 }
53 
54 int
55 ipsec_crypto_algo_decode (vl_api_ipsec_crypto_alg_t in,
56  ipsec_crypto_alg_t * out)
57 {
58  in = clib_net_to_host_u32 (in);
59 
60  switch (in)
61  {
62 #define _(v,f,s) case IPSEC_API_CRYPTO_ALG_##f: \
63  *out = IPSEC_CRYPTO_ALG_##f; \
64  return (0);
66 #undef _
67  }
68  return (VNET_API_ERROR_INVALID_ALGORITHM);
69 }
70 
71 vl_api_ipsec_crypto_alg_t
73 {
74  switch (c)
75  {
76 #define _(v,f,s) case IPSEC_CRYPTO_ALG_##f: \
77  return clib_host_to_net_u32(IPSEC_API_CRYPTO_ALG_##f);
79 #undef _
80  case IPSEC_CRYPTO_N_ALG:
81  break;
82  }
83  ASSERT (0);
84  return (VNET_API_ERROR_UNIMPLEMENTED);
85 }
86 
87 int
88 ipsec_integ_algo_decode (vl_api_ipsec_integ_alg_t in, ipsec_integ_alg_t * out)
89 {
90  in = clib_net_to_host_u32 (in);
91 
92  switch (in)
93  {
94 #define _(v,f,s) case IPSEC_API_INTEG_ALG_##f: \
95  *out = IPSEC_INTEG_ALG_##f; \
96  return (0);
98 #undef _
99  }
100  return (VNET_API_ERROR_INVALID_ALGORITHM);
101 }
102 
103 vl_api_ipsec_integ_alg_t
105 {
106  switch (i)
107  {
108 #define _(v,f,s) case IPSEC_INTEG_ALG_##f: \
109  return (clib_host_to_net_u32(IPSEC_API_INTEG_ALG_##f));
111 #undef _
112  case IPSEC_INTEG_N_ALG:
113  break;
114  }
115  ASSERT (0);
116  return (VNET_API_ERROR_UNIMPLEMENTED);
117 }
118 
119 void
120 ipsec_key_decode (const vl_api_key_t * key, ipsec_key_t * out)
121 {
122  ipsec_mk_key (out, key->data, key->length);
123 }
124 
125 void
126 ipsec_key_encode (const ipsec_key_t * in, vl_api_key_t * out)
127 {
128  out->length = in->len;
129  clib_memcpy (out->data, in->data, out->length);
130 }
131 
133 ipsec_sa_flags_decode (vl_api_ipsec_sad_flags_t in)
134 {
135  ipsec_sa_flags_t flags = IPSEC_SA_FLAG_NONE;
136  in = clib_net_to_host_u32 (in);
137 
139  flags |= IPSEC_SA_FLAG_USE_ESN;
141  flags |= IPSEC_SA_FLAG_USE_ANTI_REPLAY;
143  flags |= IPSEC_SA_FLAG_IS_TUNNEL;
145  flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
147  flags |= IPSEC_SA_FLAG_UDP_ENCAP;
149  flags |= IPSEC_SA_FLAG_IS_INBOUND;
150 
151  return (flags);
152 }
153 
154 vl_api_ipsec_sad_flags_t
156 {
157  vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
158 
159  if (ipsec_sa_is_set_USE_ESN (sa))
161  if (ipsec_sa_is_set_USE_ANTI_REPLAY (sa))
163  if (ipsec_sa_is_set_IS_TUNNEL (sa))
165  if (ipsec_sa_is_set_IS_TUNNEL_V6 (sa))
167  if (ipsec_sa_is_set_UDP_ENCAP (sa))
169  if (ipsec_sa_is_set_IS_INBOUND (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  */
void ipsec_key_decode(const vl_api_key_t *key, ipsec_key_t *out)
ipsec_integ_alg_t
Definition: ipsec_sa.h:59
#define foreach_ipsec_crypto_alg
Definition: ipsec_sa.h:23
ipsec_protocol_t
Definition: ipsec_sa.h:67
int ipsec_integ_algo_decode(vl_api_ipsec_integ_alg_t in, ipsec_integ_alg_t *out)
#define foreach_ipsec_integ_alg
Definition: ipsec_sa.h:50
void ipsec_mk_key(ipsec_key_t *key, const u8 *data, u8 len)
Definition: ipsec_sa.c:56
#define clib_memcpy(d, s, n)
Definition: string.h:180
vl_api_ipsec_crypto_alg_t ipsec_crypto_algo_encode(ipsec_crypto_alg_t c)
vl_api_ipsec_proto_t ipsec_proto_encode(ipsec_protocol_t p)
u32 flags
Definition: vhost_user.h:248
svmdb_client_t * c
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
vl_api_ipsec_sad_flags_t ipsec_sad_flags_encode(const ipsec_sa_t *sa)
enum ipsec_sad_flags_t_ ipsec_sa_flags_t
u8 data[IPSEC_KEY_MAX_LEN]
Definition: ipsec_sa.h:77
#define ASSERT(truth)
vl_api_ipsec_integ_alg_t ipsec_integ_algo_encode(ipsec_integ_alg_t i)
ipsec_sa_flags_t ipsec_sa_flags_decode(vl_api_ipsec_sad_flags_t in)
typedef key
Definition: ipsec_types.api:85
ipsec_crypto_alg_t
Definition: ipsec_sa.h:37
int ipsec_crypto_algo_decode(vl_api_ipsec_crypto_alg_t in, ipsec_crypto_alg_t *out)
int ipsec_proto_decode(vl_api_ipsec_proto_t in, ipsec_protocol_t *out)
Encode/decode function from/to API to internal types.
void ipsec_key_encode(const ipsec_key_t *in, vl_api_key_t *out)