aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/ip
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2018-08-08 01:06:40 -0700
committerOle Trøan <otroan@employees.org>2018-08-10 08:26:00 +0000
commitd0df49f26eabf2f534b567f3370e50c4e804aeea (patch)
treeeea014e723f00b4e00e57937fc5f6e043e2162f9 /src/vnet/ip
parent404d88edce63a635b58ba54d21d91735ff933584 (diff)
Use IP address types on UDP encap API
Change-Id: I3c714c519b6d0009329b50947ce250c18ee2a85a Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/ip')
-rw-r--r--src/vnet/ip/format.h6
-rw-r--r--src/vnet/ip/ip6_packet.h7
-rw-r--r--src/vnet/ip/ip_types.api7
-rw-r--r--src/vnet/ip/ip_types_api.c143
-rw-r--r--src/vnet/ip/ip_types_api.h18
5 files changed, 142 insertions, 39 deletions
diff --git a/src/vnet/ip/format.h b/src/vnet/ip/format.h
index 9ebcf084be3..4d63ba43653 100644
--- a/src/vnet/ip/format.h
+++ b/src/vnet/ip/format.h
@@ -60,12 +60,6 @@ format_function_t format_ip_adjacency_packet_data;
format_function_t format_ip46_address;
-typedef enum
-{
- IP46_TYPE_ANY,
- IP46_TYPE_IP4,
- IP46_TYPE_IP6
-} ip46_type_t;
/* unformat_ip46_address expects arguments (ip46_address_t *, ip46_type_t)
* The type argument is used to enforce a particular IP version. */
unformat_function_t unformat_ip46_address;
diff --git a/src/vnet/ip/ip6_packet.h b/src/vnet/ip/ip6_packet.h
index b8f8d6e8657..ceaa7ec7acc 100644
--- a/src/vnet/ip/ip6_packet.h
+++ b/src/vnet/ip/ip6_packet.h
@@ -67,6 +67,13 @@ typedef CLIB_PACKED (struct {
}) ip6_address_fib_t;
/* *INDENT-ON* */
+typedef enum
+{
+ IP46_TYPE_ANY,
+ IP46_TYPE_IP4,
+ IP46_TYPE_IP6
+} ip46_type_t;
+
/* *INDENT-OFF* */
typedef CLIB_PACKED (union {
struct {
diff --git a/src/vnet/ip/ip_types.api b/src/vnet/ip/ip_types.api
index 72eadaf92df..e418ed3a1c6 100644
--- a/src/vnet/ip/ip_types.api
+++ b/src/vnet/ip/ip_types.api
@@ -41,3 +41,10 @@ typedef prefix {
vl_api_address_t address;
u8 address_length;
};
+
+typedef mprefix {
+ vl_api_address_family_t af;
+ u16 grp_address_length;
+ vl_api_address_union_t grp_address;
+ vl_api_address_union_t src_address;
+};
diff --git a/src/vnet/ip/ip_types_api.c b/src/vnet/ip/ip_types_api.c
index 7fa8e404c78..f173c28c83b 100644
--- a/src/vnet/ip/ip_types_api.c
+++ b/src/vnet/ip/ip_types_api.c
@@ -29,42 +29,75 @@
#include <vnet/vnet_all_api_h.h>
#undef vl_printfun
-
-void
-ip_address_decode (const vl_api_address_t * in, ip46_address_t * 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)
{
- switch (in->af)
+ ip46_type_t type;
+
+ switch (clib_net_to_host_u32 (af))
{
case ADDRESS_IP4:
memset (out, 0, sizeof (*out));
- clib_memcpy (&out->ip4, &in->un.ip4, sizeof (out->ip4));
+ clib_memcpy (&out->ip4, &in->ip4, sizeof (out->ip4));
+ type = IP46_TYPE_IP4;
break;
case ADDRESS_IP6:
- clib_memcpy (&out->ip6, &in->un.ip6, sizeof (out->ip6));
+ clib_memcpy (&out->ip6, &in->ip6, sizeof (out->ip6));
+ type = IP46_TYPE_IP6;
+ break;
+ default:
+ ASSERT (!"Unkown address family in API address type");
+ type = IP46_TYPE_ANY;
break;
}
+
+ return type;
}
-void
-ip_address_encode (const ip46_address_t * in, vl_api_address_t * out)
+ip46_type_t
+ip_address_decode (const vl_api_address_t * in, ip46_address_t * out)
{
- if (ip46_address_is_ip4 (in))
- {
- memset (out, 0, sizeof (*out));
- out->af = ADDRESS_IP4;
- clib_memcpy (&out->un.ip4, &in->ip4, sizeof (out->un.ip4));
- }
+ return (ip_address_union_decode (&in->un, in->af, out));
+}
+
+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));
else
+ memcpy (out->ip4.address, &in->ip4, sizeof (out->ip4));
+}
+
+void
+ip_address_encode (const ip46_address_t * in,
+ ip46_type_t type, vl_api_address_t * out)
+{
+ switch (type)
{
- out->af = ADDRESS_IP6;
- clib_memcpy (&out->un.ip6, &in->ip6, sizeof (out->un.ip6));
+ case IP46_TYPE_IP4:
+ out->af = clib_net_to_host_u32 (ADDRESS_IP4);
+ break;
+ case IP46_TYPE_IP6:
+ out->af = clib_net_to_host_u32 (ADDRESS_IP6);
+ break;
+ case IP46_TYPE_ANY:
+ if (ip46_address_is_ip4 (in))
+ out->af = clib_net_to_host_u32 (ADDRESS_IP4);
+ else
+ out->af = clib_net_to_host_u32 (ADDRESS_IP6);
+ break;
}
+ ip_address_union_encode (in, out->af, &out->un);
}
void
ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out)
{
- switch (in->address.af)
+ switch (clib_net_to_host_u32 (in->address.af))
{
case ADDRESS_IP4:
out->fp_proto = FIB_PROTOCOL_IP4;
@@ -80,20 +113,70 @@ ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out)
void
ip_prefix_encode (const fib_prefix_t * in, vl_api_prefix_t * out)
{
- switch (in->fp_proto)
- {
- case FIB_PROTOCOL_IP4:
- out->address.af = ADDRESS_IP4;
- break;
- case FIB_PROTOCOL_IP6:
- out->address.af = ADDRESS_IP6;
- break;
- case FIB_PROTOCOL_MPLS:
- ASSERT (0);
- break;
- }
out->address_length = in->fp_len;
- ip_address_encode (&in->fp_addr, &out->address);
+ ip_address_encode (&in->fp_addr,
+ fib_proto_to_ip46 (in->fp_proto), &out->address);
+}
+
+void
+ip_mprefix_encode (const mfib_prefix_t * in, vl_api_mprefix_t * out)
+{
+ out->af = (FIB_PROTOCOL_IP6 == in->fp_proto ? ADDRESS_IP6 : ADDRESS_IP4);
+ out->af = clib_host_to_net_u32 (out->af);
+ out->grp_address_length = clib_host_to_net_u16 (in->fp_len);
+
+ ip_address_union_encode (&in->fp_grp_addr, out->af, &out->grp_address);
+ ip_address_union_encode (&in->fp_src_addr, out->af, &out->src_address);
+}
+
+void
+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);
+
+ 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;
}
/*
diff --git a/src/vnet/ip/ip_types_api.h b/src/vnet/ip/ip_types_api.h
index 2ad59ae438e..1bc899a4588 100644
--- a/src/vnet/ip/ip_types_api.h
+++ b/src/vnet/ip/ip_types_api.h
@@ -22,23 +22,35 @@
#include <vnet/ip/ip.h>
#include <vnet/fib/fib_types.h>
+#include <vnet/mfib/mfib_types.h>
/**
* Forward declarations so we need not #include the API definitions here
*/
struct _vl_api_address;
struct _vl_api_prefix;
+struct _vl_api_mprefix;
-extern void ip_address_decode (const struct _vl_api_address *in,
- ip46_address_t * out);
+extern ip46_type_t ip_address_decode (const struct _vl_api_address *in,
+ ip46_address_t * out);
extern void ip_address_encode (const ip46_address_t * in,
- struct _vl_api_address *out);
+ ip46_type_t type, struct _vl_api_address *out);
extern void ip_prefix_decode (const struct _vl_api_prefix *in,
fib_prefix_t * out);
extern void ip_prefix_encode (const fib_prefix_t * in,
struct _vl_api_prefix *out);
+extern void ip_mprefix_decode (const struct _vl_api_mprefix *in,
+ mfib_prefix_t * out);
+extern void ip_mprefix_encode (const mfib_prefix_t * in,
+ struct _vl_api_mprefix *out);
+
+extern u8 *format_vl_api_address (u8 * s, va_list * args);
+extern u8 *format_vl_api_address_union (u8 * s, va_list * args);
+extern u8 *format_vl_api_prefix (u8 * s, va_list * args);
+extern u8 *format_vl_api_mprefix (u8 * s, va_list * args);
+
#endif
/*