X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fip%2Fip_types_api.c;h=2e92e72377292483d8d0ece2f5614340db0599b3;hb=282872127;hp=f173c28c83b01b6a59bdb860824f492f107b6a97;hpb=d0df49f26eabf2f534b567f3370e50c4e804aeea;p=vpp.git diff --git a/src/vnet/ip/ip_types_api.c b/src/vnet/ip/ip_types_api.c index f173c28c83b..2e92e723772 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,107 @@ #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)); +} + +ip_dscp_t +ip_dscp_decode (u8 in) +{ + return ((ip_dscp_t) in); +} + +u8 +ip_dscp_encode (ip_dscp_t dscp) +{ + return (dscp); +} + +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) @@ -38,7 +140,7 @@ ip_address_union_decode (const vl_api_address_union_t * in, switch (clib_net_to_host_u32 (af)) { case ADDRESS_IP4: - memset (out, 0, sizeof (*out)); + clib_memset (out, 0, sizeof (*out)); clib_memcpy (&out->ip4, &in->ip4, sizeof (out->ip4)); type = IP46_TYPE_IP4; break; @@ -47,7 +149,7 @@ ip_address_union_decode (const vl_api_address_union_t * in, type = IP46_TYPE_IP6; break; default: - ASSERT (!"Unkown address family in API address type"); + ASSERT (!"Unknown address family in API address type"); type = IP46_TYPE_ANY; break; } @@ -61,15 +163,35 @@ ip_address_decode (const vl_api_address_t * in, ip46_address_t * out) return (ip_address_union_decode (&in->un, in->af, out)); } +void +ip_address_decode2 (const vl_api_address_t * in, ip_address_t * out) +{ + switch (clib_net_to_host_u32 (in->af)) + { + case ADDRESS_IP4: + clib_memset (out, 0, sizeof (*out)); + clib_memcpy (&ip_addr_v4 (out), &in->un.ip4, sizeof (ip_addr_v4 (out))); + out->version = AF_IP4; + break; + case ADDRESS_IP6: + clib_memcpy (&ip_addr_v6 (out), &in->un.ip6, sizeof (ip_addr_v6 (out))); + out->version = AF_IP6; + break; + default: + ASSERT (!"Unknown address family in API address type"); + break; + } +} + static void ip_address_union_encode (const ip46_address_t * in, vl_api_address_family_t af, 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 @@ -94,6 +216,22 @@ ip_address_encode (const ip46_address_t * in, ip_address_union_encode (in, out->af, &out->un); } +void +ip_address_encode2 (const ip_address_t * in, vl_api_address_t * out) +{ + switch (in->version) + { + case AF_IP4: + out->af = clib_net_to_host_u32 (ADDRESS_IP4); + ip4_address_encode (&in->ip.v4, out->un.ip4); + break; + case AF_IP6: + out->af = clib_net_to_host_u32 (ADDRESS_IP6); + ip6_address_encode (&in->ip.v6, out->un.ip6); + break; + } +} + void ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out) { @@ -106,14 +244,15 @@ ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out) out->fp_proto = FIB_PROTOCOL_IP6; break; } - out->fp_len = in->address_length; + out->fp_len = in->len; + out->___fp___pad = 0; ip_address_decode (&in->address, &out->fp_addr); } void ip_prefix_encode (const fib_prefix_t * in, vl_api_prefix_t * out) { - out->address_length = in->fp_len; + out->len = in->fp_len; ip_address_encode (&in->fp_addr, fib_proto_to_ip46 (in->fp_proto), &out->address); } @@ -135,48 +274,13 @@ ip_mprefix_decode (const vl_api_mprefix_t * in, mfib_prefix_t * out) out->fp_proto = (ADDRESS_IP6 == clib_net_to_host_u32 (in->af) ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); out->fp_len = clib_net_to_host_u16 (in->grp_address_length); + out->___fp___pad = 0; 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); -} - -u8 * -format_vl_api_address (u8 * s, va_list * args) -{ - const vl_api_address_t *addr = va_arg (*args, vl_api_address_t *); - - if (ADDRESS_IP6 == clib_net_to_host_u32 (addr->af)) - s = format (s, "ip6:%U", format_ip6_address, addr->un.ip6.address); - else - s = format (s, "ip4:%U", format_ip4_address, addr->un.ip4.address); - - return s; -} - -u8 * -format_vl_api_address_union (u8 * s, va_list * args) -{ - const vl_api_address_union_t *addr = - va_arg (*args, vl_api_address_union_t *); - vl_api_address_family_t af = va_arg (*args, vl_api_address_family_t); - - if (ADDRESS_IP6 == af) - s = format (s, "ip6:%U", format_ip6_address, addr->ip6.address); - else - s = format (s, "ip4:%U", format_ip4_address, addr->ip4.address); - - return s; -} - -u8 * -format_vl_api_prefix (u8 * s, va_list * args) -{ - const vl_api_prefix_t *pfx = va_arg (*args, vl_api_prefix_t *); - - s = format (s, "%U/%d", format_vl_api_address, - &pfx->address, pfx->address_length); - return s; + if (!ip46_address_is_zero (&out->fp_src_addr)) + out->fp_len = (out->fp_proto == FIB_PROTOCOL_IP6 ? 256 : 64); } /*