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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <vnet/ipsec/ipsec_types_api.h>
18 #include <vlibapi/api_types.h>
21 ipsec_proto_decode (vl_api_ipsec_proto_t in, ipsec_protocol_t * out)
23 in = clib_net_to_host_u32 (in);
27 case IPSEC_API_PROTO_ESP:
28 *out = IPSEC_PROTOCOL_ESP;
30 case IPSEC_API_PROTO_AH:
31 *out = IPSEC_PROTOCOL_AH;
34 return (VNET_API_ERROR_INVALID_PROTOCOL);
38 ipsec_proto_encode (ipsec_protocol_t p)
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);
47 return (VNET_API_ERROR_UNIMPLEMENTED);
51 ipsec_crypto_algo_decode (vl_api_ipsec_crypto_alg_t in,
52 ipsec_crypto_alg_t * out)
54 in = clib_net_to_host_u32 (in);
58 #define _(v,f,s) case IPSEC_API_CRYPTO_ALG_##f: \
59 *out = IPSEC_CRYPTO_ALG_##f; \
61 foreach_ipsec_crypto_alg
64 return (VNET_API_ERROR_INVALID_ALGORITHM);
67 vl_api_ipsec_crypto_alg_t
68 ipsec_crypto_algo_encode (ipsec_crypto_alg_t c)
72 #define _(v,f,s) case IPSEC_CRYPTO_ALG_##f: \
73 return clib_host_to_net_u32(IPSEC_API_CRYPTO_ALG_##f);
74 foreach_ipsec_crypto_alg
76 case IPSEC_CRYPTO_N_ALG:
80 return (VNET_API_ERROR_UNIMPLEMENTED);
84 ipsec_integ_algo_decode (vl_api_ipsec_integ_alg_t in, ipsec_integ_alg_t * out)
86 in = clib_net_to_host_u32 (in);
90 #define _(v,f,s) case IPSEC_API_INTEG_ALG_##f: \
91 *out = IPSEC_INTEG_ALG_##f; \
93 foreach_ipsec_integ_alg
96 return (VNET_API_ERROR_INVALID_ALGORITHM);
99 vl_api_ipsec_integ_alg_t
100 ipsec_integ_algo_encode (ipsec_integ_alg_t i)
104 #define _(v,f,s) case IPSEC_INTEG_ALG_##f: \
105 return (clib_host_to_net_u32(IPSEC_API_INTEG_ALG_##f));
106 foreach_ipsec_integ_alg
108 case IPSEC_INTEG_N_ALG:
112 return (VNET_API_ERROR_UNIMPLEMENTED);
116 ipsec_key_decode (const vl_api_key_t * key, ipsec_key_t * out)
118 ipsec_mk_key (out, key->data, key->length);
122 ipsec_key_encode (const ipsec_key_t * in, vl_api_key_t * out)
124 out->length = in->len;
125 clib_memcpy (out->data, in->data, out->length);
129 ipsec_sa_flags_decode (vl_api_ipsec_sad_flags_t in)
131 ipsec_sa_flags_t flags = IPSEC_SA_FLAG_NONE;
132 in = clib_net_to_host_u32 (in);
134 if (in & IPSEC_API_SAD_FLAG_USE_ESN)
135 flags |= IPSEC_SA_FLAG_USE_ESN;
136 if (in & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY)
137 flags |= IPSEC_SA_FLAG_USE_ANTI_REPLAY;
138 if (in & IPSEC_API_SAD_FLAG_IS_TUNNEL)
139 flags |= IPSEC_SA_FLAG_IS_TUNNEL;
140 if (in & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6)
141 flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
142 if (in & IPSEC_API_SAD_FLAG_UDP_ENCAP)
143 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
144 if (in & IPSEC_API_SAD_FLAG_IS_INBOUND)
145 flags |= IPSEC_SA_FLAG_IS_INBOUND;
146 if (in & IPSEC_API_SAD_FLAG_ASYNC)
147 flags |= IPSEC_SA_FLAG_IS_ASYNC;
152 vl_api_ipsec_sad_flags_t
153 ipsec_sad_flags_encode (const ipsec_sa_t * sa)
155 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
157 if (ipsec_sa_is_set_USE_ESN (sa))
158 flags |= IPSEC_API_SAD_FLAG_USE_ESN;
159 if (ipsec_sa_is_set_USE_ANTI_REPLAY (sa))
160 flags |= IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY;
161 if (ipsec_sa_is_set_IS_TUNNEL (sa))
162 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
163 if (ipsec_sa_is_set_IS_TUNNEL_V6 (sa))
164 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
165 if (ipsec_sa_is_set_UDP_ENCAP (sa))
166 flags |= IPSEC_API_SAD_FLAG_UDP_ENCAP;
167 if (ipsec_sa_is_set_IS_INBOUND (sa))
168 flags |= IPSEC_API_SAD_FLAG_IS_INBOUND;
169 if (ipsec_sa_is_set_IS_ASYNC (sa))
170 flags |= IPSEC_API_SAD_FLAG_ASYNC;
172 return clib_host_to_net_u32 (flags);
176 * fd.io coding-style-patch-verification: ON
179 * eval: (c-set-style "gnu")