X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fip%2Fip_types_api.c;h=6ad2c366dff4a7461eab1e8530419766ce526517;hb=097fa66b986f06281f603767d321ab13ab6c88c3;hp=11b52760fad92ab27fa0d5c0c9d837bb01a9b93e;hpb=86327be9751ad54cb24d16c161cacb001dc20772;p=vpp.git diff --git a/src/vnet/ip/ip_types_api.c b/src/vnet/ip/ip_types_api.c index 11b52760fad..6ad2c366dff 100644 --- a/src/vnet/ip/ip_types_api.c +++ b/src/vnet/ip/ip_types_api.c @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #define vl_typedefs /* define message structures */ @@ -29,6 +30,95 @@ #include #undef vl_printfun +int +ip_address_family_decode (int _af, ip_address_family_t * out) +{ + vl_api_address_family_t af = clib_host_to_net_u32 (_af); + + switch (af) + { + case ADDRESS_IP4: + *out = AF_IP4; + return (0); + case ADDRESS_IP6: + *out = AF_IP6; + return (0); + } + return (-1); +} + +int +ip_address_family_encode (ip_address_family_t af) +{ + switch (af) + { + case AF_IP4: + return (clib_host_to_net_u32 (ADDRESS_IP4)); + case AF_IP6: + return (clib_host_to_net_u32 (ADDRESS_IP6)); + } + + ASSERT (0); + return (clib_host_to_net_u32 (ADDRESS_IP4)); +} + +int +ip_proto_decode (int _ipp, ip_protocol_t * out) +{ + ip_protocol_t ipp = clib_host_to_net_u32 (_ipp); + + switch (ipp) + { +#define ip_protocol(n,s) \ + case IP_PROTOCOL_##s: \ + *out = IP_PROTOCOL_##s; \ + return (0); +#include "protocols.def" +#undef ip_protocol + } + return (-1); +} + +int +ip_proto_encode (ip_protocol_t ipp) +{ + switch (ipp) + { +#define ip_protocol(n,s) \ + case IP_PROTOCOL_##s: \ + return (clib_host_to_net_u32 (IP_PROTOCOL_##s)); +#include "protocols.def" +#undef ip_protocol + } + + ASSERT (0); + return (clib_host_to_net_u32 (IP_API_PROTO_TCP)); +} + +void +ip6_address_encode (const ip6_address_t * in, vl_api_ip6_address_t out) +{ + clib_memcpy (out, in, sizeof (*in)); +} + +void +ip6_address_decode (const vl_api_ip6_address_t in, ip6_address_t * out) +{ + clib_memcpy (out, in, sizeof (*out)); +} + +void +ip4_address_encode (const ip4_address_t * in, vl_api_ip4_address_t out) +{ + clib_memcpy (out, in, sizeof (*in)); +} + +void +ip4_address_decode (const vl_api_ip4_address_t in, ip4_address_t * out) +{ + clib_memcpy (out, in, sizeof (*out)); +} + static ip46_type_t ip_address_union_decode (const vl_api_address_union_t * in, vl_api_address_family_t af, ip46_address_t * out) @@ -67,9 +157,9 @@ ip_address_union_encode (const ip46_address_t * in, vl_api_address_union_t * out) { if (ADDRESS_IP6 == clib_net_to_host_u32 (af)) - memcpy (out->ip6.address, &in->ip6, sizeof (out->ip6)); + ip6_address_encode (&in->ip6, out->ip6); else - memcpy (out->ip4.address, &in->ip4, sizeof (out->ip4)); + ip4_address_encode (&in->ip4, out->ip4); } void @@ -107,6 +197,7 @@ ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out) break; } out->fp_len = in->address_length; + out->___fp___pad = 0; ip_address_decode (&in->address, &out->fp_addr); } @@ -138,6 +229,9 @@ ip_mprefix_decode (const vl_api_mprefix_t * in, mfib_prefix_t * out) ip_address_union_decode (&in->grp_address, in->af, &out->fp_grp_addr); ip_address_union_decode (&in->src_address, in->af, &out->fp_src_addr); + + if (!ip46_address_is_zero (&out->fp_src_addr)) + out->fp_len = (out->fp_proto == FIB_PROTOCOL_IP6 ? 256 : 64); } /*