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 <vnet/ip/ip_types_api.h>
18 #define vl_typedefs /* define message structures */
19 #include <vnet/vnet_all_api_h.h>
22 #define vl_endianfun /* define message structures */
23 #include <vnet/vnet_all_api_h.h>
26 /* instantiate all the print functions we know about */
27 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
29 #include <vnet/vnet_all_api_h.h>
33 ip_address_union_decode (const vl_api_address_union_t * in,
34 vl_api_address_family_t af, ip46_address_t * out)
38 switch (clib_net_to_host_u32 (af))
41 memset (out, 0, sizeof (*out));
42 clib_memcpy (&out->ip4, &in->ip4, sizeof (out->ip4));
46 clib_memcpy (&out->ip6, &in->ip6, sizeof (out->ip6));
50 ASSERT (!"Unkown address family in API address type");
59 ip_address_decode (const vl_api_address_t * in, ip46_address_t * out)
61 return (ip_address_union_decode (&in->un, in->af, out));
65 ip_address_union_encode (const ip46_address_t * in,
66 vl_api_address_family_t af,
67 vl_api_address_union_t * out)
69 if (ADDRESS_IP6 == clib_net_to_host_u32 (af))
70 memcpy (out->ip6.address, &in->ip6, sizeof (out->ip6));
72 memcpy (out->ip4.address, &in->ip4, sizeof (out->ip4));
76 ip_address_encode (const ip46_address_t * in,
77 ip46_type_t type, vl_api_address_t * out)
82 out->af = clib_net_to_host_u32 (ADDRESS_IP4);
85 out->af = clib_net_to_host_u32 (ADDRESS_IP6);
88 if (ip46_address_is_ip4 (in))
89 out->af = clib_net_to_host_u32 (ADDRESS_IP4);
91 out->af = clib_net_to_host_u32 (ADDRESS_IP6);
94 ip_address_union_encode (in, out->af, &out->un);
98 ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out)
100 switch (clib_net_to_host_u32 (in->address.af))
103 out->fp_proto = FIB_PROTOCOL_IP4;
106 out->fp_proto = FIB_PROTOCOL_IP6;
109 out->fp_len = in->address_length;
110 ip_address_decode (&in->address, &out->fp_addr);
114 ip_prefix_encode (const fib_prefix_t * in, vl_api_prefix_t * out)
116 out->address_length = in->fp_len;
117 ip_address_encode (&in->fp_addr,
118 fib_proto_to_ip46 (in->fp_proto), &out->address);
122 ip_mprefix_encode (const mfib_prefix_t * in, vl_api_mprefix_t * out)
124 out->af = (FIB_PROTOCOL_IP6 == in->fp_proto ? ADDRESS_IP6 : ADDRESS_IP4);
125 out->af = clib_host_to_net_u32 (out->af);
126 out->grp_address_length = clib_host_to_net_u16 (in->fp_len);
128 ip_address_union_encode (&in->fp_grp_addr, out->af, &out->grp_address);
129 ip_address_union_encode (&in->fp_src_addr, out->af, &out->src_address);
133 ip_mprefix_decode (const vl_api_mprefix_t * in, mfib_prefix_t * out)
135 out->fp_proto = (ADDRESS_IP6 == clib_net_to_host_u32 (in->af) ?
136 FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
137 out->fp_len = clib_net_to_host_u16 (in->grp_address_length);
139 ip_address_union_decode (&in->grp_address, in->af, &out->fp_grp_addr);
140 ip_address_union_decode (&in->src_address, in->af, &out->fp_src_addr);
144 format_vl_api_address (u8 * s, va_list * args)
146 const vl_api_address_t *addr = va_arg (*args, vl_api_address_t *);
148 if (ADDRESS_IP6 == clib_net_to_host_u32 (addr->af))
149 s = format (s, "ip6:%U", format_ip6_address, addr->un.ip6.address);
151 s = format (s, "ip4:%U", format_ip4_address, addr->un.ip4.address);
157 format_vl_api_address_union (u8 * s, va_list * args)
159 const vl_api_address_union_t *addr =
160 va_arg (*args, vl_api_address_union_t *);
161 vl_api_address_family_t af = va_arg (*args, vl_api_address_family_t);
163 if (ADDRESS_IP6 == af)
164 s = format (s, "ip6:%U", format_ip6_address, addr->ip6.address);
166 s = format (s, "ip4:%U", format_ip4_address, addr->ip4.address);
172 format_vl_api_prefix (u8 * s, va_list * args)
174 const vl_api_prefix_t *pfx = va_arg (*args, vl_api_prefix_t *);
176 s = format (s, "%U/%d", format_vl_api_address,
177 &pfx->address, pfx->address_length);
183 * fd.io coding-style-patch-verification: ON
186 * eval: (c-set-style "gnu")