2 * Copyright (c) 2018 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.
16 #include <vlibapi/api_types.h>
17 #include <vnet/ip/ip_types_api.h>
19 #define vl_typedefs /* define message structures */
20 #include <vnet/vnet_all_api_h.h>
23 #define vl_endianfun /* define message structures */
24 #include <vnet/vnet_all_api_h.h>
27 /* instantiate all the print functions we know about */
28 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
30 #include <vnet/vnet_all_api_h.h>
34 ip_address_family_decode (int _af, ip_address_family_t * out)
36 vl_api_address_family_t af = clib_host_to_net_u32 (_af);
51 ip_address_family_encode (ip_address_family_t af)
56 return (clib_host_to_net_u32 (ADDRESS_IP4));
58 return (clib_host_to_net_u32 (ADDRESS_IP6));
62 return (clib_host_to_net_u32 (ADDRESS_IP4));
66 ip_proto_decode (int _ipp, ip_protocol_t * out)
68 ip_protocol_t ipp = clib_host_to_net_u32 (_ipp);
72 #define ip_protocol(n,s) \
73 case IP_PROTOCOL_##s: \
74 *out = IP_PROTOCOL_##s; \
76 #include "protocols.def"
83 ip_proto_encode (ip_protocol_t ipp)
87 #define ip_protocol(n,s) \
88 case IP_PROTOCOL_##s: \
89 return (clib_host_to_net_u32 (IP_PROTOCOL_##s));
90 #include "protocols.def"
95 return (clib_host_to_net_u32 (IP_API_PROTO_TCP));
99 ip_dscp_decode (u8 in)
101 return ((ip_dscp_t) in);
105 ip_dscp_encode (ip_dscp_t dscp)
111 ip6_address_encode (const ip6_address_t * in, vl_api_ip6_address_t out)
113 clib_memcpy (out, in, sizeof (*in));
117 ip6_address_decode (const vl_api_ip6_address_t in, ip6_address_t * out)
119 clib_memcpy (out, in, sizeof (*out));
123 ip4_address_encode (const ip4_address_t * in, vl_api_ip4_address_t out)
125 clib_memcpy (out, in, sizeof (*in));
129 ip4_address_decode (const vl_api_ip4_address_t in, ip4_address_t * out)
131 clib_memcpy (out, in, sizeof (*out));
135 ip_address_union_decode (const vl_api_address_union_t * in,
136 vl_api_address_family_t af, ip46_address_t * out)
140 switch (clib_net_to_host_u32 (af))
143 clib_memset (out, 0, sizeof (*out));
144 clib_memcpy (&out->ip4, &in->ip4, sizeof (out->ip4));
145 type = IP46_TYPE_IP4;
148 clib_memcpy (&out->ip6, &in->ip6, sizeof (out->ip6));
149 type = IP46_TYPE_IP6;
152 ASSERT (!"Unknown address family in API address type");
153 type = IP46_TYPE_ANY;
161 ip_address_decode (const vl_api_address_t * in, ip46_address_t * out)
163 return (ip_address_union_decode (&in->un, in->af, out));
167 ip_address_decode2 (const vl_api_address_t * in, ip_address_t * out)
169 switch (clib_net_to_host_u32 (in->af))
172 clib_memset (out, 0, sizeof (*out));
173 clib_memcpy (&ip_addr_v4 (out), &in->un.ip4, sizeof (ip_addr_v4 (out)));
174 out->version = AF_IP4;
177 clib_memcpy (&ip_addr_v6 (out), &in->un.ip6, sizeof (ip_addr_v6 (out)));
178 out->version = AF_IP6;
181 ASSERT (!"Unknown address family in API address type");
187 ip_address_union_encode (const ip46_address_t * in,
188 vl_api_address_family_t af,
189 vl_api_address_union_t * out)
191 if (ADDRESS_IP6 == clib_net_to_host_u32 (af))
192 ip6_address_encode (&in->ip6, out->ip6);
194 ip4_address_encode (&in->ip4, out->ip4);
198 ip_address_encode (const ip46_address_t * in,
199 ip46_type_t type, vl_api_address_t * out)
204 out->af = clib_net_to_host_u32 (ADDRESS_IP4);
207 out->af = clib_net_to_host_u32 (ADDRESS_IP6);
210 if (ip46_address_is_ip4 (in))
211 out->af = clib_net_to_host_u32 (ADDRESS_IP4);
213 out->af = clib_net_to_host_u32 (ADDRESS_IP6);
216 ip_address_union_encode (in, out->af, &out->un);
220 ip_address_encode2 (const ip_address_t * in, vl_api_address_t * out)
225 out->af = clib_net_to_host_u32 (ADDRESS_IP4);
226 ip4_address_encode (&in->ip.v4, out->un.ip4);
229 out->af = clib_net_to_host_u32 (ADDRESS_IP6);
230 ip6_address_encode (&in->ip.v6, out->un.ip6);
236 ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out)
238 switch (clib_net_to_host_u32 (in->address.af))
241 out->fp_proto = FIB_PROTOCOL_IP4;
244 out->fp_proto = FIB_PROTOCOL_IP6;
247 out->fp_len = in->len;
248 out->___fp___pad = 0;
249 ip_address_decode (&in->address, &out->fp_addr);
253 ip_prefix_encode (const fib_prefix_t * in, vl_api_prefix_t * out)
255 out->len = in->fp_len;
256 ip46_type_t ip46_type;
258 switch (in->fp_proto)
260 case FIB_PROTOCOL_IP4:
261 ip46_type = (IP46_TYPE_IP4);
263 case FIB_PROTOCOL_IP6:
264 ip46_type = (IP46_TYPE_IP6);
266 case FIB_PROTOCOL_MPLS:
267 ip46_type = (IP46_TYPE_ANY);
270 ip46_type = (IP46_TYPE_ANY);
273 ip_address_encode (&in->fp_addr, ip46_type, &out->address);
277 ip_mprefix_encode (const mfib_prefix_t * in, vl_api_mprefix_t * out)
279 out->af = (FIB_PROTOCOL_IP6 == in->fp_proto ? ADDRESS_IP6 : ADDRESS_IP4);
280 out->af = clib_host_to_net_u32 (out->af);
281 out->grp_address_length = clib_host_to_net_u16 (in->fp_len);
283 ip_address_union_encode (&in->fp_grp_addr, out->af, &out->grp_address);
284 ip_address_union_encode (&in->fp_src_addr, out->af, &out->src_address);
288 ip_mprefix_decode (const vl_api_mprefix_t * in, mfib_prefix_t * out)
290 out->fp_proto = (ADDRESS_IP6 == clib_net_to_host_u32 (in->af) ?
291 FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
292 out->fp_len = clib_net_to_host_u16 (in->grp_address_length);
293 out->___fp___pad = 0;
295 ip_address_union_decode (&in->grp_address, in->af, &out->fp_grp_addr);
296 ip_address_union_decode (&in->src_address, in->af, &out->fp_src_addr);
298 if (!ip46_address_is_zero (&out->fp_src_addr))
299 out->fp_len = (out->fp_proto == FIB_PROTOCOL_IP6 ? 256 : 64);
303 * fd.io coding-style-patch-verification: ON
306 * eval: (c-set-style "gnu")