X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fip%2Fip_types_api.c;h=bcf594c70b29a407c2cf2cceffeafb86aea94dd9;hb=3ec09e9243dceb78e7548725281b0da8eddf72b1;hp=e9be1c613b629555a3ec49b1e952475eae45e7e4;hpb=5b755e2f9fce239b5280ac1e5e21f835464fa017;p=vpp.git diff --git a/src/vnet/ip/ip_types_api.c b/src/vnet/ip/ip_types_api.c index e9be1c613b6..bcf594c70b2 100644 --- a/src/vnet/ip/ip_types_api.c +++ b/src/vnet/ip/ip_types_api.c @@ -163,6 +163,22 @@ 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 (ip_address_union_decode (&in->un, in->af, &out->ip)) + { + case IP46_TYPE_IP4: + out->version = AF_IP4; + break; + case IP46_TYPE_IP6: + out->version = AF_IP6; + break; + default: + break; + } +} + static void ip_address_union_encode (const ip46_address_t * in, vl_api_address_family_t af, @@ -196,6 +212,21 @@ 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); + break; + case AF_IP6: + out->af = clib_net_to_host_u32 (ADDRESS_IP6); + break; + } + ip_address_union_encode (&in->ip, out->af, &out->un); +} + void ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out) { @@ -213,12 +244,46 @@ ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out) ip_address_decode (&in->address, &out->fp_addr); } +int +ip_prefix_decode2 (const vl_api_prefix_t * in, ip_prefix_t * out) +{ + out->len = in->len; + ip_address_decode2 (&in->address, &out->addr); + + if (!ip_prefix_validate (out)) + return (VNET_API_ERROR_IP_PREFIX_INVALID); + return (0); +} + void ip_prefix_encode (const fib_prefix_t * in, vl_api_prefix_t * out) { out->len = in->fp_len; - ip_address_encode (&in->fp_addr, - fib_proto_to_ip46 (in->fp_proto), &out->address); + ip46_type_t ip46_type; + + switch (in->fp_proto) + { + case FIB_PROTOCOL_IP4: + ip46_type = (IP46_TYPE_IP4); + break; + case FIB_PROTOCOL_IP6: + ip46_type = (IP46_TYPE_IP6); + break; + case FIB_PROTOCOL_MPLS: + ip46_type = (IP46_TYPE_ANY); + break; + default: + ip46_type = (IP46_TYPE_ANY); + } + + ip_address_encode (&in->fp_addr, ip46_type, &out->address); +} + +void +ip_prefix_encode2 (const ip_prefix_t * in, vl_api_prefix_t * out) +{ + out->len = in->len; + ip_address_encode2 (&in->addr, &out->address); } void @@ -238,6 +303,7 @@ 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);